cmdbabstract.class.inc.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  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. $aCSSClasses = array();
  914. $bMandatory = 0;
  915. if ( (!$oAttDef->IsNullAllowed()) || ($iFlags & OPT_ATT_MANDATORY))
  916. {
  917. $aCSSClasses[] = 'mandatory';
  918. $bMandatory = 1;
  919. }
  920. $sCSSClasses = self::GetCSSClasses($aCSSClasses);
  921. $sValidationField = "<span id=\"v_{$iId}\"></span>";
  922. $sHelpText = $oAttDef->GetHelpOnEdition();
  923. $aEventsList = array('validate');
  924. switch($oAttDef->GetEditClass())
  925. {
  926. case 'Date':
  927. case 'DateTime':
  928. $aEventsList[] ='keyup';
  929. $aEventsList[] ='change';
  930. $sHTMLValue = "<input title=\"$sHelpText\" class=\"date-pick\" type=\"text\" size=\"20\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  931. break;
  932. case 'Password':
  933. $aEventsList[] ='keyup';
  934. $aEventsList[] ='change';
  935. $sHTMLValue = "<input title=\"$sHelpText\" type=\"password\" size=\"30\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  936. break;
  937. case 'Text':
  938. $aEventsList[] ='keyup';
  939. $aEventsList[] ='change';
  940. $sHTMLValue = "<textarea class=\"resizable\" title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" rows=\"8\" cols=\"40\" id=\"$iId\">$value</textarea>&nbsp;{$sValidationField}";
  941. break;
  942. case 'LinkedSet':
  943. $aEventsList[] ='change';
  944. $oWidget = new UILinksWidget($sClass, $sAttCode, $iId, $sNameSuffix);
  945. $sHTMLValue = $oWidget->Display($oPage, $value);
  946. break;
  947. case 'Document':
  948. $aEventsList[] ='change';
  949. $oDocument = $value; // Value is an ormDocument object
  950. $sFileName = '';
  951. if (is_object($oDocument))
  952. {
  953. $sFileName = $oDocument->GetFileName();
  954. }
  955. $iMaxFileSize = utils::ConvertToBytes(ini_get('upload_max_filesize'));
  956. $sHTMLValue = "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$iMaxFileSize\" />\n";
  957. $sHTMLValue .= "<input name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" type=\"hidden\" id=\"$iId\" \" value=\"$sFileName\"/>\n";
  958. $sHTMLValue .= "<span id=\"name_$iInputId\">$sFileName</span><br/>\n";
  959. $sHTMLValue .= "<input title=\"$sHelpText\" name=\"file_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" type=\"file\" id=\"file_$iId\" onChange=\"UpdateFileName('$iId', this.value)\"/>&nbsp;{$sValidationField}\n";
  960. break;
  961. case 'List':
  962. // Not editable for now...
  963. $sHTMLValue = '';
  964. break;
  965. case 'One Way Password':
  966. $oWidget = new UIPasswordWidget($sAttCode, $iId, $sNameSuffix);
  967. $sHTMLValue = $oWidget->Display($oPage, $aArgs);
  968. // Event list & validation is handled directly by the widget
  969. break;
  970. case 'String':
  971. default:
  972. // #@# todo - add context information (depending on dimensions)
  973. $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
  974. if ($aAllowedValues !== null)
  975. {
  976. //Enum field or external key, display a combo
  977. //if (count($aAllowedValues) == 0)
  978. //{
  979. // $sHTMLValue = "<input count=\"0\" type=\"text\" size=\"30\" value=\"\" name=\"attr_{$sAttCode}{$sNameSuffix}\" id=\"$iInputId\"{$sCSSClasses}/>";
  980. //}
  981. //else if (count($aAllowedValues) > 50)
  982. if (count($aAllowedValues) > 50)
  983. {
  984. // too many choices, use an autocomplete
  985. // The input for the auto complete
  986. if ($sDisplayValue == $oAttDef->GetNullValue()) // Null or zero is displayed as ''
  987. {
  988. $sDisplayValue = '';
  989. }
  990. $sHTMLValue = "<input count=\"".count($aAllowedValues)."\" type=\"text\" id=\"label_$iId\" size=\"30\" maxlength=\"255\" value=\"$sDisplayValue\"{$sCSSClasses}/>&nbsp;{$sValidationField}";
  991. // another hidden input to store & pass the object's Id
  992. $sHTMLValue .= "<input type=\"hidden\" id=\"$iId\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" />\n";
  993. $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."'}});");
  994. $oPage->add_ready_script("\$('#label_$iId').result( function(event, data, formatted) { if (data) { $('#{$iId}').val(data[1]); } } );");
  995. $aEventsList[] ='change';
  996. }
  997. else
  998. {
  999. // Few choices, use a normal 'select'
  1000. // In case there are no valid values, the select will be empty, thus blocking the user from validating the form
  1001. $sHTMLValue = "<select title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" id=\"$iId\">\n";
  1002. $sHTMLValue .= "<option value=\"0\">".Dict::S('UI:SelectOne')."</option>\n";
  1003. foreach($aAllowedValues as $key => $display_value)
  1004. {
  1005. if ((count($aAllowedValues) == 1) && $bMandatory )
  1006. {
  1007. // When there is only once choice, select it by default
  1008. $sSelected = ' selected';
  1009. }
  1010. else
  1011. {
  1012. $sSelected = ($value == $key) ? ' selected' : '';
  1013. }
  1014. $sHTMLValue .= "<option value=\"$key\"$sSelected>$display_value</option>\n";
  1015. }
  1016. $sHTMLValue .= "</select>&nbsp;{$sValidationField}\n";
  1017. $aEventsList[] ='change';
  1018. }
  1019. }
  1020. else
  1021. {
  1022. $sHTMLValue = "<input title=\"$sHelpText\" type=\"text\" size=\"30\" maxlength=\"255\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  1023. $aEventsList[] ='keyup';
  1024. $aEventsList[] ='change';
  1025. }
  1026. break;
  1027. }
  1028. $sPattern = addslashes($oAttDef->GetValidationPattern()); //'^([0-9]+)$';
  1029. if (!empty($aEventsList))
  1030. {
  1031. $oPage->add_ready_script("$('#$iId').bind('".implode(' ', $aEventsList)."', function(evt, sFormId) { return ValidateField('$iId', '$sPattern', $bMandatory, sFormId) } );"); // Bind to a custom event: validate
  1032. }
  1033. $aDependencies = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that depend on the current one
  1034. if (count($aDependencies) > 0)
  1035. {
  1036. $oPage->add_ready_script("$('#$iId').bind('change', function(evt, sFormId) { return UpdateDependentFields(['".implode("','", $aDependencies)."']) } );"); // Bind to a custom event: validate
  1037. }
  1038. }
  1039. return "<div>{$sHTMLValue}</div>";
  1040. }
  1041. public function DisplayModifyForm(WebPage $oPage, $aExtraParams = array())
  1042. {
  1043. static $iGlobalFormId = 0;
  1044. $iGlobalFormId++;
  1045. $this->m_iFormId = $iGlobalFormId;
  1046. $sClass = get_class($this);
  1047. $oAppContext = new ApplicationContext();
  1048. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  1049. $iKey = $this->GetKey();
  1050. $aDetails = array();
  1051. $aFieldsMap = array();
  1052. if (!isset($aExtraParams['action']))
  1053. {
  1054. $sFormAction = $_SERVER['SCRIPT_NAME']; // No parameter in the URL, the only parameter will be the ones passed through the form
  1055. }
  1056. else
  1057. {
  1058. $sFormAction = $aExtraParams['action'];
  1059. }
  1060. $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");
  1061. $oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
  1062. $oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
  1063. $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
  1064. $aDetailsList = $this->FLattenZList(MetaModel::GetZListItems($sClass, 'details'));
  1065. //$aFullList = MetaModel::ListAttributeDefs($sClass);
  1066. $aList = array();
  1067. // Compute the list of properties to display, first the attributes in the 'details' list, then
  1068. // all the remaining attributes that are not external fields
  1069. foreach($aDetailsList as $sAttCode)
  1070. {
  1071. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1072. if (!$oAttDef->IsExternalField())
  1073. {
  1074. $aList[] = $sAttCode;
  1075. }
  1076. }
  1077. foreach($aList as $sAttCode)
  1078. {
  1079. $iFlags = $this->GetAttributeFlags($sAttCode);
  1080. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1081. if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0))
  1082. {
  1083. if ($oAttDef->IsWritable())
  1084. {
  1085. if ($sStateAttCode == $sAttCode)
  1086. {
  1087. // State attribute is always read-only from the UI
  1088. $sHTMLValue = $this->GetStateLabel();
  1089. $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue);
  1090. }
  1091. else
  1092. {
  1093. $iFlags = $this->GetAttributeFlags($sAttCode);
  1094. if ($iFlags & OPT_ATT_HIDDEN)
  1095. {
  1096. // Attribute is hidden, do nothing
  1097. }
  1098. else
  1099. {
  1100. if ($iFlags & OPT_ATT_READONLY)
  1101. {
  1102. // Attribute is read-only
  1103. $sHTMLValue = $this->GetAsHTML($sAttCode);
  1104. }
  1105. else
  1106. {
  1107. $sValue = $this->Get($sAttCode);
  1108. $sDisplayValue = $this->GetEditValue($sAttCode);
  1109. $aArgs = array('this' => $this);
  1110. $sInputId = $this->m_iFormId.'_'.$sAttCode;
  1111. $sHTMLValue = "<span id=\"field_{$sInputId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).'</span>';
  1112. $aFieldsMap[$sAttCode] = $sInputId;
  1113. }
  1114. $aDetails[] = array('label' => '<span title="'.$oAttDef->GetDescription().'">'.$oAttDef->GetLabel().'</span>', 'value' => $sHTMLValue);
  1115. }
  1116. }
  1117. }
  1118. else
  1119. {
  1120. $aDetails[] = array('label' => '<span title="'.$oAttDef->GetDescription().'">'.$oAttDef->GetLabel().'</span>', 'value' => $this->GetAsHTML($sAttCode));
  1121. }
  1122. }
  1123. }
  1124. $oPage->details($aDetails);
  1125. // Now display the relations, one tab per relation
  1126. $this->DisplayBareRelations($oPage, true); // Edit mode
  1127. $oPage->SetCurrentTab('');
  1128. $oPage->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">\n");
  1129. $oPage->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
  1130. foreach($aExtraParams as $sName => $value)
  1131. {
  1132. $oPage->add("<input type=\"hidden\" name=\"$sName\" value=\"$value\">\n");
  1133. }
  1134. $oPage->add($oAppContext->GetForForm());
  1135. if ($iKey > 0)
  1136. {
  1137. // The object already exists in the database, it's modification
  1138. $oPage->add("<input type=\"hidden\" name=\"id\" value=\"$iKey\">\n");
  1139. $oPage->add("<input type=\"hidden\" name=\"operation\" value=\"apply_modify\">\n");
  1140. $oPage->add("<button type=\"button\" class=\"action\" onClick=\"BackToDetails('$sClass', $iKey)\"><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:Apply')."</span></button>\n");
  1142. }
  1143. else
  1144. {
  1145. // The object does not exist in the database it's a creation
  1146. $oPage->add("<input type=\"hidden\" name=\"operation\" value=\"apply_new\">\n");
  1147. $oPage->add("<button type=\"button\" class=\"action\" onClick=\"goBack()\"><span>".Dict::S('UI:Button:Cancel')."</span></button>&nbsp;&nbsp;&nbsp;&nbsp;\n");
  1148. $oPage->add("<button type=\"submit\" class=\"action\"><span>".Dict::S('UI:Button:Create')."</span></button>\n");
  1149. }
  1150. $oPage->add("</form>\n");
  1151. $iFieldsCount = count($aFieldsMap);
  1152. $sJsonFieldsMap = json_encode($aFieldsMap);
  1153. $oPage->add_script(
  1154. <<<EOF
  1155. // Create the object once at the beginning of the page...
  1156. var oWizardHelper = new WizardHelper('$sClass');
  1157. oWizardHelper.SetFieldsMap($sJsonFieldsMap);
  1158. oWizardHelper.SetFieldsCount($iFieldsCount);
  1159. EOF
  1160. );
  1161. $oPage->add_ready_script(
  1162. <<<EOF
  1163. // Starts the validation when the page is ready
  1164. CheckFields('form_{$this->m_iFormId}', false);
  1165. EOF
  1166. );
  1167. }
  1168. public static function DisplayCreationForm(WebPage $oPage, $sClass, $oObjectToClone = null, $aArgs = array(), $aExtraParams = array())
  1169. {
  1170. $oAppContext = new ApplicationContext();
  1171. $sClass = ($oObjectToClone == null) ? $sClass : get_class($oObjectToClone);
  1172. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  1173. $aStates = MetaModel::EnumStates($sClass);
  1174. if ($oObjectToClone == null)
  1175. {
  1176. $sTargetState = MetaModel::GetDefaultState($sClass);
  1177. $oObj = MetaModel::NewObject($sClass);
  1178. $oObj->Set($sStateAttCode, $sTargetState);
  1179. }
  1180. else
  1181. {
  1182. $oObj = clone $oObjectToClone;
  1183. }
  1184. // Pre-fill the object with default values, when there is only on possible choice
  1185. // AND the field is mandatory (otherwise there is always the possiblity to let it empty)
  1186. $aArgs['this'] = $oObj;
  1187. $aDetailsList = self::FLattenZList(MetaModel::GetZListItems($sClass, 'details'));
  1188. // TO DO: the list should be ordered based on the dependencies between fields
  1189. // i.e. if some fields depend on another field, the latter should be computed first...
  1190. // Right now we depend on the display order... anyhow if the display order does not
  1191. // reflect the dependency order, the UI will not be so intuitive to use... beware
  1192. foreach($aDetailsList as $sAttCode)
  1193. {
  1194. $bMandatory = false;
  1195. $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
  1196. if (count($aAllowedValues) == 1)
  1197. {
  1198. // If the field is mandatory, set it to the only possible value
  1199. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1200. $iFlags = $oObj->GetAttributeFlags($sAttCode);
  1201. if ( (!$oAttDef->IsNullAllowed()) || ($iFlags & OPT_ATT_MANDATORY))
  1202. {
  1203. $aValues = array_keys($aAllowedValues);
  1204. $oObj->Set($sAttCode, $aValues[0]);
  1205. }
  1206. }
  1207. }
  1208. return $oObj->DisplayModifyForm( $oPage, $aExtraParams = array());
  1209. }
  1210. protected static function GetCSSClasses($aCSSClasses)
  1211. {
  1212. $sCSSClasses = '';
  1213. if (!empty($aCSSClasses))
  1214. {
  1215. $sCSSClasses = ' class="'.implode(' ', $aCSSClasses).'" ';
  1216. }
  1217. return $sCSSClasses;
  1218. }
  1219. protected static function ProcessZlist($aList, $aDetails, $sCurrentTab, $sCurrentCol, $sCurrentSet)
  1220. {
  1221. //echo "<pre>ZList: ";
  1222. //print_r($aList);
  1223. //echo "</pre>\n";
  1224. foreach($aList as $sKey => $value)
  1225. {
  1226. if (is_array($value))
  1227. {
  1228. if (preg_match('/^(.*):(.*)$/U', $sKey, $aMatches))
  1229. {
  1230. $sCode = $aMatches[1];
  1231. $sName = $aMatches[2];
  1232. switch($sCode)
  1233. {
  1234. case 'tab':
  1235. //echo "<p>Found a tab: $sName ($sKey)</p>\n";
  1236. if(!isset($aDetails[$sName]))
  1237. {
  1238. $aDetails[$sName] = array('col1' => array('' => array()));
  1239. }
  1240. $aDetails = self::ProcessZlist($value, $aDetails, $sName, 'col1', '');
  1241. break;
  1242. case 'fieldset':
  1243. //echo "<p>Found a fieldset: $sName ($sKey)</p>\n";
  1244. if(!isset($aDetailsStruct[$sCurrentTab][$sCurrentCol][$sName]))
  1245. {
  1246. $aDetails[$sCurrentTab][$sCurrentCol][$sName] = array();
  1247. }
  1248. $aDetails = self::ProcessZlist($value, $aDetails, $sCurrentTab, $sCurrentCol, $sName);
  1249. break;
  1250. default:
  1251. case 'col':
  1252. //echo "<p>Found a column: $sName ($sKey)</p>\n";
  1253. if(!isset($aDetails[$sCurrentTab][$sName]))
  1254. {
  1255. $aDetails[$sCurrentTab][$sName] = array('' => array());
  1256. }
  1257. $aDetails = self::ProcessZlist($value, $aDetails, $sCurrentTab, $sName, '');
  1258. break;
  1259. }
  1260. }
  1261. }
  1262. else
  1263. {
  1264. //echo "<p>Scalar value: $value, in [$sCurrentTab][$sCurrentCol][$sCurrentSet][]</p>\n";
  1265. $aDetails[$sCurrentTab][$sCurrentCol][$sCurrentSet][] = $value;
  1266. }
  1267. }
  1268. return $aDetails;
  1269. }
  1270. protected static function FlattenZList($aList)
  1271. {
  1272. $aResult = array();
  1273. foreach($aList as $value)
  1274. {
  1275. if (!is_array($value))
  1276. {
  1277. $aResult[] = $value;
  1278. }
  1279. else
  1280. {
  1281. $aResult = array_merge($aResult, $this->FlattenZList($value));
  1282. }
  1283. }
  1284. return $aResult;
  1285. }
  1286. protected function GetFieldAsHtml($sClass, $sAttCode, $sStateAttCode)
  1287. {
  1288. $retVal = null;
  1289. $iFlags = $this->GetAttributeFlags($sAttCode);
  1290. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1291. if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0) )
  1292. {
  1293. // The field is visible in the current state of the object
  1294. if ($sStateAttCode == $sAttCode)
  1295. {
  1296. // Special display for the 'state' attribute itself
  1297. $sDisplayValue = $this->GetStateLabel();
  1298. }
  1299. else if ($oAttDef->GetEditClass() == 'Document')
  1300. {
  1301. $oDocument = $this->Get($sAttCode);
  1302. $sDisplayValue = $this->GetAsHTML($sAttCode);
  1303. $sDisplayValue .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_', $oDocument->GetDisplayLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
  1304. $sDisplayValue .= "<br/>".Dict::Format('UI:DownloadDocument_', $oDocument->GetDisplayLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
  1305. }
  1306. else
  1307. {
  1308. $sDisplayValue = $this->GetAsHTML($sAttCode);
  1309. }
  1310. $retVal = array('label' => '<span title="'.MetaModel::GetDescription($sClass, $sAttCode).'">'.MetaModel::GetLabel($sClass, $sAttCode).'</span>', 'value' => $sDisplayValue);
  1311. }
  1312. return $retVal;
  1313. }
  1314. /**
  1315. * Displays a blob document *inline* (if possible, depending on the type of the document)
  1316. * @return string
  1317. */
  1318. public function DisplayDocumentInline(WebPage $oPage, $sAttCode)
  1319. {
  1320. $oDoc = $this->Get($sAttCode);
  1321. $sClass = get_class($this);
  1322. $Id = $this->GetKey();
  1323. switch ($oDoc->GetMainMimeType())
  1324. {
  1325. case 'text':
  1326. case 'html':
  1327. $data = $oDoc->GetData();
  1328. switch($oDoc->GetMimeType())
  1329. {
  1330. case 'text/html':
  1331. case 'text/xml':
  1332. $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");
  1333. break;
  1334. default:
  1335. $oPage->add("<pre>".htmlentities(MyHelpers::beautifulstr($data, 1000, true))."</pre>\n");
  1336. }
  1337. break;
  1338. case 'application':
  1339. switch($oDoc->GetMimeType())
  1340. {
  1341. case 'application/pdf':
  1342. $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");
  1343. break;
  1344. default:
  1345. $oPage->add(Dict::S('UI:Document:NoPreview'));
  1346. }
  1347. break;
  1348. case 'image':
  1349. $oPage->add("<img src=\"../pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" />\n");
  1350. break;
  1351. default:
  1352. $oPage->add(Dict::S('UI:Document:NoPreview'));
  1353. }
  1354. }
  1355. /**
  1356. * This function returns a 'hilight' CSS class, used to hilight a given row in a table
  1357. * There are currently (i.e defined in the CSS) 4 possible values HILIGHT_CLASS_CRITICAL,
  1358. * HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  1359. * To Be overridden by derived classes
  1360. * @param void
  1361. * @return String The desired higlight class for the object/row
  1362. */
  1363. public function GetHilightClass()
  1364. {
  1365. // Possible return values are:
  1366. // HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  1367. return HILIGHT_CLASS_NONE; // Not hilighted by default
  1368. }
  1369. }
  1370. ?>