diff --git a/dev/skeletons/modMyModule.class.php b/dev/skeletons/modMyModule.class.php index c7a992727e5..d9994e31839 100644 --- a/dev/skeletons/modMyModule.class.php +++ b/dev/skeletons/modMyModule.class.php @@ -120,6 +120,7 @@ class modMyModule extends DolibarrModules // 'user' to add a tab in user view // 'group' to add a tab in group view // 'contact' to add a tab in contact view + // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member) $this->tabs = array(); // Dictionnaries diff --git a/htdocs/categories/photos.php b/htdocs/categories/photos.php index 1aff74342a2..62f894c62fd 100644 --- a/htdocs/categories/photos.php +++ b/htdocs/categories/photos.php @@ -29,22 +29,29 @@ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/categories.lib.php"); -$langs->load("category"); +$langs->load("categories"); $langs->load("bills"); -$mesg = ''; -$type=$_REQUEST['type']; - // Security check if (!$user->rights->categorie->lire) accessforbidden(); -if ($_REQUEST['id'] == "") +$mesg = ''; + +$id=GETPOST('id'); +$ref=GETPOST('ref'); +$type=GETPOST('type'); +$action=GETPOST('action'); +$confirm=GETPOST('confirm'); + +if ($id == "") { dol_print_error('','Missing parameter id'); exit(); } +$object = new Categorie($db); /* * Actions @@ -52,26 +59,22 @@ if ($_REQUEST['id'] == "") if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) { - if ($_GET["id"]) + if ($id) { - $c = new Categorie($db); - $result = $c->fetch($_GET["id"]); + $result = $object->fetch($id); - $result = $c->add_photo($conf->categorie->dir_output, $_FILES['userfile']); + $result = $object->add_photo($conf->categorie->dir_output, $_FILES['userfile']); } } - -if ($_REQUEST["action"] == 'confirm_delete' && $_GET["file"] && $_REQUEST['confirm'] == 'yes' && $user->rights->categorie->creer) +if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer) { - $c = new Categorie($db); - $c->delete_photo($conf->categorie->dir_output."/".$_GET["file"]); + $object->delete_photo($conf->categorie->dir_output."/".$_GET["file"]); } -if ($_GET["action"] == 'addthumb' && $_GET["file"]) +if ($action == 'addthumb' && $_GET["file"]) { - $c = new Category($db); - $c->add_thumb($conf->categorie->dir_output."/".$_GET["file"]); + $object->add_thumb($conf->categorie->dir_output."/".$_GET["file"]); } @@ -81,48 +84,29 @@ if ($_GET["action"] == 'addthumb' && $_GET["file"]) llxHeader ("","",$langs->trans("Categories")); -$c = new Categorie($db); -$c->fetch($_REQUEST['id']); - $html = new Form($db); -if ($_GET["id"] || $_GET["ref"]) +if (!empty($id) || !empty($ref)) { - $c = new Categorie($db); - - if ($_GET["id"]) $result = $c->fetch($_GET["id"]); - + $result = $object->fetch($id); if ($result) { - - $h = 0; - $head = array(); - - $head[$h][0] = DOL_URL_ROOT.'/categories/viewcat.php?id='.$c->id.'&type='.$type; - $head[$h][1] = $langs->trans("Card"); - $head[$h][2] = 'card'; - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/categories/photos.php?id='.$c->id.'&type='.$type; - $head[$h][1] = $langs->trans("Photos"); - $head[$h][2] = 'photos'; - $h++; - $title=$langs->trans("ProductsCategoryShort"); if ($type == 0) $title=$langs->trans("ProductsCategoryShort"); elseif ($type == 1) $title=$langs->trans("SuppliersCategoryShort"); elseif ($type == 2) $title=$langs->trans("CustomersCategoryShort"); elseif ($type == 3) $title=$langs->trans("MembersCategoryShort"); + $head = categories_prepare_head($object,$type); dol_fiche_head($head, 'photos', $title, 0, 'category'); /* * Confirmation de la suppression de photo */ - if ($_GET['action'] == 'delete') + if ($action == 'delete') { - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$c->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1); + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1); if ($ret == 'html') print '
'; } @@ -132,7 +116,7 @@ if ($_GET["id"] || $_GET["ref"]) // Path of category print ''; - $ways = $c->print_all_ways (); + $ways = $object->print_all_ways (); print $langs->trans("Ref").''; print ''.$langs->trans("Root").' >> '; foreach ($ways as $way) @@ -144,23 +128,23 @@ if ($_GET["id"] || $_GET["ref"]) // Description print ''; print $langs->trans("Description").''; - print nl2br($c->description); + print nl2br($object->description); print ''; // Visibility /* if ($type == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) { - if ($c->socid) + if ($object->socid) { $soc = new Societe($db); - $soc->fetch($c->socid); + $soc->fetch($object->socid); print ''; print $langs->trans("AssignedToTheCustomer").''; print $soc->getNomUrl(1); print ''; - $catsMeres = $c->get_meres (); + $catsMeres = $object->get_meres (); if ($catsMeres < 0) { @@ -170,7 +154,7 @@ if ($_GET["id"] || $_GET["ref"]) { print ''; print $langs->trans("CategoryContents").''; - print ($c->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); print ''; } } @@ -178,7 +162,7 @@ if ($_GET["id"] || $_GET["ref"]) { print ''; print $langs->trans("CategoryContents").''; - print ($c->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); print ''; } } @@ -186,7 +170,7 @@ if ($_GET["id"] || $_GET["ref"]) { print ''; print $langs->trans("CategoryContents").''; - print ($c->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); print ''; } */ @@ -205,11 +189,11 @@ if ($_GET["id"] || $_GET["ref"]) print "\n
\n"; - if ($_GET["action"] != 'ajout_photo' && $user->rights->produit->creer) + if ($action != 'ajout_photo' && $user->rights->produit->creer) { if (! empty($conf->global->MAIN_UPLOAD_DOC)) { - print ''; + print ''; print $langs->trans("AddPhoto").''; } else @@ -224,15 +208,15 @@ if ($_GET["id"] || $_GET["ref"]) /* * Ajouter une photo */ - if ($_GET["action"] == 'ajout_photo' && $user->rights->categorie->creer && ! empty($conf->global->MAIN_UPLOAD_DOC)) + if ($action == 'ajout_photo' && $user->rights->categorie->creer && ! empty($conf->global->MAIN_UPLOAD_DOC)) { // Affiche formulaire upload $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/categories/photos.php?id='.$c->id.'&type='.$type,$langs->trans("AddPhoto"),1); + $formfile->form_attach_new_file(DOL_URL_ROOT.'/categories/photos.php?id='.$object->id.'&type='.$type,$langs->trans("AddPhoto"),1); } // Affiche photos - if ($_GET["action"] != 'ajout_photo') + if ($action != 'ajout_photo') { $nbphoto=0; $nbbyrow=5; @@ -240,13 +224,13 @@ if ($_GET["id"] || $_GET["ref"]) $maxWidth = 160; $maxHeight = 120; - $pdir = get_exdir($c->id,2) . $c->id ."/photos/"; + $pdir = get_exdir($object->id,2) . $object->id ."/photos/"; $dir = $conf->categorie->dir_output.'/'.$pdir; print '
'; print ''; - foreach ($c->liste_photos($dir) as $key => $obj) + foreach ($object->liste_photos($dir) as $key => $obj) { $nbphoto++; @@ -270,9 +254,9 @@ if ($_GET["id"] || $_GET["ref"]) $viewfilename=$obj['photo']; // Taille de l'image - $c->get_image_size($dir.$filename); - $imgWidth = ($c->imgWidth < $maxWidth) ? $c->imgWidth : $maxWidth; - $imgHeight = ($c->imgHeight < $maxHeight) ? $c->imgHeight : $maxHeight; + $object->get_image_size($dir.$filename); + $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth; + $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight; print ''; @@ -281,7 +265,7 @@ if ($_GET["id"] || $_GET["ref"]) print '
'; // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites - if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$obj['photo']) && ($c->imgWidth > $maxWidth || $c->imgHeight > $maxHeight)) + if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) { print ''.img_refresh($langs->trans('GenerateThumb')).'  '; } diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index bd902b68482..fe9b2bcb2a0 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -28,46 +28,51 @@ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/categories.lib.php"); // Security check -if (! $user->rights->categorie->lire) -{ - accessforbidden(); -} +if (! $user->rights->categorie->lire) accessforbidden(); $mesg = ''; -if (GETPOST('id') == "") +$mesg = ''; +$id=GETPOST('id'); +$ref=GETPOST('ref'); +$type=GETPOST('type'); +$action=GETPOST('action'); +$confirm=GETPOST('confirm'); + +if ($id == "") { dol_print_error('','Missing parameter id'); exit(); } -$c = new Categorie($db); -$result=$c->fetch(GETPOST('id')); +$object = new Categorie($db); +$result=$object->fetch($id); if ($result <= 0) { - dol_print_error($db,$c->error); + dol_print_error($db,$object->error); exit; } -$type=$c->type; +$type=$object->type; /* * Actions */ -if ($user->rights->categorie->supprimer && $_POST["action"] == 'confirm_delete' && $_POST['confirm'] == 'yes') +if ($user->rights->categorie->supprimer && $action == 'confirm_delete' && $confirm == 'yes') { - if ($c->delete($user) >= 0) + if ($object->delete($user) >= 0) { header("Location: ".DOL_URL_ROOT.'/categories/index.php?type='.$type); exit; } else { - $mesg='
'.$c->error.'
'; + $mesg='
'.$object->error.'
'; } } @@ -81,38 +86,24 @@ $html = new Form($db); llxHeader ("","",$langs->trans("Categories")); - if ($mesg) print $mesg.'
'; - -$h = 0; -$head = array(); - -$head[$h][0] = DOL_URL_ROOT.'/categories/viewcat.php?id='.$c->id.'&type='.$type; -$head[$h][1] = $langs->trans("Card"); -$head[$h][2] = 'card'; -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/categories/photos.php?id='.$c->id.'&type='.$type; -$head[$h][1] = $langs->trans("Photos"); -$head[$h][2] = 'photos'; -$h++; - if ($type == 0) $title=$langs->trans("ProductsCategoryShort"); elseif ($type == 1) $title=$langs->trans("SuppliersCategoryShort"); elseif ($type == 2) $title=$langs->trans("CustomersCategoryShort"); elseif ($type == 3) $title=$langs->trans("MembersCategoryShort"); else $title=$langs->trans("Category"); +$head = categories_prepare_head($object,$type); dol_fiche_head($head, 'card', $title, 0, 'category'); /* * Confirmation suppression */ -if ($_GET['action'] == 'delete') +if ($action == 'delete') { - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$c->id.'&type='.$type,$langs->trans('DeleteCategory'),$langs->trans('ConfirmDeleteCategory'),'confirm_delete'); + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type,$langs->trans('DeleteCategory'),$langs->trans('ConfirmDeleteCategory'),'confirm_delete'); if ($ret == 'html') print '
'; } @@ -120,7 +111,7 @@ print '
'; // Path of category print ''; // Description print ''; print '
'; -$ways = $c->print_all_ways (); +$ways = $object->print_all_ways (); print $langs->trans("Ref").''; print ''.$langs->trans("Root").' >> '; foreach ($ways as $way) @@ -132,7 +123,7 @@ print '
'; print $langs->trans("Description").''; -print nl2br($c->description); +print nl2br($object->description); print '
'; @@ -147,13 +138,13 @@ print "
\n"; if ($user->rights->categorie->creer) { - $socid = ($c->socid ? "&socid=".$c->socid : ""); - print "".$langs->trans("Modify").""; + $socid = ($object->socid ? "&socid=".$object->socid : ""); + print "".$langs->trans("Modify").""; } if ($user->rights->categorie->supprimer) { - print "".$langs->trans("Delete").""; + print "".$langs->trans("Delete").""; } print "
"; @@ -161,7 +152,7 @@ print "
"; -$cats = $c->get_filles(); +$cats = $object->get_filles(); if ($cats < 0) { dol_print_error(); @@ -173,7 +164,7 @@ else print "".$langs->trans("SubCats").''; if ($user->rights->categorie->creer) { - print ""; + print ""; print img_picto($langs->trans("Create"),'filenew'); print ""; } @@ -214,10 +205,10 @@ else } // List of products -if ($c->type == 0) +if ($object->type == 0) { - $prods = $c->get_type("product","Product"); + $prods = $object->get_type("product","Product"); if ($prods < 0) { dol_print_error(); @@ -253,9 +244,9 @@ if ($c->type == 0) } } -if ($c->type == 1) +if ($object->type == 1) { - $socs = $c->get_type("societe","Fournisseur","fournisseur"); + $socs = $object->get_type("societe","Fournisseur","fournisseur"); if ($socs < 0) { dol_print_error(); @@ -291,9 +282,9 @@ if ($c->type == 1) } } -if($c->type == 2) +if($object->type == 2) { - $socs = $c->get_type("societe","Societe"); + $socs = $object->get_type("societe","Societe"); if ($socs < 0) { dol_print_error(); @@ -329,14 +320,14 @@ if($c->type == 2) } // List of members -if ($c->type == 3) +if ($object->type == 3) { require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); - $prods = $c->get_type("member","Adherent"); + $prods = $object->get_type("member","Adherent"); if ($prods < 0) { - dol_print_error($db,$c->error); + dol_print_error($db,$object->error); } else { diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 9eacdd5907c..0635ee861a6 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -45,23 +45,28 @@ $langs->load('bills'); $langs->load('orders'); $langs->load('products'); +$id=GETPOST('id'); +$ref=GETPOST('ref'); +$socid=GETPOST('socid'); +$action=GETPOST('action'); +$confirm=GETPOST('confirm'); + $sall=GETPOST("sall"); $mesg=(GETPOST("msg") ? GETPOST("msg") : GETPOST("mesg")); $year=GETPOST("year"); $month=GETPOST("month"); -$socid=GETPOST('socid'); // Security check $module='propale'; -if (isset($_GET["socid"])) +if (isset($socid)) { - $objectid=$_GET["socid"]; + $objectid=$socid; $module='societe'; $dbtable=''; } -else if (isset($_GET["id"]) && $_GET["id"] > 0) +else if (isset($id) && $id > 0) { - $objectid=$_GET["id"]; + $objectid=$id; $module='propale'; $dbtable='propal'; } diff --git a/htdocs/lib/categories.lib.php b/htdocs/lib/categories.lib.php new file mode 100644 index 00000000000..e3d99f899b6 --- /dev/null +++ b/htdocs/lib/categories.lib.php @@ -0,0 +1,58 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/lib/categories.lib.php + * \brief Ensemble de fonctions de base pour le module categorie + * \ingroup categorie + * \version $Id$ + * + * Ensemble de fonctions de base de dolibarr sous forme d'include + */ + +function categories_prepare_head($object,$type) +{ + global $langs, $conf, $user; + + $langs->load("categories"); + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/categories/photos.php?id='.$object->id.'&type='.$type; + $head[$h][1] = $langs->trans("Photos"); + $head[$h][2] = 'photos'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab + complete_head_from_modules($conf,$langs,$object,$head,$h,'categories_'.$type); + + return $head; +} + + +?> \ No newline at end of file