displayblock.class.inc.php 39 KB

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