Source for file menumaint-defs.php

Documentation is available at menumaint-defs.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: menumaint-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Definitions for maintenance of menus. Menu structure is */
  24. /* stored in the Axyl database in the ax_menu and the */
  25. /* ax_menuoption tables. This module contains classes */
  26. /* which allow this to be maintained via web forms. */
  27. /* */
  28. /* ******************************************************************** */
  29. /** @package menu */
  30. include_once("menu-defs.php");
  31.  
  32. // ......................................................................
  33. /** Create new menuoption */
  34. ("NEW_MENUOPTION", -1);
  35.  
  36. // ......................................................................
  37. /**
  38. * Menu Maintainer
  39. * @package menu
  40. */
  41. class menumaintainer extends HTMLObject {
  42. // Public
  43. /** The name of the menu */
  44.  
  45. var $menu_name = "";
  46. /** The language of the menu (0 = default) */
  47.  
  48. var $language = 0;
  49. /** The name of the language of the menu */
  50.  
  51. var $lang_desc = "default";
  52. /** The description of the menu */
  53.  
  54. var $menu_desc = "";
  55.  
  56. // Private
  57. /** The ID of the menu
  58. @access private */
  59. var $menu_id = false;
  60. /** Array of groups allowed to access menu
  61. @access private */
  62. var $user_groups = array();
  63. /** Menu active flag
  64. @access private */
  65. var $active = true;
  66. /** The parent ID of the menu-options being edited
  67. @access private */
  68. var $edit_parent_id = 0;
  69. /** The ID of the current menuoption being edited, if any
  70. @access private */
  71. var $edit_menuop_id;
  72. /** The level of the menu-options
  73. @access private */
  74. var $menu_level = 0;
  75. /** Whether this menu exists in the database
  76. @access private */
  77. var $exists = false;
  78. /** The array of menu options
  79. @access private */
  80. var $menuoptions = array();
  81. /** The name of our form
  82. @access private */
  83. var $formname = "";
  84. // ....................................................................
  85. /**
  86. * Constructor
  87. * Create a new menumaintainer.
  88. * @param string $id The unique name/identity of the menu.
  89. * @param integer $pid The optional id of a parent menuoption.
  90. * @param boolean $multilang If true, offer multi-language options
  91. */
  92. function menumaintainer($menuname="", $pid=0, $multilang=MULTILANG_DISABLED) {
  93. global $edit_parent_id, $sel_menu_id, $edit_menu_id, $menuopid;
  94. global $menumode, $menu_name, $language;
  95. global $RESPONSE;
  96.  
  97. // Mode
  98. if (isset($menumode)) $this->mode = $menumode;
  99. else $this->mode = "viewing";
  100.  
  101. // Initialise..
  102. $this->multilang = $multilang;
  103. $this->formname = "menufm";
  104.  
  105. // When you have one of these, you need this script..
  106. $RESPONSE->add_script(
  107. "function menugo(mode) {\n"
  108. . " var rc=true;\n"
  109. . " if(mode=='delete') {\n"
  110. . " var msg = \"WARNING:\\n\\n\";\n"
  111. . " msg+=\"Do you really want to delete this menu?\\n\\n\";\n"
  112. . " rc = confirm(msg);\n"
  113. . " }\n"
  114. . " if(rc) {\n"
  115. . " document.forms." . $this->formname . ".menumode.value=mode;\n"
  116. . " document.forms." . $this->formname . ".submit();\n"
  117. . " }\n"
  118. . "}\n"
  119. );
  120.  
  121. // Set up menu name..
  122. if ($menuname != "") {
  123. $this->menu_name = $menuname;
  124. }
  125. elseif (isset($menu_name)) {
  126. $this->menu_name = $menu_name;
  127. }
  128.  
  129. // Set up menu language..
  130. if ($this->multilang && isset($language)) {
  131. $this->language = $language;
  132. }
  133.  
  134. if ($this->mode != "createnew") {
  135. // Obtain a menu ID to work with..
  136. // A menu we are selecting..
  137. if (isset($sel_menu_id)) {
  138. $this->menu_id = $sel_menu_id;
  139. }
  140. // A menu we are editing currently..
  141. elseif (isset($edit_menu_id)) {
  142. $this->menu_id = $edit_menu_id;
  143. }
  144.  
  145. // A language we are selecting..
  146. // Save parent ID..
  147. if (isset($edit_parent_id)) {
  148. $this->edit_parent_id = $edit_parent_id;
  149. }
  150. else {
  151. $this->edit_parent_id = $pid;
  152. }
  153.  
  154. // Edit request overrides parent ID..
  155. if ($this->mode == "edit" && isset($menuopid)) {
  156. $m = new menuoption($menuopid);
  157. if ($m->exists) {
  158. $this->edit_parent_id = $m->parent_id;
  159. $this->edit_menuop_id = $menuopid;
  160. $this->mode = "editing";
  161. }
  162. }
  163. }
  164. // Process anything POSTed via form..
  165. $this->POSTprocess();
  166.  
  167. // Edit new, or get the existing menu..
  168. if ($this->mode != "createnew") {
  169. $this->get();
  170. }
  171.  
  172. } // menumaintainer
  173. // ....................................................................
  174. /**
  175. * Get the menu
  176. * Retrieves the specified menu from database. If it doesn't exist
  177. * then we create a new one.
  178. * @return boolean True if the record was acquired successfully
  179. */
  180. function get() {
  181. debug_trace($this);
  182. $this->exists = false;
  183.  
  184. // Two method of finding the menu - by ID and by Name/language..
  185. $qByName = "SELECT * FROM ax_menu m, ax_language l";
  186. $qByName .= " WHERE m.lang_id=$this->language";
  187. $qByName .= " AND l.lang_id=m.lang_id";
  188. if ($this->menu_name != "") {
  189. $qByName .= " AND menu_name='" . addslashes($this->menu_name) . "'";
  190. }
  191. $qByID = "SELECT * FROM ax_menu m, ax_language l";
  192. $qByID .= " WHERE m.menu_id=$this->menu_id";
  193. $qByID .= " AND l.lang_id=m.lang_id";
  194.  
  195. // Try and find it..
  196. $found = false;
  197. if ($this->menu_id != false) {
  198. $mnuQ = dbrecordset($qByID);
  199. $found = $mnuQ->hasdata;
  200. }
  201. // Fallback procedure..
  202. if (!$found) {
  203. $mnuQ = dbrecordset($qByName);
  204. }
  205. if ($mnuQ->hasdata) {
  206. $this->menu_id = $mnuQ->field("menu_id");
  207. $this->menu_name = $mnuQ->field("menu_name");
  208. $this->language = $mnuQ->field("lang_id");
  209. $this->lang_desc = $mnuQ->field("lang_desc");
  210. $this->menu_desc = $mnuQ->field("menu_desc");
  211. $this->user_groups = explode(",", $mnuQ->field("menu_user_groups"));
  212. $this->active = $mnuQ->istrue("active");
  213. $this->exists = true;
  214. $this->menu_level = 0;
  215.  
  216. // Get menuoptions as required..
  217. $q = "SELECT *";
  218. $q .= " FROM ax_menuoption";
  219. $q .= " WHERE menu_id=$this->menu_id";
  220. if ($this->edit_parent_id > 0) {
  221. $q .= " AND parent_id=$this->edit_parent_id";
  222. }
  223. else {
  224. $q .= " AND menu_level=0";
  225. }
  226. $q .= " ORDER BY display_order";
  227. $mnuQ = dbrecordset($q);
  228. if ($mnuQ->hasdata) {
  229. do {
  230. $menuoptionid = $mnuQ->field("menuoption_id");
  231. $menuoption = new menuoption();
  232. $menuoption->menu_id = $this->menu_id;
  233. $menuoption->menuoptionid = $menuoptionid;
  234. $menuoption->parent_id = $mnuQ->field("parent_id");
  235. $menuoption->user_groups = explode(",", $mnuQ->field("user_groups"));
  236. $menuoption->user_type = $mnuQ->field("user_type");
  237. $menuoption->menu_level = $mnuQ->field("menu_level");
  238. $menuoption->label = $mnuQ->field("label");
  239. $menuoption->description = $mnuQ->field("description");
  240. $menuoption->display_order = $mnuQ->field("display_order");
  241. $menuoption->action = $mnuQ->field("action");
  242. $menuoption->target = $mnuQ->field("target");
  243. $menuoption->sitepage = $mnuQ->field("sitepage");
  244. $menuoption->sitepage_parms = $mnuQ->field("sitepage_parms");
  245. $menuoption->auth_code = $mnuQ->istrue("auth_code");
  246. $menuoption->active = $mnuQ->istrue("active");
  247. $menuoption->last_modified = $mnuQ->field("last_modified");
  248. $menuoption->width = $mnuQ->field("width");
  249. $menuoption->height = $mnuQ->field("height");
  250. $menuoption->is_parent = $mnuQ->istrue("is_parent");
  251. $menuoption->exists = true;
  252. $menuoption->syncparms();
  253. // Stash menuoption..
  254. $this->menuoptions[$menuoptionid] = $menuoption;
  255. } while ($mnuQ->get_next());
  256. $this->menu_level = $menuoption->menu_level;
  257. }
  258. }
  259. debug_trace();
  260. // Return true if at least the menu exists..
  261. return $this->exists;
  262. } // get
  263. // ....................................................................
  264. /**
  265. * Save this menu to the database. Create a new one if it doesn't
  266. * already exist.
  267. */
  268. function put() {
  269. debug_trace($this);
  270. // Deal with brand new menu..
  271. if ($this->exists) {
  272. $mnuQ = new dbupdate("ax_menu");
  273. $mnuQ->where("menu_id=$this->menu_id");
  274. }
  275. else {
  276. $mnuQ = new dbinsert("ax_menu");
  277. $this->menu_id = get_next_sequencevalue("seq_menu_id", "ax_menu", "menu_id");
  278. $mnuQ->set("menu_id", $this->menu_id);
  279. }
  280. $mnuQ->set("menu_name", $this->menu_name);
  281. $mnuQ->set("menu_desc", $this->menu_desc);
  282. $mnuQ->set("menu_user_groups", implode(",", $this->user_groups));
  283. $mnuQ->set("active", $this->active);
  284. $mnuQ->set("last_modified", 'now()');
  285. $this->exists = $mnuQ->execute();
  286.  
  287. // Save any menuoptions..
  288. if (isset($this->menuoptions) && count($this->menuoptions) > 0) {
  289. foreach ($this->menuoptions as $menuoption) {
  290. $menuoption->put();
  291. } // foreach
  292. }
  293. debug_trace();
  294. } // put
  295. // ....................................................................
  296. /**
  297. * This adds a new menuoption to the list, but does not add any records
  298. * to the database.
  299. */
  300. function add_menuoption() {
  301. debug_trace($this);
  302. $menuoption = new menuoption();
  303. $menuoption->menu_id = $this->menu_id;
  304. $menuoption->menu_level = $this->menu_level;
  305. $menuoption->display_order = 999;
  306. $this->menuoptions[$menuoption->menuoptionid] = $menuoption;
  307. debug_trace();
  308. } // add_menuoption
  309. // ....................................................................
  310. /**
  311. * Remove menuoption from the menu. Just removes the given menuoption
  312. * from the list in this object - no database changes are made.
  313. * @param integer $id The id of the menuoption to remove
  314. */
  315. function remove_menuoption($id) {
  316. debug_trace($this);
  317. if (isset($this->menuoptions[$id])) {
  318. $menuoption->delete();
  319. unset($this->menuoptions[$id]);
  320. }
  321. debug_trace();
  322. } // remove_menuoption
  323. // ....................................................................
  324. /**
  325. * Delete this menu from the database.
  326. */
  327. function delete() {
  328. debug_trace($this);
  329. if ($this->exists) {
  330. // RI will delete the menuoptions of this menu..
  331. $del = new dbdelete("ax_menu");
  332. $del->where("menu_id=$this->menu_id");
  333. $del->execute();
  334. $this->menuoptions = array();
  335. }
  336. debug_trace();
  337. } // delete
  338. // ....................................................................
  339. /**
  340. * Render the menu editing suite.
  341. * @return string The HTML for the editing suite form etc.
  342. * @access private
  343. */
  344. function editform() {
  345. debug_trace($this);
  346. global $LIBDIR;
  347. global $RESPONSE;
  348.  
  349. // Width of large form elements..
  350. $ewidth = "300px";
  351. $pwidth = "110px";
  352.  
  353. // Generic combo for user groups..
  354. $cboGroups = new form_combofield();
  355. $cboGroups->multiselect = true;
  356. $cboGroups->setclass("axlistbox");
  357. $cboGroups->setstyle("width:$ewidth;");
  358. $cboGroups->set_size(4);
  359. $cboGroups->additem("", "Any");
  360. $gQ = dbrecordset("SELECT * FROM ax_group ORDER BY group_desc");
  361. $cboGroups->add_querydata($gQ, "group_desc", "group_desc");
  362.  
  363. // Generic combo for site pages..
  364. $cboWebPages = new form_combofield();
  365. $cboWebPages->setclass("axcombo");
  366. $cboWebPages->additem(MENU_ITEM_SUBMENU);
  367. $cboWebPages->additem(MENU_ITEM_SPACER);
  368. $cboWebPages->additem(MENU_ITEM_SEPARATOR);
  369. $cboWebPages->additem(MENU_ITEM_URL);
  370. $gQ = dbrecordset("SELECT * FROM ax_sitepage WHERE enabled=TRUE ORDER BY page_title");
  371. if ($gQ->hasdata) {
  372. do {
  373. $pgtitle = $gQ->field("page_title");
  374. $pgpath = $gQ->field("page_path");
  375. $pgfile = basename($pgpath);
  376. $cboWebPages->additem($pgpath, "$pgtitle ($pgfile)");
  377. } while ($gQ->get_next());
  378. }
  379.  
  380. // Initialise content..
  381. $s = "";
  382.  
  383. // ..................................................................
  384. // KEYFIELD and RECORD MAINTAINER
  385. // Menuoption listbox
  386. // Declared here so we can create the maintainer and register buttons
  387. // before they are used in the form.
  388. //
  389. // This is the keyfield listbox which controls the maintainance
  390. // process. It lists all records being maintained..
  391. $menuoption_listbox = new form_combofield("menuoption_id");
  392. $menuoption_listbox->setclass("axlistbox");
  393. // Make a new record maintainer, and attach the buttons..
  394. $maintainer = new recmaintainer($this->formname, $menuoption_listbox);
  395.  
  396. // Create buttons..
  397. $bup = new form_imagebutton("_up", "", "", "$LIBDIR/img/_up.gif", "Move up", 57, 15);
  398. $bdown = new form_imagebutton("_down", "", "", "$LIBDIR/img/_down.gif", "Move down", 57, 15);
  399. $bdel = new form_imagebutton("_del", "", "", "$LIBDIR/img/_delete.gif", "Delete menu option", 57, 15);
  400. $badd = new form_imagebutton("_add", "", "", "$LIBDIR/img/_add.gif", "Add new menu option", 57, 15);
  401. $bsave = new form_imagebutton("_save", "", "", "$LIBDIR/img/_save.gif", "Save menu settings", 57, 15);
  402. $bdone = new form_imagebutton("_done", "", "", "$LIBDIR/img/_done.gif", "Done with editing", 57, 15);
  403. $breset = new form_imagebutton("_reset", "", "", "$LIBDIR/img/_reset.gif", "Reset form", 57, 15);
  404. $btop = new form_imagebutton("_top", "", "", "$LIBDIR/img/_top.gif", "Top of menu tree", 57, 15);
  405. $bprev = new form_imagebutton("_prev", "", "", "$LIBDIR/img/_prev.gif", "Previous menu level", 57, 15);
  406. $bnext = new form_imagebutton("_next", "", "", "$LIBDIR/img/_next.gif", "Next sub-menu level", 57, 15);
  407. $bnewpg = new form_imagebutton("_newpg", "", "", "$LIBDIR/img/_create.gif", "Create new webpage", 57, 15);
  408. $breset->set_onclick("document.forms.$this->formname.reset()");
  409.  
  410. // Special handling for Next button
  411. $RESPONSE->add_script(
  412. "var rc=false;\n"
  413. . "function checkforsubmenu() {\n"
  414. . " fm = document.forms.$this->formname;\n"
  415. . " if (fm.menuoption_id != null && fm.menuoption_id.options.length != 0) {\n"
  416. . " if (fm.sitepage.value != '') {\n"
  417. . " alert('The current item is not a sub-menu.');\n"
  418. . " rc= false;\n"
  419. . " }\n"
  420. . " else rc = true;\n"
  421. . " }\n"
  422. . "}\n"
  423. );
  424. $bnext->set_onclick("checkforsubmenu();return rc;");
  425.  
  426. // Register all relevant buttons to the maintainer..
  427. $maintainer->register_button("up" , $bup);
  428. $maintainer->register_button("down", $bdown);
  429. $maintainer->register_button("add", $badd);
  430. $maintainer->register_button("save", $bsave);
  431. $maintainer->register_button("del", $bdel);
  432. $maintainer->register_button("reset", $breset);
  433.  
  434. // Control table..
  435. $Ted = new table("menu_$this->menu_id");
  436. $Ted->setpadding(2);
  437.  
  438. // ..................................................................
  439. // Toolbar..
  440. $toolbar[] = $bdone;
  441. $toolbar[] = $bsave;
  442. $Tbar = new table("toolbar");
  443. $Tbar->tr("axtitle");
  444. $Tbar->th("<b>EDITING</b> [$this->menu_id]", "axtitle");
  445. $tools = "";
  446. foreach ($toolbar as $button) {
  447. $tools .= $button->render();
  448. }
  449. $Tbar->th($tools, "text-align:right");
  450. $Ted->thead();
  451. $Ted->tr();
  452. $Ted->td( $Tbar->render() );
  453. $Ted->td_colspan(3);
  454.  
  455. // ..................................................................
  456. // Global Menu Properties..
  457. $Ted->tr("axhdg");
  458. $Ted->td("<b>MENU PROPERTIES</b>", "axhdg");
  459. $Ted->td_colspan(3);
  460.  
  461. // ..................................................................
  462. // Menu name & Active flag
  463. $menu_name = new form_textfield("menu_name", "", $this->menu_name);
  464. $menu_name->setstyle("width:$ewidth;");
  465. $menu_name->setclass("axtxtbox");
  466. $menu_active = new form_checkbox("menu_active");
  467. $menu_active->setclass("axchkbox");
  468. $menu_active->checked = $this->active;
  469. $Ted->tr("axbglite");
  470. $Ted->td("Menu name:", "axfg");
  471. $Ted->td( $menu_name->render() . "&nbsp;&nbsp;" . "Active:&nbsp;" . $menu_active->render(), "axfg" );
  472. $Ted->td_colspan(2);
  473.  
  474. // Multi-language selector..
  475. if ($this->multilang) {
  476. $cboLangs = new form_combofield("language");
  477. $cboLangs->setclass("axcombo");
  478. $cboLangs->setstyle("width:$ewidth;");
  479. $LQ = dbrecordset("SELECT * FROM ax_language ORDER BY display_order");
  480. $cboLangs->add_querydata($LQ, "lang_id", "lang_desc");
  481. $cboLangs->setvalue($this->language);
  482. // Insert this combo..
  483. $Ted->tr("axbglite");
  484. $Ted->td("Menu language:", "axfg");
  485. $Ted->td( $cboLangs->render() );
  486. $Ted->td_colspan(2);
  487. }
  488. else {
  489. $hidLang = new form_hiddenfield("language", $this->language);
  490. $Ted->tr("axbglite");
  491. $Ted->td( $hidLang->render() );
  492. $Ted->td_colspan(3);
  493. }
  494.  
  495. // Menu description
  496. $menu_desc = new form_textfield("menu_desc", "", $this->menu_desc);
  497. $menu_desc->setstyle("width:$ewidth;");
  498. $menu_desc->setclass("axtxtbox");
  499. $Ted->tr("axbgdark");
  500. $Ted->td("Description:", "axfg");
  501. $Ted->td( $menu_desc->render() );
  502. $Ted->td_colspan(2);
  503.  
  504. // Menu group access
  505. $menu_user_groups = $cboGroups;
  506. $menu_user_groups->name = "menu_user_groups";
  507. $menu_user_groups->setvalue($this->user_groups);
  508. $Ted->tr("axbglite");
  509. $Ted->td("Group access:", "axfg");
  510. $Ted->td_alignment("", "top");
  511. $Ted->td( $menu_user_groups->render() );
  512. $Ted->td( "&nbsp;" );
  513.  
  514. // ..................................................................
  515. // Menu Options Editing Fields..
  516. $Ted->tr("axhdg");
  517. $Ted->td("<b>MENU ITEMS</b>", "axhdg");
  518. $Ted->td_colspan(3);
  519.  
  520. // Continue defining listbox..
  521. $menuoption_listbox->setstyle("width:$ewidth;");
  522. $menuoption_listbox->size = 10;
  523. $default_parent_id = 0;
  524. foreach ($this->menuoptions as $m) {
  525. // Populate listbox..
  526. $menuoption_listbox->additem($m->menuoptionid, $m->label);
  527.  
  528. // Set the displayed menu action..
  529. $actionbits = explode("?", $m->action);
  530. $menuaction = $actionbits[0];
  531. if ($menuaction == "" || $menuaction == $m->sitepage) {
  532. $menuaction = MENU_ITEM_URL;
  533. }
  534. else {
  535. $menuaction = $m->sitepage;
  536. }
  537.  
  538. // Populate maintainer data. The maintainer add_record method
  539. // requires an associative array keyed on listbox key id..
  540. $rec = array(
  541. "parent_id" => $m->parent_id,
  542. "label" => $m->label,
  543. "description" => $m->description,
  544. "action" => $menuaction,
  545. "target" => $m->target,
  546. "sitepage" => $m->sitepage,
  547. "sitepage_parms" => $m->sitepage_parms,
  548. "is_parent" => (($m->is_parent) ? "t" : "f"),
  549. "user_groups" => implode(",", $m->user_groups),
  550. "user_type" => $m->user_type,
  551. "auth_code" => (($m->auth_code) ? "t" : "f"),
  552. "width" => $m->width,
  553. "height" => $m->height,
  554. "active" => (($m->active) ? "t" : "f")
  555. );
  556. $maintainer->add_record($m->menuoptionid, $rec);
  557.  
  558. // If this is the menuoption being edited, make sure
  559. // that it gets focussed..
  560. if (isset($this->edit_menuop_id) && $m->menuoptionid == $this->edit_menuop_id) {
  561. $maintainer->initial_record($m->menuoptionid);
  562. }
  563. // Save default as the last value..
  564. $default_parent_id = $m->parent_id;
  565. }
  566. // Now set the defaults for each of the fields. These are
  567. // necessary for when a new record is created..
  568. $defaults = array(
  569. "parent_id" => $default_parent_id,
  570. "label" => MENU_ITEM_SUBMENU,
  571. "description" => "",
  572. "action" => MENU_ITEM_URL,
  573. "target" => "",
  574. "sitepage" => MENU_ITEM_SUBMENU,
  575. "sitepage_parms" => "",
  576. "is_parent" => "f",
  577. "user_groups" => "",
  578. "user_type" => "",
  579. "auth_code" => "f",
  580. "width" => 100,
  581. "height" => 18,
  582. "active" => "t"
  583. );
  584. $maintainer->add_defaults($defaults);
  585.  
  586. // The listbox field..
  587. $menuoption_listbox->setvalue($m->menuoptionid);
  588. $Ted->tr("axbgdark");
  589. $Ted->td(
  590. $btop->render() . "<br>"
  591. . $bnext->render() . "<br>"
  592. . $bprev->render()
  593. );
  594. $Ted->td_alignment("", "top");
  595. $Ted->td( $menuoption_listbox->render() );
  596. $Ted->td(
  597. $bup->render() . "<br>"
  598. . $bdown->render() . "<br>"
  599. . $bdel->render() . "<br>"
  600. . $badd->render()
  601. );
  602. $Ted->td_alignment("right", "top");
  603.  
  604. // ..................................................................
  605. $Ted->tr("axhdg");
  606. $Ted->td("<b>MENU ITEM SETTINGS</b>", "axhdg");
  607. $Ted->td_colspan(3);
  608.  
  609. // ..................................................................
  610. // Parent field..
  611. $menuop_parents = new form_combofield("parent_id", "", $m->parent_id);
  612. $maintainer->register_field($menuop_parents);
  613. $menuop_parents->setstyle("width:$ewidth;");
  614. $menuop_parents->setclass("axcombo");
  615. $menuop_parents->additem("0", "TOP LEVEL");
  616. if ($this->exists) {
  617. $q = "SELECT * FROM ax_menuoption";
  618. $q .= " WHERE menu_id=$this->menu_id";
  619. $q .= " AND is_parent";
  620. $q .= " ORDER BY label";
  621. $moQ = dbrecordset($q);
  622. if ($moQ->hasdata) {
  623. do {
  624. $mid = $moQ->field("menuoption_id");
  625. $mlabel = $moQ->field("label");
  626. $menuop_parents->additem($mid, $mlabel);
  627. } while ($moQ->get_next());
  628. }
  629. }
  630. $Ted->tr("axbglite");
  631. $Ted->td( "Child of:", "axfg" );
  632. $Ted->td( $menuop_parents->render() );
  633. $Ted->td( "&nbsp;" );
  634.  
  635. // ..................................................................
  636. // Menuoption label field..
  637. $menuop_label = new form_textfield("label", "", $m->label);
  638. $maintainer->register_field($menuop_label);
  639. $menuop_label->setstyle("width:$ewidth;");
  640. $menuop_label->setclass("axtxtbox");
  641. $Ted->tr("axbglite");
  642. $Ted->td( "Label:", "axfg" );
  643. $Ted->td( $menuop_label->render() );
  644. $Ted->td( "&nbsp;" );
  645.  
  646. // ..................................................................
  647. // Menuoption description field..
  648. $menuop_desc = new form_textfield("description", "", $m->description);
  649. $maintainer->register_field($menuop_desc);
  650. $menuop_desc->setstyle("width:$ewidth;");
  651. $menuop_desc->setclass("axtxtbox");
  652. $Ted->tr("axbgdark");
  653. $Ted->td( "Description:", "axfg" );
  654. $Ted->td( $menuop_desc->render() );
  655. $Ted->td( "&nbsp;" );
  656.  
  657. // ..................................................................
  658. // Menuoption is parent field..
  659. $menuop_is_parent = new form_checkbox("is_parent");
  660. $maintainer->register_field($menuop_is_parent);
  661. $menuop_is_parent->checked = $m->is_parent;
  662. $menuop_is_parent->setclass("axchkbox");
  663. $Ted->tr("axbgdark");
  664. $Ted->td( "Is parent of sub-menu:", "axfg" );
  665. $Ted->td( $menuop_is_parent->render() );
  666. $Ted->td( "&nbsp;" );
  667.  
  668. // ..................................................................
  669. // Menuoption sitepage and sitepage parms, action & target fields..
  670. $menuop_spage = $cboWebPages;
  671. $menuop_spage->name = "sitepage";
  672. $maintainer->register_field($menuop_spage);
  673. $menuop_spage->setvalue($m->sitepage);
  674. $menuop_spage->setstyle("width:$ewidth;");
  675.  
  676. $menuop_action = new form_textfield("action");
  677. $maintainer->register_field($menuop_action);
  678. $menuop_action->setstyle("width:$ewidth;");
  679. $menuop_action->setclass("axtxtbox");
  680. $menuop_action->set_onblur("setAdhocURL(this,'" . $this->formname . "','_')");
  681.  
  682. $menuop_spage_parms = new form_textfield("sitepage_parms", "", $m->sitepage_parms);
  683. $maintainer->register_field($menuop_spage_parms);
  684. $menuop_spage_parms->setstyle("width:$ewidth;");
  685. $menuop_spage_parms->setclass("axtxtbox");
  686.  
  687. $menuop_target = new form_textfield("target");
  688. $maintainer->register_field($menuop_target);
  689. $menuop_target->setstyle("width:$pwidth;");
  690. $menuop_target->setclass("axtxtbox");
  691.  
  692. $Ted->tr("axbglite");
  693. $Ted->td( "Target webpage:", "axfg" );
  694. $Ted->td( $menuop_spage->render() );
  695. $Ted->td( "&nbsp;" );
  696. $Ted->tr("axbglite");
  697. $Ted->td( "or:", "axfg" );
  698. $Ted->td_alignment("right");
  699. $Ted->td( $menuop_action->render() );
  700. $Ted->td( "&nbsp;" );
  701. $Ted->tr("axbglite");
  702. $Ted->td( "URL Parameters:", "axfg" );
  703. $Ted->td( $menuop_spage_parms->render() );
  704. $Ted->td( "&nbsp;" );
  705. $Ted->tr("axbglite");
  706. $Ted->td( "Target frame:", "axfg" );
  707. $Ted->td( $menuop_target->render() );
  708. $Ted->td( "&nbsp;" );
  709.  
  710. $RESPONSE->add_script(
  711. "function setAdhocURL(elem, fm, pfx) {\n"
  712. . " if(elem.value!='" . MENU_ITEM_URL . "') {\n"
  713. . " pgcombo=eval('document.forms.'+fm+'.sitepage');\n"
  714. . " if(pgcombo!=null) {\n"
  715. . " comboSet(pgcombo, '" . MENU_ITEM_URL . "');\n"
  716. . " changedValue(fm, pgcombo, pfx);\n"
  717. . " }\n"
  718. . " }\n"
  719. . "}\n"
  720. );
  721.  
  722. // ..................................................................
  723. // Menuoption user groups field..
  724. $menuop_ugroups = $cboGroups;
  725. $menuop_ugroups->name = "user_groups";
  726. $maintainer->register_field($menuop_ugroups);
  727. $menuop_ugroups->setvalue($m->user_groups);
  728. $Ted->tr("axbgdark");
  729. $Ted->td( "Permitted groups:", "axfg" );
  730. $Ted->td_alignment("", "top");
  731. $Ted->td( $menuop_ugroups->render() );
  732. $Ted->td_alignment("", "top");
  733. $Ted->td( "&nbsp;" );
  734.  
  735. // ..................................................................
  736. // User type and authorisation code
  737. $menuop_utype = new form_combofield("user_type", "", $m->user_type);
  738. $menuop_utype->setclass("axcombo");
  739. $maintainer->register_field($menuop_utype);
  740. $menuop_utype->setstyle("width:$ewidth;");
  741. $menuop_utype->additem("", "Anyone");
  742. $menuop_utype->additem("sys", "System engineer only");
  743. $menuop_auth = new form_checkbox("auth_code");
  744. $menuop_auth->setclass("axchkbox");
  745. $menuop_auth->checked = $m->auth_code;
  746. $maintainer->register_field($menuop_auth);
  747. $Ted->tr("axbglite");
  748. $Ted->td( "Permitted user type:", "axfg" );
  749. $Ted->td( $menuop_utype->render() );
  750. $Ted->td( "Auth code reqd:&nbsp;" . $menuop_auth->render(), "axfg" );
  751. $Ted->td_alignment("right");
  752.  
  753. // ..................................................................
  754. // Width, height and active
  755. $menuop_width = new form_textfield("width", "", $m->width);
  756. $maintainer->register_field($menuop_width);
  757. $menuop_width->setstyle("width:60px;");
  758. $menuop_width->setclass("axtxtbox");
  759. $menuop_height = new form_textfield("height", "", $m->height);
  760. $maintainer->register_field($menuop_height);
  761. $menuop_height->setstyle("width:60px;");
  762. $menuop_height->setclass("axtxtbox");
  763. $menuop_active = new form_checkbox("active");
  764. $menuop_active->checked = $m->active;
  765. $maintainer->register_field($menuop_active);
  766. $Ted->tr("axbgdark");
  767. $Ted->td( "HVmenu sizing:", "axfg" );
  768. $Tin = new table("size");
  769. $Tin->tr();
  770. $Tin->td( $menuop_width->render() . " wide", "axfg" );
  771. $Tin->td( " x ", "axfg" );
  772. $Tin->td_alignment("center");
  773. $Tin->td( $menuop_height->render() . " high", "axfg" );
  774. $Ted->td( $Tin->render() );
  775. $Ted->td("Active:&nbsp;" . $menuop_active->render(), "axfg" );
  776. $Ted->td_alignment("right");
  777.  
  778. // ..................................................................
  779. // Render the whole form..
  780. $Ted->tr("axtitle");
  781. $Ted->td("&nbsp;", "axtitle");
  782. $Ted->td_colspan(3);
  783.  
  784. $Ted->set_width_profile("25%,55%,20%");
  785. $Ted->inherit_attributes($this);
  786. $s .= $Ted->render();
  787.  
  788. // Render the maintainer. This adds the Javascript data structures
  789. // and renders the hidden fields for submitting changed field data..
  790. $s .= $maintainer->render();
  791.  
  792. // ....................................................................
  793. debug_trace();
  794. // Return the html..
  795. return $s;
  796. } // editform
  797. // ....................................................................
  798. /** Renders a menu entry for the hierarchical list of options being
  799. * generated recursively.
  800. * @access private
  801. */
  802. function menu_entry($rendermode, $prefix, $mopid, $mno_children, $mno_details) {
  803. debug_trace($this);
  804. global $RESPONSE;
  805. $childcount = 0;
  806. $submnu = new table();
  807. $submnu->setstyle("margin-left:40px;");
  808.  
  809. // Store current menu option..
  810. $details = explode("|", $mno_details[$mopid]);
  811. $menu_level = $details[0];
  812. $label = $details[1];
  813. $action = $details[3];
  814. if ($menu_level == 0) $label = "<b>$label</b>";
  815. switch ($rendermode) {
  816. case "editmap":
  817. $maintainer_href = "$RESPONSE->requested?edit_menu_id=" . rawurlencode($this->menu_id);
  818. $maintainer_href .= "&menuopid=$mopid";
  819. $maintainer_href .= "&menumode=edit";
  820. break;
  821. case "sitemap":
  822. $maintainer_href = $action;
  823. break;
  824. }
  825. $submnu->tr();
  826. $submnu->td("<a href=\"$maintainer_href\">$label</a>");
  827.  
  828. // And children..
  829. if (isset($mno_children[$mopid]) && $mno_children[$mopid] != "") {
  830. $childoptions = explode("|", $mno_children[$mopid]);
  831. $childcount = count($childoptions);
  832. $pfxcount = 1;
  833. foreach ($childoptions as $childmopid) {
  834. $childprefix = $prefix . "|" . $pfxcount;
  835. $submnu->tr();
  836. $submnu->td( $this->menu_entry($rendermode, $childprefix, $childmopid, $mno_children, $mno_details) );
  837. $pfxcount += 1;
  838. }
  839. }
  840. debug_trace();
  841. return $submnu->render();
  842. } // menu_entry
  843. // ....................................................................
  844. /**
  845. * Render the whole menu layout hierarchy as a sitemap, which simply
  846. * gives links to each menu page.
  847. * @return string The HTML
  848. */
  849. function sitemap() {
  850. return $this->menulayout("sitemap");
  851. } // sitemap
  852. // ....................................................................
  853. /**
  854. * Render the whole menu layout content. We have two modes of operation,
  855. * one to return the hierarchy as a sitemap, which simply gives links
  856. * to each menu page, and one which acts as a navigator to go and edit
  857. * the menu options at any point in the menu.
  858. * @param string $rendermode Mode of display: 'editmap' or 'sitemap'
  859. * @return string The HTML
  860. * @access private
  861. */
  862. function menulayout($rendermode="editmap") {
  863. debug_trace($this);
  864. global $LIBDIR;
  865. global $RESPONSE;
  866. global $edit_menu_id;
  867.  
  868. // Initialise content..
  869. $s = "";
  870.  
  871. // Render dropdown menu if more than one menu..
  872. $menucombo = false;
  873. if ($rendermode == "editmap") {
  874. $menus = dbrecordset("SELECT * FROM ax_menu m, ax_language l WHERE l.lang_id=m.lang_id ORDER BY menu_name");
  875. if ($menus->rowcount > 0) {
  876. $menucombo = new form_combofield("sel_menu_id");
  877. do {
  878. $menu_id = $menus->field("menu_id");
  879. $menuname = $menus->field("menu_name");
  880. $menudesc = $menus->field("menu_desc");
  881. $menulang = $menus->field("lang_desc");
  882. $menucombo->additem($menu_id, "$menuname ($menulang)");
  883. } while ($menus->get_next());
  884. $menucombo->setvalue($this->menu_id);
  885. $menucombo->set_onchange("menugo('viewing')");
  886. }
  887. }
  888.  
  889. // Create buttons..
  890. $bed = new form_imagebutton("_edit", "", "", "$LIBDIR/img/_edit.gif", "Edit this menu", 42, 15);
  891. $bnew = new form_imagebutton("_new", "", "", "$LIBDIR/img/_new.gif", "Create new menu", 42, 15);
  892. $bdel = new form_imagebutton("_del", "", "", "$LIBDIR/img/_delete.gif", "Delete this menu", 57, 15);
  893. $bed->set_onclick("menugo('editing')");
  894. $bnew->set_onclick("menugo('createnew')");
  895. $bdel->set_onclick("menugo('delete')");
  896.  
  897. // Menu layout table..
  898. $Tvw = new table();
  899. if ($rendermode == "editmap") {
  900. $Tvw->tr("axtitle");
  901. $Tvw->td("Menu Layout", "axtitle");
  902. // Select, new, delete toolbar..
  903. $Toolbar = new table("toolbar");
  904. $Toolbar->setpadding(2);
  905. $Toolbar->setwidth("");
  906. if ($menucombo) {
  907. $Toolbar->td( $menucombo->render() );
  908. }
  909. $Toolbar->td( $bed->render() );
  910. $Toolbar->td( $bnew->render() );
  911. $Toolbar->td( $bdel->render() );
  912. $Tvw->td( $Toolbar->render() );
  913. $Tvw->td_alignment("right");
  914. }
  915.  
  916. // MENU ITEM DETAIL..
  917. if ($this->exists) {
  918. $q = "SELECT *";
  919. $q .= " FROM ax_menu m, ax_menuoption mo";
  920. $q .= " WHERE m.menu_id=$this->menu_id";
  921. $q .= " AND mo.menu_id=m.menu_id";
  922. $q .= " AND mo.active=TRUE";
  923. $q .= " ORDER BY mo.menu_level,mo.parent_id,mo.display_order";
  924. $item = dbrecordset($q);
  925. if ($item->hasdata) {
  926. $topcount = 0;
  927. do {
  928. $mopid = $item->field("menuoption_id");
  929. $mnu_ugroups = $item->field("user_groups");
  930. $mnu_usertype = $item->field("user_type");
  931. if ($mnu_ugroups == "" || $RESPONSE->ismemberof_group_in($mnu_ugroups)) {
  932. if ($mnu_usertype == "" || ($RESPONSE->user_type == $mnu_usertype)) {
  933. $parent_id = $item->field("parent_id");
  934. $menu_level = $item->field("menu_level");
  935. $label = $item->field("label");
  936. $description = $item->field("description");
  937. $action = $item->field("action");
  938. $authcode = $item->field("auth_code");
  939. if ($menu_level == 0) {
  940. $topcount += 1;
  941. $mno_top[$topcount] = $mopid;
  942. }
  943. $mno_details[$mopid] = "$menu_level|$label|$description|$action|$authcode";
  944. $mno_level[$mopid] = $menu_level;
  945. $mno_parent[$mopid] = $parent_id;
  946. if ($parent_id != "") {
  947. if (isset($mno_children[$parent_id])) {
  948. $mno_children[$parent_id] .= "|";
  949. }
  950. $mno_children[$parent_id] .= $mopid;
  951. }
  952. } // user type check
  953. } // memberof
  954. } while ($item->get_next());
  955.  
  956. // Store each row..
  957. $toplevels = new table();
  958. $toplevels->setpadding(4);
  959. while (list($item_no, $mopid) = each($mno_top)) {
  960. $prefix = "$item_no";
  961. $toplevels->tr();
  962. $toplevels->td( $this->menu_entry($rendermode, $prefix, $mopid, $mno_children, $mno_details) );
  963. }
  964. $Tvw->tr();
  965. $Tvw->td( $toplevels->render() );
  966. $Tvw->td_colspan(2);
  967. }
  968. else {
  969. $Tvw->tr();
  970. $Tvw->td( "No menu items defined.", "axfg" );
  971. $Tvw->td_colspan(2);
  972. }
  973. }
  974. else {
  975. $Tvw->tr();
  976. $Tvw->td( "Empty menu.", "axfg" );
  977. $Tvw->td_colspan(2);
  978. }
  979.  
  980. // Render the menu viewer table..
  981. $s .= $Tvw->render();
  982. return $s;
  983. } // menulayout
  984. // ....................................................................
  985. /**
  986. * Render the block content according to the mode of operation
  987. * we are in. Possible modes: 'viewing', 'editing', 'saving'.
  988. * @return string The HTML
  989. */
  990. function html() {
  991. debug_trace($this);
  992. global $RESPONSE;
  993.  
  994. $s = "";
  995.  
  996. // Start form for editing..
  997. if ($RESPONSE->ismemberof_group_in("Editor,Admin")) {
  998. $s .= "<form name=\"$this->formname\" method=\"post\">\n";
  999. }
  1000. switch($this->mode) {
  1001. case "editing":
  1002. $this->mode = "saving";
  1003. $s .= $this->editform();
  1004. break;
  1005. case "createnew":
  1006. $this->mode = "savingnew";
  1007. $s .= $this->editform();
  1008. break;
  1009. default:
  1010. $this->mode = "viewing";
  1011. $s .= $this->menulayout();
  1012. } // switch
  1013.  
  1014. // Finish the form..
  1015. if ($RESPONSE->ismemberof_group_in("Editor,Admin")) {
  1016. // Include action hidden field, and block ID
  1017. $mode = new form_hiddenfield("menumode", $this->mode);
  1018. $mid = new form_hiddenfield("edit_menu_id", $this->menu_id);
  1019. $mlevel = new form_hiddenfield("menulevel", $this->menu_level);
  1020. $pid = new form_hiddenfield("edit_parent_id", $this->edit_parent_id);
  1021. $s .= $mode->render() . $mid->render() . $pid->render() . $mlevel->render();
  1022. $s .= "</form>\n";
  1023. }
  1024. debug_trace();
  1025. return $s;
  1026. } // html
  1027. // ....................................................................
  1028. /**
  1029. * Process a block edit form POST.
  1030. * Assume that the fields have been submitted in a form as named
  1031. * in the config, and grab the POSTed values. This method is executed
  1032. * from the constructor usually, before anything is read in from
  1033. * the database. We get first shot to change data here.
  1034. * @access private
  1035. */
  1036. function POSTprocess() {
  1037. debug_trace($this);
  1038. global $HTTP_POST_VARS, $RESPONSE;
  1039. if (isset($HTTP_POST_VARS["menumode"])) {
  1040. global $_done_x, $_edit_x;
  1041. global $edit_menu_id, $edit_parent_id, $menuoption_id, $menulevel;
  1042. $this->mode = $HTTP_POST_VARS["menumode"];
  1043. debugbr("POSTprocess: mode: $this->mode");
  1044. switch ($this->mode) {
  1045. case "viewing":
  1046. if (isset($_edit_x)) {
  1047. $this->mode = "editing";
  1048. }
  1049. break;
  1050.  
  1051. case "delete":
  1052. if ($this->menu_id != false) {
  1053. $mdel = new dbdelete("ax_menu");
  1054. $mdel->where("menu_id=$this->menu_id");
  1055. $mdel->execute();
  1056. }
  1057. break;
  1058.  
  1059. case "createnew":
  1060. $this->menu_id = false;
  1061. $this->menu_name = "(new menu name)";
  1062. $this->menu_desc = "(new menu description)";
  1063. break;
  1064.  
  1065. case "savingnew":
  1066. $this->put();
  1067. $this->get();
  1068. $edit_menu_id = $this->menu_id;
  1069. case "saving":
  1070. if ($edit_menu_id == $this->menu_id) {
  1071. global $_save_x, $_cancel_x, $_done_x;
  1072. global $_prev_x, $_next_x, $_top_x, $_newpg_x;
  1073. global $_recmaintpost_form;
  1074. global $_recmaintpost_data;
  1075. global $_recmaintpost_flds;
  1076. global $_recmaintpost_dels;
  1077. global $_recmaintpost_order;
  1078.  
  1079. // Let me out of here..
  1080. if (isset($_done_x) || isset($_cancel_x)) {
  1081. // Drop through to viewing..
  1082. $this->mode = "viewing";
  1083. }
  1084. // Go to top level of menu..
  1085. elseif ( isset($_top_x)) {
  1086. $this->edit_parent_id = 0;
  1087. $this->mode = "editing";
  1088. }
  1089. // Go to previous menu level..
  1090. elseif ( isset($_prev_x)) {
  1091. if ($edit_parent_id > 0) {
  1092. $mo = new menuoption($edit_parent_id);
  1093. if ($mo->exists) {
  1094. $edit_parent_id = $mo->parent_id;
  1095. $this->edit_parent_id = $mo->parent_id;
  1096. }
  1097. }
  1098. $this->mode = "editing";
  1099. }
  1100. // Go to to next menu level..
  1101. elseif ( isset($_next_x)) {
  1102. if (isset($menuoption_id) && $menuoption_id != 0) {
  1103. $this->edit_parent_id = $menuoption_id;
  1104. $edit_parent_id = $menuoption_id;
  1105. }
  1106. $this->mode = "editing";
  1107. }
  1108. // Posted record maintenance data..
  1109. elseif ( isset($_recmaintpost_form)
  1110. && $_recmaintpost_form == $this->formname) {
  1111. // Deal with deletes..
  1112. if (isset($_recmaintpost_dels) && $_recmaintpost_dels != "") {
  1113. $menuoption_delids = explode(FIELD_DELIM, $_recmaintpost_dels);
  1114. foreach ($menuoption_delids as $delmenuoptionid) {
  1115. // First, clear out microsite references to this menu option..
  1116. $mopnul = new dbupdate("ax_microsite_page");
  1117. $mopnul->set("menuoption_id", NULLVALUE);
  1118. $mopnul->where("menuoption_id=$delmenuoptionid");
  1119. $mopnul->execute();
  1120. // Remove menuoption..
  1121. $mopdel = new dbdelete("ax_menuoption");
  1122. $mopdel->where("menuoption_id=$delmenuoptionid");
  1123. $mopdel->execute();
  1124. }
  1125. }
  1126. // Menu option adds and saves..
  1127. if (isset($_recmaintpost_data) && $_recmaintpost_data != "") {
  1128. $menuoptionrecs = explode(RECORD_DELIM, $_recmaintpost_data);
  1129. $menuoption_fields = explode(",", $_recmaintpost_flds);
  1130. foreach ($menuoptionrecs as $menuoptionrec) {
  1131. $menuoption_values = explode(FIELD_DELIM, $menuoptionrec);
  1132. $menuoptionid = array_shift($menuoption_values);
  1133. // Cater for new creations..
  1134. if (strstr($menuoptionid, "NEW_")) {
  1135. $savedid = $menuoptionid;
  1136. $menuoptionid = get_next_sequencevalue(
  1137. "seq_menuoption_id",
  1138. "ax_menuoption",
  1139. "menuoption_id"
  1140. );
  1141. $im = new dbinsert("ax_menuoption");
  1142. $im->set("menuoption_id", $menuoptionid);
  1143. $im->set("menu_id", $this->menu_id);
  1144. $im->set("parent_id", $this->edit_parent_id);
  1145. $im->set("menu_level", $menulevel);
  1146. $im->set("display_order", 999);
  1147. $im->execute();
  1148. // Fix up potential re-ordering id..
  1149. if (isset($_recmaintpost_order)) {
  1150. $_recmaintpost_order = str_replace($savedid, $menuoptionid, $_recmaintpost_order);
  1151. }
  1152. }
  1153. // Update the menuoption data..
  1154. $um = new dbupdate("ax_menuoption");
  1155. $um->where("menuoption_id=$menuoptionid");
  1156. $pos = 0; $sitepage = ""; $sitepage_parms = "";
  1157. foreach ($menuoption_fields as $menuoption_field) {
  1158. // Set the menu level..
  1159. if ($menuoption_field == "parent_id") {
  1160. $new_parid = $menuoption_values[$pos];
  1161. if ($new_parid != $this->edit_parent_id) {
  1162. if ($new_parid == 0) {
  1163. $menulevel = 0;
  1164. }
  1165. else {
  1166. $q = "SELECT menu_level FROM ax_menuoption";
  1167. $q .= " WHERE menuoption_id=$new_parid";
  1168. $lq = dbrecordset($q);
  1169. if ($lq->hasdata) {
  1170. $menulevel = $lq->field("menu_level") + 1;
  1171. }
  1172. }
  1173. $um->set("menu_level", $menulevel);
  1174. }
  1175. }
  1176. // Record sitepage settings for later..
  1177. if ($menuoption_field == "sitepage") {
  1178. $sitepage = $menuoption_values[$pos];
  1179. }
  1180. elseif ($menuoption_field == "sitepage_parms") {
  1181. $sitepage_parms = $menuoption_values[$pos];
  1182. }
  1183.  
  1184. if ($menuoption_field == "action") {
  1185. // Defer action setting 'til later..
  1186. $menuaction = $menuoption_values[$pos++];
  1187. }
  1188. else {
  1189. // All other 'normal' field settings..
  1190. $um->set($menuoption_field, $menuoption_values[$pos++]);
  1191. }
  1192. } // foreach
  1193.  
  1194. // Post-processing for label and menu action etc..
  1195. switch ($sitepage) {
  1196. // Special-function menu items first..
  1197. case MENU_ITEM_SPACER:
  1198. $um->set("label", MENU_ITEM_SPACER);
  1199. $menuaction = "";
  1200. break;
  1201. case MENU_ITEM_SEPARATOR:
  1202. $um->set("label", MENU_ITEM_SEPARATOR);
  1203. $menuaction = "";
  1204. break;
  1205. case MENU_ITEM_SUBMENU:
  1206. $menuaction = "";
  1207. break;
  1208. case MENU_ITEM_URL:
  1209. // Leave menuaction as-is..
  1210. break;
  1211. // Normal menu items last..
  1212. default:
  1213. $menuaction = $sitepage;
  1214. } // switch
  1215.  
  1216. // Set the resulting menu action..
  1217. if ($menuaction != "") {
  1218. // Fix leading slash for action and sitepage if reqd..
  1219. if (substr($menuaction, 0, 1) != "/" && !protocol_prefixed($menuaction)) {
  1220. $menuaction = "/$menuaction";
  1221. if ($sitepage != MENU_ITEM_URL) {
  1222. $um->set("sitepage", $menuaction);
  1223. }
  1224. }
  1225. if ($sitepage_parms != "") {
  1226. $menuaction .= "?" . $sitepage_parms;
  1227. }
  1228. }
  1229. $um->set("action", $menuaction);
  1230.  
  1231. // Set lastmodified, and fire it off..
  1232. $um->set("last_modified", 'now()');
  1233. $um->execute();
  1234. } // foreach menuoptionrecs
  1235. }
  1236. // Save menu properties..
  1237. global $menu_name, $language, $menu_desc, $menu_user_groups, $menu_active;
  1238. $mu = new dbupdate("ax_menu");
  1239. $mu->where("menu_id='" . addslashes($this->menu_id) . "'");
  1240. $mu->set("menu_name", $menu_name);
  1241. $mu->set("lang_id", $language);
  1242. $mu->set("menu_name", $menu_name);
  1243. $mu->set("active", isset($menu_active));
  1244. $mu->set("last_modified", 'now()');
  1245. $mu->execute();
  1246.  
  1247. // Check/save menuoption ordering..
  1248. if (isset($_recmaintpost_order) && $_recmaintpost_order != "") {
  1249. $ord = 1;
  1250. $idlist = explode(FIELD_DELIM, $_recmaintpost_order);
  1251. foreach ($idlist as $menuoptionid) {
  1252. $upd = new dbupdate("ax_menuoption");
  1253. $upd->where("menuoption_id=$menuoptionid");
  1254. $upd->set("display_order", $ord);
  1255. $upd->set("last_modified", 'now()');
  1256. $upd->execute();
  1257. $ord += 1;
  1258. }
  1259. }
  1260. // Drop through to viewing..
  1261. $this->mode = "viewing";
  1262. } // if our menu being saved
  1263. }
  1264. break;
  1265. } // switch
  1266. }
  1267. debug_trace();
  1268. } // POSTprocess
  1269.  
  1270.  
  1271.  
  1272. } // menumaintainer class
  1273. // ----------------------------------------------------------------------
  1274.  
  1275. ?>

Documentation generated by phpDocumentor 1.3.0RC3