displayblock.class.inc.php 37 KB

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