menunode.class.inc.php 40 KB

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