UI.php 56 KB

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