UI.php 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567
  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('../application/application.inc.php');
  479. require_once('../application/itopwebpage.class.inc.php');
  480. require_once('../application/wizardhelper.class.inc.php');
  481. require_once('../application/startup.inc.php');
  482. $operation = utils::ReadParam('operation', '');
  483. $oKPI = new ExecutionKPI();
  484. require_once('../application/loginwebpage.class.inc.php');
  485. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  486. $oAppContext = new ApplicationContext();
  487. $oKPI->ComputeAndReport('User login');
  488. $oP = new iTopWebPage(Dict::S('UI:WelcomeToITop'));
  489. switch($operation)
  490. {
  491. case 'details':
  492. $sClass = utils::ReadParam('class', '');
  493. $sClassLabel = MetaModel::GetName($sClass);
  494. $id = utils::ReadParam('id', '');
  495. $oSearch = new DBObjectSearch($sClass);
  496. $oBlock = new DisplayBlock($oSearch, 'search', false);
  497. $oBlock->Display($oP, 0);
  498. if ( empty($sClass) || empty($id)) // TO DO: check that the class name is valid !
  499. {
  500. throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
  501. }
  502. $oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
  503. if (is_null($oObj))
  504. {
  505. $oP->set_title(Dict::S('UI:ErrorPageTitle'));
  506. $oP->P(Dict::S('UI:ObjectDoesNotExist'));
  507. }
  508. else
  509. {
  510. // The object could be listed, check if it is actually allowed to view it
  511. $oSet = CMDBObjectSet::FromObject($oObj);
  512. if (UserRights::IsActionAllowed($sClass, UR_ACTION_READ, $oSet) == UR_ALLOWED_NO)
  513. {
  514. throw new SecurityException('User not allowed to view this object', array('class' => $sClass, 'id' => $id));
  515. }
  516. $oP->set_title(Dict::Format('UI:DetailsPageTitle', $oObj->GetName(), $sClassLabel));
  517. $oObj->DisplayDetails($oP);
  518. }
  519. break;
  520. case 'search_oql':
  521. $sOQLClass = utils::ReadParam('oql_class', '');
  522. $sOQLClause = utils::ReadParam('oql_clause', '');
  523. $sFormat = utils::ReadParam('format', '');
  524. $bSearchForm = utils::ReadParam('search_form', true);
  525. if (empty($sOQLClass))
  526. {
  527. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'oql_class'));
  528. }
  529. $oP->set_title(Dict::S('UI:SearchResultsPageTitle'));
  530. $sOQL = "SELECT $sOQLClass $sOQLClause";
  531. try
  532. {
  533. $oFilter = DBObjectSearch::FromOQL($sOQL); // To Do: Make sure we don't bypass security
  534. $oSet = new DBObjectSet($oFilter);
  535. if ($bSearchForm)
  536. {
  537. $oBlock = new DisplayBlock($oFilter, 'search', false);
  538. $oBlock->Display($oP, 0);
  539. }
  540. if (strtolower($sFormat) == 'csv')
  541. {
  542. $oBlock = new DisplayBlock($oFilter, 'csv', false);
  543. $oBlock->Display($oP, 'csv');
  544. $oPage->add_ready_script(" $('#csv').css('height', '95%');"); // adjust the size of the block
  545. }
  546. else
  547. {
  548. $oBlock = new DisplayBlock($oFilter, 'list', false);
  549. $oBlock->Display($oP, 1);
  550. }
  551. }
  552. catch(CoreException $e)
  553. {
  554. $oFilter = new DBObjectSearch($sOQLClass); // To Do: Make sure we don't bypass security
  555. $oSet = new DBObjectSet($oFilter);
  556. if ($bSearchForm)
  557. {
  558. $oBlock = new DisplayBlock($oFilter, 'search', false);
  559. $oBlock->Display($oP, 0);
  560. }
  561. $oP->P('<b>'.Dict::Format('UI:Error:IncorrectOQLQuery_Message', $e->getHtmlDesc()).'</b>');
  562. }
  563. catch(Exception $e)
  564. {
  565. $oP->P('<b>'.Dict::Format('UI:Error:AnErrorOccuredWhileRunningTheQuery_Message', $e->getMessage()).'</b>');
  566. }
  567. break;
  568. case 'search_form':
  569. $sClass = utils::ReadParam('class', '');
  570. $sFormat = utils::ReadParam('format', 'html');
  571. $bSearchForm = utils::ReadParam('search_form', true);
  572. if (empty($sClass))
  573. {
  574. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
  575. }
  576. $oP->set_title(Dict::S('UI:SearchResultsPageTitle'));
  577. $oFilter = new DBObjectSearch($sClass);
  578. $oSet = new DBObjectSet($oFilter);
  579. if ($bSearchForm)
  580. {
  581. $aParams = array('open' => true);
  582. $sBaseClass = utils::ReadParam('baseClass', '');
  583. if (!empty($sBaseClass))
  584. {
  585. $aParams['baseClass'] = $sBaseClass;
  586. }
  587. $oBlock = new DisplayBlock($oFilter, 'search', false /* Asynchronous */, $aParams);
  588. $oBlock->Display($oP, 0);
  589. }
  590. if (strtolower($sFormat) == 'csv')
  591. {
  592. $oBlock = new DisplayBlock($oFilter, 'csv', false);
  593. $oBlock->Display($oP, 1);
  594. $oP->add_ready_script(" $('#csv').css('height', '95%');"); // adjust the size of the block
  595. }
  596. else
  597. {
  598. $oBlock = new DisplayBlock($oFilter, 'list', false);
  599. $oBlock->Display($oP, 1);
  600. }
  601. break;
  602. case 'search':
  603. $sFilter = utils::ReadParam('filter', '');
  604. $sFormat = utils::ReadParam('format', '');
  605. $bSearchForm = utils::ReadParam('search_form', true);
  606. if (empty($sFilter))
  607. {
  608. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'filter'));
  609. }
  610. $oP->set_title(Dict::S('UI:SearchResultsPageTitle'));
  611. // TO DO: limit the search filter by the user context
  612. $oFilter = CMDBSearchFilter::unserialize($sFilter); // TO DO : check that the filter is valid
  613. $oSet = new DBObjectSet($oFilter);
  614. if ($bSearchForm)
  615. {
  616. $oBlock = new DisplayBlock($oFilter, 'search', false);
  617. $oBlock->Display($oP, 0);
  618. }
  619. if (strtolower($sFormat) == 'csv')
  620. {
  621. $oBlock = new DisplayBlock($oFilter, 'csv', false);
  622. $oBlock->Display($oP, 'csv');
  623. $oP->add_ready_script(" $('#csv').css('height', '95%');"); // adjust the size of the block
  624. }
  625. else
  626. {
  627. $oBlock = new DisplayBlock($oFilter, 'list', false);
  628. $oBlock->Display($oP, 1);
  629. }
  630. break;
  631. case 'full_text':
  632. $sFullText = trim(utils::ReadParam('text', ''));
  633. if (empty($sFullText))
  634. {
  635. $oP->p(Dict::S('UI:Search:NoSearch'));
  636. }
  637. else
  638. {
  639. $oP->set_title(Dict::S('UI:SearchResultsPageTitle'));
  640. $oP->p("<h1>".Dict::Format('UI:FullTextSearchTitle_Text', $sFullText)."</h1>");
  641. $iCount = 0;
  642. $iBlock = 0;
  643. // Search in full text mode in all the classes
  644. $aMatches = array();
  645. if (preg_match('/^"(.*)"$/', $sFullText, $aMatches))
  646. {
  647. // The text is surrounded by double-quotes, remove the quotes and treat it as one single expression
  648. $aFullTextNeedles = array($aMatches[1]);
  649. }
  650. else
  651. {
  652. // Split the text on the blanks and treat this as a search for <word1> AND <word2> AND <word3>
  653. $aFullTextNeedles = explode(' ', $sFullText);
  654. }
  655. foreach(MetaModel::GetClasses('searchable') as $sClassName)
  656. {
  657. $oFilter = new DBObjectSearch($sClassName);
  658. foreach($aFullTextNeedles as $sSearchText)
  659. {
  660. $oFilter->AddCondition_FullText($sSearchText);
  661. }
  662. $oSet = new DBObjectSet($oFilter);
  663. if ($oSet->Count() > 0)
  664. {
  665. $aLeafs = array();
  666. while($oObj = $oSet->Fetch())
  667. {
  668. if (get_class($oObj) == $sClassName)
  669. {
  670. $aLeafs[] = $oObj->GetKey();
  671. }
  672. }
  673. $oLeafsFilter = new DBObjectSearch($sClassName);
  674. if (count($aLeafs) > 0)
  675. {
  676. $iCount += count($aLeafs);
  677. $oP->add("<div class=\"page_header\">\n");
  678. $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");
  679. $oP->add("</div>\n");
  680. $oLeafsFilter->AddCondition('id', $aLeafs, 'IN');
  681. $oBlock = new DisplayBlock($oLeafsFilter, 'list', false);
  682. $oBlock->Display($oP, $iBlock++);
  683. $oP->P('&nbsp;'); // Some space ?
  684. }
  685. }
  686. }
  687. if ($iCount == 0)
  688. {
  689. $oP->p(Dict::S('UI:Search:NoObjectFound'));
  690. }
  691. }
  692. break;
  693. case 'modify':
  694. $oP->add_linked_script("../js/json.js");
  695. $oP->add_linked_script("../js/forms-json-utils.js");
  696. $oP->add_linked_script("../js/wizardhelper.js");
  697. $oP->add_linked_script("../js/wizard.utils.js");
  698. $oP->add_linked_script("../js/linkswidget.js");
  699. $oP->add_linked_script("../js/autocompletewidget.js");
  700. $oP->add_linked_script("../js/jquery.blockUI.js");
  701. $sClass = utils::ReadParam('class', '');
  702. $sClassLabel = MetaModel::GetName($sClass);
  703. $id = utils::ReadParam('id', '');
  704. if ( empty($sClass) || empty($id)) // TO DO: check that the class name is valid !
  705. {
  706. throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
  707. }
  708. // Check if the user can modify this object
  709. $oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
  710. if (is_null($oObj))
  711. {
  712. $oP->set_title(Dict::S('UI:ErrorPageTitle'));
  713. $oP->P(Dict::S('UI:ObjectDoesNotExist'));
  714. }
  715. else
  716. {
  717. // The object could be read - check if it is allowed to modify it
  718. $oSet = CMDBObjectSet::FromObject($oObj);
  719. if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_NO)
  720. {
  721. throw new SecurityException('User not allowed to modify this object', array('class' => $sClass, 'id' => $id));
  722. }
  723. // Note: code duplicated to the case 'apply_modify' when a data integrity issue has been found
  724. $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
  725. $oP->add("<div class=\"page_header\">\n");
  726. $oP->add("<h1>".$oObj->GetIcon()."&nbsp;".Dict::Format('UI:ModificationTitle_Class_Object', $sClassLabel, $oObj->GetName())."</h1>\n");
  727. $oP->add("</div>\n");
  728. $oP->add("<div class=\"wizContainer\">\n");
  729. $oObj->DisplayModifyForm($oP);
  730. $oP->add("</div>\n");
  731. }
  732. break;
  733. case 'new':
  734. $sClass = utils::ReadParam('class', '');
  735. $sStateCode = utils::ReadParam('state', '');
  736. $bCheckSubClass = utils::ReadParam('checkSubclass', true);
  737. if ( empty($sClass) )
  738. {
  739. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
  740. }
  741. // Note: code duplicated to the case 'apply_modify' when a data integrity issue has been found
  742. $oP->add_linked_script("../js/json.js");
  743. $oP->add_linked_script("../js/forms-json-utils.js");
  744. $oP->add_linked_script("../js/wizardhelper.js");
  745. $oP->add_linked_script("../js/wizard.utils.js");
  746. $oP->add_linked_script("../js/linkswidget.js");
  747. $oP->add_linked_script("../js/autocompletewidget.js");
  748. $oP->add_linked_script("../js/jquery.blockUI.js");
  749. $aArgs = utils::ReadParam('default', array());
  750. $aContext = $oAppContext->GetAsHash();
  751. foreach( $oAppContext->GetNames() as $key)
  752. {
  753. $aArgs[$key] = $oAppContext->GetCurrentValue($key);
  754. }
  755. // If the specified class has subclasses, ask the user an instance of which class to create
  756. $aSubClasses = MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself
  757. $aPossibleClasses = array();
  758. $sRealClass = '';
  759. if ($bCheckSubClass)
  760. {
  761. foreach($aSubClasses as $sCandidateClass)
  762. {
  763. if (!MetaModel::IsAbstract($sCandidateClass) && (UserRights::IsActionAllowed($sCandidateClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES))
  764. {
  765. $aPossibleClasses[$sCandidateClass] = MetaModel::GetName($sCandidateClass);
  766. }
  767. }
  768. // Only one of the subclasses can be instantiated...
  769. if (count($aPossibleClasses) == 1)
  770. {
  771. $aKeys = array_keys($aPossibleClasses);
  772. $sRealClass = $aKeys[0];
  773. }
  774. }
  775. else
  776. {
  777. $sRealClass = $sClass;
  778. }
  779. if (!empty($sRealClass))
  780. {
  781. // Display the creation form
  782. $sClassLabel = MetaModel::GetName($sRealClass);
  783. // Note: some code has been duplicated to the case 'apply_new' when a data integrity issue has been found
  784. $oP->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel));
  785. $oP->add("<h1>".MetaModel::GetClassIcon($sRealClass)."&nbsp;".Dict::Format('UI:CreationTitle_Class', $sClassLabel)."</h1>\n");
  786. $oP->add("<div class=\"wizContainer\">\n");
  787. $aDefaults = utils::ReadParam('default', array());
  788. $aContext = $oAppContext->GetAsHash();
  789. foreach( $oAppContext->GetNames() as $key)
  790. {
  791. $aDefaults[$key] = $oAppContext->GetCurrentValue($key);
  792. }
  793. // Set all the default values in an object and clone this "default" object
  794. $oObjToClone = MetaModel::NewObject($sRealClass);
  795. foreach($aDefaults as $sName => $value)
  796. {
  797. if (MetaModel::IsValidAttCode($sRealClass, $sName))
  798. {
  799. $oAttDef = MetaModel::GetAttributeDef($sRealClass, $sName);
  800. if ($oAttDef->IsWritable())
  801. {
  802. $oObjToClone->Set($sName, $value);
  803. }
  804. }
  805. }
  806. cmdbAbstractObject::DisplayCreationForm($oP, $sRealClass, $oObjToClone, array('default' => $aDefaults));
  807. $oP->add("</div>\n");
  808. }
  809. else
  810. {
  811. // Select the derived class to create
  812. $sClassLabel = MetaModel::GetName($sClass);
  813. $oP->add("<h1>".MetaModel::GetClassIcon($sClass)."&nbsp;".Dict::Format('UI:CreationTitle_Class', $sClassLabel)."</h1>\n");
  814. $oP->add("<div class=\"wizContainer\">\n");
  815. $oP->add('<form>');
  816. $oP->add('<p>'.Dict::Format('UI:SelectTheTypeOf_Class_ToCreate', $sClassLabel));
  817. $aDefaults = utils::ReadParam('default', array());
  818. $oP->add($oAppContext->GetForForm());
  819. $oP->add("<input type=\"hidden\" name=\"checkSubclass\" value=\"0\">\n");
  820. $oP->add("<input type=\"hidden\" name=\"state\" value=\"$sStateCode\">\n");
  821. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"new\">\n");
  822. foreach($aDefaults as $key => $value)
  823. {
  824. $oP->add("<input type=\"hidden\" name=\"default[$key]\" value=\"$value\">\n");
  825. $aDefaults[$key] = $value;
  826. }
  827. $oP->add('<select name="class">');
  828. asort($aPossibleClasses);
  829. foreach($aPossibleClasses as $sClassName => $sClassLabel)
  830. {
  831. $sSelected = ($sClassName == $sClass) ? 'selected' : '';
  832. $oP->add("<option $sSelected value=\"$sClassName\">$sClassLabel</option>");
  833. }
  834. $oP->add('</select>');
  835. $oP->add("&nbsp; <input type=\"submit\" value=\"".Dict::S('UI:Button:Apply')."\"></p>");
  836. $oP->add('</form>');
  837. $oP->add("</div>\n");
  838. }
  839. break;
  840. case 'apply_modify':
  841. $sClass = utils::ReadPostedParam('class', '');
  842. $sClassLabel = MetaModel::GetName($sClass);
  843. $id = utils::ReadPostedParam('id', '');
  844. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  845. if ( empty($sClass) || empty($id)) // TO DO: check that the class name is valid !
  846. {
  847. throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
  848. }
  849. $bDisplayDetails = true;
  850. $oObj = MetaModel::GetObject($sClass, $id, false);
  851. if ($oObj == null)
  852. {
  853. $bDisplayDetails = false;
  854. $oP->set_title(Dict::S('UI:ErrorPageTitle'));
  855. $oP->P(Dict::S('UI:ObjectDoesNotExist'));
  856. }
  857. elseif (!utils::IsTransactionValid($sTransactionId, false))
  858. {
  859. $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
  860. $oP->p("<strong>".Dict::S('UI:Error:ObjectAlreadyUpdated')."</strong>\n");
  861. }
  862. else
  863. {
  864. UpdateObject($oObj);
  865. if (!$oObj->IsModified())
  866. {
  867. $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
  868. $oP->p(Dict::Format('UI:Class_Object_NotUpdated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()));
  869. }
  870. else
  871. {
  872. list($bRes, $aIssues) = $oObj->CheckToWrite();
  873. if ($bRes)
  874. {
  875. $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
  876. $oP->add("<h1>".Dict::Format('UI:ModificationTitle_Class_Object', $sClassLabel, $oObj->GetName())."</h1>\n");
  877. $oMyChange = MetaModel::NewObject("CMDBChange");
  878. $oMyChange->Set("date", time());
  879. if (UserRights::IsImpersonated())
  880. {
  881. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  882. }
  883. else
  884. {
  885. $sUserString = UserRights::GetUser();
  886. }
  887. $oMyChange->Set("userinfo", $sUserString);
  888. $iChangeId = $oMyChange->DBInsert();
  889. $oObj->DBUpdateTracked($oMyChange);
  890. utils::RemoveTransaction($sTransactionId);
  891. $oP->p(Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()));
  892. }
  893. else
  894. {
  895. $bDisplayDetails = false;
  896. // Found issues, explain and give the user a second chance
  897. //
  898. // Note: code duplicated from the case 'modify'
  899. $oP->add_linked_script("../js/json.js");
  900. $oP->add_linked_script("../js/forms-json-utils.js");
  901. $oP->add_linked_script("../js/wizardhelper.js");
  902. $oP->add_linked_script("../js/wizard.utils.js");
  903. $oP->add_linked_script("../js/linkswidget.js");
  904. $oP->add_linked_script("../js/autocompletewidget.js");
  905. $oP->add_linked_script("../js/jquery.blockUI.js");
  906. $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
  907. $oP->add("<div class=\"page_header\">\n");
  908. $oP->add("<h1>".$oObj->GetIcon()."&nbsp;".Dict::Format('UI:ModificationTitle_Class_Object', $sClassLabel, $oObj->GetName())."</h1>\n");
  909. $oP->add("</div>\n");
  910. $oP->add("<div class=\"wizContainer\">\n");
  911. $oObj->DisplayModifyForm($oP);
  912. $oP->add("</div>\n");
  913. $sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten', implode(', ', $aIssues));
  914. $oP->add_ready_script("alert('".addslashes($sIssueDesc)."');");
  915. }
  916. }
  917. }
  918. if ($bDisplayDetails)
  919. {
  920. $oObj = MetaModel::GetObject(get_class($oObj), $oObj->GetKey()); //Workaround: reload the object so that the linkedset are displayed properly
  921. $oObj->DisplayDetails($oP);
  922. }
  923. break;
  924. case 'select_for_deletion':
  925. $sFilter = utils::ReadParam('filter', '');
  926. $sFormat = utils::ReadParam('format', '');
  927. if (empty($sFilter))
  928. {
  929. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'filter'));
  930. }
  931. $oP->set_title(Dict::S('UI:BulkDeletePageTitle'));
  932. $oP->add("<h1>".Dict::S('UI:BulkDeleteTitle')."</h1>\n");
  933. // TO DO: limit the search filter by the user context
  934. $oFilter = CMDBSearchFilter::unserialize($sFilter); // TO DO : check that the filter is valid
  935. $oSet = new DBObjectSet($oFilter);
  936. $oBlock = new DisplayBlock($oFilter, 'list', false);
  937. $oP->add("<form method=\"post\">\n");
  938. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"bulk_delete\">\n");
  939. $oP->add("<input type=\"hidden\" name=\"class\" value=\"".$oFilter->GetClass()."\">\n");
  940. $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
  941. $oBlock->Display($oP, 1, array('selection_type' => 'multiple', 'selection_mode' => true, 'display_limit' => false, 'menu' => false));
  942. $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");
  943. $oP->add("</form>\n");
  944. break;
  945. case 'bulk_delete_confirmed':
  946. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  947. if (!utils::IsTransactionValid($sTransactionId))
  948. {
  949. throw new ApplicationException(Dict::S('UI:Error:ObjectsAlreadyDeleted'));
  950. }
  951. case 'bulk_delete':
  952. $sClass = utils::ReadPostedParam('class', '');
  953. $sClassLabel = MetaModel::GetName($sClass);
  954. $aSelectObject = utils::ReadPostedParam('selectObject', '');
  955. $aObjects = array();
  956. if ( empty($sClass) || empty($aSelectObject)) // TO DO: check that the class name is valid !
  957. {
  958. throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'selectObject[]'));
  959. }
  960. foreach($aSelectObject as $iId)
  961. {
  962. $aObjects[] = MetaModel::GetObject($sClass, $iId);
  963. }
  964. if (!UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, DBObjectSet::FromArray($sClass, $aObjects)))
  965. {
  966. throw new SecurityException(Dict::Format('UI:Error:BulkDeleteNotAllowedOn_Class', $sClass));
  967. }
  968. $oP->set_title(Dict::S('UI:BulkDeletePageTitle'));
  969. DeleteObjects($oP, $sClass, $aObjects, ($operation == 'bulk_delete_confirmed'));
  970. break;
  971. case 'delete':
  972. case 'delete_confirmed':
  973. $sClass = utils::ReadParam('class', '');
  974. $sClassLabel = MetaModel::GetName($sClass);
  975. $id = utils::ReadParam('id', '');
  976. $oObj = MetaModel::GetObject($sClass, $id);
  977. if (!UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, DBObjectSet::FromObject($oObj)))
  978. {
  979. throw new SecurityException(Dict::Format('UI:Error:DeleteNotAllowedOn_Class', $sClass));
  980. }
  981. DeleteObjects($oP, $sClass, array($oObj), ($operation == 'delete_confirmed'));
  982. break;
  983. case 'apply_new':
  984. $sClass = utils::ReadPostedParam('class', '');
  985. $sClassLabel = MetaModel::GetName($sClass);
  986. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  987. if ( empty($sClass) ) // TO DO: check that the class name is valid !
  988. {
  989. throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
  990. }
  991. if (!utils::IsTransactionValid($sTransactionId, false))
  992. {
  993. $oP->p("<strong>".Dict::S('UI:Error:ObjectAlreadyCreated')."</strong>\n");
  994. }
  995. else
  996. {
  997. $oObj = MetaModel::NewObject($sClass);
  998. UpdateObject($oObj);
  999. }
  1000. if (isset($oObj) && is_object($oObj))
  1001. {
  1002. $sClass = get_class($oObj);
  1003. $sClassLabel = MetaModel::GetName($sClass);
  1004. list($bRes, $aIssues) = $oObj->CheckToWrite();
  1005. if ($bRes)
  1006. {
  1007. $oMyChange = MetaModel::NewObject("CMDBChange");
  1008. $oMyChange->Set("date", time());
  1009. if (UserRights::IsImpersonated())
  1010. {
  1011. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  1012. }
  1013. else
  1014. {
  1015. $sUserString = UserRights::GetUser();
  1016. }
  1017. $oMyChange->Set("userinfo", $sUserString);
  1018. $iChangeId = $oMyChange->DBInsert();
  1019. $oObj->DBInsertTracked($oMyChange);
  1020. utils::RemoveTransaction($sTransactionId);
  1021. $oP->set_title(Dict::S('UI:PageTitle:ObjectCreated'));
  1022. $oP->add("<h1>".Dict::Format('UI:Title:Object_Of_Class_Created', $oObj->GetName(), $sClassLabel)."</h1>\n");
  1023. $oObj->DisplayDetails($oP);
  1024. }
  1025. else
  1026. {
  1027. // Found issues, explain and give the user a second chance
  1028. //
  1029. // Note: code similar to the case 'modify'
  1030. $oP->add_linked_script("../js/json.js");
  1031. $oP->add_linked_script("../js/forms-json-utils.js");
  1032. $oP->add_linked_script("../js/wizardhelper.js");
  1033. $oP->add_linked_script("../js/wizard.utils.js");
  1034. $oP->add_linked_script("../js/linkswidget.js");
  1035. $oP->add_linked_script("../js/autocompletewidget.js");
  1036. $oP->add_linked_script("../js/jquery.blockUI.js");
  1037. $oP->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel));
  1038. $oP->add("<h1>".MetaModel::GetClassIcon($sClass)."&nbsp;".Dict::Format('UI:CreationTitle_Class', $sClassLabel)."</h1>\n");
  1039. $oP->add("<div class=\"wizContainer\">\n");
  1040. cmdbAbstractObject::DisplayCreationForm($oP, $sClass, $oObj);
  1041. $oP->add("</div>\n");
  1042. $sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten', implode(', ', $aIssues));
  1043. $oP->add_ready_script("alert('".addslashes($sIssueDesc)."');");
  1044. }
  1045. }
  1046. break;
  1047. case 'wizard_apply_new':
  1048. $sJson = utils::ReadPostedParam('json_obj', '');
  1049. $oWizardHelper = WizardHelper::FromJSON($sJson);
  1050. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  1051. if (!utils::IsTransactionValid($sTransactionId))
  1052. {
  1053. $oP->p(Dict::S('UI:Error:ObjectAlreadyCreated'));
  1054. }
  1055. else
  1056. {
  1057. $oObj = $oWizardHelper->GetTargetObject(true /* read uploaded files */);
  1058. if (is_object($oObj))
  1059. {
  1060. $sClass = get_class($oObj);
  1061. $sClassLabel = MetaModel::GetName($sClass);
  1062. $oMyChange = MetaModel::NewObject("CMDBChange");
  1063. $oMyChange->Set("date", time());
  1064. if (UserRights::IsImpersonated())
  1065. {
  1066. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  1067. }
  1068. else
  1069. {
  1070. $sUserString = UserRights::GetUser();
  1071. }
  1072. $oMyChange->Set("userinfo", $sUserString);
  1073. $iChangeId = $oMyChange->DBInsert();
  1074. $oObj->DBInsertTracked($oMyChange);
  1075. $oP->set_title(Dict::S('UI:PageTitle:ObjectCreated'));
  1076. $oP->add("<h1>".Dict::Format('UI:Title:Object_Of_Class_Created', $oObj->GetName(), $sClassLabel)."</h1>\n");
  1077. $oObj->DisplayDetails($oP);
  1078. }
  1079. }
  1080. break;
  1081. case 'stimulus':
  1082. $sClass = utils::ReadParam('class', '');
  1083. $id = utils::ReadParam('id', '');
  1084. $sStimulus = utils::ReadParam('stimulus', '');
  1085. if ( empty($sClass) || empty($id) || empty($sStimulus) ) // TO DO: check that the class name is valid !
  1086. {
  1087. throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'class', 'id', 'stimulus'));
  1088. }
  1089. $oObj = MetaModel::GetObject($sClass, $id, false);
  1090. if ($oObj != null)
  1091. {
  1092. $aTransitions = $oObj->EnumTransitions();
  1093. $aStimuli = MetaModel::EnumStimuli($sClass);
  1094. if (!isset($aTransitions[$sStimulus]))
  1095. {
  1096. // Invalid stimulus
  1097. throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $oObj->GetName(), $oObj->GetStateLabel()));
  1098. }
  1099. $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
  1100. $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
  1101. $aTransition = $aTransitions[$sStimulus];
  1102. $sTargetState = $aTransition['target_state'];
  1103. $aTargetStates = MetaModel::EnumStates($sClass);
  1104. $oP->add_linked_script("../js/json.js");
  1105. $oP->add_linked_script("../js/forms-json-utils.js");
  1106. $oP->add_linked_script("../js/wizardhelper.js");
  1107. $oP->add_linked_script("../js/wizard.utils.js");
  1108. $oP->add_linked_script("../js/linkswidget.js");
  1109. $oP->add_linked_script("../js/autocompletewidget.js");
  1110. $oP->add_linked_script("../js/jquery.blockUI.js");
  1111. $oP->add("<div class=\"page_header\">\n");
  1112. $oP->add("<h1>$sActionLabel - <span class=\"hilite\">{$oObj->GetName()}</span></h1>\n");
  1113. $oP->set_title($sActionLabel);
  1114. $oP->add("</div>\n");
  1115. $oObj->DisplayBareProperties($oP);
  1116. $aTargetState = $aTargetStates[$sTargetState];
  1117. $aExpectedAttributes = $aTargetState['attribute_list'];
  1118. $oP->add("<h1>$sActionDetails</h1>\n");
  1119. $oP->add("<div class=\"wizContainer\">\n");
  1120. $oP->add("<form id=\"apply_stimulus\" method=\"post\" onSubmit=\"return CheckFields('apply_stimulus', true);\">\n");
  1121. $aDetails = array();
  1122. $iFieldIndex = 0;
  1123. $aFieldsMap = array();
  1124. foreach($aExpectedAttributes as $sAttCode => $iExpectCode)
  1125. {
  1126. // Prompt for an attribute if
  1127. // - the attribute must be changed or must be displayed to the user for confirmation
  1128. // - or the field is mandatory and currently empty
  1129. if ( ($iExpectCode & (OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT)) ||
  1130. (($iExpectCode & OPT_ATT_MANDATORY) && ($oObj->Get($sAttCode) == '')) )
  1131. {
  1132. $aAttributesDef = MetaModel::ListAttributeDefs($sClass);
  1133. $oAttDef = $aAttributesDef[$sAttCode];
  1134. $aArgs = array('this' => $oObj);
  1135. $sHTMLValue = cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $oObj->Get($sAttCode), $oObj->GetEditValue($sAttCode), 'att_'.$iFieldIndex, '', $iExpectCode, $aArgs);
  1136. $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => "<span id=\"field_att_$iFieldIndex\">$sHTMLValue</span>");
  1137. $aFieldsMap[$sAttCode] = 'att_'.$iFieldIndex;
  1138. $iFieldIndex++;
  1139. }
  1140. }
  1141. $oP->details($aDetails);
  1142. $oP->add("<input type=\"hidden\" name=\"id\" value=\"$id\" id=\"id\">\n");
  1143. $aFieldsMap['id'] = 'id';
  1144. $oP->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">\n");
  1145. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"apply_stimulus\">\n");
  1146. $oP->add("<input type=\"hidden\" name=\"stimulus\" value=\"$sStimulus\">\n");
  1147. $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
  1148. $oP->add($oAppContext->GetForForm());
  1149. $oP->add("<button type=\"button\" class=\"action\" onClick=\"BackToDetails('$sClass', $id)\"><span>".Dict::S('UI:Button:Cancel')."</span></button>&nbsp;&nbsp;&nbsp;&nbsp;\n");
  1150. $oP->add("<button type=\"submit\" class=\"action\"><span>$sActionLabel</span></button>\n");
  1151. $oP->add("</form>\n");
  1152. $oP->add("</div>\n");
  1153. $iFieldsCount = count($aFieldsMap);
  1154. $sJsonFieldsMap = json_encode($aFieldsMap);
  1155. $oP->add_script(
  1156. <<<EOF
  1157. // Initializes the object once at the beginning of the page...
  1158. var oWizardHelper = new WizardHelper('$sClass');
  1159. oWizardHelper.SetFieldsMap($sJsonFieldsMap);
  1160. oWizardHelper.SetFieldsCount($iFieldsCount);
  1161. EOF
  1162. );
  1163. $oP->add_ready_script(
  1164. <<<EOF
  1165. // Starts the validation when the page is ready
  1166. CheckFields('apply_stimulus', false);
  1167. EOF
  1168. );
  1169. }
  1170. else
  1171. {
  1172. $oP->set_title(Dict::S('UI:ErrorPageTitle'));
  1173. $oP->P(Dict::S('UI:ObjectDoesNotExist'));
  1174. }
  1175. break;
  1176. case 'apply_stimulus':
  1177. $sClass = utils::ReadPostedParam('class', '');
  1178. $id = utils::ReadPostedParam('id', '');
  1179. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  1180. $sStimulus = utils::ReadPostedParam('stimulus', '');
  1181. if ( empty($sClass) || empty($id) || empty($sStimulus) ) // TO DO: check that the class name is valid !
  1182. {
  1183. throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'class', 'id', 'stimulus'));
  1184. }
  1185. $oObj = MetaModel::GetObject($sClass, $id, false);
  1186. if ($oObj != null)
  1187. {
  1188. $aTransitions = $oObj->EnumTransitions();
  1189. $aStimuli = MetaModel::EnumStimuli($sClass);
  1190. if (!isset($aTransitions[$sStimulus]))
  1191. {
  1192. throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $oObj->GetName(), $oObj->GetStateLabel()));
  1193. }
  1194. if (!utils::IsTransactionValid($sTransactionId))
  1195. {
  1196. $oP->p(Dict::S('UI:Error:ObjectAlreadyUpdated'));
  1197. }
  1198. else
  1199. {
  1200. $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
  1201. $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
  1202. $aTransition = $aTransitions[$sStimulus];
  1203. $sTargetState = $aTransition['target_state'];
  1204. $aTargetStates = MetaModel::EnumStates($sClass);
  1205. //$oP->add("<div class=\"page_header\">\n");
  1206. //$oP->add("<h1>$sActionLabel - <span class=\"hilite\">{$oObj->GetName()}</span></h1>\n");
  1207. //$oP->add("<p>$sActionDetails</p>\n");
  1208. //$oP->p(Dict::Format('UI:Apply_Stimulus_On_Object_In_State_ToTarget_State', $sActionLabel, $oObj->GetName(), $oObj->GetStateLabel(), $sTargetState));
  1209. //$oP->add("</div>\n");
  1210. $aTargetState = $aTargetStates[$sTargetState];
  1211. $aExpectedAttributes = $aTargetState['attribute_list'];
  1212. $aDetails = array();
  1213. foreach($aExpectedAttributes as $sAttCode => $iExpectCode)
  1214. {
  1215. if (($iExpectCode & (OPT_ATT_MUSTCHANGE|OPT_ATT_MUSTPROMPT)) || ($oObj->Get($sAttCode) == '') )
  1216. {
  1217. $paramValue = utils::ReadPostedParam("attr_$sAttCode", '');
  1218. $oObj->Set($sAttCode, $paramValue);
  1219. }
  1220. }
  1221. if ($oObj->ApplyStimulus($sStimulus))
  1222. {
  1223. $oMyChange = MetaModel::NewObject("CMDBChange");
  1224. $oMyChange->Set("date", time());
  1225. if (UserRights::IsImpersonated())
  1226. {
  1227. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  1228. }
  1229. else
  1230. {
  1231. $sUserString = UserRights::GetUser();
  1232. }
  1233. $oMyChange->Set("userinfo", $sUserString);
  1234. $iChangeId = $oMyChange->DBInsert();
  1235. $oObj->DBUpdateTracked($oMyChange);
  1236. $oP->p(Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()));
  1237. }
  1238. }
  1239. $oObj->DisplayDetails($oP);
  1240. }
  1241. else
  1242. {
  1243. $oP->set_title(Dict::S('UI:ErrorPageTitle'));
  1244. $oP->P(Dict::S('UI:ObjectDoesNotExist'));
  1245. }
  1246. break;
  1247. case 'modify_links':
  1248. $sClass = utils::ReadParam('class', '');
  1249. $sLinkAttr = utils::ReadParam('link_attr', '');
  1250. $sTargetClass = utils::ReadParam('target_class', '');
  1251. $id = utils::ReadParam('id', '');
  1252. $bAddObjects = utils::ReadParam('addObjects', false);
  1253. if ( empty($sClass) || empty($id) || empty($sLinkAttr) || empty($sTargetClass)) // TO DO: check that the class name is valid !
  1254. {
  1255. throw new ApplicationException(Dict::Format('UI:Error:4ParametersMissing', 'class', 'id', 'target_class', 'link_attr'));
  1256. }
  1257. require_once('../application/uilinkswizard.class.inc.php');
  1258. $oWizard = new UILinksWizard($sClass, $sLinkAttr, $id, $sTargetClass);
  1259. $oWizard->Display($oP, array('StartWithAdd' => $bAddObjects));
  1260. break;
  1261. case 'do_modify_links':
  1262. $aLinks = utils::ReadPostedParam('linkId', array());
  1263. $sLinksToRemove = trim(utils::ReadPostedParam('linksToRemove', ''));
  1264. $aLinksToRemove = array();
  1265. if (!empty($sLinksToRemove))
  1266. {
  1267. $aLinksToRemove = explode(' ', trim($sLinksToRemove));
  1268. }
  1269. $sClass = utils::ReadPostedParam('class', '');
  1270. $sLinkageAtt = utils::ReadPostedParam('linkage', '');
  1271. $iObjectId = utils::ReadPostedParam('object_id', '');
  1272. $sLinkingAttCode = utils::ReadPostedParam('linking_attcode', '');
  1273. $oMyChange = MetaModel::NewObject("CMDBChange");
  1274. $oMyChange->Set("date", time());
  1275. if (UserRights::IsImpersonated())
  1276. {
  1277. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  1278. }
  1279. else
  1280. {
  1281. $sUserString = UserRights::GetUser();
  1282. }
  1283. $oMyChange->Set("userinfo", $sUserString);
  1284. $iChangeId = $oMyChange->DBInsert();
  1285. // Delete links that are to be deleted
  1286. foreach($aLinksToRemove as $iLinkId)
  1287. {
  1288. if ($iLinkId > 0) // Negative IDs are objects that were not even created
  1289. {
  1290. $oLink = MetaModel::GetObject($sClass, $iLinkId);
  1291. $oLink->DBDeleteTracked($oMyChange);
  1292. }
  1293. }
  1294. $aEditableFields = array();
  1295. $aData = array();
  1296. foreach(MetaModel::GetAttributesList($sClass) as $sAttCode)
  1297. {
  1298. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1299. if ( (!$oAttDef->IsExternalKey()) && (!$oAttDef->IsExternalField()))
  1300. {
  1301. $aEditableFields[] = $sAttCode;
  1302. $aData[$sAttCode] = utils::ReadParam('attr_'.$sAttCode, array(), 'post');
  1303. }
  1304. }
  1305. // Update existing links or create new links
  1306. foreach($aLinks as $iLinkId)
  1307. {
  1308. if ($iLinkId > 0)
  1309. {
  1310. // This is an existing link to be modified
  1311. $oLink = MetaModel::GetObject($sClass, $iLinkId);
  1312. // Update all the attributes of the link
  1313. foreach($aEditableFields as $sAttCode)
  1314. {
  1315. $value = $aData[$sAttCode][$iLinkId];
  1316. $oLink->Set($sAttCode, $value);
  1317. }
  1318. if ($oLink->IsModified())
  1319. {
  1320. $oLink->DBUpdateTracked($oMyChange);
  1321. }
  1322. //echo "Updated link:<br/>\n";
  1323. //var_dump($oLink);
  1324. }
  1325. else
  1326. {
  1327. // A new link must be created
  1328. $oLink = MetaModel::NewObject($sClass);
  1329. $oLinkedObjectId = -$iLinkId;
  1330. // Set all the attributes of the link
  1331. foreach($aEditableFields as $sAttCode)
  1332. {
  1333. $value = $aData[$sAttCode][$iLinkId];
  1334. $oLink->Set($sAttCode, $value);
  1335. }
  1336. // And the two external keys
  1337. $oLink->Set($sLinkageAtt, $iObjectId);
  1338. $oLink->Set($sLinkingAttCode, $oLinkedObjectId);
  1339. // then save it
  1340. //echo "Created link:<br/>\n";
  1341. //var_dump($oLink);
  1342. $oLink->DBInsertTracked($oMyChange);
  1343. }
  1344. }
  1345. // Display again the details of the linked object
  1346. $oAttDef = MetaModel::GetAttributeDef($sClass, $sLinkageAtt);
  1347. $sTargetClass = $oAttDef->GetTargetClass();
  1348. $oObj = MetaModel::GetObject($sTargetClass, $iObjectId);
  1349. $oSearch = new DBObjectSearch(get_class($oObj));
  1350. $oBlock = new DisplayBlock($oSearch, 'search', false);
  1351. $oBlock->Display($oP, 0);
  1352. $oObj->DisplayDetails($oP);
  1353. break;
  1354. case 'swf_navigator':
  1355. $sClass = utils::ReadParam('class', '');
  1356. $id = utils::ReadParam('id', 0);
  1357. $sRelation = utils::ReadParam('relation', 'impact');
  1358. $oP->AddTabContainer('Navigator');
  1359. $oP->SetCurrentTabContainer('Navigator');
  1360. $oP->SetCurrentTab(Dict::S('UI:RelationshipGraph'));
  1361. $width = 1000;
  1362. $height = 700;
  1363. $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";
  1364. $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\">
  1365. <param name=\"allowScriptAccess\" value=\"sameDomain\" />
  1366. <param name=\"allowFullScreen\" value=\"false\" />
  1367. <param name=\"FlashVars\" value=\"$sParams\" />
  1368. <param name=\"movie\" value=\"../navigator/navigator.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#ffffff\" />
  1369. <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\" />
  1370. </object>\n");
  1371. $oP->SetCurrentTab(Dict::S('UI:RelationshipList'));
  1372. $oP->add("<div id=\"impacted_objects\" style=\"width:100%;background-color:#fff;padding:10px;\"><p style=\"height:150px;\">&nbsp;</p></div>");
  1373. $oP->add_ready_script(
  1374. <<<EOF
  1375. var ajax_request = null;
  1376. function UpdateImpactedObjects(sClass, iId, sRelation)
  1377. {
  1378. var class_name = sClass; //$('select[name=class_name]').val();
  1379. if (class_name != '')
  1380. {
  1381. $('#impacted_objects').block();
  1382. // Make sure that we cancel any pending request before issuing another
  1383. // since responses may arrive in arbitrary order
  1384. if (ajax_request != null)
  1385. {
  1386. ajax_request.abort();
  1387. ajax_request = null;
  1388. }
  1389. ajax_request = $.get('xml.navigator.php', { 'class': sClass, id: iId, relation: sRelation, format: 'html' },
  1390. function(data)
  1391. {
  1392. $('#impacted_objects').empty();
  1393. $('#impacted_objects').append(data);
  1394. $('#impacted_objects').unblock();
  1395. $('#impacted_objects .listResults').tablesorter( { widgets: ['myZebra', 'truncatedList']} ); // sortable and zebra tables
  1396. $('#impacted_objects table.listResults').tableHover(); // hover tables
  1397. }
  1398. );
  1399. }
  1400. }
  1401. UpdateImpactedObjects('$sClass', $id, '$sRelation');
  1402. EOF
  1403. );
  1404. $oP->SetCurrentTab('');
  1405. break;
  1406. default:
  1407. $oMenuNode = ApplicationMenu::GetMenuNode(ApplicationMenu::GetActiveNodeId());
  1408. if (is_object($oMenuNode))
  1409. {
  1410. $oMenuNode->RenderContent($oP, $oAppContext->GetAsHash());
  1411. $oP->set_title($oMenuNode->GetLabel());
  1412. }
  1413. }
  1414. $oKPI->ComputeAndReport('GUI creation before output');
  1415. ExecutionKPI::ReportStats();
  1416. MetaModel::ShowQueryTrace();
  1417. DisplayWelcomePopup($oP);
  1418. $oP->output();
  1419. }
  1420. catch(CoreException $e)
  1421. {
  1422. require_once('../setup/setuppage.class.inc.php');
  1423. $oP = new SetupWebPage(Dict::S('UI:PageTitle:FatalError'));
  1424. if ($e instanceof SecurityException)
  1425. {
  1426. $oP->add("<h1>".Dict::S('UI:SystemIntrusion')."</h1>\n");
  1427. }
  1428. else
  1429. {
  1430. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1431. }
  1432. $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
  1433. $oP->output();
  1434. if (MetaModel::IsLogEnabledIssue())
  1435. {
  1436. if (MetaModel::IsValidClass('EventIssue'))
  1437. {
  1438. try
  1439. {
  1440. $oLog = new EventIssue();
  1441. $oLog->Set('message', $e->getMessage());
  1442. $oLog->Set('userinfo', '');
  1443. $oLog->Set('issue', $e->GetIssue());
  1444. $oLog->Set('impact', 'Page could not be displayed');
  1445. $oLog->Set('callstack', $e->getTrace());
  1446. $oLog->Set('data', $e->getContextData());
  1447. $oLog->DBInsertNoReload();
  1448. }
  1449. catch(Exception $e)
  1450. {
  1451. IssueLog::Error("Failed to log issue into the DB");
  1452. }
  1453. }
  1454. IssueLog::Error($e->getMessage());
  1455. }
  1456. // For debugging only
  1457. //throw $e;
  1458. }
  1459. catch(Exception $e)
  1460. {
  1461. require_once('../setup/setuppage.class.inc.php');
  1462. $oP = new SetupWebPage(Dict::S('UI:PageTitle:FatalError'));
  1463. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1464. $oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
  1465. $oP->output();
  1466. if (MetaModel::IsLogEnabledIssue())
  1467. {
  1468. if (MetaModel::IsValidClass('EventIssue'))
  1469. {
  1470. try
  1471. {
  1472. $oLog = new EventIssue();
  1473. $oLog->Set('message', $e->getMessage());
  1474. $oLog->Set('userinfo', '');
  1475. $oLog->Set('issue', 'PHP Exception');
  1476. $oLog->Set('impact', 'Page could not be displayed');
  1477. $oLog->Set('callstack', $e->getTrace());
  1478. $oLog->Set('data', array());
  1479. $oLog->DBInsertNoReload();
  1480. }
  1481. catch(Exception $e)
  1482. {
  1483. IssueLog::Error("Failed to log issue into the DB");
  1484. }
  1485. }
  1486. IssueLog::Error($e->getMessage());
  1487. }
  1488. }
  1489. ?>