cmdbabstract.class.inc.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  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. * Abstract class that implements some common and useful methods for displaying
  18. * the objects
  19. *
  20. * @author Erwan Taloc <erwan.taloc@combodo.com>
  21. * @author Romain Quetiez <romain.quetiez@combodo.com>
  22. * @author Denis Flaven <denis.flaven@combodo.com>
  23. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  24. */
  25. define('OBJECT_PROPERTIES_TAB', 'ObjectProperties');
  26. define('HILIGHT_CLASS_CRITICAL', 'red');
  27. define('HILIGHT_CLASS_WARNING', 'orange');
  28. define('HILIGHT_CLASS_OK', 'green');
  29. define('HILIGHT_CLASS_NONE', '');
  30. require_once('../core/cmdbobject.class.inc.php');
  31. require_once('../application/utils.inc.php');
  32. require_once('../application/applicationcontext.class.inc.php');
  33. require_once('../application/ui.linkswidget.class.inc.php');
  34. require_once('../application/ui.passwordwidget.class.inc.php');
  35. abstract class cmdbAbstractObject extends CMDBObject
  36. {
  37. protected $m_iFormId; // The ID of the form used to edit the object (when in edition mode !)
  38. public static function GetUIPage()
  39. {
  40. return '../pages/UI.php';
  41. }
  42. public static function ComputeUIPage($sClass)
  43. {
  44. static $aUIPagesCache = array(); // Cache to store the php page used to display each class of object
  45. if (!isset($aUIPagesCache[$sClass]))
  46. {
  47. $UIPage = false;
  48. if (is_callable("$sClass::GetUIPage"))
  49. {
  50. $UIPage = eval("return $sClass::GetUIPage();"); // May return false in case of error
  51. }
  52. $aUIPagesCache[$sClass] = $UIPage === false ? './UI.php' : $UIPage;
  53. }
  54. $sPage = $aUIPagesCache[$sClass];
  55. return $sPage;
  56. }
  57. protected static function MakeHyperLink($sObjClass, $sObjKey, $aAvailableFields)
  58. {
  59. if ($sObjKey <= 0) return '<em>'.Dict::S('UI:UndefinedObject').'</em>'; // Objects built in memory have negative IDs
  60. $oAppContext = new ApplicationContext();
  61. $sExtClassNameAtt = MetaModel::GetNameAttributeCode($sObjClass);
  62. $sPage = self::ComputeUIPage($sObjClass);
  63. $sAbsoluteUrl = utils::GetAbsoluteUrl(false); // False => Don't get the query string
  64. $sAbsoluteUrl = substr($sAbsoluteUrl, 0, 1+strrpos($sAbsoluteUrl, '/')); // remove the current page, keep just the path, up to the last /
  65. // Use the "name" of the target class as the label of the hyperlink
  66. // unless it's not available in the external attributes...
  67. if (isset($aAvailableFields[$sExtClassNameAtt]))
  68. {
  69. $sLabel = $aAvailableFields[$sExtClassNameAtt];
  70. }
  71. else
  72. {
  73. $sLabel = implode(' / ', $aAvailableFields);
  74. }
  75. // Safety belt
  76. //
  77. if (empty($sLabel))
  78. {
  79. // Developer's note:
  80. // This is doing the job for you, but that is just there in case
  81. // the external fields associated to the external key are blanks
  82. // The ultimate solution will be to query the name automatically
  83. // and independantly from the data model (automatic external field)
  84. // AND make the name be a mandatory field
  85. //
  86. $sObject = MetaModel::GetObject($sObjClass, $sObjKey);
  87. $sLabel = $sObject->GetName();
  88. }
  89. // Safety net
  90. //
  91. if (empty($sLabel))
  92. {
  93. $sLabel = MetaModel::GetName($sObjClass)." #$sObjKey";
  94. }
  95. $sHint = MetaModel::GetName($sObjClass)."::$sObjKey";
  96. return "<a href=\"{$sAbsoluteUrl}{$sPage}?operation=details&class=$sObjClass&id=$sObjKey&".$oAppContext->GetForLink()."\" title=\"$sHint\">$sLabel</a>";
  97. }
  98. function DisplayBareHeader(WebPage $oPage, $bEditMode = false)
  99. {
  100. // Standard Header with name, actions menu and history block
  101. //
  102. // action menu
  103. $oSingletonFilter = new DBObjectSearch(get_class($this));
  104. $oSingletonFilter->AddCondition('id', $this->GetKey(), '=');
  105. $oBlock = new MenuBlock($oSingletonFilter, 'popup', false);
  106. $oBlock->Display($oPage, -1);
  107. $oPage->add("<div class=\"page_header\"><h1>".$this->GetIcon()."&nbsp;\n");
  108. $oPage->add(MetaModel::GetName(get_class($this)).": <span class=\"hilite\">".$this->GetName()."</span></h1>\n");
  109. $oPage->add("</div>\n");
  110. }
  111. function DisplayBareHistory(WebPage $oPage, $bEditMode = false)
  112. {
  113. // history block (with as a tab)
  114. $oHistoryFilter = new DBObjectSearch('CMDBChangeOp');
  115. $oHistoryFilter->AddCondition('objkey', $this->GetKey(), '=');
  116. $oHistoryFilter->AddCondition('objclass', get_class($this), '=');
  117. $oBlock = new HistoryBlock($oHistoryFilter, 'table', false);
  118. $oBlock->Display($oPage, -1);
  119. }
  120. function DisplayBareProperties(WebPage $oPage, $bEditMode = false)
  121. {
  122. $oPage->add($this->GetBareProperties($oPage, $bEditMode));
  123. }
  124. function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
  125. {
  126. // Related objects: display all the linkset attributes, each as a separate tab
  127. // In the order described by the 'display' ZList
  128. $aList = $this->FlattenZList(MetaModel::GetZListItems(get_class($this), 'details'));
  129. if (count($aList) == 0)
  130. {
  131. // Empty ZList defined, display all the linkedset attributes defined
  132. $aList = array_keys(MetaModel::ListAttributeDefs(get_class($this)));
  133. }
  134. foreach($aList as $sAttCode)
  135. {
  136. $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
  137. // Display mode
  138. if (!$oAttDef->IsLinkset()) continue; // Process only linkset attributes...
  139. $oPage->SetCurrentTab($oAttDef->GetLabel());
  140. if ($bEditMode)
  141. {
  142. $iFlags = $this->GetAttributeFlags($sAttCode);
  143. $sClass = get_class($this);
  144. $sInputId = $this->m_iFormId.'_'.$sAttCode;
  145. if (get_class($oAttDef) == 'AttributeLinkedSet')
  146. {
  147. // 1:n links
  148. $sTargetClass = $oAttDef->GetLinkedClass();
  149. $oPage->p(MetaModel::GetClassIcon($sTargetClass)."&nbsp;".$oAttDef->GetDescription());
  150. $oFilter = new DBObjectSearch($sTargetClass);
  151. $oFilter->AddCondition($oAttDef->GetExtKeyToMe(), $this->GetKey(),'=');
  152. $aParams = array(
  153. 'target_attr' => $oAttDef->GetExtKeyToMe(),
  154. 'object_id' => $this->GetKey(),
  155. 'menu' => true,
  156. 'default' => array($oAttDef->GetExtKeyToMe() => $this->GetKey()),
  157. );
  158. $oBlock = new DisplayBlock($oFilter, 'list', false);
  159. $oBlock->Display($oPage, $sInputId, $aParams);
  160. }
  161. else // get_class($oAttDef) == 'AttributeLinkedSetIndirect'
  162. {
  163. // n:n links
  164. $sLinkedClass = $oAttDef->GetLinkedClass();
  165. $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote());
  166. $sTargetClass = $oLinkingAttDef->GetTargetClass();
  167. $oPage->p(MetaModel::GetClassIcon($sTargetClass)."&nbsp;".$oAttDef->GetDescription());
  168. $sValue = $this->Get($sAttCode);
  169. $sDisplayValue = $this->GetEditValue($sAttCode);
  170. $aArgs = array('this' => $this);
  171. $sHTMLValue = "<span id=\"field_{$sInputId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).'</span>';
  172. $aFieldsMap[$sAttCode] = $sInputId;
  173. $oPage->add($sHTMLValue);
  174. }
  175. }
  176. else
  177. {
  178. // Display mode
  179. if (!$oAttDef->IsIndirect())
  180. {
  181. // 1:n links
  182. $sTargetClass = $oAttDef->GetLinkedClass();
  183. $aParams = array(
  184. 'target_attr' => $oAttDef->GetExtKeyToMe(),
  185. 'object_id' => $this->GetKey(),
  186. 'menu' => true,
  187. 'default' => array($oAttDef->GetExtKeyToMe() => $this->GetKey()),
  188. );
  189. }
  190. else
  191. {
  192. // n:n links
  193. $sLinkedClass = $oAttDef->GetLinkedClass();
  194. $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote());
  195. $sTargetClass = $oLinkingAttDef->GetTargetClass();
  196. $bMenu = ($this->Get($sAttCode)->Count() > 0); // The menu is enabled only if there are already some elements...
  197. $aParams = array(
  198. 'link_attr' => $oAttDef->GetExtKeyToMe(),
  199. 'object_id' => $this->GetKey(),
  200. 'target_attr' => $oAttDef->GetExtKeyToRemote(),
  201. 'view_link' => false,
  202. 'menu' => false,
  203. 'display_limit' => true, // By default limit the list to speed up the initial load & display
  204. );
  205. }
  206. $oPage->p(MetaModel::GetClassIcon($sTargetClass)."&nbsp;".$oAttDef->GetDescription());
  207. $oBlock = new DisplayBlock($this->Get($sAttCode)->GetFilter(), 'list', false);
  208. $oBlock->Display($oPage, 'rel_'.$sAttCode, $aParams);
  209. }
  210. }
  211. $oPage->SetCurrentTab('');
  212. if (!$bEditMode)
  213. {
  214. // Get the actual class of the current object
  215. // And look for triggers referring to it
  216. // If any trigger has been found then display a tab with notifications
  217. //
  218. $sClass = get_class($this);
  219. $oTriggerSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnObject AS T WHERE T.target_class = '$sClass'"));
  220. if ($oTriggerSet->Count() > 0)
  221. {
  222. $oPage->SetCurrentTab(Dict::S('UI:NotificationsTab'));
  223. // Display notifications regarding the object
  224. $iId = $this->GetKey();
  225. $oNotifSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT EventNotificationEmail AS Ev JOIN TriggerOnObject AS T ON Ev.trigger_id = T.id WHERE T.target_class = '$sClass' AND Ev.object_id = $iId"));
  226. self::DisplaySet($oPage, $oNotifSet);
  227. }
  228. }
  229. }
  230. function GetBareProperties(WebPage $oPage, $bEditMode = false)
  231. {
  232. $sHtml = '';
  233. $oAppContext = new ApplicationContext();
  234. $sStateAttCode = MetaModel::GetStateAttributeCode(get_class($this));
  235. $aDetails = array();
  236. $sClass = get_class($this);
  237. $aDetailsList = MetaModel::GetZListItems($sClass, 'details');
  238. $aDetailsStruct = self::ProcessZlist($aDetailsList, array('UI:PropertiesTab' => array()), 'UI:PropertiesTab', 'col1', '');
  239. // Compute the list of properties to display, first the attributes in the 'details' list, then
  240. // all the remaining attributes that are not external fields
  241. $sHtml = '';
  242. $aDetails = array();
  243. foreach($aDetailsStruct as $sTab => $aCols )
  244. {
  245. $aDetails[$sTab] = array();
  246. ksort($aCols);
  247. $oPage->SetCurrentTab(Dict::S($sTab));
  248. $oPage->add('<table style="vertical-align:top"><tr>');
  249. foreach($aCols as $sColIndex => $aFieldsets)
  250. {
  251. $aDetails[$sTab][$sColIndex] = array();
  252. foreach($aFieldsets as $sFieldsetName => $aFields)
  253. {
  254. //if ($sFieldsetName == '')
  255. //{
  256. foreach($aFields as $sAttCode)
  257. {
  258. $val = $this->GetFieldAsHtml($sClass, $sAttCode, $sStateAttCode);
  259. if ($val != null)
  260. {
  261. // The field is visible, add it to the current column
  262. $aDetails[$sTab][$sColIndex][] = $val;
  263. }
  264. }
  265. //}
  266. }
  267. $oPage->add('<td style="vertical-align:top">');
  268. $oPage->Details($aDetails[$sTab][$sColIndex]);
  269. $oPage->add('</td>');
  270. }
  271. $oPage->add('</tr></table>');
  272. }
  273. return $sHtml;
  274. }
  275. function DisplayDetails(WebPage $oPage, $bEditMode = false)
  276. {
  277. $sTemplate = Utils::ReadFromFile(MetaModel::GetDisplayTemplate(get_class($this)));
  278. if (!empty($sTemplate))
  279. {
  280. $oTemplate = new DisplayTemplate($sTemplate);
  281. $sNameAttCode = MetaModel::GetNameAttributeCode(get_class($this));
  282. // Note: to preserve backward compatibility with home-made templates, the placeholder '$pkey$' has been preserved
  283. // but the preferred method is to use '$id$'
  284. $oTemplate->Render($oPage, array('class_name'=> MetaModel::GetName(get_class($this)),'class'=> get_class($this), 'pkey'=> $this->GetKey(), 'id'=> $this->GetKey(), 'name' => $this->Get($sNameAttCode)));
  285. }
  286. else
  287. {
  288. // Object's details
  289. // template not found display the object using the *old style*
  290. $this->DisplayBareHeader($oPage, $bEditMode);
  291. $oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
  292. $oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
  293. $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
  294. $this->DisplayBareProperties($oPage, $bEditMode);
  295. $this->DisplayBareRelations($oPage, $bEditMode);
  296. $oPage->SetCurrentTab(Dict::S('UI:HistoryTab'));
  297. $this->DisplayBareHistory($oPage, $bEditMode);
  298. }
  299. }
  300. function DisplayPreview(WebPage $oPage)
  301. {
  302. $aDetails = array();
  303. $sClass = get_class($this);
  304. $aList = MetaModel::GetZListItems($sClass, 'preview');
  305. foreach($aList as $sAttCode)
  306. {
  307. $aDetails[] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'value' =>$this->GetAsHTML($sAttCode));
  308. }
  309. $oPage->details($aDetails);
  310. }
  311. public static function DisplaySet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  312. {
  313. $oPage->add(self::GetDisplaySet($oPage, $oSet, $aExtraParams));
  314. }
  315. /**
  316. * Get the HTML fragment corresponding to the display of a table representing a set of objects
  317. * @param WebPage $oPage The page object is used for out-of-band information (mostly scripts) output
  318. * @param CMDBObjectSet The set of objects to display
  319. * @param Hash $aExtraParams Some extra configuration parameters to tweak the behavior of the display
  320. * @return String The HTML fragment representing the table of objects
  321. */
  322. public static function GetDisplaySet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  323. {
  324. static $iListId = 0;
  325. $iListId++;
  326. // Initialize and check the parameters
  327. $bViewLink = isset($aExtraParams['view_link']) ? $aExtraParams['view_link'] : true;
  328. $sLinkageAttribute = isset($aExtraParams['link_attr']) ? $aExtraParams['link_attr'] : '';
  329. $iLinkedObjectId = isset($aExtraParams['object_id']) ? $aExtraParams['object_id'] : 0;
  330. $sTargetAttr = isset($aExtraParams['target_attr']) ? $aExtraParams['target_attr'] : '';
  331. if (!empty($sLinkageAttribute))
  332. {
  333. if($iLinkedObjectId == 0)
  334. {
  335. // if 'links' mode is requested the id of the object to link to must be specified
  336. throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_object_id'));
  337. }
  338. if($sTargetAttr == '')
  339. {
  340. // if 'links' mode is requested the d of the object to link to must be specified
  341. throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_target_attr'));
  342. }
  343. }
  344. $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true;
  345. $bSelectMode = isset($aExtraParams['selection_mode']) ? $aExtraParams['selection_mode'] == true : false;
  346. $bSingleSelectMode = isset($aExtraParams['selection_type']) ? ($aExtraParams['selection_type'] == 'single') : false;
  347. $aExtraFields = isset($aExtraParams['extra_fields']) ? explode(',', trim($aExtraParams['extra_fields'])) : array();
  348. $sHtml = '';
  349. $oAppContext = new ApplicationContext();
  350. $sClassName = $oSet->GetFilter()->GetClass();
  351. $aAttribs = array();
  352. $aList = MetaModel::GetZListItems($sClassName, 'list');
  353. $aList = array_merge($aList, $aExtraFields);
  354. if (!empty($sLinkageAttribute))
  355. {
  356. // The set to display is in fact a set of links between the object specified in the $sLinkageAttribute
  357. // and other objects...
  358. // The display will then group all the attributes related to the link itself:
  359. // | Link_attr1 | link_attr2 | ... || Object_attr1 | Object_attr2 | Object_attr3 | .. | Object_attr_n |
  360. $aAttDefs = MetaModel::ListAttributeDefs($sClassName);
  361. assert(isset($aAttDefs[$sLinkageAttribute]));
  362. $oAttDef = $aAttDefs[$sLinkageAttribute];
  363. assert($oAttDef->IsExternalKey());
  364. // First display all the attributes specific to the link record
  365. foreach($aList as $sLinkAttCode)
  366. {
  367. $oLinkAttDef = $aAttDefs[$sLinkAttCode];
  368. if ( (!$oLinkAttDef->IsExternalKey()) && (!$oLinkAttDef->IsExternalField()) )
  369. {
  370. $aDisplayList[] = $sLinkAttCode;
  371. }
  372. }
  373. // Then display all the attributes neither specific to the link record nor to the 'linkage' object (because the latter are constant)
  374. foreach($aList as $sLinkAttCode)
  375. {
  376. $oLinkAttDef = $aAttDefs[$sLinkAttCode];
  377. if (($oLinkAttDef->IsExternalKey() && ($sLinkAttCode != $sLinkageAttribute))
  378. || ($oLinkAttDef->IsExternalField() && ($oLinkAttDef->GetKeyAttCode()!=$sLinkageAttribute)) )
  379. {
  380. $aDisplayList[] = $sLinkAttCode;
  381. }
  382. }
  383. // First display all the attributes specific to the link
  384. // Then display all the attributes linked to the other end of the relationship
  385. $aList = $aDisplayList;
  386. }
  387. if ($bSelectMode)
  388. {
  389. if (!$bSingleSelectMode)
  390. {
  391. $aAttribs['form::select'] = array('label' => "<input type=\"checkbox\" onChange=\"var value = this.checked; $('.selectList{$iListId}').each( function() { this.checked = value; } );\"></input>", 'description' => Dict::S('UI:SelectAllToggle+'));
  392. }
  393. else
  394. {
  395. $aAttribs['form::select'] = array('label' => "", 'description' => '');
  396. }
  397. }
  398. if ($bViewLink)
  399. {
  400. $aAttribs['key'] = array('label' => MetaModel::GetName($sClassName), 'description' => '');
  401. }
  402. foreach($aList as $sAttCode)
  403. {
  404. $aAttribs[$sAttCode] = array('label' => MetaModel::GetLabel($sClassName, $sAttCode), 'description' => MetaModel::GetDescription($sClassName, $sAttCode));
  405. }
  406. $aValues = array();
  407. $oSet->Seek(0);
  408. $bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true;
  409. $iMaxObjects = -1;
  410. if ($bDisplayLimit)
  411. {
  412. if ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit())
  413. {
  414. $iMaxObjects = utils::GetConfig()->GetMinDisplayLimit();
  415. }
  416. }
  417. while (($oObj = $oSet->Fetch()) && ($iMaxObjects != 0))
  418. {
  419. $aRow = array();
  420. $sHilightClass = $oObj->GetHilightClass();
  421. if ($sHilightClass != '')
  422. {
  423. $aRow['@class'] = $sHilightClass;
  424. }
  425. if ($bViewLink)
  426. {
  427. $aRow['key'] = $oObj->GetHyperLink();
  428. }
  429. if ($bSelectMode)
  430. {
  431. if ($bSingleSelectMode)
  432. {
  433. $aRow['form::select'] = "<input type=\"radio\" class=\"selectList{$iListId}\" name=\"selectObject\" value=\"".$oObj->GetKey()."\"></input>";
  434. }
  435. else
  436. {
  437. $aRow['form::select'] = "<input type=\"checkBox\" class=\"selectList{$iListId}\" name=\"selectObject[]\" value=\"".$oObj->GetKey()."\"></input>";
  438. }
  439. }
  440. foreach($aList as $sAttCode)
  441. {
  442. $aRow[$sAttCode] = $oObj->GetAsHTML($sAttCode);
  443. }
  444. $aValues[] = $aRow;
  445. $iMaxObjects--;
  446. }
  447. $sHtml .= '<table class="listContainer">';
  448. $sColspan = '';
  449. if ($bDisplayLimit && ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit()))
  450. {
  451. // list truncated
  452. $divId = $aExtraParams['block_id'];
  453. $sFilter = $oSet->GetFilter()->serialize();
  454. $aExtraParams['display_limit'] = false; // To expand the full list
  455. $sExtraParams = addslashes(str_replace('"', "'", json_encode($aExtraParams))); // JSON encode, change the style of the quotes and escape them
  456. $sHtml .= '<tr class="containerHeader"><td>'.Dict::Format('UI:TruncatedResults', utils::GetConfig()->GetMinDisplayLimit(), $oSet->Count()).'&nbsp;&nbsp;<a href="#open_'.$divId.'" onClick="Javascript:ReloadTruncatedList(\''.$divId.'\', \''.$sFilter.'\', \''.$sExtraParams.'\');">'.Dict::S('UI:DisplayAll').'</a></td><td>';
  457. $oPage->add_ready_script("$('#{$divId} table.listResults').addClass('truncated');");
  458. $oPage->add_ready_script("$('#{$divId} table.listResults tr:last td').addClass('truncated');");
  459. }
  460. else
  461. {
  462. // Full list
  463. $sHtml .= '<tr class="containerHeader"><td>&nbsp;'.Dict::Format('UI:CountOfResults', $oSet->Count()).'</td><td>';
  464. }
  465. if ($bDisplayMenu)
  466. {
  467. $oMenuBlock = new MenuBlock($oSet->GetFilter());
  468. $sColspan = 'colspan="2"';
  469. $aMenuExtraParams = $aExtraParams;
  470. if (!empty($sLinkageAttribute))
  471. {
  472. //$aMenuExtraParams['linkage'] = $sLinkageAttribute;
  473. $aMenuExtraParams = $aExtraParams;
  474. }
  475. $sHtml .= $oMenuBlock->GetRenderContent($oPage, $aMenuExtraParams);
  476. $sHtml .= '</td></tr>';
  477. }
  478. $sHtml .= "<tr><td $sColspan>";
  479. $sHtml .= $oPage->GetTable($aAttribs, $aValues);
  480. $sHtml .= '</td></tr>';
  481. $sHtml .= '</table>';
  482. return $sHtml;
  483. }
  484. public static function GetDisplayExtendedSet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  485. {
  486. static $iListId = 0;
  487. $iListId++;
  488. $aList = array();
  489. // Initialize and check the parameters
  490. $bViewLink = isset($aExtraParams['view_link']) ? $aExtraParams['view_link'] : true;
  491. $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true;
  492. // Check if there is a list of aliases to limit the display to...
  493. $aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', $aExtraParams['display_aliases']) : array();
  494. $sHtml = '';
  495. $oAppContext = new ApplicationContext();
  496. $aClasses = $oSet->GetFilter()->GetSelectedClasses();
  497. $aAuthorizedClasses = array();
  498. foreach($aClasses as $sAlias => $sClassName)
  499. {
  500. if ( (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS)) &&
  501. ( (count($aDisplayAliases) == 0) || (in_array($sAlias, $aDisplayAliases))) )
  502. {
  503. $aAuthorizedClasses[$sAlias] = $sClassName;
  504. }
  505. }
  506. $aAttribs = array();
  507. foreach($aAuthorizedClasses as $sAlias => $sClassName) // TO DO: check if the user has enough rights to view the classes of the list...
  508. {
  509. $aList[$sClassName] = MetaModel::GetZListItems($sClassName, 'list');
  510. if ($bViewLink)
  511. {
  512. $aAttribs['key_'.$sAlias] = array('label' => MetaModel::GetName($sClassName), 'description' => '');
  513. }
  514. foreach($aList[$sClassName] as $sAttCode)
  515. {
  516. $aAttribs[$sAttCode.'_'.$sAlias] = array('label' => MetaModel::GetLabel($sClassName, $sAttCode), 'description' => MetaModel::GetDescription($sClassName, $sAttCode));
  517. }
  518. }
  519. $aValues = array();
  520. $oSet->Seek(0);
  521. $bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true;
  522. $iMaxObjects = -1;
  523. if ($bDisplayLimit)
  524. {
  525. if ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit())
  526. {
  527. $iMaxObjects = utils::GetConfig()->GetMinDisplayLimit();
  528. }
  529. }
  530. while (($aObjects = $oSet->FetchAssoc()) && ($iMaxObjects != 0))
  531. {
  532. $aRow = array();
  533. foreach($aAuthorizedClasses as $sAlias => $sClassName) // TO DO: check if the user has enough rights to view the classes of the list...
  534. {
  535. if ($bViewLink)
  536. {
  537. $aRow['key_'.$sAlias] = $aObjects[$sAlias]->GetHyperLink();
  538. }
  539. foreach($aList[$sClassName] as $sAttCode)
  540. {
  541. $aRow[$sAttCode.'_'.$sAlias] = $aObjects[$sAlias]->GetAsHTML($sAttCode);
  542. }
  543. }
  544. $aValues[] = $aRow;
  545. $iMaxObjects--;
  546. }
  547. $sHtml .= '<table class="listContainer">';
  548. $sColspan = '';
  549. if ($bDisplayMenu)
  550. {
  551. $oMenuBlock = new MenuBlock($oSet->GetFilter());
  552. $sColspan = 'colspan="2"';
  553. $aMenuExtraParams = $aExtraParams;
  554. if (!empty($sLinkageAttribute))
  555. {
  556. $aMenuExtraParams = $aExtraParams;
  557. }
  558. if ($bDisplayLimit && ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit()))
  559. {
  560. // list truncated
  561. $divId = $aExtraParams['block_id'];
  562. $sFilter = $oSet->GetFilter()->serialize();
  563. $aExtraParams['display_limit'] = false; // To expand the full list
  564. $sExtraParams = addslashes(str_replace('"', "'", json_encode($aExtraParams))); // JSON encode, change the style of the quotes and escape them
  565. $sHtml .= '<tr class="containerHeader"><td>'.Dict::Format('UI:TruncatedResults', utils::GetConfig()->GetMinDisplayLimit(), $oSet->Count()).'&nbsp;&nbsp;<a href="Javascript:ReloadTruncatedList(\''.$divId.'\', \''.$sFilter.'\', \''.$sExtraParams.'\');">'.Dict::S('UI:DisplayAll').'</a></td><td>';
  566. $oPage->add_ready_script("$('#{$divId} table.listResults').addClass('truncated');");
  567. $oPage->add_ready_script("$('#{$divId} table.listResults tr:last td').addClass('truncated');");
  568. }
  569. else
  570. {
  571. // Full list
  572. $sHtml .= '<tr class="containerHeader"><td>&nbsp;'.Dict::Format('UI:CountOfResults', $oSet->Count()).'</td><td>';
  573. }
  574. $sHtml .= $oMenuBlock->GetRenderContent($oPage, $aMenuExtraParams);
  575. $sHtml .= '</td></tr>';
  576. }
  577. $sHtml .= "<tr><td $sColspan>";
  578. $sHtml .= $oPage->GetTable($aAttribs, $aValues);
  579. $sHtml .= '</td></tr>';
  580. $sHtml .= '</table>';
  581. return $sHtml;
  582. }
  583. static function DisplaySetAsCSV(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array())
  584. {
  585. $oPage->add(self::GetSetAsCSV($oSet, $aParams));
  586. }
  587. static function GetSetAsCSV(DBObjectSet $oSet, $aParams = array())
  588. {
  589. $sSeparator = isset($aParams['separator']) ? $aParams['separator'] : ','; // default separator is comma
  590. $sTextQualifier = isset($aParams['text_qualifier']) ? $aParams['text_qualifier'] : '"'; // default text qualifier is double quote
  591. $aList = array();
  592. $oAppContext = new ApplicationContext();
  593. $aClasses = $oSet->GetFilter()->GetSelectedClasses();
  594. $aAuthorizedClasses = array();
  595. foreach($aClasses as $sAlias => $sClassName)
  596. {
  597. if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS))
  598. {
  599. $aAuthorizedClasses[$sAlias] = $sClassName;
  600. }
  601. }
  602. $aAttribs = array();
  603. $aHeader = array();
  604. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  605. {
  606. foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode => $oAttDef)
  607. {
  608. if ((($oAttDef->IsExternalField()) || ($oAttDef->IsWritable())) && $oAttDef->IsScalar())
  609. {
  610. $aList[$sClassName][$sAttCode] = $oAttDef;
  611. }
  612. }
  613. $aHeader[] = 'id';
  614. foreach($aList[$sClassName] as $sAttCode => $oAttDef)
  615. {
  616. if ($oAttDef->IsExternalField())
  617. {
  618. $sExtKeyLabel = MetaModel::GetLabel($sClassName, $oAttDef->GetKeyAttCode());
  619. $sRemoteAttLabel = MetaModel::GetLabel($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
  620. $aHeader[] = $sExtKeyLabel.'->'.$sRemoteAttLabel;
  621. }
  622. else
  623. {
  624. $aHeader[] = MetaModel::GetLabel($sClassName, $sAttCode);
  625. }
  626. }
  627. }
  628. $sHtml = implode($sSeparator, $aHeader)."\n";
  629. $oSet->Seek(0);
  630. while ($aObjects = $oSet->FetchAssoc())
  631. {
  632. $aRow = array();
  633. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  634. {
  635. $oObj = $aObjects[$sAlias];
  636. $aRow[] = $oObj->GetKey();
  637. foreach($aList[$sClassName] as $sAttCode => $oAttDef)
  638. {
  639. $aRow[] = $oObj->GetAsCSV($sAttCode, $sSeparator, '\\');
  640. }
  641. }
  642. $sHtml .= implode($sSeparator, $aRow)."\n";
  643. }
  644. return $sHtml;
  645. }
  646. static function DisplaySetAsXML(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array())
  647. {
  648. $oAppContext = new ApplicationContext();
  649. $aClasses = $oSet->GetFilter()->GetSelectedClasses();
  650. $aAuthorizedClasses = array();
  651. foreach($aClasses as $sAlias => $sClassName)
  652. {
  653. if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS))
  654. {
  655. $aAuthorizedClasses[$sAlias] = $sClassName;
  656. }
  657. }
  658. $aAttribs = array();
  659. $aList = array();
  660. $aList[$sClassName] = MetaModel::GetZListItems($sClassName, 'details');
  661. $oPage->add("<Set>\n");
  662. $oSet->Seek(0);
  663. while ($aObjects = $oSet->FetchAssoc())
  664. {
  665. if (count($aAuthorizedClasses) > 1)
  666. {
  667. $oPage->add("<Row>\n");
  668. }
  669. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  670. {
  671. $oObj = $aObjects[$sAlias];
  672. $sClassName = get_class($oObj);
  673. $oPage->add("<$sClassName alias=\"$sAlias\" id=\"".$oObj->GetKey()."\">\n");
  674. foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode=>$oAttDef)
  675. {
  676. if (($oAttDef->IsWritable()) && ($oAttDef->IsScalar()))
  677. {
  678. $sValue = $oObj->GetAsXML($sAttCode);
  679. $oPage->add("<$sAttCode>$sValue</$sAttCode>\n");
  680. }
  681. }
  682. $oPage->add("</$sClassName>\n");
  683. }
  684. if (count($aAuthorizedClasses) > 1)
  685. {
  686. $oPage->add("</Row>\n");
  687. }
  688. }
  689. $oPage->add("</Set>\n");
  690. }
  691. // By rom
  692. function DisplayChangesLog(WebPage $oPage)
  693. {
  694. $oFltChangeOps = new CMDBSearchFilter('CMDBChangeOpSetAttribute');
  695. $oFltChangeOps->AddCondition('objkey', $this->GetKey(), '=');
  696. $oFltChangeOps->AddCondition('objclass', get_class($this), '=');
  697. $oSet = new CMDBObjectSet($oFltChangeOps, array('date' => false)); // order by date descending (i.e. false)
  698. $count = $oSet->Count();
  699. if ($count > 0)
  700. {
  701. $oPage->p(Dict::Format('UI:ChangesLogTitle', $count));
  702. self::DisplaySet($oPage, $oSet);
  703. }
  704. else
  705. {
  706. $oPage->p(Dict::S('UI:EmptyChangesLogTitle'));
  707. }
  708. }
  709. public static function DisplaySearchForm(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  710. {
  711. $oPage->add(self::GetSearchForm($oPage, $oSet, $aExtraParams));
  712. }
  713. public static function GetSearchForm(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  714. {
  715. static $iSearchFormId = 0;
  716. $oAppContext = new ApplicationContext();
  717. $sHtml = '';
  718. $numCols=4;
  719. $sClassName = $oSet->GetFilter()->GetClass();
  720. // Romain: temporarily removed the tab "OQL query" because it was not finalized
  721. // (especially when used to add a link)
  722. /*
  723. $sHtml .= "<div class=\"mini_tabs\" id=\"mini_tabs{$iSearchFormId}\"><ul>
  724. <li><a href=\"#\" onClick=\"$('div.mini_tab{$iSearchFormId}').toggle();$('#mini_tabs{$iSearchFormId} ul li a').toggleClass('selected');\">".Dict::S('UI:OQLQueryTab')."</a></li>
  725. <li><a class=\"selected\" href=\"#\" onClick=\"$('div.mini_tab{$iSearchFormId}').toggle();$('#mini_tabs{$iSearchFormId} ul li a').toggleClass('selected');\">".Dict::S('UI:SimpleSearchTab')."</a></li>
  726. </ul></div>\n";
  727. */
  728. // Simple search form
  729. if (isset($aExtraParams['currentId']))
  730. {
  731. $sSearchFormId = $aExtraParams['currentId'];
  732. $iSearchFormId++;
  733. }
  734. else
  735. {
  736. $iSearchFormId++;
  737. $sSearchFormId = 'SimpleSearchForm'.$iSearchFormId;
  738. $sHtml .= "<div id=\"$sSearchFormId\" class=\"mini_tab{$iSearchFormId}\">\n";
  739. }
  740. // Check if the current class has some sub-classes
  741. if (isset($aExtraParams['baseClass']))
  742. {
  743. $sRootClass = $aExtraParams['baseClass'];
  744. }
  745. else
  746. {
  747. $sRootClass = $sClassName;
  748. }
  749. $aSubClasses = MetaModel::GetSubclasses($sRootClass);
  750. if (count($aSubClasses) > 0)
  751. {
  752. $aOptions = array();
  753. $aOptions[MetaModel::GetName($sRootClass)] = "<option value=\"$sRootClass\">".MetaModel::GetName($sRootClass)."</options>\n";
  754. foreach($aSubClasses as $sSubclassName)
  755. {
  756. $aOptions[MetaModel::GetName($sSubclassName)] = "<option value=\"$sSubclassName\">".MetaModel::GetName($sSubclassName)."</options>\n";
  757. }
  758. $aOptions[MetaModel::GetName($sClassName)] = "<option selected value=\"$sClassName\">".MetaModel::GetName($sClassName)."</options>\n";
  759. ksort($aOptions);
  760. $sClassesCombo = "<select name=\"class\" onChange=\"ReloadSearchForm('$sSearchFormId', this.value, '$sRootClass')\">\n".implode('', $aOptions)."</select>\n";
  761. }
  762. else
  763. {
  764. $sClassesCombo = MetaModel::GetName($sClassName);
  765. }
  766. $oUnlimitedFilter = new DBObjectSearch($sClassName);
  767. $sHtml .= "<form id=\"form{$iSearchFormId}\">\n";
  768. $sHtml .= "<h2>".Dict::Format('UI:SearchFor_Class_Objects', $sClassesCombo)."</h2>\n";
  769. $index = 0;
  770. $sHtml .= "<p>\n";
  771. $aFilterCriteria = $oSet->GetFilter()->GetCriteria();
  772. $aMapCriteria = array();
  773. foreach($aFilterCriteria as $aCriteria)
  774. {
  775. $aMapCriteria[$aCriteria['filtercode']][] = array('value' => $aCriteria['value'], 'opcode' => $aCriteria['opcode']);
  776. }
  777. $aList = MetaModel::GetZListItems($sClassName, 'standard_search');
  778. foreach($aList as $sFilterCode)
  779. {
  780. $oAppContext->Reset($sFilterCode); // Make sure the same parameter will not be passed twice
  781. $sHtml .= '<span style="white-space: nowrap;padding:5px;display:inline-block;">';
  782. $sFilterValue = '';
  783. $sFilterValue = utils::ReadParam($sFilterCode, '');
  784. $sFilterOpCode = null; // Use the default 'loose' OpCode
  785. if (empty($sFilterValue))
  786. {
  787. if (isset($aMapCriteria[$sFilterCode]))
  788. {
  789. if (count($aMapCriteria[$sFilterCode]) > 1)
  790. {
  791. $sFilterValue = Dict::S('UI:SearchValue:Mixed');
  792. }
  793. else
  794. {
  795. $sFilterValue = $aMapCriteria[$sFilterCode][0]['value'];
  796. $sFilterOpCode = $aMapCriteria[$sFilterCode][0]['opcode'];
  797. }
  798. if ($sFilterCode != 'company')
  799. {
  800. $oUnlimitedFilter->AddCondition($sFilterCode, $sFilterValue, $sFilterOpCode);
  801. }
  802. }
  803. }
  804. $aAllowedValues = MetaModel::GetAllowedValues_flt($sClassName, $sFilterCode, $aExtraParams);
  805. if ($aAllowedValues != null)
  806. {
  807. //Enum field or external key, display a combo
  808. $sValue = "<select name=\"$sFilterCode\">\n";
  809. $sValue .= "<option value=\"\">".Dict::S('UI:SearchValue:Any')."</option>\n";
  810. foreach($aAllowedValues as $key => $value)
  811. {
  812. if ($sFilterValue == $key)
  813. {
  814. $sSelected = ' selected';
  815. }
  816. else
  817. {
  818. $sSelected = '';
  819. }
  820. $sValue .= "<option value=\"$key\"$sSelected>$value</option>\n";
  821. }
  822. $sValue .= "</select>\n";
  823. $sHtml .= "<label>".MetaModel::GetFilterLabel($sClassName, $sFilterCode).":</label>&nbsp;$sValue\n";
  824. }
  825. else
  826. {
  827. // Any value is possible, display an input box
  828. $sHtml .= "<label>".MetaModel::GetFilterLabel($sClassName, $sFilterCode).":</label>&nbsp;<input class=\"textSearch\" name=\"$sFilterCode\" value=\"$sFilterValue\"/>\n";
  829. }
  830. $index++;
  831. $sHtml .= '</span> ';
  832. }
  833. $sHtml .= "</p>\n";
  834. $sHtml .= "<p align=\"right\"><input type=\"submit\" value=\"".Dict::S('UI:Button:Search')."\"></p>\n";
  835. foreach($aExtraParams as $sName => $sValue)
  836. {
  837. $sHtml .= "<input type=\"hidden\" name=\"$sName\" value=\"$sValue\" />\n";
  838. }
  839. $sHtml .= "<input type=\"hidden\" name=\"class\" value=\"$sClassName\" />\n";
  840. $sHtml .= "<input type=\"hidden\" name=\"dosearch\" value=\"1\" />\n";
  841. $sHtml .= "<input type=\"hidden\" name=\"operation\" value=\"search_form\" />\n";
  842. $sHtml .= $oAppContext->GetForForm();
  843. $sHtml .= "</form>\n";
  844. if (!isset($aExtraParams['currentId']))
  845. {
  846. $sHtml .= "</div><!-- Simple search form -->\n";
  847. }
  848. // OQL query builder
  849. $sHtml .= "<div id=\"OQLQuery{$iSearchFormId}\" style=\"display:none\" class=\"mini_tab{$iSearchFormId}\">\n";
  850. $sHtml .= "<h1>".Dict::S('UI:OQLQueryBuilderTitle')."</h1>\n";
  851. $sHtml .= "<form id=\"formOQL{$iSearchFormId}\"><table style=\"width:80%;\"><tr style=\"vertical-align:top\">\n";
  852. $sHtml .= "<td style=\"text-align:right\"><label>SELECT&nbsp;</label><select name=\"oql_class\">";
  853. $aClasses = MetaModel::EnumChildClasses($sClassName, ENUM_CHILD_CLASSES_ALL);
  854. $sSelectedClass = utils::ReadParam('oql_class', $sClassName);
  855. $sOQLClause = utils::ReadParam('oql_clause', '');
  856. asort($aClasses);
  857. foreach($aClasses as $sChildClass)
  858. {
  859. $sSelected = ($sChildClass == $sSelectedClass) ? 'selected' : '';
  860. $sHtml.= "<option value=\"$sChildClass\" $sSelected>".MetaModel::GetName($sChildClass)."</option>\n";
  861. }
  862. $sHtml .= "</select>&nbsp;</td><td>\n";
  863. $sHtml .= "<textarea name=\"oql_clause\" style=\"width:100%\">$sOQLClause</textarea></td></tr>\n";
  864. $sHtml .= "<tr><td colspan=\"2\" style=\"text-align:right\"><input type=\"submit\" value=\"".Dict::S('UI:Button:Query')."\"></td></tr>\n";
  865. $sHtml .= "<input type=\"hidden\" name=\"dosearch\" value=\"1\" />\n";
  866. foreach($aExtraParams as $sName => $sValue)
  867. {
  868. $sHtml .= "<input type=\"hidden\" name=\"$sName\" value=\"$sValue\" />\n";
  869. }
  870. $sHtml .= "<input type=\"hidden\" name=\"operation\" value=\"search_oql\" />\n";
  871. $sHtml .= $oAppContext->GetForForm();
  872. $sHtml .= "</table></form>\n";
  873. $sHtml .= "</div><!-- OQL query form -->\n";
  874. return $sHtml;
  875. }
  876. public static function GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value = '', $sDisplayValue = '', $iId = '', $sNameSuffix = '', $iFlags = 0, $aArgs = array())
  877. {
  878. static $iInputId = 0;
  879. $sFieldPrefix = '';
  880. if (isset($aArgs['prefix']))
  881. {
  882. $sFieldPrefix = $aArgs['prefix'];
  883. }
  884. if (isset($aArgs[$sAttCode]) && empty($value))
  885. {
  886. // default value passed by the context (either the app context of the operation)
  887. $value = $aArgs[$sAttCode];
  888. }
  889. if (!empty($iId))
  890. {
  891. $iInputId = $iId;
  892. }
  893. else
  894. {
  895. $iInputId++;
  896. $iId = $iInputId;
  897. }
  898. if (!$oAttDef->IsExternalField())
  899. {
  900. $aCSSClasses = array();
  901. $bMandatory = 0;
  902. if ( (!$oAttDef->IsNullAllowed()) || ($iFlags & OPT_ATT_MANDATORY))
  903. {
  904. $aCSSClasses[] = 'mandatory';
  905. $bMandatory = 1;
  906. }
  907. $sCSSClasses = self::GetCSSClasses($aCSSClasses);
  908. $sValidationField = "<span id=\"v_{$iId}\"></span>";
  909. $sHelpText = $oAttDef->GetHelpOnEdition();
  910. $aEventsList = array('validate');
  911. switch($oAttDef->GetEditClass())
  912. {
  913. case 'Date':
  914. case 'DateTime':
  915. $aEventsList[] ='keyup';
  916. $aEventsList[] ='change';
  917. $sHTMLValue = "<input title=\"$sHelpText\" class=\"date-pick\" type=\"text\" size=\"20\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  918. break;
  919. case 'Password':
  920. $aEventsList[] ='keyup';
  921. $aEventsList[] ='change';
  922. $sHTMLValue = "<input title=\"$sHelpText\" type=\"password\" size=\"30\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  923. break;
  924. case 'Text':
  925. $aEventsList[] ='keyup';
  926. $aEventsList[] ='change';
  927. $sHTMLValue = "<textarea class=\"resizable\" title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" rows=\"8\" cols=\"40\" id=\"$iId\">$value</textarea>&nbsp;{$sValidationField}";
  928. break;
  929. case 'LinkedSet':
  930. $aEventsList[] ='change';
  931. $oWidget = new UILinksWidget($sClass, $sAttCode, $iId, $sNameSuffix);
  932. $sHTMLValue = $oWidget->Display($oPage, $value);
  933. break;
  934. case 'Document':
  935. $aEventsList[] ='change';
  936. $oDocument = $value; // Value is an ormDocument object
  937. $sFileName = '';
  938. if (is_object($oDocument))
  939. {
  940. $sFileName = $oDocument->GetFileName();
  941. }
  942. $iMaxFileSize = utils::ConvertToBytes(ini_get('upload_max_filesize'));
  943. $sHTMLValue = "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$iMaxFileSize\" />\n";
  944. $sHTMLValue .= "<input name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" type=\"hidden\" id=\"$iId\" \" value=\"$sFileName\"/>\n";
  945. $sHTMLValue .= "<span id=\"name_$iInputId\">$sFileName</span><br/>\n";
  946. $sHTMLValue .= "<input title=\"$sHelpText\" name=\"file_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" type=\"file\" id=\"file_$iId\" onChange=\"UpdateFileName('$iId', this.value)\"/>&nbsp;{$sValidationField}\n";
  947. break;
  948. case 'List':
  949. // Not editable for now...
  950. $sHTMLValue = '';
  951. break;
  952. case 'One Way Password':
  953. $oWidget = new UIPasswordWidget($sAttCode, $iId, $sNameSuffix);
  954. $sHTMLValue = $oWidget->Display($oPage, $aArgs);
  955. // Event list & validation is handled directly by the widget
  956. break;
  957. case 'String':
  958. default:
  959. // #@# todo - add context information (depending on dimensions)
  960. $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
  961. if ($aAllowedValues !== null)
  962. {
  963. //Enum field or external key, display a combo
  964. //if (count($aAllowedValues) == 0)
  965. //{
  966. // $sHTMLValue = "<input count=\"0\" type=\"text\" size=\"30\" value=\"\" name=\"attr_{$sAttCode}{$sNameSuffix}\" id=\"$iInputId\"{$sCSSClasses}/>";
  967. //}
  968. //else if (count($aAllowedValues) > 50)
  969. if (count($aAllowedValues) > 50)
  970. {
  971. // too many choices, use an autocomplete
  972. // The input for the auto complete
  973. $sHTMLValue = "<input count=\"".count($aAllowedValues)."\" type=\"text\" id=\"label_$iId\" size=\"30\" value=\"$sDisplayValue\"{$sCSSClasses}/>&nbsp;{$sValidationField}";
  974. // another hidden input to store & pass the object's Id
  975. $sHTMLValue .= "<input type=\"hidden\" id=\"$iId\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" />\n";
  976. $oPage->add_ready_script("\$('#label_$iId').autocomplete('./ajax.render.php', { scroll:true, minChars:3, onItemSelect:selectItem, onFindValue:findValue, formatItem:formatItem, autoFill:true, keyHolder:'#$iId', extraParams:{operation:'autocomplete', sclass:'$sClass',attCode:'".$sAttCode."'}});");
  977. $oPage->add_ready_script("\$('#label_$iId').result( function(event, data, formatted) { if (data) { $('#{$iId}').val(data[1]); } } );");
  978. $aEventsList[] ='change';
  979. }
  980. else
  981. {
  982. // Few choices, use a normal 'select'
  983. // In case there are no valid values, the select will be empty, thus blocking the user from validating the form
  984. $sHTMLValue = "<select title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" id=\"$iId\">\n";
  985. $sHTMLValue .= "<option value=\"0\">".Dict::S('UI:SelectOne')."</option>\n";
  986. foreach($aAllowedValues as $key => $display_value)
  987. {
  988. if ((count($aAllowedValues) == 1) && $bMandatory )
  989. {
  990. // When there is only once choice, select it by default
  991. $sSelected = ' selected';
  992. }
  993. else
  994. {
  995. $sSelected = ($value == $key) ? ' selected' : '';
  996. }
  997. $sHTMLValue .= "<option value=\"$key\"$sSelected>$display_value</option>\n";
  998. }
  999. $sHTMLValue .= "</select>&nbsp;{$sValidationField}\n";
  1000. $aEventsList[] ='change';
  1001. }
  1002. }
  1003. else
  1004. {
  1005. $sHTMLValue = "<input title=\"$sHelpText\" type=\"text\" size=\"30\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  1006. $aEventsList[] ='keyup';
  1007. $aEventsList[] ='change';
  1008. }
  1009. break;
  1010. }
  1011. $sPattern = addslashes($oAttDef->GetValidationPattern()); //'^([0-9]+)$';
  1012. if (!empty($aEventlist))
  1013. {
  1014. $oPage->add_ready_script("$('#$iId').bind('".implode(' ', $aEventsList)."', function(evt, sFormId) { return ValidateField('$iId', '$sPattern', $bMandatory, sFormId) } );"); // Bind to a custom event: validate
  1015. }
  1016. $aDependencies = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that depend on the current one
  1017. if (count($aDependencies) > 0)
  1018. {
  1019. $oPage->add_ready_script("$('#$iId').bind('change', function(evt, sFormId) { return UpdateDependentFields(['".implode("','", $aDependencies)."']) } );"); // Bind to a custom event: validate
  1020. }
  1021. }
  1022. return "<div>{$sHTMLValue}</div>";
  1023. }
  1024. public function DisplayModifyForm(WebPage $oPage, $aExtraParams = array())
  1025. {
  1026. static $iGlobalFormId = 0;
  1027. $iGlobalFormId++;
  1028. $this->m_iFormId = $iGlobalFormId;
  1029. $sClass = get_class($this);
  1030. $oAppContext = new ApplicationContext();
  1031. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  1032. $iKey = $this->GetKey();
  1033. $aDetails = array();
  1034. $aFieldsMap = array();
  1035. if (!isset($aExtraParams['action']))
  1036. {
  1037. $sFormAction = $_SERVER['SCRIPT_NAME']; // No parameter in the URL, the only parameter will be the ones passed through the form
  1038. }
  1039. else
  1040. {
  1041. $sFormAction = $aExtraParams['action'];
  1042. }
  1043. $oPage->add("<form action=\"$sFormAction\" id=\"form_{$this->m_iFormId}\" enctype=\"multipart/form-data\" method=\"post\" onSubmit=\"return CheckFields('form_{$this->m_iFormId}', true)\">\n");
  1044. $oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
  1045. $oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
  1046. $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
  1047. $aDetailsList = $this->FLattenZList(MetaModel::GetZListItems($sClass, 'details'));
  1048. //$aFullList = MetaModel::ListAttributeDefs($sClass);
  1049. $aList = array();
  1050. // Compute the list of properties to display, first the attributes in the 'details' list, then
  1051. // all the remaining attributes that are not external fields
  1052. foreach($aDetailsList as $sAttCode)
  1053. {
  1054. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1055. if (!$oAttDef->IsExternalField())
  1056. {
  1057. $aList[] = $sAttCode;
  1058. }
  1059. }
  1060. foreach($aList as $sAttCode)
  1061. {
  1062. $iFlags = $this->GetAttributeFlags($sAttCode);
  1063. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1064. if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0))
  1065. {
  1066. if ($oAttDef->IsWritable())
  1067. {
  1068. if ($sStateAttCode == $sAttCode)
  1069. {
  1070. // State attribute is always read-only from the UI
  1071. $sHTMLValue = $this->GetStateLabel();
  1072. $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue);
  1073. }
  1074. else
  1075. {
  1076. $iFlags = $this->GetAttributeFlags($sAttCode);
  1077. if ($iFlags & OPT_ATT_HIDDEN)
  1078. {
  1079. // Attribute is hidden, do nothing
  1080. }
  1081. else
  1082. {
  1083. if ($iFlags & OPT_ATT_READONLY)
  1084. {
  1085. // Attribute is read-only
  1086. $sHTMLValue = $this->GetAsHTML($sAttCode);
  1087. }
  1088. else
  1089. {
  1090. $sValue = $this->Get($sAttCode);
  1091. $sDisplayValue = $this->GetEditValue($sAttCode);
  1092. $aArgs = array('this' => $this);
  1093. $sInputId = $this->m_iFormId.'_'.$sAttCode;
  1094. $sHTMLValue = "<span id=\"field_{$sInputId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).'</span>';
  1095. $aFieldsMap[$sAttCode] = $sInputId;
  1096. }
  1097. $aDetails[] = array('label' => '<span title="'.$oAttDef->GetDescription().'">'.$oAttDef->GetLabel().'</span>', 'value' => $sHTMLValue);
  1098. }
  1099. }
  1100. }
  1101. else
  1102. {
  1103. $aDetails[] = array('label' => '<span title="'.$oAttDef->GetDescription().'">'.$oAttDef->GetLabel().'</span>', 'value' => $this->GetAsHTML($sAttCode));
  1104. }
  1105. }
  1106. }
  1107. $oPage->details($aDetails);
  1108. // Now display the relations, one tab per relation
  1109. $this->DisplayBareRelations($oPage, true); // Edit mode
  1110. $oPage->SetCurrentTab('');
  1111. $oPage->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">\n");
  1112. $oPage->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
  1113. foreach($aExtraParams as $sName => $value)
  1114. {
  1115. $oPage->add("<input type=\"hidden\" name=\"$sName\" value=\"$value\">\n");
  1116. }
  1117. $oPage->add($oAppContext->GetForForm());
  1118. if ($iKey > 0)
  1119. {
  1120. // The object already exists in the database, it's modification
  1121. $oPage->add("<input type=\"hidden\" name=\"id\" value=\"$iKey\">\n");
  1122. $oPage->add("<input type=\"hidden\" name=\"operation\" value=\"apply_modify\">\n");
  1123. $oPage->add("<button type=\"button\" class=\"action\" onClick=\"BackToDetails('$sClass', $iKey)\"><span>".Dict::S('UI:Button:Cancel')."</span></button>&nbsp;&nbsp;&nbsp;&nbsp;\n");
  1124. $oPage->add("<button type=\"submit\" class=\"action\"><span>".Dict::S('UI:Button:Apply')."</span></button>\n");
  1125. }
  1126. else
  1127. {
  1128. // The object does not exist in the database it's a creation
  1129. $oPage->add("<input type=\"hidden\" name=\"operation\" value=\"apply_new\">\n");
  1130. $oPage->add("<button type=\"button\" class=\"action\" onClick=\"goBack()\"><span>".Dict::S('UI:Button:Cancel')."</span></button>&nbsp;&nbsp;&nbsp;&nbsp;\n");
  1131. $oPage->add("<button type=\"submit\" class=\"action\"><span>".Dict::S('UI:Button:Create')."</span></button>\n");
  1132. }
  1133. $oPage->add("</form>\n");
  1134. $iFieldsCount = count($aFieldsMap);
  1135. $sJsonFieldsMap = json_encode($aFieldsMap);
  1136. $oPage->add_script(
  1137. <<<EOF
  1138. // Create the object once at the beginning of the page...
  1139. var oWizardHelper = new WizardHelper('$sClass');
  1140. oWizardHelper.SetFieldsMap($sJsonFieldsMap);
  1141. oWizardHelper.SetFieldsCount($iFieldsCount);
  1142. EOF
  1143. );
  1144. $oPage->add_ready_script(
  1145. <<<EOF
  1146. // Starts the validation when the page is ready
  1147. CheckFields('form_{$this->m_iFormId}', false);
  1148. EOF
  1149. );
  1150. }
  1151. public static function DisplayCreationForm(WebPage $oPage, $sClass, $oObjectToClone = null, $aArgs = array(), $aExtraParams = array())
  1152. {
  1153. $oAppContext = new ApplicationContext();
  1154. $sClass = ($oObjectToClone == null) ? $sClass : get_class($oObjectToClone);
  1155. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  1156. $aStates = MetaModel::EnumStates($sClass);
  1157. if ($oObjectToClone == null)
  1158. {
  1159. $sTargetState = MetaModel::GetDefaultState($sClass);
  1160. $oObj = MetaModel::NewObject($sClass);
  1161. $oObj->Set($sStateAttCode, $sTargetState);
  1162. }
  1163. else
  1164. {
  1165. $oObj = clone $oObjectToClone;
  1166. }
  1167. // Pre-fill the object with default values, when there is only on possible choice
  1168. // AND the field is mandatory (otherwise there is always the possiblity to let it empty)
  1169. $aArgs['this'] = $oObj;
  1170. $aDetailsList = self::FLattenZList(MetaModel::GetZListItems($sClass, 'details'));
  1171. // TO DO: the list should be ordered based on the dependencies between fields
  1172. // i.e. if some fields depend on another field, the latter should be computed first...
  1173. // Right now we depend on the display order... anyhow if the display order does not
  1174. // reflect the dependency order, the UI will not be so intuitive to use... beware
  1175. foreach($aDetailsList as $sAttCode)
  1176. {
  1177. $bMandatory = false;
  1178. $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
  1179. if (count($aAllowedValues) == 1)
  1180. {
  1181. // If the field is mandatory, set it to the only possible value
  1182. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1183. $iFlags = $oObj->GetAttributeFlags($sAttCode);
  1184. if ( (!$oAttDef->IsNullAllowed()) || ($iFlags & OPT_ATT_MANDATORY))
  1185. {
  1186. $aValues = array_keys($aAllowedValues);
  1187. $oObj->Set($sAttCode, $aValues[0]);
  1188. }
  1189. }
  1190. }
  1191. return $oObj->DisplayModifyForm( $oPage, $aExtraParams = array());
  1192. }
  1193. protected static function GetCSSClasses($aCSSClasses)
  1194. {
  1195. $sCSSClasses = '';
  1196. if (!empty($aCSSClasses))
  1197. {
  1198. $sCSSClasses = ' class="'.implode(' ', $aCSSClasses).'" ';
  1199. }
  1200. return $sCSSClasses;
  1201. }
  1202. protected static function ProcessZlist($aList, $aDetails, $sCurrentTab, $sCurrentCol, $sCurrentSet)
  1203. {
  1204. //echo "<pre>ZList: ";
  1205. //print_r($aList);
  1206. //echo "</pre>\n";
  1207. foreach($aList as $sKey => $value)
  1208. {
  1209. if (is_array($value))
  1210. {
  1211. if (preg_match('/^(.*):(.*)$/U', $sKey, $aMatches))
  1212. {
  1213. $sCode = $aMatches[1];
  1214. $sName = $aMatches[2];
  1215. switch($sCode)
  1216. {
  1217. case 'tab':
  1218. //echo "<p>Found a tab: $sName ($sKey)</p>\n";
  1219. if(!isset($aDetails[$sName]))
  1220. {
  1221. $aDetails[$sName] = array('col1' => array('' => array()));
  1222. }
  1223. $aDetails = self::ProcessZlist($value, $aDetails, $sName, 'col1', '');
  1224. break;
  1225. case 'fieldset':
  1226. //echo "<p>Found a fieldset: $sName ($sKey)</p>\n";
  1227. if(!isset($aDetailsStruct[$sCurrentTab][$sCurrentCol][$sName]))
  1228. {
  1229. $aDetails[$sCurrentTab][$sCurrentCol][$sName] = array();
  1230. }
  1231. $aDetails = self::ProcessZlist($value, $aDetails, $sCurrentTab, $sCurrentCol, $sName);
  1232. break;
  1233. default:
  1234. case 'col':
  1235. //echo "<p>Found a column: $sName ($sKey)</p>\n";
  1236. if(!isset($aDetails[$sCurrentTab][$sName]))
  1237. {
  1238. $aDetails[$sCurrentTab][$sName] = array('' => array());
  1239. }
  1240. $aDetails = self::ProcessZlist($value, $aDetails, $sCurrentTab, $sName, '');
  1241. break;
  1242. }
  1243. }
  1244. }
  1245. else
  1246. {
  1247. //echo "<p>Scalar value: $value, in [$sCurrentTab][$sCurrentCol][$sCurrentSet][]</p>\n";
  1248. $aDetails[$sCurrentTab][$sCurrentCol][$sCurrentSet][] = $value;
  1249. }
  1250. }
  1251. return $aDetails;
  1252. }
  1253. protected static function FlattenZList($aList)
  1254. {
  1255. $aResult = array();
  1256. foreach($aList as $value)
  1257. {
  1258. if (!is_array($value))
  1259. {
  1260. $aResult[] = $value;
  1261. }
  1262. else
  1263. {
  1264. $aResult = array_merge($aResult, $this->FlattenZList($value));
  1265. }
  1266. }
  1267. return $aResult;
  1268. }
  1269. protected function GetFieldAsHtml($sClass, $sAttCode, $sStateAttCode)
  1270. {
  1271. $retVal = null;
  1272. $iFlags = $this->GetAttributeFlags($sAttCode);
  1273. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1274. if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0) )
  1275. {
  1276. // The field is visible in the current state of the object
  1277. if ($sStateAttCode == $sAttCode)
  1278. {
  1279. // Special display for the 'state' attribute itself
  1280. $sDisplayValue = $this->GetStateLabel();
  1281. }
  1282. else if ($oAttDef->GetEditClass() == 'Document')
  1283. {
  1284. $oDocument = $this->Get($sAttCode);
  1285. $sDisplayValue = $this->GetAsHTML($sAttCode);
  1286. $sDisplayValue .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_', $oDocument->GetDisplayLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
  1287. $sDisplayValue .= "<br/>".Dict::Format('UI:DownloadDocument_', $oDocument->GetDisplayLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
  1288. }
  1289. else
  1290. {
  1291. $sDisplayValue = $this->GetAsHTML($sAttCode);
  1292. }
  1293. $retVal = array('label' => '<span title="'.MetaModel::GetDescription($sClass, $sAttCode).'">'.MetaModel::GetLabel($sClass, $sAttCode).'</span>', 'value' => $sDisplayValue);
  1294. }
  1295. return $retVal;
  1296. }
  1297. /**
  1298. * Displays a blob document *inline* (if possible, depending on the type of the document)
  1299. * @return string
  1300. */
  1301. public function DisplayDocumentInline(WebPage $oPage, $sAttCode)
  1302. {
  1303. $oDoc = $this->Get($sAttCode);
  1304. $sClass = get_class($this);
  1305. $Id = $this->GetKey();
  1306. switch ($oDoc->GetMainMimeType())
  1307. {
  1308. case 'text':
  1309. case 'html':
  1310. $data = $oDoc->GetData();
  1311. switch($oDoc->GetMimeType())
  1312. {
  1313. case 'text/html':
  1314. case 'text/xml':
  1315. $oPage->add("<iframe id='preview_$sAttCode' src=\"../pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" width=\"100%\" height=\"400\">Loading...</iframe>\n");
  1316. break;
  1317. default:
  1318. $oPage->add("<pre>".htmlentities(MyHelpers::beautifulstr($data, 1000, true))."</pre>\n");
  1319. }
  1320. break;
  1321. case 'application':
  1322. switch($oDoc->GetMimeType())
  1323. {
  1324. case 'application/pdf':
  1325. $oPage->add("<iframe id='preview_$sAttCode' src=\"../pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" width=\"100%\" height=\"400\">Loading...</iframe>\n");
  1326. break;
  1327. default:
  1328. $oPage->add(Dict::S('UI:Document:NoPreview'));
  1329. }
  1330. break;
  1331. case 'image':
  1332. $oPage->add("<img src=\"../pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" />\n");
  1333. break;
  1334. default:
  1335. $oPage->add(Dict::S('UI:Document:NoPreview'));
  1336. }
  1337. }
  1338. /**
  1339. * This function returns a 'hilight' CSS class, used to hilight a given row in a table
  1340. * There are currently (i.e defined in the CSS) 4 possible values HILIGHT_CLASS_CRITICAL,
  1341. * HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  1342. * To Be overridden by derived classes
  1343. * @param void
  1344. * @return String The desired higlight class for the object/row
  1345. */
  1346. public function GetHilightClass()
  1347. {
  1348. // Possible return values are:
  1349. // HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  1350. return HILIGHT_CLASS_NONE; // Not hilighted by default
  1351. }
  1352. }
  1353. ?>