cmdbabstract.class.inc.php 55 KB

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