displayblock.class.inc.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * DisplayBlock and derived class
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. require_once('../application/webpage.class.inc.php');
  25. require_once('../application/utils.inc.php');
  26. /**
  27. * Helper class to manage 'blocks' of HTML pieces that are parts of a page and contain some list of cmdb objects
  28. *
  29. * Each block is actually rendered as a <div></div> tag that can be rendered synchronously
  30. * or as a piece of Javascript/JQuery/Ajax that will get its content from another page (ajax.render.php).
  31. * The list of cmdbObjects to be displayed into the block is defined by a filter
  32. * Right now the type of display is either: list, count, bare_details, details, csv, modify or search
  33. * - list produces a table listing the objects
  34. * - count produces a paragraphs with a sentence saying 'cont' objects found
  35. * - bare_details displays just the details of the attributes of the object (best if only one)
  36. * - details display the full details of each object found using its template (best if only one)
  37. * - csv displays a textarea with the CSV export of the list of objects
  38. * - modify displays the form to modify an object (best if only one)
  39. * - search displays a search form with the criteria of the filter set
  40. */
  41. class DisplayBlock
  42. {
  43. const TAG_BLOCK = 'itopblock';
  44. protected $m_oFilter;
  45. protected $m_sStyle;
  46. protected $m_bAsynchronous;
  47. protected $m_aParams;
  48. protected $m_oSet;
  49. public function __construct(DBObjectSearch $oFilter, $sStyle = 'list', $bAsynchronous = false, $aParams = array(), $oSet = null)
  50. {
  51. $this->m_oFilter = $oFilter;
  52. $this->m_sStyle = $sStyle;
  53. $this->m_bAsynchronous = $bAsynchronous;
  54. $this->m_aParams = $aParams;
  55. $this->m_oSet = $oSet;
  56. }
  57. /**
  58. * Constructs a DisplayBlock object from a DBObjectSet already in memory
  59. * @param $oSet DBObjectSet
  60. * @return DisplayBlock The DisplayBlock object, or null if the creation failed
  61. */
  62. public static function FromObjectSet(DBObjectSet $oSet, $sStyle, $aParams = array())
  63. {
  64. $oDummyFilter = new DBObjectSearch($oSet->GetClass());
  65. $oBlock = new DisplayBlock($oDummyFilter, $sStyle, false, $aParams, $oSet); // DisplayBlocks built this way are synchronous
  66. return $oBlock;
  67. }
  68. /**
  69. * Constructs a DisplayBlock object from an XML template
  70. * @param $sTemplate string The XML template
  71. * @return DisplayBlock The DisplayBlock object, or null if the template is invalid
  72. */
  73. public static function FromTemplate($sTemplate)
  74. {
  75. $iStartPos = stripos($sTemplate, '<'.self::TAG_BLOCK.' ',0);
  76. $iEndPos = stripos($sTemplate, '</'.self::TAG_BLOCK.'>', $iStartPos);
  77. $iEndTag = stripos($sTemplate, '>', $iStartPos);
  78. $aParams = array();
  79. if (($iStartPos === false) || ($iEndPos === false)) return null; // invalid template
  80. $sITopBlock = substr($sTemplate,$iStartPos, $iEndPos-$iStartPos+strlen('</'.self::TAG_BLOCK.'>'));
  81. $sITopData = substr($sTemplate, 1+$iEndTag, $iEndPos - $iEndTag - 1);
  82. $sITopTag = substr($sTemplate, $iStartPos + strlen('<'.self::TAG_BLOCK), $iEndTag - $iStartPos - strlen('<'.self::TAG_BLOCK));
  83. $aMatches = array();
  84. $sBlockClass = "DisplayBlock";
  85. $bAsynchronous = false;
  86. $sBlockType = 'list';
  87. $sEncoding = 'text/serialize';
  88. if (preg_match('/ type="(.*)"/U',$sITopTag, $aMatches))
  89. {
  90. $sBlockType = strtolower($aMatches[1]);
  91. }
  92. if (preg_match('/ asynchronous="(.*)"/U',$sITopTag, $aMatches))
  93. {
  94. $bAsynchronous = (strtolower($aMatches[1]) == 'true');
  95. }
  96. if (preg_match('/ blockclass="(.*)"/U',$sITopTag, $aMatches))
  97. {
  98. $sBlockClass = $aMatches[1];
  99. }
  100. if (preg_match('/ objectclass="(.*)"/U',$sITopTag, $aMatches))
  101. {
  102. $sObjectClass = $aMatches[1];
  103. }
  104. if (preg_match('/ encoding="(.*)"/U',$sITopTag, $aMatches))
  105. {
  106. $sEncoding = strtolower($aMatches[1]);
  107. }
  108. if (preg_match('/ link_attr="(.*)"/U',$sITopTag, $aMatches))
  109. {
  110. // The list to display is a list of links to the specified object
  111. $aParams['link_attr'] = $aMatches[1]; // Name of the Ext. Key that makes this linkage
  112. }
  113. if (preg_match('/ target_attr="(.*)"/U',$sITopTag, $aMatches))
  114. {
  115. // The list to display is a list of links to the specified object
  116. $aParams['target_attr'] = $aMatches[1]; // Name of the Ext. Key that make this linkage
  117. }
  118. if (preg_match('/ object_id="(.*)"/U',$sITopTag, $aMatches))
  119. {
  120. // The list to display is a list of links to the specified object
  121. $aParams['object_id'] = $aMatches[1]; // Id of the object to be linked to
  122. }
  123. // Parameters contains a list of extra parameters for the block
  124. // the syntax is param_name1:value1;param_name2:value2;...
  125. if (preg_match('/ parameters="(.*)"/U',$sITopTag, $aMatches))
  126. {
  127. $sParameters = $aMatches[1];
  128. $aPairs = explode(';', $sParameters);
  129. foreach($aPairs as $sPair)
  130. {
  131. if (preg_match('/(.*)\:(.*)/',$sPair, $aMatches))
  132. {
  133. $aParams[trim($aMatches[1])] = trim($aMatches[2]);
  134. }
  135. }
  136. }
  137. if (!empty($aParams['link_attr']))
  138. {
  139. // Check that all mandatory parameters are present:
  140. if(empty($aParams['object_id']))
  141. {
  142. // if 'links' mode is requested the d of the object to link to must be specified
  143. throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_object_id'));
  144. }
  145. if(empty($aParams['target_attr']))
  146. {
  147. // if 'links' mode is requested the id of the object to link to must be specified
  148. throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_target_attr'));
  149. }
  150. }
  151. switch($sEncoding)
  152. {
  153. case 'text/serialize':
  154. $oFilter = CMDBSearchFilter::unserialize($sITopData);
  155. break;
  156. case 'text/oql':
  157. $oFilter = CMDBSearchFilter::FromOQL($sITopData);
  158. break;
  159. }
  160. return new $sBlockClass($oFilter, $sBlockType, $bAsynchronous, $aParams);
  161. }
  162. public function Display(WebPage $oPage, $sId, $aExtraParams = array())
  163. {
  164. $oPage->add($this->GetDisplay($oPage, $sId, $aExtraParams));
  165. /*
  166. $aExtraParams = array_merge($aExtraParams, $this->m_aParams);
  167. $aExtraParams['block_id'] = $sId;
  168. if (!$this->m_bAsynchronous)
  169. {
  170. // render now
  171. $oPage->add("<div id=\"$sId\" class=\"display_block\">\n");
  172. $this->RenderContent($oPage, $aExtraParams);
  173. $oPage->add("</div>\n");
  174. }
  175. else
  176. {
  177. // render it as an Ajax (asynchronous) call
  178. $sFilter = $this->m_oFilter->serialize();
  179. $oPage->add("<div id=\"$sId\" class=\"display_block loading\">\n");
  180. $oPage->p("<img src=\"../images/indicator_arrows.gif\"> Loading...");
  181. $oPage->add("</div>\n");
  182. $oPage->add('
  183. <script language="javascript">
  184. $.post("ajax.render.php?style='.$this->m_sStyle.'",
  185. { operation: "ajax", filter: "$sFilter" },
  186. function(data){
  187. $("#'.$sId.'").empty();
  188. $("#'.$sId.'").append(data);
  189. $("#'.$sId.'").removeClass("loading");
  190. }
  191. );
  192. </script>'); // TO DO: add support for $aExtraParams in asynchronous/Ajax mode
  193. }
  194. */
  195. }
  196. public function GetDisplay(WebPage $oPage, $sId, $aExtraParams = array())
  197. {
  198. $sHtml = '';
  199. $aExtraParams = array_merge($aExtraParams, $this->m_aParams);
  200. $aExtraParams['block_id'] = $sId;
  201. $sExtraParams = addslashes(str_replace('"', "'", json_encode($aExtraParams))); // JSON encode, change the style of the quotes and escape them
  202. $bAutoReload = false;
  203. if (isset($aExtraParams['auto_reload']))
  204. {
  205. switch($aExtraParams['auto_reload'])
  206. {
  207. case 'fast':
  208. $bAutoReload = true;
  209. $iReloadInterval = utils::GetConfig()->GetFastReloadInterval()*1000;
  210. break;
  211. case 'standard':
  212. case 'true':
  213. case true:
  214. $bAutoReload = true;
  215. $iReloadInterval = utils::GetConfig()->GetStandardReloadInterval()*1000;
  216. break;
  217. default:
  218. if (is_numeric($aExtraParams['auto_reload']))
  219. {
  220. $bAutoReload = true;
  221. $iReloadInterval = $aExtraParams['auto_reload']*1000;
  222. }
  223. else
  224. {
  225. // incorrect config, ignore it
  226. $bAutoReload = false;
  227. }
  228. }
  229. }
  230. $sFilter = $this->m_oFilter->serialize(); // Used either for asynchronous or auto_reload
  231. if (!$this->m_bAsynchronous)
  232. {
  233. // render now
  234. $sHtml .= "<div id=\"$sId\" class=\"display_block\">\n";
  235. $sHtml .= $this->GetRenderContent($oPage, $aExtraParams);
  236. $sHtml .= "</div>\n";
  237. }
  238. else
  239. {
  240. // render it as an Ajax (asynchronous) call
  241. $sHtml .= "<div id=\"$sId\" class=\"display_block loading\">\n";
  242. $sHtml .= $oPage->GetP("<img src=\"../images/indicator_arrows.gif\"> ".Dict::S('UI:Loading'));
  243. $sHtml .= "</div>\n";
  244. $sHtml .= '
  245. <script language="javascript">
  246. $.post("ajax.render.php?style='.$this->m_sStyle.'",
  247. { operation: "ajax", filter: "'.$sFilter.'", extra_params: "'.$sExtraParams.'" },
  248. function(data){
  249. $("#'.$sId.'").empty();
  250. $("#'.$sId.'").append(data);
  251. $("#'.$sId.'").removeClass("loading");
  252. $("#'.$sId.' .listResults").tablesorter( { headers: { 0:{sorter: false }}, widgets: [\'zebra\']} ); // sortable and zebra tables
  253. }
  254. );
  255. </script>';
  256. }
  257. if ($bAutoReload)
  258. {
  259. $sHtml .= '
  260. <script language="javascript">
  261. setInterval("ReloadBlock(\''.$sId.'\', \''.$this->m_sStyle.'\', \''.$sFilter.'\', \"'.$sExtraParams.'\")", '.$iReloadInterval.');
  262. </script>';
  263. }
  264. return $sHtml;
  265. }
  266. public function RenderContent(WebPage $oPage, $aExtraParams = array())
  267. {
  268. $oPage->add($this->GetRenderContent($oPage, $aExtraParams));
  269. }
  270. public function GetRenderContent(WebPage $oPage, $aExtraParams = array())
  271. {
  272. $sHtml = '';
  273. // Add the extra params into the filter if they make sense for such a filter
  274. $bDoSearch = utils::ReadParam('dosearch', false);
  275. if ($this->m_oSet == null)
  276. {
  277. if ($this->m_sStyle != 'links')
  278. {
  279. $aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass()));
  280. foreach($aFilterCodes as $sFilterCode)
  281. {
  282. $sExternalFilterValue = utils::ReadParam($sFilterCode, '');
  283. if (isset($aExtraParams[$sFilterCode]))
  284. {
  285. $this->m_oFilter->AddCondition($sFilterCode, $aExtraParams[$sFilterCode]); // Use the default 'loose' operator
  286. }
  287. else if ($bDoSearch && $sExternalFilterValue != "")
  288. {
  289. $this->m_oFilter->AddCondition($sFilterCode, $sExternalFilterValue); // Use the default 'loose' operator
  290. }
  291. }
  292. }
  293. $this->m_oSet = new CMDBObjectSet($this->m_oFilter);
  294. }
  295. switch($this->m_sStyle)
  296. {
  297. case 'count':
  298. if (isset($aExtraParams['group_by']))
  299. {
  300. $sGroupByField = $aExtraParams['group_by'];
  301. $aGroupBy = array();
  302. $sLabels = array();
  303. while($oObj = $this->m_oSet->Fetch())
  304. {
  305. $sValue = $oObj->Get($sGroupByField);
  306. $aGroupBy[$sValue] = isset($aGroupBy[$sValue]) ? $aGroupBy[$sValue]+1 : 1;
  307. $sLabels[$sValue] = $oObj->GetAsHtml($sGroupByField);
  308. }
  309. $sFilter = urlencode($this->m_oFilter->serialize());
  310. $aData = array();
  311. $oAppContext = new ApplicationContext();
  312. $sParams = $oAppContext->GetForLink();
  313. foreach($aGroupBy as $sValue => $iCount)
  314. {
  315. $aData[] = array ( 'group' => $sLabels[$sValue],
  316. 'value' => "<a href=\"./UI.php?operation=search&dosearch=1&$sParams&filter=$sFilter&$sGroupByField=".urlencode($sValue)."\">$iCount</a>"); // TO DO: add the context information
  317. }
  318. $aAttribs =array(
  319. 'group' => array('label' => MetaModel::GetLabel($this->m_oFilter->GetClass(), $sGroupByField), 'description' => ''),
  320. 'value' => array('label'=> Dict::S('UI:GroupBy:Count'), 'description' => Dict::S('UI:GroupBy:Count+'))
  321. );
  322. $sHtml .= $oPage->GetTable($aAttribs, $aData);
  323. }
  324. else
  325. {
  326. // Simply count the number of elements in the set
  327. $iCount = $oSet->Count();
  328. $sHtml .= $oPage->GetP(Dict::Format('UI:CountOfObjects', $iCount));
  329. }
  330. break;
  331. case 'join':
  332. $aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', $aExtraParams['display_aliases']): array();
  333. if (!isset($aExtraParams['group_by']))
  334. {
  335. $sHtml .= $oPage->GetP(Dict::S('UI:Error:MandatoryTemplateParameter_group_by'));
  336. }
  337. else
  338. {
  339. $aGroupByFields = array();
  340. $aGroupBy = explode(',', $aExtraParams['group_by']);
  341. foreach($aGroupBy as $sGroupBy)
  342. {
  343. $aMatches = array();
  344. if (preg_match('/^(.+)\.(.+)$/', $sGroupBy, $aMatches) > 0)
  345. {
  346. $aGroupByFields[] = array('alias' => $aMatches[1], 'att_code' => $aMatches[2]);
  347. }
  348. }
  349. if (count($aGroupByFields) == 0)
  350. {
  351. $sHtml .= $oPage->GetP(Dict::Format('UI:Error:InvalidGroupByFields', $aExtraParams['group_by']));
  352. }
  353. else
  354. {
  355. $aResults = array();
  356. $aCriteria = array();
  357. while($aObjects = $this->m_oSet->FetchAssoc())
  358. {
  359. $aKeys = array();
  360. foreach($aGroupByFields as $aField)
  361. {
  362. $aKeys[$aField['alias'].'.'.$aField['att_code']] = $aObjects[$aField['alias']]->Get($aField['att_code']);
  363. }
  364. $sCategory = implode($aKeys, ' ');
  365. $aResults[$sCategory][] = $aObjects;
  366. $aCriteria[$sCategory] = $aKeys;
  367. }
  368. $sHtml .= "<table>\n";
  369. // Construct a new (parametric) query that will return the content of this block
  370. $oBlockFilter = clone $this->m_oFilter;
  371. $aExpressions = array();
  372. $index = 0;
  373. foreach($aGroupByFields as $aField)
  374. {
  375. $aExpressions[] = '`'.$aField['alias'].'`.`'.$aField['att_code'].'` = :param'.$index++;
  376. }
  377. $sExpression = implode(' AND ', $aExpressions);
  378. $oExpression = Expression::FromOQL($sExpression);
  379. $oBlockFilter->AddConditionExpression($oExpression);
  380. $aExtraParams['menu'] = false;
  381. foreach($aResults as $sCategory => $aObjects)
  382. {
  383. $sHtml .= "<tr><td><h1>$sCategory</h1></td></tr>\n";
  384. if (count($aDisplayAliases) == 1)
  385. {
  386. $aSimpleArray = array();
  387. foreach($aObjects as $aRow)
  388. {
  389. $aSimpleArray[] = $aRow[$aDisplayAliases[0]];
  390. }
  391. $oSet = CMDBObjectSet::FromArray($this->m_oFilter->GetClass(), $aSimpleArray);
  392. $sHtml .= "<tr><td>".cmdbAbstractObject::GetDisplaySet($oPage, $oSet, $aExtraParams)."</td></tr>\n";
  393. }
  394. else
  395. {
  396. $index = 0;
  397. $aArgs = array();
  398. foreach($aGroupByFields as $aField)
  399. {
  400. $aArgs['param'.$index] = $aCriteria[$sCategory][$aField['alias'].'.'.$aField['att_code']];
  401. $index++;
  402. }
  403. $oSet = new CMDBObjectSet($oBlockFilter, array(), $aArgs);
  404. $sHtml .= "<tr><td>".cmdbAbstractObject::GetDisplayExtendedSet($oPage, $oSet, $aExtraParams)."</td></tr>\n";
  405. }
  406. }
  407. $sHtml .= "</table>\n";
  408. }
  409. }
  410. break;
  411. case 'list':
  412. $aClasses = $this->m_oSet->GetSelectedClasses();
  413. $aAuthorizedClasses = array();
  414. if (count($aClasses) > 1)
  415. {
  416. // Check the classes that can be read (i.e authorized) by this user...
  417. foreach($aClasses as $sAlias => $sClassName)
  418. {
  419. if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES)
  420. {
  421. $aAuthorizedClasses[$sAlias] = $sClassName;
  422. }
  423. }
  424. if (count($aAuthorizedClasses) > 0)
  425. {
  426. if($this->m_oSet->Count() > 0)
  427. {
  428. $sHtml .= cmdbAbstractObject::GetDisplayExtendedSet($oPage, $this->m_oSet, $aExtraParams);
  429. }
  430. else
  431. {
  432. // Empty set
  433. $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay'));
  434. }
  435. }
  436. else
  437. {
  438. // Not authorized
  439. $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay'));
  440. }
  441. }
  442. else
  443. {
  444. // The list is made of only 1 class of objects, actions on the list are possible
  445. if ( ($this->m_oSet->Count()> 0) && (UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES) )
  446. {
  447. $sHtml .= cmdbAbstractObject::GetDisplaySet($oPage, $this->m_oSet, $aExtraParams);
  448. }
  449. else
  450. {
  451. $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay'));
  452. $sClass = $this->m_oFilter->GetClass();
  453. $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true;
  454. if ($bDisplayMenu)
  455. {
  456. if ((UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES)
  457. && !MetaModel::IsReadOnlyClass($sClass))
  458. {
  459. $oAppContext = new ApplicationContext();
  460. $sParams = $oAppContext->GetForLink();
  461. // 1:n links, populate the target object as a default value when creating a new linked object
  462. if (isset($aExtraParams['target_attr']))
  463. {
  464. $aExtraParams['default'][$aExtraParams['target_attr']] = $aExtraParams['object_id'];
  465. }
  466. $sDefault = '';
  467. if (!empty($aExtraParams['default']))
  468. {
  469. foreach($aExtraParams['default'] as $sKey => $sValue)
  470. {
  471. $sDefault.= "&default[$sKey]=$sValue";
  472. }
  473. }
  474. $sHtml .= $oPage->GetP("<a href=\"./UI.php?operation=new&class=$sClass&$sParams{$sDefault}\">".Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass))."</a>\n");
  475. }
  476. }
  477. }
  478. }
  479. break;
  480. case 'links':
  481. //$bDashboardMode = isset($aExtraParams['dashboard']) ? ($aExtraParams['dashboard'] == 'true') : false;
  482. //$bSelectMode = isset($aExtraParams['select']) ? ($aExtraParams['select'] == 'true') : false;
  483. if ( ($this->m_oSet->Count()> 0) && (UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES) )
  484. {
  485. //$sLinkage = isset($aExtraParams['linkage']) ? $aExtraParams['linkage'] : '';
  486. $sHtml .= cmdbAbstractObject::GetDisplaySet($oPage, $this->m_oSet, $aExtraParams);
  487. }
  488. else
  489. {
  490. $sClass = $this->m_oFilter->GetClass();
  491. $oAttDef = MetaModel::GetAttributeDef($sClass, $this->m_aParams['target_attr']);
  492. $sTargetClass = $oAttDef->GetTargetClass();
  493. $sHtml .= $oPage->GetP(Dict::Format('UI:NoObject_Class_ToDisplay', MetaModel::GetName($sTargetClass)));
  494. $bDisplayMenu = isset($this->m_aParams['menu']) ? $this->m_aParams['menu'] == true : true;
  495. if ($bDisplayMenu)
  496. {
  497. if ((UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES)
  498. && (!MetaModel::IsReadOnlyClass($sClass)))
  499. {
  500. $oAppContext = new ApplicationContext();
  501. $sParams = $oAppContext->GetForLink();
  502. $sHtml .= $oPage->GetP("<a href=\"../pages/UI.php?operation=modify_links&class=$sClass&sParams&link_attr=".$aExtraParams['link_attr']."&id=".$aExtraParams['object_id']."&target_class=$sTargetClass&addObjects=true\">".Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass))."</a>\n");
  503. }
  504. }
  505. }
  506. break;
  507. case 'details':
  508. if (UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES)
  509. {
  510. while($oObj = $this->m_oSet->Fetch())
  511. {
  512. $sHtml .= $oObj->GetDetails($oPage); // Still used ???
  513. }
  514. }
  515. break;
  516. case 'bare_details':
  517. if (UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES)
  518. {
  519. while($oObj = $this->m_oSet->Fetch())
  520. {
  521. $sHtml .= $oObj->GetBareProperties($oPage);
  522. }
  523. }
  524. break;
  525. case 'csv':
  526. if (UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES)
  527. {
  528. $sHtml .= "<textarea style=\"width:95%;height:98%\">\n";
  529. $sHtml .= cmdbAbstractObject::GetSetAsCSV($this->m_oSet);
  530. $sHtml .= "</textarea>\n";
  531. }
  532. break;
  533. case 'modify':
  534. if ((UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_MODIFY, $this->m_oSet) == UR_ALLOWED_YES)
  535. && !MetaModel::IsReadOnlyClass($this->m_oSet->GetClass()))
  536. {
  537. while($oObj = $this->m_oSet->Fetch())
  538. {
  539. $sHtml .= $oObj->GetModifyForm($oPage);
  540. }
  541. }
  542. break;
  543. case 'search':
  544. static $iSearchSectionId = 1;
  545. $sStyle = (isset($aExtraParams['open']) && ($aExtraParams['open'] == 'true')) ? 'SearchDrawer' : 'SearchDrawer DrawerClosed';
  546. $sHtml .= "<div id=\"Search_$iSearchSectionId\" class=\"$sStyle\">\n";
  547. $oPage->add_ready_script(
  548. <<<EOF
  549. $("#LnkSearch_$iSearchSectionId").click( function() {
  550. $("#Search_$iSearchSectionId").slideToggle('normal', function() { $("#Search_$iSearchSectionId").parent().resize(); } );
  551. $("#LnkSearch_$iSearchSectionId").toggleClass('open');
  552. });
  553. EOF
  554. );
  555. $sHtml .= cmdbAbstractObject::GetSearchForm($oPage, $this->m_oSet, $aExtraParams);
  556. $sHtml .= "</div>\n";
  557. $sHtml .= "<div class=\"HRDrawer\"></div>\n";
  558. $sHtml .= "<div id=\"LnkSearch_$iSearchSectionId\" class=\"DrawerHandle\">".Dict::S('UI:SearchToggle')."</div>\n";
  559. $iSearchSectionId++;
  560. break;
  561. case 'open_flash_chart':
  562. static $iChartCounter = 0;
  563. $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie';
  564. $sTitle = isset($aExtraParams['chart_title']) ? $aExtraParams['chart_title'] : '';
  565. $sGroupBy = isset($aExtraParams['group_by']) ? $aExtraParams['group_by'] : '';
  566. $sFilter = $this->m_oFilter->ToOQL();
  567. $sHtml .= "<div id=\"my_chart_{$iChartCounter}\">If the chart does not display, <a href=\"http://get.adobe.com/flash/\" target=\"_blank\">install Flash</a></div>\n";
  568. $oPage->add_script("function ofc_resize(left, width, top, height) { /* do nothing special */ }");
  569. $oPage->add_ready_script("swfobject.embedSWF(\"../images/open-flash-chart.swf\", \"my_chart_{$iChartCounter}\", \"100%\", \"300\",\"9.0.0\", \"expressInstall.swf\",
  570. {\"data-file\":\"".urlencode("../pages/ajax.render.php?operation=open_flash_chart&params[group_by]=$sGroupBy&params[chart_type]=$sChartType&params[chart_title]=$sTitle&encoding=oql&filter=".urlencode($sFilter))."\"}, {wmode: 'transparent'} );\n");
  571. $iChartCounter++;
  572. break;
  573. case 'open_flash_chart_ajax':
  574. include '../pages/php-ofc-library/open-flash-chart.php';
  575. $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie';
  576. $oChart = new open_flash_chart();
  577. switch($sChartType)
  578. {
  579. case 'bars':
  580. $oChartElement = new bar_glass();
  581. if (isset($aExtraParams['group_by']))
  582. {
  583. $sGroupByField = $aExtraParams['group_by'];
  584. $aGroupBy = array();
  585. while($oObj = $this->m_oSet->Fetch())
  586. {
  587. $sValue = $oObj->Get($sGroupByField);
  588. $aGroupBy[$sValue] = isset($aGroupBy[$sValue]) ? $aGroupBy[$sValue]+1 : 1;
  589. }
  590. $sFilter = urlencode($this->m_oFilter->serialize());
  591. $aData = array();
  592. $aLabels = array();
  593. foreach($aGroupBy as $sValue => $iValue)
  594. {
  595. $aData[] = $iValue;
  596. $aLabels[] = $sValue;
  597. }
  598. $maxValue = max($aData);
  599. $oYAxis = new y_axis();
  600. $aMagicValues = array(1,2,5,10);
  601. $iMultiplier = 1;
  602. $index = 0;
  603. $iTop = $aMagicValues[$index % count($aMagicValues)]*$iMultiplier;
  604. while($maxValue > $iTop)
  605. {
  606. $index++;
  607. $iTop = $aMagicValues[$index % count($aMagicValues)]*$iMultiplier;
  608. if (($index % count($aMagicValues)) == 0)
  609. {
  610. $iMultiplier = $iMultiplier * 10;
  611. }
  612. }
  613. //echo "oYAxis->set_range(0, $iTop, $iMultiplier);\n";
  614. $oYAxis->set_range(0, $iTop, $iMultiplier);
  615. $oChart->set_y_axis( $oYAxis );
  616. $oChartElement->set_values( $aData );
  617. $oXAxis = new x_axis();
  618. $oXLabels = new x_axis_labels();
  619. // set them vertical
  620. $oXLabels->set_vertical();
  621. // set the label text
  622. $oXLabels->set_labels($aLabels);
  623. // Add the X Axis Labels to the X Axis
  624. $oXAxis->set_labels( $oXLabels );
  625. $oChart->set_x_axis( $oXAxis );
  626. }
  627. break;
  628. case 'pie':
  629. default:
  630. $oChartElement = new pie();
  631. $oChartElement->set_start_angle( 35 );
  632. $oChartElement->set_animate( true );
  633. $oChartElement->set_tooltip( '#label# - #val# (#percent#)' );
  634. $oChartElement->set_colours( array('#FF8A00', '#909980', '#2C2B33', '#CCC08D', '#596664') );
  635. if (isset($aExtraParams['group_by']))
  636. {
  637. $sGroupByField = $aExtraParams['group_by'];
  638. $aGroupBy = array();
  639. while($oObj = $this->m_oSet->Fetch())
  640. {
  641. $sValue = $oObj->Get($sGroupByField);
  642. $aGroupBy[$sValue] = isset($aGroupBy[$sValue]) ? $aGroupBy[$sValue]+1 : 1;
  643. }
  644. $sFilter = urlencode($this->m_oFilter->serialize());
  645. $aData = array();
  646. foreach($aGroupBy as $sValue => $iValue)
  647. {
  648. $aData[] = new pie_value($iValue, $sValue); //@@ BUG: not passed via ajax !!!
  649. }
  650. $oChartElement->set_values( $aData );
  651. $oChart->x_axis = null;
  652. }
  653. }
  654. if (isset($aExtraParams['chart_title']))
  655. {
  656. $oTitle = new title( Dict::S($aExtraParams['chart_title']) );
  657. $oChart->set_title( $oTitle );
  658. }
  659. $oChart->set_bg_colour('#FFFFFF');
  660. $oChart->add_element( $oChartElement );
  661. $sHtml = $oChart->toPrettyString();
  662. break;
  663. default:
  664. // Unsupported style, do nothing.
  665. $sHtml .= Dict::format('UI:Error:UnsupportedStyleOfBlock', $this->m_sStyle);
  666. }
  667. return $sHtml;
  668. }
  669. }
  670. /**
  671. * Helper class to manage 'blocks' of HTML pieces that are parts of a page and contain some list of cmdb objects
  672. *
  673. * Each block is actually rendered as a <div></div> tag that can be rendered synchronously
  674. * or as a piece of Javascript/JQuery/Ajax that will get its content from another page (ajax.render.php).
  675. * The list of cmdbObjects to be displayed into the block is defined by a filter
  676. * Right now the type of display is either: list, count or details
  677. * - list produces a table listing the objects
  678. * - count produces a paragraphs with a sentence saying 'cont' objects found
  679. * - details display (as table) the details of each object found (best if only one)
  680. */
  681. class HistoryBlock extends DisplayBlock
  682. {
  683. public function GetRenderContent(WebPage $oPage, $aExtraParams = array())
  684. {
  685. $sHtml = '';
  686. $oSet = new CMDBObjectSet($this->m_oFilter, array('date'=>false));
  687. $sHtml .= "<!-- filter: ".($this->m_oFilter->ToOQL())."-->\n";
  688. switch($this->m_sStyle)
  689. {
  690. case 'toggle':
  691. // First the latest change that the user is allowed to see
  692. do
  693. {
  694. $oLatestChangeOp = $oSet->Fetch();
  695. }
  696. while(is_object($oLatestChangeOp) && ($oLatestChangeOp->GetDescription() == ''));
  697. if (is_object($oLatestChangeOp))
  698. {
  699. $oContext = new UserContext();
  700. // There is one change in the list... only when the object has been created !
  701. $sDate = $oLatestChangeOp->GetAsHTML('date');
  702. $oChange = $oContext->GetObject('CMDBChange', $oLatestChangeOp->Get('change'));
  703. $sUserInfo = $oChange->GetAsHTML('userinfo');
  704. $sHtml .= $oPage->GetStartCollapsibleSection(Dict::Format('UI:History:LastModified_On_By', $sDate, $sUserInfo));
  705. $sHtml .= $this->GetHistoryTable($oPage, $oSet);
  706. $sHtml .= $oPage->GetEndCollapsibleSection();
  707. }
  708. break;
  709. case 'table':
  710. default:
  711. $sHtml .= $this->GetHistoryTable($oPage, $oSet);
  712. }
  713. return $sHtml;
  714. }
  715. protected function GetHistoryTable(WebPage $oPage, DBObjectSet $oSet)
  716. {
  717. $sHtml = '';
  718. // First the latest change that the user is allowed to see
  719. $oSet->Rewind(); // Reset the pointer to the beginning of the set
  720. $aChanges = array();
  721. while($oChangeOp = $oSet->Fetch())
  722. {
  723. $sChangeDescription = $oChangeOp->GetDescription();
  724. if ($sChangeDescription != '')
  725. {
  726. // The change is visible for the current user
  727. $changeId = $oChangeOp->Get('change');
  728. $aChanges[$changeId]['date'] = $oChangeOp->Get('date');
  729. $aChanges[$changeId]['userinfo'] = $oChangeOp->Get('userinfo');
  730. if (!isset($aChanges[$changeId]['log']))
  731. {
  732. $aChanges[$changeId]['log'] = array();
  733. }
  734. $aChanges[$changeId]['log'][] = $sChangeDescription;
  735. }
  736. }
  737. $aAttribs = array('date' => array('label' => Dict::S('UI:History:Date'), 'description' => Dict::S('UI:History:Date+')),
  738. 'userinfo' => array('label' => Dict::S('UI:History:User'), 'description' => Dict::S('UI:History:User+')),
  739. 'log' => array('label' => Dict::S('UI:History:Changes'), 'description' => Dict::S('UI:History:Changes+')),
  740. );
  741. $aValues = array();
  742. foreach($aChanges as $aChange)
  743. {
  744. $aValues[] = array('date' => $aChange['date'], 'userinfo' => $aChange['userinfo'], 'log' => "<ul><li>".implode('</li><li>', $aChange['log'])."</li></ul>");
  745. }
  746. $sHtml .= $oPage->GetTable($aAttribs, $aValues);
  747. return $sHtml;
  748. }
  749. }
  750. class MenuBlock extends DisplayBlock
  751. {
  752. /**
  753. * Renders the "Actions" popup menu for the given set of objects
  754. *
  755. * Note that the menu links containing (or ending) with a hash (#) will have their fragment
  756. * part (whatever is after the hash) dynamically replaced (by javascript) when the menu is
  757. * displayed, to correspond to the current hash/fragment in the page. This allows modifying
  758. * an object in with the same tab active by default as the tab that was active when selecting
  759. * the "Modify..." action.
  760. */
  761. public function GetRenderContent(WebPage $oPage, $aExtraParams = array())
  762. {
  763. $sHtml = '';
  764. $oAppContext = new ApplicationContext();
  765. $sContext = $oAppContext->GetForLink();
  766. $sClass = $this->m_oFilter->GetClass();
  767. $oSet = new CMDBObjectSet($this->m_oFilter);
  768. $sFilter = $this->m_oFilter->serialize();
  769. $aActions = array();
  770. $sUIPage = cmdbAbstractObject::ComputeUIPage($sClass);
  771. // 1:n links, populate the target object as a default value when creating a new linked object
  772. if (isset($aExtraParams['target_attr']))
  773. {
  774. $aExtraParams['default'][$aExtraParams['target_attr']] = $aExtraParams['object_id'];
  775. }
  776. $sDefault = '';
  777. if (!empty($aExtraParams['default']))
  778. {
  779. foreach($aExtraParams['default'] as $sKey => $sValue)
  780. {
  781. $sDefault.= "&default[$sKey]=$sValue";
  782. }
  783. }
  784. switch($oSet->Count())
  785. {
  786. case 0:
  787. // No object in the set, the only possible action is "new"
  788. $bIsModifyAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) && !MetaModel::IsReadOnlyClass($sClass);
  789. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:New'), 'url' => "../page/$sUIPage?operation=new&class=$sClass&$sContext{$sDefault}"); }
  790. break;
  791. case 1:
  792. $oObj = $oSet->Fetch();
  793. $id = $oObj->GetKey();
  794. $bIsModifyAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_YES) && !MetaModel::IsReadOnlyClass($sClass);
  795. $bIsDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  796. $bIsBulkModifyAllowed = (!MetaModel::IsAbstract($sClass)) && UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  797. $bIsBulkDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  798. // Just one object in the set, possible actions are "new / clone / modify and delete"
  799. if (isset($aExtraParams['link_attr']))
  800. {
  801. $id = $aExtraParams['object_id'];
  802. $sTargetAttr = $aExtraParams['target_attr'];
  803. $oAttDef = MetaModel::GetAttributeDef($sClass, $sTargetAttr);
  804. $sTargetClass = $oAttDef->GetTargetClass();
  805. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:Add'), 'url' => "../pages/$sUIPage?operation=modify_links&class=$sClass&link_attr=".$aExtraParams['link_attr']."&target_class=$sTargetClass&id=$id&addObjects=true&$sContext"); }
  806. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:Manage'), 'url' => "../pages/$sUIPage?operation=modify_links&class=$sClass&link_attr=".$aExtraParams['link_attr']."&target_class=$sTargetClass&id=$id&sContext"); }
  807. //if ($bIsDeleteAllowed) { $aActions[] = array ('label' => 'Remove All', 'url' => "#"); }
  808. }
  809. else
  810. {
  811. $sUrl = utils::GetAbsoluteUrl();
  812. $aActions[] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=".$oSet->GetFilter()->__DescribeHTML()."&body=".urlencode("$sUrl?operation=search&filter=$sFilter&$sContext"));
  813. $aActions[] = array ('label' => Dict::S('UI:Menu:CSVExport'), 'url' => "../pages/$sUIPage?operation=search&filter=$sFilter&format=csv&$sContext");
  814. //$aActions[] = array ('label' => 'Bookmark...', 'url' => "../pages/ajax.render.php?operation=create&class=$sClass&filter=$sFilter", 'class' => 'jqmTrigger');
  815. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:New'), 'url' => "../pages/$sUIPage?operation=new&class=$sClass&$sContext{$sDefault}"); }
  816. //if ($bIsModifyAllowed) { $aActions[] = array ('label' => 'Clone...', 'url' => "../pages/$sUIPage?operation=clone&class=$sClass&id=$id&$sContext"); }
  817. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:Modify'), 'url' => "../pages/$sUIPage?operation=modify&class=$sClass&id=$id&$sContext#"); }
  818. if ($bIsDeleteAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:Delete'), 'url' => "../pages/$sUIPage?operation=delete&class=$sClass&id=$id&$sContext"); }
  819. $aRelations = MetaModel::EnumRelations($sClass);
  820. foreach($aRelations as $sRelationCode)
  821. {
  822. $aActions[] = array ('label' => MetaModel::GetRelationVerbUp($sRelationCode), 'url' => "../pages/$sUIPage?operation=swf_navigator&relation=$sRelationCode&class=$sClass&id=$id&$sContext");
  823. }
  824. }
  825. $aTransitions = $oObj->EnumTransitions();
  826. $aStimuli = Metamodel::EnumStimuli($sClass);
  827. foreach($aTransitions as $sStimulusCode => $aTransitionDef)
  828. {
  829. $iActionAllowed = (get_class($aStimuli[$sStimulusCode]) == 'StimulusUserAction') ? UserRights::IsStimulusAllowed($sClass, $sStimulusCode, $oSet) : UR_ALLOWED_NO;
  830. switch($iActionAllowed)
  831. {
  832. case UR_ALLOWED_YES:
  833. $aActions[] = array('label' => $aStimuli[$sStimulusCode]->GetLabel(), 'url' => "../pages/UI.php?operation=stimulus&stimulus=$sStimulusCode&class=$sClass&id=$id&$sContext");
  834. break;
  835. case UR_ALLOWED_DEPENDS:
  836. $aActions[] = array('label' => $aStimuli[$sStimulusCode]->GetLabel().' (*)', 'url' => "../pages/UI.php?operation=stimulus&stimulus=$sStimulusCode&class=$sClass&id=$id&$sContext");
  837. break;
  838. default:
  839. // Do nothing
  840. }
  841. }
  842. //print_r($aTransitions);
  843. break;
  844. default:
  845. // Check rights
  846. // New / Modify
  847. $bIsModifyAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  848. $bIsBulkModifyAllowed = (!MetaModel::IsAbstract($sClass)) && UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  849. $bIsBulkDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  850. if (isset($aExtraParams['link_attr']))
  851. {
  852. $id = $aExtraParams['object_id'];
  853. $sTargetAttr = $aExtraParams['target_attr'];
  854. $oAttDef = MetaModel::GetAttributeDef($sClass, $sTargetAttr);
  855. $sTargetClass = $oAttDef->GetTargetClass();
  856. $bIsDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  857. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:Add'), 'url' => "../pages/$sUIPage?operation=modify_links&class=$sClass&link_attr=".$aExtraParams['link_attr']."&target_class=$sTargetClass&id=$id&addObjects=true&$sContext"); }
  858. //if ($bIsBulkModifyAllowed) { $aActions[] = array ('label' => 'Add...', 'url' => "../pages/$sUIPage?operation=modify_links&class=$sClass&linkage=".$aExtraParams['linkage']."&id=$id&addObjects=true&$sContext"); }
  859. if ($bIsBulkModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:Manage'), 'url' => "../pages/$sUIPage?operation=modify_links&class=$sClass&link_attr=".$aExtraParams['link_attr']."&target_class=$sTargetClass&id=$id&sContext"); }
  860. //if ($bIsBulkDeleteAllowed) { $aActions[] = array ('label' => 'Remove All...', 'url' => "#"); }
  861. }
  862. else
  863. {
  864. // many objects in the set, possible actions are: new / modify all / delete all
  865. $sUrl = utils::GetAbsoluteUrl();
  866. $aActions[] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=".$oSet->GetFilter()->__DescribeHTML()."&body=".urlencode("$sUrl?operation=search&filter=$sFilter&$sContext"));
  867. $aActions[] = array ('label' => Dict::S('UI:Menu:CSVExport'), 'url' => "../pages/$sUIPage?operation=search&filter=$sFilter&format=csv&$sContext");
  868. //$aActions[] = array ('label' => 'Bookmark...', 'url' => "../pages/ajax.render.php?operation=create&class=$sClass&filter=$sFilter", 'class' => 'jqmTrigger');
  869. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:New'), 'url' => "../pages/$sUIPage?operation=new&class=$sClass&$sContext{$sDefault}"); }
  870. //if ($bIsBulkModifyAllowed) { $aActions[] = array ('label' => 'Modify All...', 'url' => "../pages/$sUIPage?operation=modify_all&filter=$sFilter&$sContext"); }
  871. if ($bIsBulkDeleteAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:BulkDelete'), 'url' => "../pages/$sUIPage?operation=select_for_deletion&filter=$sFilter&$sContext"); }
  872. }
  873. }
  874. $sHtml .= "<div class=\"itop_popup\"><ul>\n<li>".Dict::S('UI:Menu:Actions')."\n<ul>\n";
  875. foreach ($aActions as $aAction)
  876. {
  877. $sClass = isset($aAction['class']) ? " class=\"{$aAction['class']}\"" : "";
  878. $sHtml .= "<li><a href=\"{$aAction['url']}\"$sClass>{$aAction['label']}</a></li>\n";
  879. }
  880. $sHtml .= "</ul>\n</li>\n</ul></div>\n";
  881. static $bPopupScript = false;
  882. if (!$bPopupScript)
  883. {
  884. // Output this once per page...
  885. $oPage->add_ready_script("$(\"div.itop_popup>ul\").popupmenu();\n");
  886. $bPopupScript = true;
  887. }
  888. return $sHtml;
  889. }
  890. }
  891. ?>