displayblock.class.inc.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  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("\$(\"#LnkSearch_$iSearchSectionId\").click(function() {\n" .
  548. " \$(\"#Search_$iSearchSectionId\").slideToggle('normal');\n" .
  549. " $(\"#LnkSearch_$iSearchSectionId\").toggleClass('open');});");
  550. $sHtml .= cmdbAbstractObject::GetSearchForm($oPage, $this->m_oSet, $aExtraParams);
  551. $sHtml .= "</div>\n";
  552. $sHtml .= "<div class=\"HRDrawer\"></div>\n";
  553. $sHtml .= "<div id=\"LnkSearch_$iSearchSectionId\" class=\"DrawerHandle\">".Dict::S('UI:SearchToggle')."</div>\n";
  554. $iSearchSectionId++;
  555. break;
  556. case 'open_flash_chart':
  557. static $iChartCounter = 0;
  558. $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie';
  559. $sTitle = isset($aExtraParams['chart_title']) ? $aExtraParams['chart_title'] : '';
  560. $sGroupBy = isset($aExtraParams['group_by']) ? $aExtraParams['group_by'] : '';
  561. $sFilter = $this->m_oFilter->ToOQL();
  562. $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";
  563. $oPage->add_script("function ofc_resize(left, width, top, height) { /* do nothing special */ }");
  564. $oPage->add_ready_script("swfobject.embedSWF(\"../images/open-flash-chart.swf\", \"my_chart_{$iChartCounter}\", \"100%\", \"300\",\"9.0.0\", \"expressInstall.swf\",
  565. {\"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");
  566. $iChartCounter++;
  567. break;
  568. case 'open_flash_chart_ajax':
  569. include '../pages/php-ofc-library/open-flash-chart.php';
  570. $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie';
  571. $oChart = new open_flash_chart();
  572. switch($sChartType)
  573. {
  574. case 'bars':
  575. $oChartElement = new bar_glass();
  576. if (isset($aExtraParams['group_by']))
  577. {
  578. $sGroupByField = $aExtraParams['group_by'];
  579. $aGroupBy = array();
  580. while($oObj = $this->m_oSet->Fetch())
  581. {
  582. $sValue = $oObj->Get($sGroupByField);
  583. $aGroupBy[$sValue] = isset($aGroupBy[$sValue]) ? $aGroupBy[$sValue]+1 : 1;
  584. }
  585. $sFilter = urlencode($this->m_oFilter->serialize());
  586. $aData = array();
  587. $aLabels = array();
  588. foreach($aGroupBy as $sValue => $iValue)
  589. {
  590. $aData[] = $iValue;
  591. $aLabels[] = $sValue;
  592. }
  593. $maxValue = max($aData);
  594. $oYAxis = new y_axis();
  595. $aMagicValues = array(1,2,5,10);
  596. $iMultiplier = 1;
  597. $index = 0;
  598. $iTop = $aMagicValues[$index % count($aMagicValues)]*$iMultiplier;
  599. while($maxValue > $iTop)
  600. {
  601. $index++;
  602. $iTop = $aMagicValues[$index % count($aMagicValues)]*$iMultiplier;
  603. if (($index % count($aMagicValues)) == 0)
  604. {
  605. $iMultiplier = $iMultiplier * 10;
  606. }
  607. }
  608. //echo "oYAxis->set_range(0, $iTop, $iMultiplier);\n";
  609. $oYAxis->set_range(0, $iTop, $iMultiplier);
  610. $oChart->set_y_axis( $oYAxis );
  611. $oChartElement->set_values( $aData );
  612. $oXAxis = new x_axis();
  613. $oXLabels = new x_axis_labels();
  614. // set them vertical
  615. $oXLabels->set_vertical();
  616. // set the label text
  617. $oXLabels->set_labels($aLabels);
  618. // Add the X Axis Labels to the X Axis
  619. $oXAxis->set_labels( $oXLabels );
  620. $oChart->set_x_axis( $oXAxis );
  621. }
  622. break;
  623. case 'pie':
  624. default:
  625. $oChartElement = new pie();
  626. $oChartElement->set_start_angle( 35 );
  627. $oChartElement->set_animate( true );
  628. $oChartElement->set_tooltip( '#label# - #val# (#percent#)' );
  629. $oChartElement->set_colours( array('#FF8A00', '#909980', '#2C2B33', '#CCC08D', '#596664') );
  630. if (isset($aExtraParams['group_by']))
  631. {
  632. $sGroupByField = $aExtraParams['group_by'];
  633. $aGroupBy = array();
  634. while($oObj = $this->m_oSet->Fetch())
  635. {
  636. $sValue = $oObj->Get($sGroupByField);
  637. $aGroupBy[$sValue] = isset($aGroupBy[$sValue]) ? $aGroupBy[$sValue]+1 : 1;
  638. }
  639. $sFilter = urlencode($this->m_oFilter->serialize());
  640. $aData = array();
  641. foreach($aGroupBy as $sValue => $iValue)
  642. {
  643. $aData[] = new pie_value($iValue, $sValue); //@@ BUG: not passed via ajax !!!
  644. }
  645. $oChartElement->set_values( $aData );
  646. $oChart->x_axis = null;
  647. }
  648. }
  649. if (isset($aExtraParams['chart_title']))
  650. {
  651. $oTitle = new title( Dict::S($aExtraParams['chart_title']) );
  652. $oChart->set_title( $oTitle );
  653. }
  654. $oChart->set_bg_colour('#FFFFFF');
  655. $oChart->add_element( $oChartElement );
  656. $sHtml = $oChart->toPrettyString();
  657. break;
  658. default:
  659. // Unsupported style, do nothing.
  660. $sHtml .= Dict::format('UI:Error:UnsupportedStyleOfBlock', $this->m_sStyle);
  661. }
  662. return $sHtml;
  663. }
  664. }
  665. /**
  666. * Helper class to manage 'blocks' of HTML pieces that are parts of a page and contain some list of cmdb objects
  667. *
  668. * Each block is actually rendered as a <div></div> tag that can be rendered synchronously
  669. * or as a piece of Javascript/JQuery/Ajax that will get its content from another page (ajax.render.php).
  670. * The list of cmdbObjects to be displayed into the block is defined by a filter
  671. * Right now the type of display is either: list, count or details
  672. * - list produces a table listing the objects
  673. * - count produces a paragraphs with a sentence saying 'cont' objects found
  674. * - details display (as table) the details of each object found (best if only one)
  675. */
  676. class HistoryBlock extends DisplayBlock
  677. {
  678. public function GetRenderContent(WebPage $oPage, $aExtraParams = array())
  679. {
  680. $sHtml = '';
  681. $oSet = new CMDBObjectSet($this->m_oFilter, array('date'=>false));
  682. $sHtml .= "<!-- filter: ".($this->m_oFilter->ToOQL())."-->\n";
  683. switch($this->m_sStyle)
  684. {
  685. case 'toggle':
  686. // First the latest change that the user is allowed to see
  687. do
  688. {
  689. $oLatestChangeOp = $oSet->Fetch();
  690. }
  691. while(is_object($oLatestChangeOp) && ($oLatestChangeOp->GetDescription() == ''));
  692. if (is_object($oLatestChangeOp))
  693. {
  694. $oContext = new UserContext();
  695. // There is one change in the list... only when the object has been created !
  696. $sDate = $oLatestChangeOp->GetAsHTML('date');
  697. $oChange = $oContext->GetObject('CMDBChange', $oLatestChangeOp->Get('change'));
  698. $sUserInfo = $oChange->GetAsHTML('userinfo');
  699. $sHtml .= $oPage->GetStartCollapsibleSection(Dict::Format('UI:History:LastModified_On_By', $sDate, $sUserInfo));
  700. $sHtml .= $this->GetHistoryTable($oPage, $oSet);
  701. $sHtml .= $oPage->GetEndCollapsibleSection();
  702. }
  703. break;
  704. case 'table':
  705. default:
  706. $sHtml .= $this->GetHistoryTable($oPage, $oSet);
  707. }
  708. return $sHtml;
  709. }
  710. protected function GetHistoryTable(WebPage $oPage, DBObjectSet $oSet)
  711. {
  712. $sHtml = '';
  713. // First the latest change that the user is allowed to see
  714. $oSet->Rewind(); // Reset the pointer to the beginning of the set
  715. $aChanges = array();
  716. while($oChangeOp = $oSet->Fetch())
  717. {
  718. $sChangeDescription = $oChangeOp->GetDescription();
  719. if ($sChangeDescription != '')
  720. {
  721. // The change is visible for the current user
  722. $changeId = $oChangeOp->Get('change');
  723. $aChanges[$changeId]['date'] = $oChangeOp->Get('date');
  724. $aChanges[$changeId]['userinfo'] = $oChangeOp->Get('userinfo');
  725. if (!isset($aChanges[$changeId]['log']))
  726. {
  727. $aChanges[$changeId]['log'] = array();
  728. }
  729. $aChanges[$changeId]['log'][] = $sChangeDescription;
  730. }
  731. }
  732. $aAttribs = array('date' => array('label' => Dict::S('UI:History:Date'), 'description' => Dict::S('UI:History:Date+')),
  733. 'userinfo' => array('label' => Dict::S('UI:History:User'), 'description' => Dict::S('UI:History:User+')),
  734. 'log' => array('label' => Dict::S('UI:History:Changes'), 'description' => Dict::S('UI:History:Changes+')),
  735. );
  736. $aValues = array();
  737. foreach($aChanges as $aChange)
  738. {
  739. $aValues[] = array('date' => $aChange['date'], 'userinfo' => $aChange['userinfo'], 'log' => "<ul><li>".implode('</li><li>', $aChange['log'])."</li></ul>");
  740. }
  741. $sHtml .= $oPage->GetTable($aAttribs, $aValues);
  742. return $sHtml;
  743. }
  744. }
  745. class MenuBlock extends DisplayBlock
  746. {
  747. /**
  748. * Renders the "Actions" popup menu for the given set of objects
  749. *
  750. * Note that the menu links containing (or ending) with a hash (#) will have their fragment
  751. * part (whatever is after the hash) dynamically replaced (by javascript) when the menu is
  752. * displayed, to correspond to the current hash/fragment in the page. This allows modifying
  753. * an object in with the same tab active by default as the tab that was active when selecting
  754. * the "Modify..." action.
  755. */
  756. public function GetRenderContent(WebPage $oPage, $aExtraParams = array())
  757. {
  758. $sHtml = '';
  759. $oAppContext = new ApplicationContext();
  760. $sContext = $oAppContext->GetForLink();
  761. $sClass = $this->m_oFilter->GetClass();
  762. $oSet = new CMDBObjectSet($this->m_oFilter);
  763. $sFilter = $this->m_oFilter->serialize();
  764. $aActions = array();
  765. $sUIPage = cmdbAbstractObject::ComputeUIPage($sClass);
  766. // 1:n links, populate the target object as a default value when creating a new linked object
  767. if (isset($aExtraParams['target_attr']))
  768. {
  769. $aExtraParams['default'][$aExtraParams['target_attr']] = $aExtraParams['object_id'];
  770. }
  771. $sDefault = '';
  772. if (!empty($aExtraParams['default']))
  773. {
  774. foreach($aExtraParams['default'] as $sKey => $sValue)
  775. {
  776. $sDefault.= "&default[$sKey]=$sValue";
  777. }
  778. }
  779. switch($oSet->Count())
  780. {
  781. case 0:
  782. // No object in the set, the only possible action is "new"
  783. $bIsModifyAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) && !MetaModel::IsReadOnlyClass($sClass);
  784. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:New'), 'url' => "../page/$sUIPage?operation=new&class=$sClass&$sContext{$sDefault}"); }
  785. break;
  786. case 1:
  787. $oObj = $oSet->Fetch();
  788. $id = $oObj->GetKey();
  789. $bIsModifyAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_YES) && !MetaModel::IsReadOnlyClass($sClass);
  790. $bIsDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  791. $bIsBulkModifyAllowed = (!MetaModel::IsAbstract($sClass)) && UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  792. $bIsBulkDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  793. // Just one object in the set, possible actions are "new / clone / modify and delete"
  794. if (isset($aExtraParams['link_attr']))
  795. {
  796. $id = $aExtraParams['object_id'];
  797. $sTargetAttr = $aExtraParams['target_attr'];
  798. $oAttDef = MetaModel::GetAttributeDef($sClass, $sTargetAttr);
  799. $sTargetClass = $oAttDef->GetTargetClass();
  800. 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"); }
  801. 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"); }
  802. //if ($bIsDeleteAllowed) { $aActions[] = array ('label' => 'Remove All', 'url' => "#"); }
  803. }
  804. else
  805. {
  806. $sUrl = utils::GetAbsoluteUrl();
  807. $aActions[] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=".$oSet->GetFilter()->__DescribeHTML()."&body=".urlencode("$sUrl?operation=search&filter=$sFilter&$sContext"));
  808. $aActions[] = array ('label' => Dict::S('UI:Menu:CSVExport'), 'url' => "../pages/$sUIPage?operation=search&filter=$sFilter&format=csv&$sContext");
  809. //$aActions[] = array ('label' => 'Bookmark...', 'url' => "../pages/ajax.render.php?operation=create&class=$sClass&filter=$sFilter", 'class' => 'jqmTrigger');
  810. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:New'), 'url' => "../pages/$sUIPage?operation=new&class=$sClass&$sContext{$sDefault}"); }
  811. //if ($bIsModifyAllowed) { $aActions[] = array ('label' => 'Clone...', 'url' => "../pages/$sUIPage?operation=clone&class=$sClass&id=$id&$sContext"); }
  812. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:Modify'), 'url' => "../pages/$sUIPage?operation=modify&class=$sClass&id=$id&$sContext#"); }
  813. if ($bIsDeleteAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:Delete'), 'url' => "../pages/$sUIPage?operation=delete&class=$sClass&id=$id&$sContext"); }
  814. $aRelations = MetaModel::EnumRelations($sClass);
  815. foreach($aRelations as $sRelationCode)
  816. {
  817. $aActions[] = array ('label' => MetaModel::GetRelationVerbUp($sRelationCode), 'url' => "../pages/$sUIPage?operation=swf_navigator&relation=$sRelationCode&class=$sClass&id=$id&$sContext");
  818. }
  819. }
  820. $aTransitions = $oObj->EnumTransitions();
  821. $aStimuli = Metamodel::EnumStimuli($sClass);
  822. foreach($aTransitions as $sStimulusCode => $aTransitionDef)
  823. {
  824. $iActionAllowed = (get_class($aStimuli[$sStimulusCode]) == 'StimulusUserAction') ? UserRights::IsStimulusAllowed($sClass, $sStimulusCode, $oSet) : UR_ALLOWED_NO;
  825. switch($iActionAllowed)
  826. {
  827. case UR_ALLOWED_YES:
  828. $aActions[] = array('label' => $aStimuli[$sStimulusCode]->GetLabel(), 'url' => "../pages/UI.php?operation=stimulus&stimulus=$sStimulusCode&class=$sClass&id=$id&$sContext");
  829. break;
  830. case UR_ALLOWED_DEPENDS:
  831. $aActions[] = array('label' => $aStimuli[$sStimulusCode]->GetLabel().' (*)', 'url' => "../pages/UI.php?operation=stimulus&stimulus=$sStimulusCode&class=$sClass&id=$id&$sContext");
  832. break;
  833. default:
  834. // Do nothing
  835. }
  836. }
  837. //print_r($aTransitions);
  838. break;
  839. default:
  840. // Check rights
  841. // New / Modify
  842. $bIsModifyAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  843. $bIsBulkModifyAllowed = (!MetaModel::IsAbstract($sClass)) && UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  844. $bIsBulkDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  845. if (isset($aExtraParams['link_attr']))
  846. {
  847. $id = $aExtraParams['object_id'];
  848. $sTargetAttr = $aExtraParams['target_attr'];
  849. $oAttDef = MetaModel::GetAttributeDef($sClass, $sTargetAttr);
  850. $sTargetClass = $oAttDef->GetTargetClass();
  851. $bIsDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  852. 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"); }
  853. //if ($bIsBulkModifyAllowed) { $aActions[] = array ('label' => 'Add...', 'url' => "../pages/$sUIPage?operation=modify_links&class=$sClass&linkage=".$aExtraParams['linkage']."&id=$id&addObjects=true&$sContext"); }
  854. 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"); }
  855. //if ($bIsBulkDeleteAllowed) { $aActions[] = array ('label' => 'Remove All...', 'url' => "#"); }
  856. }
  857. else
  858. {
  859. // many objects in the set, possible actions are: new / modify all / delete all
  860. $sUrl = utils::GetAbsoluteUrl();
  861. $aActions[] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=".$oSet->GetFilter()->__DescribeHTML()."&body=".urlencode("$sUrl?operation=search&filter=$sFilter&$sContext"));
  862. $aActions[] = array ('label' => Dict::S('UI:Menu:CSVExport'), 'url' => "../pages/$sUIPage?operation=search&filter=$sFilter&format=csv&$sContext");
  863. //$aActions[] = array ('label' => 'Bookmark...', 'url' => "../pages/ajax.render.php?operation=create&class=$sClass&filter=$sFilter", 'class' => 'jqmTrigger');
  864. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:New'), 'url' => "../pages/$sUIPage?operation=new&class=$sClass&$sContext{$sDefault}"); }
  865. //if ($bIsBulkModifyAllowed) { $aActions[] = array ('label' => 'Modify All...', 'url' => "../pages/$sUIPage?operation=modify_all&filter=$sFilter&$sContext"); }
  866. if ($bIsBulkDeleteAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:BulkDelete'), 'url' => "../pages/$sUIPage?operation=select_for_deletion&filter=$sFilter&$sContext"); }
  867. }
  868. }
  869. $sHtml .= "<div class=\"itop_popup\"><ul>\n<li>".Dict::S('UI:Menu:Actions')."\n<ul>\n";
  870. foreach ($aActions as $aAction)
  871. {
  872. $sClass = isset($aAction['class']) ? " class=\"{$aAction['class']}\"" : "";
  873. $sHtml .= "<li><a href=\"{$aAction['url']}\"$sClass>{$aAction['label']}</a></li>\n";
  874. }
  875. $sHtml .= "</ul>\n</li>\n</ul></div>\n";
  876. static $bPopupScript = false;
  877. if (!$bPopupScript)
  878. {
  879. // Output this once per page...
  880. $oPage->add_ready_script("$(\"div.itop_popup>ul\").popupmenu();\n");
  881. $bPopupScript = true;
  882. }
  883. return $sHtml;
  884. }
  885. }
  886. ?>