cmdbabstract.class.inc.php 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  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(APPROOT.'/core/cmdbobject.class.inc.php');
  31. require_once(APPROOT.'/application/utils.inc.php');
  32. require_once(APPROOT.'/application/applicationcontext.class.inc.php');
  33. require_once(APPROOT.'/application/ui.linkswidget.class.inc.php');
  34. require_once(APPROOT.'/application/ui.passwordwidget.class.inc.php');
  35. require_once(APPROOT.'/application/ui.extkeywidget.class.inc.php');
  36. require_once(APPROOT.'/application/ui.htmleditorwidget.class.inc.php');
  37. /**
  38. * All objects to be displayed in the application (either as a list or as details)
  39. * must implement this interface.
  40. */
  41. interface iDisplay
  42. {
  43. /**
  44. * Maps the given context parameter name to the appropriate filter/search code for this class
  45. * @param string $sContextParam Name of the context parameter, i.e. 'org_id'
  46. * @return string Filter code, i.e. 'customer_id'
  47. */
  48. public static function MapContextParam($sContextParam);
  49. /**
  50. * This function returns a 'hilight' CSS class, used to hilight a given row in a table
  51. * There are currently (i.e defined in the CSS) 4 possible values HILIGHT_CLASS_CRITICAL,
  52. * HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  53. * To Be overridden by derived classes
  54. * @param void
  55. * @return String The desired higlight class for the object/row
  56. */
  57. public function GetHilightClass();
  58. /**
  59. * Returns the relative path to the page that handles the display of the object
  60. * @return string
  61. */
  62. public static function GetUIPage();
  63. /**
  64. * Displays the details of the object
  65. */
  66. public function DisplayDetails(WebPage $oPage, $bEditMode = false);
  67. }
  68. abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
  69. {
  70. protected $m_iFormId; // The ID of the form used to edit the object (when in edition mode !)
  71. public static function GetUIPage()
  72. {
  73. return '../pages/UI.php';
  74. }
  75. function DisplayBareHeader(WebPage $oPage, $bEditMode = false)
  76. {
  77. // Standard Header with name, actions menu and history block
  78. //
  79. // action menu
  80. $oSingletonFilter = new DBObjectSearch(get_class($this));
  81. $oSingletonFilter->AddCondition('id', $this->GetKey(), '=');
  82. $oBlock = new MenuBlock($oSingletonFilter, 'popup', false);
  83. $oBlock->Display($oPage, -1);
  84. // Master data sources
  85. $oReplicaSet = $this->GetMasterReplica();
  86. $bSynchronized = false;
  87. $bCreated = false;
  88. $bCanBeDeleted = false;
  89. $aMasterSources = array();
  90. if ($oReplicaSet->Count() > 0)
  91. {
  92. $bSynchronized = true;
  93. $sTip = "<p>The object is synchronized with an external data source</p>";
  94. while($aData = $oReplicaSet->FetchAssoc())
  95. {
  96. $sApplicationURL = $aData['datasource']->GetApplicationUrl($this, $aData['replica']);
  97. $sLink = "<a href=\"$sApplicationURL\" target=\"_blank\">".$aData['datasource']->GetName()."</a>";
  98. if ($aData['replica']->Get('status_dest_creator') == 1)
  99. {
  100. $sTip .= "<p>The object was <b>created</b> by the external data source $sLink</p>";
  101. $bCreated = true;
  102. }
  103. if ($bCreated)
  104. {
  105. $sDeletePolicy = $aData['datasource']->Get('delete_policy');
  106. if (($sDeletePolicy == 'delete') || ($sDeletePolicy == 'update_then_delete'))
  107. {
  108. $bCanBeDeleted = true;
  109. $sTip .= "<p>The object <b>can be deleted</b> by the external data source $sLink</p>";
  110. }
  111. }
  112. $aMasterSources[$aData['datasource']->GetKey()]['datasource'] = $aData['datasource'];
  113. $aMasterSources[$aData['datasource']->GetKey()]['url'] = $sLink;
  114. }
  115. }
  116. $sSynchroIcon = '';
  117. if ($bSynchronized)
  118. {
  119. $sTip .= "<p><b>List of data sources:</b></p>";
  120. foreach($aMasterSources as $aStruct)
  121. {
  122. $oDataSource = $aStruct['datasource'];
  123. $sLink = $aStruct['url'];
  124. $sTip .= "<p style=\"white-space:nowrap\">".$oDataSource->GetIcon(true, 'style="vertical-align:middle"')."&nbsp;$sLink</p>";
  125. }
  126. $sSynchroIcon = '&nbsp;<img style="vertical-align:middle;" id="synchro_icon" src="../images/locked.png"/>';
  127. $oPage->add_ready_script("$('#synchro_icon').qtip( { content: '$sTip', show: 'mouseover', hide: 'unfocus', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );");
  128. }
  129. $oPage->add("<div class=\"page_header\"><h1>".$this->GetIcon()."&nbsp;\n");
  130. $oPage->add(MetaModel::GetName(get_class($this)).": <span class=\"hilite\">".$this->GetName()."</span>$sSynchroIcon</h1>\n");
  131. $oPage->add("</div>\n");
  132. }
  133. function DisplayBareHistory(WebPage $oPage, $bEditMode = false)
  134. {
  135. // history block (with as a tab)
  136. $oHistoryFilter = new DBObjectSearch('CMDBChangeOp');
  137. $oHistoryFilter->AddCondition('objkey', $this->GetKey(), '=');
  138. $oHistoryFilter->AddCondition('objclass', get_class($this), '=');
  139. $oBlock = new HistoryBlock($oHistoryFilter, 'table', false);
  140. $oBlock->Display($oPage, -1);
  141. }
  142. function DisplayBareProperties(WebPage $oPage, $bEditMode = false)
  143. {
  144. $oPage->add($this->GetBareProperties($oPage, $bEditMode));
  145. }
  146. function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
  147. {
  148. // Related objects: display all the linkset attributes, each as a separate tab
  149. // In the order described by the 'display' ZList
  150. $aList = $this->FlattenZList(MetaModel::GetZListItems(get_class($this), 'details'));
  151. if (count($aList) == 0)
  152. {
  153. // Empty ZList defined, display all the linkedset attributes defined
  154. $aList = array_keys(MetaModel::ListAttributeDefs(get_class($this)));
  155. }
  156. $sClass = get_class($this);
  157. foreach($aList as $sAttCode)
  158. {
  159. $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
  160. // Display mode
  161. if (!$oAttDef->IsLinkset()) continue; // Process only linkset attributes...
  162. $oPage->SetCurrentTab($oAttDef->GetLabel());
  163. if ($bEditMode)
  164. {
  165. $iFlags = $this->GetAttributeFlags($sAttCode);
  166. $sInputId = $this->m_iFormId.'_'.$sAttCode;
  167. if (get_class($oAttDef) == 'AttributeLinkedSet')
  168. {
  169. // 1:n links
  170. $sTargetClass = $oAttDef->GetLinkedClass();
  171. if ($this->IsNew())
  172. {
  173. $oPage->p(Dict::Format('UI:BeforeAdding_Class_ObjectsSaveThisObject', MetaModel::GetName($sTargetClass)));
  174. }
  175. else
  176. {
  177. $oPage->p(MetaModel::GetClassIcon($sTargetClass)."&nbsp;".$oAttDef->GetDescription());
  178. $oFilter = new DBObjectSearch($sTargetClass);
  179. $oFilter->AddCondition($oAttDef->GetExtKeyToMe(), $this->GetKey(),'=');
  180. $aDefaults = array($oAttDef->GetExtKeyToMe() => $this->GetKey());
  181. $oAppContext = new ApplicationContext();
  182. foreach($oAppContext->GetNames() as $sKey)
  183. {
  184. // The linked object inherits the parent's value for the context
  185. if (MetaModel::IsValidAttCode($sClass, $sKey))
  186. {
  187. $aDefaults[$sKey] = $this->Get($sKey);
  188. }
  189. }
  190. $aParams = array(
  191. 'target_attr' => $oAttDef->GetExtKeyToMe(),
  192. 'object_id' => $this->GetKey(),
  193. 'menu' => true,
  194. 'default' => $aDefaults,
  195. );
  196. $oBlock = new DisplayBlock($oFilter, 'list', false);
  197. $oBlock->Display($oPage, $sInputId, $aParams);
  198. }
  199. }
  200. else // get_class($oAttDef) == 'AttributeLinkedSetIndirect'
  201. {
  202. // n:n links
  203. $sLinkedClass = $oAttDef->GetLinkedClass();
  204. $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote());
  205. $sTargetClass = $oLinkingAttDef->GetTargetClass();
  206. $oPage->p(MetaModel::GetClassIcon($sTargetClass)."&nbsp;".$oAttDef->GetDescription().'<span id="busy_'.$sInputId.'"></span>');
  207. $sValue = $this->Get($sAttCode);
  208. $sDisplayValue = $this->GetEditValue($sAttCode);
  209. $aArgs = array('this' => $this);
  210. $sHTMLValue = "<span id=\"field_{$sInputId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).'</span>';
  211. $aFieldsMap[$sAttCode] = $sInputId;
  212. $oPage->add($sHTMLValue);
  213. }
  214. }
  215. else
  216. {
  217. // Display mode
  218. if (!$oAttDef->IsIndirect())
  219. {
  220. // 1:n links
  221. $sTargetClass = $oAttDef->GetLinkedClass();
  222. $aDefaults = array($oAttDef->GetExtKeyToMe() => $this->GetKey());
  223. $oAppContext = new ApplicationContext();
  224. foreach($oAppContext->GetNames() as $sKey)
  225. {
  226. // The linked object inherits the parent's value for the context
  227. if (MetaModel::IsValidAttCode($sClass, $sKey))
  228. {
  229. $aDefaults[$sKey] = $this->Get($sKey);
  230. }
  231. }
  232. $aParams = array(
  233. 'target_attr' => $oAttDef->GetExtKeyToMe(),
  234. 'object_id' => $this->GetKey(),
  235. 'menu' => false,
  236. 'default' => $aDefaults,
  237. );
  238. }
  239. else
  240. {
  241. // n:n links
  242. $sLinkedClass = $oAttDef->GetLinkedClass();
  243. $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote());
  244. $sTargetClass = $oLinkingAttDef->GetTargetClass();
  245. $bMenu = ($this->Get($sAttCode)->Count() > 0); // The menu is enabled only if there are already some elements...
  246. $aParams = array(
  247. 'link_attr' => $oAttDef->GetExtKeyToMe(),
  248. 'object_id' => $this->GetKey(),
  249. 'target_attr' => $oAttDef->GetExtKeyToRemote(),
  250. 'view_link' => false,
  251. 'menu' => false,
  252. 'display_limit' => true, // By default limit the list to speed up the initial load & display
  253. );
  254. }
  255. $oPage->p(MetaModel::GetClassIcon($sTargetClass)."&nbsp;".$oAttDef->GetDescription());
  256. $oBlock = new DisplayBlock($this->Get($sAttCode)->GetFilter(), 'list', false);
  257. $oBlock->Display($oPage, 'rel_'.$sAttCode, $aParams);
  258. }
  259. }
  260. $oPage->SetCurrentTab('');
  261. if (!$bEditMode)
  262. {
  263. // Get the actual class of the current object
  264. // And look for triggers referring to it
  265. // If any trigger has been found then display a tab with notifications
  266. //
  267. $sClass = get_class($this);
  268. $sClassList = implode("', '", MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL));
  269. $oTriggerSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnObject AS T WHERE T.target_class IN ('$sClassList')"));
  270. if ($oTriggerSet->Count() > 0)
  271. {
  272. $oPage->SetCurrentTab(Dict::S('UI:NotificationsTab'));
  273. // Display notifications regarding the object
  274. $iId = $this->GetKey();
  275. $oBlock = new DisplayBlock(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"), 'list', false);
  276. $oBlock->Display($oPage, 'notifications', array());
  277. }
  278. }
  279. }
  280. function GetBareProperties(WebPage $oPage, $bEditMode = false)
  281. {
  282. $sHtml = '';
  283. $oAppContext = new ApplicationContext();
  284. $sStateAttCode = MetaModel::GetStateAttributeCode(get_class($this));
  285. $aDetails = array();
  286. $sClass = get_class($this);
  287. $aDetailsList = MetaModel::GetZListItems($sClass, 'details');
  288. $aDetailsStruct = self::ProcessZlist($aDetailsList, array('UI:PropertiesTab' => array()), 'UI:PropertiesTab', 'col1', '');
  289. // Compute the list of properties to display, first the attributes in the 'details' list, then
  290. // all the remaining attributes that are not external fields
  291. $sHtml = '';
  292. $aDetails = array();
  293. $iInputId = 0;
  294. foreach($aDetailsStruct as $sTab => $aCols )
  295. {
  296. $aDetails[$sTab] = array();
  297. ksort($aCols);
  298. $oPage->SetCurrentTab(Dict::S($sTab));
  299. $oPage->add('<table style="vertical-align:top"><tr>');
  300. foreach($aCols as $sColIndex => $aFieldsets)
  301. {
  302. $oPage->add('<td style="vertical-align:top">');
  303. //$aDetails[$sTab][$sColIndex] = array();
  304. $sLabel = '';
  305. $sPreviousLabel = '';
  306. $aDetails[$sTab][$sColIndex] = array();
  307. foreach($aFieldsets as $sFieldsetName => $aFields)
  308. {
  309. if (!empty($sFieldsetName) && ($sFieldsetName[0] != '_'))
  310. {
  311. $sLabel = $sFieldsetName;
  312. }
  313. else
  314. {
  315. $sLabel = '';
  316. }
  317. if ($sLabel != $sPreviousLabel)
  318. {
  319. if (!empty($sPreviousLabel))
  320. {
  321. $oPage->add('<fieldset>');
  322. $oPage->add('<legend>'.Dict::S($sPreviousLabel).'</legend>');
  323. }
  324. $oPage->Details($aDetails[$sTab][$sColIndex]);
  325. if (!empty($sPreviousLabel))
  326. {
  327. $oPage->add('</fieldset>');
  328. }
  329. $aDetails[$sTab][$sColIndex] = array();
  330. $sPreviousLabel = $sLabel;
  331. }
  332. foreach($aFields as $sAttCode)
  333. {
  334. $val = $this->GetFieldAsHtml($sClass, $sAttCode, $sStateAttCode);
  335. if ($val != null)
  336. {
  337. // Check if the attribute is not mastered by a synchro...
  338. $aReasons = array();
  339. $iSynchroFlags = $this->GetSynchroReplicaFlags($sAttCode, $aReasons);
  340. $sSynchroIcon = '';
  341. if ($iSynchroFlags & OPT_ATT_READONLY)
  342. {
  343. $sSynchroIcon = "&nbsp;<img id=\"synchro_$iInputId\" src=\"../images/transp-lock.png\" style=\"vertical-align:middle\"/>";
  344. $sTip = '';
  345. foreach($aReasons as $aRow)
  346. {
  347. $sTip .= "<p>Synchronized with {$aRow['name']} - {$aRow['description']}</p>";
  348. }
  349. $oPage->add_ready_script("$('#synchro_$iInputId').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );");
  350. }
  351. $val['value'] .= $sSynchroIcon;
  352. // The field is visible, add it to the current column
  353. $aDetails[$sTab][$sColIndex][] = $val;
  354. $iInputId++;
  355. }
  356. }
  357. }
  358. if (!empty($sPreviousLabel))
  359. {
  360. $oPage->add('<fieldset>');
  361. $oPage->add('<legend>'.Dict::S($sFieldsetName).'</legend>');
  362. }
  363. $oPage->Details($aDetails[$sTab][$sColIndex]);
  364. if (!empty($sPreviousLabel))
  365. {
  366. $oPage->add('</fieldset>');
  367. }
  368. $oPage->add('</td>');
  369. }
  370. $oPage->add('</tr></table>');
  371. }
  372. return $sHtml;
  373. }
  374. function DisplayDetails(WebPage $oPage, $bEditMode = false)
  375. {
  376. $sTemplate = Utils::ReadFromFile(MetaModel::GetDisplayTemplate(get_class($this)));
  377. if (!empty($sTemplate))
  378. {
  379. $oTemplate = new DisplayTemplate($sTemplate);
  380. // Note: to preserve backward compatibility with home-made templates, the placeholder '$pkey$' has been preserved
  381. // but the preferred method is to use '$id$'
  382. $oTemplate->Render($oPage, array('class_name'=> MetaModel::GetName(get_class($this)),'class'=> get_class($this), 'pkey'=> $this->GetKey(), 'id'=> $this->GetKey(), 'name' => $this->Get('friendlyname')));
  383. }
  384. else
  385. {
  386. // Object's details
  387. // template not found display the object using the *old style*
  388. $this->DisplayBareHeader($oPage, $bEditMode);
  389. $oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
  390. $oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
  391. $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
  392. $this->DisplayBareProperties($oPage, $bEditMode);
  393. $this->DisplayBareRelations($oPage, $bEditMode);
  394. $oPage->SetCurrentTab(Dict::S('UI:HistoryTab'));
  395. $this->DisplayBareHistory($oPage, $bEditMode);
  396. }
  397. }
  398. function DisplayPreview(WebPage $oPage)
  399. {
  400. $aDetails = array();
  401. $sClass = get_class($this);
  402. $aList = MetaModel::GetZListItems($sClass, 'preview');
  403. foreach($aList as $sAttCode)
  404. {
  405. $aDetails[] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'value' =>$this->GetAsHTML($sAttCode));
  406. }
  407. $oPage->details($aDetails);
  408. }
  409. public static function DisplaySet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  410. {
  411. $oPage->add(self::GetDisplaySet($oPage, $oSet, $aExtraParams));
  412. }
  413. /**
  414. * Get the HTML fragment corresponding to the display of a table representing a set of objects
  415. * @param WebPage $oPage The page object is used for out-of-band information (mostly scripts) output
  416. * @param CMDBObjectSet The set of objects to display
  417. * @param Hash $aExtraParams Some extra configuration parameters to tweak the behavior of the display
  418. * @return String The HTML fragment representing the table of objects
  419. */
  420. public static function GetDisplaySet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  421. {
  422. if (empty($aExtraParams['currentId']))
  423. {
  424. $iListId = $oPage->GetUniqueId(); // Works only if not in an Ajax page !!
  425. }
  426. else
  427. {
  428. $iListId = $aExtraParams['currentId'];
  429. }
  430. // Initialize and check the parameters
  431. $bViewLink = isset($aExtraParams['view_link']) ? $aExtraParams['view_link'] : true;
  432. $sLinkageAttribute = isset($aExtraParams['link_attr']) ? $aExtraParams['link_attr'] : '';
  433. $iLinkedObjectId = isset($aExtraParams['object_id']) ? $aExtraParams['object_id'] : 0;
  434. $sTargetAttr = isset($aExtraParams['target_attr']) ? $aExtraParams['target_attr'] : '';
  435. if (!empty($sLinkageAttribute))
  436. {
  437. if($iLinkedObjectId == 0)
  438. {
  439. // if 'links' mode is requested the id of the object to link to must be specified
  440. throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_object_id'));
  441. }
  442. if($sTargetAttr == '')
  443. {
  444. // if 'links' mode is requested the d of the object to link to must be specified
  445. throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_target_attr'));
  446. }
  447. }
  448. $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true;
  449. $bTruncated = isset($aExtraParams['truncated']) ? $aExtraParams['truncated'] == true : true;
  450. $bSelectMode = isset($aExtraParams['selection_mode']) ? $aExtraParams['selection_mode'] == true : false;
  451. $bSingleSelectMode = isset($aExtraParams['selection_type']) ? ($aExtraParams['selection_type'] == 'single') : false;
  452. $aExtraFields = isset($aExtraParams['extra_fields']) ? explode(',', trim($aExtraParams['extra_fields'])) : array();
  453. $sHtml = '';
  454. $oAppContext = new ApplicationContext();
  455. $sClassName = $oSet->GetFilter()->GetClass();
  456. $aAttribs = array();
  457. $sZListName = isset($aExtraParams['zlist']) ? ($aExtraParams['zlist']) : 'list';
  458. $aList = self::FlattenZList(MetaModel::GetZListItems($sClassName, $sZListName));
  459. $aList = array_merge($aList, $aExtraFields);
  460. // Filter the list to removed linked set since we are not able to display them here
  461. foreach($aList as $index => $sAttCode)
  462. {
  463. $oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
  464. if ($oAttDef instanceof AttributeLinkedSet)
  465. {
  466. // Removed from the display list
  467. unset($aList[$index]);
  468. }
  469. }
  470. if (!empty($sLinkageAttribute))
  471. {
  472. // The set to display is in fact a set of links between the object specified in the $sLinkageAttribute
  473. // and other objects...
  474. // The display will then group all the attributes related to the link itself:
  475. // | Link_attr1 | link_attr2 | ... || Object_attr1 | Object_attr2 | Object_attr3 | .. | Object_attr_n |
  476. $aDisplayList = array();
  477. $aAttDefs = MetaModel::ListAttributeDefs($sClassName);
  478. assert(isset($aAttDefs[$sLinkageAttribute]));
  479. $oAttDef = $aAttDefs[$sLinkageAttribute];
  480. assert($oAttDef->IsExternalKey());
  481. // First display all the attributes specific to the link record
  482. foreach($aList as $sLinkAttCode)
  483. {
  484. $oLinkAttDef = $aAttDefs[$sLinkAttCode];
  485. if ( (!$oLinkAttDef->IsExternalKey()) && (!$oLinkAttDef->IsExternalField()) )
  486. {
  487. $aDisplayList[] = $sLinkAttCode;
  488. }
  489. }
  490. // Then display all the attributes neither specific to the link record nor to the 'linkage' object (because the latter are constant)
  491. foreach($aList as $sLinkAttCode)
  492. {
  493. $oLinkAttDef = $aAttDefs[$sLinkAttCode];
  494. if (($oLinkAttDef->IsExternalKey() && ($sLinkAttCode != $sLinkageAttribute))
  495. || ($oLinkAttDef->IsExternalField() && ($oLinkAttDef->GetKeyAttCode()!=$sLinkageAttribute)) )
  496. {
  497. $aDisplayList[] = $sLinkAttCode;
  498. }
  499. }
  500. // First display all the attributes specific to the link
  501. // Then display all the attributes linked to the other end of the relationship
  502. $aList = $aDisplayList;
  503. }
  504. if ($bSelectMode)
  505. {
  506. if (!$bSingleSelectMode)
  507. {
  508. $aAttribs['form::select'] = array('label' => "<input type=\"checkbox\" onClick=\"CheckAll('.selectList{$iListId}', this.checked);\"></input>", 'description' => Dict::S('UI:SelectAllToggle+'));
  509. }
  510. else
  511. {
  512. $aAttribs['form::select'] = array('label' => "", 'description' => '');
  513. }
  514. }
  515. if ($bViewLink)
  516. {
  517. $aAttribs['key'] = array('label' => MetaModel::GetName($sClassName), 'description' => '');
  518. }
  519. foreach($aList as $sAttCode)
  520. {
  521. $aAttribs[$sAttCode] = array('label' => MetaModel::GetLabel($sClassName, $sAttCode), 'description' => MetaModel::GetDescription($sClassName, $sAttCode));
  522. }
  523. $aValues = array();
  524. $bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true;
  525. $iMaxObjects = -1;
  526. if ($bDisplayLimit && $bTruncated)
  527. {
  528. if ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit())
  529. {
  530. $iMaxObjects = MetaModel::GetConfig()->GetMinDisplayLimit();
  531. $oSet->SetLimit($iMaxObjects);
  532. }
  533. }
  534. $oSet->Seek(0);
  535. while (($oObj = $oSet->Fetch()) && ($iMaxObjects != 0))
  536. {
  537. $aRow = array();
  538. $sHilightClass = $oObj->GetHilightClass();
  539. if ($sHilightClass != '')
  540. {
  541. $aRow['@class'] = $sHilightClass;
  542. }
  543. if ($bViewLink)
  544. {
  545. $aRow['key'] = $oObj->GetHyperLink();
  546. }
  547. if ($bSelectMode)
  548. {
  549. if ($bSingleSelectMode)
  550. {
  551. $aRow['form::select'] = "<input type=\"radio\" class=\"selectList{$iListId}\" name=\"selectObject\" value=\"".$oObj->GetKey()."\"></input>";
  552. }
  553. else
  554. {
  555. $aRow['form::select'] = "<input type=\"checkBox\" class=\"selectList{$iListId}\" name=\"selectObject[]\" value=\"".$oObj->GetKey()."\"></input>";
  556. }
  557. }
  558. foreach($aList as $sAttCode)
  559. {
  560. $aRow[$sAttCode] = $oObj->GetAsHTML($sAttCode);
  561. }
  562. $aValues[] = $aRow;
  563. $iMaxObjects--;
  564. }
  565. $sHtml .= '<table class="listContainer">';
  566. $sColspan = '';
  567. // if (isset($aExtraParams['block_id']))
  568. // {
  569. // $divId = $aExtraParams['block_id'];
  570. // }
  571. // else
  572. // {
  573. // $divId = 'missingblockid';
  574. // }
  575. $sFilter = $oSet->GetFilter()->serialize();
  576. $iMinDisplayLimit = MetaModel::GetConfig()->GetMinDisplayLimit();
  577. $sCollapsedLabel = Dict::Format('UI:TruncatedResults', $iMinDisplayLimit, $oSet->Count());
  578. $sLinkLabel = Dict::S('UI:DisplayAll');
  579. foreach($oSet->GetFilter()->GetInternalParams() as $sName => $sValue)
  580. {
  581. $aExtraParams['query_params'][$sName] = $sValue;
  582. }
  583. if ($bDisplayLimit && $bTruncated && ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit()))
  584. {
  585. // list truncated
  586. $aExtraParams['display_limit'] = true;
  587. $sHtml .= '<tr class="containerHeader"><td><span id="lbl_'.$iListId.'">'.$sCollapsedLabel.'</span>&nbsp;&nbsp;<a class="truncated" id="trc_'.$iListId.'">'.$sLinkLabel.'</a></td><td>';
  588. $oPage->add_ready_script(
  589. <<<EOF
  590. $('#$iListId table.listResults').addClass('truncated');
  591. $('#$iListId table.listResults tr:last td').addClass('truncated');
  592. EOF
  593. );
  594. }
  595. else if ($bDisplayLimit && !$bTruncated && ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit()))
  596. {
  597. // Collapsible list
  598. $aExtraParams['display_limit'] = true;
  599. $sHtml .= '<tr class="containerHeader"><td><span id="lbl_'.$iListId.'">'.Dict::Format('UI:CountOfResults', $oSet->Count()).'</span><a class="truncated" id="trc_'.$iListId.'">'.Dict::S('UI:CollapseList').'</a></td><td>';
  600. }
  601. $aExtraParams['truncated'] = false; // To expand the full list when clicked
  602. $sExtraParamsExpand = addslashes(str_replace('"', "'", json_encode($aExtraParams))); // JSON encode, change the style of the quotes and escape them
  603. $oPage->add_ready_script(
  604. <<<EOF
  605. // Handle truncated lists
  606. $('#trc_$iListId').click(function()
  607. {
  608. var state = {};
  609. var currentState = $.bbq.getState( this.id, true ) || 'close';
  610. // Toggle the state!
  611. if (currentState == 'close')
  612. {
  613. state[ this.id ] = 'open';
  614. }
  615. else
  616. {
  617. state[ this.id ] = 'close';
  618. }
  619. $.bbq.pushState( state );
  620. $(this).trigger(state[this.id]);
  621. });
  622. $('#trc_$iListId').unbind('open');
  623. $('#trc_$iListId').bind('open', function()
  624. {
  625. ReloadTruncatedList('$iListId', '$sFilter', '$sExtraParamsExpand');
  626. });
  627. $('#trc_$iListId').unbind('close');
  628. $('#trc_$iListId').bind('close', function()
  629. {
  630. TruncateList('$iListId', $iMinDisplayLimit, '$sCollapsedLabel', '$sLinkLabel');
  631. });
  632. EOF
  633. );
  634. if ($bDisplayMenu)
  635. {
  636. $oMenuBlock = new MenuBlock($oSet->GetFilter());
  637. $sColspan = 'colspan="2"';
  638. $aMenuExtraParams = $aExtraParams;
  639. if (!empty($sLinkageAttribute))
  640. {
  641. //$aMenuExtraParams['linkage'] = $sLinkageAttribute;
  642. $aMenuExtraParams = $aExtraParams;
  643. }
  644. $sHtml .= $oMenuBlock->GetRenderContent($oPage, $aMenuExtraParams, $iListId);
  645. $sHtml .= '</td></tr>';
  646. }
  647. $sHtml .= "<tr><td $sColspan>";
  648. $sHtml .= $oPage->GetTable($aAttribs, $aValues);
  649. $sHtml .= '</td></tr>';
  650. $sHtml .= '</table>';
  651. return $sHtml;
  652. }
  653. public static function GetDisplayExtendedSet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  654. {
  655. static $iListId = 0;
  656. $iListId++;
  657. $aList = array();
  658. // Initialize and check the parameters
  659. $bViewLink = isset($aExtraParams['view_link']) ? $aExtraParams['view_link'] : true;
  660. $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true;
  661. // Check if there is a list of aliases to limit the display to...
  662. $aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', $aExtraParams['display_aliases']) : array();
  663. $sHtml = '';
  664. $oAppContext = new ApplicationContext();
  665. $aClasses = $oSet->GetFilter()->GetSelectedClasses();
  666. $aAuthorizedClasses = array();
  667. foreach($aClasses as $sAlias => $sClassName)
  668. {
  669. if ( (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS)) &&
  670. ( (count($aDisplayAliases) == 0) || (in_array($sAlias, $aDisplayAliases))) )
  671. {
  672. $aAuthorizedClasses[$sAlias] = $sClassName;
  673. }
  674. }
  675. $aAttribs = array();
  676. foreach($aAuthorizedClasses as $sAlias => $sClassName) // TO DO: check if the user has enough rights to view the classes of the list...
  677. {
  678. $aList[$sClassName] = MetaModel::GetZListItems($sClassName, 'list');
  679. if ($bViewLink)
  680. {
  681. $aAttribs['key_'.$sAlias] = array('label' => MetaModel::GetName($sClassName), 'description' => '');
  682. }
  683. foreach($aList[$sClassName] as $sAttCode)
  684. {
  685. $aAttribs[$sAttCode.'_'.$sAlias] = array('label' => MetaModel::GetLabel($sClassName, $sAttCode), 'description' => MetaModel::GetDescription($sClassName, $sAttCode));
  686. }
  687. }
  688. $aValues = array();
  689. $oSet->Seek(0);
  690. $bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true;
  691. $iMaxObjects = -1;
  692. if ($bDisplayLimit)
  693. {
  694. if ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit())
  695. {
  696. $iMaxObjects = MetaModel::GetConfig()->GetMinDisplayLimit();
  697. }
  698. }
  699. while (($aObjects = $oSet->FetchAssoc()) && ($iMaxObjects != 0))
  700. {
  701. $aRow = array();
  702. foreach($aAuthorizedClasses as $sAlias => $sClassName) // TO DO: check if the user has enough rights to view the classes of the list...
  703. {
  704. if ($bViewLink)
  705. {
  706. $aRow['key_'.$sAlias] = $aObjects[$sAlias]->GetHyperLink();
  707. }
  708. foreach($aList[$sClassName] as $sAttCode)
  709. {
  710. $aRow[$sAttCode.'_'.$sAlias] = $aObjects[$sAlias]->GetAsHTML($sAttCode);
  711. }
  712. }
  713. $aValues[] = $aRow;
  714. $iMaxObjects--;
  715. }
  716. $sHtml .= '<table class="listContainer">';
  717. $sColspan = '';
  718. if ($bDisplayMenu)
  719. {
  720. $oMenuBlock = new MenuBlock($oSet->GetFilter());
  721. $sColspan = 'colspan="2"';
  722. $aMenuExtraParams = $aExtraParams;
  723. if (!empty($sLinkageAttribute))
  724. {
  725. $aMenuExtraParams = $aExtraParams;
  726. }
  727. if ($bDisplayLimit && ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit()))
  728. {
  729. // list truncated
  730. $divId = $aExtraParams['block_id'];
  731. $sFilter = $oSet->GetFilter()->serialize();
  732. $aExtraParams['display_limit'] = false; // To expand the full list
  733. $sExtraParams = addslashes(str_replace('"', "'", json_encode($aExtraParams))); // JSON encode, change the style of the quotes and escape them
  734. $sHtml .= '<tr class="containerHeader"><td>'.Dict::Format('UI:TruncatedResults', MetaModel::GetConfig()->GetMinDisplayLimit(), $oSet->Count()).'&nbsp;&nbsp;<a href="Javascript:ReloadTruncatedList(\''.$divId.'\', \''.$sFilter.'\', \''.$sExtraParams.'\');">'.Dict::S('UI:DisplayAll').'</a></td><td>';
  735. $oPage->add_ready_script("$('#{$divId} table.listResults').addClass('truncated');");
  736. $oPage->add_ready_script("$('#{$divId} table.listResults tr:last td').addClass('truncated');");
  737. }
  738. else
  739. {
  740. // Full list
  741. $sHtml .= '<tr class="containerHeader"><td>&nbsp;'.Dict::Format('UI:CountOfResults', $oSet->Count()).'</td><td>';
  742. }
  743. $sHtml .= $oMenuBlock->GetRenderContent($oPage, $aMenuExtraParams);
  744. $sHtml .= '</td></tr>';
  745. }
  746. $sHtml .= "<tr><td $sColspan>";
  747. $sHtml .= $oPage->GetTable($aAttribs, $aValues);
  748. $sHtml .= '</td></tr>';
  749. $sHtml .= '</table>';
  750. return $sHtml;
  751. }
  752. static function DisplaySetAsCSV(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array())
  753. {
  754. $oPage->add(self::GetSetAsCSV($oSet, $aParams));
  755. }
  756. static function GetSetAsCSV(DBObjectSet $oSet, $aParams = array())
  757. {
  758. $sSeparator = isset($aParams['separator']) ? $aParams['separator'] : ','; // default separator is comma
  759. $sTextQualifier = isset($aParams['text_qualifier']) ? $aParams['text_qualifier'] : '"'; // default text qualifier is double quote
  760. $aList = array();
  761. $oAppContext = new ApplicationContext();
  762. $aClasses = $oSet->GetFilter()->GetSelectedClasses();
  763. $aAuthorizedClasses = array();
  764. foreach($aClasses as $sAlias => $sClassName)
  765. {
  766. if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS))
  767. {
  768. $aAuthorizedClasses[$sAlias] = $sClassName;
  769. }
  770. }
  771. $aAttribs = array();
  772. $aHeader = array();
  773. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  774. {
  775. foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode => $oAttDef)
  776. {
  777. if ((($oAttDef->IsExternalField()) || ($oAttDef->IsWritable())) && $oAttDef->IsScalar())
  778. {
  779. $aList[$sClassName][$sAttCode] = $oAttDef;
  780. }
  781. }
  782. $aHeader[] = 'id';
  783. foreach($aList[$sClassName] as $sAttCode => $oAttDef)
  784. {
  785. $sStar = '';
  786. if ($oAttDef->IsExternalField())
  787. {
  788. $sExtKeyLabel = MetaModel::GetLabel($sClassName, $oAttDef->GetKeyAttCode());
  789. $oExtKeyAttDef = MetaModel::GetAttributeDef($sClassName, $oAttDef->GetKeyAttCode());
  790. if (!$oExtKeyAttDef->IsNullAllowed() && isset($aParams['showMandatoryFields']))
  791. {
  792. $sStar = '*';
  793. }
  794. $sRemoteAttLabel = MetaModel::GetLabel($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
  795. $oTargetAttDef = MetaModel::GetAttributeDef($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
  796. $sSuffix = '';
  797. if ($oTargetAttDef->IsExternalKey())
  798. {
  799. $sSuffix = '->id';
  800. }
  801. $aHeader[] = $sExtKeyLabel.'->'.$sRemoteAttLabel.$sSuffix.$sStar;
  802. }
  803. else
  804. {
  805. if (!$oAttDef->IsNullAllowed() && isset($aParams['showMandatoryFields']))
  806. {
  807. $sStar = '*';
  808. }
  809. $aHeader[] = MetaModel::GetLabel($sClassName, $sAttCode).$sStar;
  810. }
  811. }
  812. }
  813. $sHtml = implode($sSeparator, $aHeader)."\n";
  814. $oSet->Seek(0);
  815. while ($aObjects = $oSet->FetchAssoc())
  816. {
  817. $aRow = array();
  818. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  819. {
  820. $oObj = $aObjects[$sAlias];
  821. $aRow[] = $oObj->GetKey();
  822. foreach($aList[$sClassName] as $sAttCode => $oAttDef)
  823. {
  824. $aRow[] = $oObj->GetAsCSV($sAttCode, $sSeparator, '\\');
  825. }
  826. }
  827. $sHtml .= implode($sSeparator, $aRow)."\n";
  828. }
  829. return $sHtml;
  830. }
  831. static function DisplaySetAsXML(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array())
  832. {
  833. $oAppContext = new ApplicationContext();
  834. $aClasses = $oSet->GetFilter()->GetSelectedClasses();
  835. $aAuthorizedClasses = array();
  836. foreach($aClasses as $sAlias => $sClassName)
  837. {
  838. if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS))
  839. {
  840. $aAuthorizedClasses[$sAlias] = $sClassName;
  841. }
  842. }
  843. $aAttribs = array();
  844. $aList = array();
  845. $aList[$sClassName] = MetaModel::GetZListItems($sClassName, 'details');
  846. $oPage->add("<Set>\n");
  847. $oSet->Seek(0);
  848. while ($aObjects = $oSet->FetchAssoc())
  849. {
  850. if (count($aAuthorizedClasses) > 1)
  851. {
  852. $oPage->add("<Row>\n");
  853. }
  854. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  855. {
  856. $oObj = $aObjects[$sAlias];
  857. $sClassName = get_class($oObj);
  858. $oPage->add("<$sClassName alias=\"$sAlias\" id=\"".$oObj->GetKey()."\">\n");
  859. foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode=>$oAttDef)
  860. {
  861. if (($oAttDef->IsWritable()) && ($oAttDef->IsScalar()))
  862. {
  863. $sValue = $oObj->GetAsXML($sAttCode);
  864. $oPage->add("<$sAttCode>$sValue</$sAttCode>\n");
  865. }
  866. }
  867. $oPage->add("</$sClassName>\n");
  868. }
  869. if (count($aAuthorizedClasses) > 1)
  870. {
  871. $oPage->add("</Row>\n");
  872. }
  873. }
  874. $oPage->add("</Set>\n");
  875. }
  876. public static function DisplaySearchForm(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  877. {
  878. $oPage->add(self::GetSearchForm($oPage, $oSet, $aExtraParams));
  879. }
  880. public static function GetSearchForm(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  881. {
  882. static $iSearchFormId = 0;
  883. $oAppContext = new ApplicationContext();
  884. $sHtml = '';
  885. $numCols=4;
  886. $sClassName = $oSet->GetFilter()->GetClass();
  887. // Romain: temporarily removed the tab "OQL query" because it was not finalized
  888. // (especially when used to add a link)
  889. /*
  890. $sHtml .= "<div class=\"mini_tabs\" id=\"mini_tabs{$iSearchFormId}\"><ul>
  891. <li><a href=\"#\" onClick=\"$('div.mini_tab{$iSearchFormId}').toggle();$('#mini_tabs{$iSearchFormId} ul li a').toggleClass('selected');\">".Dict::S('UI:OQLQueryTab')."</a></li>
  892. <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>
  893. </ul></div>\n";
  894. */
  895. // Simple search form
  896. if (isset($aExtraParams['currentId']))
  897. {
  898. $sSearchFormId = $aExtraParams['currentId'];
  899. }
  900. else
  901. {
  902. $iSearchFormId = $oPage->GetUniqueId();
  903. $sSearchFormId = 'SimpleSearchForm'.$iSearchFormId;
  904. $sHtml .= "<div id=\"ds_$sSearchFormId\" class=\"mini_tab{$iSearchFormId}\">\n";
  905. }
  906. // Check if the current class has some sub-classes
  907. if (isset($aExtraParams['baseClass']))
  908. {
  909. $sRootClass = $aExtraParams['baseClass'];
  910. }
  911. else
  912. {
  913. $sRootClass = $sClassName;
  914. }
  915. $aSubClasses = MetaModel::GetSubclasses($sRootClass);
  916. if (count($aSubClasses) > 0)
  917. {
  918. $aOptions = array();
  919. $aOptions[MetaModel::GetName($sRootClass)] = "<option value=\"$sRootClass\">".MetaModel::GetName($sRootClass)."</options>\n";
  920. foreach($aSubClasses as $sSubclassName)
  921. {
  922. $aOptions[MetaModel::GetName($sSubclassName)] = "<option value=\"$sSubclassName\">".MetaModel::GetName($sSubclassName)."</options>\n";
  923. }
  924. $aOptions[MetaModel::GetName($sClassName)] = "<option selected value=\"$sClassName\">".MetaModel::GetName($sClassName)."</options>\n";
  925. ksort($aOptions);
  926. $sContext = $oAppContext->GetForLink();
  927. $sClassesCombo = "<select name=\"class\" onChange=\"ReloadSearchForm('$sSearchFormId', this.value, '$sRootClass', '$sContext')\">\n".implode('', $aOptions)."</select>\n";
  928. }
  929. else
  930. {
  931. $sClassesCombo = MetaModel::GetName($sClassName);
  932. }
  933. $oUnlimitedFilter = new DBObjectSearch($sClassName);
  934. $sHtml .= "<form id=\"fs_{$sSearchFormId}\" action=\"../pages/UI.php\">\n"; // Don't use $_SERVER['SCRIPT_NAME'] since the form may be called asynchronously (from ajax.php)
  935. $sHtml .= "<h2>".Dict::Format('UI:SearchFor_Class_Objects', $sClassesCombo)."</h2>\n";
  936. $index = 0;
  937. $sHtml .= "<p>\n";
  938. $aFilterCriteria = $oSet->GetFilter()->GetCriteria();
  939. $aMapCriteria = array();
  940. foreach($aFilterCriteria as $aCriteria)
  941. {
  942. $aMapCriteria[$aCriteria['filtercode']][] = array('value' => $aCriteria['value'], 'opcode' => $aCriteria['opcode']);
  943. }
  944. $aList = MetaModel::GetZListItems($sClassName, 'standard_search');
  945. foreach($aList as $sFilterCode)
  946. {
  947. //$oAppContext->Reset($sFilterCode); // Make sure the same parameter will not be passed twice
  948. $sHtml .= '<span style="white-space: nowrap;padding:5px;display:inline-block;">';
  949. $sFilterValue = '';
  950. $sFilterValue = utils::ReadParam($sFilterCode, '');
  951. $sFilterOpCode = null; // Use the default 'loose' OpCode
  952. if (empty($sFilterValue))
  953. {
  954. if (isset($aMapCriteria[$sFilterCode]))
  955. {
  956. if (count($aMapCriteria[$sFilterCode]) > 1)
  957. {
  958. $sFilterValue = Dict::S('UI:SearchValue:Mixed');
  959. }
  960. else
  961. {
  962. $sFilterValue = $aMapCriteria[$sFilterCode][0]['value'];
  963. $sFilterOpCode = $aMapCriteria[$sFilterCode][0]['opcode'];
  964. }
  965. if ($sFilterCode != 'company')
  966. {
  967. $oUnlimitedFilter->AddCondition($sFilterCode, $sFilterValue, $sFilterOpCode);
  968. }
  969. }
  970. }
  971. $aAllowedValues = MetaModel::GetAllowedValues_flt($sClassName, $sFilterCode, $aExtraParams);
  972. if ($aAllowedValues != null)
  973. {
  974. //Enum field or external key, display a combo
  975. $sValue = "<select name=\"$sFilterCode\">\n";
  976. $sValue .= "<option value=\"\">".Dict::S('UI:SearchValue:Any')."</option>\n";
  977. foreach($aAllowedValues as $key => $value)
  978. {
  979. if ($sFilterValue == $key)
  980. {
  981. $sSelected = ' selected';
  982. }
  983. else
  984. {
  985. $sSelected = '';
  986. }
  987. $sValue .= "<option value=\"$key\"$sSelected>$value</option>\n";
  988. }
  989. $sValue .= "</select>\n";
  990. $sHtml .= "<label>".MetaModel::GetFilterLabel($sClassName, $sFilterCode).":</label>&nbsp;$sValue\n";
  991. unset($aExtraParams[$sFilterCode]);
  992. }
  993. else
  994. {
  995. // Any value is possible, display an input box
  996. $sHtml .= "<label>".MetaModel::GetFilterLabel($sClassName, $sFilterCode).":</label>&nbsp;<input class=\"textSearch\" name=\"$sFilterCode\" value=\"$sFilterValue\"/>\n";
  997. unset($aExtraParams[$sFilterCode]);
  998. }
  999. $index++;
  1000. $sHtml .= '</span> ';
  1001. }
  1002. $sHtml .= "</p>\n";
  1003. $sHtml .= "<p align=\"right\"><input type=\"submit\" value=\"".Dict::S('UI:Button:Search')."\"></p>\n";
  1004. foreach($aExtraParams as $sName => $sValue)
  1005. {
  1006. $sHtml .= "<input type=\"hidden\" name=\"$sName\" value=\"$sValue\" />\n";
  1007. }
  1008. $sHtml .= "<input type=\"hidden\" name=\"class\" value=\"$sClassName\" />\n";
  1009. $sHtml .= "<input type=\"hidden\" name=\"dosearch\" value=\"1\" />\n";
  1010. $sHtml .= "<input type=\"hidden\" name=\"operation\" value=\"search_form\" />\n";
  1011. $sHtml .= $oAppContext->GetForForm();
  1012. $sHtml .= "</form>\n";
  1013. if (!isset($aExtraParams['currentId']))
  1014. {
  1015. $sHtml .= "</div><!-- Simple search form -->\n";
  1016. }
  1017. /*
  1018. // OQL query builder
  1019. $sHtml .= "<div id=\"OQLQuery{$iSearchFormId}\" style=\"display:none\" class=\"mini_tab{$iSearchFormId}\">\n";
  1020. $sHtml .= "<h1>".Dict::S('UI:OQLQueryBuilderTitle')."</h1>\n";
  1021. $sHtml .= "<form id=\"formOQL{$iSearchFormId}\"><table style=\"width:80%;\"><tr style=\"vertical-align:top\">\n";
  1022. $sHtml .= "<td style=\"text-align:right\"><label>SELECT&nbsp;</label><select name=\"oql_class\">";
  1023. $aClasses = MetaModel::EnumChildClasses($sClassName, ENUM_CHILD_CLASSES_ALL);
  1024. $sSelectedClass = utils::ReadParam('oql_class', $sClassName);
  1025. $sOQLClause = utils::ReadParam('oql_clause', '');
  1026. asort($aClasses);
  1027. foreach($aClasses as $sChildClass)
  1028. {
  1029. $sSelected = ($sChildClass == $sSelectedClass) ? 'selected' : '';
  1030. $sHtml.= "<option value=\"$sChildClass\" $sSelected>".MetaModel::GetName($sChildClass)."</option>\n";
  1031. }
  1032. $sHtml .= "</select>&nbsp;</td><td>\n";
  1033. $sHtml .= "<textarea name=\"oql_clause\" style=\"width:100%\">$sOQLClause</textarea></td></tr>\n";
  1034. $sHtml .= "<tr><td colspan=\"2\" style=\"text-align:right\"><input type=\"submit\" value=\"".Dict::S('UI:Button:Query')."\"></td></tr>\n";
  1035. $sHtml .= "<input type=\"hidden\" name=\"dosearch\" value=\"1\" />\n";
  1036. foreach($aExtraParams as $sName => $sValue)
  1037. {
  1038. $sHtml .= "<input type=\"hidden\" name=\"$sName\" value=\"$sValue\" />\n";
  1039. }
  1040. $sHtml .= "<input type=\"hidden\" name=\"operation\" value=\"search_oql\" />\n";
  1041. $sHtml .= $oAppContext->GetForForm();
  1042. $sHtml .= "</table></form>\n";
  1043. $sHtml .= "</div><!-- OQL query form -->\n";
  1044. */
  1045. return $sHtml;
  1046. }
  1047. public static function GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value = '', $sDisplayValue = '', $iId = '', $sNameSuffix = '', $iFlags = 0, $aArgs = array())
  1048. {
  1049. static $iInputId = 0;
  1050. $sFieldPrefix = '';
  1051. $sFormPrefix = isset($aArgs['formPrefix']) ? $aArgs['formPrefix'] : '';
  1052. $sFieldPrefix = isset($aArgs['prefix']) ? $sFormPrefix.$aArgs['prefix'] : $sFormPrefix;
  1053. if (isset($aArgs[$sAttCode]) && empty($value))
  1054. {
  1055. // default value passed by the context (either the app context of the operation)
  1056. $value = $aArgs[$sAttCode];
  1057. }
  1058. if (!empty($iId))
  1059. {
  1060. $iInputId = $iId;
  1061. }
  1062. else
  1063. {
  1064. $iInputId = $oPage->GetUniqueId();
  1065. }
  1066. if (!$oAttDef->IsExternalField())
  1067. {
  1068. $bMandatory = 'false';
  1069. if ( (!$oAttDef->IsNullAllowed()) || ($iFlags & OPT_ATT_MANDATORY))
  1070. {
  1071. $bMandatory = 'true';
  1072. }
  1073. $sValidationField = "<span class=\"form_validation\" id=\"v_{$iId}\"></span>";
  1074. $sHelpText = $oAttDef->GetHelpOnEdition();
  1075. $aEventsList = array();
  1076. switch($oAttDef->GetEditClass())
  1077. {
  1078. case 'Date':
  1079. case 'DateTime':
  1080. $aEventsList[] ='validate';
  1081. $aEventsList[] ='keyup';
  1082. $aEventsList[] ='change';
  1083. $sHTMLValue = "<input title=\"$sHelpText\" class=\"date-pick\" type=\"text\" size=\"20\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  1084. break;
  1085. case 'Duration':
  1086. $aEventsList[] ='validate';
  1087. $aEventsList[] ='change';
  1088. $oPage->add_ready_script("$('#{$iId}_d').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });");
  1089. $oPage->add_ready_script("$('#{$iId}_h').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });");
  1090. $oPage->add_ready_script("$('#{$iId}_m').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });");
  1091. $oPage->add_ready_script("$('#{$iId}_s').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });");
  1092. $aVal = AttributeDuration::SplitDuration($value);
  1093. $sDays = "<input title=\"$sHelpText\" type=\"text\" size=\"3\" name=\"attr_{$sFieldPrefix}{$sAttCode}[d]{$sNameSuffix}\" value=\"{$aVal['days']}\" id=\"{$iId}_d\"/>";
  1094. $sHours = "<input title=\"$sHelpText\" type=\"text\" size=\"2\" name=\"attr_{$sFieldPrefix}{$sAttCode}[h]{$sNameSuffix}\" value=\"{$aVal['hours']}\" id=\"{$iId}_h\"/>";
  1095. $sMinutes = "<input title=\"$sHelpText\" type=\"text\" size=\"2\" name=\"attr_{$sFieldPrefix}{$sAttCode}[m]{$sNameSuffix}\" value=\"{$aVal['minutes']}\" id=\"{$iId}_m\"/>";
  1096. $sSeconds = "<input title=\"$sHelpText\" type=\"text\" size=\"2\" name=\"attr_{$sFieldPrefix}{$sAttCode}[s]{$sNameSuffix}\" value=\"{$aVal['seconds']}\" id=\"{$iId}_s\"/>";
  1097. $sHidden = "<input type=\"hidden\" id=\"{$iId}\" value=\"$value\"/>";
  1098. $sHTMLValue = Dict::Format('UI:DurationForm_Days_Hours_Minutes_Seconds', $sDays, $sHours, $sMinutes, $sSeconds).$sHidden."&nbsp;".$sValidationField;
  1099. break;
  1100. case 'Password':
  1101. $aEventsList[] ='validate';
  1102. $aEventsList[] ='keyup';
  1103. $aEventsList[] ='change';
  1104. $sHTMLValue = "<input title=\"$sHelpText\" type=\"password\" size=\"30\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  1105. break;
  1106. case 'Text':
  1107. $aEventsList[] ='validate';
  1108. $aEventsList[] ='keyup';
  1109. $aEventsList[] ='change';
  1110. $sEditValue = $oAttDef->GetEditValue($value);
  1111. $sHTMLValue = "<table><tr><td><textarea class=\"resizable\" title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" rows=\"8\" cols=\"40\" id=\"$iId\">$sEditValue</textarea></td><td>{$sValidationField}</td></tr></table>";
  1112. break;
  1113. case 'HTML':
  1114. $oWidget = new UIHTMLEditorWidget($iId, $sAttCode, $sNameSuffix, $sFieldPrefix, $sHelpText, $sValidationField, $value, $bMandatory);
  1115. $sHTMLValue = $oWidget->Display($oPage, $aArgs);
  1116. break;
  1117. case 'LinkedSet':
  1118. $aEventsList[] ='validate';
  1119. $aEventsList[] ='change';
  1120. $oWidget = new UILinksWidget($sClass, $sAttCode, $iId, $sNameSuffix, $oAttDef->DuplicatesAllowed());
  1121. $sHTMLValue = $oWidget->Display($oPage, $value);
  1122. break;
  1123. case 'Document':
  1124. $aEventsList[] ='validate';
  1125. $aEventsList[] ='change';
  1126. $oDocument = $value; // Value is an ormDocument object
  1127. $sFileName = '';
  1128. if (is_object($oDocument))
  1129. {
  1130. $sFileName = $oDocument->GetFileName();
  1131. }
  1132. $iMaxFileSize = utils::ConvertToBytes(ini_get('upload_max_filesize'));
  1133. $sHTMLValue = "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$iMaxFileSize\" />\n";
  1134. $sHTMLValue .= "<input name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" type=\"hidden\" id=\"$iId\" \" value=\"$sFileName\"/>\n";
  1135. $sHTMLValue .= "<span id=\"name_$iInputId\">$sFileName</span><br/>\n";
  1136. $sHTMLValue .= "<input title=\"$sHelpText\" name=\"file_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" type=\"file\" id=\"file_$iId\" onChange=\"UpdateFileName('$iId', this.value)\"/>&nbsp;{$sValidationField}\n";
  1137. break;
  1138. case 'List':
  1139. // Not editable for now...
  1140. $sHTMLValue = '';
  1141. break;
  1142. case 'One Way Password':
  1143. $aEventsList[] ='validate';
  1144. $oWidget = new UIPasswordWidget($sAttCode, $iId, $sNameSuffix);
  1145. $sHTMLValue = $oWidget->Display($oPage, $aArgs);
  1146. // Event list & validation is handled directly by the widget
  1147. break;
  1148. case 'ExtKey':
  1149. $aEventsList[] ='validate';
  1150. $aEventsList[] ='change';
  1151. $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
  1152. $iFieldSize = $oAttDef->GetMaxSize();
  1153. $iMaxComboLength = $oAttDef->GetMaximumComboLength();
  1154. $oWidget = new UIExtKeyWidget($sAttCode, $sClass, $oAttDef->GetLabel(), $aAllowedValues, $value, $iId, $bMandatory, $sNameSuffix, $sFieldPrefix, $sFormPrefix);
  1155. $sHTMLValue = $oWidget->Display($oPage, $aArgs);
  1156. break;
  1157. case 'String':
  1158. default:
  1159. $aEventsList[] ='validate';
  1160. // #@# todo - add context information (depending on dimensions)
  1161. $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
  1162. $iFieldSize = $oAttDef->GetMaxSize();
  1163. if ($aAllowedValues !== null)
  1164. {
  1165. // Discrete list of values, use a SELECT
  1166. $sHTMLValue = "<select title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" id=\"$iId\">\n";
  1167. $sHTMLValue .= "<option value=\"\">".Dict::S('UI:SelectOne')."</option>\n";
  1168. foreach($aAllowedValues as $key => $display_value)
  1169. {
  1170. if ((count($aAllowedValues) == 1) && ($bMandatory == 'true') )
  1171. {
  1172. // When there is only once choice, select it by default
  1173. $sSelected = ' selected';
  1174. }
  1175. else
  1176. {
  1177. $sSelected = ($value == $key) ? ' selected' : '';
  1178. }
  1179. $sHTMLValue .= "<option value=\"$key\"$sSelected>$display_value</option>\n";
  1180. }
  1181. $sHTMLValue .= "</select>&nbsp;{$sValidationField}\n";
  1182. $aEventsList[] ='change';
  1183. }
  1184. else
  1185. {
  1186. $sHTMLValue = "<input title=\"$sHelpText\" type=\"text\" size=\"30\" maxlength=\"$iFieldSize\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  1187. $aEventsList[] ='keyup';
  1188. $aEventsList[] ='change';
  1189. }
  1190. break;
  1191. }
  1192. $sPattern = addslashes($oAttDef->GetValidationPattern()); //'^([0-9]+)$';
  1193. if (!empty($aEventsList))
  1194. {
  1195. $sNullValue = $oAttDef->GetNullValue();
  1196. if (!is_numeric($sNullValue))
  1197. {
  1198. $sNullValue = "'$sNullValue'"; // Add quotes to turn this into a JS string if it's not a number
  1199. }
  1200. $oPage->add_ready_script("$('#$iId').bind('".implode(' ', $aEventsList)."', function(evt, sFormId) { return ValidateField('$iId', '$sPattern', $bMandatory, sFormId, $sNullValue) } );\n"); // Bind to a custom event: validate
  1201. }
  1202. $aDependencies = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that depend on the current one
  1203. if (count($aDependencies) > 0)
  1204. {
  1205. $oPage->add_ready_script("$('#$iId').bind('change', function(evt, sFormId) { return oWizardHelper{$sFormPrefix}.UpdateDependentFields(['".implode("','", $aDependencies)."']) } );\n"); // Bind to a custom event: validate
  1206. }
  1207. }
  1208. return "<div>{$sHTMLValue}</div>";
  1209. }
  1210. public function DisplayModifyForm(WebPage $oPage, $aExtraParams = array())
  1211. {
  1212. static $iGlobalFormId = 1;
  1213. $iGlobalFormId++;
  1214. $sPrefix = '';
  1215. if (isset($aExtraParams['formPrefix']))
  1216. {
  1217. $sPrefix = $aExtraParams['formPrefix'];
  1218. }
  1219. $this->m_iFormId = $sPrefix.$iGlobalFormId;
  1220. $sClass = get_class($this);
  1221. $oAppContext = new ApplicationContext();
  1222. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  1223. $iKey = $this->GetKey();
  1224. $aDetails = array();
  1225. $aFieldsMap = array();
  1226. if (!isset($aExtraParams['action']))
  1227. {
  1228. $sFormAction = $_SERVER['SCRIPT_NAME']; // No parameter in the URL, the only parameter will be the ones passed through the form
  1229. }
  1230. else
  1231. {
  1232. $sFormAction = $aExtraParams['action'];
  1233. }
  1234. $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");
  1235. $oPage->AddTabContainer(OBJECT_PROPERTIES_TAB, $sPrefix);
  1236. $oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
  1237. $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
  1238. // $aDetailsList = $this->FLattenZList(MetaModel::GetZListItems($sClass, 'details'));
  1239. //$aFullList = MetaModel::ListAttributeDefs($sClass);
  1240. $aList = array();
  1241. // Compute the list of properties to display, first the attributes in the 'details' list, then
  1242. // all the remaining attributes that are not external fields
  1243. // foreach($aDetailsList as $sAttCode)
  1244. // {
  1245. // $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1246. // if (!$oAttDef->IsExternalField())
  1247. // {
  1248. // $aList[] = $sAttCode;
  1249. // }
  1250. // }
  1251. $aDetailsList = MetaModel::GetZListItems($sClass, 'details');
  1252. $aDetailsStruct = self::ProcessZlist($aDetailsList, array('UI:PropertiesTab' => array()), 'UI:PropertiesTab', 'col1', '');
  1253. $sHtml = '';
  1254. $aDetails = array();
  1255. foreach($aDetailsStruct as $sTab => $aCols )
  1256. {
  1257. $aDetails[$sTab] = array();
  1258. ksort($aCols);
  1259. $oPage->SetCurrentTab(Dict::S($sTab));
  1260. $oPage->add('<table style="vertical-align:top"><tr>');
  1261. foreach($aCols as $sColIndex => $aFieldsets)
  1262. {
  1263. $sLabel = '';
  1264. $sPreviousLabel = '';
  1265. $aDetails[$sTab][$sColIndex] = array();
  1266. $oPage->add('<td style="vertical-align:top">');
  1267. //$aDetails[$sTab][$sColIndex] = array();
  1268. foreach($aFieldsets as $sFieldsetName => $aFields)
  1269. {
  1270. if (!empty($sFieldsetName) && ($sFieldsetName[0]!='_'))
  1271. {
  1272. $sLabel = $sFieldsetName;
  1273. }
  1274. else
  1275. {
  1276. $sLabel = '';
  1277. }
  1278. if ($sLabel != $sPreviousLabel)
  1279. {
  1280. if (!empty($sPreviousLabel))
  1281. {
  1282. $oPage->add('<fieldset>');
  1283. $oPage->add('<legend>'.Dict::S($sPreviousLabel).'</legend>');
  1284. }
  1285. $oPage->Details($aDetails[$sTab][$sColIndex]);
  1286. if (!empty($sPreviousLabel))
  1287. {
  1288. $oPage->add('</fieldset>');
  1289. }
  1290. $aDetails[$sTab][$sColIndex] = array();
  1291. $sPreviousLabel = $sLabel;
  1292. }
  1293. foreach($aFields as $sAttCode)
  1294. {
  1295. $aVal = null;
  1296. $iFlags = $this->GetAttributeFlags($sAttCode);
  1297. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1298. if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0))
  1299. {
  1300. if ($oAttDef->IsWritable())
  1301. {
  1302. if ($sStateAttCode == $sAttCode)
  1303. {
  1304. // State attribute is always read-only from the UI
  1305. $sHTMLValue = $this->GetStateLabel();
  1306. $aVal = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue);
  1307. }
  1308. else
  1309. {
  1310. $sInputId = $this->m_iFormId.'_'.$sAttCode;
  1311. if ($iFlags & OPT_ATT_HIDDEN)
  1312. {
  1313. // Attribute is hidden, add a hidden input
  1314. $oPage->add('<input type="hidden" id="'.$sInputId.'" name="attr_'.$sPrefix.$sAttCode.'" value="'.htmlentities($this->Get($sAttCode), ENT_QUOTES, 'UTF-8').'"/>');
  1315. $aFieldsMap[$sAttCode] = $sInputId;
  1316. }
  1317. else
  1318. {
  1319. if ($iFlags & OPT_ATT_READONLY)
  1320. {
  1321. // Check if the attribute is not read-only becuase of a synchro...
  1322. $aReasons = array();
  1323. $iSynchroFlags = $this->GetSynchroReplicaFlags($sAttCode, $aReasons);
  1324. $sSynchroIcon = '';
  1325. if ($iSynchroFlags & OPT_ATT_READONLY)
  1326. {
  1327. $sSynchroIcon = "&nbsp;<img id=\"synchro_$sInputId\" src=\"../images/transp-lock.png\" style=\"vertical-align:middle\"/>";
  1328. $sTip = '';
  1329. foreach($aReasons as $aRow)
  1330. {
  1331. $sTip .= "<p>Synchronized with {$aRow['name']} - {$aRow['description']}</p>";
  1332. }
  1333. $oPage->add_ready_script("$('#synchro_$sInputId').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );");
  1334. }
  1335. // Attribute is read-only
  1336. $sHTMLValue = $this->GetAsHTML($sAttCode).$sSynchroIcon;
  1337. $sHTMLValue .= '<input type="hidden" id="'.$sInputId.'" name="attr_'.$sPrefix.$sAttCode.'" value="'.htmlentities($this->Get($sAttCode), ENT_QUOTES, 'UTF-8').'"/>';
  1338. $aFieldsMap[$sAttCode] = $sInputId;
  1339. }
  1340. else
  1341. {
  1342. $sValue = $this->Get($sAttCode);
  1343. $sDisplayValue = $this->GetEditValue($sAttCode);
  1344. $aArgs = array('this' => $this, 'formPrefix' => $sPrefix);
  1345. $sHTMLValue = "<span id=\"field_{$sInputId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).'</span>';
  1346. $aFieldsMap[$sAttCode] = $sInputId;
  1347. }
  1348. $aVal = array('label' => '<span title="'.$oAttDef->GetDescription().'">'.$oAttDef->GetLabel().'</span>', 'value' => $sHTMLValue);
  1349. }
  1350. }
  1351. }
  1352. else
  1353. {
  1354. $aVal = array('label' => '<span title="'.$oAttDef->GetDescription().'">'.$oAttDef->GetLabel().'</span>', 'value' => $this->GetAsHTML($sAttCode));
  1355. }
  1356. }
  1357. if ($aVal != null)
  1358. {
  1359. // The field is visible, add it to the current column
  1360. $aDetails[$sTab][$sColIndex][] = $aVal;
  1361. }
  1362. }
  1363. }
  1364. if (!empty($sPreviousLabel))
  1365. {
  1366. $oPage->add('<fieldset>');
  1367. $oPage->add('<legend>'.Dict::S($sPreviousLabel).'</legend>');
  1368. }
  1369. $oPage->Details($aDetails[$sTab][$sColIndex]);
  1370. if (!empty($sPreviousLabel))
  1371. {
  1372. $oPage->add('</fieldset>');
  1373. }
  1374. $oPage->add('</td>');
  1375. }
  1376. $oPage->add('</tr></table>');
  1377. }
  1378. // Now display the relations, one tab per relation
  1379. if (!isset($aExtraParams['noRelations']))
  1380. {
  1381. $this->DisplayBareRelations($oPage, true); // Edit mode
  1382. }
  1383. $oPage->SetCurrentTab('');
  1384. $oPage->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">\n");
  1385. $oPage->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
  1386. foreach($aExtraParams as $sName => $value)
  1387. {
  1388. $oPage->add("<input type=\"hidden\" name=\"$sName\" value=\"$value\">\n");
  1389. }
  1390. $oPage->add($oAppContext->GetForForm());
  1391. if ($iKey > 0)
  1392. {
  1393. // The object already exists in the database, it's modification
  1394. $oPage->add("<input type=\"hidden\" name=\"id\" value=\"$iKey\">\n");
  1395. $oPage->add("<input type=\"hidden\" name=\"operation\" value=\"apply_modify\">\n");
  1396. // $oPage->add("<button type=\"button\" id=\"btn_cancel_{$sPrefix}\" class=\"action\" onClick=\"BackToDetails('$sClass', $iKey)\"><span>".Dict::S('UI:Button:Cancel')."</span></button>&nbsp;&nbsp;&nbsp;&nbsp;\n");
  1397. $oPage->add("<button type=\"button\" class=\"action cancel\"><span>".Dict::S('UI:Button:Cancel')."</span></button>&nbsp;&nbsp;&nbsp;&nbsp;\n");
  1398. $oPage->add("<button type=\"submit\" class=\"action\"><span>".Dict::S('UI:Button:Apply')."</span></button>\n");
  1399. }
  1400. else
  1401. {
  1402. // The object does not exist in the database it's a creation
  1403. $oPage->add("<input type=\"hidden\" name=\"operation\" value=\"apply_new\">\n");
  1404. // $oPage->add("<button type=\"button\" id=\"btn_cancel_{$sPrefix}\" class=\"action\" onClick=\"BackToDetails('$sClass', $iKey)\"><span>".Dict::S('UI:Button:Cancel')."</span></button>&nbsp;&nbsp;&nbsp;&nbsp;\n");
  1405. $oPage->add("<button type=\"button\" class=\"action cancel\">".Dict::S('UI:Button:Cancel')."</button>&nbsp;&nbsp;&nbsp;&nbsp;\n");
  1406. $oPage->add("<button type=\"submit\" class=\"action\"><span>".Dict::S('UI:Button:Create')."</span></button>\n");
  1407. }
  1408. // Hook the cancel button via jQuery so that it can be unhooked easily as well if needed
  1409. $sDefaultUrl = '../pages/UI.php?operation=cancel';
  1410. $oPage->add_ready_script("$('#form_{$this->m_iFormId} button.cancel').click( function() { BackToDetails('$sClass', $iKey, '$sDefaultUrl')} );");
  1411. $oPage->add("</form>\n");
  1412. $iFieldsCount = count($aFieldsMap);
  1413. $sJsonFieldsMap = json_encode($aFieldsMap);
  1414. $oPage->add_script(
  1415. <<<EOF
  1416. // Create the object once at the beginning of the page...
  1417. var oWizardHelper$sPrefix = new WizardHelper('$sClass', '$sPrefix');
  1418. oWizardHelper$sPrefix.SetFieldsMap($sJsonFieldsMap);
  1419. oWizardHelper$sPrefix.SetFieldsCount($iFieldsCount);
  1420. EOF
  1421. );
  1422. $oPage->add_ready_script(
  1423. <<<EOF
  1424. // Starts the validation when the page is ready
  1425. CheckFields('form_{$this->m_iFormId}', false);
  1426. EOF
  1427. );
  1428. }
  1429. public static function DisplayCreationForm(WebPage $oPage, $sClass, $oObjectToClone = null, $aArgs = array(), $aExtraParams = array())
  1430. {
  1431. $oAppContext = new ApplicationContext();
  1432. $sClass = ($oObjectToClone == null) ? $sClass : get_class($oObjectToClone);
  1433. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  1434. $aStates = MetaModel::EnumStates($sClass);
  1435. if ($oObjectToClone == null)
  1436. {
  1437. $oObj = MetaModel::NewObject($sClass);
  1438. if (!empty($sStateAttCode))
  1439. {
  1440. $sTargetState = MetaModel::GetDefaultState($sClass);
  1441. $oObj->Set($sStateAttCode, $sTargetState);
  1442. }
  1443. }
  1444. else
  1445. {
  1446. $oObj = clone $oObjectToClone;
  1447. }
  1448. // Pre-fill the object with default values, when there is only on possible choice
  1449. // AND the field is mandatory (otherwise there is always the possiblity to let it empty)
  1450. $aArgs['this'] = $oObj;
  1451. $aDetailsList = self::FLattenZList(MetaModel::GetZListItems($sClass, 'details'));
  1452. // Order the fields based on their dependencies
  1453. $aDeps = array();
  1454. foreach($aDetailsList as $sAttCode)
  1455. {
  1456. $aDeps[$sAttCode] = MetaModel::GetPrequisiteAttributes($sClass, $sAttCode);
  1457. }
  1458. $aList = self::OrderDependentFields($aDeps);
  1459. // Now fill-in the fields with default/supplied values
  1460. foreach($aList as $sAttCode)
  1461. {
  1462. $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
  1463. if (isset($aArgs['default'][$sAttCode]))
  1464. {
  1465. $oObj->Set($sAttCode, $aArgs['default'][$sAttCode]);
  1466. }
  1467. elseif (count($aAllowedValues) == 1)
  1468. {
  1469. // If the field is mandatory, set it to the only possible value
  1470. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1471. $iFlags = $oObj->GetAttributeFlags($sAttCode);
  1472. if ( (!$oAttDef->IsNullAllowed()) || ($iFlags & OPT_ATT_MANDATORY))
  1473. {
  1474. $aValues = array_keys($aAllowedValues);
  1475. $oObj->Set($sAttCode, $aValues[0]);
  1476. }
  1477. }
  1478. }
  1479. return $oObj->DisplayModifyForm( $oPage, $aExtraParams);
  1480. }
  1481. protected static function ProcessZlist($aList, $aDetails, $sCurrentTab, $sCurrentCol, $sCurrentSet)
  1482. {
  1483. //echo "<pre>ZList: ";
  1484. //print_r($aList);
  1485. //echo "</pre>\n";
  1486. $index = 0;
  1487. foreach($aList as $sKey => $value)
  1488. {
  1489. if (is_array($value))
  1490. {
  1491. if (preg_match('/^(.*):(.*)$/U', $sKey, $aMatches))
  1492. {
  1493. $sCode = $aMatches[1];
  1494. $sName = $aMatches[2];
  1495. switch($sCode)
  1496. {
  1497. case 'tab':
  1498. //echo "<p>Found a tab: $sName ($sKey)</p>\n";
  1499. if(!isset($aDetails[$sName]))
  1500. {
  1501. $aDetails[$sName] = array('col1' => array());
  1502. }
  1503. $aDetails = self::ProcessZlist($value, $aDetails, $sName, 'col1', '');
  1504. break;
  1505. case 'fieldset':
  1506. //echo "<p>Found a fieldset: $sName ($sKey)</p>\n";
  1507. if(!isset($aDetailsStruct[$sCurrentTab][$sCurrentCol][$sName]))
  1508. {
  1509. $aDetails[$sCurrentTab][$sCurrentCol][$sName] = array();
  1510. }
  1511. $aDetails = self::ProcessZlist($value, $aDetails, $sCurrentTab, $sCurrentCol, $sName);
  1512. break;
  1513. default:
  1514. case 'col':
  1515. //echo "<p>Found a column: $sName ($sKey)</p>\n";
  1516. if(!isset($aDetails[$sCurrentTab][$sName]))
  1517. {
  1518. $aDetails[$sCurrentTab][$sName] = array();
  1519. }
  1520. $aDetails = self::ProcessZlist($value, $aDetails, $sCurrentTab, $sName, '');
  1521. break;
  1522. }
  1523. }
  1524. }
  1525. else
  1526. {
  1527. //echo "<p>Scalar value: $value, in [$sCurrentTab][$sCurrentCol][$sCurrentSet][]</p>\n";
  1528. if (empty($sCurrentSet))
  1529. {
  1530. $aDetails[$sCurrentTab][$sCurrentCol]['_'.$index][] = $value;
  1531. }
  1532. else
  1533. {
  1534. $aDetails[$sCurrentTab][$sCurrentCol][$sCurrentSet][] = $value;
  1535. }
  1536. }
  1537. $index++;
  1538. }
  1539. return $aDetails;
  1540. }
  1541. protected static function FlattenZList($aList)
  1542. {
  1543. $aResult = array();
  1544. foreach($aList as $value)
  1545. {
  1546. if (!is_array($value))
  1547. {
  1548. $aResult[] = $value;
  1549. }
  1550. else
  1551. {
  1552. $aResult = array_merge($aResult,self::FlattenZList($value));
  1553. }
  1554. }
  1555. return $aResult;
  1556. }
  1557. protected function GetFieldAsHtml($sClass, $sAttCode, $sStateAttCode)
  1558. {
  1559. $retVal = null;
  1560. $iFlags = $this->GetAttributeFlags($sAttCode);
  1561. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1562. if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0) )
  1563. {
  1564. // The field is visible in the current state of the object
  1565. if ($sStateAttCode == $sAttCode)
  1566. {
  1567. // Special display for the 'state' attribute itself
  1568. $sDisplayValue = $this->GetStateLabel();
  1569. }
  1570. else if ($oAttDef->GetEditClass() == 'Document')
  1571. {
  1572. $oDocument = $this->Get($sAttCode);
  1573. $sDisplayValue = $this->GetAsHTML($sAttCode);
  1574. $sDisplayValue .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_', $oDocument->GetDisplayLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
  1575. $sDisplayValue .= "<br/>".Dict::Format('UI:DownloadDocument_', $oDocument->GetDisplayLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
  1576. }
  1577. else
  1578. {
  1579. $sDisplayValue = $this->GetAsHTML($sAttCode);
  1580. }
  1581. $retVal = array('label' => '<span title="'.MetaModel::GetDescription($sClass, $sAttCode).'">'.MetaModel::GetLabel($sClass, $sAttCode).'</span>', 'value' => $sDisplayValue);
  1582. }
  1583. return $retVal;
  1584. }
  1585. /**
  1586. * Displays a blob document *inline* (if possible, depending on the type of the document)
  1587. * @return string
  1588. */
  1589. public function DisplayDocumentInline(WebPage $oPage, $sAttCode)
  1590. {
  1591. $oDoc = $this->Get($sAttCode);
  1592. $sClass = get_class($this);
  1593. $Id = $this->GetKey();
  1594. switch ($oDoc->GetMainMimeType())
  1595. {
  1596. case 'text':
  1597. case 'html':
  1598. $data = $oDoc->GetData();
  1599. switch($oDoc->GetMimeType())
  1600. {
  1601. case 'text/html':
  1602. case 'text/xml':
  1603. $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");
  1604. break;
  1605. default:
  1606. $oPage->add("<pre>".htmlentities(MyHelpers::beautifulstr($data, 1000, true))."</pre>\n");
  1607. }
  1608. break;
  1609. case 'application':
  1610. switch($oDoc->GetMimeType())
  1611. {
  1612. case 'application/pdf':
  1613. $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");
  1614. break;
  1615. default:
  1616. $oPage->add(Dict::S('UI:Document:NoPreview'));
  1617. }
  1618. break;
  1619. case 'image':
  1620. $oPage->add("<img src=\"../pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" />\n");
  1621. break;
  1622. default:
  1623. $oPage->add(Dict::S('UI:Document:NoPreview'));
  1624. }
  1625. }
  1626. /**
  1627. * This function returns a 'hilight' CSS class, used to hilight a given row in a table
  1628. * There are currently (i.e defined in the CSS) 4 possible values HILIGHT_CLASS_CRITICAL,
  1629. * HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  1630. * To Be overridden by derived classes
  1631. * @param void
  1632. * @return String The desired higlight class for the object/row
  1633. */
  1634. public function GetHilightClass()
  1635. {
  1636. // Possible return values are:
  1637. // HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  1638. return HILIGHT_CLASS_NONE; // Not hilighted by default
  1639. }
  1640. /**
  1641. * Re-order the fields based on their inter-dependencies
  1642. * @params hash @aFields field_code => array_of_depencies
  1643. * @return array Ordered array of fields or throws an exception
  1644. */
  1645. public static function OrderDependentFields($aFields)
  1646. {
  1647. $bCircular = false;
  1648. $aResult = array();
  1649. $iCount = 0;
  1650. do
  1651. {
  1652. $bSet = false;
  1653. $iCount++;
  1654. foreach($aFields as $sFieldCode => $aDeps)
  1655. {
  1656. foreach($aDeps as $key => $sDependency)
  1657. {
  1658. if (in_array($sDependency, $aResult))
  1659. {
  1660. // Dependency is resolved, remove it
  1661. unset($aFields[$sFieldCode][$key]);
  1662. }
  1663. }
  1664. if (count($aFields[$sFieldCode]) == 0)
  1665. {
  1666. // No more pending depencies for this field, add it to the list
  1667. $aResult[] = $sFieldCode;
  1668. unset($aFields[$sFieldCode]);
  1669. $bSet = true;
  1670. }
  1671. }
  1672. }
  1673. while($bSet && (count($aFields) > 0));
  1674. if (count($aFields) > 0)
  1675. {
  1676. $sMessage = "Error: Circular dependencies between the fields ! <pre>".print_r($aFields, true)."</pre>";
  1677. throw(new Exception($sMessage));
  1678. }
  1679. return $aResult;
  1680. }
  1681. /**
  1682. * Maps the given context parameter name to the appropriate filter/search code for this class
  1683. * @param string $sContextParam Name of the context parameter, i.e. 'org_id'
  1684. * @return string Filter code, i.e. 'customer_id'
  1685. */
  1686. public static function MapContextParam($sContextParam)
  1687. {
  1688. if ($sContextParam == 'menu')
  1689. {
  1690. return null;
  1691. }
  1692. else
  1693. {
  1694. return $sContextParam;
  1695. }
  1696. }
  1697. /**
  1698. * Updates the object from the POSTed parameters
  1699. */
  1700. public function UpdateObject($sFormPrefix = '')
  1701. {
  1702. foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode=>$oAttDef)
  1703. {
  1704. if ($oAttDef->IsLinkSet() && $oAttDef->IsIndirect())
  1705. {
  1706. $aLinks = utils::ReadPostedParam("attr_{$sFormPrefix}{$sAttCode}", '');
  1707. $sLinkedClass = $oAttDef->GetLinkedClass();
  1708. $sExtKeyToRemote = $oAttDef->GetExtKeyToRemote();
  1709. $sExtKeyToMe = $oAttDef->GetExtKeyToMe();
  1710. $oLinkedSet = DBObjectSet::FromScratch($sLinkedClass);
  1711. if (is_array($aLinks))
  1712. {
  1713. foreach($aLinks as $id => $aData)
  1714. {
  1715. if (is_numeric($id))
  1716. {
  1717. if ($id < 0)
  1718. {
  1719. // New link to be created, the opposite of the id (-$id) is the ID of the remote object
  1720. $oLink = MetaModel::NewObject($sLinkedClass);
  1721. $oLink->Set($sExtKeyToRemote, -$id);
  1722. $oLink->Set($sExtKeyToMe, $this->GetKey());
  1723. }
  1724. else
  1725. {
  1726. // Existing link, potentially to be updated...
  1727. $oLink = MetaModel::GetObject($sLinkedClass, $id);
  1728. }
  1729. // Now populate the attributes
  1730. foreach($aData as $sName => $value)
  1731. {
  1732. if (MetaModel::IsValidAttCode($sLinkedClass, $sName))
  1733. {
  1734. $oLinkAttDef = MetaModel::GetAttributeDef($sLinkedClass, $sName);
  1735. if ($oLinkAttDef->IsWritable())
  1736. {
  1737. $oLink->Set($sName, $value);
  1738. }
  1739. }
  1740. }
  1741. $oLinkedSet->AddObject($oLink);
  1742. }
  1743. }
  1744. }
  1745. $this->Set($sAttCode, $oLinkedSet);
  1746. }
  1747. else if ($oAttDef->IsWritable())
  1748. {
  1749. $iFlags = $this->GetAttributeFlags($sAttCode);
  1750. if ($iFlags & (OPT_ATT_HIDDEN | OPT_ATT_READONLY))
  1751. {
  1752. // Non-visible, or read-only attribute, do nothing
  1753. }
  1754. elseif ($oAttDef->GetEditClass() == 'Document')
  1755. {
  1756. // There should be an uploaded file with the named attr_<attCode>
  1757. $oDocument = utils::ReadPostedDocument("file_{$sFormPrefix}{$sAttCode}");
  1758. if (!$oDocument->IsEmpty())
  1759. {
  1760. // A new file has been uploaded
  1761. $this->Set($sAttCode, $oDocument);
  1762. }
  1763. }
  1764. elseif ($oAttDef->GetEditClass() == 'One Way Password')
  1765. {
  1766. // Check if the password was typed/changed
  1767. $bChanged = utils::ReadPostedParam("attr_{$sFormPrefix}{$sAttCode}_changed", false);
  1768. if ($bChanged)
  1769. {
  1770. // The password has been changed or set
  1771. $rawValue = utils::ReadPostedParam("attr_{$sFormPrefix}{$sAttCode}", null);
  1772. $this->Set($sAttCode, $rawValue);
  1773. }
  1774. }
  1775. elseif ($oAttDef->GetEditClass() == 'Duration')
  1776. {
  1777. $rawValue = utils::ReadPostedParam("attr_{$sFormPrefix}{$sAttCode}", null);
  1778. if (!is_array($rawValue))
  1779. {
  1780. $iValue = null;
  1781. }
  1782. else
  1783. {
  1784. $iValue = (((24*$rawValue['d'])+$rawValue['h'])*60 +$rawValue['m'])*60 + $rawValue['s'];
  1785. }
  1786. $this->Set($sAttCode, $iValue);
  1787. $previousValue = $this->Get($sAttCode);
  1788. if ($previousValue !== $iValue)
  1789. {
  1790. $this->Set($sAttCode, $iValue);
  1791. }
  1792. }
  1793. else
  1794. {
  1795. $rawValue = utils::ReadPostedParam("attr_{$sFormPrefix}{$sAttCode}", null);
  1796. if (!is_null($rawValue))
  1797. {
  1798. $aAttributes[$sAttCode] = trim($rawValue);
  1799. $previousValue = $this->Get($sAttCode);
  1800. if ($previousValue !== $aAttributes[$sAttCode])
  1801. {
  1802. $this->Set($sAttCode, $aAttributes[$sAttCode]);
  1803. }
  1804. }
  1805. }
  1806. }
  1807. }
  1808. }
  1809. }
  1810. ?>