menunode.class.inc.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. <?php
  2. // Copyright (C) 2010-2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Construction and display of the application's main menu
  20. *
  21. * @copyright Copyright (C) 2010-2016 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. require_once(APPROOT.'/application/utils.inc.php');
  25. require_once(APPROOT.'/application/template.class.inc.php');
  26. require_once(APPROOT."/application/user.dashboard.class.inc.php");
  27. /**
  28. * This class manipulates, stores and displays the navigation menu used in the application
  29. * In order to improve the modularity of the data model and to ease the update/migration
  30. * between evolving data models, the menus are no longer stored in the database, but are instead
  31. * built on the fly each time a page is loaded.
  32. * The application's menu is organized into top-level groups with, inside each group, a tree of menu items.
  33. * Top level groups do not display any content, they just expand/collapse.
  34. * Sub-items drive the actual content of the page, they are based either on templates, OQL queries or full (external?) web pages.
  35. *
  36. * Example:
  37. * Here is how to insert the following items in the application's menu:
  38. * +----------------------------------------+
  39. * | Configuration Management Group | >> Top level group
  40. * +----------------------------------------+
  41. * + Configuration Management Overview >> Template based menu item
  42. * + Contacts >> Template based menu item
  43. * + Persons >> Plain list (OQL based)
  44. * + Teams >> Plain list (OQL based)
  45. *
  46. * // Create the top-level group. fRank = 1, means it will be inserted after the group '0', which is usually 'Welcome'
  47. * $oConfigMgmtMenu = new MenuGroup('ConfigurationManagementMenu', 1);
  48. * // Create an entry, based on a custom template, for the Configuration management overview, under the top-level group
  49. * new TemplateMenuNode('ConfigurationManagementMenu', '../somedirectory/configuration_management_menu.html', $oConfigMgmtMenu->GetIndex(), 0);
  50. * // Create an entry (template based) for the overview of contacts
  51. * $oContactsMenu = new TemplateMenuNode('ContactsMenu', '../somedirectory/configuration_management_menu.html',$oConfigMgmtMenu->GetIndex(), 1);
  52. * // Plain list of persons
  53. * new OQLMenuNode('PersonsMenu', 'SELECT bizPerson', $oContactsMenu->GetIndex(), 0);
  54. *
  55. */
  56. class ApplicationMenu
  57. {
  58. static $bAdditionalMenusLoaded = false;
  59. static $aRootMenus = array();
  60. static $aMenusIndex = array();
  61. static $sFavoriteSiloQuery = 'SELECT Organization';
  62. static public function LoadAdditionalMenus()
  63. {
  64. if (!self::$bAdditionalMenusLoaded)
  65. {
  66. // Build menus from module handlers
  67. //
  68. foreach(get_declared_classes() as $sPHPClass)
  69. {
  70. if (is_subclass_of($sPHPClass, 'ModuleHandlerAPI'))
  71. {
  72. $aCallSpec = array($sPHPClass, 'OnMenuCreation');
  73. call_user_func($aCallSpec);
  74. }
  75. }
  76. // Build menus from the menus themselves (e.g. the ShortcutContainerMenuNode will do that)
  77. //
  78. foreach(self::$aRootMenus as $aMenu)
  79. {
  80. $oMenuNode = self::GetMenuNode($aMenu['index']);
  81. $oMenuNode->PopulateChildMenus();
  82. }
  83. self::$bAdditionalMenusLoaded = true;
  84. }
  85. }
  86. /**
  87. * Set the query used to limit the list of displayed organizations in the drop-down menu
  88. * @param $sOQL string The OQL query returning a list of Organization objects
  89. * @return none
  90. */
  91. static public function SetFavoriteSiloQuery($sOQL)
  92. {
  93. self::$sFavoriteSiloQuery = $sOQL;
  94. }
  95. /**
  96. * Get the query used to limit the list of displayed organizations in the drop-down menu
  97. * @return string The OQL query returning a list of Organization objects
  98. */
  99. static public function GetFavoriteSiloQuery()
  100. {
  101. return self::$sFavoriteSiloQuery;
  102. }
  103. /**
  104. * Main function to add a menu entry into the application, can be called during the definition
  105. * of the data model objects
  106. */
  107. static public function InsertMenu(MenuNode $oMenuNode, $iParentIndex, $fRank)
  108. {
  109. $index = self::GetMenuIndexById($oMenuNode->GetMenuId());
  110. if ($index == -1)
  111. {
  112. // The menu does not already exist, insert it
  113. $index = count(self::$aMenusIndex);
  114. if ($iParentIndex == -1)
  115. {
  116. $sParentId = '';
  117. self::$aRootMenus[] = array ('rank' => $fRank, 'index' => $index);
  118. }
  119. else
  120. {
  121. $sParentId = self::$aMenusIndex[$iParentIndex]['node']->GetMenuId();
  122. self::$aMenusIndex[$iParentIndex]['children'][] = array ('rank' => $fRank, 'index' => $index);
  123. }
  124. // Note: At the time when 'parent', 'rank' and 'source_file' have been added for the reflection API,
  125. // they were not used to display the menus (redundant or unused)
  126. //
  127. $aBacktrace = debug_backtrace();
  128. $sFile = isset($aBacktrace[2]["file"]) ? $aBacktrace[2]["file"] : $aBacktrace[1]["file"];
  129. self::$aMenusIndex[$index] = array('node' => $oMenuNode, 'children' => array(), 'parent' => $sParentId, 'rank' => $fRank, 'source_file' => $sFile);
  130. }
  131. else
  132. {
  133. // the menu already exists, let's combine the conditions that make it visible
  134. self::$aMenusIndex[$index]['node']->AddCondition($oMenuNode);
  135. }
  136. return $index;
  137. }
  138. /**
  139. * Reflection API - Get menu entries
  140. */
  141. static public function ReflectionMenuNodes()
  142. {
  143. self::LoadAdditionalMenus();
  144. return self::$aMenusIndex;
  145. }
  146. /**
  147. * Entry point to display the whole menu into the web page, used by iTopWebPage
  148. */
  149. static public function DisplayMenu($oPage, $aExtraParams)
  150. {
  151. self::LoadAdditionalMenus();
  152. // Sort the root menu based on the rank
  153. usort(self::$aRootMenus, array('ApplicationMenu', 'CompareOnRank'));
  154. $iAccordion = 0;
  155. $iActiveMenu = self::GetMenuIndexById(self::GetActiveNodeId());
  156. foreach(self::$aRootMenus as $aMenu)
  157. {
  158. $oMenuNode = self::GetMenuNode($aMenu['index']);
  159. if (!$oMenuNode->IsEnabled()) continue; // Don't display a non-enabled menu
  160. $oPage->AddToMenu('<h3>'.$oMenuNode->GetTitle().'</h3>');
  161. $oPage->AddToMenu('<div>');
  162. $aChildren = self::GetChildren($aMenu['index']);
  163. if (count($aChildren) > 0)
  164. {
  165. $oPage->AddToMenu('<ul>');
  166. $bActive = self::DisplaySubMenu($oPage, $aChildren, $aExtraParams, $iActiveMenu);
  167. $oPage->AddToMenu('</ul>');
  168. if ($bActive)
  169. {
  170. $oPage->add_ready_script(
  171. <<<EOF
  172. // Accordion Menu
  173. $("#accordion").css({display:'block'}).accordion({ header: "h3", navigation: true, heightStyle: "content", collapsible: true, active: $iAccordion, icons: false, animate:true }); // collapsible will be enabled once the item will be selected
  174. EOF
  175. );
  176. }
  177. }
  178. $oPage->AddToMenu('</div>');
  179. $iAccordion++;
  180. }
  181. }
  182. /**
  183. * Handles the display of the sub-menus (called recursively if necessary)
  184. * @return true if the currently selected menu is one of the submenus
  185. */
  186. static protected function DisplaySubMenu($oPage, $aMenus, $aExtraParams, $iActiveMenu = -1)
  187. {
  188. // Sort the menu based on the rank
  189. $bActive = false;
  190. usort($aMenus, array('ApplicationMenu', 'CompareOnRank'));
  191. foreach($aMenus as $aMenu)
  192. {
  193. $index = $aMenu['index'];
  194. $oMenu = self::GetMenuNode($index);
  195. if ($oMenu->IsEnabled())
  196. {
  197. $aChildren = self::GetChildren($index);
  198. $sCSSClass = (count($aChildren) > 0) ? ' class="submenu"' : '';
  199. $sHyperlink = $oMenu->GetHyperlink($aExtraParams);
  200. if ($sHyperlink != '')
  201. {
  202. $oPage->AddToMenu('<li'.$sCSSClass.'><a href="'.$oMenu->GetHyperlink($aExtraParams).'">'.$oMenu->GetTitle().'</a></li>');
  203. }
  204. else
  205. {
  206. $oPage->AddToMenu('<li'.$sCSSClass.'>'.$oMenu->GetTitle().'</li>');
  207. }
  208. $aCurrentMenu = self::$aMenusIndex[$index];
  209. if ($iActiveMenu == $index)
  210. {
  211. $bActive = true;
  212. }
  213. if (count($aChildren) > 0)
  214. {
  215. $oPage->AddToMenu('<ul>');
  216. $bActive |= self::DisplaySubMenu($oPage, $aChildren, $aExtraParams, $iActiveMenu);
  217. $oPage->AddToMenu('</ul>');
  218. }
  219. }
  220. }
  221. return $bActive;
  222. }
  223. /**
  224. * Helper function to sort the menus based on their rank
  225. */
  226. static public function CompareOnRank($a, $b)
  227. {
  228. $result = 1;
  229. if ($a['rank'] == $b['rank'])
  230. {
  231. $result = 0;
  232. }
  233. if ($a['rank'] < $b['rank'])
  234. {
  235. $result = -1;
  236. }
  237. return $result;
  238. }
  239. /**
  240. * Helper function to retrieve the MenuNodeObject based on its ID
  241. */
  242. static public function GetMenuNode($index)
  243. {
  244. return isset(self::$aMenusIndex[$index]) ? self::$aMenusIndex[$index]['node'] : null;
  245. }
  246. /**
  247. * Helper function to get the list of child(ren) of a menu
  248. */
  249. static public function GetChildren($index)
  250. {
  251. return self::$aMenusIndex[$index]['children'];
  252. }
  253. /**
  254. * Helper function to get the ID of a menu based on its name
  255. * @param string $sTitle Title of the menu (as passed when creating the menu)
  256. * @return integer ID of the menu, or -1 if not found
  257. */
  258. static public function GetMenuIndexById($sTitle)
  259. {
  260. $index = -1;
  261. foreach(self::$aMenusIndex as $aMenu)
  262. {
  263. if ($aMenu['node']->GetMenuId() == $sTitle)
  264. {
  265. $index = $aMenu['node']->GetIndex();
  266. break;
  267. }
  268. }
  269. return $index;
  270. }
  271. /**
  272. * Retrieves the currently active menu (if any, otherwise the first menu is the default)
  273. * @return string The Id of the currently active menu
  274. */
  275. static public function GetActiveNodeId()
  276. {
  277. $oAppContext = new ApplicationContext();
  278. $sMenuId = $oAppContext->GetCurrentValue('menu', null);
  279. if ($sMenuId === null)
  280. {
  281. $sMenuId = self::GetDefaultMenuId();
  282. }
  283. return $sMenuId;
  284. }
  285. static public function GetDefaultMenuId()
  286. {
  287. static $sDefaultMenuId = null;
  288. if (is_null($sDefaultMenuId))
  289. {
  290. // Make sure the root menu is sorted on 'rank'
  291. usort(self::$aRootMenus, array('ApplicationMenu', 'CompareOnRank'));
  292. $oFirstGroup = self::GetMenuNode(self::$aRootMenus[0]['index']);
  293. $aChildren = self::$aMenusIndex[$oFirstGroup->GetIndex()]['children'];
  294. usort($aChildren, array('ApplicationMenu', 'CompareOnRank'));
  295. $oMenuNode = self::GetMenuNode($aChildren[0]['index']);
  296. $sDefaultMenuId = $oMenuNode->GetMenuId();
  297. }
  298. return $sDefaultMenuId;
  299. }
  300. }
  301. /**
  302. * Root class for all the kind of node in the menu tree, data model providers are responsible for instantiating
  303. * MenuNodes (i.e instances from derived classes) in order to populate the application's menu. Creating an objet
  304. * derived from MenuNode is enough to have it inserted in the application's main menu.
  305. * The class iTopWebPage, takes care of 3 items:
  306. * +--------------------+
  307. * | Welcome |
  308. * +--------------------+
  309. * Welcome To iTop
  310. * +--------------------+
  311. * | Tools |
  312. * +--------------------+
  313. * CSV Import
  314. * +--------------------+
  315. * | Admin Tools |
  316. * +--------------------+
  317. * User Accounts
  318. * Profiles
  319. * Notifications
  320. * Run Queries
  321. * Export
  322. * Data Model
  323. * Universal Search
  324. *
  325. * All the other menu items must constructed along with the various data model modules
  326. */
  327. abstract class MenuNode
  328. {
  329. protected $sMenuId;
  330. protected $index;
  331. protected $iParentIndex;
  332. /**
  333. * Properties reflecting how the node has been declared
  334. */
  335. protected $aReflectionProperties;
  336. /**
  337. * Class of objects to check if the menu is enabled, null if none
  338. */
  339. protected $m_aEnableClasses;
  340. /**
  341. * User Rights Action code to check if the menu is enabled, null if none
  342. */
  343. protected $m_aEnableActions;
  344. /**
  345. * User Rights allowed results (actually a bitmask) to check if the menu is enabled, null if none
  346. */
  347. protected $m_aEnableActionResults;
  348. /**
  349. * Stimulus to check: if the user can 'apply' this stimulus, then she/he can see this menu
  350. */
  351. protected $m_aEnableStimuli;
  352. /**
  353. * Create a menu item, sets the condition to have it displayed and inserts it into the application's main menu
  354. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  355. * @param integer $iParentIndex ID of the parent menu, pass -1 for top level (group) items
  356. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  357. * @param string $sEnableClass Name of class of object
  358. * @param mixed $iActionCode UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  359. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  360. * @param string $sEnableStimulus The user can see this menu if she/he has enough rights to apply this stimulus
  361. * @return MenuNode
  362. */
  363. public function __construct($sMenuId, $iParentIndex = -1, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  364. {
  365. $this->sMenuId = $sMenuId;
  366. $this->iParentIndex = $iParentIndex;
  367. $this->aReflectionProperties = array();
  368. if (strlen($sEnableClass) > 0)
  369. {
  370. $this->aReflectionProperties['enable_class'] = $sEnableClass;
  371. $this->aReflectionProperties['enable_action'] = $iActionCode;
  372. $this->aReflectionProperties['enable_permission'] = $iAllowedResults;
  373. $this->aReflectionProperties['enable_stimulus'] = $sEnableStimulus;
  374. }
  375. $this->m_aEnableClasses = array($sEnableClass);
  376. $this->m_aEnableActions = array($iActionCode);
  377. $this->m_aEnableActionResults = array($iAllowedResults);
  378. $this->m_aEnableStimuli = array($sEnableStimulus);
  379. $this->index = ApplicationMenu::InsertMenu($this, $iParentIndex, $fRank);
  380. }
  381. public function ReflectionProperties()
  382. {
  383. return $this->aReflectionProperties;
  384. }
  385. public function GetMenuId()
  386. {
  387. return $this->sMenuId;
  388. }
  389. public function GetTitle()
  390. {
  391. return Dict::S("Menu:$this->sMenuId", str_replace('_', ' ', $this->sMenuId));
  392. }
  393. public function GetLabel()
  394. {
  395. $sRet = Dict::S("Menu:$this->sMenuId+", "");
  396. if ($sRet === '')
  397. {
  398. if ($this->iParentIndex != -1)
  399. {
  400. $oParentMenu = ApplicationMenu::GetMenuNode($this->iParentIndex);
  401. $sRet = $oParentMenu->GetTitle().' / '.$this->GetTitle();
  402. }
  403. else
  404. {
  405. $sRet = $this->GetTitle();
  406. }
  407. //$sRet = $this->GetTitle();
  408. }
  409. return $sRet;
  410. }
  411. public function GetIndex()
  412. {
  413. return $this->index;
  414. }
  415. public function PopulateChildMenus()
  416. {
  417. foreach (ApplicationMenu::GetChildren($this->GetIndex()) as $aMenu)
  418. {
  419. $index = $aMenu['index'];
  420. $oMenu = ApplicationMenu::GetMenuNode($index);
  421. $oMenu->PopulateChildMenus();
  422. }
  423. }
  424. public function GetHyperlink($aExtraParams)
  425. {
  426. $aExtraParams['c[menu]'] = $this->GetMenuId();
  427. return $this->AddParams(utils::GetAbsoluteUrlAppRoot().'pages/UI.php', $aExtraParams);
  428. }
  429. /**
  430. * Add a limiting display condition for the same menu node. The conditions will be combined with a AND
  431. * @param $oMenuNode MenuNode Another definition of the same menu node, with potentially different access restriction
  432. * @return void
  433. */
  434. public function AddCondition(MenuNode $oMenuNode)
  435. {
  436. foreach($oMenuNode->m_aEnableClasses as $index => $sClass )
  437. {
  438. $this->m_aEnableClasses[] = $sClass;
  439. $this->m_aEnableActions[] = $oMenuNode->m_aEnableActions[$index];
  440. $this->m_aEnableActionResults[] = $oMenuNode->m_aEnableActionResults[$index];
  441. $this->m_aEnableStimuli[] = $oMenuNode->m_aEnableStimuli[$index];
  442. }
  443. }
  444. /**
  445. * Tells whether the menu is enabled (i.e. displayed) for the current user
  446. * @return bool True if enabled, false otherwise
  447. */
  448. public function IsEnabled()
  449. {
  450. foreach($this->m_aEnableClasses as $index => $sClass)
  451. {
  452. if ($sClass != null)
  453. {
  454. if (MetaModel::IsValidClass($sClass))
  455. {
  456. if ($this->m_aEnableStimuli[$index] != null)
  457. {
  458. if (!UserRights::IsStimulusAllowed($sClass, $this->m_aEnableStimuli[$index]))
  459. {
  460. return false;
  461. }
  462. }
  463. if ($this->m_aEnableActions[$index] != null)
  464. {
  465. $iResult = UserRights::IsActionAllowed($sClass, $this->m_aEnableActions[$index]);
  466. if (!($iResult & $this->m_aEnableActionResults[$index]))
  467. {
  468. return false;
  469. }
  470. }
  471. }
  472. else
  473. {
  474. return false;
  475. }
  476. }
  477. }
  478. return true;
  479. }
  480. public abstract function RenderContent(WebPage $oPage, $aExtraParams = array());
  481. protected function AddParams($sHyperlink, $aExtraParams)
  482. {
  483. if (count($aExtraParams) > 0)
  484. {
  485. $aQuery = array();
  486. $sSeparator = '?';
  487. if (strpos($sHyperlink, '?') !== false)
  488. {
  489. $sSeparator = '&';
  490. }
  491. foreach($aExtraParams as $sName => $sValue)
  492. {
  493. $aQuery[] = urlencode($sName).'='.urlencode($sValue);
  494. }
  495. $sHyperlink .= $sSeparator.implode('&', $aQuery);
  496. }
  497. return $sHyperlink;
  498. }
  499. }
  500. /**
  501. * This class implements a top-level menu group. A group is just a container for sub-items
  502. * it does not display a page by itself
  503. */
  504. class MenuGroup extends MenuNode
  505. {
  506. /**
  507. * Create a top-level menu group and inserts it into the application's main menu
  508. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  509. * @param float $fRank Number used to order the list, the groups are sorted based on this value
  510. * @param string $sEnableClass Name of class of object
  511. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  512. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  513. * @return MenuGroup
  514. */
  515. public function __construct($sMenuId, $fRank, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  516. {
  517. parent::__construct($sMenuId, -1 /* no parent, groups are at root level */, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  518. }
  519. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  520. {
  521. assert(false); // Shall never be called, groups do not display any content
  522. }
  523. }
  524. /**
  525. * This class defines a menu item which content is based on a custom template.
  526. * Note the template can be either a local file or an URL !
  527. */
  528. class TemplateMenuNode extends MenuNode
  529. {
  530. protected $sTemplateFile;
  531. /**
  532. * Create a menu item based on a custom template and inserts it into the application's main menu
  533. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  534. * @param string $sTemplateFile Path (or URL) to the file that will be used as a template for displaying the page's content
  535. * @param integer $iParentIndex ID of the parent menu
  536. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  537. * @param string $sEnableClass Name of class of object
  538. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  539. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  540. * @return MenuNode
  541. */
  542. public function __construct($sMenuId, $sTemplateFile, $iParentIndex, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  543. {
  544. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  545. $this->sTemplateFile = $sTemplateFile;
  546. $this->aReflectionProperties['template_file'] = $sTemplateFile;
  547. }
  548. public function GetHyperlink($aExtraParams)
  549. {
  550. if ($this->sTemplateFile == '') return '';
  551. return parent::GetHyperlink($aExtraParams);
  552. }
  553. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  554. {
  555. $sTemplate = @file_get_contents($this->sTemplateFile);
  556. if ($sTemplate !== false)
  557. {
  558. $aExtraParams['table_id'] = 'Menu_'.$this->GetMenuId();
  559. $oTemplate = new DisplayTemplate($sTemplate);
  560. $oTemplate->Render($oPage, $aExtraParams);
  561. }
  562. else
  563. {
  564. $oPage->p("Error: failed to load template file: '{$this->sTemplateFile}'"); // No need to translate ?
  565. }
  566. }
  567. }
  568. /**
  569. * This class defines a menu item that uses a standard template to display a list of items therefore it allows
  570. * only two parameters: the page's title and the OQL expression defining the list of items to be displayed
  571. */
  572. class OQLMenuNode extends MenuNode
  573. {
  574. protected $sPageTitle;
  575. protected $sOQL;
  576. protected $bSearch;
  577. protected $bSearchFormOpen;
  578. /**
  579. * Extra parameters to be passed to the display block to fine tune its appearence
  580. */
  581. protected $m_aParams;
  582. /**
  583. * Create a menu item based on an OQL query and inserts it into the application's main menu
  584. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  585. * @param string $sOQL OQL query defining the set of objects to be displayed
  586. * @param integer $iParentIndex ID of the parent menu
  587. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  588. * @param bool $bSearch Whether or not to display a (collapsed) search frame at the top of the page
  589. * @param string $sEnableClass Name of class of object
  590. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  591. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  592. * @return MenuNode
  593. */
  594. public function __construct($sMenuId, $sOQL, $iParentIndex, $fRank = 0, $bSearch = false, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null, $bSearchFormOpen = null)
  595. {
  596. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  597. $this->sPageTitle = "Menu:$sMenuId+";
  598. $this->sOQL = $sOQL;
  599. $this->bSearch = $bSearch;
  600. if ($bSearchFormOpen == null)
  601. {
  602. $this->bSearchFormOpen = MetaModel::GetConfig()->Get('legacy_search_drawer_open');
  603. }
  604. else
  605. {
  606. $this->bSearchFormOpen = $bSearchFormOpen;
  607. }
  608. $this->m_aParams = array();
  609. $this->aReflectionProperties['oql'] = $sOQL;
  610. $this->aReflectionProperties['do_search'] = $bSearch;
  611. // Enhancement: we could set as the "enable" condition that the user has enough rights to "read" the objects
  612. // of the class specified by the OQL...
  613. }
  614. /**
  615. * Set some extra parameters to be passed to the display block to fine tune its appearence
  616. * @param Hash $aParams paramCode => value. See DisplayBlock::GetDisplay for the meaning of the parameters
  617. */
  618. public function SetParameters($aParams)
  619. {
  620. $this->m_aParams = $aParams;
  621. foreach($aParams as $sKey => $value)
  622. {
  623. $this->aReflectionProperties[$sKey] = $value;
  624. }
  625. }
  626. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  627. {
  628. OQLMenuNode::RenderOQLSearch
  629. (
  630. $this->sOQL,
  631. Dict::S($this->sPageTitle),
  632. 'Menu_'.$this->GetMenuId(),
  633. $this->bSearch, // Search pane
  634. $this->bSearchFormOpen, // Search open
  635. $oPage,
  636. array_merge($this->m_aParams, $aExtraParams),
  637. true
  638. );
  639. }
  640. public static function RenderOQLSearch($sOql, $sTitle, $sUsageId, $bSearchPane, $bSearchOpen, WebPage $oPage, $aExtraParams = array(), $bEnableBreadcrumb = false)
  641. {
  642. $sUsageId = utils::GetSafeId($sUsageId);
  643. $oSearch = DBObjectSearch::FromOQL($sOql);
  644. $sIcon = MetaModel::GetClassIcon($oSearch->GetClass());
  645. if ($bSearchPane)
  646. {
  647. $aParams = array_merge(array('open' => $bSearchOpen, 'table_id' => $sUsageId), $aExtraParams);
  648. $oBlock = new DisplayBlock($oSearch, 'search', false /* Asynchronous */, $aParams);
  649. $oBlock->Display($oPage, 0);
  650. }
  651. $oPage->add("<p class=\"page-header\">$sIcon ".Dict::S($sTitle)."</p>");
  652. $aParams = array_merge(array('table_id' => $sUsageId), $aExtraParams);
  653. $oBlock = new DisplayBlock($oSearch, 'list', false /* Asynchronous */, $aParams);
  654. $oBlock->Display($oPage, $sUsageId);
  655. if ($bEnableBreadcrumb && ($oPage instanceof iTopWebPage))
  656. {
  657. // Breadcrumb
  658. //$iCount = $oBlock->GetDisplayedCount();
  659. $sPageId = "ui-search-".$oSearch->GetClass();
  660. $sLabel = MetaModel::GetName($oSearch->GetClass());
  661. $oPage->SetBreadCrumbEntry($sPageId, $sLabel, $sTitle, '', '../images/breadcrumb-search.png');
  662. }
  663. }
  664. }
  665. /**
  666. * This class defines a menu item that displays a search form for the given class of objects
  667. */
  668. class SearchMenuNode extends MenuNode
  669. {
  670. protected $sPageTitle;
  671. protected $sClass;
  672. /**
  673. * Create a menu item based on an OQL query and inserts it into the application's main menu
  674. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  675. * @param string $sClass The class of objects to search for
  676. * @param string $sPageTitle Title displayed into the page's content (will be looked-up in the dictionnary for translation)
  677. * @param integer $iParentIndex ID of the parent menu
  678. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  679. * @param string $sEnableClass Name of class of object
  680. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  681. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  682. * @return MenuNode
  683. */
  684. public function __construct($sMenuId, $sClass, $iParentIndex, $fRank = 0, $bSearch = false, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  685. {
  686. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  687. $this->sPageTitle = "Menu:$sMenuId+";
  688. $this->sClass = $sClass;
  689. $this->aReflectionProperties['class'] = $sClass;
  690. }
  691. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  692. {
  693. $oPage->SetBreadCrumbEntry("menu-".$this->sMenuId, $this->GetTitle(), '', '', utils::GetAbsoluteUrlAppRoot().'images/search.png');
  694. $oSearch = new DBObjectSearch($this->sClass);
  695. $aParams = array_merge(array('open' => true, 'table_id' => 'Menu_'.utils::GetSafeId($this->GetMenuId())), $aExtraParams);
  696. $oBlock = new DisplayBlock($oSearch, 'search', false /* Asynchronous */, $aParams);
  697. $oBlock->Display($oPage, 0);
  698. }
  699. }
  700. /**
  701. * This class defines a menu that points to any web page. It takes only two parameters:
  702. * - The hyperlink to point to
  703. * - The name of the menu
  704. * Note: the parameter menu=xxx (where xxx is the id of the menu itself) will be added to the hyperlink
  705. * in order to make it the active one, if the target page is based on iTopWebPage and therefore displays the menu
  706. */
  707. class WebPageMenuNode extends MenuNode
  708. {
  709. protected $sHyperlink;
  710. /**
  711. * Create a menu item that points to any web page (not only UI.php)
  712. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  713. * @param string $sHyperlink URL to the page to load. Use relative URL if you want to keep the application portable !
  714. * @param integer $iParentIndex ID of the parent menu
  715. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  716. * @param string $sEnableClass Name of class of object
  717. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  718. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  719. * @return MenuNode
  720. */
  721. public function __construct($sMenuId, $sHyperlink, $iParentIndex, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  722. {
  723. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  724. $this->sHyperlink = $sHyperlink;
  725. $this->aReflectionProperties['url'] = $sHyperlink;
  726. }
  727. public function GetHyperlink($aExtraParams)
  728. {
  729. $aExtraParams['c[menu]'] = $this->GetMenuId();
  730. return $this->AddParams( $this->sHyperlink, $aExtraParams);
  731. }
  732. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  733. {
  734. assert(false); // Shall never be called, the external web page will handle the display by itself
  735. }
  736. }
  737. /**
  738. * This class defines a menu that points to the page for creating a new object of the specified class.
  739. * It take only one parameter: the name of the class
  740. * Note: the parameter menu=xxx (where xxx is the id of the menu itself) will be added to the hyperlink
  741. * in order to make it the active one
  742. */
  743. class NewObjectMenuNode extends MenuNode
  744. {
  745. protected $sClass;
  746. /**
  747. * Create a menu item that points to the URL for creating a new object, the menu will be added only if the current user has enough
  748. * rights to create such an object (or an object of a child class)
  749. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  750. * @param string $sClass URL to the page to load. Use relative URL if you want to keep the application portable !
  751. * @param integer $iParentIndex ID of the parent menu
  752. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  753. * @return MenuNode
  754. */
  755. public function __construct($sMenuId, $sClass, $iParentIndex, $fRank = 0)
  756. {
  757. parent::__construct($sMenuId, $iParentIndex, $fRank);
  758. $this->sClass = $sClass;
  759. $this->aReflectionProperties['class'] = $sClass;
  760. }
  761. public function GetHyperlink($aExtraParams)
  762. {
  763. $sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$this->sClass;
  764. $aExtraParams['c[menu]'] = $this->GetMenuId();
  765. return $this->AddParams($sHyperlink, $aExtraParams);
  766. }
  767. /**
  768. * Overload the check of the "enable" state of this menu to take into account
  769. * derived classes of objects
  770. */
  771. public function IsEnabled()
  772. {
  773. // Enable this menu, only if the current user has enough rights to create such an object, or an object of
  774. // any child class
  775. $aSubClasses = MetaModel::EnumChildClasses($this->sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself
  776. $bActionIsAllowed = false;
  777. foreach($aSubClasses as $sCandidateClass)
  778. {
  779. if (!MetaModel::IsAbstract($sCandidateClass) && (UserRights::IsActionAllowed($sCandidateClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES))
  780. {
  781. $bActionIsAllowed = true;
  782. break; // Enough for now
  783. }
  784. }
  785. return $bActionIsAllowed;
  786. }
  787. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  788. {
  789. assert(false); // Shall never be called, the external web page will handle the display by itself
  790. }
  791. }
  792. require_once(APPROOT.'application/dashboard.class.inc.php');
  793. /**
  794. * This class defines a menu item which content is based on XML dashboard.
  795. */
  796. class DashboardMenuNode extends MenuNode
  797. {
  798. protected $sDashboardFile;
  799. /**
  800. * Create a menu item based on a custom template and inserts it into the application's main menu
  801. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  802. * @param string $sTemplateFile Path (or URL) to the file that will be used as a template for displaying the page's content
  803. * @param integer $iParentIndex ID of the parent menu
  804. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  805. * @param string $sEnableClass Name of class of object
  806. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  807. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  808. * @return MenuNode
  809. */
  810. public function __construct($sMenuId, $sDashboardFile, $iParentIndex, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  811. {
  812. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  813. $this->sDashboardFile = $sDashboardFile;
  814. $this->aReflectionProperties['definition_file'] = $sDashboardFile;
  815. }
  816. public function GetHyperlink($aExtraParams)
  817. {
  818. if ($this->sDashboardFile == '') return '';
  819. return parent::GetHyperlink($aExtraParams);
  820. }
  821. public function GetDashboard()
  822. {
  823. $sDashboardDefinition = @file_get_contents($this->sDashboardFile);
  824. if ($sDashboardDefinition !== false)
  825. {
  826. $bCustomized = false;
  827. // Search for an eventual user defined dashboard, overloading the existing one
  828. $oUDSearch = new DBObjectSearch('UserDashboard');
  829. $oUDSearch->AddCondition('user_id', UserRights::GetUserId(), '=');
  830. $oUDSearch->AddCondition('menu_code', $this->sMenuId, '=');
  831. $oUDSet = new DBObjectSet($oUDSearch);
  832. if ($oUDSet->Count() > 0)
  833. {
  834. // Assuming there is at most one couple {user, menu}!
  835. $oUserDashboard = $oUDSet->Fetch();
  836. $sDashboardDefinition = $oUserDashboard->Get('contents');
  837. $bCustomized = true;
  838. }
  839. $oDashboard = new RuntimeDashboard($this->sMenuId);
  840. $oDashboard->FromXml($sDashboardDefinition);
  841. $oDashboard->SetCustomFlag($bCustomized);
  842. }
  843. else
  844. {
  845. $oDashboard = null;
  846. }
  847. return $oDashboard;
  848. }
  849. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  850. {
  851. $oDashboard = $this->GetDashboard();
  852. if ($oDashboard != null)
  853. {
  854. $sDivId = preg_replace('/[^a-zA-Z0-9_]/', '', $this->sMenuId);
  855. $oPage->add('<div class="dashboard_contents" id="'.$sDivId.'">');
  856. $oDashboard->Render($oPage, false, $aExtraParams);
  857. $oPage->add('</div>');
  858. $oDashboard->RenderEditionTools($oPage);
  859. if ($oDashboard->GetAutoReload())
  860. {
  861. $sId = $this->sMenuId;
  862. $sExtraParams = json_encode($aExtraParams);
  863. $iReloadInterval = 1000 * $oDashboard->GetAutoReloadInterval();
  864. $oPage->add_script(
  865. <<<EOF
  866. setInterval("ReloadDashboard('$sDivId');", $iReloadInterval);
  867. function ReloadDashboard(sDivId)
  868. {
  869. var oExtraParams = $sExtraParams;
  870. // Do not reload when a dialog box is active
  871. if (!($('.ui-dialog:visible').length > 0))
  872. {
  873. $('.dashboard_contents#'+sDivId).block();
  874. $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php',
  875. { operation: 'reload_dashboard', dashboard_id: '$sId', extra_params: oExtraParams},
  876. function(data){
  877. $('.dashboard_contents#'+sDivId).html(data);
  878. $('.dashboard_contents#'+sDivId).unblock();
  879. }
  880. );
  881. }
  882. }
  883. EOF
  884. );
  885. }
  886. $bEdit = utils::ReadParam('edit', false);
  887. if ($bEdit)
  888. {
  889. $sId = addslashes($this->sMenuId);
  890. $oPage->add_ready_script("EditDashboard('$sId');");
  891. }
  892. else
  893. {
  894. $oParentMenu = ApplicationMenu::GetMenuNode($this->iParentIndex);
  895. $sParentTitle = $oParentMenu->GetTitle();
  896. $sThisTitle = $this->GetTitle();
  897. if ($sParentTitle != $sThisTitle)
  898. {
  899. $sDescription = $sParentTitle.' / '.$sThisTitle;
  900. }
  901. else
  902. {
  903. $sDescription = $sThisTitle;
  904. }
  905. if ($this->sMenuId == ApplicationMenu::GetDefaultMenuId())
  906. {
  907. $sIcon = '../images/breadcrumb_home.png';
  908. }
  909. else
  910. {
  911. $sIcon = '../images/breadcrumb-dashboard.png';
  912. }
  913. $oPage->SetBreadCrumbEntry("ui-dashboard-".$this->sMenuId, $this->GetTitle(), $sDescription, '', $sIcon);
  914. }
  915. }
  916. else
  917. {
  918. $oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
  919. }
  920. }
  921. public function RenderEditor(WebPage $oPage)
  922. {
  923. $oDashboard = $this->GetDashboard();
  924. if ($oDashboard != null)
  925. {
  926. $oDashboard->RenderEditor($oPage);
  927. }
  928. else
  929. {
  930. $oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
  931. }
  932. }
  933. public function AddDashlet($oDashlet)
  934. {
  935. $oDashboard = $this->GetDashboard();
  936. if ($oDashboard != null)
  937. {
  938. $oDashboard->AddDashlet($oDashlet);
  939. $oDashboard->Save();
  940. }
  941. else
  942. {
  943. throw new Exception("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
  944. }
  945. }
  946. }
  947. /**
  948. * A shortcut container is the preferred destination of newly created shortcuts
  949. */
  950. class ShortcutContainerMenuNode extends MenuNode
  951. {
  952. public function GetHyperlink($aExtraParams)
  953. {
  954. return '';
  955. }
  956. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  957. {
  958. }
  959. public function PopulateChildMenus()
  960. {
  961. // Load user shortcuts in DB
  962. //
  963. $oBMSearch = new DBObjectSearch('Shortcut');
  964. $oBMSearch->AddCondition('user_id', UserRights::GetUserId(), '=');
  965. $oBMSet = new DBObjectSet($oBMSearch, array('friendlyname' => true)); // ascending on friendlyname
  966. $fRank = 1;
  967. while ($oShortcut = $oBMSet->Fetch())
  968. {
  969. $sName = $this->GetMenuId().'_'.$oShortcut->GetKey();
  970. $oShortcutMenu = new ShortcutMenuNode($sName, $oShortcut, $this->GetIndex(), $fRank++);
  971. }
  972. // Complete the tree
  973. //
  974. parent::PopulateChildMenus();
  975. }
  976. }
  977. require_once(APPROOT.'application/shortcut.class.inc.php');
  978. /**
  979. * This class defines a menu item which content is a shortcut.
  980. */
  981. class ShortcutMenuNode extends MenuNode
  982. {
  983. protected $oShortcut;
  984. /**
  985. * Create a menu item based on a custom template and inserts it into the application's main menu
  986. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  987. * @param object $oShortcut Shortcut object
  988. * @param integer $iParentIndex ID of the parent menu
  989. * @param float $fRank Number used to order the list, any number will do, but for a given level (i.e same parent) all menus are sorted based on this value
  990. * @param string $sEnableClass Name of class of object
  991. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  992. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  993. * @return MenuNode
  994. */
  995. public function __construct($sMenuId, $oShortcut, $iParentIndex, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  996. {
  997. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  998. $this->oShortcut = $oShortcut;
  999. $this->aReflectionProperties['shortcut'] = $oShortcut->GetKey();
  1000. }
  1001. public function GetHyperlink($aExtraParams)
  1002. {
  1003. $sContext = $this->oShortcut->Get('context');
  1004. $aContext = unserialize($sContext);
  1005. if (isset($aContext['menu']))
  1006. {
  1007. unset($aContext['menu']);
  1008. }
  1009. foreach ($aContext as $sArgName => $sArgValue)
  1010. {
  1011. $aExtraParams[$sArgName] = $sArgValue;
  1012. }
  1013. return parent::GetHyperlink($aExtraParams);
  1014. }
  1015. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  1016. {
  1017. $this->oShortcut->RenderContent($oPage, $aExtraParams);
  1018. }
  1019. public function GetTitle()
  1020. {
  1021. return $this->oShortcut->Get('name');
  1022. }
  1023. public function GetLabel()
  1024. {
  1025. return $this->oShortcut->Get('name');
  1026. }
  1027. }