cmdbabstract.class.inc.php 55 KB

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