UI.php 57 KB

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