menunode.class.inc.php 40 KB

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