UI.php 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568
  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. * Main page of iTop
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. /**
  25. * Perform all the needed checks to delete one (or more) objects
  26. */
  27. function DeleteObjects(WebPage $oP, $sClass, $aObjects, $bDeleteConfirmed)
  28. {
  29. $bFoundManual = false;
  30. $bFoundStopper = false;
  31. $iTotalDelete = 0; // count of object that must be deleted
  32. $iTotalReset = 0; // count of object for which an ext key will be reset (to 0)
  33. $aTotalDeletedObjs = array();
  34. $aTotalResetedObjs = array();
  35. foreach($aObjects as $oObj)
  36. {
  37. // Evaluate the impact on the DB integrity
  38. //
  39. $aDeletedObjs = array();
  40. $aResetedObjs = array();
  41. $oObj->GetDeletionScheme($aDeletedObjs, $aResetedObjs);
  42. // Evaluate feasibility (user access control)
  43. //
  44. foreach ($aDeletedObjs as $sRemoteClass => $aDeletes)
  45. {
  46. $iTotalDelete += count($aDeletes);
  47. foreach ($aDeletes as $iId => $aData)
  48. {
  49. $oToDelete = $aData['to_delete'];
  50. $bDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, DBObjectSet::FromObject($oToDelete));
  51. $aTotalDeletedObjs[$sRemoteClass][$iId]['auto_delete'] = $aData['auto_delete'];
  52. if (!$bDeleteAllowed)
  53. {
  54. $aTotalDeletedObjs[$sRemoteClass][$iId]['issue'] = Dict::S('UI:Delete:NotAllowedToDelete');
  55. $bFoundStopper = true;
  56. }
  57. else
  58. {
  59. $aTotalDeletedObjs[$sRemoteClass][$iId]['to_delete'] = $oToDelete;
  60. }
  61. $bAutoDel = $aData['auto_delete'];
  62. if (!$bAutoDel)
  63. {
  64. $bFoundManual = true;
  65. }
  66. }
  67. }
  68. foreach ($aResetedObjs as $sRemoteClass => $aToReset)
  69. {
  70. $iTotalReset += count($aToReset);
  71. foreach ($aToReset as $iId => $aData)
  72. {
  73. $oToReset = $aData['to_reset'];
  74. $aExtKeyLabels = array();
  75. $aForbiddenKeys = array(); // keys on which the current user is not allowed to write
  76. foreach ($aData['attributes'] as $sRemoteExtKey => $aRemoteAttDef)
  77. {
  78. $bUpdateAllowed = UserRights::IsActionAllowedOnAttribute($sClass, $sRemoteExtKey, UR_ACTION_MODIFY, DBObjectSet::FromObject($oToReset));
  79. if (!$bUpdateAllowed)
  80. {
  81. $bFoundStopper = true;
  82. $aForbiddenKeys[] = $aRemoteAttDef->GetLabel();
  83. }
  84. $aExtKeyLabels[] = $aRemoteAttDef->GetLabel();
  85. }
  86. $aResetedObjs[$sRemoteClass][$iId]['attributes_list'] = implode(', ', $aExtKeyLabels);
  87. $aTotalResetedObjs[$sRemoteClass][$iId]['attributes_list'] = $aResetedObjs[$sRemoteClass][$iId]['attributes_list'];
  88. $aTotalResetedObjs[$sRemoteClass][$iId]['attributes'] = $aResetedObjs[$sRemoteClass][$iId]['attributes'];
  89. if (count($aForbiddenKeys) > 0)
  90. {
  91. $aTotalResetedObjs[$sRemoteClass][$iId]['issue'] = Dict::Format('UI:Delete:NotAllowedToUpdate_Fields',implode(', ', $aForbiddenKeys));
  92. }
  93. else
  94. {
  95. $aTotalResetedObjs[$sRemoteClass][$iId]['to_reset'] = $oToReset;
  96. }
  97. }
  98. }
  99. // Count of dependent objects (+ the current one)
  100. $iTotalTargets = $iTotalDelete + $iTotalReset;
  101. }
  102. if ($bDeleteConfirmed)
  103. {
  104. if (count($aObjects) == 1)
  105. {
  106. $oObj = $aObjects[0];
  107. $oP->add("<h1>".Dict::Format('UI:Title:DeletionOf_Object', $oObj->GetName())."</h1>\n");
  108. }
  109. else
  110. {
  111. $oP->add("<h1>".Dict::Format('UI:Title:BulkDeletionOf_Count_ObjectsOf_Class', count($aObjects), MetaModel::GetName($sClass))."</h1>\n");
  112. }
  113. // Security - do not allow the user to force a forbidden delete by the mean of page arguments...
  114. if ($bFoundStopper)
  115. {
  116. throw new CoreException(Dict::S('UI:Error:NotEnoughRightsToDelete'));
  117. }
  118. if ($bFoundManual)
  119. {
  120. throw new CoreException(Dict::S('UI:Error:CannotDeleteBecauseOfDepencies'));
  121. }
  122. // Prepare the change reporting
  123. //
  124. $oMyChange = MetaModel::NewObject("CMDBChange");
  125. $oMyChange->Set("date", time());
  126. if (UserRights::IsImpersonated())
  127. {
  128. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  129. }
  130. else
  131. {
  132. $sUserString = UserRights::GetUser();
  133. }
  134. $oMyChange->Set("userinfo", $sUserString);
  135. $oMyChange->DBInsert();
  136. // Delete dependencies
  137. //
  138. $aDisplayData = array();
  139. foreach ($aTotalDeletedObjs as $sRemoteClass => $aDeletes)
  140. {
  141. foreach ($aDeletes as $iId => $aData)
  142. {
  143. $oToDelete = $aData['to_delete'];
  144. $aDisplayData[] = array(
  145. 'class' => MetaModel::GetName(get_class($oToDelete)),
  146. 'object' => $oToDelete->GetHyperLink(),
  147. 'consequence' => Dict::S('UI:Delete:AutomaticallyDeleted'),
  148. );
  149. $oToDelete->DBDeleteTracked($oMyChange);
  150. }
  151. }
  152. // Update dependencies
  153. //
  154. foreach ($aTotalResetedObjs as $sRemoteClass => $aToReset)
  155. {
  156. foreach ($aToReset as $iId => $aData)
  157. {
  158. $oToReset = $aData['to_reset'];
  159. $aDisplayData[] = array(
  160. 'class' => MetaModel::GetName(get_class($oToReset)),
  161. 'object' => $oToReset->GetHyperLink(),
  162. 'consequence' => Dict::Format('UI:Delete:AutomaticResetOf_Fields', $aData['attributes_list']),
  163. );
  164. foreach ($aData['attributes'] as $sRemoteExtKey => $aRemoteAttDef)
  165. {
  166. $oToReset->Set($sRemoteExtKey, 0);
  167. $oToReset->DBUpdateTracked($oMyChange);
  168. }
  169. }
  170. }
  171. // Report automatic jobs
  172. //
  173. if ($iTotalTargets > 0)
  174. {
  175. if (count($aObjects) == 1)
  176. {
  177. $oObj = $aObjects[0];
  178. $oP->p(Dict::Format('UI:Delete:CleaningUpRefencesTo_Object', $oObj->GetName()));
  179. }
  180. else
  181. {
  182. $oP->p(Dict::Format('UI:Delete:CleaningUpRefencesTo_Several_ObjectsOf_Class', count($aObjects), MetaModel::GetName($sClass)));
  183. }
  184. $aDisplayConfig = array();
  185. $aDisplayConfig['class'] = array('label' => 'Class', 'description' => '');
  186. $aDisplayConfig['object'] = array('label' => 'Object', 'description' => '');
  187. $aDisplayConfig['consequence'] = array('label' => 'Done', 'description' => Dict::S('UI:Delete:Done+'));
  188. $oP->table($aDisplayConfig, $aDisplayData);
  189. }
  190. foreach($aObjects as $oObj)
  191. {
  192. $sName = $oObj->GetName();
  193. $sClassLabel = MetaModel::GetName(get_class($oObj));
  194. $oObj->DBDeleteTracked($oMyChange);
  195. $oP->add("<h1>".Dict::Format('UI:Delete:_Name_Class_Deleted', $sName, $sClassLabel)."</h1>\n");
  196. }
  197. }
  198. else
  199. {
  200. if (count($aObjects) == 1)
  201. {
  202. $oObj = $aObjects[0];
  203. $oP->add("<h1>".Dict::Format('UI:Delete:ConfirmDeletionOf_Name', $oObj->GetName())."</h1>\n");
  204. }
  205. else
  206. {
  207. $oP->add("<h1>".Dict::Format('UI:Delete:ConfirmDeletionOf_Count_ObjectsOf_Class', count($aObjects), MetaModel::GetName($sClass))."</h1>\n");
  208. }
  209. // Explain what should be done
  210. //
  211. $aDisplayData = array();
  212. foreach ($aTotalDeletedObjs as $sRemoteClass => $aDeletes)
  213. {
  214. foreach ($aDeletes as $iId => $aData)
  215. {
  216. $oToDelete = $aData['to_delete'];
  217. $bAutoDel = $aData['auto_delete'];
  218. if (array_key_exists('issue', $aData))
  219. {
  220. if ($bAutoDel)
  221. {
  222. $sConsequence = Dict::S('UI:Delete:ShouldBeDeletedAtomaticallyButNotAllowed');
  223. }
  224. else
  225. {
  226. $sConsequence = Dict::S('UI:Delete:MustBeDeletedManuallyButNotAllowed');
  227. }
  228. }
  229. else
  230. {
  231. if ($bAutoDel)
  232. {
  233. $sConsequence = Dict::S('UI:Delete:WillBeDeletedAutomatically');
  234. }
  235. else
  236. {
  237. $sConsequence = Dict::S('UI:Delete:MustBeDeletedManually');
  238. }
  239. }
  240. $aDisplayData[] = array(
  241. 'class' => MetaModel::GetName(get_class($oToDelete)),
  242. 'object' => $oToDelete->GetHyperLink(),
  243. 'consequence' => $sConsequence,
  244. );
  245. }
  246. }
  247. foreach ($aTotalResetedObjs as $sRemoteClass => $aToReset)
  248. {
  249. foreach ($aToReset as $iId => $aData)
  250. {
  251. $oToReset = $aData['to_reset'];
  252. if (array_key_exists('issue', $aData))
  253. {
  254. $sConsequence = Dict::Format('UI:Delete:CannotUpdateBecause_Issue', $aData['issue']);
  255. }
  256. else
  257. {
  258. $sConsequence = Dict::Format('UI:Delete:WillAutomaticallyUpdate_Fields', $aData['attributes_list']);
  259. }
  260. $aDisplayData[] = array(
  261. 'class' => MetaModel::GetName(get_class($oToReset)),
  262. 'object' => $oToReset->GetHyperLink(),
  263. 'consequence' => $sConsequence,
  264. );
  265. }
  266. }
  267. if ($iTotalTargets > 0)
  268. {
  269. if (count($aObjects) == 1)
  270. {
  271. $oObj = $aObjects[0];
  272. $oP->p(Dict::Format('UI:Delete:Count_Objects/LinksReferencing_Object', $iTotalTargets, $oObj->GetName()));
  273. }
  274. else
  275. {
  276. $oP->p(Dict::Format('UI:Delete:Count_Objects/LinksReferencingTheObjects', $iTotalTargets));
  277. }
  278. $oP->p(Dict::S('UI:Delete:ReferencesMustBeDeletedToEnsureIntegrity'));
  279. $aDisplayConfig = array();
  280. $aDisplayConfig['class'] = array('label' => 'Class', 'description' => '');
  281. $aDisplayConfig['object'] = array('label' => 'Object', 'description' => '');
  282. $aDisplayConfig['consequence'] = array('label' => 'Consequence', 'description' => Dict::S('UI:Delete:Consequence+'));
  283. $oP->table($aDisplayConfig, $aDisplayData);
  284. }
  285. if ($iTotalTargets > 0 && ($bFoundManual || $bFoundStopper))
  286. {
  287. if ($bFoundStopper)
  288. {
  289. $oP->p(Dict::S('UI:Delete:SorryDeletionNotAllowed'));
  290. }
  291. elseif ($bFoundManual)
  292. {
  293. $oP->p(Dict::S('UI:Delete:PleaseDoTheManualOperations'));
  294. }
  295. $oP->add("<form method=\"post\">\n");
  296. $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::ReadParam('transaction_id')."\">\n");
  297. $oP->add("<input type=\"button\" onclick=\"window.history.back();\" value=\"".Dict::S('UI:Button:Back')."\">\n");
  298. $oP->add("<input DISABLED type=\"submit\" name=\"\" value=\"".Dict::S('UI:Button:Delete')."\">\n");
  299. $oP->add("</form>\n");
  300. }
  301. else
  302. {
  303. if (count($aObjects) == 1)
  304. {
  305. $oObj = $aObjects[0];
  306. $id = $oObj->GetKey();
  307. $oP->p('<h1>'.Dict::Format('UI:Delect:Confirm_Object', $oObj->GetHyperLink()).'</h1>');
  308. $oP->add("<form method=\"post\">\n");
  309. $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::ReadParam('transaction_id')."\">\n");
  310. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"delete_confirmed\">\n");
  311. $oP->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">\n");
  312. $oP->add("<input type=\"hidden\" name=\"id\" value=\"$id\">\n");
  313. $oP->add("<input type=\"button\" onclick=\"window.history.back();\" value=\"".Dict::S('UI:Button:Back')."\">\n");
  314. $oP->add("<input type=\"submit\" name=\"\" value=\"".Dict::S('UI:Button:Delete')."\">\n");
  315. $oP->add("</form>\n");
  316. }
  317. else
  318. {
  319. $oP->p('<h1>'.Dict::Format('UI:Delect:Confirm_Count_ObjectsOf_Class', count($aObjects), MetaModel::GetName($sClass)).'</h1>');
  320. $oSet = CMDBobjectSet::FromArray($sClass, $aObjects);
  321. CMDBAbstractObject::DisplaySet($oP, $oSet, array('display_limit' => false, 'menu' => false));
  322. $oP->add("<form method=\"post\">\n");
  323. $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::ReadParam('transaction_id')."\">\n");
  324. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"bulk_delete_confirmed\">\n");
  325. $oP->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">\n");
  326. foreach($aObjects as $oObj)
  327. {
  328. $oP->add("<input type=\"hidden\" name=\"selectObject[]\" value=\"".$oObj->GetKey()."\">\n");
  329. }
  330. $oP->add("<input type=\"button\" onclick=\"window.history.back();\" value=\"".Dict::S('UI:Button:Back')."\">\n");
  331. $oP->add("<input type=\"submit\" name=\"\" value=\"".Dict::S('UI:Button:Delete')."\">\n");
  332. $oP->add("</form>\n");
  333. }
  334. }
  335. }
  336. }
  337. /**
  338. * Updates an object from the POSTed parameters
  339. */
  340. function UpdateObject(&$oObj)
  341. {
  342. foreach(MetaModel::ListAttributeDefs(get_class($oObj)) as $sAttCode=>$oAttDef)
  343. {
  344. if ($oAttDef->IsLinkSet() && $oAttDef->IsIndirect())
  345. {
  346. $aLinks = utils::ReadPostedParam("attr_$sAttCode", '');
  347. $sLinkedClass = $oAttDef->GetLinkedClass();
  348. $sExtKeyToRemote = $oAttDef->GetExtKeyToRemote();
  349. $sExtKeyToMe = $oAttDef->GetExtKeyToMe();
  350. $oLinkedSet = DBObjectSet::FromScratch($sLinkedClass);
  351. if (is_array($aLinks))
  352. {
  353. foreach($aLinks as $id => $aData)
  354. {
  355. if (is_numeric($id))
  356. {
  357. if ($id < 0)
  358. {
  359. // New link to be created, the opposite of the id (-$id) is the ID of the remote object
  360. $oLink = MetaModel::NewObject($sLinkedClass);
  361. $oLink->Set($sExtKeyToRemote, -$id);
  362. $oLink->Set($sExtKeyToMe, $oObj->GetKey());
  363. }
  364. else
  365. {
  366. // Existing link, potentially to be updated...
  367. $oLink = MetaModel::GetObject($sLinkedClass, $id);
  368. }
  369. // Now populate the attributes
  370. foreach($aData as $sName => $value)
  371. {
  372. if (MetaModel::IsValidAttCode($sLinkedClass, $sName))
  373. {
  374. $oLinkAttDef = MetaModel::GetAttributeDef($sLinkedClass, $sName);
  375. if ($oLinkAttDef->IsWritable())
  376. {
  377. $oLink->Set($sName, $value);
  378. }
  379. }
  380. }
  381. $oLinkedSet->AddObject($oLink);
  382. }
  383. }
  384. }
  385. $oObj->Set($sAttCode, $oLinkedSet);
  386. }
  387. else if ($oAttDef->IsWritable())
  388. {
  389. $iFlags = $oObj->GetAttributeFlags($sAttCode);
  390. if ($iFlags & (OPT_ATT_HIDDEN | OPT_ATT_READONLY))
  391. {
  392. // Non-visible, or read-only attribute, do nothing
  393. }
  394. elseif ($oAttDef->GetEditClass() == 'Document')
  395. {
  396. // There should be an uploaded file with the named attr_<attCode>
  397. $oDocument = utils::ReadPostedDocument('file_'.$sAttCode);
  398. if (!$oDocument->IsEmpty())
  399. {
  400. // A new file has been uploaded
  401. $oObj->Set($sAttCode, $oDocument);
  402. }
  403. }
  404. elseif ($oAttDef->GetEditClass() == 'One Way Password')
  405. {
  406. // Check if the password was typed/changed
  407. $bChanged = utils::ReadPostedParam("attr_{$sAttCode}_changed", false);
  408. if ($bChanged)
  409. {
  410. // The password has been changed or set
  411. $rawValue = utils::ReadPostedParam("attr_$sAttCode", null);
  412. $oObj->Set($sAttCode, $rawValue);
  413. }
  414. }
  415. else
  416. {
  417. $rawValue = utils::ReadPostedParam("attr_$sAttCode", null);
  418. if (!is_null($rawValue))
  419. {
  420. $aAttributes[$sAttCode] = trim($rawValue);
  421. $previousValue = $oObj->Get($sAttCode);
  422. if ($previousValue !== $aAttributes[$sAttCode])
  423. {
  424. $oObj->Set($sAttCode, $aAttributes[$sAttCode]);
  425. }
  426. }
  427. }
  428. }
  429. }
  430. }
  431. /**
  432. * Displays a popup welcome message, once per session at maximum
  433. * until the user unchecks the "Display welcome at startup"
  434. * @param WebPage $oP The current web page for the display
  435. * @return void
  436. */
  437. function DisplayWelcomePopup(WebPage $oP)
  438. {
  439. if (!isset($_SESSION['welcome']))
  440. {
  441. // Check, only once per session, if the popup should be displayed...
  442. // If the user did not already ask for hiding it forever
  443. $bPopup = appUserPreferences::GetPref('welcome_popup', true);
  444. if ($bPopup)
  445. {
  446. $sTemplate = @file_get_contents('../application/templates/welcome_popup.html');
  447. if ($sTemplate !== false)
  448. {
  449. $oTemplate = new DisplayTemplate($sTemplate);
  450. $oP->add("<div id=\"welcome_popup\">");
  451. $oTemplate->Render($oP, array());
  452. $oP->add("<p style=\"float:left\"><input type=\"checkbox\" checked id=\"display_welcome_popup\"/><label for=\"display_welcome_popup\">&nbsp;".Dict::S('UI:DisplayThisMessageAtStartup')."</label></p>\n");
  453. $oP->add("<p style=\"float:right\"><input type=\"button\" value=\"".Dict::S('UI:Button:Ok')."\" onClick=\"$('#welcome_popup').dialog('close');\"/>\n");
  454. $oP->add("</div>\n");
  455. $sTitle = addslashes(Dict::S('UI:WelcomeMenu:Title'));
  456. $oP->add_ready_script(
  457. <<<EOF
  458. $('#welcome_popup').dialog( { width:'80%', title: '$sTitle', autoOpen: true, modal:true,
  459. close: function() {
  460. var bDisplay = $('#display_welcome_popup:checked').length;
  461. SetUserPreference('welcome_popup', bDisplay, true);
  462. }
  463. });
  464. EOF
  465. );
  466. $_SESSION['welcome'] = 'ok';
  467. }
  468. }
  469. }
  470. }
  471. /***********************************************************************************
  472. *
  473. * Main user interface page, starts here
  474. *
  475. * ***********************************************************************************/
  476. try
  477. {
  478. require_once('../approot.inc.php');
  479. require_once(APPROOT.'/application/application.inc.php');
  480. require_once(APPROOT.'/application/itopwebpage.class.inc.php');
  481. require_once(APPROOT.'/application/wizardhelper.class.inc.php');
  482. require_once(APPROOT.'/application/startup.inc.php');
  483. $operation = utils::ReadParam('operation', '');
  484. $oKPI = new ExecutionKPI();
  485. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  486. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  487. $oAppContext = new ApplicationContext();
  488. $oKPI->ComputeAndReport('User login');
  489. $oP = new iTopWebPage(Dict::S('UI:WelcomeToITop'));
  490. switch($operation)
  491. {
  492. case 'details':
  493. $sClass = utils::ReadParam('class', '');
  494. $sClassLabel = MetaModel::GetName($sClass);
  495. $id = utils::ReadParam('id', '');
  496. $oSearch = new DBObjectSearch($sClass);
  497. $oBlock = new DisplayBlock($oSearch, 'search', false);
  498. $oBlock->Display($oP, 0);
  499. if ( empty($sClass) || empty($id)) // TO DO: check that the class name is valid !
  500. {
  501. throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
  502. }
  503. $oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
  504. if (is_null($oObj))
  505. {
  506. $oP->set_title(Dict::S('UI:ErrorPageTitle'));
  507. $oP->P(Dict::S('UI:ObjectDoesNotExist'));
  508. }
  509. else
  510. {
  511. // The object could be listed, check if it is actually allowed to view it
  512. $oSet = CMDBObjectSet::FromObject($oObj);
  513. if (UserRights::IsActionAllowed($sClass, UR_ACTION_READ, $oSet) == UR_ALLOWED_NO)
  514. {
  515. throw new SecurityException('User not allowed to view this object', array('class' => $sClass, 'id' => $id));
  516. }
  517. $oP->set_title(Dict::Format('UI:DetailsPageTitle', $oObj->GetName(), $sClassLabel));
  518. $oObj->DisplayDetails($oP);
  519. }
  520. break;
  521. case 'search_oql':
  522. $sOQLClass = utils::ReadParam('oql_class', '');
  523. $sOQLClause = utils::ReadParam('oql_clause', '');
  524. $sFormat = utils::ReadParam('format', '');
  525. $bSearchForm = utils::ReadParam('search_form', true);
  526. if (empty($sOQLClass))
  527. {
  528. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'oql_class'));
  529. }
  530. $oP->set_title(Dict::S('UI:SearchResultsPageTitle'));
  531. $sOQL = "SELECT $sOQLClass $sOQLClause";
  532. try
  533. {
  534. $oFilter = DBObjectSearch::FromOQL($sOQL); // To Do: Make sure we don't bypass security
  535. $oSet = new DBObjectSet($oFilter);
  536. if ($bSearchForm)
  537. {
  538. $oBlock = new DisplayBlock($oFilter, 'search', false);
  539. $oBlock->Display($oP, 0);
  540. }
  541. if (strtolower($sFormat) == 'csv')
  542. {
  543. $oBlock = new DisplayBlock($oFilter, 'csv', false);
  544. $oBlock->Display($oP, 'csv');
  545. $oPage->add_ready_script(" $('#csv').css('height', '95%');"); // adjust the size of the block
  546. }
  547. else
  548. {
  549. $oBlock = new DisplayBlock($oFilter, 'list', false);
  550. $oBlock->Display($oP, 1);
  551. }
  552. }
  553. catch(CoreException $e)
  554. {
  555. $oFilter = new DBObjectSearch($sOQLClass); // To Do: Make sure we don't bypass security
  556. $oSet = new DBObjectSet($oFilter);
  557. if ($bSearchForm)
  558. {
  559. $oBlock = new DisplayBlock($oFilter, 'search', false);
  560. $oBlock->Display($oP, 0);
  561. }
  562. $oP->P('<b>'.Dict::Format('UI:Error:IncorrectOQLQuery_Message', $e->getHtmlDesc()).'</b>');
  563. }
  564. catch(Exception $e)
  565. {
  566. $oP->P('<b>'.Dict::Format('UI:Error:AnErrorOccuredWhileRunningTheQuery_Message', $e->getMessage()).'</b>');
  567. }
  568. break;
  569. case 'search_form':
  570. $sClass = utils::ReadParam('class', '');
  571. $sFormat = utils::ReadParam('format', 'html');
  572. $bSearchForm = utils::ReadParam('search_form', true);
  573. if (empty($sClass))
  574. {
  575. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
  576. }
  577. $oP->set_title(Dict::S('UI:SearchResultsPageTitle'));
  578. $oFilter = new DBObjectSearch($sClass);
  579. $oSet = new DBObjectSet($oFilter);
  580. if ($bSearchForm)
  581. {
  582. $aParams = array('open' => true);
  583. $sBaseClass = utils::ReadParam('baseClass', '');
  584. if (!empty($sBaseClass))
  585. {
  586. $aParams['baseClass'] = $sBaseClass;
  587. }
  588. $oBlock = new DisplayBlock($oFilter, 'search', false /* Asynchronous */, $aParams);
  589. $oBlock->Display($oP, 0);
  590. }
  591. if (strtolower($sFormat) == 'csv')
  592. {
  593. $oBlock = new DisplayBlock($oFilter, 'csv', false);
  594. $oBlock->Display($oP, 1);
  595. $oP->add_ready_script(" $('#csv').css('height', '95%');"); // adjust the size of the block
  596. }
  597. else
  598. {
  599. $oBlock = new DisplayBlock($oFilter, 'list', false);
  600. $oBlock->Display($oP, 1);
  601. }
  602. break;
  603. case 'search':
  604. $sFilter = utils::ReadParam('filter', '');
  605. $sFormat = utils::ReadParam('format', '');
  606. $bSearchForm = utils::ReadParam('search_form', true);
  607. if (empty($sFilter))
  608. {
  609. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'filter'));
  610. }
  611. $oP->set_title(Dict::S('UI:SearchResultsPageTitle'));
  612. // TO DO: limit the search filter by the user context
  613. $oFilter = CMDBSearchFilter::unserialize($sFilter); // TO DO : check that the filter is valid
  614. $oSet = new DBObjectSet($oFilter);
  615. if ($bSearchForm)
  616. {
  617. $oBlock = new DisplayBlock($oFilter, 'search', false);
  618. $oBlock->Display($oP, 0);
  619. }
  620. if (strtolower($sFormat) == 'csv')
  621. {
  622. $oBlock = new DisplayBlock($oFilter, 'csv', false);
  623. $oBlock->Display($oP, 'csv');
  624. $oP->add_ready_script(" $('#csv').css('height', '95%');"); // adjust the size of the block
  625. }
  626. else
  627. {
  628. $oBlock = new DisplayBlock($oFilter, 'list', false);
  629. $oBlock->Display($oP, 1);
  630. }
  631. break;
  632. case 'full_text':
  633. $sFullText = trim(utils::ReadParam('text', ''));
  634. if (empty($sFullText))
  635. {
  636. $oP->p(Dict::S('UI:Search:NoSearch'));
  637. }
  638. else
  639. {
  640. $oP->set_title(Dict::S('UI:SearchResultsPageTitle'));
  641. $oP->p("<h1>".Dict::Format('UI:FullTextSearchTitle_Text', $sFullText)."</h1>");
  642. $iCount = 0;
  643. $iBlock = 0;
  644. // Search in full text mode in all the classes
  645. $aMatches = array();
  646. if (preg_match('/^"(.*)"$/', $sFullText, $aMatches))
  647. {
  648. // The text is surrounded by double-quotes, remove the quotes and treat it as one single expression
  649. $aFullTextNeedles = array($aMatches[1]);
  650. }
  651. else
  652. {
  653. // Split the text on the blanks and treat this as a search for <word1> AND <word2> AND <word3>
  654. $aFullTextNeedles = explode(' ', $sFullText);
  655. }
  656. foreach(MetaModel::GetClasses('searchable') as $sClassName)
  657. {
  658. $oFilter = new DBObjectSearch($sClassName);
  659. foreach($aFullTextNeedles as $sSearchText)
  660. {
  661. $oFilter->AddCondition_FullText($sSearchText);
  662. }
  663. $oSet = new DBObjectSet($oFilter);
  664. if ($oSet->Count() > 0)
  665. {
  666. $aLeafs = array();
  667. while($oObj = $oSet->Fetch())
  668. {
  669. if (get_class($oObj) == $sClassName)
  670. {
  671. $aLeafs[] = $oObj->GetKey();
  672. }
  673. }
  674. $oLeafsFilter = new DBObjectSearch($sClassName);
  675. if (count($aLeafs) > 0)
  676. {
  677. $iCount += count($aLeafs);
  678. $oP->add("<div class=\"page_header\">\n");
  679. $oP->add("<h2>".MetaModel::GetClassIcon($sClassName)."&nbsp;<span class=\"hilite\">".Dict::Format('UI:Search:Count_ObjectsOf_Class_Found', count($aLeafs), Metamodel::GetName($sClassName))."</h2>\n");
  680. $oP->add("</div>\n");
  681. $oLeafsFilter->AddCondition('id', $aLeafs, 'IN');
  682. $oBlock = new DisplayBlock($oLeafsFilter, 'list', false);
  683. $oBlock->Display($oP, $iBlock++);
  684. $oP->P('&nbsp;'); // Some space ?
  685. }
  686. }
  687. }
  688. if ($iCount == 0)
  689. {
  690. $oP->p(Dict::S('UI:Search:NoObjectFound'));
  691. }
  692. }
  693. break;
  694. case 'modify':
  695. $oP->add_linked_script("../js/json.js");
  696. $oP->add_linked_script("../js/forms-json-utils.js");
  697. $oP->add_linked_script("../js/wizardhelper.js");
  698. $oP->add_linked_script("../js/wizard.utils.js");
  699. $oP->add_linked_script("../js/linkswidget.js");
  700. $oP->add_linked_script("../js/autocompletewidget.js");
  701. $oP->add_linked_script("../js/jquery.blockUI.js");
  702. $sClass = utils::ReadParam('class', '');
  703. $sClassLabel = MetaModel::GetName($sClass);
  704. $id = utils::ReadParam('id', '');
  705. if ( empty($sClass) || empty($id)) // TO DO: check that the class name is valid !
  706. {
  707. throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
  708. }
  709. // Check if the user can modify this object
  710. $oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
  711. if (is_null($oObj))
  712. {
  713. $oP->set_title(Dict::S('UI:ErrorPageTitle'));
  714. $oP->P(Dict::S('UI:ObjectDoesNotExist'));
  715. }
  716. else
  717. {
  718. // The object could be read - check if it is allowed to modify it
  719. $oSet = CMDBObjectSet::FromObject($oObj);
  720. if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_NO)
  721. {
  722. throw new SecurityException('User not allowed to modify this object', array('class' => $sClass, 'id' => $id));
  723. }
  724. // Note: code duplicated to the case 'apply_modify' when a data integrity issue has been found
  725. $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
  726. $oP->add("<div class=\"page_header\">\n");
  727. $oP->add("<h1>".$oObj->GetIcon()."&nbsp;".Dict::Format('UI:ModificationTitle_Class_Object', $sClassLabel, $oObj->GetName())."</h1>\n");
  728. $oP->add("</div>\n");
  729. $oP->add("<div class=\"wizContainer\">\n");
  730. $oObj->DisplayModifyForm($oP);
  731. $oP->add("</div>\n");
  732. }
  733. break;
  734. case 'new':
  735. $sClass = utils::ReadParam('class', '');
  736. $sStateCode = utils::ReadParam('state', '');
  737. $bCheckSubClass = utils::ReadParam('checkSubclass', true);
  738. if ( empty($sClass) )
  739. {
  740. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
  741. }
  742. // Note: code duplicated to the case 'apply_modify' when a data integrity issue has been found
  743. $oP->add_linked_script("../js/json.js");
  744. $oP->add_linked_script("../js/forms-json-utils.js");
  745. $oP->add_linked_script("../js/wizardhelper.js");
  746. $oP->add_linked_script("../js/wizard.utils.js");
  747. $oP->add_linked_script("../js/linkswidget.js");
  748. $oP->add_linked_script("../js/autocompletewidget.js");
  749. $oP->add_linked_script("../js/jquery.blockUI.js");
  750. $aArgs = utils::ReadParam('default', array());
  751. $aContext = $oAppContext->GetAsHash();
  752. foreach( $oAppContext->GetNames() as $key)
  753. {
  754. $aArgs[$key] = $oAppContext->GetCurrentValue($key);
  755. }
  756. // If the specified class has subclasses, ask the user an instance of which class to create
  757. $aSubClasses = MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself
  758. $aPossibleClasses = array();
  759. $sRealClass = '';
  760. if ($bCheckSubClass)
  761. {
  762. foreach($aSubClasses as $sCandidateClass)
  763. {
  764. if (!MetaModel::IsAbstract($sCandidateClass) && (UserRights::IsActionAllowed($sCandidateClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES))
  765. {
  766. $aPossibleClasses[$sCandidateClass] = MetaModel::GetName($sCandidateClass);
  767. }
  768. }
  769. // Only one of the subclasses can be instantiated...
  770. if (count($aPossibleClasses) == 1)
  771. {
  772. $aKeys = array_keys($aPossibleClasses);
  773. $sRealClass = $aKeys[0];
  774. }
  775. }
  776. else
  777. {
  778. $sRealClass = $sClass;
  779. }
  780. if (!empty($sRealClass))
  781. {
  782. // Display the creation form
  783. $sClassLabel = MetaModel::GetName($sRealClass);
  784. // Note: some code has been duplicated to the case 'apply_new' when a data integrity issue has been found
  785. $oP->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel));
  786. $oP->add("<h1>".MetaModel::GetClassIcon($sRealClass)."&nbsp;".Dict::Format('UI:CreationTitle_Class', $sClassLabel)."</h1>\n");
  787. $oP->add("<div class=\"wizContainer\">\n");
  788. $aDefaults = utils::ReadParam('default', array());
  789. $aContext = $oAppContext->GetAsHash();
  790. foreach( $oAppContext->GetNames() as $key)
  791. {
  792. $aDefaults[$key] = $oAppContext->GetCurrentValue($key);
  793. }
  794. // Set all the default values in an object and clone this "default" object
  795. $oObjToClone = MetaModel::NewObject($sRealClass);
  796. foreach($aDefaults as $sName => $value)
  797. {
  798. if (MetaModel::IsValidAttCode($sRealClass, $sName))
  799. {
  800. $oAttDef = MetaModel::GetAttributeDef($sRealClass, $sName);
  801. if ($oAttDef->IsWritable())
  802. {
  803. $oObjToClone->Set($sName, $value);
  804. }
  805. }
  806. }
  807. cmdbAbstractObject::DisplayCreationForm($oP, $sRealClass, $oObjToClone, array('default' => $aDefaults));
  808. $oP->add("</div>\n");
  809. }
  810. else
  811. {
  812. // Select the derived class to create
  813. $sClassLabel = MetaModel::GetName($sClass);
  814. $oP->add("<h1>".MetaModel::GetClassIcon($sClass)."&nbsp;".Dict::Format('UI:CreationTitle_Class', $sClassLabel)."</h1>\n");
  815. $oP->add("<div class=\"wizContainer\">\n");
  816. $oP->add('<form>');
  817. $oP->add('<p>'.Dict::Format('UI:SelectTheTypeOf_Class_ToCreate', $sClassLabel));
  818. $aDefaults = utils::ReadParam('default', array());
  819. $oP->add($oAppContext->GetForForm());
  820. $oP->add("<input type=\"hidden\" name=\"checkSubclass\" value=\"0\">\n");
  821. $oP->add("<input type=\"hidden\" name=\"state\" value=\"$sStateCode\">\n");
  822. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"new\">\n");
  823. foreach($aDefaults as $key => $value)
  824. {
  825. $oP->add("<input type=\"hidden\" name=\"default[$key]\" value=\"$value\">\n");
  826. $aDefaults[$key] = $value;
  827. }
  828. $oP->add('<select name="class">');
  829. asort($aPossibleClasses);
  830. foreach($aPossibleClasses as $sClassName => $sClassLabel)
  831. {
  832. $sSelected = ($sClassName == $sClass) ? 'selected' : '';
  833. $oP->add("<option $sSelected value=\"$sClassName\">$sClassLabel</option>");
  834. }
  835. $oP->add('</select>');
  836. $oP->add("&nbsp; <input type=\"submit\" value=\"".Dict::S('UI:Button:Apply')."\"></p>");
  837. $oP->add('</form>');
  838. $oP->add("</div>\n");
  839. }
  840. break;
  841. case 'apply_modify':
  842. $sClass = utils::ReadPostedParam('class', '');
  843. $sClassLabel = MetaModel::GetName($sClass);
  844. $id = utils::ReadPostedParam('id', '');
  845. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  846. if ( empty($sClass) || empty($id)) // TO DO: check that the class name is valid !
  847. {
  848. throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
  849. }
  850. $bDisplayDetails = true;
  851. $oObj = MetaModel::GetObject($sClass, $id, false);
  852. if ($oObj == null)
  853. {
  854. $bDisplayDetails = false;
  855. $oP->set_title(Dict::S('UI:ErrorPageTitle'));
  856. $oP->P(Dict::S('UI:ObjectDoesNotExist'));
  857. }
  858. elseif (!utils::IsTransactionValid($sTransactionId, false))
  859. {
  860. $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
  861. $oP->p("<strong>".Dict::S('UI:Error:ObjectAlreadyUpdated')."</strong>\n");
  862. }
  863. else
  864. {
  865. UpdateObject($oObj);
  866. if (!$oObj->IsModified())
  867. {
  868. $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
  869. $oP->p(Dict::Format('UI:Class_Object_NotUpdated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()));
  870. }
  871. else
  872. {
  873. list($bRes, $aIssues) = $oObj->CheckToWrite();
  874. if ($bRes)
  875. {
  876. $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
  877. $oP->add("<h1>".Dict::Format('UI:ModificationTitle_Class_Object', $sClassLabel, $oObj->GetName())."</h1>\n");
  878. $oMyChange = MetaModel::NewObject("CMDBChange");
  879. $oMyChange->Set("date", time());
  880. if (UserRights::IsImpersonated())
  881. {
  882. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  883. }
  884. else
  885. {
  886. $sUserString = UserRights::GetUser();
  887. }
  888. $oMyChange->Set("userinfo", $sUserString);
  889. $iChangeId = $oMyChange->DBInsert();
  890. $oObj->DBUpdateTracked($oMyChange);
  891. utils::RemoveTransaction($sTransactionId);
  892. $oP->p(Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()));
  893. }
  894. else
  895. {
  896. $bDisplayDetails = false;
  897. // Found issues, explain and give the user a second chance
  898. //
  899. // Note: code duplicated from the case 'modify'
  900. $oP->add_linked_script("../js/json.js");
  901. $oP->add_linked_script("../js/forms-json-utils.js");
  902. $oP->add_linked_script("../js/wizardhelper.js");
  903. $oP->add_linked_script("../js/wizard.utils.js");
  904. $oP->add_linked_script("../js/linkswidget.js");
  905. $oP->add_linked_script("../js/autocompletewidget.js");
  906. $oP->add_linked_script("../js/jquery.blockUI.js");
  907. $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
  908. $oP->add("<div class=\"page_header\">\n");
  909. $oP->add("<h1>".$oObj->GetIcon()."&nbsp;".Dict::Format('UI:ModificationTitle_Class_Object', $sClassLabel, $oObj->GetName())."</h1>\n");
  910. $oP->add("</div>\n");
  911. $oP->add("<div class=\"wizContainer\">\n");
  912. $oObj->DisplayModifyForm($oP);
  913. $oP->add("</div>\n");
  914. $sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten', implode(', ', $aIssues));
  915. $oP->add_ready_script("alert('".addslashes($sIssueDesc)."');");
  916. }
  917. }
  918. }
  919. if ($bDisplayDetails)
  920. {
  921. $oObj = MetaModel::GetObject(get_class($oObj), $oObj->GetKey()); //Workaround: reload the object so that the linkedset are displayed properly
  922. $oObj->DisplayDetails($oP);
  923. }
  924. break;
  925. case 'select_for_deletion':
  926. $sFilter = utils::ReadParam('filter', '');
  927. $sFormat = utils::ReadParam('format', '');
  928. if (empty($sFilter))
  929. {
  930. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'filter'));
  931. }
  932. $oP->set_title(Dict::S('UI:BulkDeletePageTitle'));
  933. $oP->add("<h1>".Dict::S('UI:BulkDeleteTitle')."</h1>\n");
  934. // TO DO: limit the search filter by the user context
  935. $oFilter = CMDBSearchFilter::unserialize($sFilter); // TO DO : check that the filter is valid
  936. $oSet = new DBObjectSet($oFilter);
  937. $oBlock = new DisplayBlock($oFilter, 'list', false);
  938. $oP->add("<form method=\"post\">\n");
  939. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"bulk_delete\">\n");
  940. $oP->add("<input type=\"hidden\" name=\"class\" value=\"".$oFilter->GetClass()."\">\n");
  941. $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
  942. $oBlock->Display($oP, 1, array('selection_type' => 'multiple', 'selection_mode' => true, 'display_limit' => false, 'menu' => false));
  943. $oP->add("<input type=\"button\" value=\"".Dict::S('UI:Button:Cancel')."\" onClick=\"window.history.back()\">&nbsp;&nbsp;<input type=\"submit\" value=\"".Dict::S('UI:Button:Next')."\">\n");
  944. $oP->add("</form>\n");
  945. break;
  946. case 'bulk_delete_confirmed':
  947. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  948. if (!utils::IsTransactionValid($sTransactionId))
  949. {
  950. throw new ApplicationException(Dict::S('UI:Error:ObjectsAlreadyDeleted'));
  951. }
  952. case 'bulk_delete':
  953. $sClass = utils::ReadPostedParam('class', '');
  954. $sClassLabel = MetaModel::GetName($sClass);
  955. $aSelectObject = utils::ReadPostedParam('selectObject', '');
  956. $aObjects = array();
  957. if ( empty($sClass) || empty($aSelectObject)) // TO DO: check that the class name is valid !
  958. {
  959. throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'selectObject[]'));
  960. }
  961. foreach($aSelectObject as $iId)
  962. {
  963. $aObjects[] = MetaModel::GetObject($sClass, $iId);
  964. }
  965. if (!UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, DBObjectSet::FromArray($sClass, $aObjects)))
  966. {
  967. throw new SecurityException(Dict::Format('UI:Error:BulkDeleteNotAllowedOn_Class', $sClass));
  968. }
  969. $oP->set_title(Dict::S('UI:BulkDeletePageTitle'));
  970. DeleteObjects($oP, $sClass, $aObjects, ($operation == 'bulk_delete_confirmed'));
  971. break;
  972. case 'delete':
  973. case 'delete_confirmed':
  974. $sClass = utils::ReadParam('class', '');
  975. $sClassLabel = MetaModel::GetName($sClass);
  976. $id = utils::ReadParam('id', '');
  977. $oObj = MetaModel::GetObject($sClass, $id);
  978. if (!UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, DBObjectSet::FromObject($oObj)))
  979. {
  980. throw new SecurityException(Dict::Format('UI:Error:DeleteNotAllowedOn_Class', $sClass));
  981. }
  982. DeleteObjects($oP, $sClass, array($oObj), ($operation == 'delete_confirmed'));
  983. break;
  984. case 'apply_new':
  985. $sClass = utils::ReadPostedParam('class', '');
  986. $sClassLabel = MetaModel::GetName($sClass);
  987. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  988. if ( empty($sClass) ) // TO DO: check that the class name is valid !
  989. {
  990. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
  991. }
  992. if (!utils::IsTransactionValid($sTransactionId, false))
  993. {
  994. $oP->p("<strong>".Dict::S('UI:Error:ObjectAlreadyCreated')."</strong>\n");
  995. }
  996. else
  997. {
  998. $oObj = MetaModel::NewObject($sClass);
  999. UpdateObject($oObj);
  1000. }
  1001. if (isset($oObj) && is_object($oObj))
  1002. {
  1003. $sClass = get_class($oObj);
  1004. $sClassLabel = MetaModel::GetName($sClass);
  1005. list($bRes, $aIssues) = $oObj->CheckToWrite();
  1006. if ($bRes)
  1007. {
  1008. $oMyChange = MetaModel::NewObject("CMDBChange");
  1009. $oMyChange->Set("date", time());
  1010. if (UserRights::IsImpersonated())
  1011. {
  1012. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  1013. }
  1014. else
  1015. {
  1016. $sUserString = UserRights::GetUser();
  1017. }
  1018. $oMyChange->Set("userinfo", $sUserString);
  1019. $iChangeId = $oMyChange->DBInsert();
  1020. $oObj->DBInsertTracked($oMyChange);
  1021. utils::RemoveTransaction($sTransactionId);
  1022. $oP->set_title(Dict::S('UI:PageTitle:ObjectCreated'));
  1023. $oP->add("<h1>".Dict::Format('UI:Title:Object_Of_Class_Created', $oObj->GetName(), $sClassLabel)."</h1>\n");
  1024. $oObj->DisplayDetails($oP);
  1025. }
  1026. else
  1027. {
  1028. // Found issues, explain and give the user a second chance
  1029. //
  1030. // Note: code similar to the case 'modify'
  1031. $oP->add_linked_script("../js/json.js");
  1032. $oP->add_linked_script("../js/forms-json-utils.js");
  1033. $oP->add_linked_script("../js/wizardhelper.js");
  1034. $oP->add_linked_script("../js/wizard.utils.js");
  1035. $oP->add_linked_script("../js/linkswidget.js");
  1036. $oP->add_linked_script("../js/autocompletewidget.js");
  1037. $oP->add_linked_script("../js/jquery.blockUI.js");
  1038. $oP->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel));
  1039. $oP->add("<h1>".MetaModel::GetClassIcon($sClass)."&nbsp;".Dict::Format('UI:CreationTitle_Class', $sClassLabel)."</h1>\n");
  1040. $oP->add("<div class=\"wizContainer\">\n");
  1041. cmdbAbstractObject::DisplayCreationForm($oP, $sClass, $oObj);
  1042. $oP->add("</div>\n");
  1043. $sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten', implode(', ', $aIssues));
  1044. $oP->add_ready_script("alert('".addslashes($sIssueDesc)."');");
  1045. }
  1046. }
  1047. break;
  1048. case 'wizard_apply_new':
  1049. $sJson = utils::ReadPostedParam('json_obj', '');
  1050. $oWizardHelper = WizardHelper::FromJSON($sJson);
  1051. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  1052. if (!utils::IsTransactionValid($sTransactionId))
  1053. {
  1054. $oP->p(Dict::S('UI:Error:ObjectAlreadyCreated'));
  1055. }
  1056. else
  1057. {
  1058. $oObj = $oWizardHelper->GetTargetObject(true /* read uploaded files */);
  1059. if (is_object($oObj))
  1060. {
  1061. $sClass = get_class($oObj);
  1062. $sClassLabel = MetaModel::GetName($sClass);
  1063. $oMyChange = MetaModel::NewObject("CMDBChange");
  1064. $oMyChange->Set("date", time());
  1065. if (UserRights::IsImpersonated())
  1066. {
  1067. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  1068. }
  1069. else
  1070. {
  1071. $sUserString = UserRights::GetUser();
  1072. }
  1073. $oMyChange->Set("userinfo", $sUserString);
  1074. $iChangeId = $oMyChange->DBInsert();
  1075. $oObj->DBInsertTracked($oMyChange);
  1076. $oP->set_title(Dict::S('UI:PageTitle:ObjectCreated'));
  1077. $oP->add("<h1>".Dict::Format('UI:Title:Object_Of_Class_Created', $oObj->GetName(), $sClassLabel)."</h1>\n");
  1078. $oObj->DisplayDetails($oP);
  1079. }
  1080. }
  1081. break;
  1082. case 'stimulus':
  1083. $sClass = utils::ReadParam('class', '');
  1084. $id = utils::ReadParam('id', '');
  1085. $sStimulus = utils::ReadParam('stimulus', '');
  1086. if ( empty($sClass) || empty($id) || empty($sStimulus) ) // TO DO: check that the class name is valid !
  1087. {
  1088. throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'class', 'id', 'stimulus'));
  1089. }
  1090. $oObj = MetaModel::GetObject($sClass, $id, false);
  1091. if ($oObj != null)
  1092. {
  1093. $aTransitions = $oObj->EnumTransitions();
  1094. $aStimuli = MetaModel::EnumStimuli($sClass);
  1095. if (!isset($aTransitions[$sStimulus]))
  1096. {
  1097. // Invalid stimulus
  1098. throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $oObj->GetName(), $oObj->GetStateLabel()));
  1099. }
  1100. $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
  1101. $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
  1102. $aTransition = $aTransitions[$sStimulus];
  1103. $sTargetState = $aTransition['target_state'];
  1104. $aTargetStates = MetaModel::EnumStates($sClass);
  1105. $oP->add_linked_script("../js/json.js");
  1106. $oP->add_linked_script("../js/forms-json-utils.js");
  1107. $oP->add_linked_script("../js/wizardhelper.js");
  1108. $oP->add_linked_script("../js/wizard.utils.js");
  1109. $oP->add_linked_script("../js/linkswidget.js");
  1110. $oP->add_linked_script("../js/autocompletewidget.js");
  1111. $oP->add_linked_script("../js/jquery.blockUI.js");
  1112. $oP->add("<div class=\"page_header\">\n");
  1113. $oP->add("<h1>$sActionLabel - <span class=\"hilite\">{$oObj->GetName()}</span></h1>\n");
  1114. $oP->set_title($sActionLabel);
  1115. $oP->add("</div>\n");
  1116. $oObj->DisplayBareProperties($oP);
  1117. $aTargetState = $aTargetStates[$sTargetState];
  1118. $aExpectedAttributes = $aTargetState['attribute_list'];
  1119. $oP->add("<h1>$sActionDetails</h1>\n");
  1120. $oP->add("<div class=\"wizContainer\">\n");
  1121. $oP->add("<form id=\"apply_stimulus\" method=\"post\" onSubmit=\"return CheckFields('apply_stimulus', true);\">\n");
  1122. $aDetails = array();
  1123. $iFieldIndex = 0;
  1124. $aFieldsMap = array();
  1125. foreach($aExpectedAttributes as $sAttCode => $iExpectCode)
  1126. {
  1127. // Prompt for an attribute if
  1128. // - the attribute must be changed or must be displayed to the user for confirmation
  1129. // - or the field is mandatory and currently empty
  1130. if ( ($iExpectCode & (OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT)) ||
  1131. (($iExpectCode & OPT_ATT_MANDATORY) && ($oObj->Get($sAttCode) == '')) )
  1132. {
  1133. $aAttributesDef = MetaModel::ListAttributeDefs($sClass);
  1134. $oAttDef = $aAttributesDef[$sAttCode];
  1135. $aArgs = array('this' => $oObj);
  1136. $sHTMLValue = cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $oObj->Get($sAttCode), $oObj->GetEditValue($sAttCode), 'att_'.$iFieldIndex, '', $iExpectCode, $aArgs);
  1137. $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => "<span id=\"field_att_$iFieldIndex\">$sHTMLValue</span>");
  1138. $aFieldsMap[$sAttCode] = 'att_'.$iFieldIndex;
  1139. $iFieldIndex++;
  1140. }
  1141. }
  1142. $oP->details($aDetails);
  1143. $oP->add("<input type=\"hidden\" name=\"id\" value=\"$id\" id=\"id\">\n");
  1144. $aFieldsMap['id'] = 'id';
  1145. $oP->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">\n");
  1146. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"apply_stimulus\">\n");
  1147. $oP->add("<input type=\"hidden\" name=\"stimulus\" value=\"$sStimulus\">\n");
  1148. $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
  1149. $oP->add($oAppContext->GetForForm());
  1150. $oP->add("<button type=\"button\" class=\"action\" onClick=\"BackToDetails('$sClass', $id)\"><span>".Dict::S('UI:Button:Cancel')."</span></button>&nbsp;&nbsp;&nbsp;&nbsp;\n");
  1151. $oP->add("<button type=\"submit\" class=\"action\"><span>$sActionLabel</span></button>\n");
  1152. $oP->add("</form>\n");
  1153. $oP->add("</div>\n");
  1154. $iFieldsCount = count($aFieldsMap);
  1155. $sJsonFieldsMap = json_encode($aFieldsMap);
  1156. $oP->add_script(
  1157. <<<EOF
  1158. // Initializes the object once at the beginning of the page...
  1159. var oWizardHelper = new WizardHelper('$sClass');
  1160. oWizardHelper.SetFieldsMap($sJsonFieldsMap);
  1161. oWizardHelper.SetFieldsCount($iFieldsCount);
  1162. EOF
  1163. );
  1164. $oP->add_ready_script(
  1165. <<<EOF
  1166. // Starts the validation when the page is ready
  1167. CheckFields('apply_stimulus', false);
  1168. EOF
  1169. );
  1170. }
  1171. else
  1172. {
  1173. $oP->set_title(Dict::S('UI:ErrorPageTitle'));
  1174. $oP->P(Dict::S('UI:ObjectDoesNotExist'));
  1175. }
  1176. break;
  1177. case 'apply_stimulus':
  1178. $sClass = utils::ReadPostedParam('class', '');
  1179. $id = utils::ReadPostedParam('id', '');
  1180. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  1181. $sStimulus = utils::ReadPostedParam('stimulus', '');
  1182. if ( empty($sClass) || empty($id) || empty($sStimulus) ) // TO DO: check that the class name is valid !
  1183. {
  1184. throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'class', 'id', 'stimulus'));
  1185. }
  1186. $oObj = MetaModel::GetObject($sClass, $id, false);
  1187. if ($oObj != null)
  1188. {
  1189. $aTransitions = $oObj->EnumTransitions();
  1190. $aStimuli = MetaModel::EnumStimuli($sClass);
  1191. if (!isset($aTransitions[$sStimulus]))
  1192. {
  1193. throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $oObj->GetName(), $oObj->GetStateLabel()));
  1194. }
  1195. if (!utils::IsTransactionValid($sTransactionId))
  1196. {
  1197. $oP->p(Dict::S('UI:Error:ObjectAlreadyUpdated'));
  1198. }
  1199. else
  1200. {
  1201. $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
  1202. $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
  1203. $aTransition = $aTransitions[$sStimulus];
  1204. $sTargetState = $aTransition['target_state'];
  1205. $aTargetStates = MetaModel::EnumStates($sClass);
  1206. //$oP->add("<div class=\"page_header\">\n");
  1207. //$oP->add("<h1>$sActionLabel - <span class=\"hilite\">{$oObj->GetName()}</span></h1>\n");
  1208. //$oP->add("<p>$sActionDetails</p>\n");
  1209. //$oP->p(Dict::Format('UI:Apply_Stimulus_On_Object_In_State_ToTarget_State', $sActionLabel, $oObj->GetName(), $oObj->GetStateLabel(), $sTargetState));
  1210. //$oP->add("</div>\n");
  1211. $aTargetState = $aTargetStates[$sTargetState];
  1212. $aExpectedAttributes = $aTargetState['attribute_list'];
  1213. $aDetails = array();
  1214. foreach($aExpectedAttributes as $sAttCode => $iExpectCode)
  1215. {
  1216. if (($iExpectCode & (OPT_ATT_MUSTCHANGE|OPT_ATT_MUSTPROMPT)) || ($oObj->Get($sAttCode) == '') )
  1217. {
  1218. $paramValue = utils::ReadPostedParam("attr_$sAttCode", '');
  1219. $oObj->Set($sAttCode, $paramValue);
  1220. }
  1221. }
  1222. if ($oObj->ApplyStimulus($sStimulus))
  1223. {
  1224. $oMyChange = MetaModel::NewObject("CMDBChange");
  1225. $oMyChange->Set("date", time());
  1226. if (UserRights::IsImpersonated())
  1227. {
  1228. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  1229. }
  1230. else
  1231. {
  1232. $sUserString = UserRights::GetUser();
  1233. }
  1234. $oMyChange->Set("userinfo", $sUserString);
  1235. $iChangeId = $oMyChange->DBInsert();
  1236. $oObj->DBUpdateTracked($oMyChange);
  1237. $oP->p(Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()));
  1238. }
  1239. }
  1240. $oObj->DisplayDetails($oP);
  1241. }
  1242. else
  1243. {
  1244. $oP->set_title(Dict::S('UI:ErrorPageTitle'));
  1245. $oP->P(Dict::S('UI:ObjectDoesNotExist'));
  1246. }
  1247. break;
  1248. case 'modify_links':
  1249. $sClass = utils::ReadParam('class', '');
  1250. $sLinkAttr = utils::ReadParam('link_attr', '');
  1251. $sTargetClass = utils::ReadParam('target_class', '');
  1252. $id = utils::ReadParam('id', '');
  1253. $bAddObjects = utils::ReadParam('addObjects', false);
  1254. if ( empty($sClass) || empty($id) || empty($sLinkAttr) || empty($sTargetClass)) // TO DO: check that the class name is valid !
  1255. {
  1256. throw new ApplicationException(Dict::Format('UI:Error:4ParametersMissing', 'class', 'id', 'target_class', 'link_attr'));
  1257. }
  1258. require_once(APPROOT.'/application/uilinkswizard.class.inc.php');
  1259. $oWizard = new UILinksWizard($sClass, $sLinkAttr, $id, $sTargetClass);
  1260. $oWizard->Display($oP, array('StartWithAdd' => $bAddObjects));
  1261. break;
  1262. case 'do_modify_links':
  1263. $aLinks = utils::ReadPostedParam('linkId', array());
  1264. $sLinksToRemove = trim(utils::ReadPostedParam('linksToRemove', ''));
  1265. $aLinksToRemove = array();
  1266. if (!empty($sLinksToRemove))
  1267. {
  1268. $aLinksToRemove = explode(' ', trim($sLinksToRemove));
  1269. }
  1270. $sClass = utils::ReadPostedParam('class', '');
  1271. $sLinkageAtt = utils::ReadPostedParam('linkage', '');
  1272. $iObjectId = utils::ReadPostedParam('object_id', '');
  1273. $sLinkingAttCode = utils::ReadPostedParam('linking_attcode', '');
  1274. $oMyChange = MetaModel::NewObject("CMDBChange");
  1275. $oMyChange->Set("date", time());
  1276. if (UserRights::IsImpersonated())
  1277. {
  1278. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  1279. }
  1280. else
  1281. {
  1282. $sUserString = UserRights::GetUser();
  1283. }
  1284. $oMyChange->Set("userinfo", $sUserString);
  1285. $iChangeId = $oMyChange->DBInsert();
  1286. // Delete links that are to be deleted
  1287. foreach($aLinksToRemove as $iLinkId)
  1288. {
  1289. if ($iLinkId > 0) // Negative IDs are objects that were not even created
  1290. {
  1291. $oLink = MetaModel::GetObject($sClass, $iLinkId);
  1292. $oLink->DBDeleteTracked($oMyChange);
  1293. }
  1294. }
  1295. $aEditableFields = array();
  1296. $aData = array();
  1297. foreach(MetaModel::GetAttributesList($sClass) as $sAttCode)
  1298. {
  1299. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1300. if ( (!$oAttDef->IsExternalKey()) && (!$oAttDef->IsExternalField()))
  1301. {
  1302. $aEditableFields[] = $sAttCode;
  1303. $aData[$sAttCode] = utils::ReadParam('attr_'.$sAttCode, array(), 'post');
  1304. }
  1305. }
  1306. // Update existing links or create new links
  1307. foreach($aLinks as $iLinkId)
  1308. {
  1309. if ($iLinkId > 0)
  1310. {
  1311. // This is an existing link to be modified
  1312. $oLink = MetaModel::GetObject($sClass, $iLinkId);
  1313. // Update all the attributes of the link
  1314. foreach($aEditableFields as $sAttCode)
  1315. {
  1316. $value = $aData[$sAttCode][$iLinkId];
  1317. $oLink->Set($sAttCode, $value);
  1318. }
  1319. if ($oLink->IsModified())
  1320. {
  1321. $oLink->DBUpdateTracked($oMyChange);
  1322. }
  1323. //echo "Updated link:<br/>\n";
  1324. //var_dump($oLink);
  1325. }
  1326. else
  1327. {
  1328. // A new link must be created
  1329. $oLink = MetaModel::NewObject($sClass);
  1330. $oLinkedObjectId = -$iLinkId;
  1331. // Set all the attributes of the link
  1332. foreach($aEditableFields as $sAttCode)
  1333. {
  1334. $value = $aData[$sAttCode][$iLinkId];
  1335. $oLink->Set($sAttCode, $value);
  1336. }
  1337. // And the two external keys
  1338. $oLink->Set($sLinkageAtt, $iObjectId);
  1339. $oLink->Set($sLinkingAttCode, $oLinkedObjectId);
  1340. // then save it
  1341. //echo "Created link:<br/>\n";
  1342. //var_dump($oLink);
  1343. $oLink->DBInsertTracked($oMyChange);
  1344. }
  1345. }
  1346. // Display again the details of the linked object
  1347. $oAttDef = MetaModel::GetAttributeDef($sClass, $sLinkageAtt);
  1348. $sTargetClass = $oAttDef->GetTargetClass();
  1349. $oObj = MetaModel::GetObject($sTargetClass, $iObjectId);
  1350. $oSearch = new DBObjectSearch(get_class($oObj));
  1351. $oBlock = new DisplayBlock($oSearch, 'search', false);
  1352. $oBlock->Display($oP, 0);
  1353. $oObj->DisplayDetails($oP);
  1354. break;
  1355. case 'swf_navigator':
  1356. $sClass = utils::ReadParam('class', '');
  1357. $id = utils::ReadParam('id', 0);
  1358. $sRelation = utils::ReadParam('relation', 'impact');
  1359. $oP->AddTabContainer('Navigator');
  1360. $oP->SetCurrentTabContainer('Navigator');
  1361. $oP->SetCurrentTab(Dict::S('UI:RelationshipGraph'));
  1362. $width = 1000;
  1363. $height = 700;
  1364. $sParams = "pWidth=$width&pHeight=$height&drillUrl=".urlencode('../pages/UI.php?operation=details')."&displayController=false&xmlUrl=".urlencode("./xml.navigator.php")."&obj_class=$sClass&obj_id=$id&relation=$sRelation";
  1365. $oP->add("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"$width\" height=\"$height\" id=\"navigator\" align=\"middle\">
  1366. <param name=\"allowScriptAccess\" value=\"sameDomain\" />
  1367. <param name=\"allowFullScreen\" value=\"false\" />
  1368. <param name=\"FlashVars\" value=\"$sParams\" />
  1369. <param name=\"movie\" value=\"../navigator/navigator.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#ffffff\" />
  1370. <embed src=\"../navigator/navigator.swf\" flashVars=\"$sParams\" quality=\"high\" bgcolor=\"#ffffff\" width=\"$width\" height=\"$height\" name=\"navigator\" align=\"middle\" allowScriptAccess=\"sameDomain\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" />
  1371. </object>\n");
  1372. $oP->SetCurrentTab(Dict::S('UI:RelationshipList'));
  1373. $oP->add("<div id=\"impacted_objects\" style=\"width:100%;background-color:#fff;padding:10px;\"><p style=\"height:150px;\">&nbsp;</p></div>");
  1374. $oP->add_ready_script(
  1375. <<<EOF
  1376. var ajax_request = null;
  1377. function UpdateImpactedObjects(sClass, iId, sRelation)
  1378. {
  1379. var class_name = sClass; //$('select[name=class_name]').val();
  1380. if (class_name != '')
  1381. {
  1382. $('#impacted_objects').block();
  1383. // Make sure that we cancel any pending request before issuing another
  1384. // since responses may arrive in arbitrary order
  1385. if (ajax_request != null)
  1386. {
  1387. ajax_request.abort();
  1388. ajax_request = null;
  1389. }
  1390. ajax_request = $.get('xml.navigator.php', { 'class': sClass, id: iId, relation: sRelation, format: 'html' },
  1391. function(data)
  1392. {
  1393. $('#impacted_objects').empty();
  1394. $('#impacted_objects').append(data);
  1395. $('#impacted_objects').unblock();
  1396. $('#impacted_objects .listResults').tablesorter( { widgets: ['myZebra', 'truncatedList']} ); // sortable and zebra tables
  1397. $('#impacted_objects table.listResults').tableHover(); // hover tables
  1398. }
  1399. );
  1400. }
  1401. }
  1402. UpdateImpactedObjects('$sClass', $id, '$sRelation');
  1403. EOF
  1404. );
  1405. $oP->SetCurrentTab('');
  1406. break;
  1407. default:
  1408. $oMenuNode = ApplicationMenu::GetMenuNode(ApplicationMenu::GetActiveNodeId());
  1409. if (is_object($oMenuNode))
  1410. {
  1411. $oMenuNode->RenderContent($oP, $oAppContext->GetAsHash());
  1412. $oP->set_title($oMenuNode->GetLabel());
  1413. }
  1414. }
  1415. $oKPI->ComputeAndReport('GUI creation before output');
  1416. ExecutionKPI::ReportStats();
  1417. MetaModel::ShowQueryTrace();
  1418. DisplayWelcomePopup($oP);
  1419. $oP->output();
  1420. }
  1421. catch(CoreException $e)
  1422. {
  1423. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  1424. $oP = new SetupWebPage(Dict::S('UI:PageTitle:FatalError'));
  1425. if ($e instanceof SecurityException)
  1426. {
  1427. $oP->add("<h1>".Dict::S('UI:SystemIntrusion')."</h1>\n");
  1428. }
  1429. else
  1430. {
  1431. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1432. }
  1433. $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
  1434. $oP->output();
  1435. if (MetaModel::IsLogEnabledIssue())
  1436. {
  1437. if (MetaModel::IsValidClass('EventIssue'))
  1438. {
  1439. try
  1440. {
  1441. $oLog = new EventIssue();
  1442. $oLog->Set('message', $e->getMessage());
  1443. $oLog->Set('userinfo', '');
  1444. $oLog->Set('issue', $e->GetIssue());
  1445. $oLog->Set('impact', 'Page could not be displayed');
  1446. $oLog->Set('callstack', $e->getTrace());
  1447. $oLog->Set('data', $e->getContextData());
  1448. $oLog->DBInsertNoReload();
  1449. }
  1450. catch(Exception $e)
  1451. {
  1452. IssueLog::Error("Failed to log issue into the DB");
  1453. }
  1454. }
  1455. IssueLog::Error($e->getMessage());
  1456. }
  1457. // For debugging only
  1458. //throw $e;
  1459. }
  1460. catch(Exception $e)
  1461. {
  1462. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  1463. $oP = new SetupWebPage(Dict::S('UI:PageTitle:FatalError'));
  1464. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1465. $oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
  1466. $oP->output();
  1467. if (MetaModel::IsLogEnabledIssue())
  1468. {
  1469. if (MetaModel::IsValidClass('EventIssue'))
  1470. {
  1471. try
  1472. {
  1473. $oLog = new EventIssue();
  1474. $oLog->Set('message', $e->getMessage());
  1475. $oLog->Set('userinfo', '');
  1476. $oLog->Set('issue', 'PHP Exception');
  1477. $oLog->Set('impact', 'Page could not be displayed');
  1478. $oLog->Set('callstack', $e->getTrace());
  1479. $oLog->Set('data', array());
  1480. $oLog->DBInsertNoReload();
  1481. }
  1482. catch(Exception $e)
  1483. {
  1484. IssueLog::Error("Failed to log issue into the DB");
  1485. }
  1486. }
  1487. IssueLog::Error($e->getMessage());
  1488. }
  1489. }
  1490. ?>