diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 2637612acc0..c87c1d90b0d 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -2597,38 +2597,8 @@ class Adherent extends CommonObject */ public function setCategories($categories) { - // Handle single category - if (!is_array($categories)) { - $categories = array($categories); - } - - // Get current categories require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $c = new Categorie($this->db); - $existing = $c->containing($this->id, Categorie::TYPE_MEMBER, 'id'); - - // Diff - if (is_array($existing)) { - $to_del = array_diff($existing, $categories); - $to_add = array_diff($categories, $existing); - } else { - $to_del = array(); // Nothing to delete - $to_add = $categories; - } - - // Process - foreach ($to_del as $del) { - if ($c->fetch($del) > 0) { - $c->del_type($this, Categorie::TYPE_MEMBER); - } - } - foreach ($to_add as $add) { - if ($c->fetch($add) > 0) { - $c->add_type($this, Categorie::TYPE_MEMBER); - } - } - - return; + return parent::setCategoriesCommon($categories, Categorie::TYPE_MEMBER); } /** diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 1da75fdefa5..87eec3676f8 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -230,6 +230,7 @@ if (empty($reshook)) { $objectlabel = 'Members'; $permissiontoread = $user->rights->adherent->lire; $permissiontodelete = $user->rights->adherent->supprimer; + $permissiontoadd = $user->rights->adherent->creer; $uploaddir = $conf->adherent->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } @@ -406,7 +407,8 @@ $arrayofmassactions = array( ); if ($user->rights->adherent->creer) $arrayofmassactions['close'] = $langs->trans("Resiliate"); if ($user->rights->adherent->supprimer) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); -if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); +if ($user->rights->societe->creer) $arrayofmassactions['preaffecttag'] = ''.$langs->trans("AffectTag"); +if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) $arrayofmassactions = array(); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); $newcardbutton = ''; diff --git a/htdocs/comm/action/list.php b/htdocs/comm/action/list.php index 2fe47ab39f1..7fc58b73c9f 100644 --- a/htdocs/comm/action/list.php +++ b/htdocs/comm/action/list.php @@ -233,6 +233,7 @@ if (empty($reshook)) $uploaddir = true; // Only users that can delete any event can remove records. $permissiontodelete = $user->rights->agenda->allactions->delete; + $permissiontoadd = $user->rights->agenda->myactions->create; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } @@ -296,7 +297,8 @@ if ($user->rights->agenda->allactions->delete) { $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); } -if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); +if ($user->rights->agenda->myactions->create) $arrayofmassactions['preaffecttag'] = ''.$langs->trans("AffectTag"); +if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete','preaffecttag'))) $arrayofmassactions = array(); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); $sql = "SELECT"; @@ -532,6 +534,7 @@ if ($resql) print $s; + $objecttmp = new ActionComm($db); include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; $moreforfilter = ''; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index f4a4f0f0480..76b22e29a96 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -1024,38 +1024,8 @@ class Account extends CommonObject */ public function setCategories($categories) { - // Handle single category - if (!is_array($categories)) { - $categories = array($categories); - } - - // Get current categories require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $c = new Categorie($this->db); - $existing = $c->containing($this->id, Categorie::TYPE_ACCOUNT, 'id'); - - // Diff - if (is_array($existing)) { - $to_del = array_diff($existing, $categories); - $to_add = array_diff($categories, $existing); - } else { - $to_del = array(); // Nothing to delete - $to_add = $categories; - } - - // Process - foreach ($to_del as $del) { - if ($c->fetch($del) > 0) { - $c->del_type($this, Categorie::TYPE_ACCOUNT); - } - } - foreach ($to_add as $add) { - if ($c->fetch($add) > 0) { - $c->add_type($this, Categorie::TYPE_ACCOUNT); - } - } - - return; + return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT); } /** diff --git a/htdocs/compta/bank/list.php b/htdocs/compta/bank/list.php index f3efea15235..1184da6d7ac 100644 --- a/htdocs/compta/bank/list.php +++ b/htdocs/compta/bank/list.php @@ -123,18 +123,26 @@ $parameters = array('socid'=>$socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; +if (empty($reshook)) { + include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php'; -// Purge search criteria -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers -{ - $search_ref = ''; - $search_label = ''; - $search_number = ''; - $search_status = ''; + // Purge search criteria + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers + { + $search_ref = ''; + $search_label = ''; + $search_number = ''; + $search_status = ''; + } + + // Mass actions + $objectclass = 'Account'; + $objectlabel = 'FinancialAccount'; + $permissiontoadd = $user->rights->banque->modifier; + $uploaddir = $conf->banque->dir_output; + include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php'; } - /* * View */ @@ -235,7 +243,8 @@ $arrayofmassactions = array( // 'builddoc'=>$langs->trans("PDFMerge"), ); if ($user->rights->banque->supprimer) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); -if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); +if ($user->rights->banque->modifier) $arrayofmassactions['preaffecttag'] = ''.$langs->trans("AffectTag"); +if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) $arrayofmassactions = array(); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); $newcardbutton = dolGetButtonTitle($langs->trans('NewFinancialAccount'), '', 'fa fa-plus-circle', 'card.php?action=create', '', $user->rights->banque->configurer); @@ -251,7 +260,7 @@ print ''; print ''; print ''; -print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'bank_account', 0, $newcardbutton, '', $limit, 1); +print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bank_account', 0, $newcardbutton, '', $limit, 1); $topicmail = "Information"; //$modelmail="subscription"; diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 367a2e7cd62..8fe4943d267 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1579,38 +1579,8 @@ class Contact extends CommonObject */ public function setCategories($categories) { - // Handle single category - if (!is_array($categories)) { - $categories = array($categories); - } - - // Get current categories require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $c = new Categorie($this->db); - $existing = $c->containing($this->id, Categorie::TYPE_CONTACT, 'id'); - - // Diff - if (is_array($existing)) { - $to_del = array_diff($existing, $categories); - $to_add = array_diff($categories, $existing); - } else { - $to_del = array(); // Nothing to delete - $to_add = $categories; - } - - // Process - foreach ($to_del as $del) { - if ($c->fetch($del) > 0) { - $c->del_type($this, Categorie::TYPE_CONTACT); - } - } - foreach ($to_add as $add) { - if ($c->fetch($add) > 0) { - $c->add_type($this, Categorie::TYPE_CONTACT); - } - } - - return; + return parent::setCategoriesCommon($categories, Categorie::TYPE_CONTACT); } /** diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 00c74544d17..8d6b11e19f0 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -267,7 +267,7 @@ if (empty($reshook)) $search_categ_thirdparty = ''; $search_categ_supplier = ''; $search_import_key = ''; - $toselect = ''; + $toselect = array(); $search_array_options = array(); $search_roles = array(); } @@ -277,6 +277,7 @@ if (empty($reshook)) $objectlabel = 'Contact'; $permissiontoread = $user->rights->societe->lire; $permissiontodelete = $user->rights->societe->supprimer; + $permissiontoadd = $user->rights->societe->creer; $uploaddir = $conf->societe->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; @@ -525,7 +526,8 @@ $arrayofmassactions = array( ); //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer"); if ($user->rights->societe->supprimer) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); -if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); +if ($user->rights->societe->creer) $arrayofmassactions['preaffecttag'] = ''.$langs->trans("AffectTag"); +if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) $arrayofmassactions = array(); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); $newcardbutton = dolGetButtonTitle($langs->trans('NewContactAddress'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?action=create', '', $user->rights->societe->contact->creer); diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 356eb36a04b..81cc4d81bd4 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1291,6 +1291,64 @@ if (!$error && $massaction == 'generate_doc' && $permissiontoread) } } +if (!$error && ($action == 'affecttag' && $confirm == 'yes') && $permissiontoadd) { + $db->begin(); + + $affecttag_type=GETPOST('affecttag_type', 'alpha'); + if (!empty($affecttag_type)) { + $affecttag_type_array=explode(',', $affecttag_type); + } else { + setEventMessage('CategTypeNotFound', 'errors'); + } + if (!empty($affecttag_type_array)) { + //check if tag type submited exists into Tag Map categorie class + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + $categ = new Categorie($db); + $to_affecttag_type_array=array(); + $categ_type_array=$categ->getMapList(); + foreach ($categ_type_array as $categdef) { + if (in_array($categdef['code'], $affecttag_type_array)) { + $to_affecttag_type_array[] = $categdef['code']; + } + } + + //For each valid categ type set common categ + $nbok = 0; + if (!empty($to_affecttag_type_array)) { + foreach ($to_affecttag_type_array as $categ_type) { + $contcats = GETPOST('contcats_' . $categ_type, 'array'); + //var_dump($toselect);exit; + foreach ($toselect as $toselectid) { + $result = $object->fetch($toselectid); + //var_dump($contcats);exit; + if ($result > 0) { + $result = $object->setCategoriesCommon($contcats, $categ_type, false); + if ($result > 0) { + $nbok++; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } else { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + break; + } + } + } + } + } + + if (!$error) + { + if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null); + else setEventMessages($langs->trans("RecordsModified", $nbok), null); + $db->commit(); + $toselect=array(); + } else { + $db->rollback(); + } +} + $parameters['toselect'] = $toselect; $parameters['uploaddir'] = $uploaddir; $parameters['massaction'] = $massaction; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index de4f2bc367c..0a9b7838e97 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -8384,18 +8384,26 @@ abstract class CommonObject /** * Sets object to given categories. * - * Deletes object from existing categories not supplied. * Adds it to non existing supplied categories. + * Deletes object from existing categories not supplied (if remove_existing==true). * Existing categories are left untouch. * - * @param int[]|int $categories Category ID or array of Categories IDs - * @param string $type_categ Category type ('customer', 'supplier', 'website_page', ...) + * @param int[]|int $categories Category ID or array of Categories IDs + * @param string $type_categ Category type ('customer', 'supplier', 'website_page', ...) definied into const class Categorie type + * @param boolean $remove_existing True: Remove existings categories from Object if not supplies by $categories, False: let them * @return int <0 if KO, >0 if OK */ - public function setCategoriesCommon($categories, $type_categ) + public function setCategoriesCommon($categories, $type_categ = '', $remove_existing = true) { + dol_syslog(get_class($this)."::setCategoriesCommon Oject Id:".$this->id.' type_categ:'.$type_categ.' nb tag add:'.count($categories), LOG_DEBUG); + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + if (empty($type_categ)) { + dol_syslog(__METHOD__.': Type '.$type_categ.'is an unknown category type. Done nothing.', LOG_ERR); + return -1; + } + // Handle single category if (!is_array($categories)) { $categories = array($categories); @@ -8404,22 +8412,36 @@ abstract class CommonObject // Get current categories $c = new Categorie($this->db); $existing = $c->containing($this->id, $type_categ, 'id'); - - // Diff - if (is_array($existing)) { - $to_del = array_diff($existing, $categories); - $to_add = array_diff($categories, $existing); + if ($remove_existing) { + // Diff + if (is_array($existing)) { + $to_del = array_diff($existing, $categories); + $to_add = array_diff($categories, $existing); + } else { + $to_del = array(); // Nothing to delete + $to_add = $categories; + } } else { $to_del = array(); // Nothing to delete - $to_add = $categories; + $to_add = array_diff($categories, $existing); } $error = 0; + $ok=0; // Process foreach ($to_del as $del) { if ($c->fetch($del) > 0) { - $c->del_type($this, $type_categ); + $result=$c->del_type($this, $type_categ); + if ($result < 0) + { + $error++; + $this->error = $c->error; + $this->errors = $c->errors; + break; + } else { + $ok+=$result; + } } } foreach ($to_add as $add) { @@ -8432,11 +8454,13 @@ abstract class CommonObject $this->error = $c->error; $this->errors = $c->errors; break; + } else { + $ok+=$result; } } } - return $error ? -1 : 1; + return $error ? -1 * $error : $ok; } /** diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index fd3ba8c6fb2..8e25deb21cb 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -64,7 +64,7 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh print ''; print ''; print ''; - if ($massaction != 'predelete') { // When $massaction == 'predelete', action may be already output to 'delete' by the mass action system. + if ($massaction != 'predelete' && $massaction != 'preaffecttag') { // When $massaction == 'predelete', action may be already output to 'delete' by the mass action system. print ''; } print ''; diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index 21070467f57..7c6ab6deaa5 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -37,6 +37,40 @@ if ($massaction == 'predelete') print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1); } +if ($massaction == 'preaffecttag') +{ + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + $categ = new Categorie($db); + $categ_types=array(); + $categ_type_array=$categ->getMapList(); + foreach ($categ_type_array as $categdef) { + if (isset($object) && $categdef['obj_table']==$object->table_element) { + if (!array_key_exists($categdef['code'], $categ_types)) $categ_types[$categdef['code']] = array('code'=>$categdef['code'],'label'=>$langs->trans($categdef['obj_class'])); + } + if (isset($objecttmp) && $categdef['obj_table']==$objecttmp->table_element) { + if (!array_key_exists($categdef['code'], $categ_types)) $categ_types[$categdef['code']] = array('code'=>$categdef['code'],'label'=>$langs->trans($categdef['obj_class'])); + } + } + + $formquestion = array(); + if (!empty($categ_types)) { + foreach ($categ_types as $categ_type) { + $cate_arbo = $form->select_all_categories($categ_type['code'], null, 'parent', null, null, 1); + $formquestion[]=array('type' => 'other', + 'name' => 'affecttag_'.$categ_type['code'], + 'label' => $langs->trans("Tag").' '.$categ_type['label'], + 'value' => $form->multiselectarray('contcats_'.$categ_type['code'], $cate_arbo, GETPOST('contcats_'.$categ_type['code'], 'array'), null, null, null, null, '60%')); + } + $formquestion[]=array('type' => 'other', + 'name' => 'affecttag_type', + 'label' => '', + 'value' => ''); + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmAffectTag"), $langs->trans("ConfirmAffectTagQuestion", count($toselect)), "affecttag", $formquestion, 1, 0, 200, 500, 1); + } else { + setEventMessage('CategTypeNotFound'); + } +} + if ($massaction == 'presend') { $langs->load("mails"); @@ -47,8 +81,7 @@ if ($massaction == 'presend') if (!GETPOST('cancel', 'alpha')) { - foreach ($arrayofselected as $toselectid) - { + foreach ($arrayofselected as $toselectid) { $result = $objecttmp->fetch($toselectid); if ($result > 0) { diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index efa89f07bb7..6c94c4299d3 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -550,7 +550,7 @@ CREATE TABLE llx_session( fk_user integer NOT NULL, remote_ip varchar(64) NULL, user_agent varchar(128) NULL -)ENGINE=innodb; +) ENGINE=innodb; INSERT INTO llx_c_socialnetworks (entity, code, label, url, icon, active) VALUES(1, 'github', 'Github', 'https://github.com/{socialid}', 'fa-github', 1); diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 7075df90783..e196120c27d 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1112,4 +1112,8 @@ UpToDate=Up-to-date OutOfDate=Out-of-date EventReminder=Event Reminder UpdateForAllLines=Update for all lines -OnHold=On hold \ No newline at end of file +OnHold=On hold +AffectTag=Affect Tag +ConfirmAffectTag=Bulk Tag Affect +ConfirmAffectTagQuestion=Are you sure you want to affect tags to the %s selected record(s)? +CategTypeNotFound=No tag type found for type of records diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 63e0fea2b36..d0314fb9c45 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5504,38 +5504,9 @@ class Product extends CommonObject */ public function setCategories($categories) { - // Handle single category - if (!is_array($categories)) { - $categories = array($categories); - } - // Get current categories - include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $c = new Categorie($this->db); - $existing = $c->containing($this->id, Categorie::TYPE_PRODUCT, 'id'); - - // Diff - if (is_array($existing)) { - $to_del = array_diff($existing, $categories); - $to_add = array_diff($categories, $existing); - } else { - $to_del = array(); // Nothing to delete - $to_add = $categories; - } - - // Process - foreach ($to_del as $del) { - if ($c->fetch($del) > 0) { - $c->del_type($this, Categorie::TYPE_PRODUCT); - } - } - foreach ($to_add as $add) { - if ($c->fetch($add) > 0) { - $c->add_type($this, Categorie::TYPE_PRODUCT); - } - } - - return; + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + return parent::setCategoriesCommon($categories, Categorie::TYPE_PRODUCT); } /** diff --git a/htdocs/product/list.php b/htdocs/product/list.php index a624daf8afb..21705e74663 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -304,6 +304,7 @@ if (empty($reshook)) $permissiontoread = $user->rights->{$rightskey}->lire; $permissiontodelete = $user->rights->{$rightskey}->supprimer; + $permissiontoadd = $user->rights->{$rightskey}->creer; $uploaddir = $conf->product->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } @@ -533,8 +534,10 @@ if ($resql) //'builddoc'=>$langs->trans("PDFMerge"), //'presend'=>$langs->trans("SendByMail"), ); + if ($user->rights->{$rightskey}->supprimer) $arrayofmassactions['predelete'] = "".$langs->trans("Delete"); - if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); + if ($user->rights->{$rightskey}->creer) $arrayofmassactions['preaffecttag'] = ''.$langs->trans("AffectTag"); + if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) $arrayofmassactions = array(); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); $newcardbutton = ''; diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index d7a52cd1910..f975eaabc67 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -890,39 +890,7 @@ class Entrepot extends CommonObject */ public function setCategories($categories) { - $type_categ = Categorie::TYPE_WAREHOUSE; - - // Handle single category - if (!is_array($categories)) { - $categories = array($categories); - } - - // Get current categories require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $c = new Categorie($this->db); - $existing = $c->containing($this->id, $type_categ, 'id'); - - // Diff - if (is_array($existing)) { - $to_del = array_diff($existing, $categories); - $to_add = array_diff($categories, $existing); - } else { - $to_del = array(); // Nothing to delete - $to_add = $categories; - } - - // Process - foreach ($to_del as $del) { - if ($c->fetch($del) > 0) { - $c->del_type($this, $type_categ); - } - } - foreach ($to_add as $add) { - if ($c->fetch($add) > 0) { - $c->add_type($this, $type_categ); - } - } - - return; + return parent::setCategoriesCommon($categories, Categorie::TYPE_WAREHOUSE); } } diff --git a/htdocs/product/stock/list.php b/htdocs/product/stock/list.php index f2c7133618b..1470bdc2aa0 100644 --- a/htdocs/product/stock/list.php +++ b/htdocs/product/stock/list.php @@ -46,6 +46,8 @@ $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'stocklist'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') +$toselect = GETPOST('toselect', 'array'); + $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); $search_ref = GETPOST("sref", "alpha") ?GETPOST("sref", "alpha") : GETPOST("search_ref", "alpha"); @@ -160,7 +162,7 @@ if (empty($reshook)) { $search[$key] = ''; } - $toselect = ''; + $toselect = array(); $search_array_options = array(); } if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') @@ -174,6 +176,7 @@ if (empty($reshook)) $objectlabel = 'Warehouse'; $permissiontoread = $user->rights->stock->lire; $permissiontodelete = $user->rights->stock->supprimer; + $permissiontoadd = $user->rights->stock->creer; $uploaddir = $conf->stock->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } @@ -343,7 +346,8 @@ $arrayofmassactions = array( //'builddoc'=>$langs->trans("PDFMerge"), ); //if ($user->rights->stock->supprimer) $arrayofmassactions['predelete']=''.$langs->trans("Delete"); -if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); +if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete','preaffecttag'))) $arrayofmassactions = array(); +if ($user->rights->stock->creer) $arrayofmassactions['preaffecttag'] = ''.$langs->trans("AffectTag"); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); print '