displayblock.class.inc.php 37 KB

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