cmdbabstract.class.inc.php 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897
  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 '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, $sPrefix = '', $aExtraParams = array())
  191. {
  192. $aFieldsMap = $this->GetBareProperties($oPage, $bEditMode, $sPrefix, $aExtraParams);
  193. // Special case to display the case log, if any...
  194. // WARNING: if you modify the loop below, also check the corresponding code in UpdateObject and DisplayModifyForm
  195. foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode => $oAttDef)
  196. {
  197. if ($oAttDef instanceof AttributeCaseLog)
  198. {
  199. $sComment = (isset($aExtraParams['fieldsComments'][$sAttCode])) ? $aExtraParams['fieldsComments'][$sAttCode] : '';
  200. $this->DisplayCaseLog($oPage, $sAttCode, $sComment, $sPrefix, $bEditMode);
  201. }
  202. }
  203. foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance)
  204. {
  205. $oExtensionInstance->OnDisplayProperties($this, $oPage, $bEditMode);
  206. }
  207. return $aFieldsMap;
  208. }
  209. function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
  210. {
  211. // Related objects: display all the linkset attributes, each as a separate tab
  212. // In the order described by the 'display' ZList
  213. $aList = $this->FlattenZList(MetaModel::GetZListItems(get_class($this), 'details'));
  214. if (count($aList) == 0)
  215. {
  216. // Empty ZList defined, display all the linkedset attributes defined
  217. $aList = array_keys(MetaModel::ListAttributeDefs(get_class($this)));
  218. }
  219. $sClass = get_class($this);
  220. foreach($aList as $sAttCode)
  221. {
  222. $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
  223. // Display mode
  224. if (!$oAttDef->IsLinkset()) continue; // Process only linkset attributes...
  225. $oSet = new DBObjectSet($this->Get($sAttCode)->GetFilter());
  226. $iCount = $oSet->Count();
  227. $sCount = '';
  228. if ($iCount != 0)
  229. {
  230. $sCount = " ($iCount)";
  231. }
  232. $oPage->SetCurrentTab($oAttDef->GetLabel().$sCount);
  233. if ($bEditMode)
  234. {
  235. if ($this->IsNew())
  236. {
  237. $iFlags = $this->GetInitialStateAttributeFlags($sAttCode);
  238. }
  239. else
  240. {
  241. $iFlags = $this->GetAttributeFlags($sAttCode);
  242. }
  243. $sInputId = $this->m_iFormId.'_'.$sAttCode;
  244. if (get_class($oAttDef) == 'AttributeLinkedSet')
  245. {
  246. // 1:n links
  247. $sTargetClass = $oAttDef->GetLinkedClass();
  248. if ($this->IsNew())
  249. {
  250. $oPage->p(Dict::Format('UI:BeforeAdding_Class_ObjectsSaveThisObject', MetaModel::GetName($sTargetClass)));
  251. }
  252. else
  253. {
  254. $oPage->p(MetaModel::GetClassIcon($sTargetClass)."&nbsp;".$oAttDef->GetDescription());
  255. $oFilter = new DBObjectSearch($sTargetClass);
  256. $oFilter->AddCondition($oAttDef->GetExtKeyToMe(), $this->GetKey(),'=');
  257. $aDefaults = array($oAttDef->GetExtKeyToMe() => $this->GetKey());
  258. $oAppContext = new ApplicationContext();
  259. foreach($oAppContext->GetNames() as $sKey)
  260. {
  261. // The linked object inherits the parent's value for the context
  262. if (MetaModel::IsValidAttCode($sClass, $sKey))
  263. {
  264. $aDefaults[$sKey] = $this->Get($sKey);
  265. }
  266. }
  267. $aParams = array(
  268. 'target_attr' => $oAttDef->GetExtKeyToMe(),
  269. 'object_id' => $this->GetKey(),
  270. 'menu' => true,
  271. 'default' => $aDefaults,
  272. );
  273. $oBlock = new DisplayBlock($oFilter, 'list', false);
  274. $oBlock->Display($oPage, $sInputId, $aParams);
  275. }
  276. }
  277. else // get_class($oAttDef) == 'AttributeLinkedSetIndirect'
  278. {
  279. // n:n links
  280. $sLinkedClass = $oAttDef->GetLinkedClass();
  281. $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote());
  282. $sTargetClass = $oLinkingAttDef->GetTargetClass();
  283. $oPage->p(MetaModel::GetClassIcon($sTargetClass)."&nbsp;".$oAttDef->GetDescription().'<span id="busy_'.$sInputId.'"></span>');
  284. $sValue = $this->Get($sAttCode);
  285. $sDisplayValue = $this->GetEditValue($sAttCode);
  286. $aArgs = array('this' => $this);
  287. $sHTMLValue = "<span id=\"field_{$sInputId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).'</span>';
  288. $aFieldsMap[$sAttCode] = $sInputId;
  289. $oPage->add($sHTMLValue);
  290. }
  291. }
  292. else
  293. {
  294. // Display mode
  295. if (!$oAttDef->IsIndirect())
  296. {
  297. // 1:n links
  298. $sTargetClass = $oAttDef->GetLinkedClass();
  299. $aDefaults = array($oAttDef->GetExtKeyToMe() => $this->GetKey());
  300. $oAppContext = new ApplicationContext();
  301. foreach($oAppContext->GetNames() as $sKey)
  302. {
  303. // The linked object inherits the parent's value for the context
  304. if (MetaModel::IsValidAttCode($sClass, $sKey))
  305. {
  306. $aDefaults[$sKey] = $this->Get($sKey);
  307. }
  308. }
  309. $aParams = array(
  310. 'target_attr' => $oAttDef->GetExtKeyToMe(),
  311. 'object_id' => $this->GetKey(),
  312. 'menu' => false,
  313. 'default' => $aDefaults,
  314. );
  315. }
  316. else
  317. {
  318. // n:n links
  319. $sLinkedClass = $oAttDef->GetLinkedClass();
  320. $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote());
  321. $sTargetClass = $oLinkingAttDef->GetTargetClass();
  322. $bMenu = ($this->Get($sAttCode)->Count() > 0); // The menu is enabled only if there are already some elements...
  323. $aParams = array(
  324. 'link_attr' => $oAttDef->GetExtKeyToMe(),
  325. 'object_id' => $this->GetKey(),
  326. 'target_attr' => $oAttDef->GetExtKeyToRemote(),
  327. 'view_link' => false,
  328. 'menu' => false,
  329. 'display_limit' => true, // By default limit the list to speed up the initial load & display
  330. );
  331. }
  332. $oPage->p(MetaModel::GetClassIcon($sTargetClass)."&nbsp;".$oAttDef->GetDescription());
  333. $oBlock = new DisplayBlock($this->Get($sAttCode)->GetFilter(), 'list', false);
  334. $oBlock->Display($oPage, 'rel_'.$sAttCode, $aParams);
  335. }
  336. }
  337. $oPage->SetCurrentTab('');
  338. foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance)
  339. {
  340. $oExtensionInstance->OnDisplayRelations($this, $oPage, $bEditMode);
  341. }
  342. // Display Notifications after the other tabs since this tab disappears in edition
  343. if (!$bEditMode)
  344. {
  345. // Get the actual class of the current object
  346. // And look for triggers referring to it
  347. // If any trigger has been found then display a tab with notifications
  348. //
  349. $sClass = get_class($this);
  350. $sClassList = implode("', '", MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL));
  351. $oTriggerSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnObject AS T WHERE T.target_class IN ('$sClassList')"));
  352. if ($oTriggerSet->Count() > 0)
  353. {
  354. // Display notifications regarding the object
  355. $iId = $this->GetKey();
  356. $oNotifSearch = 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");
  357. $oNotifSet = new DBObjectSet($oNotifSearch);
  358. $sCount = ($oNotifSet->Count() > 0) ? ' ('.$oNotifSet->Count().')' : '';
  359. $oPage->SetCurrentTab(Dict::S('UI:NotificationsTab').$sCount);
  360. $oBlock = new DisplayBlock($oNotifSearch, 'list', false);
  361. $oBlock->Display($oPage, 'notifications', array('menu' => false));
  362. }
  363. }
  364. }
  365. function GetBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix, $aExtraParams = array())
  366. {
  367. $sHtml = '';
  368. $oAppContext = new ApplicationContext();
  369. $sStateAttCode = MetaModel::GetStateAttributeCode(get_class($this));
  370. $aDetails = array();
  371. $sClass = get_class($this);
  372. $aDetailsList = MetaModel::GetZListItems($sClass, 'details');
  373. $aDetailsStruct = self::ProcessZlist($aDetailsList, array('UI:PropertiesTab' => array()), 'UI:PropertiesTab', 'col1', '');
  374. // Compute the list of properties to display, first the attributes in the 'details' list, then
  375. // all the remaining attributes that are not external fields
  376. $sHtml = '';
  377. $aDetails = array();
  378. $iInputId = 0;
  379. $aFieldsMap = array();
  380. $aFieldsComments = (isset($aExtraParams['fieldsComments'])) ? $aExtraParams['fieldsComments'] : array();
  381. $bFieldComments = (count($aFieldsComments) > 0);
  382. foreach($aDetailsStruct as $sTab => $aCols )
  383. {
  384. $aDetails[$sTab] = array();
  385. ksort($aCols);
  386. $oPage->SetCurrentTab(Dict::S($sTab));
  387. $oPage->add('<table style="vertical-align:top"><tr>');
  388. foreach($aCols as $sColIndex => $aFieldsets)
  389. {
  390. $oPage->add('<td style="vertical-align:top">');
  391. //$aDetails[$sTab][$sColIndex] = array();
  392. $sLabel = '';
  393. $sPreviousLabel = '';
  394. $aDetails[$sTab][$sColIndex] = array();
  395. foreach($aFieldsets as $sFieldsetName => $aFields)
  396. {
  397. if (!empty($sFieldsetName) && ($sFieldsetName[0] != '_'))
  398. {
  399. $sLabel = $sFieldsetName;
  400. }
  401. else
  402. {
  403. $sLabel = '';
  404. }
  405. if ($sLabel != $sPreviousLabel)
  406. {
  407. if (!empty($sPreviousLabel))
  408. {
  409. $oPage->add('<fieldset>');
  410. $oPage->add('<legend>'.Dict::S($sPreviousLabel).'</legend>');
  411. }
  412. $oPage->Details($aDetails[$sTab][$sColIndex]);
  413. if (!empty($sPreviousLabel))
  414. {
  415. $oPage->add('</fieldset>');
  416. }
  417. $aDetails[$sTab][$sColIndex] = array();
  418. $sPreviousLabel = $sLabel;
  419. }
  420. foreach($aFields as $sAttCode)
  421. {
  422. if ($bEditMode)
  423. {
  424. $sComments = isset($aFieldsComments[$sAttCode]) ? $aFieldsComments[$sAttCode] : '&nbsp;';
  425. $sInfos = '&nbsp;';
  426. if ($this->IsNew())
  427. {
  428. $iFlags = $this->GetInitialStateAttributeFlags($sAttCode);
  429. }
  430. else
  431. {
  432. $iFlags = $this->GetAttributeFlags($sAttCode);
  433. }
  434. if (($iFlags & OPT_ATT_MANDATORY) && $this->IsNew())
  435. {
  436. $iFlags = $iFlags & ~OPT_ATT_READONLY; // Mandatory fields cannot be read-only when creating an object
  437. }
  438. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  439. if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0))
  440. {
  441. if ($oAttDef->IsWritable())
  442. {
  443. if ($sStateAttCode == $sAttCode)
  444. {
  445. // State attribute is always read-only from the UI
  446. $sHTMLValue = $this->GetStateLabel();
  447. $val = array('label' => '<span>'.$oAttDef->GetLabel().'</span>', 'value' => $sHTMLValue, 'comments' => $sComments, 'infos' => $sInfos);
  448. }
  449. else
  450. {
  451. $sInputId = $this->m_iFormId.'_'.$sAttCode;
  452. if ($iFlags & OPT_ATT_HIDDEN)
  453. {
  454. // Attribute is hidden, add a hidden input
  455. $oPage->add('<input type="hidden" id="'.$sInputId.'" name="attr_'.$sPrefix.$sAttCode.'" value="'.htmlentities($this->Get($sAttCode), ENT_QUOTES, 'UTF-8').'"/>');
  456. $aFieldsMap[$sAttCode] = $sInputId;
  457. }
  458. else
  459. {
  460. if ($iFlags & (OPT_ATT_READONLY|OPT_ATT_SLAVE))
  461. {
  462. // Check if the attribute is not read-only because of a synchro...
  463. $aReasons = array();
  464. $sSynchroIcon = '';
  465. if ($iFlags & OPT_ATT_SLAVE)
  466. {
  467. $iSynchroFlags = $this->GetSynchroReplicaFlags($sAttCode, $aReasons);
  468. $sSynchroIcon = "&nbsp;<img id=\"synchro_$sInputId\" src=\"../images/transp-lock.png\" style=\"vertical-align:middle\"/>";
  469. $sTip = '';
  470. foreach($aReasons as $aRow)
  471. {
  472. $sTip .= "<p>Synchronized with {$aRow['name']} - {$aRow['description']}</p>";
  473. }
  474. $oPage->add_ready_script("$('#synchro_$sInputId').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );");
  475. }
  476. // Attribute is read-only
  477. $sHTMLValue = "<span id=\"field_{$sInputId}\">".$this->GetAsHTML($sAttCode);
  478. $sHTMLValue .= '<input type="hidden" id="'.$sInputId.'" name="attr_'.$sPrefix.$sAttCode.'" value="'.htmlentities($this->Get($sAttCode), ENT_QUOTES, 'UTF-8').'"/></span>';
  479. $aFieldsMap[$sAttCode] = $sInputId;
  480. $sComments = $sSynchroIcon;
  481. }
  482. else
  483. {
  484. $sValue = $this->Get($sAttCode);
  485. $sDisplayValue = $this->GetEditValue($sAttCode);
  486. $aArgs = array('this' => $this, 'formPrefix' => $sPrefix);
  487. $sHTMLValue = "<span id=\"field_{$sInputId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).'</span>';
  488. $aFieldsMap[$sAttCode] = $sInputId;
  489. }
  490. $val = array('label' => '<span title="'.$oAttDef->GetDescription().'">'.$oAttDef->GetLabel().'</span>', 'value' => $sHTMLValue, 'comments' => $sComments, 'infos' => $sInfos);
  491. }
  492. }
  493. }
  494. else
  495. {
  496. $val = array('label' => '<span title="'.$oAttDef->GetDescription().'">'.$oAttDef->GetLabel().'</span>', 'value' => $this->GetAsHTML($sAttCode), 'comments' => $sComments, 'infos' => $sInfos);
  497. }
  498. }
  499. else
  500. {
  501. $val = null; // Skip this field
  502. }
  503. }
  504. else
  505. {
  506. // !bEditMode
  507. $val = $this->GetFieldAsHtml($sClass, $sAttCode, $sStateAttCode);
  508. }
  509. if ($val != null)
  510. {
  511. // The field is visible, add it to the current column
  512. $aDetails[$sTab][$sColIndex][] = $val;
  513. $iInputId++;
  514. }
  515. }
  516. }
  517. if (!empty($sPreviousLabel))
  518. {
  519. $oPage->add('<fieldset>');
  520. $oPage->add('<legend>'.Dict::S($sFieldsetName).'</legend>');
  521. }
  522. $oPage->Details($aDetails[$sTab][$sColIndex]);
  523. if (!empty($sPreviousLabel))
  524. {
  525. $oPage->add('</fieldset>');
  526. }
  527. $oPage->add('</td>');
  528. }
  529. $oPage->add('</tr></table>');
  530. }
  531. return $aFieldsMap;
  532. }
  533. function DisplayDetails(WebPage $oPage, $bEditMode = false)
  534. {
  535. $sTemplate = Utils::ReadFromFile(MetaModel::GetDisplayTemplate(get_class($this)));
  536. if (!empty($sTemplate))
  537. {
  538. $oTemplate = new DisplayTemplate($sTemplate);
  539. // Note: to preserve backward compatibility with home-made templates, the placeholder '$pkey$' has been preserved
  540. // but the preferred method is to use '$id$'
  541. $oTemplate->Render($oPage, array('class_name'=> MetaModel::GetName(get_class($this)),'class'=> get_class($this), 'pkey'=> $this->GetKey(), 'id'=> $this->GetKey(), 'name' => $this->GetName()));
  542. }
  543. else
  544. {
  545. // Object's details
  546. // template not found display the object using the *old style*
  547. $this->DisplayBareHeader($oPage, $bEditMode);
  548. $oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
  549. $oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
  550. $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
  551. $this->DisplayBareProperties($oPage, $bEditMode);
  552. $this->DisplayBareRelations($oPage, $bEditMode);
  553. $oPage->SetCurrentTab(Dict::S('UI:HistoryTab'));
  554. $this->DisplayBareHistory($oPage, $bEditMode);
  555. }
  556. }
  557. function DisplayPreview(WebPage $oPage)
  558. {
  559. $aDetails = array();
  560. $sClass = get_class($this);
  561. $aList = MetaModel::GetZListItems($sClass, 'preview');
  562. foreach($aList as $sAttCode)
  563. {
  564. $aDetails[] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'value' =>$this->GetAsHTML($sAttCode));
  565. }
  566. $oPage->details($aDetails);
  567. }
  568. public static function DisplaySet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  569. {
  570. $oPage->add(self::GetDisplaySet($oPage, $oSet, $aExtraParams));
  571. }
  572. /**
  573. * Get the HTML fragment corresponding to the display of a table representing a set of objects
  574. * @param WebPage $oPage The page object is used for out-of-band information (mostly scripts) output
  575. * @param CMDBObjectSet The set of objects to display
  576. * @param Hash $aExtraParams Some extra configuration parameters to tweak the behavior of the display
  577. * @return String The HTML fragment representing the table of objects
  578. */
  579. public static function GetDisplaySet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  580. {
  581. if (empty($aExtraParams['currentId']))
  582. {
  583. $iListId = $oPage->GetUniqueId(); // Works only if not in an Ajax page !!
  584. }
  585. else
  586. {
  587. $iListId = $aExtraParams['currentId'];
  588. }
  589. // Initialize and check the parameters
  590. $bViewLink = isset($aExtraParams['view_link']) ? $aExtraParams['view_link'] : true;
  591. $sLinkageAttribute = isset($aExtraParams['link_attr']) ? $aExtraParams['link_attr'] : '';
  592. $iLinkedObjectId = isset($aExtraParams['object_id']) ? $aExtraParams['object_id'] : 0;
  593. $sTargetAttr = isset($aExtraParams['target_attr']) ? $aExtraParams['target_attr'] : '';
  594. if (!empty($sLinkageAttribute))
  595. {
  596. if($iLinkedObjectId == 0)
  597. {
  598. // if 'links' mode is requested the id of the object to link to must be specified
  599. throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_object_id'));
  600. }
  601. if($sTargetAttr == '')
  602. {
  603. // if 'links' mode is requested the d of the object to link to must be specified
  604. throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_target_attr'));
  605. }
  606. }
  607. $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true;
  608. $bTruncated = isset($aExtraParams['truncated']) ? $aExtraParams['truncated'] == true : true;
  609. $bSelectMode = isset($aExtraParams['selection_mode']) ? $aExtraParams['selection_mode'] == true : false;
  610. $bSingleSelectMode = isset($aExtraParams['selection_type']) ? ($aExtraParams['selection_type'] == 'single') : false;
  611. $aExtraFields = isset($aExtraParams['extra_fields']) ? explode(',', trim($aExtraParams['extra_fields'])) : array();
  612. $sHtml = '';
  613. $oAppContext = new ApplicationContext();
  614. $sClassName = $oSet->GetFilter()->GetClass();
  615. $aAttribs = array();
  616. $sZListName = isset($aExtraParams['zlist']) ? ($aExtraParams['zlist']) : 'list';
  617. if ($sZListName !== false)
  618. {
  619. $aList = self::FlattenZList(MetaModel::GetZListItems($sClassName, $sZListName));
  620. $aList = array_merge($aList, $aExtraFields);
  621. }
  622. else
  623. {
  624. $aList = $aExtraFields;
  625. }
  626. // Filter the list to removed linked set since we are not able to display them here
  627. foreach($aList as $index => $sAttCode)
  628. {
  629. $oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
  630. if ($oAttDef instanceof AttributeLinkedSet)
  631. {
  632. // Removed from the display list
  633. unset($aList[$index]);
  634. }
  635. }
  636. // Load only the requested columns
  637. $sClassAlias = $oSet->GetFilter()->GetClassAlias();
  638. $oSet->OptimizeColumnLoad(array($sClassAlias => $aList));
  639. if (!empty($sLinkageAttribute))
  640. {
  641. // The set to display is in fact a set of links between the object specified in the $sLinkageAttribute
  642. // and other objects...
  643. // The display will then group all the attributes related to the link itself:
  644. // | Link_attr1 | link_attr2 | ... || Object_attr1 | Object_attr2 | Object_attr3 | .. | Object_attr_n |
  645. $aDisplayList = array();
  646. $aAttDefs = MetaModel::ListAttributeDefs($sClassName);
  647. assert(isset($aAttDefs[$sLinkageAttribute]));
  648. $oAttDef = $aAttDefs[$sLinkageAttribute];
  649. assert($oAttDef->IsExternalKey());
  650. // First display all the attributes specific to the link record
  651. foreach($aList as $sLinkAttCode)
  652. {
  653. $oLinkAttDef = $aAttDefs[$sLinkAttCode];
  654. if ( (!$oLinkAttDef->IsExternalKey()) && (!$oLinkAttDef->IsExternalField()) )
  655. {
  656. $aDisplayList[] = $sLinkAttCode;
  657. }
  658. }
  659. // Then display all the attributes neither specific to the link record nor to the 'linkage' object (because the latter are constant)
  660. foreach($aList as $sLinkAttCode)
  661. {
  662. $oLinkAttDef = $aAttDefs[$sLinkAttCode];
  663. if (($oLinkAttDef->IsExternalKey() && ($sLinkAttCode != $sLinkageAttribute))
  664. || ($oLinkAttDef->IsExternalField() && ($oLinkAttDef->GetKeyAttCode()!=$sLinkageAttribute)) )
  665. {
  666. $aDisplayList[] = $sLinkAttCode;
  667. }
  668. }
  669. // First display all the attributes specific to the link
  670. // Then display all the attributes linked to the other end of the relationship
  671. $aList = $aDisplayList;
  672. }
  673. if ($bSelectMode)
  674. {
  675. if (!$bSingleSelectMode)
  676. {
  677. $aAttribs['form::select'] = array('label' => "<input type=\"checkbox\" onClick=\"CheckAll('.selectList{$iListId}:not(:disabled)', this.checked);\" class=\"checkAll\"></input>", 'description' => Dict::S('UI:SelectAllToggle+'));
  678. }
  679. else
  680. {
  681. $aAttribs['form::select'] = array('label' => "", 'description' => '');
  682. }
  683. }
  684. if ($bViewLink)
  685. {
  686. $aAttribs['key'] = array('label' => MetaModel::GetName($sClassName), 'description' => '');
  687. }
  688. foreach($aList as $sAttCode)
  689. {
  690. $aAttribs[$sAttCode] = array('label' => MetaModel::GetLabel($sClassName, $sAttCode), 'description' => MetaModel::GetDescription($sClassName, $sAttCode));
  691. }
  692. $aValues = array();
  693. $bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true;
  694. $iMaxObjects = -1;
  695. //if ($bDisplayLimit && $bTruncated)
  696. //{
  697. if ($bDisplayLimit && ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit()))
  698. {
  699. $iMaxObjects = MetaModel::GetConfig()->GetMinDisplayLimit();
  700. $oSet->SetLimit($iMaxObjects);
  701. }
  702. //}
  703. $oSet->Seek(0);
  704. while (($oObj = $oSet->Fetch()) && ($iMaxObjects != 0))
  705. {
  706. $aRow = array();
  707. $sHilightClass = $oObj->GetHilightClass();
  708. if ($sHilightClass != '')
  709. {
  710. $aRow['@class'] = $sHilightClass;
  711. }
  712. if ($bViewLink)
  713. {
  714. $aRow['key'] = $oObj->GetHyperLink();
  715. }
  716. if ($bSelectMode)
  717. {
  718. if (array_key_exists('selection_enabled', $aExtraParams) && isset($aExtraParams['selection_enabled'][$oObj->GetKey()]))
  719. {
  720. $sDisabled = ($aExtraParams['selection_enabled'][$oObj->GetKey()]) ? '' : ' disabled="disabled"';
  721. }
  722. else
  723. {
  724. $sDisabled = '';
  725. }
  726. if ($bSingleSelectMode)
  727. {
  728. $aRow['form::select'] = "<input type=\"radio\" $sDisabled class=\"selectList{$iListId}\" name=\"selectObject\" value=\"".$oObj->GetKey()."\"></input>";
  729. }
  730. else
  731. {
  732. $aRow['form::select'] = "<input type=\"checkBox\" $sDisabled class=\"selectList{$iListId}\" name=\"selectObject[]\" value=\"".$oObj->GetKey()."\"></input>";
  733. }
  734. }
  735. foreach($aList as $sAttCode)
  736. {
  737. $aRow[$sAttCode] = $oObj->GetAsHTML($sAttCode);
  738. }
  739. $aValues[] = $aRow;
  740. $iMaxObjects--;
  741. }
  742. $sHtml .= '<table class="listContainer">';
  743. $sColspan = '';
  744. // if (isset($aExtraParams['block_id']))
  745. // {
  746. // $divId = $aExtraParams['block_id'];
  747. // }
  748. // else
  749. // {
  750. // $divId = 'missingblockid';
  751. // }
  752. $sFilter = $oSet->GetFilter()->serialize();
  753. $iMinDisplayLimit = MetaModel::GetConfig()->GetMinDisplayLimit();
  754. $sCollapsedLabel = Dict::Format('UI:TruncatedResults', $iMinDisplayLimit, $oSet->Count());
  755. $sLinkLabel = Dict::S('UI:DisplayAll');
  756. foreach($oSet->GetFilter()->GetInternalParams() as $sName => $sValue)
  757. {
  758. $aExtraParams['query_params'][$sName] = $sValue;
  759. }
  760. if ($bDisplayMenu)
  761. {
  762. $oMenuBlock = new MenuBlock($oSet->GetFilter());
  763. $sColspan = 'colspan="2"';
  764. $aMenuExtraParams = $aExtraParams;
  765. if (!empty($sLinkageAttribute))
  766. {
  767. //$aMenuExtraParams['linkage'] = $sLinkageAttribute;
  768. $aMenuExtraParams = $aExtraParams;
  769. }
  770. $sHtml .= $oMenuBlock->GetRenderContent($oPage, $aMenuExtraParams, $iListId);
  771. $sHtml .= '</td></tr>';
  772. }
  773. $sHtml .= "<tr><td $sColspan>";
  774. $sHtml .= $oPage->GetTable($aAttribs, $aValues);
  775. $sHtml .= '</td></tr>';
  776. $sHtml .= '</table>';
  777. $iCount = $oSet->Count();
  778. if ($bSelectMode)
  779. {
  780. $sHeader = Dict::Format('UI:Pagination:HeaderSelection', '<span id="total">'.$iCount.'</span>', '<span class="selectedCount">0</span>');
  781. }
  782. else
  783. {
  784. $sHeader = Dict::Format('UI:Pagination:HeaderNoSelection', '<span id="total">'.$iCount.'</span>');
  785. }
  786. if ($bDisplayLimit && ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit()))
  787. {
  788. $sCombo = '<select class="pagesize">';
  789. for($iPage = 1; $iPage < 5; $iPage++)
  790. {
  791. $sSelected = '';
  792. if ($iPage == 1)
  793. {
  794. $sSelected = 'selected="selected"';
  795. }
  796. $iNbItems = $iPage * MetaModel::GetConfig()->GetMinDisplayLimit();
  797. $sCombo .= "<option $sSelected value=\"$iNbItems\">$iNbItems</option>";
  798. }
  799. $sCombo .= "<option $sSelected value=\"-1\">".Dict::S('UI:Pagination:All')."</option>";
  800. $sCombo .= '</select>';
  801. $sPages = Dict::S('UI:Pagination:PagesLabel');
  802. $sPageSizeCombo = Dict::Format('UI:Pagination:PageSize', $sCombo);
  803. $sHtml =
  804. <<<EOF
  805. <div id="pager{$iListId}" class="pager">
  806. <p>$sHeader</p>
  807. <p><table class="pagination"><tr><td>$sPages</td><td><img src="../images/first.png" class="first"/></td>
  808. <td><img src="../images/prev.png" class="prev"/></td>
  809. <td><span id="index"></span></td>
  810. <td><img src="../images/next.png" class="next"/></td>
  811. <td><img src="../images/last.png" class="last"/></td>
  812. <td>$sPageSizeCombo</td>
  813. <td><span id="loading">&nbsp;</span></td>
  814. </tr>
  815. </table>
  816. <input type="hidden" name="selectionMode" value="positive"></input>
  817. </div>
  818. EOF
  819. .$sHtml;
  820. $aArgs = $oSet->GetArgs();
  821. $sExtraParams = addslashes(str_replace('"', "'", json_encode(array_merge($aExtraParams, $aArgs)))); // JSON encode, change the style of the quotes and escape them
  822. $sSelectMode = '';
  823. $sHeaders = '';
  824. if ($bSelectMode)
  825. {
  826. $sSelectMode = $bSingleSelectMode ? 'single' : 'multiple';
  827. $sHeaders = 'headers: { 0: {sorter: false}},';
  828. }
  829. $sDisplayKey = ($bViewLink) ? 'true' : 'false';
  830. $sDisplayList = json_encode($aList);
  831. $sCssCount = isset($aExtraParams['cssCount']) ? ", cssCount: '{$aExtraParams['cssCount']}'" : '';
  832. $iPageSize = MetaModel::GetConfig()->GetMinDisplayLimit();
  833. $oPage->add_ready_script("$('#{$iListId} table.listResults').tablesorter( { $sHeaders widgets: ['myZebra', 'truncatedList']} ).tablesorterPager({container: $('#pager{$iListId}'), totalRows:$iCount, size: $iPageSize, filter: '$sFilter', extra_params: '$sExtraParams', select_mode: '$sSelectMode', displayKey: $sDisplayKey, displayList: $sDisplayList $sCssCount});\n");
  834. }
  835. else
  836. {
  837. $sHtml =
  838. <<<EOF
  839. <div id="pager{$iListId}" class="pager">
  840. <p>$sHeader</p>
  841. </div>
  842. EOF
  843. .$sHtml;
  844. $sHeaders = '';
  845. if ($bSelectMode)
  846. {
  847. $sHeaders = 'headers: { 0: {sorter: false}},';
  848. }
  849. $oPage->add_ready_script("$('#{$iListId} table.listResults').tableHover().tablesorter( { $sHeaders widgets: ['myZebra', 'truncatedList']} );\n");
  850. // Manage how we update the 'Ok/Add' buttons that depend on the number of selected items
  851. if (isset($aExtraParams['cssCount']))
  852. {
  853. $sCssCount = $aExtraParams['cssCount'];
  854. if ($bSingleSelectMode)
  855. {
  856. $sSelectSelector = ":radio[name^=selectObj]";
  857. }
  858. else
  859. {
  860. $sSelectSelector = ":checkbox[name^=selectObj]";
  861. }
  862. $oPage->add_ready_script(
  863. <<<EOF
  864. $('#{$iListId} table.listResults $sSelectSelector').change(function() {
  865. var c = $('{$sCssCount}');
  866. var v = $('#{$iListId} table.listResults $sSelectSelector:checked').length;
  867. c.val(v);
  868. $('#{$iListId} .selectedCount').text(v);
  869. c.trigger('change');
  870. });
  871. EOF
  872. );
  873. }
  874. }
  875. return $sHtml;
  876. }
  877. public static function GetDisplayExtendedSet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  878. {
  879. static $iListId = 0;
  880. $iListId++;
  881. $aList = array();
  882. // Initialize and check the parameters
  883. $bViewLink = isset($aExtraParams['view_link']) ? $aExtraParams['view_link'] : true;
  884. $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true;
  885. // Check if there is a list of aliases to limit the display to...
  886. $aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', $aExtraParams['display_aliases']) : array();
  887. $sHtml = '';
  888. $oAppContext = new ApplicationContext();
  889. $aClasses = $oSet->GetFilter()->GetSelectedClasses();
  890. $aAuthorizedClasses = array();
  891. foreach($aClasses as $sAlias => $sClassName)
  892. {
  893. if ( (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS)) &&
  894. ( (count($aDisplayAliases) == 0) || (in_array($sAlias, $aDisplayAliases))) )
  895. {
  896. $aAuthorizedClasses[$sAlias] = $sClassName;
  897. }
  898. }
  899. $aAttribs = array();
  900. foreach($aAuthorizedClasses as $sAlias => $sClassName) // TO DO: check if the user has enough rights to view the classes of the list...
  901. {
  902. $aList[$sClassName] = MetaModel::GetZListItems($sClassName, 'list');
  903. if ($bViewLink)
  904. {
  905. $aAttribs['key_'.$sAlias] = array('label' => MetaModel::GetName($sClassName), 'description' => '');
  906. }
  907. foreach($aList[$sClassName] as $sAttCode)
  908. {
  909. $aAttribs[$sAttCode.'_'.$sAlias] = array('label' => MetaModel::GetLabel($sClassName, $sAttCode), 'description' => MetaModel::GetDescription($sClassName, $sAttCode));
  910. }
  911. }
  912. // Load only the requested columns
  913. $aAttToLoad = array(); // attributes to load
  914. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  915. {
  916. foreach($aList[$sClassName] as $sAttCode)
  917. {
  918. $aAttToLoad[$sAlias][] = $sAttCode;
  919. }
  920. }
  921. $oSet->OptimizeColumnLoad($aAttToLoad);
  922. $aValues = array();
  923. $oSet->Seek(0);
  924. $bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true;
  925. $iMaxObjects = -1;
  926. if ($bDisplayLimit)
  927. {
  928. if ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit())
  929. {
  930. $iMaxObjects = MetaModel::GetConfig()->GetMinDisplayLimit();
  931. }
  932. }
  933. while (($aObjects = $oSet->FetchAssoc()) && ($iMaxObjects != 0))
  934. {
  935. $aRow = array();
  936. foreach($aAuthorizedClasses as $sAlias => $sClassName) // TO DO: check if the user has enough rights to view the classes of the list...
  937. {
  938. if ($bViewLink)
  939. {
  940. if (is_null($aObjects[$sAlias]))
  941. {
  942. $aRow['key_'.$sAlias] = '';
  943. }
  944. else
  945. {
  946. $aRow['key_'.$sAlias] = $aObjects[$sAlias]->GetHyperLink();
  947. }
  948. }
  949. foreach($aList[$sClassName] as $sAttCode)
  950. {
  951. if (is_null($aObjects[$sAlias]))
  952. {
  953. $aRow[$sAttCode.'_'.$sAlias] = '';
  954. }
  955. else
  956. {
  957. $aRow[$sAttCode.'_'.$sAlias] = $aObjects[$sAlias]->GetAsHTML($sAttCode);
  958. }
  959. }
  960. }
  961. $aValues[] = $aRow;
  962. $iMaxObjects--;
  963. }
  964. $sHtml .= '<table class="listContainer">';
  965. $sColspan = '';
  966. if ($bDisplayMenu)
  967. {
  968. $oMenuBlock = new MenuBlock($oSet->GetFilter());
  969. $sColspan = 'colspan="2"';
  970. $aMenuExtraParams = $aExtraParams;
  971. if (!empty($sLinkageAttribute))
  972. {
  973. $aMenuExtraParams = $aExtraParams;
  974. }
  975. if ($bDisplayLimit && ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit()))
  976. {
  977. // list truncated
  978. $divId = $aExtraParams['block_id'];
  979. $sFilter = $oSet->GetFilter()->serialize();
  980. $aExtraParams['display_limit'] = false; // To expand the full list
  981. $sExtraParams = addslashes(str_replace('"', "'", json_encode($aExtraParams))); // JSON encode, change the style of the quotes and escape them
  982. $sHtml .= '<tr class="containerHeader"><td>'.Dict::Format('UI:TruncatedResults', MetaModel::GetConfig()->GetMinDisplayLimit(), $oSet->Count()).'&nbsp;&nbsp;<span style=\"cursor:pointer;\" onClick="Javascript:ReloadTruncatedList(\''.$divId.'\', \''.$sFilter.'\', \''.$sExtraParams.'\');">'.Dict::S('UI:DisplayAll').'</span></td><td>';
  983. $oPage->add_ready_script("$('#{$divId} table.listResults').addClass('truncated');");
  984. $oPage->add_ready_script("$('#{$divId} table.listResults tr:last td').addClass('truncated');");
  985. }
  986. else
  987. {
  988. // Full list
  989. $sHtml .= '<tr class="containerHeader"><td>&nbsp;'.Dict::Format('UI:CountOfResults', $oSet->Count()).'</td><td>';
  990. }
  991. $sHtml .= $oMenuBlock->GetRenderContent($oPage, $aMenuExtraParams, $aMenuExtraParams['currentId']);
  992. $sHtml .= '</td></tr>';
  993. }
  994. $sHtml .= "<tr><td $sColspan>";
  995. $sHtml .= $oPage->GetTable($aAttribs, $aValues);
  996. $sHtml .= '</td></tr>';
  997. $sHtml .= '</table>';
  998. return $sHtml;
  999. }
  1000. static function DisplaySetAsCSV(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array())
  1001. {
  1002. $oPage->add(self::GetSetAsCSV($oSet, $aParams));
  1003. }
  1004. static function GetSetAsCSV(DBObjectSet $oSet, $aParams = array())
  1005. {
  1006. $sSeparator = isset($aParams['separator']) ? $aParams['separator'] : ','; // default separator is comma
  1007. $sTextQualifier = isset($aParams['text_qualifier']) ? $aParams['text_qualifier'] : '"'; // default text qualifier is double quote
  1008. $aFields = null;
  1009. if (isset($aParams['fields']) && (strlen($aParams['fields']) > 0))
  1010. {
  1011. $aFields = explode(',', $aParams['fields']);
  1012. }
  1013. $aList = array();
  1014. $oAppContext = new ApplicationContext();
  1015. $aClasses = $oSet->GetFilter()->GetSelectedClasses();
  1016. $aAuthorizedClasses = array();
  1017. foreach($aClasses as $sAlias => $sClassName)
  1018. {
  1019. if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS))
  1020. {
  1021. $aAuthorizedClasses[$sAlias] = $sClassName;
  1022. }
  1023. }
  1024. $aAttribs = array();
  1025. $aHeader = array();
  1026. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  1027. {
  1028. foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode => $oAttDef)
  1029. {
  1030. if (is_null($aFields) || (count($aFields) == 0))
  1031. {
  1032. // Standard list of attributes (no link sets)
  1033. if ($oAttDef->IsScalar() && ($oAttDef->IsWritable() || $oAttDef->IsExternalField()))
  1034. {
  1035. $aList[$sClassName][$sAttCode] = $oAttDef;
  1036. }
  1037. }
  1038. else
  1039. {
  1040. // User defined list of attributes
  1041. if (in_array($sAttCode, $aFields))
  1042. {
  1043. $aList[$sClassName][$sAttCode] = $oAttDef;
  1044. }
  1045. }
  1046. }
  1047. $aHeader[] = 'id';
  1048. foreach($aList[$sClassName] as $sAttCode => $oAttDef)
  1049. {
  1050. $sStar = '';
  1051. if ($oAttDef->IsExternalField())
  1052. {
  1053. $sExtKeyLabel = MetaModel::GetLabel($sClassName, $oAttDef->GetKeyAttCode());
  1054. $oExtKeyAttDef = MetaModel::GetAttributeDef($sClassName, $oAttDef->GetKeyAttCode());
  1055. if (!$oExtKeyAttDef->IsNullAllowed() && isset($aParams['showMandatoryFields']))
  1056. {
  1057. $sStar = '*';
  1058. }
  1059. $sRemoteAttLabel = MetaModel::GetLabel($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
  1060. $oTargetAttDef = MetaModel::GetAttributeDef($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
  1061. $sSuffix = '';
  1062. if ($oTargetAttDef->IsExternalKey())
  1063. {
  1064. $sSuffix = '->id';
  1065. }
  1066. $aHeader[] = $sExtKeyLabel.'->'.$sRemoteAttLabel.$sSuffix.$sStar;
  1067. }
  1068. else
  1069. {
  1070. if (!$oAttDef->IsNullAllowed() && isset($aParams['showMandatoryFields']))
  1071. {
  1072. $sStar = '*';
  1073. }
  1074. $aHeader[] = MetaModel::GetLabel($sClassName, $sAttCode).$sStar;
  1075. }
  1076. }
  1077. }
  1078. $sHtml = implode($sSeparator, $aHeader)."\n";
  1079. $oSet->Seek(0);
  1080. while ($aObjects = $oSet->FetchAssoc())
  1081. {
  1082. $aRow = array();
  1083. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  1084. {
  1085. $oObj = $aObjects[$sAlias];
  1086. if (is_null($oObj))
  1087. {
  1088. $aRow[] = '';
  1089. }
  1090. else
  1091. {
  1092. $aRow[] = $oObj->GetKey();
  1093. }
  1094. foreach($aList[$sClassName] as $sAttCode => $oAttDef)
  1095. {
  1096. if (is_null($oObj))
  1097. {
  1098. $aRow[] = '';
  1099. }
  1100. else
  1101. {
  1102. $aRow[] = $oObj->GetAsCSV($sAttCode, $sSeparator, $sTextQualifier);
  1103. }
  1104. }
  1105. }
  1106. $sHtml .= implode($sSeparator, $aRow)."\n";
  1107. }
  1108. return $sHtml;
  1109. }
  1110. static function DisplaySetAsHTMLSpreadsheet(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array())
  1111. {
  1112. $oPage->add(self::GetSetAsHTMLSpreadsheet($oSet, $aParams));
  1113. }
  1114. static function GetSetAsHTMLSpreadsheet(DBObjectSet $oSet, $aParams = array())
  1115. {
  1116. $aFields = null;
  1117. if (isset($aParams['fields']) && (strlen($aParams['fields']) > 0))
  1118. {
  1119. $aFields = explode(',', $aParams['fields']);
  1120. }
  1121. $aList = array();
  1122. $oAppContext = new ApplicationContext();
  1123. $aClasses = $oSet->GetFilter()->GetSelectedClasses();
  1124. $aAuthorizedClasses = array();
  1125. foreach($aClasses as $sAlias => $sClassName)
  1126. {
  1127. if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS))
  1128. {
  1129. $aAuthorizedClasses[$sAlias] = $sClassName;
  1130. }
  1131. }
  1132. $aAttribs = array();
  1133. $aHeader = array();
  1134. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  1135. {
  1136. foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode => $oAttDef)
  1137. {
  1138. if (is_null($aFields) || (count($aFields) == 0))
  1139. {
  1140. // Standard list of attributes (no link sets)
  1141. if ($oAttDef->IsScalar() && ($oAttDef->IsWritable() || $oAttDef->IsExternalField()))
  1142. {
  1143. $aList[$sClassName][$sAttCode] = $oAttDef;
  1144. }
  1145. }
  1146. else
  1147. {
  1148. // User defined list of attributes
  1149. if (in_array($sAttCode, $aFields))
  1150. {
  1151. $aList[$sClassName][$sAttCode] = $oAttDef;
  1152. }
  1153. }
  1154. }
  1155. $aHeader[] = 'id';
  1156. foreach($aList[$sClassName] as $sAttCode => $oAttDef)
  1157. {
  1158. $sStar = '';
  1159. if ($oAttDef->IsExternalField())
  1160. {
  1161. $sExtKeyLabel = MetaModel::GetLabel($sClassName, $oAttDef->GetKeyAttCode());
  1162. $oExtKeyAttDef = MetaModel::GetAttributeDef($sClassName, $oAttDef->GetKeyAttCode());
  1163. if (!$oExtKeyAttDef->IsNullAllowed() && isset($aParams['showMandatoryFields']))
  1164. {
  1165. $sStar = '*';
  1166. }
  1167. $sRemoteAttLabel = MetaModel::GetLabel($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
  1168. $oTargetAttDef = MetaModel::GetAttributeDef($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
  1169. $sSuffix = '';
  1170. if ($oTargetAttDef->IsExternalKey())
  1171. {
  1172. $sSuffix = '->id';
  1173. }
  1174. $sColLabel = $sExtKeyLabel.'->'.$sRemoteAttLabel.$sSuffix.$sStar;
  1175. }
  1176. else
  1177. {
  1178. if (!$oAttDef->IsNullAllowed() && isset($aParams['showMandatoryFields']))
  1179. {
  1180. $sStar = '*';
  1181. }
  1182. $sColLabel = MetaModel::GetLabel($sClassName, $sAttCode).$sStar;
  1183. }
  1184. $oFinalAttDef = $oAttDef->GetFinalAttDef();
  1185. if (get_class($oFinalAttDef) == 'AttributeDateTime')
  1186. {
  1187. $aHeader[] = $sColLabel.' ('.Dict::S('UI:SplitDateTime-Date').')';
  1188. $aHeader[] = $sColLabel.' ('.Dict::S('UI:SplitDateTime-Time').')';
  1189. }
  1190. else
  1191. {
  1192. $aHeader[] = $sColLabel;
  1193. }
  1194. }
  1195. }
  1196. $sHtml = "<table border=\"1\">\n";
  1197. $sHtml .= "<tr>\n";
  1198. $sHtml .= "<td>".implode("</td><td>", $aHeader)."</td>\n";
  1199. $sHtml .= "</tr>\n";
  1200. $oSet->Seek(0);
  1201. while ($aObjects = $oSet->FetchAssoc())
  1202. {
  1203. $aRow = array();
  1204. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  1205. {
  1206. $oObj = $aObjects[$sAlias];
  1207. if (is_null($oObj))
  1208. {
  1209. $aRow[] = '';
  1210. }
  1211. else
  1212. {
  1213. $aRow[] = '<td>'.$oObj->GetKey().'</td>';
  1214. }
  1215. foreach($aList[$sClassName] as $sAttCode => $oAttDef)
  1216. {
  1217. if (is_null($oObj))
  1218. {
  1219. $aRow[] = '';
  1220. }
  1221. else
  1222. {
  1223. $oFinalAttDef = $oAttDef->GetFinalAttDef();
  1224. if (get_class($oFinalAttDef) == 'AttributeDateTime')
  1225. {
  1226. $iDate = AttributeDateTime::GetAsUnixSeconds($oObj->Get($sAttCode));
  1227. $aRow[] = '<td>'.date('Y-m-d', $iDate).'</td>';
  1228. $aRow[] = '<td>'.date('h:i:s', $iDate).'</td>';
  1229. }
  1230. else
  1231. {
  1232. $aRow[] = '<td>'.(string) $oObj->Get($sAttCode).'</td>';
  1233. }
  1234. }
  1235. }
  1236. }
  1237. $sHtml .= implode("\n", $aRow);
  1238. $sHtml .= "</tr>\n";
  1239. }
  1240. $sHtml .= "</table>\n";
  1241. return $sHtml;
  1242. }
  1243. static function DisplaySetAsXML(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array())
  1244. {
  1245. $oAppContext = new ApplicationContext();
  1246. $aClasses = $oSet->GetFilter()->GetSelectedClasses();
  1247. $aAuthorizedClasses = array();
  1248. foreach($aClasses as $sAlias => $sClassName)
  1249. {
  1250. if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS))
  1251. {
  1252. $aAuthorizedClasses[$sAlias] = $sClassName;
  1253. }
  1254. }
  1255. $aAttribs = array();
  1256. $aList = array();
  1257. $aList[$sClassName] = MetaModel::GetZListItems($sClassName, 'details');
  1258. $oPage->add("<Set>\n");
  1259. $oSet->Seek(0);
  1260. while ($aObjects = $oSet->FetchAssoc())
  1261. {
  1262. if (count($aAuthorizedClasses) > 1)
  1263. {
  1264. $oPage->add("<Row>\n");
  1265. }
  1266. foreach($aAuthorizedClasses as $sAlias => $sClassName)
  1267. {
  1268. $oObj = $aObjects[$sAlias];
  1269. if (is_null($oObj))
  1270. {
  1271. $oPage->add("<$sClassName alias=\"$sAlias\" id=\"null\">\n");
  1272. }
  1273. else
  1274. {
  1275. $sClassName = get_class($oObj);
  1276. $oPage->add("<$sClassName alias=\"$sAlias\" id=\"".$oObj->GetKey()."\">\n");
  1277. }
  1278. foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode=>$oAttDef)
  1279. {
  1280. if (is_null($oObj))
  1281. {
  1282. $oPage->add("<$sAttCode>null</$sAttCode>\n");
  1283. }
  1284. else
  1285. {
  1286. if ($oAttDef->IsWritable())
  1287. {
  1288. $sValue = $oObj->GetAsXML($sAttCode);
  1289. $oPage->add("<$sAttCode>$sValue</$sAttCode>\n");
  1290. }
  1291. }
  1292. }
  1293. $oPage->add("</$sClassName>\n");
  1294. }
  1295. if (count($aAuthorizedClasses) > 1)
  1296. {
  1297. $oPage->add("</Row>\n");
  1298. }
  1299. }
  1300. $oPage->add("</Set>\n");
  1301. }
  1302. public static function DisplaySearchForm(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  1303. {
  1304. $oPage->add(self::GetSearchForm($oPage, $oSet, $aExtraParams));
  1305. }
  1306. public static function GetSearchForm(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
  1307. {
  1308. static $iSearchFormId = 0;
  1309. $oAppContext = new ApplicationContext();
  1310. $sHtml = '';
  1311. $numCols=4;
  1312. $sClassName = $oSet->GetFilter()->GetClass();
  1313. // Romain: temporarily removed the tab "OQL query" because it was not finalized
  1314. // (especially when used to add a link)
  1315. /*
  1316. $sHtml .= "<div class=\"mini_tabs\" id=\"mini_tabs{$iSearchFormId}\"><ul>
  1317. <li><a href=\"#\" onClick=\"$('div.mini_tab{$iSearchFormId}').toggle();$('#mini_tabs{$iSearchFormId} ul li a').toggleClass('selected');\">".Dict::S('UI:OQLQueryTab')."</a></li>
  1318. <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>
  1319. </ul></div>\n";
  1320. */
  1321. // Simple search form
  1322. if (isset($aExtraParams['currentId']))
  1323. {
  1324. $sSearchFormId = $aExtraParams['currentId'];
  1325. }
  1326. else
  1327. {
  1328. $iSearchFormId = $oPage->GetUniqueId();
  1329. $sSearchFormId = 'SimpleSearchForm'.$iSearchFormId;
  1330. $sHtml .= "<div id=\"ds_$sSearchFormId\" class=\"mini_tab{$iSearchFormId}\">\n";
  1331. }
  1332. // Check if the current class has some sub-classes
  1333. if (isset($aExtraParams['baseClass']))
  1334. {
  1335. $sRootClass = $aExtraParams['baseClass'];
  1336. }
  1337. else
  1338. {
  1339. $sRootClass = $sClassName;
  1340. }
  1341. $aSubClasses = MetaModel::GetSubclasses($sRootClass);
  1342. if (count($aSubClasses) > 0)
  1343. {
  1344. $aOptions = array();
  1345. $aOptions[MetaModel::GetName($sRootClass)] = "<option value=\"$sRootClass\">".MetaModel::GetName($sRootClass)."</options>\n";
  1346. foreach($aSubClasses as $sSubclassName)
  1347. {
  1348. $aOptions[MetaModel::GetName($sSubclassName)] = "<option value=\"$sSubclassName\">".MetaModel::GetName($sSubclassName)."</options>\n";
  1349. }
  1350. $aOptions[MetaModel::GetName($sClassName)] = "<option selected value=\"$sClassName\">".MetaModel::GetName($sClassName)."</options>\n";
  1351. ksort($aOptions);
  1352. $sContext = $oAppContext->GetForLink();
  1353. $sClassesCombo = "<select name=\"class\" onChange=\"ReloadSearchForm('$sSearchFormId', this.value, '$sRootClass', '$sContext')\">\n".implode('', $aOptions)."</select>\n";
  1354. }
  1355. else
  1356. {
  1357. $sClassesCombo = MetaModel::GetName($sClassName);
  1358. }
  1359. $oUnlimitedFilter = new DBObjectSearch($sClassName);
  1360. $sAction = (isset($aExtraParams['action'])) ? $aExtraParams['action'] : utils::GetAbsoluteUrlAppRoot().'pages/UI.php';
  1361. $sHtml .= "<form id=\"fs_{$sSearchFormId}\" action=\"{$sAction}\">\n"; // Don't use $_SERVER['SCRIPT_NAME'] since the form may be called asynchronously (from ajax.php)
  1362. $sHtml .= "<h2>".Dict::Format('UI:SearchFor_Class_Objects', $sClassesCombo)."</h2>\n";
  1363. $index = 0;
  1364. $sHtml .= "<p>\n";
  1365. $aFilterCriteria = $oSet->GetFilter()->GetCriteria();
  1366. $aMapCriteria = array();
  1367. foreach($aFilterCriteria as $aCriteria)
  1368. {
  1369. $aMapCriteria[$aCriteria['filtercode']][] = array('value' => $aCriteria['value'], 'opcode' => $aCriteria['opcode']);
  1370. }
  1371. $aList = MetaModel::GetZListItems($sClassName, 'standard_search');
  1372. $aConsts = $oSet->ListConstantFields(); // Some fields are constants based on the query/context
  1373. $sClassAlias = $oSet->GetFilter()->GetClassAlias();
  1374. foreach($aList as $sFilterCode)
  1375. {
  1376. //$oAppContext->Reset($sFilterCode); // Make sure the same parameter will not be passed twice
  1377. $sHtml .= '<span style="white-space: nowrap;padding:5px;display:inline-block;">';
  1378. $sFilterValue = isset($aConsts[$sClassAlias][$sFilterCode]) ? $aConsts[$sClassAlias][$sFilterCode] : '';
  1379. $sFilterValue = utils::ReadParam($sFilterCode, $sFilterValue, false, 'raw_data');
  1380. $sFilterOpCode = null; // Use the default 'loose' OpCode
  1381. if (empty($sFilterValue))
  1382. {
  1383. if (isset($aMapCriteria[$sFilterCode]))
  1384. {
  1385. if (count($aMapCriteria[$sFilterCode]) > 1)
  1386. {
  1387. $sFilterValue = Dict::S('UI:SearchValue:Mixed');
  1388. }
  1389. else
  1390. {
  1391. $sFilterValue = $aMapCriteria[$sFilterCode][0]['value'];
  1392. $sFilterOpCode = $aMapCriteria[$sFilterCode][0]['opcode'];
  1393. }
  1394. if ($sFilterCode != 'company')
  1395. {
  1396. $oUnlimitedFilter->AddCondition($sFilterCode, $sFilterValue, $sFilterOpCode);
  1397. }
  1398. }
  1399. }
  1400. $oAttDef = MetaModel::GetAttributeDef($sClassName, $sFilterCode);
  1401. if ($oAttDef->IsExternalKey())
  1402. {
  1403. $sTargetClass = $oAttDef->GetTargetClass();
  1404. $oAllowedValues = new DBObjectSet(new DBObjectSearch($sTargetClass));
  1405. $iFieldSize = $oAttDef->GetMaxSize();
  1406. $iMaxComboLength = $oAttDef->GetMaximumComboLength();
  1407. $sHtml .= "<label>".MetaModel::GetFilterLabel($sClassName, $sFilterCode).":</label>&nbsp;";
  1408. $aExtKeyParams = $aExtraParams;
  1409. $aExtKeyParams['iFieldSize'] = $oAttDef->GetMaxSize();
  1410. $aExtKeyParams['iMinChars'] = $oAttDef->GetMinAutoCompleteChars();
  1411. $sHtml .= UIExtKeyWidget::DisplayFromAttCode($oPage, $sFilterCode, $sClassName, $oAttDef->GetLabel(), $oAllowedValues, $sFilterValue, $sSearchFormId.'search_'.$sFilterCode, false, $sFilterCode, '', $aExtKeyParams, true);
  1412. }
  1413. else
  1414. {
  1415. $aAllowedValues = MetaModel::GetAllowedValues_flt($sClassName, $sFilterCode, $aExtraParams);
  1416. if (is_null($aAllowedValues))
  1417. {
  1418. // Any value is possible, display an input box
  1419. $sHtml .= "<label>".MetaModel::GetFilterLabel($sClassName, $sFilterCode).":</label>&nbsp;<input class=\"textSearch\" name=\"$sFilterCode\" value=\"$sFilterValue\"/>\n";
  1420. }
  1421. else
  1422. {
  1423. //Enum field, display a combo
  1424. $sValue = "<select name=\"$sFilterCode\">\n";
  1425. $sValue .= "<option value=\"\">".Dict::S('UI:SearchValue:Any')."</option>\n";
  1426. foreach($aAllowedValues as $key => $value)
  1427. {
  1428. if ($sFilterValue == $key)
  1429. {
  1430. $sSelected = ' selected';
  1431. }
  1432. else
  1433. {
  1434. $sSelected = '';
  1435. }
  1436. $sValue .= "<option value=\"$key\"$sSelected>$value</option>\n";
  1437. }
  1438. $sValue .= "</select>\n";
  1439. $sHtml .= "<label>".MetaModel::GetFilterLabel($sClassName, $sFilterCode).":</label>&nbsp;$sValue\n";
  1440. }
  1441. }
  1442. unset($aExtraParams[$sFilterCode]);
  1443. // Finally, add a tooltip if one is defined for this attribute definition
  1444. $sTip = $oAttDef->GetHelpOnSmartSearch();
  1445. if (strlen($sTip) > 0)
  1446. {
  1447. $sTip = addslashes($sTip);
  1448. $sTip = str_replace(array("\n", "\r"), " ", $sTip);
  1449. // :input does represent in form visible input (INPUT, SELECT, TEXTAREA)
  1450. $oPage->add_ready_script("$('form#fs_$sSearchFormId :input[name={$sFilterCode}]').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );");
  1451. }
  1452. $index++;
  1453. $sHtml .= '</span> ';
  1454. }
  1455. $sHtml .= "</p>\n";
  1456. $sHtml .= "<p align=\"right\"><input type=\"submit\" value=\"".Dict::S('UI:Button:Search')."\"></p>\n";
  1457. foreach($aExtraParams as $sName => $sValue)
  1458. {
  1459. $sHtml .= "<input type=\"hidden\" name=\"$sName\" value=\"$sValue\" />\n";
  1460. }
  1461. $sHtml .= "<input type=\"hidden\" name=\"class\" value=\"$sClassName\" />\n";
  1462. $sHtml .= "<input type=\"hidden\" name=\"dosearch\" value=\"1\" />\n";
  1463. $sHtml .= "<input type=\"hidden\" name=\"operation\" value=\"search_form\" />\n";
  1464. $sHtml .= $oAppContext->GetForForm();
  1465. $sHtml .= "</form>\n";
  1466. if (!isset($aExtraParams['currentId']))
  1467. {
  1468. $sHtml .= "</div><!-- Simple search form -->\n";
  1469. }
  1470. /*
  1471. // OQL query builder
  1472. $sHtml .= "<div id=\"OQLQuery{$iSearchFormId}\" style=\"display:none\" class=\"mini_tab{$iSearchFormId}\">\n";
  1473. $sHtml .= "<h1>".Dict::S('UI:OQLQueryBuilderTitle')."</h1>\n";
  1474. $sHtml .= "<form id=\"formOQL{$iSearchFormId}\"><table style=\"width:80%;\"><tr style=\"vertical-align:top\">\n";
  1475. $sHtml .= "<td style=\"text-align:right\"><label>SELECT&nbsp;</label><select name=\"oql_class\">";
  1476. $aClasses = MetaModel::EnumChildClasses($sClassName, ENUM_CHILD_CLASSES_ALL);
  1477. $sSelectedClass = utils::ReadParam('oql_class', $sClassName, false, 'class');
  1478. $sOQLClause = utils::ReadParam('oql_clause', '', false, 'raw_data');
  1479. asort($aClasses);
  1480. foreach($aClasses as $sChildClass)
  1481. {
  1482. $sSelected = ($sChildClass == $sSelectedClass) ? 'selected' : '';
  1483. $sHtml.= "<option value=\"$sChildClass\" $sSelected>".MetaModel::GetName($sChildClass)."</option>\n";
  1484. }
  1485. $sHtml .= "</select>&nbsp;</td><td>\n";
  1486. $sHtml .= "<textarea name=\"oql_clause\" style=\"width:100%\">$sOQLClause</textarea></td></tr>\n";
  1487. $sHtml .= "<tr><td colspan=\"2\" style=\"text-align:right\"><input type=\"submit\" value=\"".Dict::S('UI:Button:Query')."\"></td></tr>\n";
  1488. $sHtml .= "<input type=\"hidden\" name=\"dosearch\" value=\"1\" />\n";
  1489. foreach($aExtraParams as $sName => $sValue)
  1490. {
  1491. $sHtml .= "<input type=\"hidden\" name=\"$sName\" value=\"$sValue\" />\n";
  1492. }
  1493. $sHtml .= "<input type=\"hidden\" name=\"operation\" value=\"search_oql\" />\n";
  1494. $sHtml .= $oAppContext->GetForForm();
  1495. $sHtml .= "</table></form>\n";
  1496. $sHtml .= "</div><!-- OQL query form -->\n";
  1497. */
  1498. return $sHtml;
  1499. }
  1500. public static function GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value = '', $sDisplayValue = '', $iId = '', $sNameSuffix = '', $iFlags = 0, $aArgs = array())
  1501. {
  1502. static $iInputId = 0;
  1503. $sFieldPrefix = '';
  1504. $sFormPrefix = isset($aArgs['formPrefix']) ? $aArgs['formPrefix'] : '';
  1505. $sFieldPrefix = isset($aArgs['prefix']) ? $sFormPrefix.$aArgs['prefix'] : $sFormPrefix;
  1506. if ($sDisplayValue == '')
  1507. {
  1508. $sDisplayValue = $value;
  1509. }
  1510. if (isset($aArgs[$sAttCode]) && empty($value))
  1511. {
  1512. // default value passed by the context (either the app context of the operation)
  1513. $value = $aArgs[$sAttCode];
  1514. }
  1515. if (!empty($iId))
  1516. {
  1517. $iInputId = $iId;
  1518. }
  1519. else
  1520. {
  1521. $iInputId = $oPage->GetUniqueId();
  1522. }
  1523. if (!$oAttDef->IsExternalField())
  1524. {
  1525. $bMandatory = 'false';
  1526. if ( (!$oAttDef->IsNullAllowed()) || ($iFlags & OPT_ATT_MANDATORY))
  1527. {
  1528. $bMandatory = 'true';
  1529. }
  1530. $sValidationField = "<span class=\"form_validation\" id=\"v_{$iId}\"></span>";
  1531. $sHelpText = $oAttDef->GetHelpOnEdition();
  1532. $aEventsList = array();
  1533. switch($oAttDef->GetEditClass())
  1534. {
  1535. case 'Date':
  1536. $aEventsList[] ='validate';
  1537. $aEventsList[] ='keyup';
  1538. $aEventsList[] ='change';
  1539. $sHTMLValue = "<input title=\"$sHelpText\" class=\"date-pick\" type=\"text\" size=\"12\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"".htmlentities($sDisplayValue, ENT_QUOTES, 'UTF-8')."\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  1540. break;
  1541. case 'DateTime':
  1542. $aEventsList[] ='validate';
  1543. $aEventsList[] ='keyup';
  1544. $aEventsList[] ='change';
  1545. $sHTMLValue = "<input title=\"$sHelpText\" class=\"date-pick\" type=\"text\" size=\"20\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"".htmlentities($sDisplayValue, ENT_QUOTES, 'UTF-8')."\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  1546. break;
  1547. case 'Duration':
  1548. $aEventsList[] ='validate';
  1549. $aEventsList[] ='change';
  1550. $oPage->add_ready_script("$('#{$iId}_d').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });");
  1551. $oPage->add_ready_script("$('#{$iId}_h').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });");
  1552. $oPage->add_ready_script("$('#{$iId}_m').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });");
  1553. $oPage->add_ready_script("$('#{$iId}_s').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });");
  1554. $aVal = AttributeDuration::SplitDuration($value);
  1555. $sDays = "<input title=\"$sHelpText\" type=\"text\" size=\"3\" name=\"attr_{$sFieldPrefix}{$sAttCode}[d]{$sNameSuffix}\" value=\"{$aVal['days']}\" id=\"{$iId}_d\"/>";
  1556. $sHours = "<input title=\"$sHelpText\" type=\"text\" size=\"2\" name=\"attr_{$sFieldPrefix}{$sAttCode}[h]{$sNameSuffix}\" value=\"{$aVal['hours']}\" id=\"{$iId}_h\"/>";
  1557. $sMinutes = "<input title=\"$sHelpText\" type=\"text\" size=\"2\" name=\"attr_{$sFieldPrefix}{$sAttCode}[m]{$sNameSuffix}\" value=\"{$aVal['minutes']}\" id=\"{$iId}_m\"/>";
  1558. $sSeconds = "<input title=\"$sHelpText\" type=\"text\" size=\"2\" name=\"attr_{$sFieldPrefix}{$sAttCode}[s]{$sNameSuffix}\" value=\"{$aVal['seconds']}\" id=\"{$iId}_s\"/>";
  1559. $sHidden = "<input type=\"hidden\" id=\"{$iId}\" value=\"".htmlentities($value, ENT_QUOTES, 'UTF-8')."\"/>";
  1560. $sHTMLValue = Dict::Format('UI:DurationForm_Days_Hours_Minutes_Seconds', $sDays, $sHours, $sMinutes, $sSeconds).$sHidden."&nbsp;".$sValidationField;
  1561. $oPage->add_ready_script("$('#{$iId}').bind('update', function(evt, sFormId) { return ToggleDurationField('$iId'); });");
  1562. break;
  1563. case 'Password':
  1564. $aEventsList[] ='validate';
  1565. $aEventsList[] ='keyup';
  1566. $aEventsList[] ='change';
  1567. $sHTMLValue = "<input title=\"$sHelpText\" type=\"password\" size=\"30\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"".htmlentities($value, ENT_QUOTES, 'UTF-8')."\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  1568. break;
  1569. case 'OQLExpression':
  1570. case 'Text':
  1571. $aEventsList[] ='validate';
  1572. $aEventsList[] ='keyup';
  1573. $aEventsList[] ='change';
  1574. $sEditValue = $oAttDef->GetEditValue($value);
  1575. $aStyles = array();
  1576. $sStyle = '';
  1577. $sWidth = $oAttDef->GetWidth('width', '');
  1578. if (!empty($sWidth))
  1579. {
  1580. $aStyles[] = 'width:'.$sWidth;
  1581. }
  1582. $sHeight = $oAttDef->GetHeight('height', '');
  1583. if (!empty($sHeight))
  1584. {
  1585. $aStyles[] = 'height:'.$sHeight;
  1586. }
  1587. if (count($aStyles) > 0)
  1588. {
  1589. $sStyle = 'style="'.implode('; ', $aStyles).'"';
  1590. }
  1591. if ($oAttDef->GetEditClass() == 'OQLExpression')
  1592. {
  1593. $sTestResId = 'query_res_'.$sFieldPrefix.$sAttCode.$sNameSuffix; //$oPage->GetUniqueId();
  1594. $sBaseUrl = utils::GetAbsoluteUrlAppRoot().'pages/run_query.php?expression=';
  1595. $sInitialUrl = $sBaseUrl.urlencode($sEditValue);
  1596. $sAdditionalStuff = "<a id=\"$sTestResId\" target=\"_blank\" href=\"$sInitialUrl\">".Dict::S('UI:Edit:TestQuery')."</a>";
  1597. $oPage->add_ready_script("$('#$iId').bind('change keyup', function(evt, sFormId) { $('#$sTestResId').attr('href', '$sBaseUrl'+encodeURIComponent($(this).val())); } );");
  1598. }
  1599. else
  1600. {
  1601. $sAdditionalStuff = "";
  1602. }
  1603. // Ok, the text area is drawn here
  1604. $sHTMLValue = "<table><tr><td><textarea class=\"resizable\" title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" rows=\"8\" cols=\"40\" id=\"$iId\" $sStyle>".htmlentities($sEditValue, ENT_QUOTES, 'UTF-8')."</textarea>$sAdditionalStuff</td><td>{$sValidationField}</td></tr></table>";
  1605. break;
  1606. case 'CaseLog':
  1607. $aStyles = array();
  1608. $sStyle = '';
  1609. $sWidth = $oAttDef->GetWidth('width', '');
  1610. if (!empty($sWidth))
  1611. {
  1612. $aStyles[] = 'width:'.$sWidth;
  1613. }
  1614. $sHeight = $oAttDef->GetHeight('height', '');
  1615. if (!empty($sHeight))
  1616. {
  1617. $aStyles[] = 'height:'.$sHeight;
  1618. }
  1619. if (count($aStyles) > 0)
  1620. {
  1621. $sStyle = 'style="'.implode('; ', $aStyles).'"';
  1622. }
  1623. $sHeader = '<div class="caselog_input_header">&nbsp;'.Dict::S('UI:CaseLogTypeYourTextHere').'</div>';
  1624. $sEditValue = $oAttDef->GetEditValue($value);
  1625. $sPreviousLog = is_object($value) ? $value->GetAsHTML() : '';
  1626. $iEntriesCount = is_object($value) ? count($value->GetIndex()) : 0;
  1627. $sHidden = "<input type=\"hidden\" id=\"{$iId}_count\" value=\"$iEntriesCount\"/>"; // To know how many entries the case log already contains
  1628. $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\">".htmlentities($sEditValue, ENT_QUOTES, 'UTF-8')."</textarea>$sPreviousLog</td><td>{$sValidationField}</td></tr></table>$sHidden</div>";
  1629. $oPage->add_ready_script("$('#$iId').bind('keyup change validate', function(evt, sFormId) { return ValidateCaseLogField('$iId', $bMandatory, sFormId) } );"); // Custom validation function
  1630. break;
  1631. case 'HTML':
  1632. $oWidget = new UIHTMLEditorWidget($iId, $sAttCode, $sNameSuffix, $sFieldPrefix, $sHelpText, $sValidationField, $value, $bMandatory);
  1633. $sHTMLValue = $oWidget->Display($oPage, $aArgs);
  1634. break;
  1635. case 'LinkedSet':
  1636. $aEventsList[] ='validate';
  1637. $aEventsList[] ='change';
  1638. $oWidget = new UILinksWidget($sClass, $sAttCode, $iId, $sNameSuffix, $oAttDef->DuplicatesAllowed(), $aArgs);
  1639. $oObj = isset($aArgs['this']) ? $aArgs['this'] : null;
  1640. $sHTMLValue = $oWidget->Display($oPage, $value, array(), $sFormPrefix, $oObj);
  1641. break;
  1642. case 'Document':
  1643. $aEventsList[] ='validate';
  1644. $aEventsList[] ='change';
  1645. $oDocument = $value; // Value is an ormDocument object
  1646. $sFileName = '';
  1647. if (is_object($oDocument))
  1648. {
  1649. $sFileName = $oDocument->GetFileName();
  1650. }
  1651. $iMaxFileSize = utils::ConvertToBytes(ini_get('upload_max_filesize'));
  1652. $sHTMLValue = "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$iMaxFileSize\" />\n";
  1653. $sHTMLValue .= "<input name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}[filename]\" type=\"hidden\" id=\"$iId\" \" value=\"".htmlentities($sFileName, ENT_QUOTES, 'UTF-8')."\"/>\n";
  1654. $sHTMLValue .= "<span id=\"name_$iInputId\">$sFileName</span><br/>\n";
  1655. $sHTMLValue .= "<input title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}[fcontents]\" type=\"file\" id=\"file_$iId\" onChange=\"UpdateFileName('$iId', this.value)\"/>&nbsp;{$sValidationField}\n";
  1656. break;
  1657. case 'List':
  1658. // Not editable for now...
  1659. $sHTMLValue = '';
  1660. break;
  1661. case 'One Way Password':
  1662. $aEventsList[] ='validate';
  1663. $oWidget = new UIPasswordWidget($sAttCode, $iId, $sNameSuffix);
  1664. $sHTMLValue = $oWidget->Display($oPage, $aArgs);
  1665. // Event list & validation is handled directly by the widget
  1666. break;
  1667. case 'ExtKey':
  1668. $aEventsList[] ='validate';
  1669. $aEventsList[] ='change';
  1670. $oAllowedValues = MetaModel::GetAllowedValuesAsObjectSet($sClass, $sAttCode, $aArgs);
  1671. $sFieldName = $sFieldPrefix.$sAttCode.$sNameSuffix;
  1672. $aExtKeyParams = $aArgs;
  1673. $aExtKeyParams['iFieldSize'] = $oAttDef->GetMaxSize();
  1674. $aExtKeyParams['iMinChars'] = $oAttDef->GetMinAutoCompleteChars();
  1675. $sHTMLValue = UIExtKeyWidget::DisplayFromAttCode($oPage, $sAttCode, $sClass, $oAttDef->GetLabel(), $oAllowedValues, $value, $iId, $bMandatory, $sFieldName, $sFormPrefix, $aArgs);
  1676. $sHTMLValue .= "<!-- iFlags: $iFlags bMandatory: $bMandatory -->\n";
  1677. break;
  1678. case 'String':
  1679. default:
  1680. $aEventsList[] ='validate';
  1681. // #@# todo - add context information (depending on dimensions)
  1682. $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
  1683. $iFieldSize = $oAttDef->GetMaxSize();
  1684. if ($aAllowedValues !== null)
  1685. {
  1686. // Discrete list of values, use a SELECT or RADIO buttons depending on the config
  1687. $sDisplayStyle = $oAttDef->GetDisplayStyle();
  1688. switch($sDisplayStyle)
  1689. {
  1690. case 'radio':
  1691. case 'radio_horizontal':
  1692. case 'radio_vertical':
  1693. $sHTMLValue = '';
  1694. $bVertical = ($sDisplayStyle != 'radio_horizontal');
  1695. $sHTMLValue = $oPage->GetRadioButtons($aAllowedValues, $value, $iId, "attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}", $bMandatory, $bVertical, $sValidationField);
  1696. $aEventsList[] ='change';
  1697. break;
  1698. case 'select':
  1699. default:
  1700. $sHTMLValue = "<select title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" id=\"$iId\">\n";
  1701. $sHTMLValue .= "<option value=\"\">".Dict::S('UI:SelectOne')."</option>\n";
  1702. foreach($aAllowedValues as $key => $display_value)
  1703. {
  1704. if ((count($aAllowedValues) == 1) && ($bMandatory == 'true') )
  1705. {
  1706. // When there is only once choice, select it by default
  1707. $sSelected = ' selected';
  1708. }
  1709. else
  1710. {
  1711. $sSelected = ($value == $key) ? ' selected' : '';
  1712. }
  1713. $sHTMLValue .= "<option value=\"$key\"$sSelected>$display_value</option>\n";
  1714. }
  1715. $sHTMLValue .= "</select>&nbsp;{$sValidationField}\n";
  1716. $aEventsList[] ='change';
  1717. }
  1718. }
  1719. else
  1720. {
  1721. $sHTMLValue = "<input title=\"$sHelpText\" type=\"text\" size=\"30\" maxlength=\"$iFieldSize\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"".htmlentities($sDisplayValue, ENT_QUOTES, 'UTF-8')."\" id=\"$iId\"/>&nbsp;{$sValidationField}";
  1722. $aEventsList[] ='keyup';
  1723. $aEventsList[] ='change';
  1724. }
  1725. break;
  1726. }
  1727. $sPattern = addslashes($oAttDef->GetValidationPattern()); //'^([0-9]+)$';
  1728. if (!empty($aEventsList))
  1729. {
  1730. $sNullValue = $oAttDef->GetNullValue();
  1731. if (!is_numeric($sNullValue))
  1732. {
  1733. $sNullValue = "'$sNullValue'"; // Add quotes to turn this into a JS string if it's not a number
  1734. }
  1735. $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
  1736. }
  1737. $aDependencies = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that depend on the current one
  1738. if (count($aDependencies) > 0)
  1739. {
  1740. $oPage->add_ready_script("$('#$iId').bind('change', function(evt, sFormId) { return oWizardHelper{$sFormPrefix}.UpdateDependentFields(['".implode("','", $aDependencies)."']) } );\n"); // Bind to a custom event: validate
  1741. }
  1742. }
  1743. return "<div>{$sHTMLValue}</div>";
  1744. }
  1745. public function DisplayModifyForm(WebPage $oPage, $aExtraParams = array())
  1746. {
  1747. self::$iGlobalFormId++;
  1748. $sPrefix = '';
  1749. if (isset($aExtraParams['formPrefix']))
  1750. {
  1751. $sPrefix = $aExtraParams['formPrefix'];
  1752. }
  1753. $aFieldsComments = (isset($aExtraParams['fieldsComments'])) ? $aExtraParams['fieldsComments'] : array();
  1754. $this->m_iFormId = $sPrefix.self::$iGlobalFormId;
  1755. $sClass = get_class($this);
  1756. $oAppContext = new ApplicationContext();
  1757. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  1758. $iKey = $this->GetKey();
  1759. $aDetails = array();
  1760. $aFieldsMap = array();
  1761. if (!isset($aExtraParams['action']))
  1762. {
  1763. $sFormAction = $_SERVER['SCRIPT_NAME']; // No parameter in the URL, the only parameter will be the ones passed through the form
  1764. }
  1765. else
  1766. {
  1767. $sFormAction = $aExtraParams['action'];
  1768. }
  1769. // Custom label for the apply button ?
  1770. if (isset($aExtraParams['custom_button']))
  1771. {
  1772. $sApplyButton = $aExtraParams['custom_button'];
  1773. }
  1774. else if ($iKey > 0)
  1775. {
  1776. $sApplyButton = Dict::S('UI:Button:Apply');
  1777. }
  1778. else
  1779. {
  1780. $sApplyButton = Dict::S('UI:Button:Create');
  1781. }
  1782. // Custom operation for the form ?
  1783. if (isset($aExtraParams['custom_operation']))
  1784. {
  1785. $sOperation = $aExtraParams['custom_operation'];
  1786. }
  1787. else if ($iKey > 0)
  1788. {
  1789. $sOperation = 'apply_modify';
  1790. }
  1791. else
  1792. {
  1793. $sOperation = 'apply_new';
  1794. }
  1795. if ($iKey > 0)
  1796. {
  1797. // The object already exists in the database, it's a modification
  1798. $sButtons = "<input id=\"{$sPrefix}_id\" type=\"hidden\" name=\"id\" value=\"$iKey\">\n";
  1799. $sButtons .= "<input type=\"hidden\" name=\"operation\" value=\"{$sOperation}\">\n";
  1800. $sButtons .= "<button type=\"button\" class=\"action cancel\"><span>".Dict::S('UI:Button:Cancel')."</span></button>&nbsp;&nbsp;&nbsp;&nbsp;\n";
  1801. $sButtons .= "<button type=\"submit\" class=\"action\"><span>{$sApplyButton}</span></button>\n";
  1802. }
  1803. else
  1804. {
  1805. // The object does not exist in the database it's a creation
  1806. $sButtons = "<input type=\"hidden\" name=\"operation\" value=\"$sOperation\">\n";
  1807. $sButtons .= "<button type=\"button\" class=\"action cancel\">".Dict::S('UI:Button:Cancel')."</button>&nbsp;&nbsp;&nbsp;&nbsp;\n";
  1808. $sButtons .= "<button type=\"submit\" class=\"action\"><span>{$sApplyButton}</span></button>\n";
  1809. }
  1810. $aTransitions = $this->EnumTransitions();
  1811. if (!isset($aExtraParams['custom_operation']) && count($aTransitions))
  1812. {
  1813. // transitions are displayed only for the standard new/modify actions, not for modify_all or any other case...
  1814. $oSetToCheckRights = DBObjectSet::FromObject($this);
  1815. $aStimuli = Metamodel::EnumStimuli($sClass);
  1816. foreach($aTransitions as $sStimulusCode => $aTransitionDef)
  1817. {
  1818. $iActionAllowed = (get_class($aStimuli[$sStimulusCode]) == 'StimulusUserAction') ? UserRights::IsStimulusAllowed($sClass, $sStimulusCode, $oSetToCheckRights) : UR_ALLOWED_NO;
  1819. switch($iActionAllowed)
  1820. {
  1821. case UR_ALLOWED_YES:
  1822. $sButtons .= "<button type=\"submit\" name=\"next_action\" value=\"{$sStimulusCode}\" class=\"action\"><span>".$aStimuli[$sStimulusCode]->GetLabel()."</span></button>\n";
  1823. break;
  1824. default:
  1825. // Do nothing
  1826. }
  1827. }
  1828. }
  1829. $sButtonsPosition = MetaModel::GetConfig()->Get('buttons_position');
  1830. $iTransactionId = isset($aExtraParams['transaction_id']) ? $aExtraParams['transaction_id'] : utils::GetNewTransactionId();
  1831. $oPage->SetTransactionId($iTransactionId);
  1832. $oPage->add("<form action=\"$sFormAction\" id=\"form_{$this->m_iFormId}\" enctype=\"multipart/form-data\" method=\"post\" onSubmit=\"return OnSubmit('form_{$this->m_iFormId}');\">\n");
  1833. $sStatesSelection = '';
  1834. if (!isset($aExtraParams['custom_operation']) && $this->IsNew())
  1835. {
  1836. $aInitialStates = MetaModel::EnumInitialStates($sClass);
  1837. //$aInitialStates = array('new' => 'foo', 'closed' => 'bar');
  1838. if (count($aInitialStates) > 1)
  1839. {
  1840. $sStatesSelection = Dict::Format('UI:Create_Class_InState', MetaModel::GetName($sClass)).'<select name="obj_state" class="state_select_'.$this->m_iFormId.'">';
  1841. foreach($aInitialStates as $sStateCode => $sStateData)
  1842. {
  1843. $sSelected = '';
  1844. if ($sStateCode == $this->GetState())
  1845. {
  1846. $sSelected = ' selected';
  1847. }
  1848. $sStatesSelection .= '<option value="'.$sStateCode.'"'.$sSelected.'>'.MetaModel::GetStateLabel($sClass, $sStateCode).'</option>';
  1849. }
  1850. $sStatesSelection .= '</select>';
  1851. $oPage->add_ready_script("$('.state_select_{$this->m_iFormId}').change( function() { oWizardHelper$sPrefix.ReloadObjectCreationForm('form_{$this->m_iFormId}', $(this).val()); } );");
  1852. }
  1853. }
  1854. $sConfirmationMessage = addslashes(Dict::S('UI:NavigateAwayConfirmationMessage'));
  1855. $oPage->add_ready_script(
  1856. <<<EOF
  1857. $(window).unload(function() { return OnUnload('$iTransactionId') } );
  1858. window.onbeforeunload = function() {
  1859. if (!window.bInSubmit && !window.bInCancel)
  1860. {
  1861. return '$sConfirmationMessage';
  1862. }
  1863. // return nothing ! safer for IE
  1864. };
  1865. EOF
  1866. );
  1867. if ($sButtonsPosition != 'bottom')
  1868. {
  1869. // top or both, display the buttons here
  1870. $oPage->p($sStatesSelection);
  1871. $oPage->add($sButtons);
  1872. }
  1873. $oPage->AddTabContainer(OBJECT_PROPERTIES_TAB, $sPrefix);
  1874. $oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
  1875. $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
  1876. $aFieldsMap = $this->DisplayBareProperties($oPage, true, $sPrefix, $aExtraParams);
  1877. if ($iKey > 0)
  1878. {
  1879. $aFieldsMap['id'] = $sPrefix.'_id';
  1880. }
  1881. // Now display the relations, one tab per relation
  1882. if (!isset($aExtraParams['noRelations']))
  1883. {
  1884. $this->DisplayBareRelations($oPage, true); // Edit mode
  1885. }
  1886. $oPage->SetCurrentTab('');
  1887. $oPage->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">\n");
  1888. $oPage->add("<input type=\"hidden\" name=\"transaction_id\" value=\"$iTransactionId\">\n");
  1889. foreach($aExtraParams as $sName => $value)
  1890. {
  1891. $oPage->add("<input type=\"hidden\" name=\"$sName\" value=\"$value\">\n");
  1892. }
  1893. $oPage->add($oAppContext->GetForForm());
  1894. if ($sButtonsPosition != 'top')
  1895. {
  1896. // bottom or both: display the buttons here
  1897. $oPage->p($sStatesSelection);
  1898. $oPage->add($sButtons);
  1899. }
  1900. // Hook the cancel button via jQuery so that it can be unhooked easily as well if needed
  1901. $sDefaultUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=cancel&'.$oAppContext->GetForLink();
  1902. $oPage->add_ready_script("$('#form_{$this->m_iFormId} button.cancel').click( function() { BackToDetails('$sClass', $iKey, '$sDefaultUrl')} );");
  1903. $oPage->add("</form>\n");
  1904. $iFieldsCount = count($aFieldsMap);
  1905. $sJsonFieldsMap = json_encode($aFieldsMap);
  1906. $sState = $this->GetState();
  1907. $oPage->add_script(
  1908. <<<EOF
  1909. // Create the object once at the beginning of the page...
  1910. var oWizardHelper$sPrefix = new WizardHelper('$sClass', '$sPrefix', '$sState');
  1911. oWizardHelper$sPrefix.SetFieldsMap($sJsonFieldsMap);
  1912. oWizardHelper$sPrefix.SetFieldsCount($iFieldsCount);
  1913. EOF
  1914. );
  1915. $oPage->add_ready_script(
  1916. <<<EOF
  1917. oWizardHelper$sPrefix.UpdateWizard();
  1918. // Starts the validation when the page is ready
  1919. CheckFields('form_{$this->m_iFormId}', false);
  1920. EOF
  1921. );
  1922. }
  1923. public static function DisplayCreationForm(WebPage $oPage, $sClass, $oObjectToClone = null, $aArgs = array(), $aExtraParams = array())
  1924. {
  1925. $oAppContext = new ApplicationContext();
  1926. $sClass = ($oObjectToClone == null) ? $sClass : get_class($oObjectToClone);
  1927. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  1928. $aStates = MetaModel::EnumStates($sClass);
  1929. $sStatesSelection = '';
  1930. if ($oObjectToClone == null)
  1931. {
  1932. $oObj = MetaModel::NewObject($sClass);
  1933. if (!empty($sStateAttCode))
  1934. {
  1935. $sTargetState = MetaModel::GetDefaultState($sClass);
  1936. $oObj->Set($sStateAttCode, $sTargetState);
  1937. }
  1938. }
  1939. else
  1940. {
  1941. $oObj = clone $oObjectToClone;
  1942. }
  1943. // Pre-fill the object with default values, when there is only on possible choice
  1944. // AND the field is mandatory (otherwise there is always the possiblity to let it empty)
  1945. $aArgs['this'] = $oObj;
  1946. $aDetailsList = self::FLattenZList(MetaModel::GetZListItems($sClass, 'details'));
  1947. // Order the fields based on their dependencies
  1948. $aDeps = array();
  1949. foreach($aDetailsList as $sAttCode)
  1950. {
  1951. $aDeps[$sAttCode] = MetaModel::GetPrequisiteAttributes($sClass, $sAttCode);
  1952. }
  1953. $aList = self::OrderDependentFields($aDeps);
  1954. // Now fill-in the fields with default/supplied values
  1955. foreach($aList as $sAttCode)
  1956. {
  1957. if (isset($aArgs['default'][$sAttCode]))
  1958. {
  1959. $oObj->Set($sAttCode, $aArgs['default'][$sAttCode]);
  1960. }
  1961. else
  1962. {
  1963. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1964. // If the field is mandatory, set it to the only possible value
  1965. $iFlags = $oObj->GetInitialStateAttributeFlags($sAttCode);
  1966. if ((!$oAttDef->IsNullAllowed()) || ($iFlags & OPT_ATT_MANDATORY))
  1967. {
  1968. if ($oAttDef->IsExternalKey())
  1969. {
  1970. $oAllowedValues = MetaModel::GetAllowedValuesAsObjectSet($sClass, $sAttCode, $aArgs);
  1971. if ($oAllowedValues->Count() == 1)
  1972. {
  1973. $oRemoteObj = $oAllowedValues->Fetch();
  1974. $oObj->Set($sAttCode, $oRemoteObj->GetKey());
  1975. }
  1976. }
  1977. else
  1978. {
  1979. $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
  1980. if (count($aAllowedValues) == 1)
  1981. {
  1982. $aValues = array_keys($aAllowedValues);
  1983. $oObj->Set($sAttCode, $aValues[0]);
  1984. }
  1985. }
  1986. }
  1987. }
  1988. }
  1989. return $oObj->DisplayModifyForm( $oPage, $aExtraParams);
  1990. }
  1991. public static function ProcessZlist($aList, $aDetails, $sCurrentTab, $sCurrentCol, $sCurrentSet)
  1992. {
  1993. //echo "<pre>ZList: ";
  1994. //print_r($aList);
  1995. //echo "</pre>\n";
  1996. $index = 0;
  1997. foreach($aList as $sKey => $value)
  1998. {
  1999. if (is_array($value))
  2000. {
  2001. if (preg_match('/^(.*):(.*)$/U', $sKey, $aMatches))
  2002. {
  2003. $sCode = $aMatches[1];
  2004. $sName = $aMatches[2];
  2005. switch($sCode)
  2006. {
  2007. case 'tab':
  2008. //echo "<p>Found a tab: $sName ($sKey)</p>\n";
  2009. if(!isset($aDetails[$sName]))
  2010. {
  2011. $aDetails[$sName] = array('col1' => array());
  2012. }
  2013. $aDetails = self::ProcessZlist($value, $aDetails, $sName, 'col1', '');
  2014. break;
  2015. case 'fieldset':
  2016. //echo "<p>Found a fieldset: $sName ($sKey)</p>\n";
  2017. if(!isset($aDetailsStruct[$sCurrentTab][$sCurrentCol][$sName]))
  2018. {
  2019. $aDetails[$sCurrentTab][$sCurrentCol][$sName] = array();
  2020. }
  2021. $aDetails = self::ProcessZlist($value, $aDetails, $sCurrentTab, $sCurrentCol, $sName);
  2022. break;
  2023. default:
  2024. case 'col':
  2025. //echo "<p>Found a column: $sName ($sKey)</p>\n";
  2026. if(!isset($aDetails[$sCurrentTab][$sName]))
  2027. {
  2028. $aDetails[$sCurrentTab][$sName] = array();
  2029. }
  2030. $aDetails = self::ProcessZlist($value, $aDetails, $sCurrentTab, $sName, '');
  2031. break;
  2032. }
  2033. }
  2034. }
  2035. else
  2036. {
  2037. //echo "<p>Scalar value: $value, in [$sCurrentTab][$sCurrentCol][$sCurrentSet][]</p>\n";
  2038. if (empty($sCurrentSet))
  2039. {
  2040. $aDetails[$sCurrentTab][$sCurrentCol]['_'.$index][] = $value;
  2041. }
  2042. else
  2043. {
  2044. $aDetails[$sCurrentTab][$sCurrentCol][$sCurrentSet][] = $value;
  2045. }
  2046. }
  2047. $index++;
  2048. }
  2049. return $aDetails;
  2050. }
  2051. static function FlattenZList($aList)
  2052. {
  2053. $aResult = array();
  2054. foreach($aList as $value)
  2055. {
  2056. if (!is_array($value))
  2057. {
  2058. $aResult[] = $value;
  2059. }
  2060. else
  2061. {
  2062. $aResult = array_merge($aResult,self::FlattenZList($value));
  2063. }
  2064. }
  2065. return $aResult;
  2066. }
  2067. protected function GetFieldAsHtml($sClass, $sAttCode, $sStateAttCode)
  2068. {
  2069. $retVal = null;
  2070. if ($this->IsNew())
  2071. {
  2072. $iFlags = $this->GetInitialStateAttributeFlags($sAttCode);
  2073. }
  2074. else
  2075. {
  2076. $iFlags = $this->GetAttributeFlags($sAttCode);
  2077. }
  2078. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  2079. if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0) )
  2080. {
  2081. // The field is visible in the current state of the object
  2082. if ($sStateAttCode == $sAttCode)
  2083. {
  2084. // Special display for the 'state' attribute itself
  2085. $sDisplayValue = $this->GetStateLabel();
  2086. }
  2087. else if ($oAttDef->GetEditClass() == 'Document')
  2088. {
  2089. $oDocument = $this->Get($sAttCode);
  2090. $sDisplayValue = $this->GetAsHTML($sAttCode);
  2091. $sDisplayValue .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_', $oDocument->GetDisplayLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
  2092. $sDisplayValue .= "<br/>".Dict::Format('UI:DownloadDocument_', $oDocument->GetDownloadLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
  2093. }
  2094. else
  2095. {
  2096. $sDisplayValue = $this->GetAsHTML($sAttCode);
  2097. }
  2098. $retVal = array('label' => '<span title="'.MetaModel::GetDescription($sClass, $sAttCode).'">'.MetaModel::GetLabel($sClass, $sAttCode).'</span>', 'value' => $sDisplayValue);
  2099. }
  2100. return $retVal;
  2101. }
  2102. /**
  2103. * Displays a blob document *inline* (if possible, depending on the type of the document)
  2104. * @return string
  2105. */
  2106. public function DisplayDocumentInline(WebPage $oPage, $sAttCode)
  2107. {
  2108. $oDoc = $this->Get($sAttCode);
  2109. $sClass = get_class($this);
  2110. $Id = $this->GetKey();
  2111. switch ($oDoc->GetMainMimeType())
  2112. {
  2113. case 'text':
  2114. case 'html':
  2115. $data = $oDoc->GetData();
  2116. switch($oDoc->GetMimeType())
  2117. {
  2118. case 'text/html':
  2119. case 'text/xml':
  2120. $oPage->add("<iframe id='preview_$sAttCode' src=\"".utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" width=\"100%\" height=\"400\">Loading...</iframe>\n");
  2121. break;
  2122. default:
  2123. $oPage->add("<pre>".htmlentities(MyHelpers::beautifulstr($data, 1000, true), ENT_QUOTES, 'UTF-8')."</pre>\n");
  2124. }
  2125. break;
  2126. case 'application':
  2127. switch($oDoc->GetMimeType())
  2128. {
  2129. case 'application/pdf':
  2130. $oPage->add("<iframe id='preview_$sAttCode' src=\"".utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" width=\"100%\" height=\"400\">Loading...</iframe>\n");
  2131. break;
  2132. default:
  2133. $oPage->add(Dict::S('UI:Document:NoPreview'));
  2134. }
  2135. break;
  2136. case 'image':
  2137. $oPage->add("<img src=\"".utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" />\n");
  2138. break;
  2139. default:
  2140. $oPage->add(Dict::S('UI:Document:NoPreview'));
  2141. }
  2142. }
  2143. // $m_highlightComparison[previous][new] => next value
  2144. protected static $m_highlightComparison = array(
  2145. HILIGHT_CLASS_CRITICAL => array(
  2146. HILIGHT_CLASS_CRITICAL => HILIGHT_CLASS_CRITICAL,
  2147. HILIGHT_CLASS_WARNING => HILIGHT_CLASS_CRITICAL,
  2148. HILIGHT_CLASS_OK => HILIGHT_CLASS_CRITICAL,
  2149. HILIGHT_CLASS_NONE => HILIGHT_CLASS_CRITICAL,
  2150. ),
  2151. HILIGHT_CLASS_WARNING => array(
  2152. HILIGHT_CLASS_CRITICAL => HILIGHT_CLASS_CRITICAL,
  2153. HILIGHT_CLASS_WARNING => HILIGHT_CLASS_WARNING,
  2154. HILIGHT_CLASS_OK => HILIGHT_CLASS_WARNING,
  2155. HILIGHT_CLASS_NONE => HILIGHT_CLASS_WARNING,
  2156. ),
  2157. HILIGHT_CLASS_OK => array(
  2158. HILIGHT_CLASS_CRITICAL => HILIGHT_CLASS_CRITICAL,
  2159. HILIGHT_CLASS_WARNING => HILIGHT_CLASS_WARNING,
  2160. HILIGHT_CLASS_OK => HILIGHT_CLASS_OK,
  2161. HILIGHT_CLASS_NONE => HILIGHT_CLASS_OK,
  2162. ),
  2163. HILIGHT_CLASS_NONE => array(
  2164. HILIGHT_CLASS_CRITICAL => HILIGHT_CLASS_CRITICAL,
  2165. HILIGHT_CLASS_WARNING => HILIGHT_CLASS_WARNING,
  2166. HILIGHT_CLASS_OK => HILIGHT_CLASS_OK,
  2167. HILIGHT_CLASS_NONE => HILIGHT_CLASS_NONE,
  2168. ),
  2169. );
  2170. /**
  2171. * This function returns a 'hilight' CSS class, used to hilight a given row in a table
  2172. * There are currently (i.e defined in the CSS) 4 possible values HILIGHT_CLASS_CRITICAL,
  2173. * HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  2174. * To Be overridden by derived classes
  2175. * @param void
  2176. * @return String The desired higlight class for the object/row
  2177. */
  2178. public function GetHilightClass()
  2179. {
  2180. // Possible return values are:
  2181. // HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  2182. $current = HILIGHT_CLASS_NONE; // Not hilighted by default
  2183. // Invoke extensions before the deletion (the deletion will do some cleanup and we might loose some information
  2184. foreach (MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance)
  2185. {
  2186. $new = $oExtensionInstance->GetHilightClass($this);
  2187. @$current = self::$m_highlightComparison[$current][$new];
  2188. }
  2189. return $current;
  2190. }
  2191. /**
  2192. * Re-order the fields based on their inter-dependencies
  2193. * @params hash @aFields field_code => array_of_depencies
  2194. * @return array Ordered array of fields or throws an exception
  2195. */
  2196. public static function OrderDependentFields($aFields)
  2197. {
  2198. $bCircular = false;
  2199. $aResult = array();
  2200. $iCount = 0;
  2201. do
  2202. {
  2203. $bSet = false;
  2204. $iCount++;
  2205. foreach($aFields as $sFieldCode => $aDeps)
  2206. {
  2207. foreach($aDeps as $key => $sDependency)
  2208. {
  2209. if (in_array($sDependency, $aResult))
  2210. {
  2211. // Dependency is resolved, remove it
  2212. unset($aFields[$sFieldCode][$key]);
  2213. }
  2214. }
  2215. if (count($aFields[$sFieldCode]) == 0)
  2216. {
  2217. // No more pending depencies for this field, add it to the list
  2218. $aResult[] = $sFieldCode;
  2219. unset($aFields[$sFieldCode]);
  2220. $bSet = true;
  2221. }
  2222. }
  2223. }
  2224. while($bSet && (count($aFields) > 0));
  2225. if (count($aFields) > 0)
  2226. {
  2227. $sMessage = "Error: Circular dependencies between the fields (or field missing in ZList) ! <pre>".print_r($aFields, true)."</pre>";
  2228. throw(new Exception($sMessage));
  2229. }
  2230. return $aResult;
  2231. }
  2232. /**
  2233. * Get the list of actions to be displayed as 'shortcuts' (i.e buttons) instead of inside the Actions popup menu
  2234. * @param $sFinalClass string The actual class of the objects for which to display the menu
  2235. * @return Array the list of menu codes (i.e dictionary entries) that can be displayed as shortcuts next to the actions menu
  2236. */
  2237. public static function GetShortcutActions($sFinalClass)
  2238. {
  2239. $sShortcutActions = MetaModel::GetConfig()->Get('shortcut_actions');
  2240. $aShortcutActions = explode(',', $sShortcutActions);
  2241. return $aShortcutActions;
  2242. }
  2243. /**
  2244. * Maps the given context parameter name to the appropriate filter/search code for this class
  2245. * @param string $sContextParam Name of the context parameter, i.e. 'org_id'
  2246. * @return string Filter code, i.e. 'customer_id'
  2247. */
  2248. public static function MapContextParam($sContextParam)
  2249. {
  2250. if ($sContextParam == 'menu')
  2251. {
  2252. return null;
  2253. }
  2254. else
  2255. {
  2256. return $sContextParam;
  2257. }
  2258. }
  2259. /**
  2260. * Updates the object from a flat array of values
  2261. * @param $aAttList array $aAttList array of attcode
  2262. * @param $aErrors array Returns information about slave attributes
  2263. * @param $sTargetState string Target state for which to evaluate the writeable attributes (=current state is empty)
  2264. * @return array of attcodes that can be used for writing on the current object
  2265. */
  2266. public function GetWriteableAttList($aAttList, &$aErrors, $sTargetState = '')
  2267. {
  2268. if (!is_array($aAttList))
  2269. {
  2270. $aAttList = $this->FlattenZList(MetaModel::GetZListItems(get_class($this), 'details'));
  2271. // Special case to process the case log, if any...
  2272. // WARNING: if you change this also check the functions DisplayModifyForm and DisplayCaseLog
  2273. foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode => $oAttDef)
  2274. {
  2275. if ($this->IsNew())
  2276. {
  2277. $iFlags = $this->GetInitialStateAttributeFlags($sAttCode);
  2278. }
  2279. else
  2280. {
  2281. $aVoid = array();
  2282. $iFlags = $this->GetAttributeFlags($sAttCode, $aVoid, $sTargetState);
  2283. }
  2284. if ($oAttDef instanceof AttributeCaseLog)
  2285. {
  2286. if (!($iFlags & (OPT_ATT_HIDDEN|OPT_ATT_SLAVE|OPT_ATT_READONLY)))
  2287. {
  2288. // The case log is editable, append it to the list of fields to retrieve
  2289. $aAttList[] = $sAttCode;
  2290. }
  2291. }
  2292. }
  2293. }
  2294. $aWriteableAttList = array();
  2295. foreach($aAttList as $sAttCode)
  2296. {
  2297. $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
  2298. if ($this->IsNew())
  2299. {
  2300. $iFlags = $this->GetInitialStateAttributeFlags($sAttCode);
  2301. }
  2302. else
  2303. {
  2304. $aVoid = array();
  2305. $iFlags = $this->GetAttributeFlags($sAttCode, $aVoid, $sTargetState);
  2306. }
  2307. if ($oAttDef->IsWritable())
  2308. {
  2309. if ( $iFlags & (OPT_ATT_HIDDEN | OPT_ATT_READONLY))
  2310. {
  2311. // Non-visible, or read-only attribute, do nothing
  2312. }
  2313. elseif($iFlags & OPT_ATT_SLAVE)
  2314. {
  2315. $aErrors[$sAttCode] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $oAttDef->GetLabel());
  2316. }
  2317. else
  2318. {
  2319. $aWriteableAttList[$sAttCode] = $oAttDef;
  2320. }
  2321. }
  2322. }
  2323. return $aWriteableAttList;
  2324. }
  2325. /**
  2326. * Updates the object from a flat array of values
  2327. * @param string $aValues array of attcode => scalar or array (N-N links)
  2328. * @return void
  2329. */
  2330. public function UpdateObjectFromArray($aValues)
  2331. {
  2332. foreach($aValues as $sAttCode => $value)
  2333. {
  2334. $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
  2335. if ($oAttDef->IsLinkSet() && $oAttDef->IsIndirect())
  2336. {
  2337. $aLinks = $value;
  2338. $sLinkedClass = $oAttDef->GetLinkedClass();
  2339. $sExtKeyToRemote = $oAttDef->GetExtKeyToRemote();
  2340. $sExtKeyToMe = $oAttDef->GetExtKeyToMe();
  2341. $oLinkedSet = DBObjectSet::FromScratch($sLinkedClass);
  2342. if (is_array($aLinks))
  2343. {
  2344. foreach($aLinks as $id => $aData)
  2345. {
  2346. if (is_numeric($id))
  2347. {
  2348. if ($id < 0)
  2349. {
  2350. // New link to be created, the opposite of the id (-$id) is the ID of the remote object
  2351. $oLink = MetaModel::NewObject($sLinkedClass);
  2352. $oLink->Set($sExtKeyToRemote, -$id);
  2353. $oLink->Set($sExtKeyToMe, $this->GetKey());
  2354. }
  2355. else
  2356. {
  2357. // Existing link, potentially to be updated...
  2358. $oLink = MetaModel::GetObject($sLinkedClass, $id);
  2359. }
  2360. // Now populate the attributes
  2361. foreach($aData as $sName => $value)
  2362. {
  2363. if (MetaModel::IsValidAttCode($sLinkedClass, $sName))
  2364. {
  2365. $oLinkAttDef = MetaModel::GetAttributeDef($sLinkedClass, $sName);
  2366. if ($oLinkAttDef->IsWritable())
  2367. {
  2368. $oLink->Set($sName, $value);
  2369. }
  2370. }
  2371. }
  2372. $oLinkedSet->AddObject($oLink);
  2373. }
  2374. }
  2375. }
  2376. $this->Set($sAttCode, $oLinkedSet);
  2377. }
  2378. elseif ($oAttDef->GetEditClass() == 'Document')
  2379. {
  2380. // There should be an uploaded file with the named attr_<attCode>
  2381. $oDocument = $value['fcontents'];
  2382. if (!$oDocument->IsEmpty())
  2383. {
  2384. // A new file has been uploaded
  2385. $this->Set($sAttCode, $oDocument);
  2386. }
  2387. }
  2388. elseif ($oAttDef->GetEditClass() == 'One Way Password')
  2389. {
  2390. // Check if the password was typed/changed
  2391. $aPwdData = $value;
  2392. if (!is_null($aPwdData) && $aPwdData['changed'])
  2393. {
  2394. // The password has been changed or set
  2395. $this->Set($sAttCode, $aPwdData['value']);
  2396. }
  2397. }
  2398. elseif ($oAttDef->GetEditClass() == 'Duration')
  2399. {
  2400. $aDurationData = $value;
  2401. if (!is_array($aDurationData)) continue;
  2402. $iValue = (((24*$aDurationData['d'])+$aDurationData['h'])*60 +$aDurationData['m'])*60 + $aDurationData['s'];
  2403. $this->Set($sAttCode, $iValue);
  2404. $previousValue = $this->Get($sAttCode);
  2405. if ($previousValue !== $iValue)
  2406. {
  2407. $this->Set($sAttCode, $iValue);
  2408. }
  2409. }
  2410. else
  2411. {
  2412. if (!is_null($value))
  2413. {
  2414. $aAttributes[$sAttCode] = trim($value);
  2415. $previousValue = $this->Get($sAttCode);
  2416. if ($previousValue !== $aAttributes[$sAttCode])
  2417. {
  2418. $this->Set($sAttCode, $aAttributes[$sAttCode]);
  2419. }
  2420. }
  2421. }
  2422. }
  2423. }
  2424. /**
  2425. * Updates the object from the POSTed parameters (form)
  2426. */
  2427. public function UpdateObjectFromPostedForm($sFormPrefix = '', $aAttList = null, $sTargetState = '')
  2428. {
  2429. if (is_null($aAttList))
  2430. {
  2431. $aAttList = array_keys(MetaModel::ListAttributeDefs(get_class($this)));
  2432. }
  2433. $aValues = array();
  2434. foreach($aAttList as $sAttCode)
  2435. {
  2436. $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
  2437. if ($oAttDef->GetEditClass() == 'Document')
  2438. {
  2439. $value = array('fcontents' => utils::ReadPostedDocument("attr_{$sFormPrefix}{$sAttCode}", 'fcontents'));
  2440. }
  2441. else
  2442. {
  2443. $value = utils::ReadPostedParam("attr_{$sFormPrefix}{$sAttCode}", null, 'raw_data');
  2444. }
  2445. if (!is_null($value))
  2446. {
  2447. $aValues[$sAttCode] = $value;
  2448. }
  2449. }
  2450. $aErrors = array();
  2451. $aFinalValues = array();
  2452. foreach($this->GetWriteableAttList(array_keys($aValues), $aErrors, $sTargetState) as $sAttCode => $oAttDef)
  2453. {
  2454. $aFinalValues[$sAttCode] = $aValues[$sAttCode];
  2455. }
  2456. $this->UpdateObjectFromArray($aFinalValues);
  2457. // Invoke extensions after the update of the object from the form
  2458. foreach (MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance)
  2459. {
  2460. $oExtensionInstance->OnFormSubmit($this, $sFormPrefix);
  2461. }
  2462. return $aErrors;
  2463. }
  2464. /**
  2465. * Updates the object from a given page argument
  2466. */
  2467. public function UpdateObjectFromArg($sArgName, $aAttList = null, $sTargetState = '')
  2468. {
  2469. if (is_null($aAttList))
  2470. {
  2471. $aAttList = array_keys(MetaModel::ListAttributeDefs(get_class($this)));
  2472. }
  2473. $aRawValues = utils::ReadParam($sArgName, array(), '', 'raw_data');
  2474. $aValues = array();
  2475. foreach($aAttList as $sAttCode)
  2476. {
  2477. if (isset($aRawValues[$sAttCode]))
  2478. {
  2479. $aValues[$sAttCode] = $aRawValues[$sAttCode];
  2480. }
  2481. }
  2482. $aErrors = array();
  2483. $aFinalValues = array();
  2484. foreach($this->GetWriteableAttList(array_keys($aValues), $aErrors, $sTargetState) as $sAttCode => $oAttDef)
  2485. {
  2486. $aFinalValues[$sAttCode] = $aValues[$sAttCode];
  2487. }
  2488. $this->UpdateObjectFromArray($aFinalValues);
  2489. return $aErrors;
  2490. }
  2491. protected function DBInsertTracked_Internal($bDoNotReload = false)
  2492. {
  2493. $res = parent::DBInsertTracked_Internal($bDoNotReload);
  2494. // Invoke extensions after insertion (the object must exist, have an id, etc.)
  2495. foreach (MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance)
  2496. {
  2497. $oExtensionInstance->OnDBInsert($this, self::$m_oCurrChange);
  2498. }
  2499. return $res;
  2500. }
  2501. protected function DBCloneTracked_Internal($newKey = null)
  2502. {
  2503. $oNewObj = parent::DBCloneTracked_Internal($newKey);
  2504. // Invoke extensions after insertion (the object must exist, have an id, etc.)
  2505. foreach (MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance)
  2506. {
  2507. $oExtensionInstance->OnDBInsert($oNewObj, self::$m_oCurrChange);
  2508. }
  2509. return $oNewObj;
  2510. }
  2511. protected function DBUpdateTracked_Internal()
  2512. {
  2513. $res = parent::DBUpdateTracked_Internal();
  2514. // Invoke extensions after the update (could be before)
  2515. foreach (MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance)
  2516. {
  2517. $oExtensionInstance->OnDBUpdate($this, self::$m_oCurrChange);
  2518. }
  2519. return $res;
  2520. }
  2521. protected static function BulkUpdateTracked_Internal(DBObjectSearch $oFilter, array $aValues)
  2522. {
  2523. // Todo - invoke the extension
  2524. return parent::BulkUpdateTracked_Internal($oFilter, $aValues);
  2525. }
  2526. protected function DBDeleteTracked_Internal(&$oDeletionPlan = null)
  2527. {
  2528. // Invoke extensions before the deletion (the deletion will do some cleanup and we might loose some information
  2529. foreach (MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance)
  2530. {
  2531. $oExtensionInstance->OnDBDelete($this, self::$m_oCurrChange);
  2532. }
  2533. return parent::DBDeleteTracked_Internal($oDeletionPlan);
  2534. }
  2535. protected static function BulkDeleteTracked_Internal(DBObjectSearch $oFilter)
  2536. {
  2537. // Todo - invoke the extension
  2538. return parent::BulkDeleteTracked_Internal($oFilter);
  2539. }
  2540. public function IsModified()
  2541. {
  2542. if (parent::IsModified())
  2543. {
  2544. return true;
  2545. }
  2546. // Plugins
  2547. //
  2548. foreach (MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance)
  2549. {
  2550. if ($oExtensionInstance->OnIsModified($this))
  2551. {
  2552. return true;
  2553. }
  2554. }
  2555. }
  2556. public function DoCheckToWrite()
  2557. {
  2558. parent::DoCheckToWrite();
  2559. // Plugins
  2560. //
  2561. foreach (MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance)
  2562. {
  2563. $aNewIssues = $oExtensionInstance->OnCheckToWrite($this);
  2564. if (count($aNewIssues) > 0)
  2565. {
  2566. $this->m_aCheckIssues = array_merge($this->m_aCheckIssues, $aNewIssues);
  2567. }
  2568. }
  2569. // User rights
  2570. //
  2571. $aChanges = $this->ListChanges();
  2572. if (count($aChanges) > 0)
  2573. {
  2574. $aForbiddenFields = array();
  2575. foreach ($this->ListChanges() as $sAttCode => $value)
  2576. {
  2577. $bUpdateAllowed = UserRights::IsActionAllowedOnAttribute(get_class($this), $sAttCode, UR_ACTION_MODIFY, DBObjectSet::FromObject($this));
  2578. if (!$bUpdateAllowed)
  2579. {
  2580. $oAttCode = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
  2581. $aForbiddenFields[] = $oAttCode->GetLabel();
  2582. }
  2583. }
  2584. if (count($aForbiddenFields) > 0)
  2585. {
  2586. // Security issue
  2587. $this->m_bSecurityIssue = true;
  2588. $this->m_aCheckIssues[] = Dict::Format('UI:Delete:NotAllowedToUpdate_Fields',implode(', ', $aForbiddenFields));
  2589. }
  2590. }
  2591. }
  2592. protected function DoCheckToDelete(&$oDeletionPlan)
  2593. {
  2594. parent::DoCheckToDelete($oDeletionPlan);
  2595. // Plugins
  2596. //
  2597. foreach (MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance)
  2598. {
  2599. $aNewIssues = $oExtensionInstance->OnCheckToDelete($this);
  2600. if (count($aNewIssues) > 0)
  2601. {
  2602. $this->m_aDeleteIssues = array_merge($this->m_aDeleteIssues, $aNewIssues);
  2603. }
  2604. }
  2605. // User rights
  2606. //
  2607. $bDeleteAllowed = UserRights::IsActionAllowed(get_class($this), UR_ACTION_DELETE, DBObjectSet::FromObject($this));
  2608. if (!$bDeleteAllowed)
  2609. {
  2610. // Security issue
  2611. $this->m_bSecurityIssue = true;
  2612. $this->m_aDeleteIssues[] = Dict::S('UI:Delete:NotAllowedToDelete');
  2613. }
  2614. }
  2615. /**
  2616. * Special display where the case log uses the whole "screen" at the bottom of the "Properties" tab
  2617. */
  2618. public function DisplayCaseLog(WebPage $oPage, $sAttCode, $sComment = '', $sPrefix = '', $bEditMode = false)
  2619. {
  2620. $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
  2621. $sClass = get_class($this);
  2622. if ($this->IsNew())
  2623. {
  2624. $iFlags = $this->GetInitialStateAttributeFlags($sAttCode);
  2625. }
  2626. else
  2627. {
  2628. $iFlags = $this->GetAttributeFlags($sAttCode);
  2629. }
  2630. if ( $iFlags & OPT_ATT_HIDDEN)
  2631. {
  2632. // The case log is hidden do nothing
  2633. }
  2634. else
  2635. {
  2636. $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
  2637. $sInputId = $this->m_iFormId.'_'.$sAttCode;
  2638. if ((!$bEditMode) || ($iFlags & (OPT_ATT_READONLY|OPT_ATT_SLAVE)))
  2639. {
  2640. // Check if the attribute is not read-only because of a synchro...
  2641. $aReasons = array();
  2642. $sSynchroIcon = '';
  2643. if ($iFlags & OPT_ATT_SLAVE)
  2644. {
  2645. $iSynchroFlags = $this->GetSynchroReplicaFlags($sAttCode, $aReasons);
  2646. $sSynchroIcon = "&nbsp;<img id=\"synchro_$sInputId\" src=\"../images/transp-lock.png\" style=\"vertical-align:middle\"/>";
  2647. $sTip = '';
  2648. foreach($aReasons as $aRow)
  2649. {
  2650. $sTip .= "<p>Synchronized with {$aRow['name']} - {$aRow['description']}</p>";
  2651. }
  2652. $oPage->add_ready_script("$('#synchro_$sInputId').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );");
  2653. }
  2654. // Attribute is read-only
  2655. $sHTMLValue = $this->GetAsHTML($sAttCode);
  2656. $sHTMLValue .= '<input type="hidden" id="'.$sInputId.'" name="attr_'.$sPrefix.$sAttCode.'" value="'.htmlentities($this->Get($sAttCode), ENT_QUOTES, 'UTF-8').'"/>';
  2657. $aFieldsMap[$sAttCode] = $sInputId;
  2658. $sComment .= $sSynchroIcon;
  2659. }
  2660. else
  2661. {
  2662. $sValue = $this->Get($sAttCode);
  2663. $sDisplayValue = $this->GetEditValue($sAttCode);
  2664. $aArgs = array('this' => $this, 'formPrefix' => $sPrefix);
  2665. $sHTMLValue = '';
  2666. if ($sComment != '')
  2667. {
  2668. $sHTMLValue = '<span>'.$sComment.'</span><br/>';
  2669. }
  2670. $sHTMLValue .= "<span id=\"field_{$sInputId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).'</span>';
  2671. $aFieldsMap[$sAttCode] = $sInputId;
  2672. }
  2673. //$aVal = array('label' => '<span title="'.$oAttDef->GetDescription().'">'.$oAttDef->GetLabel().'</span>', 'value' => $sHTMLValue, 'comments' => $sComments, 'infos' => $sInfos);
  2674. $oPage->add('<fieldset><legend>'.$oAttDef->GetLabel().'</legend>');
  2675. $oPage->add($sHTMLValue);
  2676. $oPage->add('</fieldset>');
  2677. }
  2678. }
  2679. public function GetExpectedAttributes($sCurrentState, $sStimulus, $bOnlyNewOnes)
  2680. {
  2681. $aTransitions = $this->EnumTransitions();
  2682. $aStimuli = MetaModel::EnumStimuli(get_class($this));
  2683. if (!isset($aTransitions[$sStimulus]))
  2684. {
  2685. // Invalid stimulus
  2686. throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $oObj->GetName(), $oObj->GetStateLabel()));
  2687. }
  2688. $aTransition = $aTransitions[$sStimulus];
  2689. $sTargetState = $aTransition['target_state'];
  2690. $aTargetStates = MetaModel::EnumStates(get_class($this));
  2691. $aTargetState = $aTargetStates[$sTargetState];
  2692. $aCurrentState = $aTargetStates[$this->GetState()];
  2693. $aExpectedAttributes = $aTargetState['attribute_list'];
  2694. $aCurrentAttributes = $aCurrentState['attribute_list'];
  2695. $aComputedAttributes = array();
  2696. foreach($aExpectedAttributes as $sAttCode => $iExpectCode)
  2697. {
  2698. if (!array_key_exists($sAttCode, $aCurrentAttributes))
  2699. {
  2700. $aComputedAttributes[$sAttCode] = $iExpectCode;
  2701. }
  2702. else
  2703. {
  2704. if ( !($aCurrentAttributes[$sAttCode] & (OPT_ATT_HIDDEN|OPT_ATT_READONLY)) )
  2705. {
  2706. $iExpectCode = $iExpectCode & ~(OPT_ATT_MUSTPROMPT|OPT_ATT_MUSTCHANGE); // Already prompted/changed, reset the flags
  2707. }
  2708. //TODO: better check if the attribute is not *null*
  2709. if ( ($iExpectCode & OPT_ATT_MANDATORY) && ($this->Get($sAttCode) != ''))
  2710. {
  2711. $iExpectCode = $iExpectCode & ~(OPT_ATT_MANDATORY); // If the attribute is present, then no need to request its presence
  2712. }
  2713. $aComputedAttributes[$sAttCode] = $iExpectCode;
  2714. }
  2715. $aComputedAttributes[$sAttCode] = $aComputedAttributes[$sAttCode] & ~(OPT_ATT_READONLY|OPT_ATT_HIDDEN); // Don't care about this form now
  2716. if ($aComputedAttributes[$sAttCode] == 0)
  2717. {
  2718. unset($aComputedAttributes[$sAttCode]);
  2719. }
  2720. }
  2721. return $aComputedAttributes;
  2722. }
  2723. }
  2724. ?>