displayblock.class.inc.php 37 KB

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