cmdbabstract.class.inc.php 55 KB

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