From 325ceda4dcff35aeff3249d170561b2928e19418 Mon Sep 17 00:00:00 2001 From: Florian Henry Date: Wed, 31 Jul 2013 21:52:49 +0200 Subject: [PATCH 1/2] [ task #1014 ] Add option to recursivly add parent cactegory --- ChangeLog | 1 + htdocs/categories/admin/categorie.php | 121 ++++++++++++++++++++ htdocs/categories/class/categorie.class.php | 28 +++++ htdocs/core/lib/categories.lib.php | 31 +++++ htdocs/core/modules/modCategorie.class.php | 7 ++ 5 files changed, 188 insertions(+) create mode 100644 htdocs/categories/admin/categorie.php diff --git a/ChangeLog b/ChangeLog index 7c9c7fc22a5..986041f4d76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -42,6 +42,7 @@ For users: - Qual: Implement same rule for return value of all command line scripts (0 when success, <>0 if error). - New: [ task #1005 ] Adapting to Spanish legislation bill numbering - New: [ task #1011 ] Now supplier order and invoice deal with payment terms and mode +- New: [ task #1014 ] Add option to recursivly add parent cactegory For translators: diff --git a/htdocs/categories/admin/categorie.php b/htdocs/categories/admin/categorie.php new file mode 100644 index 00000000000..b762e1b1fcc --- /dev/null +++ b/htdocs/categories/admin/categorie.php @@ -0,0 +1,121 @@ + + * Copyright (C) 2013 Florian Henry + * + * 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 3 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, see . + */ + +/** + * \file htdocs/categories/admin/categorie.php + * \ingroup categories + * \brief Categorie admin pages + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php'; + + +if (!$user->admin) +accessforbidden(); + +$langs->load("cateogries"); + +$action=GETPOST("action"); + +/* + * Actions + */ +if (preg_match('/set_(.*)/',$action,$reg)) +{ + $code=$reg[1]; + if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + setEventMessage($db->lasterror(),'errors'); + } +} + +if (preg_match('/del_(.*)/',$action,$reg)) +{ + $code=$reg[1]; + if (dolibarr_del_const($db, $code, $conf->entity) > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + setEventMessage($db->lasterror(),'errors'); + } +} + + + +/* + * View + */ + +llxHeader('',$langs->trans("CategoriesSetup")); + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("CategoriesSetup"),'','setup'); + + +$head=categoriesadmin_prepare_head(); + +dol_fiche_head($head, 'setup', $langs->trans("Security")); + + +print ''; +print ''; +print ''; +print ''; +print ''."\n"; +print ''; + +$var=true; +$form = new Form($db); + +// Mail required for members +$var=!$var; +print ''; +print ''; +print ''; + +print ''; + +print '
'.$langs->trans("Description").' '.$langs->trans("Value").'
'.$langs->trans("CategorieRecursiv").' '; +if ($conf->use_javascript_ajax) +{ + print ajax_constantonoff('CATEGORIE_RECURSIV_ADD'); +} +else +{ + if($conf->global->CATEGORIE_RECURSIV_ADD == 0) + { + print ''.img_picto($langs->trans("Disabled"),'off').''; + } + else if($conf->global->CATEGORIE_RECURSIV_ADD == 1) + { + print ''.img_picto($langs->trans("Enabled"),'on').''; + } +} +print '
'; + +$db->close(); +llxFooter(); \ No newline at end of file diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 5224fa2d72e..78fa74d206e 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -389,6 +389,8 @@ class Categorie */ function add_type($obj,$type) { + global $conf; + if ($this->id == -1) return -2; if ($type == 'company') $type='societe'; @@ -405,6 +407,32 @@ class Categorie dol_syslog(get_class($this).'::add_type sql='.$sql); if ($this->db->query($sql)) { + if (!empty($conf->global->CATEGORIE_RECURSIV_ADD)) { + $sql = 'SELECT fk_parent FROM '.MAIN_DB_PREFIX.'categorie'; + $sql.= " WHERE rowid = '".$this->id."'"; + + dol_syslog(get_class($this)."::add_type sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql) > 0) + { + $objparent = $this->db->fetch_object($resql); + + if (!empty($objparent->fk_parent)) { + $cat = new Categorie($this->db); + $cat->id=$objparent->fk_parent; + $cat->add_type($obj, $type); + } + } + } + else + { + $this->error=$this->db->error().' sql='.$sql; + return -1; + } + } + return 1; } else diff --git a/htdocs/core/lib/categories.lib.php b/htdocs/core/lib/categories.lib.php index fc0bb1092b8..dc4b5aaac20 100644 --- a/htdocs/core/lib/categories.lib.php +++ b/htdocs/core/lib/categories.lib.php @@ -60,4 +60,35 @@ function categories_prepare_head($object,$type) } +/** + * Prepare array with list of tabs + * + * @return array Array of tabs to show + */ +function categoriesadmin_prepare_head() +{ + global $langs, $conf, $user; + + $langs->load("categories"); + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/categories/admin/categorie.php'; + $head[$h][1] = $langs->trans("Setup"); + $head[$h][2] = 'setup'; + $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); to remove a tab + complete_head_from_modules($conf,$langs,$object,$head,$h,'categoriesadmin'); + + complete_head_from_modules($conf,$langs,$object,$head,$h,'categoriesadmin','remove'); + + return $head; +} + + ?> \ No newline at end of file diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php index d83d4fed1cc..7941df39c26 100644 --- a/htdocs/core/modules/modCategorie.class.php +++ b/htdocs/core/modules/modCategorie.class.php @@ -68,6 +68,13 @@ class modCategorie extends DolibarrModules // Constantes $this->const = array(); + $r=0; + $this->const[$r][0] = "CATEGORIE_RECURSIV_ADD"; + $this->const[$r][1] = "yesno"; + $this->const[$r][2] = "0"; + $this->const[$r][3] = 'Affect parent categories'; + $this->const[$r][4] = 0; + $r++; // Boxes $this->boxes = array(); From c5cec980c854624f89ca9a935d677996a26cfcb8 Mon Sep 17 00:00:00 2001 From: Florian Henry Date: Wed, 31 Jul 2013 21:55:32 +0200 Subject: [PATCH 2/2] Fix spelling --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 986041f4d76..f90a1048074 100644 --- a/ChangeLog +++ b/ChangeLog @@ -42,7 +42,7 @@ For users: - Qual: Implement same rule for return value of all command line scripts (0 when success, <>0 if error). - New: [ task #1005 ] Adapting to Spanish legislation bill numbering - New: [ task #1011 ] Now supplier order and invoice deal with payment terms and mode -- New: [ task #1014 ] Add option to recursivly add parent cactegory +- New: [ task #1014 ] Add option to recursivly add parent category For translators: