cmdbabstract.class.inc.php 55 KB

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