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 ''; print getTitleFieldOfList("Type", 0, $_SERVER['PHP_SELF'], 'type_container', '', $param, '', $sortfield, $sortorder, '')."\n"; print getTitleFieldOfList("Page", 0, $_SERVER['PHP_SELF'], 'pageurl', '', $param, '', $sortfield, $sortorder, '')."\n"; + print getTitleFieldOfList("Categories", 0, $_SERVER['PHP_SELF']); //print getTitleFieldOfList("Description", 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '')."\n"; print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']); print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']); print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; print ''; + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + $c = new Categorie($db); + foreach ($listofpages['list'] as $answerrecord) { if (get_class($answerrecord) == 'WebsitePage') { print ''; + // Type of container print ''.$langs->trans("Container").' - '; print $langs->trans($answerrecord->type_container); // TODO Use label of container print ''; + // Container url and label print ''; print $answerrecord->getNomUrl(1); print ' ('.($answerrecord->title ? $answerrecord->title : $langs->trans("NoTitle")).')'; @@ -3839,6 +3857,23 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction = print ''.$answerrecord->description.''; print ''; + // Categories + print ''; + if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) + { + // Get current categories + $existing = $c->containing($answerrecord->id, Categorie::TYPE_WEBSITE_PAGE, 'object'); + if (is_array($existing)) { + foreach ($existing as $tmpcategory) { + //var_dump($tmpcategory); + print 'label).'">'; + } + } + } + //var_dump($existing); + print ''; + + $param = '?action=replacesiteconfirm'; $param .= '&websiteid='.$website->id; $param .= '&optioncontent='.GETPOST('optioncontent', 'aZ09'); @@ -3882,10 +3917,10 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction = print ''; print ''; - } - else { + } else { print ''; + // Type of container print ''; $translateofrecordtype = array( 'website_csscontent'=>'WEBSITE_CSS_INLINE', @@ -3913,11 +3948,15 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction = $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09'); $param .= '&searchstring='.urlencode($searchkey); + // Container url and label print ''; $backtopageurl = $_SERVER["PHP_SELF"].$param; print 'ref.'&backtopage='.urlencode($backtopageurl).'">'.$langs->trans("EditCss").''; print ''; + print ''; + print ''; + print ''; print '';