displayblock.class.inc.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  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. $aQueryParams = array();
  278. if (isset($aExtraParams['query_params']))
  279. {
  280. $aQueryParams = $aExtraParams['query_params'];
  281. }
  282. if ($this->m_sStyle != 'links')
  283. {
  284. $aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass()));
  285. foreach($aFilterCodes as $sFilterCode)
  286. {
  287. $sExternalFilterValue = utils::ReadParam($sFilterCode, '');
  288. if (isset($aExtraParams[$sFilterCode]))
  289. {
  290. $this->m_oFilter->AddCondition($sFilterCode, trim($aExtraParams[$sFilterCode])); // Use the default 'loose' operator
  291. }
  292. else if ($bDoSearch && $sExternalFilterValue != "")
  293. {
  294. $this->m_oFilter->AddCondition($sFilterCode, trim($sExternalFilterValue)); // Use the default 'loose' operator
  295. }
  296. }
  297. }
  298. $this->m_oSet = new CMDBObjectSet($this->m_oFilter, array(), $aQueryParams);
  299. }
  300. switch($this->m_sStyle)
  301. {
  302. case 'count':
  303. if (isset($aExtraParams['group_by']))
  304. {
  305. $sGroupByField = $aExtraParams['group_by'];
  306. $aGroupBy = array();
  307. $sLabels = array();
  308. while($oObj = $this->m_oSet->Fetch())
  309. {
  310. $sValue = $oObj->Get($sGroupByField);
  311. $aGroupBy[$sValue] = isset($aGroupBy[$sValue]) ? $aGroupBy[$sValue]+1 : 1;
  312. $sLabels[$sValue] = $oObj->GetAsHtml($sGroupByField);
  313. }
  314. $sFilter = urlencode($this->m_oFilter->serialize());
  315. $aData = array();
  316. $oAppContext = new ApplicationContext();
  317. $sParams = $oAppContext->GetForLink();
  318. foreach($aGroupBy as $sValue => $iCount)
  319. {
  320. $aData[] = array ( 'group' => $sLabels[$sValue],
  321. 'value' => "<a href=\"./UI.php?operation=search&dosearch=1&$sParams&filter=$sFilter&$sGroupByField=".urlencode($sValue)."\">$iCount</a>"); // TO DO: add the context information
  322. }
  323. $aAttribs =array(
  324. 'group' => array('label' => MetaModel::GetLabel($this->m_oFilter->GetClass(), $sGroupByField), 'description' => ''),
  325. 'value' => array('label'=> Dict::S('UI:GroupBy:Count'), 'description' => Dict::S('UI:GroupBy:Count+'))
  326. );
  327. $sHtml .= $oPage->GetTable($aAttribs, $aData);
  328. }
  329. else
  330. {
  331. // Simply count the number of elements in the set
  332. $iCount = $this->m_oSet->Count();
  333. $sFormat = 'UI:CountOfObjects';
  334. if (isset($aExtraParams['format']))
  335. {
  336. $sFormat = $aExtraParams['format'];
  337. }
  338. $sHtml .= $oPage->GetP(Dict::Format($sFormat, $iCount));
  339. }
  340. break;
  341. case 'join':
  342. $aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', $aExtraParams['display_aliases']): array();
  343. if (!isset($aExtraParams['group_by']))
  344. {
  345. $sHtml .= $oPage->GetP(Dict::S('UI:Error:MandatoryTemplateParameter_group_by'));
  346. }
  347. else
  348. {
  349. $aGroupByFields = array();
  350. $aGroupBy = explode(',', $aExtraParams['group_by']);
  351. foreach($aGroupBy as $sGroupBy)
  352. {
  353. $aMatches = array();
  354. if (preg_match('/^(.+)\.(.+)$/', $sGroupBy, $aMatches) > 0)
  355. {
  356. $aGroupByFields[] = array('alias' => $aMatches[1], 'att_code' => $aMatches[2]);
  357. }
  358. }
  359. if (count($aGroupByFields) == 0)
  360. {
  361. $sHtml .= $oPage->GetP(Dict::Format('UI:Error:InvalidGroupByFields', $aExtraParams['group_by']));
  362. }
  363. else
  364. {
  365. $aResults = array();
  366. $aCriteria = array();
  367. while($aObjects = $this->m_oSet->FetchAssoc())
  368. {
  369. $aKeys = array();
  370. foreach($aGroupByFields as $aField)
  371. {
  372. $aKeys[$aField['alias'].'.'.$aField['att_code']] = $aObjects[$aField['alias']]->Get($aField['att_code']);
  373. }
  374. $sCategory = implode($aKeys, ' ');
  375. $aResults[$sCategory][] = $aObjects;
  376. $aCriteria[$sCategory] = $aKeys;
  377. }
  378. $sHtml .= "<table>\n";
  379. // Construct a new (parametric) query that will return the content of this block
  380. $oBlockFilter = clone $this->m_oFilter;
  381. $aExpressions = array();
  382. $index = 0;
  383. foreach($aGroupByFields as $aField)
  384. {
  385. $aExpressions[] = '`'.$aField['alias'].'`.`'.$aField['att_code'].'` = :param'.$index++;
  386. }
  387. $sExpression = implode(' AND ', $aExpressions);
  388. $oExpression = Expression::FromOQL($sExpression);
  389. $oBlockFilter->AddConditionExpression($oExpression);
  390. $aExtraParams['menu'] = false;
  391. foreach($aResults as $sCategory => $aObjects)
  392. {
  393. $sHtml .= "<tr><td><h1>$sCategory</h1></td></tr>\n";
  394. if (count($aDisplayAliases) == 1)
  395. {
  396. $aSimpleArray = array();
  397. foreach($aObjects as $aRow)
  398. {
  399. $aSimpleArray[] = $aRow[$aDisplayAliases[0]];
  400. }
  401. $oSet = CMDBObjectSet::FromArray($this->m_oFilter->GetClass(), $aSimpleArray);
  402. $sHtml .= "<tr><td>".cmdbAbstractObject::GetDisplaySet($oPage, $oSet, $aExtraParams)."</td></tr>\n";
  403. }
  404. else
  405. {
  406. $index = 0;
  407. $aArgs = array();
  408. foreach($aGroupByFields as $aField)
  409. {
  410. $aArgs['param'.$index] = $aCriteria[$sCategory][$aField['alias'].'.'.$aField['att_code']];
  411. $index++;
  412. }
  413. $oSet = new CMDBObjectSet($oBlockFilter, array(), $aArgs);
  414. $sHtml .= "<tr><td>".cmdbAbstractObject::GetDisplayExtendedSet($oPage, $oSet, $aExtraParams)."</td></tr>\n";
  415. }
  416. }
  417. $sHtml .= "</table>\n";
  418. }
  419. }
  420. break;
  421. case 'list':
  422. $aClasses = $this->m_oSet->GetSelectedClasses();
  423. $aAuthorizedClasses = array();
  424. if (count($aClasses) > 1)
  425. {
  426. // Check the classes that can be read (i.e authorized) by this user...
  427. foreach($aClasses as $sAlias => $sClassName)
  428. {
  429. if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $this->m_oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS))
  430. {
  431. $aAuthorizedClasses[$sAlias] = $sClassName;
  432. }
  433. }
  434. if (count($aAuthorizedClasses) > 0)
  435. {
  436. if($this->m_oSet->Count() > 0)
  437. {
  438. $sHtml .= cmdbAbstractObject::GetDisplayExtendedSet($oPage, $this->m_oSet, $aExtraParams);
  439. }
  440. else
  441. {
  442. // Empty set
  443. $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay'));
  444. }
  445. }
  446. else
  447. {
  448. // Not authorized
  449. $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay'));
  450. }
  451. }
  452. else
  453. {
  454. // The list is made of only 1 class of objects, actions on the list are possible
  455. if ( ($this->m_oSet->Count()> 0) && (UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES) )
  456. {
  457. $sHtml .= cmdbAbstractObject::GetDisplaySet($oPage, $this->m_oSet, $aExtraParams);
  458. }
  459. else
  460. {
  461. $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay'));
  462. $sClass = $this->m_oFilter->GetClass();
  463. $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true;
  464. if ($bDisplayMenu)
  465. {
  466. if ((UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES)
  467. && !MetaModel::IsReadOnlyClass($sClass))
  468. {
  469. $oAppContext = new ApplicationContext();
  470. $sParams = $oAppContext->GetForLink();
  471. // 1:n links, populate the target object as a default value when creating a new linked object
  472. if (isset($aExtraParams['target_attr']))
  473. {
  474. $aExtraParams['default'][$aExtraParams['target_attr']] = $aExtraParams['object_id'];
  475. }
  476. $sDefault = '';
  477. if (!empty($aExtraParams['default']))
  478. {
  479. foreach($aExtraParams['default'] as $sKey => $sValue)
  480. {
  481. $sDefault.= "&default[$sKey]=$sValue";
  482. }
  483. }
  484. $sHtml .= $oPage->GetP("<a href=\"./UI.php?operation=new&class=$sClass&$sParams{$sDefault}\">".Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass))."</a>\n");
  485. }
  486. }
  487. }
  488. }
  489. break;
  490. case 'links':
  491. //$bDashboardMode = isset($aExtraParams['dashboard']) ? ($aExtraParams['dashboard'] == 'true') : false;
  492. //$bSelectMode = isset($aExtraParams['select']) ? ($aExtraParams['select'] == 'true') : false;
  493. if ( ($this->m_oSet->Count()> 0) && (UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES) )
  494. {
  495. //$sLinkage = isset($aExtraParams['linkage']) ? $aExtraParams['linkage'] : '';
  496. $sHtml .= cmdbAbstractObject::GetDisplaySet($oPage, $this->m_oSet, $aExtraParams);
  497. }
  498. else
  499. {
  500. $sClass = $this->m_oFilter->GetClass();
  501. $oAttDef = MetaModel::GetAttributeDef($sClass, $this->m_aParams['target_attr']);
  502. $sTargetClass = $oAttDef->GetTargetClass();
  503. $sHtml .= $oPage->GetP(Dict::Format('UI:NoObject_Class_ToDisplay', MetaModel::GetName($sTargetClass)));
  504. $bDisplayMenu = isset($this->m_aParams['menu']) ? $this->m_aParams['menu'] == true : true;
  505. if ($bDisplayMenu)
  506. {
  507. if ((UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES)
  508. && (!MetaModel::IsReadOnlyClass($sClass)))
  509. {
  510. $oAppContext = new ApplicationContext();
  511. $sParams = $oAppContext->GetForLink();
  512. $sDefaults = '';
  513. if (isset($this->m_aParams['default']))
  514. {
  515. foreach($this->m_aParams['default'] as $sName => $sValue)
  516. {
  517. $sDefaults .= '&'.urlencode($sName).'='.urlencode($sValue);
  518. }
  519. }
  520. $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");
  521. }
  522. }
  523. }
  524. break;
  525. case 'details':
  526. while($oObj = $this->m_oSet->Fetch())
  527. {
  528. $sHtml .= $oObj->GetDetails($oPage); // Still used ???
  529. }
  530. break;
  531. case 'actions':
  532. $sClass = $this->m_oFilter->GetClass();
  533. $oAppContext = new ApplicationContext();
  534. $sParams = $oAppContext->GetForLink();
  535. $sHtml .= '<p>';
  536. if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY))
  537. {
  538. $sHtml .= "<a href=\"../pages/UI.php?operation=new&class={$sClass}&$sParams\">".Dict::Format('UI:ClickToCreateNew', MetaModel::GetName($sClass))."</a><br/>\n";
  539. }
  540. $sHtml .= "<a href=\"../pages/UI.php?operation=search_form&class={$sClass}&$sParams\">".Dict::Format('UI:SearchFor_Class', MetaModel::GetName($sClass))."</a>\n";
  541. $sHtml .= '</p>';
  542. break;
  543. case 'bare_details':
  544. while($oObj = $this->m_oSet->Fetch())
  545. {
  546. $sHtml .= $oObj->GetBareProperties($oPage);
  547. }
  548. break;
  549. case 'csv':
  550. $sHtml .= "<textarea style=\"width:95%;height:98%\">\n";
  551. $sHtml .= cmdbAbstractObject::GetSetAsCSV($this->m_oSet);
  552. $sHtml .= "</textarea>\n";
  553. break;
  554. case 'modify':
  555. if ((UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_MODIFY, $this->m_oSet) == UR_ALLOWED_YES)
  556. && !MetaModel::IsReadOnlyClass($this->m_oSet->GetClass()))
  557. {
  558. while($oObj = $this->m_oSet->Fetch())
  559. {
  560. $sHtml .= $oObj->GetModifyForm($oPage);
  561. }
  562. }
  563. break;
  564. case 'search':
  565. static $iSearchSectionId = 1;
  566. $sStyle = (isset($aExtraParams['open']) && ($aExtraParams['open'] == 'true')) ? 'SearchDrawer' : 'SearchDrawer DrawerClosed';
  567. $sHtml .= "<div id=\"Search_$iSearchSectionId\" class=\"$sStyle\">\n";
  568. $oPage->add_ready_script(
  569. <<<EOF
  570. $("#LnkSearch_$iSearchSectionId").click( function() {
  571. $("#Search_$iSearchSectionId").slideToggle('normal', function() { $("#Search_$iSearchSectionId").parent().resize(); } );
  572. $("#LnkSearch_$iSearchSectionId").toggleClass('open');
  573. });
  574. EOF
  575. );
  576. $sHtml .= cmdbAbstractObject::GetSearchForm($oPage, $this->m_oSet, $aExtraParams);
  577. $sHtml .= "</div>\n";
  578. $sHtml .= "<div class=\"HRDrawer\"></div>\n";
  579. $sHtml .= "<div id=\"LnkSearch_$iSearchSectionId\" class=\"DrawerHandle\">".Dict::S('UI:SearchToggle')."</div>\n";
  580. $iSearchSectionId++;
  581. break;
  582. case 'open_flash_chart':
  583. static $iChartCounter = 0;
  584. $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie';
  585. $sTitle = isset($aExtraParams['chart_title']) ? $aExtraParams['chart_title'] : '';
  586. $sGroupBy = isset($aExtraParams['group_by']) ? $aExtraParams['group_by'] : '';
  587. $sFilter = $this->m_oFilter->ToOQL();
  588. $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";
  589. $oPage->add_script("function ofc_resize(left, width, top, height) { /* do nothing special */ }");
  590. $oPage->add_ready_script("swfobject.embedSWF(\"../images/open-flash-chart.swf\", \"my_chart_{$iChartCounter}\", \"100%\", \"300\",\"9.0.0\", \"expressInstall.swf\",
  591. {\"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");
  592. $iChartCounter++;
  593. break;
  594. case 'open_flash_chart_ajax':
  595. include '../pages/php-ofc-library/open-flash-chart.php';
  596. $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie';
  597. $oChart = new open_flash_chart();
  598. switch($sChartType)
  599. {
  600. case 'bars':
  601. $oChartElement = new bar_glass();
  602. if (isset($aExtraParams['group_by']))
  603. {
  604. $sGroupByField = $aExtraParams['group_by'];
  605. $aGroupBy = array();
  606. while($oObj = $this->m_oSet->Fetch())
  607. {
  608. $sValue = $oObj->Get($sGroupByField);
  609. $aGroupBy[$sValue] = isset($aGroupBy[$sValue]) ? $aGroupBy[$sValue]+1 : 1;
  610. }
  611. $sFilter = urlencode($this->m_oFilter->serialize());
  612. $aData = array();
  613. $aLabels = array();
  614. foreach($aGroupBy as $sValue => $iValue)
  615. {
  616. $aData[] = $iValue;
  617. $aLabels[] = $sValue;
  618. }
  619. $maxValue = max($aData);
  620. $oYAxis = new y_axis();
  621. $aMagicValues = array(1,2,5,10);
  622. $iMultiplier = 1;
  623. $index = 0;
  624. $iTop = $aMagicValues[$index % count($aMagicValues)]*$iMultiplier;
  625. while($maxValue > $iTop)
  626. {
  627. $index++;
  628. $iTop = $aMagicValues[$index % count($aMagicValues)]*$iMultiplier;
  629. if (($index % count($aMagicValues)) == 0)
  630. {
  631. $iMultiplier = $iMultiplier * 10;
  632. }
  633. }
  634. //echo "oYAxis->set_range(0, $iTop, $iMultiplier);\n";
  635. $oYAxis->set_range(0, $iTop, $iMultiplier);
  636. $oChart->set_y_axis( $oYAxis );
  637. $oChartElement->set_values( $aData );
  638. $oXAxis = new x_axis();
  639. $oXLabels = new x_axis_labels();
  640. // set them vertical
  641. $oXLabels->set_vertical();
  642. // set the label text
  643. $oXLabels->set_labels($aLabels);
  644. // Add the X Axis Labels to the X Axis
  645. $oXAxis->set_labels( $oXLabels );
  646. $oChart->set_x_axis( $oXAxis );
  647. }
  648. break;
  649. case 'pie':
  650. default:
  651. $oChartElement = new pie();
  652. $oChartElement->set_start_angle( 35 );
  653. $oChartElement->set_animate( true );
  654. $oChartElement->set_tooltip( '#label# - #val# (#percent#)' );
  655. $oChartElement->set_colours( array('#FF8A00', '#909980', '#2C2B33', '#CCC08D', '#596664') );
  656. if (isset($aExtraParams['group_by']))
  657. {
  658. $sGroupByField = $aExtraParams['group_by'];
  659. $aGroupBy = array();
  660. while($oObj = $this->m_oSet->Fetch())
  661. {
  662. $sValue = $oObj->Get($sGroupByField);
  663. $aGroupBy[$sValue] = isset($aGroupBy[$sValue]) ? $aGroupBy[$sValue]+1 : 1;
  664. }
  665. $sFilter = urlencode($this->m_oFilter->serialize());
  666. $aData = array();
  667. foreach($aGroupBy as $sValue => $iValue)
  668. {
  669. $aData[] = new pie_value($iValue, $sValue); //@@ BUG: not passed via ajax !!!
  670. }
  671. $oChartElement->set_values( $aData );
  672. $oChart->x_axis = null;
  673. }
  674. }
  675. if (isset($aExtraParams['chart_title']))
  676. {
  677. $oTitle = new title( Dict::S($aExtraParams['chart_title']) );
  678. $oChart->set_title( $oTitle );
  679. }
  680. $oChart->set_bg_colour('#FFFFFF');
  681. $oChart->add_element( $oChartElement );
  682. $sHtml = $oChart->toPrettyString();
  683. break;
  684. default:
  685. // Unsupported style, do nothing.
  686. $sHtml .= Dict::format('UI:Error:UnsupportedStyleOfBlock', $this->m_sStyle);
  687. }
  688. return $sHtml;
  689. }
  690. }
  691. /**
  692. * Helper class to manage 'blocks' of HTML pieces that are parts of a page and contain some list of cmdb objects
  693. *
  694. * Each block is actually rendered as a <div></div> tag that can be rendered synchronously
  695. * or as a piece of Javascript/JQuery/Ajax that will get its content from another page (ajax.render.php).
  696. * The list of cmdbObjects to be displayed into the block is defined by a filter
  697. * Right now the type of display is either: list, count or details
  698. * - list produces a table listing the objects
  699. * - count produces a paragraphs with a sentence saying 'cont' objects found
  700. * - details display (as table) the details of each object found (best if only one)
  701. */
  702. class HistoryBlock extends DisplayBlock
  703. {
  704. public function GetRenderContent(WebPage $oPage, $aExtraParams = array())
  705. {
  706. $sHtml = '';
  707. $oSet = new CMDBObjectSet($this->m_oFilter, array('date'=>false));
  708. $sHtml .= "<!-- filter: ".($this->m_oFilter->ToOQL())."-->\n";
  709. switch($this->m_sStyle)
  710. {
  711. case 'toggle':
  712. // First the latest change that the user is allowed to see
  713. do
  714. {
  715. $oLatestChangeOp = $oSet->Fetch();
  716. }
  717. while(is_object($oLatestChangeOp) && ($oLatestChangeOp->GetDescription() == ''));
  718. if (is_object($oLatestChangeOp))
  719. {
  720. // There is one change in the list... only when the object has been created !
  721. $sDate = $oLatestChangeOp->GetAsHTML('date');
  722. $oChange = MetaModel::GetObject('CMDBChange', $oLatestChangeOp->Get('change'));
  723. $sUserInfo = $oChange->GetAsHTML('userinfo');
  724. $sHtml .= $oPage->GetStartCollapsibleSection(Dict::Format('UI:History:LastModified_On_By', $sDate, $sUserInfo));
  725. $sHtml .= $this->GetHistoryTable($oPage, $oSet);
  726. $sHtml .= $oPage->GetEndCollapsibleSection();
  727. }
  728. break;
  729. case 'table':
  730. default:
  731. $sHtml .= $this->GetHistoryTable($oPage, $oSet);
  732. }
  733. return $sHtml;
  734. }
  735. protected function GetHistoryTable(WebPage $oPage, DBObjectSet $oSet)
  736. {
  737. $sHtml = '';
  738. // First the latest change that the user is allowed to see
  739. $oSet->Rewind(); // Reset the pointer to the beginning of the set
  740. $aChanges = array();
  741. while($oChangeOp = $oSet->Fetch())
  742. {
  743. $sChangeDescription = $oChangeOp->GetDescription();
  744. if ($sChangeDescription != '')
  745. {
  746. // The change is visible for the current user
  747. $changeId = $oChangeOp->Get('change');
  748. $aChanges[$changeId]['date'] = $oChangeOp->Get('date');
  749. $aChanges[$changeId]['userinfo'] = $oChangeOp->Get('userinfo');
  750. if (!isset($aChanges[$changeId]['log']))
  751. {
  752. $aChanges[$changeId]['log'] = array();
  753. }
  754. $aChanges[$changeId]['log'][] = $sChangeDescription;
  755. }
  756. }
  757. $aAttribs = array('date' => array('label' => Dict::S('UI:History:Date'), 'description' => Dict::S('UI:History:Date+')),
  758. 'userinfo' => array('label' => Dict::S('UI:History:User'), 'description' => Dict::S('UI:History:User+')),
  759. 'log' => array('label' => Dict::S('UI:History:Changes'), 'description' => Dict::S('UI:History:Changes+')),
  760. );
  761. $aValues = array();
  762. foreach($aChanges as $aChange)
  763. {
  764. $aValues[] = array('date' => $aChange['date'], 'userinfo' => $aChange['userinfo'], 'log' => "<ul><li>".implode('</li><li>', $aChange['log'])."</li></ul>");
  765. }
  766. $sHtml .= $oPage->GetTable($aAttribs, $aValues);
  767. return $sHtml;
  768. }
  769. }
  770. class MenuBlock extends DisplayBlock
  771. {
  772. /**
  773. * Renders the "Actions" popup menu for the given set of objects
  774. *
  775. * Note that the menu links containing (or ending) with a hash (#) will have their fragment
  776. * part (whatever is after the hash) dynamically replaced (by javascript) when the menu is
  777. * displayed, to correspond to the current hash/fragment in the page. This allows modifying
  778. * an object in with the same tab active by default as the tab that was active when selecting
  779. * the "Modify..." action.
  780. */
  781. public function GetRenderContent(WebPage $oPage, $aExtraParams = array())
  782. {
  783. $sHtml = '';
  784. $oAppContext = new ApplicationContext();
  785. $sContext = $oAppContext->GetForLink();
  786. $sClass = $this->m_oFilter->GetClass();
  787. $oSet = new CMDBObjectSet($this->m_oFilter);
  788. $sFilter = $this->m_oFilter->serialize();
  789. $aActions = array();
  790. $sUIPage = cmdbAbstractObject::ComputeUIPage($sClass);
  791. // 1:n links, populate the target object as a default value when creating a new linked object
  792. if (isset($aExtraParams['target_attr']))
  793. {
  794. $aExtraParams['default'][$aExtraParams['target_attr']] = $aExtraParams['object_id'];
  795. }
  796. $sDefault = '';
  797. if (!empty($aExtraParams['default']))
  798. {
  799. foreach($aExtraParams['default'] as $sKey => $sValue)
  800. {
  801. $sDefault.= "&default[$sKey]=$sValue";
  802. }
  803. }
  804. switch($oSet->Count())
  805. {
  806. case 0:
  807. // No object in the set, the only possible action is "new"
  808. $bIsModifyAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) && !MetaModel::IsReadOnlyClass($sClass);
  809. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:New'), 'url' => "../page/$sUIPage?operation=new&class=$sClass&$sContext{$sDefault}"); }
  810. break;
  811. case 1:
  812. $oObj = $oSet->Fetch();
  813. $id = $oObj->GetKey();
  814. $bIsModifyAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_YES) && !MetaModel::IsReadOnlyClass($sClass);
  815. $bIsDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  816. $bIsBulkModifyAllowed = (!MetaModel::IsAbstract($sClass)) && UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  817. $bIsBulkDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  818. // Just one object in the set, possible actions are "new / clone / modify and delete"
  819. if (isset($aExtraParams['link_attr']))
  820. {
  821. $id = $aExtraParams['object_id'];
  822. $sTargetAttr = $aExtraParams['target_attr'];
  823. $oAttDef = MetaModel::GetAttributeDef($sClass, $sTargetAttr);
  824. $sTargetClass = $oAttDef->GetTargetClass();
  825. 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"); }
  826. 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"); }
  827. //if ($bIsDeleteAllowed) { $aActions[] = array ('label' => 'Remove All', 'url' => "#"); }
  828. }
  829. else
  830. {
  831. $sUrl = utils::GetAbsoluteUrl(false);
  832. $aActions[] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=".$oObj->GetName()."&body=".urlencode("$sUrl?operation=details&class=$sClass&id=$id&$sContext"));
  833. $aActions[] = array ('label' => Dict::S('UI:Menu:CSVExport'), 'url' => "../pages/$sUIPage?operation=search&filter=$sFilter&format=csv&$sContext");
  834. //$aActions[] = array ('label' => 'Bookmark...', 'url' => "../pages/ajax.render.php?operation=create&class=$sClass&filter=$sFilter", 'class' => 'jqmTrigger');
  835. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:New'), 'url' => "../pages/$sUIPage?operation=new&class=$sClass&$sContext{$sDefault}"); }
  836. //if ($bIsModifyAllowed) { $aActions[] = array ('label' => 'Clone...', 'url' => "../pages/$sUIPage?operation=clone&class=$sClass&id=$id&$sContext"); }
  837. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:Modify'), 'url' => "../pages/$sUIPage?operation=modify&class=$sClass&id=$id&$sContext#"); }
  838. if ($bIsDeleteAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:Delete'), 'url' => "../pages/$sUIPage?operation=delete&class=$sClass&id=$id&$sContext"); }
  839. $aRelations = MetaModel::EnumRelations($sClass);
  840. foreach($aRelations as $sRelationCode)
  841. {
  842. $aActions[] = array ('label' => MetaModel::GetRelationVerbUp($sRelationCode), 'url' => "../pages/$sUIPage?operation=swf_navigator&relation=$sRelationCode&class=$sClass&id=$id&$sContext");
  843. }
  844. }
  845. $aTransitions = $oObj->EnumTransitions();
  846. $aStimuli = Metamodel::EnumStimuli($sClass);
  847. foreach($aTransitions as $sStimulusCode => $aTransitionDef)
  848. {
  849. $iActionAllowed = (get_class($aStimuli[$sStimulusCode]) == 'StimulusUserAction') ? UserRights::IsStimulusAllowed($sClass, $sStimulusCode, $oSet) : UR_ALLOWED_NO;
  850. switch($iActionAllowed)
  851. {
  852. case UR_ALLOWED_YES:
  853. $aActions[] = array('label' => $aStimuli[$sStimulusCode]->GetLabel(), 'url' => "../pages/UI.php?operation=stimulus&stimulus=$sStimulusCode&class=$sClass&id=$id&$sContext");
  854. break;
  855. case UR_ALLOWED_DEPENDS:
  856. $aActions[] = array('label' => $aStimuli[$sStimulusCode]->GetLabel().' (*)', 'url' => "../pages/UI.php?operation=stimulus&stimulus=$sStimulusCode&class=$sClass&id=$id&$sContext");
  857. break;
  858. default:
  859. // Do nothing
  860. }
  861. }
  862. //print_r($aTransitions);
  863. break;
  864. default:
  865. // Check rights
  866. // New / Modify
  867. $bIsModifyAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  868. $bIsBulkModifyAllowed = (!MetaModel::IsAbstract($sClass)) && UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  869. $bIsBulkDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  870. if (isset($aExtraParams['link_attr']))
  871. {
  872. $id = $aExtraParams['object_id'];
  873. $sTargetAttr = $aExtraParams['target_attr'];
  874. $oAttDef = MetaModel::GetAttributeDef($sClass, $sTargetAttr);
  875. $sTargetClass = $oAttDef->GetTargetClass();
  876. $bIsDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, $oSet) && !MetaModel::IsReadOnlyClass($sClass);
  877. 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"); }
  878. //if ($bIsBulkModifyAllowed) { $aActions[] = array ('label' => 'Add...', 'url' => "../pages/$sUIPage?operation=modify_links&class=$sClass&linkage=".$aExtraParams['linkage']."&id=$id&addObjects=true&$sContext"); }
  879. 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"); }
  880. //if ($bIsBulkDeleteAllowed) { $aActions[] = array ('label' => 'Remove All...', 'url' => "#"); }
  881. }
  882. else
  883. {
  884. // many objects in the set, possible actions are: new / modify all / delete all
  885. $sUrl = utils::GetAbsoluteUrl();
  886. $aActions[] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=".$oSet->GetFilter()->__DescribeHTML()."&body=".urlencode("$sUrl?operation=search&filter=$sFilter&$sContext"));
  887. $aActions[] = array ('label' => Dict::S('UI:Menu:CSVExport'), 'url' => "../pages/$sUIPage?operation=search&filter=$sFilter&format=csv&$sContext");
  888. //$aActions[] = array ('label' => 'Bookmark...', 'url' => "../pages/ajax.render.php?operation=create&class=$sClass&filter=$sFilter", 'class' => 'jqmTrigger');
  889. if ($bIsModifyAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:New'), 'url' => "../pages/$sUIPage?operation=new&class=$sClass&$sContext{$sDefault}"); }
  890. //if ($bIsBulkModifyAllowed) { $aActions[] = array ('label' => 'Modify All...', 'url' => "../pages/$sUIPage?operation=modify_all&filter=$sFilter&$sContext"); }
  891. if ($bIsBulkDeleteAllowed) { $aActions[] = array ('label' => Dict::S('UI:Menu:BulkDelete'), 'url' => "../pages/$sUIPage?operation=select_for_deletion&filter=$sFilter&$sContext"); }
  892. }
  893. }
  894. $sHtml .= "<div class=\"itop_popup\"><ul>\n<li>".Dict::S('UI:Menu:Actions')."\n<ul>\n";
  895. foreach ($aActions as $aAction)
  896. {
  897. $sClass = isset($aAction['class']) ? " class=\"{$aAction['class']}\"" : "";
  898. $sHtml .= "<li><a href=\"{$aAction['url']}\"$sClass>{$aAction['label']}</a></li>\n";
  899. }
  900. $sHtml .= "</ul>\n</li>\n</ul></div>\n";
  901. static $bPopupScript = false;
  902. if (!$bPopupScript)
  903. {
  904. // Output this once per page...
  905. $oPage->add_ready_script("$(\"div.itop_popup>ul\").popupmenu();\n");
  906. $bPopupScript = true;
  907. }
  908. return $sHtml;
  909. }
  910. }
  911. ?>