menunode.class.inc.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  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 = true)
  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. $this->bSearchFormOpen = $bSearchFormOpen;
  601. $this->m_aParams = array();
  602. $this->aReflectionProperties['oql'] = $sOQL;
  603. $this->aReflectionProperties['do_search'] = $bSearch;
  604. // Enhancement: we could set as the "enable" condition that the user has enough rights to "read" the objects
  605. // of the class specified by the OQL...
  606. }
  607. /**
  608. * Set some extra parameters to be passed to the display block to fine tune its appearence
  609. * @param Hash $aParams paramCode => value. See DisplayBlock::GetDisplay for the meaning of the parameters
  610. */
  611. public function SetParameters($aParams)
  612. {
  613. $this->m_aParams = $aParams;
  614. foreach($aParams as $sKey => $value)
  615. {
  616. $this->aReflectionProperties[$sKey] = $value;
  617. }
  618. }
  619. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  620. {
  621. OQLMenuNode::RenderOQLSearch
  622. (
  623. $this->sOQL,
  624. Dict::S($this->sPageTitle),
  625. 'Menu_'.$this->GetMenuId(),
  626. $this->bSearch, // Search pane
  627. $this->bSearchFormOpen, // Search open
  628. $oPage,
  629. array_merge($this->m_aParams, $aExtraParams),
  630. true
  631. );
  632. }
  633. public static function RenderOQLSearch($sOql, $sTitle, $sUsageId, $bSearchPane, $bSearchOpen, WebPage $oPage, $aExtraParams = array(), $bEnableBreadcrumb = false)
  634. {
  635. $sUsageId = utils::GetSafeId($sUsageId);
  636. $oSearch = DBObjectSearch::FromOQL($sOql);
  637. $sIcon = MetaModel::GetClassIcon($oSearch->GetClass());
  638. if ($bSearchPane)
  639. {
  640. $aParams = array_merge(array('open' => $bSearchOpen, 'table_id' => $sUsageId), $aExtraParams);
  641. $oBlock = new DisplayBlock($oSearch, 'search', false /* Asynchronous */, $aParams);
  642. $oBlock->Display($oPage, 0);
  643. }
  644. $oPage->add("<p class=\"page-header\">$sIcon ".Dict::S($sTitle)."</p>");
  645. $aParams = array_merge(array('table_id' => $sUsageId), $aExtraParams);
  646. $oBlock = new DisplayBlock($oSearch, 'list', false /* Asynchronous */, $aParams);
  647. $oBlock->Display($oPage, $sUsageId);
  648. if ($bEnableBreadcrumb && ($oPage instanceof iTopWebPage))
  649. {
  650. // Breadcrumb
  651. //$iCount = $oBlock->GetDisplayedCount();
  652. $sPageId = "ui-search-".$oSearch->GetClass();
  653. $sLabel = MetaModel::GetName($oSearch->GetClass());
  654. $oPage->SetBreadCrumbEntry($sPageId, $sLabel, $sTitle, '', '../images/breadcrumb-search.png');
  655. }
  656. }
  657. }
  658. /**
  659. * This class defines a menu item that displays a search form for the given class of objects
  660. */
  661. class SearchMenuNode extends MenuNode
  662. {
  663. protected $sPageTitle;
  664. protected $sClass;
  665. /**
  666. * Create a menu item based on an OQL query and inserts it into the application's main menu
  667. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  668. * @param string $sClass The class of objects to search for
  669. * @param string $sPageTitle Title displayed into the page's content (will be looked-up in the dictionnary for translation)
  670. * @param integer $iParentIndex ID of the parent menu
  671. * @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
  672. * @param string $sEnableClass Name of class of object
  673. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  674. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  675. * @return MenuNode
  676. */
  677. public function __construct($sMenuId, $sClass, $iParentIndex, $fRank = 0, $bSearch = false, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  678. {
  679. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  680. $this->sPageTitle = "Menu:$sMenuId+";
  681. $this->sClass = $sClass;
  682. $this->aReflectionProperties['class'] = $sClass;
  683. }
  684. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  685. {
  686. $oSearch = new DBObjectSearch($this->sClass);
  687. $aParams = array_merge(array('open' => true, 'table_id' => 'Menu_'.utils::GetSafeId($this->GetMenuId())), $aExtraParams);
  688. $oBlock = new DisplayBlock($oSearch, 'search', false /* Asynchronous */, $aParams);
  689. $oBlock->Display($oPage, 0);
  690. }
  691. }
  692. /**
  693. * This class defines a menu that points to any web page. It takes only two parameters:
  694. * - The hyperlink to point to
  695. * - The name of the menu
  696. * Note: the parameter menu=xxx (where xxx is the id of the menu itself) will be added to the hyperlink
  697. * in order to make it the active one, if the target page is based on iTopWebPage and therefore displays the menu
  698. */
  699. class WebPageMenuNode extends MenuNode
  700. {
  701. protected $sHyperlink;
  702. /**
  703. * Create a menu item that points to any web page (not only UI.php)
  704. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  705. * @param string $sHyperlink URL to the page to load. Use relative URL if you want to keep the application portable !
  706. * @param integer $iParentIndex ID of the parent menu
  707. * @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
  708. * @param string $sEnableClass Name of class of object
  709. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  710. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  711. * @return MenuNode
  712. */
  713. public function __construct($sMenuId, $sHyperlink, $iParentIndex, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  714. {
  715. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  716. $this->sHyperlink = $sHyperlink;
  717. $this->aReflectionProperties['url'] = $sHyperlink;
  718. }
  719. public function GetHyperlink($aExtraParams)
  720. {
  721. $aExtraParams['c[menu]'] = $this->GetMenuId();
  722. return $this->AddParams( $this->sHyperlink, $aExtraParams);
  723. }
  724. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  725. {
  726. assert(false); // Shall never be called, the external web page will handle the display by itself
  727. }
  728. }
  729. /**
  730. * This class defines a menu that points to the page for creating a new object of the specified class.
  731. * It take only one parameter: the name of the class
  732. * Note: the parameter menu=xxx (where xxx is the id of the menu itself) will be added to the hyperlink
  733. * in order to make it the active one
  734. */
  735. class NewObjectMenuNode extends MenuNode
  736. {
  737. protected $sClass;
  738. /**
  739. * 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
  740. * rights to create such an object (or an object of a child class)
  741. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  742. * @param string $sClass URL to the page to load. Use relative URL if you want to keep the application portable !
  743. * @param integer $iParentIndex ID of the parent menu
  744. * @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
  745. * @return MenuNode
  746. */
  747. public function __construct($sMenuId, $sClass, $iParentIndex, $fRank = 0)
  748. {
  749. parent::__construct($sMenuId, $iParentIndex, $fRank);
  750. $this->sClass = $sClass;
  751. $this->aReflectionProperties['class'] = $sClass;
  752. }
  753. public function GetHyperlink($aExtraParams)
  754. {
  755. $sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$this->sClass;
  756. $aExtraParams['c[menu]'] = $this->GetMenuId();
  757. return $this->AddParams($sHyperlink, $aExtraParams);
  758. }
  759. /**
  760. * Overload the check of the "enable" state of this menu to take into account
  761. * derived classes of objects
  762. */
  763. public function IsEnabled()
  764. {
  765. // Enable this menu, only if the current user has enough rights to create such an object, or an object of
  766. // any child class
  767. $aSubClasses = MetaModel::EnumChildClasses($this->sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself
  768. $bActionIsAllowed = false;
  769. foreach($aSubClasses as $sCandidateClass)
  770. {
  771. if (!MetaModel::IsAbstract($sCandidateClass) && (UserRights::IsActionAllowed($sCandidateClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES))
  772. {
  773. $bActionIsAllowed = true;
  774. break; // Enough for now
  775. }
  776. }
  777. return $bActionIsAllowed;
  778. }
  779. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  780. {
  781. assert(false); // Shall never be called, the external web page will handle the display by itself
  782. }
  783. }
  784. require_once(APPROOT.'application/dashboard.class.inc.php');
  785. /**
  786. * This class defines a menu item which content is based on XML dashboard.
  787. */
  788. class DashboardMenuNode extends MenuNode
  789. {
  790. protected $sDashboardFile;
  791. /**
  792. * Create a menu item based on a custom template and inserts it into the application's main menu
  793. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  794. * @param string $sTemplateFile Path (or URL) to the file that will be used as a template for displaying the page's content
  795. * @param integer $iParentIndex ID of the parent menu
  796. * @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
  797. * @param string $sEnableClass Name of class of object
  798. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  799. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  800. * @return MenuNode
  801. */
  802. public function __construct($sMenuId, $sDashboardFile, $iParentIndex, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  803. {
  804. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  805. $this->sDashboardFile = $sDashboardFile;
  806. $this->aReflectionProperties['definition_file'] = $sDashboardFile;
  807. }
  808. public function GetHyperlink($aExtraParams)
  809. {
  810. if ($this->sDashboardFile == '') return '';
  811. return parent::GetHyperlink($aExtraParams);
  812. }
  813. public function GetDashboard()
  814. {
  815. $sDashboardDefinition = @file_get_contents($this->sDashboardFile);
  816. if ($sDashboardDefinition !== false)
  817. {
  818. $bCustomized = false;
  819. // Search for an eventual user defined dashboard, overloading the existing one
  820. $oUDSearch = new DBObjectSearch('UserDashboard');
  821. $oUDSearch->AddCondition('user_id', UserRights::GetUserId(), '=');
  822. $oUDSearch->AddCondition('menu_code', $this->sMenuId, '=');
  823. $oUDSet = new DBObjectSet($oUDSearch);
  824. if ($oUDSet->Count() > 0)
  825. {
  826. // Assuming there is at most one couple {user, menu}!
  827. $oUserDashboard = $oUDSet->Fetch();
  828. $sDashboardDefinition = $oUserDashboard->Get('contents');
  829. $bCustomized = true;
  830. }
  831. $oDashboard = new RuntimeDashboard($this->sMenuId);
  832. $oDashboard->FromXml($sDashboardDefinition);
  833. $oDashboard->SetCustomFlag($bCustomized);
  834. }
  835. else
  836. {
  837. $oDashboard = null;
  838. }
  839. return $oDashboard;
  840. }
  841. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  842. {
  843. $oDashboard = $this->GetDashboard();
  844. if ($oDashboard != null)
  845. {
  846. $sDivId = preg_replace('/[^a-zA-Z0-9_]/', '', $this->sMenuId);
  847. $oPage->add('<div class="dashboard_contents" id="'.$sDivId.'">');
  848. $oDashboard->Render($oPage, false, $aExtraParams);
  849. $oPage->add('</div>');
  850. $oDashboard->RenderEditionTools($oPage);
  851. if ($oDashboard->GetAutoReload())
  852. {
  853. $sId = $this->sMenuId;
  854. $sExtraParams = json_encode($aExtraParams);
  855. $iReloadInterval = 1000 * $oDashboard->GetAutoReloadInterval();
  856. $oPage->add_script(
  857. <<<EOF
  858. setInterval("ReloadDashboard('$sDivId');", $iReloadInterval);
  859. function ReloadDashboard(sDivId)
  860. {
  861. var oExtraParams = $sExtraParams;
  862. // Do not reload when a dialog box is active
  863. if (!($('.ui-dialog:visible').length > 0))
  864. {
  865. $('.dashboard_contents#'+sDivId).block();
  866. $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php',
  867. { operation: 'reload_dashboard', dashboard_id: '$sId', extra_params: oExtraParams},
  868. function(data){
  869. $('.dashboard_contents#'+sDivId).html(data);
  870. $('.dashboard_contents#'+sDivId).unblock();
  871. }
  872. );
  873. }
  874. }
  875. EOF
  876. );
  877. }
  878. $bEdit = utils::ReadParam('edit', false);
  879. if ($bEdit)
  880. {
  881. $sId = addslashes($this->sMenuId);
  882. $oPage->add_ready_script("EditDashboard('$sId');");
  883. }
  884. else
  885. {
  886. $oParentMenu = ApplicationMenu::GetMenuNode($this->iParentIndex);
  887. $sParentTitle = $oParentMenu->GetTitle();
  888. $sThisTitle = $this->GetTitle();
  889. if ($sParentTitle != $sThisTitle)
  890. {
  891. $sDescription = $sParentTitle.' / '.$sThisTitle;
  892. }
  893. else
  894. {
  895. $sDescription = $sThisTitle;
  896. }
  897. if ($this->sMenuId == ApplicationMenu::GetDefaultMenuId())
  898. {
  899. $sIcon = '../images/breadcrumb_home.png';
  900. }
  901. else
  902. {
  903. $sIcon = '../images/breadcrumb-dashboard.png';
  904. }
  905. $oPage->SetBreadCrumbEntry("ui-dashboard-".$this->sMenuId, $this->GetTitle(), $sDescription, '', $sIcon);
  906. }
  907. }
  908. else
  909. {
  910. $oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
  911. }
  912. }
  913. public function RenderEditor(WebPage $oPage)
  914. {
  915. $oDashboard = $this->GetDashboard();
  916. if ($oDashboard != null)
  917. {
  918. $oDashboard->RenderEditor($oPage);
  919. }
  920. else
  921. {
  922. $oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
  923. }
  924. }
  925. public function AddDashlet($oDashlet)
  926. {
  927. $oDashboard = $this->GetDashboard();
  928. if ($oDashboard != null)
  929. {
  930. $oDashboard->AddDashlet($oDashlet);
  931. $oDashboard->Save();
  932. }
  933. else
  934. {
  935. throw new Exception("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
  936. }
  937. }
  938. }
  939. /**
  940. * A shortcut container is the preferred destination of newly created shortcuts
  941. */
  942. class ShortcutContainerMenuNode extends MenuNode
  943. {
  944. public function GetHyperlink($aExtraParams)
  945. {
  946. return '';
  947. }
  948. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  949. {
  950. }
  951. public function PopulateChildMenus()
  952. {
  953. // Load user shortcuts in DB
  954. //
  955. $oBMSearch = new DBObjectSearch('Shortcut');
  956. $oBMSearch->AddCondition('user_id', UserRights::GetUserId(), '=');
  957. $oBMSet = new DBObjectSet($oBMSearch, array('friendlyname' => true)); // ascending on friendlyname
  958. $fRank = 1;
  959. while ($oShortcut = $oBMSet->Fetch())
  960. {
  961. $sName = $this->GetMenuId().'_'.$oShortcut->GetKey();
  962. $oShortcutMenu = new ShortcutMenuNode($sName, $oShortcut, $this->GetIndex(), $fRank++);
  963. }
  964. // Complete the tree
  965. //
  966. parent::PopulateChildMenus();
  967. }
  968. }
  969. require_once(APPROOT.'application/shortcut.class.inc.php');
  970. /**
  971. * This class defines a menu item which content is a shortcut.
  972. */
  973. class ShortcutMenuNode extends MenuNode
  974. {
  975. protected $oShortcut;
  976. /**
  977. * Create a menu item based on a custom template and inserts it into the application's main menu
  978. * @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
  979. * @param object $oShortcut Shortcut object
  980. * @param integer $iParentIndex ID of the parent menu
  981. * @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
  982. * @param string $sEnableClass Name of class of object
  983. * @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
  984. * @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
  985. * @return MenuNode
  986. */
  987. public function __construct($sMenuId, $oShortcut, $iParentIndex, $fRank = 0, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
  988. {
  989. parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
  990. $this->oShortcut = $oShortcut;
  991. $this->aReflectionProperties['shortcut'] = $oShortcut->GetKey();
  992. }
  993. public function GetHyperlink($aExtraParams)
  994. {
  995. $sContext = $this->oShortcut->Get('context');
  996. $aContext = unserialize($sContext);
  997. if (isset($aContext['menu']))
  998. {
  999. unset($aContext['menu']);
  1000. }
  1001. foreach ($aContext as $sArgName => $sArgValue)
  1002. {
  1003. $aExtraParams[$sArgName] = $sArgValue;
  1004. }
  1005. return parent::GetHyperlink($aExtraParams);
  1006. }
  1007. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  1008. {
  1009. $this->oShortcut->RenderContent($oPage, $aExtraParams);
  1010. }
  1011. public function GetTitle()
  1012. {
  1013. return $this->oShortcut->Get('name');
  1014. }
  1015. public function GetLabel()
  1016. {
  1017. return $this->oShortcut->Get('name');
  1018. }
  1019. }