UI.php 56 KB

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