From 06f66423de270c8f6388d5224ccd7a61ebd323bd Mon Sep 17 00:00:00 2001
From: GregMage
Date: Fri, 26 Sep 2025 20:46:37 +0200
Subject: [PATCH 01/71] Start of work on the menu manager
---
htdocs/kernel/menuscategory.php | 99 +++++++++++++++++++
htdocs/modules/system/admin/menus/index.php | 2 +
htdocs/modules/system/admin/menus/main.php | 85 ++++++++++++++++
.../system/admin/menus/xoops_version.php | 35 +++++++
.../admin/modulesadmin/modulesadmin.php | 2 +
htdocs/modules/system/constants.php | 1 +
htdocs/modules/system/include/update.php | 23 +++++
.../modules/system/language/english/admin.php | 5 +
.../system/language/english/admin/menus.php | 17 ++++
.../modules/system/language/english/menu.php | 12 ++-
.../system/templates/admin/system_menus.tpl | 25 +++++
htdocs/modules/system/xoops_version.php | 5 +-
12 files changed, 308 insertions(+), 3 deletions(-)
create mode 100644 htdocs/kernel/menuscategory.php
create mode 100644 htdocs/modules/system/admin/menus/index.php
create mode 100644 htdocs/modules/system/admin/menus/main.php
create mode 100644 htdocs/modules/system/admin/menus/xoops_version.php
create mode 100644 htdocs/modules/system/language/english/admin/menus.php
create mode 100644 htdocs/modules/system/templates/admin/system_menus.tpl
diff --git a/htdocs/kernel/menuscategory.php b/htdocs/kernel/menuscategory.php
new file mode 100644
index 000000000..bcf6b2fa8
--- /dev/null
+++ b/htdocs/kernel/menuscategory.php
@@ -0,0 +1,99 @@
+initVar('category_id', XOBJ_DTYPE_INT, null, false);
+ $this->initVar('category_title', XOBJ_DTYPE_TXTBOX, null);
+ $this->initVar('category_url', XOBJ_DTYPE_TXTBOX, null);
+ $this->initVar('category_position', XOBJ_DTYPE_INT, null, false);
+ $this->initVar('category_active', XOBJ_DTYPE_INT, 1);
+ }
+
+ public function getFormCat($action = false)
+ {
+ if ($action === false) {
+ $action = $_SERVER['REQUEST_URI'];
+ }
+ include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
+ //include __DIR__ . '/../include/common.php';
+
+ //form title
+ $title = $this->isNew() ? sprintf(_AM_SYSTEM_MENUS_ADDCAT) : sprintf(_AM_SYSTEM_MENUS_EDITCAT);
+
+ $form = new XoopsThemeForm($title, 'form', $action, 'post', true);
+ $form->setExtra('enctype="multipart/form-data"');
+
+ if (!$this->isNew()) {
+ $form->addElement(new XoopsFormHidden('category_id', $this->getVar('category_id')));
+ $position = $this->getVar('category_position');
+ $active = $this->getVar('category_active');
+ } else {
+ $position = 0;
+ $active = 1;
+ }
+
+ // title
+ $form->addElement(new XoopsFormText(_AM_SYSTEM_MENUS_TITLE, 'category_title', 50, 255, $this->getVar('category_title')), true);
+
+ // url
+ $url = new XoopsFormText(_AM_SYSTEM_MENUS_URL, 'category_url', 50, 255, $this->getVar('category_url'));
+ $url->setDescription(_AM_SYSTEM_MENUS_URLDESC);
+ $form->addElement($url, false);
+
+ // position
+ $form->addElement(new XoopsFormText(_AM_SYSTEM_MENUS_POSITION, 'category_position', 5, 5, $position));
+
+ // actif
+ $radio = new XoopsFormRadio(_AM_SYSTEM_MENUS_ACTIVE, 'category_active', $active);
+ $radio->addOption(1, _YES);
+ $radio->addOption(0, _NO);
+ $form->addElement($radio);
+
+ $form->addElement(new XoopsFormHidden('op', 'save'));
+ // submit
+ $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
+
+ return $form;
+ }
+}
+class XoopsMenusCategoryHandler extends XoopsPersistableObjectHandler
+{
+
+ /**
+ * Constructor
+ *
+ * @param XoopsDatabase $db reference to a xoopsDB object
+ */
+ public function __construct($db)
+ {
+ // table short name, class name, key field, identifier field
+ parent::__construct($db, 'menuscategory', 'XoopsMenusCategory', 'category_id', 'category_title');
+ }
+}
\ No newline at end of file
diff --git a/htdocs/modules/system/admin/menus/index.php b/htdocs/modules/system/admin/menus/index.php
new file mode 100644
index 000000000..6a5054350
--- /dev/null
+++ b/htdocs/modules/system/admin/menus/index.php
@@ -0,0 +1,2 @@
+isAdmin($xoopsModule->mid())) {
+ exit(_NOPERM);
+}
+
+// Define main template
+$GLOBALS['xoopsOption']['template_main'] = 'system_menus.tpl';
+// Call Header
+xoops_cp_header();
+
+// Define Stylesheet
+$xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
+// Define scripts
+$xoTheme->addScript('modules/system/js/admin.js');
+// Define Breadcrumb and tips
+$xoBreadCrumb->addLink(_AM_SYSTEM_MENUS_NAV_MAIN, system_adminVersion('menus', 'adminpath'));
+$xoBreadCrumb->render();
+
+// Get Action type
+$op = Request::getCmd('op', 'list');
+$xoopsTpl->assign('op', $op);
+
+switch ($op) {
+ case 'list':
+ default:
+ echo "En conctruction ";
+ break;
+
+ case 'addcat':
+ // Form
+ $menuscategoryHandler = xoops_getHandler('menuscategory');
+ $obj = $menuscategoryHandler->create();
+ $form = $obj->getFormCat();
+ $xoopsTpl->assign('form', $form->render());
+ break;
+
+ case 'save':
+ if (!$GLOBALS['xoopsSecurity']->check()) {
+ redirect_header('admin.php?fct=menus', 3, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
+ }
+ $menuscategoryHandler = xoops_getHandler('menuscategory');
+ $id = Request::getInt('category_id', 0);
+ if ($id > 0) {
+ $obj = $menuscategoryHandler->get($id);
+ } else {
+ $obj = $menuscategoryHandler->create();
+ }
+ $obj->setVar('category_title', Request::getString('category_title', ''));
+ $obj->setVar('category_position', Request::getInt('category_position', 0));
+ $obj->setVar('category_active', Request::getInt('category_active', 1));
+ var_dump($obj);
+ if ($menuscategoryHandler->insert($obj)) {
+ redirect_header('admin.php?fct=menus', 2, _AM_SYSTEM_DBUPDATED);
+ } else {
+ echo $obj->getHtmlErrors();
+ }
+ break;
+
+}
+
+
+// Call Footer
+xoops_cp_footer();
\ No newline at end of file
diff --git a/htdocs/modules/system/admin/menus/xoops_version.php b/htdocs/modules/system/admin/menus/xoops_version.php
new file mode 100644
index 000000000..af2dfccd7
--- /dev/null
+++ b/htdocs/modules/system/admin/menus/xoops_version.php
@@ -0,0 +1,35 @@
+ _AM_SYSTEM_MENUS,
+ 'version' => '1.0',
+ 'description' => _AM_SYSTEM_MENUS_DESC,
+ 'author' => '',
+ 'credits' => 'XOOPS Development Team, Grégory Mage (AKA GregMage)',
+ 'help' => 'page=menus',
+ 'license' => 'GPL see LICENSE',
+ 'official' => 1,
+ 'image' => 'edituser.png',
+ 'icon' => 'fa fa-bars',
+ 'hasAdmin' => 1,
+ 'adminpath' => 'admin.php?fct=menus',
+ 'category' => XOOPS_SYSTEM_MENUS,
+ ];
\ No newline at end of file
diff --git a/htdocs/modules/system/admin/modulesadmin/modulesadmin.php b/htdocs/modules/system/admin/modulesadmin/modulesadmin.php
index a1c892298..362899014 100644
--- a/htdocs/modules/system/admin/modulesadmin/modulesadmin.php
+++ b/htdocs/modules/system/admin/modulesadmin/modulesadmin.php
@@ -68,6 +68,8 @@ function xoops_module_install($dirname)
'banner',
'bannerclient',
'bannerfinish',
+ 'menuscategory',
+ 'menusitems',
];
/** @var XoopsModuleHandler $module_handler */
$module_handler = xoops_getHandler('module');
diff --git a/htdocs/modules/system/constants.php b/htdocs/modules/system/constants.php
index 8410fc913..406beaf85 100644
--- a/htdocs/modules/system/constants.php
+++ b/htdocs/modules/system/constants.php
@@ -34,6 +34,7 @@
define('XOOPS_SYSTEM_FILEMANAGER', 16);
define('XOOPS_SYSTEM_MAINTENANCE', 17);
define("XOOPS_SYSTEM_THEME1", 18);
+define("XOOPS_SYSTEM_MENUS", 19);
// Configuration Category
define('SYSTEM_CAT_MAIN', 0);
define('SYSTEM_CAT_USER', 1);
diff --git a/htdocs/modules/system/include/update.php b/htdocs/modules/system/include/update.php
index f1e02fbdd..d89f63596 100644
--- a/htdocs/modules/system/include/update.php
+++ b/htdocs/modules/system/include/update.php
@@ -25,6 +25,29 @@
*/
function xoops_module_update_system(XoopsModule $module, $prev_version = null)
{
+ global $xoopsDB;
+ if ($prev_version < '2.2.0') {
+ //$db = XoopsDatabaseFactory::getDatabaseConnection();
+ $sql = "CREATE TABLE " . $xoopsDB->prefix('') . "_menuscategory (
+ category_id INT AUTO_INCREMENT PRIMARY KEY,
+ category_title VARCHAR(100) NOT NULL,
+ category_url VARCHAR(255) NULL,
+ category_position INT DEFAULT 0,
+ category_active TINYINT(1) DEFAULT 1);";
+ $xoopsDB->query($sql);
+ $sql = "CREATE TABLE " . $xoopsDB->prefix('') . "_menusitems (
+ items_id INT AUTO_INCREMENT PRIMARY KEY,
+ items_pid INT NULL,
+ items_cid INT NULL,
+ items_title VARCHAR(100) NOT NULL,
+ items_url VARCHAR(255) NULL,
+ items_position INT DEFAULT 0,
+ items_active TINYINT(1) DEFAULT 1,
+ FOREIGN KEY (items_cid) REFERENCES menuscategory(category_id) ON DELETE CASCADE,
+ FOREIGN KEY (items_pid) REFERENCES menusitems(items_id) ON DELETE CASCADE);";
+ $xoopsDB->query($sql);
+ }
+
// irmtfan bug fix: solve templates duplicate issue
$ret = null;
if ($prev_version < '2.1.1') {
diff --git a/htdocs/modules/system/language/english/admin.php b/htdocs/modules/system/language/english/admin.php
index 77c39a070..119a720c7 100644
--- a/htdocs/modules/system/language/english/admin.php
+++ b/htdocs/modules/system/language/english/admin.php
@@ -74,3 +74,8 @@
//2.5.7
define('_AM_SYSTEM_USAGE', 'Usage');
define('_AM_SYSTEM_ACTIVE', 'Active');
+
+
+//2.7.0
+define('_AM_SYSTEM_MENUS', 'Menus');
+define('_AM_SYSTEM_MENUS_DESC', 'Menu manager');
\ No newline at end of file
diff --git a/htdocs/modules/system/language/english/admin/menus.php b/htdocs/modules/system/language/english/admin/menus.php
new file mode 100644
index 000000000..5df896f68
--- /dev/null
+++ b/htdocs/modules/system/language/english/admin/menus.php
@@ -0,0 +1,17 @@
+
+Manage Xoops menus
+');
+// Main
+define('_AM_SYSTEM_MENUS_', '');
\ No newline at end of file
diff --git a/htdocs/modules/system/language/english/menu.php b/htdocs/modules/system/language/english/menu.php
index 521ce0b6e..b1b5d97de 100644
--- a/htdocs/modules/system/language/english/menu.php
+++ b/htdocs/modules/system/language/english/menu.php
@@ -36,4 +36,14 @@
define('_AM_BACKUP_RESTORE', 'Backup & Restore');
define('_AM_SYSTEM_LOGS', 'System Logs');
-define('_AM_PERFORMANCE_MONITOR', 'Performance Monitoring');
\ No newline at end of file
+define('_AM_PERFORMANCE_MONITOR', 'Performance Monitoring');
+
+// Xoops 2.7
+define('_AM_SYSTEM_MENUS_ADDCAT', 'Add Category');
+define('_AM_SYSTEM_MENUS_EDITCAT', 'Edit Category');
+define('_AM_SYSTEM_MENUS_LISTCAT', 'List Categories');
+define('_AM_SYSTEM_MENUS_TITLE', 'Name of the menu category');
+define('_AM_SYSTEM_MENUS_URL', 'URL of the menu category');
+define('_AM_SYSTEM_MENUS_URLDESC', 'Optional — Only if you want the category title to be a link.');
+define('_AM_SYSTEM_MENUS_POSITION', 'Position of the menu category');
+define('_AM_SYSTEM_MENUS_ACTIVE', 'Active');
diff --git a/htdocs/modules/system/templates/admin/system_menus.tpl b/htdocs/modules/system/templates/admin/system_menus.tpl
new file mode 100644
index 000000000..4a5a9efa3
--- /dev/null
+++ b/htdocs/modules/system/templates/admin/system_menus.tpl
@@ -0,0 +1,25 @@
+<{include file="db:system_header.tpl"}>
+
+
+
+
+
+ <{$form|default:''}>
+
\ No newline at end of file
diff --git a/htdocs/modules/system/xoops_version.php b/htdocs/modules/system/xoops_version.php
index 061b366cf..56593a854 100644
--- a/htdocs/modules/system/xoops_version.php
+++ b/htdocs/modules/system/xoops_version.php
@@ -19,10 +19,10 @@
xoops_loadLanguage('modinfo', 'system');
$modversion['name'] = _MI_SYSTEM_NAME;
-$modversion['version'] = '2.1.7-Stable';
+$modversion['version'] = '2.2.0-Alpha1';
$modversion['description'] = _MI_SYSTEM_DESC;
$modversion['author'] = '';
-$modversion['credits'] = 'The XOOPS Project; MusS, Kraven30, Mage';
+$modversion['credits'] = 'The XOOPS Project; MusS, Kraven30, GregMage';
$modversion['help'] = 'system.tpl';
$modversion['license'] = 'GPL see LICENSE';
$modversion['official'] = 1;
@@ -111,6 +111,7 @@
$modversion['templates'][] = ['file' => 'system_index.tpl', 'description' => '', 'type' => 'admin'];
$modversion['templates'][] = ['file' => 'system_maintenance.tpl', 'description' => '', 'type' => 'admin'];
$modversion['templates'][] = ['file' => 'system_help.tpl', 'description' => '', 'type' => 'admin'];
+$modversion['templates'][] = ['file' => 'system_menus.tpl', 'description' => '', 'type' => 'admin'];
// Admin Modules
$modversion['templates'][] = ['file' => 'system_modules_menu.tpl', 'description' => '', 'type' => 'module'];
From f2b8edeb2a996a0bfee7605ebe5d9df39e6e0ea7 Mon Sep 17 00:00:00 2001
From: GregMage
Date: Mon, 29 Sep 2025 17:47:47 +0200
Subject: [PATCH 02/71] Optimisation category menu
---
htdocs/kernel/menuscategory.php | 2 +-
htdocs/modules/system/admin/menus/main.php | 148 ++++++++++++++++--
.../modules/system/language/english/menu.php | 4 +
.../system/templates/admin/system_menus.tpl | 106 ++++++++++++-
4 files changed, 240 insertions(+), 20 deletions(-)
diff --git a/htdocs/kernel/menuscategory.php b/htdocs/kernel/menuscategory.php
index bcf6b2fa8..9bc2236eb 100644
--- a/htdocs/kernel/menuscategory.php
+++ b/htdocs/kernel/menuscategory.php
@@ -76,7 +76,7 @@ public function getFormCat($action = false)
$radio->addOption(0, _NO);
$form->addElement($radio);
- $form->addElement(new XoopsFormHidden('op', 'save'));
+ $form->addElement(new XoopsFormHidden('op', 'savecat'));
// submit
$form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
diff --git a/htdocs/modules/system/admin/menus/main.php b/htdocs/modules/system/admin/menus/main.php
index 158477e1f..a6e85e507 100644
--- a/htdocs/modules/system/admin/menus/main.php
+++ b/htdocs/modules/system/admin/menus/main.php
@@ -19,6 +19,7 @@
*/
use Xmf\Request;
+use Xmf\Module\Helper;
// Check users rights
if (!is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid())) {
@@ -27,25 +28,65 @@
// Define main template
$GLOBALS['xoopsOption']['template_main'] = 'system_menus.tpl';
-// Call Header
-xoops_cp_header();
-
-// Define Stylesheet
-$xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
-// Define scripts
-$xoTheme->addScript('modules/system/js/admin.js');
-// Define Breadcrumb and tips
-$xoBreadCrumb->addLink(_AM_SYSTEM_MENUS_NAV_MAIN, system_adminVersion('menus', 'adminpath'));
-$xoBreadCrumb->render();
// Get Action type
$op = Request::getCmd('op', 'list');
-$xoopsTpl->assign('op', $op);
+
+// Call Header
+if ($op !== 'saveorder') {
+ xoops_cp_header();
+ $xoopsTpl->assign('op', $op);
+ $xoopsTpl->assign('xoops_token', $GLOBALS['xoopsSecurity']->getTokenHTML());
+
+ // Define Stylesheet
+ $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
+ // Define scripts
+ $xoTheme->addScript('modules/system/js/admin.js');
+ // Define Breadcrumb and tips
+ $xoBreadCrumb->addLink(_AM_SYSTEM_MENUS_NAV_MAIN, system_adminVersion('menus', 'adminpath'));
+ $xoBreadCrumb->render();
+}
+
+
+
+
+$helper = Helper::getHelper('system');
+$nb_limit = $helper->getConfig('avatars_pager', 15);
switch ($op) {
case 'list':
default:
- echo "En conctruction ";
+ $start = Request::getInt('start', 0);
+ /** @var \XoopsPersistableObjectHandler $menuscategoryHandler */
+ $menuscategoryHandler = xoops_getHandler('menuscategory');
+ $criteria = new CriteriaCompo();
+ $criteria->setSort('category_position');
+ $criteria->setOrder('ASC');
+ $criteria->setStart($start);
+ $criteria->setLimit($nb_limit);
+ $category_arr = $menuscategoryHandler->getall($criteria);
+ $category_count = $menuscategoryHandler->getCount($criteria);
+ $xoopsTpl->assign('category_count', $category_count);
+ if ($category_count > 0) {
+ foreach (array_keys($category_arr) as $i) {
+ $category = array();
+ $category['id'] = $category_arr[$i]->getVar('category_id');
+ $category['title'] = $category_arr[$i]->getVar('category_title');
+ $category['url'] = $category_arr[$i]->getVar('category_url');
+ $category['position'] = $category_arr[$i]->getVar('category_position');
+ $category['active'] = $category_arr[$i]->getVar('category_active');
+ $category_img = $category_arr[$i]->getVar('category_logo');
+ $xoopsTpl->append('category', $category);
+ unset($category);
+ }
+ // Display Page Navigation
+ if ($category_count > $nb_limit) {
+ $nav = new XoopsPageNav($category_count, $nb_limit, $start, 'start');
+ $xoopsTpl->assign('nav_menu', $nav->renderNav(4));
+ }
+ } else {
+ $xoopsTpl->assign('error_message', _AM_SYSTEM_MENUS_ERROR_NOCATEGORY);
+ }
break;
case 'addcat':
@@ -56,7 +97,21 @@
$xoopsTpl->assign('form', $form->render());
break;
- case 'save':
+ case 'editcat':
+ // Form
+ $category_id = Request::getInt('category_id', 0);
+ if ($category_id == 0) {
+ $xoopsTpl->assign('error_message', _AM_SYSTEM_MENUS_ERROR_NOCATEGORY);
+ } else {
+ $menuscategoryHandler = xoops_getHandler('menuscategory');
+ $obj = $menuscategoryHandler->create();
+ $obj = $menuscategoryHandler->get($category_id);
+ $form = $obj->getFormCat();
+ $xoopsTpl->assign('form', $form->render());
+ }
+ break;
+
+ case 'savecat':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=menus', 3, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
@@ -68,9 +123,9 @@
$obj = $menuscategoryHandler->create();
}
$obj->setVar('category_title', Request::getString('category_title', ''));
+ $obj->setVar('category_url', Request::getString('category_url', ''));
$obj->setVar('category_position', Request::getInt('category_position', 0));
$obj->setVar('category_active', Request::getInt('category_active', 1));
- var_dump($obj);
if ($menuscategoryHandler->insert($obj)) {
redirect_header('admin.php?fct=menus', 2, _AM_SYSTEM_DBUPDATED);
} else {
@@ -78,8 +133,67 @@
}
break;
-}
+ case 'saveorder':
+ // Pour les réponses AJAX : désactiver le logger et vider les buffers
+ if (isset($GLOBALS['xoopsLogger']) && is_object($GLOBALS['xoopsLogger'])) {
+ $GLOBALS['xoopsLogger']->activated = false;
+ }
+ while (ob_get_level()) {
+ @ob_end_clean();
+ }
+ // vérifie le token
+ if (!$GLOBALS['xoopsSecurity']->check()) {
+ // debug: renvoyer les erreurs et ce qui a été reçu (retirer en production)
+ header('Content-Type: application/json');
+ $errors = $GLOBALS['xoopsSecurity']->getErrors();
+ echo json_encode([
+ 'success' => false,
+ 'message' => implode(' ', $errors),
+ 'token' => $GLOBALS['xoopsSecurity']->getTokenHTML(),
+ 'received_post' => $_POST,
+ 'received_raw' => file_get_contents('php://input')
+ ]);
+ exit;
+ }
+
+ $order = Request::getArray('order', []);
+ if (!is_array($order) || count($order) === 0) {
+ header('Content-Type: application/json');
+ echo json_encode(['success' => false, 'message' => 'No order provided', 'token' => $GLOBALS['xoopsSecurity']->getTokenHTML()]);
+ exit;
+ }
+ $menuscategoryHandler = xoops_getHandler('menuscategory');
+ if (!is_object($menuscategoryHandler) && class_exists('XoopsMenusCategoryHandler')) {
+ $menuscategoryHandler = new XoopsMenusCategoryHandler($GLOBALS['xoopsDB']);
+ }
+
+ $pos = 1;
+ $errors = [];
+ foreach ($order as $id) {
+ $id = (int)$id;
+ if ($id <= 0) continue;
+ $obj = $menuscategoryHandler->get($id);
+ if (is_object($obj)) {
+ $obj->setVar('category_position', $pos);
+ if (!$menuscategoryHandler->insert($obj, true)) {
+ $errors[] = "Failed to update id {$id}";
+ }
+ } else {
+ $errors[] = "Not found id {$id}";
+ }
+ $pos++;
+ }
-// Call Footer
-xoops_cp_footer();
\ No newline at end of file
+ header('Content-Type: application/json');
+ if (empty($errors)) {
+ echo json_encode(['success' => true, 'token' => $GLOBALS['xoopsSecurity']->getTokenHTML()]);
+ } else {
+ echo json_encode(['success' => false, 'message' => implode('; ', $errors), 'token' => $GLOBALS['xoopsSecurity']->getTokenHTML()]);
+ }
+ exit;
+}
+if ($op !== 'saveorder') {
+ // Call Footer
+ xoops_cp_footer();
+}
\ No newline at end of file
diff --git a/htdocs/modules/system/language/english/menu.php b/htdocs/modules/system/language/english/menu.php
index b1b5d97de..3d4ee9bb3 100644
--- a/htdocs/modules/system/language/english/menu.php
+++ b/htdocs/modules/system/language/english/menu.php
@@ -47,3 +47,7 @@
define('_AM_SYSTEM_MENUS_URLDESC', 'Optional — Only if you want the category title to be a link.');
define('_AM_SYSTEM_MENUS_POSITION', 'Position of the menu category');
define('_AM_SYSTEM_MENUS_ACTIVE', 'Active');
+define('_AM_SYSTEM_MENUS_ACTIVE_YES', 'Enabled');
+define('_AM_SYSTEM_MENUS_ACTIVE_NO', 'Disabled');
+define('_AM_SYSTEM_MENUS_ERROR_NOCATEGORY', 'There are no menu categories. You must create one before adding menus.');
+
diff --git a/htdocs/modules/system/templates/admin/system_menus.tpl b/htdocs/modules/system/templates/admin/system_menus.tpl
index 4a5a9efa3..b93640621 100644
--- a/htdocs/modules/system/templates/admin/system_menus.tpl
+++ b/htdocs/modules/system/templates/admin/system_menus.tpl
@@ -10,7 +10,7 @@
<{$smarty.const._AM_SYSTEM_MENUS_ADDCAT}>
<{/if}>
- <{if $op == 'addcat'}>
+ <{if $op == 'addcat' || $op == 'editcat'}>
<{/if}>
+ <{if $op == 'viewcat'}>
+
+ <{/if}>
+ <{if $op == 'additem' || $op == 'edititem'}>
+
+
+ <{$smarty.const._AM_SYSTEM_MENUS_LISTITEM}>
+
+ <{/if}>
@@ -57,6 +71,9 @@
+
+
+
@@ -122,7 +139,34 @@
});
<{/literal}>
-
+<{/if}>
+<{if $op|default:'' == viewcat}>
+
+
+
+
+ <{if $cat_url|default:'' != ''}>
+
+ <{$cat_url}>
+
+ <{/if}>
+
+ <{if $cat_active}>
+ <{$smarty.const._AM_SYSTEM_MENUS_ACTIVE_YES}>
+ <{else}>
+ <{$smarty.const._AM_SYSTEM_MENUS_ACTIVE_NO}>
+ <{/if}>
+
+
+
+
<{/if}>
From d6f89ba337e8eb85acd6ba9a1d52a7bb3dd12716 Mon Sep 17 00:00:00 2001
From: GregMage
Date: Fri, 3 Oct 2025 18:18:14 +0200
Subject: [PATCH 05/71] =?UTF-8?q?pr=C3=A9paration=20de=20la=20gestion=20de?=
=?UTF-8?q?s=20sous-menus?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
htdocs/modules/system/admin/menus/main.php | 57 +++++++++++++++--
.../system/templates/admin/system_menus.tpl | 63 +++++++++++++------
2 files changed, 97 insertions(+), 23 deletions(-)
diff --git a/htdocs/modules/system/admin/menus/main.php b/htdocs/modules/system/admin/menus/main.php
index bc7a2cec6..9d96c7b6b 100644
--- a/htdocs/modules/system/admin/menus/main.php
+++ b/htdocs/modules/system/admin/menus/main.php
@@ -33,7 +33,7 @@
$op = Request::getCmd('op', 'list');
// Call Header
-if ($op !== 'saveorder') {
+if ($op !== 'saveorder' && $op !== 'toggleactive') {
xoops_cp_header();
$xoopsTpl->assign('op', $op);
$xoopsTpl->assign('xoops_token', $GLOBALS['xoopsSecurity']->getTokenHTML());
@@ -207,8 +207,6 @@
$category = $menuscategoryHandler->get($category_id);
$xoopsTpl->assign('cat_id', $category->getVar('category_id'));
$xoopsTpl->assign('cat_title', $category->getVar('category_title'));
- $xoopsTpl->assign('cat_url', $category->getVar('category_url'));
- $xoopsTpl->assign('cat_active', $category->getVar('category_active'));
}
break;
@@ -249,8 +247,59 @@
echo $obj->getHtmlErrors();
}
break;
+
+ case 'toggleactive':
+ // Pour les réponses AJAX : désactiver le logger et vider les buffers
+ if (isset($GLOBALS['xoopsLogger']) && is_object($GLOBALS['xoopsLogger'])) {
+ $GLOBALS['xoopsLogger']->activated = false;
+ }
+ while (ob_get_level()) {
+ @ob_end_clean();
+ }
+ // Vérifier token
+ if (!$GLOBALS['xoopsSecurity']->check()) {
+ header('Content-Type: application/json');
+ echo json_encode([
+ 'success' => false,
+ 'message' => implode(' ', $GLOBALS['xoopsSecurity']->getErrors()),
+ 'token' => $GLOBALS['xoopsSecurity']->getTokenHTML()
+ ]);
+ exit;
+ }
+
+ $category_id = Request::getInt('category_id', 0);
+ if ($category_id <= 0) {
+ header('Content-Type: application/json');
+ echo json_encode(['success' => false, 'message' => 'Invalid id', 'token' => $GLOBALS['xoopsSecurity']->getTokenHTML()]);
+ exit;
+ }
+
+ $menuscategoryHandler = xoops_getHandler('menuscategory');
+ if (!is_object($menuscategoryHandler) && class_exists('XoopsMenusCategoryHandler')) {
+ $menuscategoryHandler = new XoopsMenusCategoryHandler($GLOBALS['xoopsDB']);
+ }
+
+ $obj = $menuscategoryHandler->get($category_id);
+ if (!is_object($obj)) {
+ header('Content-Type: application/json');
+ echo json_encode(['success' => false, 'message' => 'Not found', 'token' => $GLOBALS['xoopsSecurity']->getTokenHTML()]);
+ exit;
+ }
+ $new = $obj->getVar('category_active') ? 0 : 1;
+ $obj->setVar('category_active', $new);
+ $res = $menuscategoryHandler->insert($obj, true);
+
+ header('Content-Type: application/json');
+ if ($res) {
+ echo json_encode(['success' => true, 'active' => (int)$new, 'token' => $GLOBALS['xoopsSecurity']->getTokenHTML()]);
+ } else {
+ echo json_encode(['success' => false, 'message' => 'Save failed', 'token' => $GLOBALS['xoopsSecurity']->getTokenHTML()]);
+ }
+ exit;
+ break;
+
}
-if ($op !== 'saveorder') {
+if ($op !== 'saveorder' && $op !== 'toggleactive') {
// Call Footer
xoops_cp_footer();
}
\ No newline at end of file
diff --git a/htdocs/modules/system/templates/admin/system_menus.tpl b/htdocs/modules/system/templates/admin/system_menus.tpl
index 2103d087c..b3e3bcef8 100644
--- a/htdocs/modules/system/templates/admin/system_menus.tpl
+++ b/htdocs/modules/system/templates/admin/system_menus.tpl
@@ -59,11 +59,15 @@
<{/if}>
- <{if $itemcategory.active}>
- <{$smarty.const._AM_SYSTEM_MENUS_ACTIVE_YES}>
- <{else}>
- <{$smarty.const._AM_SYSTEM_MENUS_ACTIVE_NO}>
- <{/if}>
+ <{if $itemcategory.active}>
+
+ <{$smarty.const._AM_SYSTEM_MENUS_ACTIVE_YES}>
+
+ <{else}>
+
+ <{$smarty.const._AM_SYSTEM_MENUS_ACTIVE_NO}>
+
+ <{/if}>
#<{$cat_id}>
-
- <{if $cat_url|default:'' != ''}>
-
- <{$cat_url}>
-
- <{/if}>
-
- <{if $cat_active}>
- <{$smarty.const._AM_SYSTEM_MENUS_ACTIVE_YES}>
- <{else}>
- <{$smarty.const._AM_SYSTEM_MENUS_ACTIVE_NO}>
- <{/if}>
-
-
<{/if}>
From b07fbc5df9670dbf7031b9fd80ab88fde6901f24 Mon Sep 17 00:00:00 2001
From: GregMage
Date: Sun, 5 Oct 2025 17:39:05 +0200
Subject: [PATCH 06/71] affichage des menus dans l'admin
---
htdocs/kernel/menusitems.php | 2 +-
htdocs/modules/system/admin/menus/main.php | 24 ++++++
.../modules/system/class/SystemMenusTree.php | 83 +++++++++++++++++++
.../system/templates/admin/system_menus.tpl | 35 +++++++-
4 files changed, 139 insertions(+), 5 deletions(-)
create mode 100644 htdocs/modules/system/class/SystemMenusTree.php
diff --git a/htdocs/kernel/menusitems.php b/htdocs/kernel/menusitems.php
index 0a741a93c..23f6e35dd 100644
--- a/htdocs/kernel/menusitems.php
+++ b/htdocs/kernel/menusitems.php
@@ -84,7 +84,7 @@ public function getFormItems($category_id, $action = false)
$form->addElement(new XoopsFormText(_AM_SYSTEM_MENUS_TITLEITEM, 'items_title', 50, 255, $this->getVar('category_title')), true);
// url
- $form->addElement(new XoopsFormText(_AM_SYSTEM_MENUS_URLITEM, 'items_url', 50, 255, $this->getVar('category_url')), true);
+ $form->addElement(new XoopsFormText(_AM_SYSTEM_MENUS_URLITEM, 'items_url', 50, 255, $this->getVar('category_url')), false);
// position
$form->addElement(new XoopsFormText(_AM_SYSTEM_MENUS_POSITIONITEM, 'items_position', 5, 5, $position));
diff --git a/htdocs/modules/system/admin/menus/main.php b/htdocs/modules/system/admin/menus/main.php
index 9d96c7b6b..d782ec0fa 100644
--- a/htdocs/modules/system/admin/menus/main.php
+++ b/htdocs/modules/system/admin/menus/main.php
@@ -207,6 +207,30 @@
$category = $menuscategoryHandler->get($category_id);
$xoopsTpl->assign('cat_id', $category->getVar('category_id'));
$xoopsTpl->assign('cat_title', $category->getVar('category_title'));
+
+ $menusitemsHandler = xoops_getHandler('menusitems');
+ $criteria = new CriteriaCompo();
+ $criteria->add(new Criteria('items_cid', $category_id));
+ $criteria->setSort('items_position ASC, items_title');
+ $criteria->setOrder('ASC');
+ $items_arr = $menusitemsHandler->getall($criteria);
+ $items_count = $menusitemsHandler->getCount($criteria);
+ $xoopsTpl->assign('items_count', $items_count);
+ xoops_load('SystemMenusTree', 'system');
+ $myTree = new SystemMenusTree($items_arr, 'items_id', 'items_pid');
+ $tree_arr = $myTree->makeTree('article_name', '--', 0);
+ if ($items_count > 0) {
+ foreach (array_keys($tree_arr) as $i) {
+ $items = array();
+ $items['id'] = $tree_arr[$i]['obj']->getVar('items_id');
+ $items['title'] = $tree_arr[$i]['obj']->getVar('items_title');
+ $items['url'] = $tree_arr[$i]['obj']->getVar('items_url');
+ $items['active'] = $tree_arr[$i]['obj']->getVar('items_active');
+ $items['level'] = ($tree_arr[$i]['level'] - 1);
+ $xoopsTpl->append('items', $items);
+ unset($items);
+ }
+ }
}
break;
diff --git a/htdocs/modules/system/class/SystemMenusTree.php b/htdocs/modules/system/class/SystemMenusTree.php
new file mode 100644
index 000000000..d1348ffd0
--- /dev/null
+++ b/htdocs/modules/system/class/SystemMenusTree.php
@@ -0,0 +1,83 @@
+path('class/tree.php');
+
+/**
+ * SystemMenusTree : extension utilitaire de XoopsObjectTree pour menus
+ */
+class SystemMenusTree extends XoopsObjectTree
+{
+ /**
+ * @access private
+ */
+ protected $listTree = array();
+ protected $cpt;
+
+ /**
+ * Constructor
+ *
+ * @param array $objectArr Array of {@link XoopsObject}s
+ * @param string $myId field name of object ID
+ * @param string $parentId field name of parent object ID
+ * @param string $rootId field name of root object ID
+ */
+ public function __construct(&$objectArr, $myId, $parentId, $rootId = null)
+ {
+ $this->cpt = 0;
+ parent::__construct($objectArr, $myId, $parentId, $rootId);
+ }
+
+ /**
+ * Make a select box with options from the tree
+ *
+ * @param string $fieldName Name of the member variable from the
+ * node objects that should be used as the title for the options.
+ * @param string $prefix String to indent deeper levels
+ *
+ * @return array $listTree Tree
+ */
+ public function makeTree(
+ $fieldName,
+ $prefix = '-',
+ $productid = 0
+ ) {
+ $this->addTree($fieldName, $productid, 0, $prefix);
+
+ return $this->listTree;
+ }
+
+ /**
+ * Make options for a select box from
+ *
+ * @param string $fieldName Name of the member variable from the node objects that
+ * should be used as the title for the options.
+ * @param int $key ID of the object to display as the root of select options
+ * @param string $prefix_orig String to indent items at deeper levels
+ * @param string $prefix_curr String to indent the current item
+ *
+ * @return void
+ * @access private
+ */
+ protected function addTree($fieldName, $productid, $key, $prefix_orig, $prefix_curr = '', $level = 1)
+ {
+ if ($key > 0) {
+ if (($productid == $this->tree[$key]['obj']->getVar('nomenclature_productid')) || $productid == 0) {
+ $value = $this->tree[$key]['obj']->getVar('nomenclature_id');
+ $name = $prefix_curr . ' ' . $this->tree[$key]['obj']->getVar($fieldName);
+ $prefix_curr .= $prefix_orig;
+ $this->listTree[$this->cpt]['name'] = $name;
+ $this->listTree[$this->cpt]['id'] = $value;
+ $this->listTree[$this->cpt]['level'] = $level;
+ $this->listTree[$this->cpt]['obj'] = $this->tree[$key]['obj'];
+ $this->cpt++;
+ $level++;
+ }
+ }
+ if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) {
+ foreach ($this->tree[$key]['child'] as $childKey) {
+ $this->addTree($fieldName, $productid, $childKey, $prefix_orig, $prefix_curr, $level);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/htdocs/modules/system/templates/admin/system_menus.tpl b/htdocs/modules/system/templates/admin/system_menus.tpl
index b3e3bcef8..1026483d9 100644
--- a/htdocs/modules/system/templates/admin/system_menus.tpl
+++ b/htdocs/modules/system/templates/admin/system_menus.tpl
@@ -35,9 +35,9 @@
<{if $error_message|default:'' != ''}>
-
- <{$error_message}>
-
+
+ <{$error_message}>
+
<{/if}>
<{if $category_count|default:0 != 0}>