UI.php 53 KB

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