diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 703460a8053..5f9582a475f 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -8270,6 +8270,27 @@ abstract class CommonObject /* Part for categories/tags */ + /** + * Sets object to given categories. + * + * Deletes object from existing categories not supplied. + * Adds it to non existing supplied categories. + * Existing categories are left untouch. + * + * @param string $type_categ Category type ('customer', 'supplier', 'website_page', ...) + * @return int Array of category objects or < 0 if KO + */ + public function getCategoriesCommon($type_categ) + { + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + + // Get current categories + $c = new Categorie($this->db); + $existing = $c->containing($this->id, $type_categ, 'id'); + + return $existing; + } + /** * Sets object to given categories. * diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index 6ddfe936d18..39559bb9bb7 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -312,6 +312,11 @@ a.buttonticket { /* height: 40px; */ } +/* Used by categories */ +span.categorysquarre { + padding: 0 4px 0 4px; +} + /* Used by timesheets */ span.timesheetalreadyrecorded input { border: none; diff --git a/htdocs/website/index.php b/htdocs/website/index.php index a4b42bfdf9b..6605923b254 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -987,23 +987,35 @@ if ($action == 'addcontainer') setEventMessages($objectpage->error, $objectpage->errors, 'errors'); $action = 'createcontainer'; } - else { - // If there is no home page yet, this new page will be set as the home page - if (empty($object->fk_default_home)) { - $object->fk_default_home = $pageid; - $res = $object->update($user); - if ($res <= 0) - { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } else { - $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php'; + } - // Generate the index.php page (to be the home page) and wrapper.php file - $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper); + if (!$error) { + // Website categories association + $categoriesarray = GETPOST('categories', 'array'); + $result = $objectpage->setCategories($categoriesarray); + if ($result < 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } + } - if ($result <= 0) setEventMessages('Failed to write file '.$fileindex, null, 'errors'); - } + if (!$error) { + // If there is no home page yet, this new page will be set as the home page + if (empty($object->fk_default_home)) { + $object->fk_default_home = $pageid; + $res = $object->update($user); + if ($res <= 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } else { + $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php'; + + // Generate the index.php page (to be the home page) and wrapper.php file + $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper); + + if ($result <= 0) setEventMessages('Failed to write file '.$fileindex, null, 'errors'); } } } @@ -1670,7 +1682,7 @@ if ($action == 'updatemeta') } if (!$error) { - // Supplier categories association + // Website categories association $categoriesarray = GETPOST('categories', 'array'); $result = $objectpage->setCategories($categoriesarray); if ($result < 0) @@ -3814,22 +3826,28 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction = print '