cmdbabstract.class.inc.php 87 KB

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