index.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  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. * iTop User Portal main page
  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. require_once('../approot.inc.php');
  25. require_once(APPROOT.'/application/application.inc.php');
  26. require_once(APPROOT.'/application/nicewebpage.class.inc.php');
  27. require_once(APPROOT.'/application/wizardhelper.class.inc.php');
  28. /**
  29. * Get the list of parameters (i.e. attribute codes) to be handled while creating a new UserRequest object
  30. * @return Array The list of attribute codes
  31. */
  32. function GetParamsList()
  33. {
  34. return array('org_id', 'caller_id', 'service_id', 'servicesubcategory_id', 'request_type', 'title', 'description', 'impact', 'urgency', 'workgroup_id');
  35. }
  36. /**
  37. * Outputs a list of parameters as hidden field into the current page
  38. * (must be called when inside a form)
  39. * @param WebPage $oP The current web page
  40. * @param Array $aInteractive The list of parameters that are handled intractively and thus should not be output as hidden fields
  41. * @param Hash $aParameters Array name => value for the parameters
  42. * @return void
  43. */
  44. function DumpHiddenParams($oP, $aInteractive, $aParameters)
  45. {
  46. foreach($aParameters as $sAttCode => $value)
  47. {
  48. if (!in_array($sAttCode, $aInteractive))
  49. {
  50. $oP->Add("<input type=\"hidden\" name=\"attr_$sAttCode\" value=\"$value\">");
  51. }
  52. }
  53. }
  54. /**
  55. * Read all the parameters of the page for building a UserRequest
  56. * Parameters that were absent from the page's parameters are not set in the resulting hash array
  57. * @input string $sMethod Either get or post
  58. * @return Hash Array of name => value corresponding to the parameters that were passed to the page
  59. */
  60. function ReadAllParams($sMethod = 'get')
  61. {
  62. $aParams = GetParamsList();
  63. $aValues = array();
  64. foreach($aParams as $sName)
  65. {
  66. $value = utils::ReadParam('attr_'.$sName, null, $sMethod);
  67. if (!is_null($value))
  68. {
  69. $aValues[$sName] = $value;
  70. }
  71. }
  72. return $aValues;
  73. }
  74. /**
  75. * Displays the portal main menu
  76. * @param WebPage $oP The current web page
  77. * @return void
  78. */
  79. function DisplayMainMenu(WebPage $oP)
  80. {
  81. $oP->AddMenuButton('refresh', 'Portal:Refresh', './index.php?operation=welcome');
  82. $oP->AddMenuButton('create', 'Portal:CreateNewRequest', './index.php?operation=create_request');
  83. $oP->AddMenuButton('change_pwd', 'Portal:ChangeMyPassword', './index.php?loginop=change_pwd');
  84. $oP->add("<div id=\"#div_resolved_requests\">\n");
  85. $oP->add("<h1 id=\"#open_requests\">".Dict::S('Portal:OpenRequests')."</h1>\n");
  86. ListOpenRequests($oP);
  87. $oP->add("</div>\n");
  88. $oP->add("<div id=\"#div_resolved_requests\">\n");
  89. $oP->add("<h1 id=\"#resolved_requests\">".Dict::S('Portal:ResolvedRequests')."</h1>\n");
  90. ListResolvedRequests($oP);
  91. $oP->add("</div>\n");
  92. }
  93. /**
  94. * Displays the form to select a Service Id (among the valid ones for the specified user Organization)
  95. * @param WebPage $oP Web page for the form output
  96. * @param Organization $oUserOrg The organization of the current user
  97. * @return void
  98. */
  99. function SelectService($oP, $oUserOrg)
  100. {
  101. // Init forms parameters
  102. $aParameters = ReadAllParams();
  103. $oSearch = DBObjectSearch::FromOQL('SELECT Service AS s JOIN SLA AS sla ON sla.service_id=s.id JOIN lnkContractToSLA AS ln ON ln.sla_id=sla.id JOIN CustomerContract AS cc ON ln.contract_id=cc.id WHERE cc.org_id = :org_id');
  104. $oSet = new CMDBObjectSet($oSearch, array(), array('org_id' => $oUserOrg->GetKey()));
  105. $oP->add("<div class=\"wizContainer\" id=\"form_select_service\">\n");
  106. $oP->add("<h1 id=\"select_subcategory\">".Dict::S('Portal:SelectService')."</h1>\n");
  107. $oP->add("<form action=\"../portal/index.php\" id=\"request_form\" method=\"get\">\n");
  108. $oP->add("<table>\n");
  109. while($oService = $oSet->Fetch())
  110. {
  111. $id = $oService->GetKey();
  112. $sChecked = "";
  113. if (isset($aParameters['service_id']) && ($id == $aParameters['service_id']))
  114. {
  115. $sChecked = "checked";
  116. }
  117. $oP->p("<tr><td style=\"vertical-align:top\"><p><input name=\"attr_service_id\" $sChecked type=\"radio\" id=\"svc_$id\" value=\"$id\"></p></td><td style=\"vertical-align:top\"><p><b><label for=\"svc_$id\">".htmlentities($oService->GetName(), ENT_QUOTES, 'UTF-8')."</label></b></p>");
  118. $oP->p("<p>".htmlentities($oService->Get('description'), ENT_QUOTES, 'UTF-8')."</p></td></tr>");
  119. }
  120. $oP->add("</table>\n");
  121. DumpHiddenParams($oP, array('service_id'), $aParameters);
  122. $oP->add("<input type=\"hidden\" name=\"step\" value=\"1\">");
  123. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_request\">");
  124. $oP->p("<input type=\"submit\" value=\"".Dict::S('UI:Button:Next')."\">");
  125. $oP->add("</form>");
  126. $oP->add("</div class=\"wizContainer\">\n");
  127. $sMessage = Dict::S('Portal:PleaseSelectOneService');
  128. $oP->add_ready_script(
  129. <<<EOF
  130. $('#request_form').submit(function() {
  131. return CheckSelection('$sMessage');
  132. });
  133. EOF
  134. );
  135. }
  136. /**
  137. * Displays the form to select a Service Subcategory Id (among the valid ones for the specified user Organization)
  138. * and based on the page's parameter 'service_id'
  139. * @param WebPage $oP Web page for the form output
  140. * @param Organization $oUserOrg The organization of the current user
  141. * @return void
  142. */
  143. function SelectSubService($oP, $oUserOrg)
  144. {
  145. // Init forms parameters
  146. $aParameters = ReadAllParams();
  147. $iSvcId = $aParameters['service_id'];
  148. $iDefaultSubSvcId = isset($aParameters['servicesubcategory_id']) ? $aParameters['servicesubcategory_id'] : 0;
  149. $oSearch = DBObjectSearch::FromOQL('SELECT ServiceSubcategory AS ss WHERE ss.service_id = :svc_id');
  150. $oSet = new CMDBObjectSet($oSearch, array(), array('svc_id' => $iSvcId));
  151. $oService = MetaModel::GetObject('Service', $iSvcId, false);
  152. if (is_object($oService))
  153. {
  154. $oP->add("<div class=\"wizContainer\" id=\"form_select_servicesubcategory\">\n");
  155. $oP->add("<h1 id=\"select_subcategory\">".Dict::Format('Portal:SelectSubcategoryFrom_Service', htmlentities($oService->GetName(), ENT_QUOTES, 'UTF-8'))."</h1>\n");
  156. $oP->add("<form id=\"request_form\" method=\"get\">\n");
  157. $oP->add("<table>\n");
  158. while($oSubService = $oSet->Fetch())
  159. {
  160. $id = $oSubService->GetKey();
  161. $sChecked = "";
  162. if ($id == $iDefaultSubSvcId)
  163. {
  164. $sChecked = "checked";
  165. }
  166. $oP->p("<tr><td style=\"vertical-align:top\"><p><input name=\"attr_servicesubcategory_id\" $sChecked type=\"radio\" id=\"subsvc_$id\" value=\"$id\"></p></td><td style=\"vertical-align:top\"><p><b><label for=\"subsvc_$id\">".htmlentities($oSubService->GetName(), ENT_QUOTES, 'UTF-8')."</label></b></p>");
  167. $oP->p("<p>".htmlentities($oSubService->Get('description'), ENT_QUOTES, 'UTF-8')."</p></td></tr>");
  168. }
  169. $sMessage = Dict::S('Portal:PleaseSelectAServiceSubCategory');
  170. $oP->add_ready_script(
  171. <<<EOF
  172. $('#request_form').submit(function() {
  173. return CheckSelection('$sMessage');
  174. });
  175. EOF
  176. );
  177. $oP->add("</table>\n");
  178. DumpHiddenParams($oP, array('servicesubcategory_id'), $aParameters);
  179. $oP->add("<input type=\"hidden\" name=\"step\" value=\"2\">");
  180. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_request\">");
  181. $oP->p("<input type=\"submit\" value=\"".Dict::S('UI:Button:Back')."\" onClick=\"GoBack();\">&nbsp;<input type=\"submit\" value=\"".Dict::S('UI:Button:Next')."\">");
  182. $oP->add("</form>");
  183. $oP->add("</div>\n");
  184. }
  185. else
  186. {
  187. $oP->p("Error: Invalid Service: id = $iSvcId");
  188. }
  189. }
  190. /**
  191. * Displays the form for the final step of the UserRequest creation
  192. * @param WebPage $oP The current web page for the form output
  193. * @param Organization $oUserOrg The organization of the current user
  194. * @return void
  195. */
  196. function RequestCreationForm($oP, $oUserOrg)
  197. {
  198. $aList = array('request_type', 'title', 'description', 'impact', 'urgency', 'workgroup_id');
  199. $aParameters = ReadAllParams();
  200. $oService = MetaModel::GetObject('Service', $aParameters['service_id'], false);
  201. $oSubService = MetaModel::GetObject('ServiceSubcategory', $aParameters['servicesubcategory_id'], false);
  202. if (is_object($oService) && is_object($oSubService))
  203. {
  204. $oRequest = new UserRequest();
  205. $oRequest->Set('org_id', $oUserOrg->GetKey());
  206. $oRequest->Set('caller_id', UserRights::GetContactId());
  207. $oRequest->Set('service_id', $aParameters['service_id']);
  208. $oRequest->Set('servicesubcategory_id', $aParameters['servicesubcategory_id']);
  209. $oAttDef = MetaModel::GetAttributeDef('UserRequest', 'service_id');
  210. $aDetails[] = array('label' => '<span>'.$oAttDef->GetLabel().'</span>', 'value' => htmlentities($oService->GetName(), ENT_QUOTES, 'UTF-8'));
  211. $oAttDef = MetaModel::GetAttributeDef('UserRequest', 'servicesubcategory_id');
  212. $aDetails[] = array('label' => '<span>'.$oAttDef->GetLabel().'</span>', 'value' => htmlentities($oSubService->GetName(), ENT_QUOTES, 'UTF-8'));
  213. $iFlags = 0;
  214. foreach($aList as $sAttCode)
  215. {
  216. $value = '';
  217. if (isset($aParameters[$sAttCode]))
  218. {
  219. $value = $aParameters[$sAttCode];
  220. $oRequest->Set($sAttCode, $value);
  221. }
  222. }
  223. $aFieldsMap = array();
  224. foreach($aList as $sAttCode)
  225. {
  226. $value = '';
  227. $oAttDef = MetaModel::GetAttributeDef(get_class($oRequest), $sAttCode);
  228. $iFlags = $oRequest->GetAttributeFlags($sAttCode);
  229. if (isset($aParameters[$sAttCode]))
  230. {
  231. $value = $aParameters[$sAttCode];
  232. }
  233. $aArgs = array('this' => $oRequest);
  234. $aFieldsMap[$sAttCode] = 'attr_'.$sAttCode;
  235. $sValue = $oRequest->GetFormElementForField($oP, get_class($oRequest), $sAttCode, $oAttDef, $value, '', 'attr_'.$sAttCode, '', $iFlags, $aArgs);
  236. $aDetails[] = array('label' => '<span>'.$oAttDef->GetLabel().'</span>', 'value' => $sValue);
  237. }
  238. $aDetails[] = array('label' => '<span>'.Dict::S('Portal:Attachments').'</span>', 'value' => '&nbsp;');
  239. $aDetails[] = array('label' => '&nbsp;', 'value' => '<div id="attachments"></div><p><button type="button" onClick="AddAttachment();">'.Dict::S('Portal:AddAttachment').'</button/></p>');
  240. $oP->add_linked_script("../js/json.js");
  241. $oP->add_linked_script("../js/forms-json-utils.js");
  242. $oP->add_linked_script("../js/wizardhelper.js");
  243. $oP->add_linked_script("../js/wizard.utils.js");
  244. $oP->add_linked_script("../js/linkswidget.js");
  245. $oP->add_linked_script("../js/extkeywidget.js");
  246. $oP->add_linked_script("../js/jquery.blockUI.js");
  247. $oP->add("<div class=\"wizContainer\" id=\"form_request_description\">\n");
  248. $oP->add("<h1 id=\"title_request_form\">".Dict::S('Portal:DescriptionOfTheRequest')."</h1>\n");
  249. $oP->add("<form action=\"../portal/index.php\" enctype=\"multipart/form-data\" id=\"request_form\" method=\"post\">\n");
  250. $oP->add("<table><tr><td>\n");
  251. $oP->details($aDetails);
  252. $oP->add("</td></tr></table>\n");
  253. DumpHiddenParams($oP, $aList, $aParameters);
  254. $oP->add("<input type=\"hidden\" name=\"step\" value=\"3\">");
  255. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_request\">");
  256. $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
  257. $oP->p("<input type=\"submit\" value=\"".Dict::S('UI:Button:Back')."\" onClick=\"GoBack();\">&nbsp;<input type=\"submit\" value=\"".Dict::S('UI:Button:Finish')."\">");
  258. $oP->add("</form>");
  259. $oP->add("</div>\n");
  260. $iFieldsCount = count($aFieldsMap);
  261. $sJsonFieldsMap = json_encode($aFieldsMap);
  262. $oP->add_ready_script(
  263. <<<EOF
  264. // Create the object once at the beginning of the page... no state specified => new
  265. var oWizardHelper = new WizardHelper('UserRequest', '');
  266. oWizardHelper.SetFieldsMap($sJsonFieldsMap);
  267. oWizardHelper.SetFieldsCount($iFieldsCount);
  268. // Starts the validation when the page is ready
  269. CheckFields('request_form', false);
  270. $('#request_form').submit( function() {
  271. return OnSubmit('request_form');
  272. });
  273. EOF
  274. );
  275. $sBtnLabel = Dict::S('Portal:RemoveAttachment');
  276. $oP->add_script(
  277. <<<EOF
  278. var index = 0;
  279. function AddAttachment()
  280. {
  281. $('#attachments').append('<p id="attachment_'+index+'"><input type="file" name="attachement_'+index+'"/>&nbsp;<button type="button" onClick="RemoveAttachment('+index+')">{$sBtnLabel}</button/></p>');
  282. index++;
  283. }
  284. function RemoveAttachment(id_attachment)
  285. {
  286. $('#attachment_'+id_attachment).remove();
  287. }
  288. EOF
  289. );
  290. }
  291. else
  292. {
  293. // User not authorized to use this service ?
  294. DisplayMainMenu($oP);
  295. }
  296. }
  297. /**
  298. * Validate the parameters and create the UserRequest object (based on the page's POSTed parameters)
  299. * @param WebPage $oP The current web page for the output
  300. * @param Organization $oUserOrg The organization of the current user
  301. * @return void
  302. */
  303. function DoCreateRequest($oP, $oUserOrg)
  304. {
  305. $aParameters = ReadAllParams();
  306. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  307. if (!utils::IsTransactionValid($sTransactionId))
  308. {
  309. $oP->add("<h1>".Dict::S('UI:Error:ObjectAlreadyCreated')."</h1>\n");
  310. DisplayMainMenu($oP);
  311. return;
  312. }
  313. // Validate the parameters
  314. // 1) Service
  315. $oSearch = DBObjectSearch::FromOQL('SELECT Service AS s JOIN SLA AS sla ON sla.service_id=s.id JOIN lnkContractToSLA AS ln ON ln.sla_id=sla.id JOIN CustomerContract AS cc ON ln.contract_id=cc.id WHERE cc.org_id = :org_id AND s.id = :svc_id');
  316. $oSet = new CMDBObjectSet($oSearch, array(), array('org_id' => $oUserOrg->GetKey(), 'svc_id' => $aParameters['service_id']));
  317. if ($oSet->Count() != 1)
  318. {
  319. // Invalid service for the current user !
  320. throw new Exception("Invalid Service: id={$aParameters['servicesubcategory_id']} for the current user (org_id=".$oUserOrg->GetKey().").");
  321. }
  322. $oService = $oSet->Fetch();
  323. // 2) Service Subcategory
  324. $oSearch = DBObjectSearch::FromOQL('SELECT ServiceSubcategory AS sc WHERE sc.id = :subcategory_id AND sc.service_id = :svc_id');
  325. $oSet = new CMDBObjectSet($oSearch, array(), array('svc_id' => $aParameters['service_id'], 'subcategory_id' =>$aParameters['servicesubcategory_id'] ));
  326. if ($oSet->Count() != 1)
  327. {
  328. // Invalid subcategory
  329. throw new Exception("Invalid ServiceSubcategory: id={$aParameters['servicesubcategory_id']} for service ".$oService->GetName()."({$aParameters['service_id']})");
  330. }
  331. $oRequest = new UserRequest();
  332. $oRequest->Set('org_id', $oUserOrg->GetKey());
  333. $oRequest->Set('caller_id', UserRights::GetContactId());
  334. $aList = array('service_id', 'servicesubcategory_id', 'request_type', 'title', 'description', 'impact', 'urgency', 'workgroup_id');
  335. foreach($aList as $sAttCode)
  336. {
  337. $oRequest->Set($sAttCode, $aParameters[$sAttCode]);
  338. }
  339. list($bRes, $aIssues) = $oRequest->CheckToWrite();
  340. if ($bRes)
  341. {
  342. $oMyChange = MetaModel::NewObject("CMDBChange");
  343. $oMyChange->Set("date", time());
  344. $sUserString = CMDBChange::GetCurrentUserName();
  345. $oMyChange->Set("userinfo", $sUserString);
  346. $iChangeId = $oMyChange->DBInsert();
  347. $oRequest->DBInsertTracked($oMyChange);
  348. $oP->add("<h1>".Dict::Format('UI:Title:Object_Of_Class_Created', $oRequest->GetName(), MetaModel::GetName(get_class($oRequest)))."</h1>\n");
  349. // Now process the attachements (if any)
  350. $index = 0;
  351. foreach($_FILES as $sName => $void)
  352. {
  353. $oAttachment = utils::ReadPostedDocument($sName);
  354. if (!$oAttachment->IsEmpty())
  355. {
  356. $index++;
  357. // Create a document and attach it to the created ticket
  358. $oDoc = new FileDoc();
  359. $oDoc->Set('name', Dict::Format('Portal:Attachment_No_To_Ticket_Name', $index, $oRequest->GetName(), $oAttachment->GetFileName()));
  360. $oDoc->Set('org_id', $oUserOrg->GetKey());
  361. $oDoc->Set('description', $oAttachment->GetFileName());
  362. $oDoc->Set('contents', $oAttachment);
  363. $oDoc->DBInsertTracked($oMyChange);
  364. // Link the document to the ticket
  365. $oLink = new lnkTicketToDoc();
  366. $oLink->Set('ticket_id', $oRequest->GetKey());
  367. $oLink->Set('document_id', $oDoc->GetKey());
  368. $oLink->DBInsertTracked($oMyChange);
  369. }
  370. }
  371. DisplayMainMenu($oP);
  372. }
  373. else
  374. {
  375. RequestCreationForm($oP, $oUserOrg);
  376. $sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten', implode(', ', $aIssues));
  377. $oP->add_ready_script("alert('".addslashes($sIssueDesc)."');");
  378. }
  379. }
  380. /**
  381. * Prompts the user for creating a new request
  382. * @param WebPage $oP The current web page
  383. * @return void
  384. */
  385. function CreateRequest(WebPage $oP, Organization $oUserOrg)
  386. {
  387. $iStep = utils::ReadParam('step', 0);
  388. switch($iStep)
  389. {
  390. case 0:
  391. default:
  392. $oP->AddMenuButton('cancel', 'UI:Button:Cancel', './index.php?operation=welcome');
  393. SelectService($oP, $oUserOrg);
  394. break;
  395. case 1:
  396. $oP->AddMenuButton('cancel', 'UI:Button:Cancel', './index.php?operation=welcome');
  397. SelectSubService($oP, $oUserOrg);
  398. break;
  399. case 2:
  400. $oP->AddMenuButton('cancel', 'UI:Button:Cancel', './index.php?operation=welcome');
  401. RequestCreationForm($oP, $oUserOrg);
  402. break;
  403. case 3:
  404. DoCreateRequest($oP, $oUserOrg);
  405. break;
  406. }
  407. }
  408. /**
  409. * Displays the value of the given field, in HTML, without any hyperlink to other objects
  410. * @param DBObject $oObj The object to use
  411. * @param string $sAttCode Code of the attribute to display
  412. * @return string HTML text representing the value of this field
  413. */
  414. function GetFieldAsHtml($oObj, $sAttCode)
  415. {
  416. $sValue = '';
  417. $oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $sAttCode);
  418. if ($oAttDef->IsExternalKey())
  419. {
  420. // Special processing for external keys: don't display any hyperlink
  421. $oTargetObj = MetaModel::GetObject($oAttDef->GetTargetClass(), $oObj->Get($sAttCode), false);
  422. if (is_object($oTargetObj))
  423. {
  424. $sValue = $oTargetObj->GetName();
  425. }
  426. else
  427. {
  428. $sValue = Dict::S('UI:UndefinedObject');
  429. }
  430. }
  431. else
  432. {
  433. $sValue = $oObj->GetAsHTML($sAttCode);
  434. }
  435. return $sValue;
  436. }
  437. /**
  438. * Displays a list of objects, without any hyperlink (except for the object's details)
  439. * @param WebPage $oP The web page for the output
  440. * @param DBObjectSet $oSet The set of objects to display
  441. * @param Array $aZList The ZList (list of field codes) to use for the tabular display
  442. * @return string The HTML text representing the list
  443. */
  444. function DisplaySet($oP, $oSet, $aZList)
  445. {
  446. if ($oSet->Count() > 0)
  447. {
  448. $aAttribs = array();
  449. $aValues = array();
  450. $oAttDef = MetaModel::GetAttributeDef('UserRequest', 'ref');
  451. $aAttribs['key'] = array('label' => $oAttDef->GetLabel(), 'description' => $oAttDef->GetDescription());
  452. foreach($aZList as $sAttCode)
  453. {
  454. $oAttDef = MetaModel::GetAttributeDef('UserRequest', $sAttCode);
  455. $aAttribs[$sAttCode] = array('label' => $oAttDef->GetLabel(), 'description' => $oAttDef->GetDescription());
  456. }
  457. while($oRequest = $oSet->Fetch())
  458. {
  459. $aRow = array();
  460. $aRow['key'] = '<a href="'.utils::GetAbsoluteUrlAppRoot().'portal/index.php?operation=details&id='.$oRequest->GetKey().'">'.$oRequest->Get('ref').'</a>';
  461. $sHilightClass = $oRequest->GetHilightClass();
  462. if ($sHilightClass != '')
  463. {
  464. $aRow['@class'] = $sHilightClass;
  465. }
  466. foreach($aZList as $sAttCode)
  467. {
  468. $aRow[$sAttCode] = GetFieldAsHtml($oRequest, $sAttCode);
  469. }
  470. $aValues[$oRequest->GetKey()] = $aRow;
  471. }
  472. $oP->Table($aAttribs, $aValues);
  473. // Temprory until we merge re-use the paginated tables:
  474. $oP->add_ready_script(
  475. <<<EOF
  476. $('table.listResults').tableHover().tablesorter( { widgets: ['myZebra', 'truncatedList']} );
  477. EOF
  478. );
  479. }
  480. else
  481. {
  482. $oP->add(Dict::S('Portal:NoOpenRequest'));
  483. }
  484. }
  485. /**
  486. * Lists all the currently opened User Requests for the current user
  487. * @param WebPage $oP The current web page
  488. * @return void
  489. */
  490. function ListOpenRequests(WebPage $oP)
  491. {
  492. $iContactId = UserRights::GetContactId();
  493. $oContact = MetaModel::GetObject('Contact', $iContactId, false); // false => Can fail
  494. if (is_object($oContact))
  495. {
  496. $sOQL = 'SELECT UserRequest WHERE caller_id = :contact_id AND status NOT IN ("resolved", "closed")';
  497. $oSearch = DBObjectSearch::FromOQL($sOQL);
  498. $oSet = new CMDBObjectSet($oSearch, array(), array('contact_id' => $iContactId));
  499. $aZList = array('title', 'start_date', 'status', 'service_id', 'priority', 'workgroup_id', 'agent_id');
  500. DisplaySet($oP, $oSet, $aZList);
  501. }
  502. }
  503. /**
  504. * Lists all the currently Resolved (not "Closed")User Requests for the current user
  505. * @param WebPage $oP The current web page
  506. * @return void
  507. */
  508. function ListResolvedRequests(WebPage $oP)
  509. {
  510. $iContactId = UserRights::GetContactId();
  511. $oContact = MetaModel::GetObject('Contact', $iContactId, false); // false => Can fail
  512. if (is_object($oContact))
  513. {
  514. $sOQL = 'SELECT UserRequest WHERE caller_id = :contact_id AND status ="resolved"';
  515. $oSearch = DBObjectSearch::FromOQL($sOQL);
  516. $oSet = new CMDBObjectSet($oSearch, array(), array('contact_id' => $iContactId));
  517. $aZList = array('title', 'start_date', 'status', 'service_id', 'priority', 'workgroup_id', 'agent_id');
  518. DisplaySet($oP, $oSet, $aZList);
  519. }
  520. }
  521. /**
  522. * Displays the details of the specified UserRequest object
  523. * @param WebPage $oP The current web page for the output
  524. * @param UserRequest $oRequest The object to display
  525. * @return void
  526. */
  527. function DisplayRequestDetails($oP, UserRequest $oRequest, $bEditMode = true)
  528. {
  529. // Identical to the standard 'details' ZList of UserRequest, except that the field 'org_id' has been removed
  530. $aList = array(
  531. 'col:col1' => array(
  532. 'fieldset:Ticket:baseinfo' => array('ref','title','request_type','status','priority','service_id','servicesubcategory_id','product' ),
  533. 'fieldset:Ticket:moreinfo' => array('impact','urgency','description','resolution_code', 'solution', 'user_satisfaction', 'user_commment','freeze_reason'),
  534. ),
  535. 'col:col2' => array(
  536. 'fieldset:Ticket:date' => array('start_date','last_update','assignment_date','tto_escalation_deadline', 'ttr_escalation_deadline', 'close_date', 'closure_deadline',),
  537. 'fieldset:Ticket:contact' => array('caller_id','workgroup_id','agent_id',),
  538. 'fieldset:Ticket:relation' => array('related_problem_id', 'related_change_id'),
  539. )
  540. );
  541. // Similar to CMDBAbstractObject::GetBareProperties except that: multiple tabs are not supported and GetFieldAsHtml is customized
  542. // in order to NOT display any hyperlink
  543. $aDetails = array();
  544. $oP->add('<div id="request_details" class="ui-widget-content">');
  545. $aDetailsStruct = CMDBAbstractObject::ProcessZlist($aList, array('UI:PropertiesTab' => array()), 'UI:PropertiesTab', 'col1', '');
  546. // Compute the list of properties to display, first the attributes in the 'details' list, then
  547. // all the remaining attributes that are not external fields
  548. $aDetails = array();
  549. $iInputId = 0;
  550. foreach($aDetailsStruct as $sTab => $aCols )
  551. {
  552. $aDetails[$sTab] = array();
  553. ksort($aCols);
  554. $oP->add('<table style="vertical-align:top"><tr>');
  555. foreach($aCols as $sColIndex => $aFieldsets)
  556. {
  557. $oP->add('<td style="vertical-align:top">');
  558. //$aDetails[$sTab][$sColIndex] = array();
  559. $sLabel = '';
  560. $sPreviousLabel = '';
  561. $aDetails[$sTab][$sColIndex] = array();
  562. foreach($aFieldsets as $sFieldsetName => $aFields)
  563. {
  564. if (!empty($sFieldsetName) && ($sFieldsetName[0] != '_'))
  565. {
  566. $sLabel = $sFieldsetName;
  567. }
  568. else
  569. {
  570. $sLabel = '';
  571. }
  572. if ($sLabel != $sPreviousLabel)
  573. {
  574. if (!empty($sPreviousLabel))
  575. {
  576. $oP->add('<fieldset>');
  577. $oP->add('<legend>'.Dict::S($sPreviousLabel).'</legend>');
  578. }
  579. $oP->Details($aDetails[$sTab][$sColIndex]);
  580. if (!empty($sPreviousLabel))
  581. {
  582. $oP->add('</fieldset>');
  583. }
  584. $aDetails[$sTab][$sColIndex] = array();
  585. $sPreviousLabel = $sLabel;
  586. }
  587. foreach($aFields as $sAttCode)
  588. {
  589. if (MetaModel::IsValidAttCode(get_class($oRequest), $sAttCode))
  590. {
  591. $iFlags = $oRequest->GetAttributeFlags($sAttCode);
  592. if ( ($iFlags & OPT_ATT_HIDDEN) == 0)
  593. {
  594. // The field is visible, add it to the current column
  595. $val = GetFieldAsHtml($oRequest, $sAttCode);
  596. $aDetails[$sTab][$sColIndex][] = array( 'label' => '<span title="'.MetaModel::GetDescription('UserRequest', $sAttCode).'">'.MetaModel::GetLabel('UserRequest', $sAttCode).'</span>', 'value' => $val);
  597. $iInputId++;
  598. }
  599. }
  600. }
  601. }
  602. if (!empty($sPreviousLabel))
  603. {
  604. $oP->add('<fieldset>');
  605. $oP->add('<legend>'.Dict::S($sFieldsetName).'</legend>');
  606. }
  607. $oP->Details($aDetails[$sTab][$sColIndex]);
  608. if (!empty($sPreviousLabel))
  609. {
  610. $oP->add('</fieldset>');
  611. }
  612. $oP->add('</td>');
  613. }
  614. $oP->add('</tr></table>');
  615. }
  616. // Attachments
  617. $sOQL = 'SELECT FileDoc AS Doc JOIN lnkTicketToDoc AS L ON L.document_id = Doc.id WHERE L.ticket_id = :request_id';
  618. $oSearch = DBObjectSearch::FromOQL($sOQL);
  619. $oSet = new CMDBObjectSet($oSearch, array(), array('request_id' => $oRequest->GetKey()));
  620. $aDetails = array();
  621. if ($oSet->Count() > 0)
  622. {
  623. $sAttachements = '<table>';
  624. while($oDoc = $oSet->Fetch())
  625. {
  626. $sAttachements .= '<tr><td>'.$oDoc->GetAsHtml('contents').'</td></tr>';
  627. }
  628. $sAttachements .= '</table>';
  629. $aDetails[] = array('label' => Dict::S('Portal:Attachments'), 'value' => $sAttachements);
  630. }
  631. $oP->Details($aDetails);
  632. // Case log... editable so that users can post comments
  633. if ($bEditMode)
  634. {
  635. $oP->add("<form action=\"../portal/index.php\" id=\"request_form\" method=\"post\">\n");
  636. $oP->add("<input type=\"hidden\" name=\"id\" value=\"".$oRequest->GetKey()."\">");
  637. $oP->add("<input type=\"hidden\" name=\"step\" value=\"3\">");
  638. $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
  639. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"details\">");
  640. $oP->add('<fieldset id="request_details_log"><legend>'.MetaModel::GetLabel('UserRequest', 'ticket_log').'</legend>');
  641. $oAttDef = MetaModel::GetAttributeDef(get_class($oRequest), 'ticket_log');
  642. $oValue = $oRequest->Get('ticket_log');
  643. $oP->add($oRequest->GetFormElementForField($oP, get_class($oRequest), 'ticket_log', $oAttDef, $oValue, $sDisplayValue = '', $iId = 'att_ticket_log'));
  644. //$oP->add(GetFieldAsHtml($oRequest, 'ticket_log'));
  645. $oP->add('</fieldset>');
  646. $oP->p('<input type="submit" value="'.Dict::S('UI:Button:Ok').'">');
  647. $oP->add('</form>');
  648. }
  649. else
  650. {
  651. $oP->add('<fieldset id="request_details_log"><legend>'.MetaModel::GetLabel('UserRequest', 'ticket_log').'</legend>');
  652. $oP->add(GetFieldAsHtml($oRequest, 'ticket_log'));
  653. $oP->add('</fieldset>');
  654. }
  655. $oP->add('</div>');
  656. }
  657. /**
  658. * Displays a form for the user to provide feedback about a 'resolved' UserRequest and then close the request
  659. * @param WebPage $oP The current web page
  660. * @param UserRequest $oRequest The object to display
  661. * @return void
  662. */
  663. function DisplayResolvedRequestForm($oP, UserRequest $oRequest)
  664. {
  665. $oP->add("<div class=\"wizContainer\" id=\"form_close_request\">\n");
  666. $oP->add("<form action=\"../portal/index.php\" id=\"request_form\" method=\"post\">\n");
  667. $aArgs = array('this' => $oRequest);
  668. $sClass = get_class($oRequest);
  669. $aDetails = array();
  670. $aTargetStates = MetaModel::EnumStates($sClass);
  671. $aTargetState = $aTargetStates['closed'];
  672. $aExpectedAttributes = $aTargetState['attribute_list'];
  673. $iFieldIndex = 0;
  674. foreach($aExpectedAttributes as $sAttCode => $iExpectCode)
  675. {
  676. // Prompt for an attribute if
  677. // - the attribute must be changed or must be displayed to the user for confirmation
  678. // - or the field is mandatory and currently empty
  679. if ( ($iExpectCode & (OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT)) ||
  680. (($iExpectCode & OPT_ATT_MANDATORY) && ($oRequest->Get($sAttCode) == '')) )
  681. {
  682. $aAttributesDef = MetaModel::ListAttributeDefs($sClass);
  683. $oAttDef = $aAttributesDef[$sAttCode];
  684. $aArgs = array('this' => $oRequest);
  685. $sHTMLValue = cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $oRequest->Get($sAttCode), $oRequest->GetEditValue($sAttCode), 'att_'.$iFieldIndex, '', $iExpectCode, $aArgs);
  686. $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => "<span id=\"field_att_$iFieldIndex\">$sHTMLValue</span>");
  687. $aFieldsMap[$sAttCode] = 'att_'.$iFieldIndex;
  688. $iFieldIndex++;
  689. }
  690. }
  691. $aStimuli = MetaModel::EnumStimuli($sClass);
  692. $oP->add("<h1>".Dict::S('Portal:EnterYourCommentsOnTicket')."</h1>");
  693. $oP->details($aDetails);
  694. $oP->add("<input type=\"hidden\" name=\"id\" value=\"".$oRequest->GetKey()."\">");
  695. $oP->add("<input type=\"hidden\" name=\"step\" value=\"2\">");
  696. $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
  697. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"details\">");
  698. $oP->p("<input type=\"submit\" value=\"".Dict::S('Portal:Button:CloseTicket')."\">");
  699. $oP->add("</form>");
  700. $oP->add("</div>\n");
  701. $oP->add("<h1 id=\"title_request_details\">".Dict::Format('Portal:TitleRequestDetailsFor_Request', $oRequest->GetName())."</h1>\n");
  702. DisplayRequestDetails($oP, $oRequest, false /* bEditMode */);
  703. $oP->add_ready_script(
  704. <<<EOF
  705. // Starts the validation when the page is ready
  706. CheckFields('request_form', false);
  707. $('#request_form').submit( function() {
  708. return OnSubmit('request_form');
  709. });
  710. EOF
  711. );
  712. }
  713. /**
  714. * Actually close the request and saves the user's feedback
  715. * @param WebPage $oP The current web page
  716. * @param UserRequest $oRequest The object to close
  717. * @return void
  718. */
  719. function DoCloseRequest($oP, UserRequest $oRequest)
  720. {
  721. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  722. if (!utils::IsTransactionValid($sTransactionId))
  723. {
  724. $oP->add("<h1>".Dict::S('UI:Error:ObjectAlreadyCreated')."</h1>\n");
  725. DisplayMainMenu($oP);
  726. return;
  727. }
  728. $sClass = get_class($oRequest);
  729. $aDetails = array();
  730. $aTargetStates = MetaModel::EnumStates($sClass);
  731. $aTargetState = $aTargetStates['closed'];
  732. $aExpectedAttributes = $aTargetState['attribute_list'];
  733. $iFieldIndex = 0;
  734. foreach($aExpectedAttributes as $sAttCode => $iExpectCode)
  735. {
  736. // Prompt for an attribute if
  737. // - the attribute must be changed or must be displayed to the user for confirmation
  738. // - or the field is mandatory and currently empty
  739. if ( ($iExpectCode & (OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT)) ||
  740. (($iExpectCode & OPT_ATT_MANDATORY) && ($oRequest->Get($sAttCode) == '')) )
  741. {
  742. $value = utils::ReadPostedParam('attr_'.$sAttCode, null);
  743. if (!is_null($value))
  744. {
  745. $oRequest->Set($sAttCode, $value);
  746. }
  747. }
  748. }
  749. if ($oRequest->ApplyStimulus('ev_close'))
  750. {
  751. $oMyChange = MetaModel::NewObject("CMDBChange");
  752. $oMyChange->Set("date", time());
  753. $sUserString = CMDBChange::GetCurrentUserName();
  754. $oMyChange->Set("userinfo", $sUserString);
  755. $iChangeId = $oMyChange->DBInsert();
  756. $oRequest->DBUpdateTracked($oMyChange);
  757. $oP->p("<h1>".Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oRequest)), $oRequest->GetName())."</h1>\n");
  758. DisplayMainMenu($oP);
  759. }
  760. else
  761. {
  762. $oP->AddMenuButton('back', 'Portal:Back', './index.php?operation=welcome');
  763. $oP->add('Error: cannot close the request - '.$oRequest->GetName());
  764. }
  765. }
  766. /**
  767. * Find the UserRequest object of the specified ID. Make sure that it the caller is the current user
  768. * @param integer $id The ID of the request to find
  769. * @return UserRequert The found object, or null in case of failure (object does not exist, user has no rights to see it...)
  770. */
  771. function FindRequest($id)
  772. {
  773. $oRequest = null;
  774. $iContactId = UserRights::GetContactId();
  775. $oContact = MetaModel::GetObject('Contact', $iContactId, false); // false => Can fail
  776. if (is_object($oContact))
  777. {
  778. $sOQL = "SELECT UserRequest WHERE caller_id = :contact_id AND id = :request_id";
  779. $oSearch = DBObjectSearch::FromOQL($sOQL);
  780. $oSet = new CMDBObjectSet($oSearch, array(), array('contact_id' => $iContactId, 'request_id' => $id));
  781. if ($oSet->Count() > 0)
  782. {
  783. $oRequest = $oSet->Fetch();
  784. }
  785. }
  786. else
  787. {
  788. $oP->AddMenuButton('back', 'Portal:Back', './index.php?operation=welcome');
  789. $oP->add("<p class=\"error\">".Dict::S('Portal:ErrorNoContactForThisUser')."</p>");
  790. }
  791. return $oRequest;
  792. }
  793. /**
  794. * Displays the details of a request
  795. * @param WebPage $oP The current web page
  796. * @return void
  797. */
  798. function RequestDetails(WebPage $oP, $id)
  799. {
  800. $oRequest = FindRequest($id);
  801. if (!is_object($oRequest))
  802. {
  803. DisplayMainMenu($oP);
  804. return;
  805. }
  806. $iDefaultStep = 0;
  807. if ($oRequest->GetState() == 'resolved')
  808. {
  809. // The current ticket is in 'resolved' state, prompt to close it
  810. $iDefaultStep = 1;
  811. }
  812. $iStep = utils::ReadParam('step', $iDefaultStep);
  813. switch($iStep)
  814. {
  815. case 0:
  816. $oP->AddMenuButton('back', 'Portal:Back', './index.php?operation=welcome');
  817. $oP->add("<h1 id=\"title_request_details\">".$oRequest->GetIcon()."&nbsp;".Dict::Format('Portal:TitleRequestDetailsFor_Request', $oRequest->GetName())."</h1>\n");
  818. DisplayRequestDetails($oP, $oRequest);
  819. break;
  820. case 1:
  821. $oP->AddMenuButton('cancel', 'UI:Button:Cancel', './index.php?operation=welcome');
  822. DisplayResolvedRequestForm($oP, $oRequest);
  823. break;
  824. case 2:
  825. DoCloseRequest($oP, $oRequest);
  826. break;
  827. case 3:
  828. AddComment($oP, $oRequest);
  829. break;
  830. default:
  831. // Should never happen
  832. DisplayMainMenu($oP);
  833. }
  834. }
  835. /**
  836. * Adds a comment to the specified UserRequest and displays the main menu
  837. * @param WebPage $oP The current web page for the output
  838. * @param $id ID of the object to update
  839. * @return void
  840. */
  841. function AddComment($oP, $id)
  842. {
  843. $oRequest = FindRequest($id);
  844. if (!is_object($oRequest))
  845. {
  846. DisplayMainMenu($oP);
  847. return;
  848. }
  849. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  850. if (!utils::IsTransactionValid($sTransactionId))
  851. {
  852. $oP->add("<h1>".Dict::S('UI:Error:ObjectAlreadyUpdated')."</h1>\n");
  853. DisplayMainMenu($oP);
  854. return;
  855. }
  856. $sComment = trim(utils::ReadPostedParam('attr_ticket_log'));
  857. if (!empty($sComment))
  858. {
  859. $oRequest->Set('ticket_log', $sComment);
  860. $oMyChange = MetaModel::NewObject("CMDBChange");
  861. $oMyChange->Set("date", time());
  862. $sUserString = CMDBChange::GetCurrentUserName();
  863. $oMyChange->Set("userinfo", $sUserString);
  864. $iChangeId = $oMyChange->DBInsert();
  865. $oRequest->DBUpdateTracked($oMyChange);
  866. $oP->p("<h1>".Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oRequest)), $oRequest->GetName())."</h1>\n");
  867. }
  868. else
  869. {
  870. $oP->p("<h1>".Dict::Format('UI:Class_Object_NotUpdated', MetaModel::GetName(get_class($oRequest)), $oRequest->GetName())."</h1>\n");
  871. }
  872. DisplayMainMenu($oP);
  873. }
  874. /**
  875. * Get The organization of the current user (i.e. the organization of its contact)
  876. * @param WebPage $oP The current page, for errors output
  877. * @return Organization The user's org or null in case of problem...
  878. */
  879. function GetUserOrg()
  880. {
  881. $oOrg = null;
  882. $iContactId = UserRights::GetContactId();
  883. $oContact = MetaModel::GetObject('Contact', $iContactId, false); // false => Can fail
  884. if (is_object($oContact))
  885. {
  886. $oOrg = MetaModel::GetObject('Organization', $oContact->Get('org_id'), false); // false => can fail
  887. }
  888. else
  889. {
  890. throw new Exception(Dict::S('Portal:ErrorNoContactForThisUser'));
  891. }
  892. return $oOrg;
  893. }
  894. try
  895. {
  896. require_once(APPROOT.'/application/startup.inc.php');
  897. require_once(APPROOT.'/application/portalwebpage.class.inc.php');
  898. $oAppContext = new ApplicationContext();
  899. $sOperation = utils::ReadParam('operation', '');
  900. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  901. LoginWebPage::DoLogin(false /* bMustBeAdmin */, true /* IsAllowedToPortalUsers */); // Check user rights and prompt if needed
  902. $oUserOrg = GetUserOrg();
  903. $sCode = $oUserOrg->Get('code');
  904. $sAlternateStylesheet = '';
  905. if (@file_exists("./$sCode/portal.css"))
  906. {
  907. $sAlternateStylesheet = "$sCode";
  908. }
  909. $oP = new PortalWebPage(Dict::S('Portal:Title'), $sAlternateStylesheet);
  910. $oP->add($sAlternateStylesheet);
  911. if (is_object($oUserOrg))
  912. {
  913. switch($sOperation)
  914. {
  915. case 'create_request':
  916. CreateRequest($oP, $oUserOrg);
  917. break;
  918. case 'details':
  919. $iRequestId = utils::ReadParam('id', 0);
  920. RequestDetails($oP, $iRequestId);
  921. break;
  922. case 'welcome':
  923. default:
  924. DisplayMainMenu($oP);
  925. }
  926. }
  927. $oP->output();
  928. }
  929. catch(CoreException $e)
  930. {
  931. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  932. $oP = new SetupWebPage(Dict::S('UI:PageTitle:FatalError'));
  933. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  934. $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
  935. $oP->output();
  936. if (MetaModel::IsLogEnabledIssue())
  937. {
  938. if (MetaModel::IsValidClass('EventIssue'))
  939. {
  940. try
  941. {
  942. $oLog = new EventIssue();
  943. $oLog->Set('message', $e->getMessage());
  944. $oLog->Set('userinfo', '');
  945. $oLog->Set('issue', $e->GetIssue());
  946. $oLog->Set('impact', 'Page could not be displayed');
  947. $oLog->Set('callstack', $e->getTrace());
  948. $oLog->Set('data', $e->getContextData());
  949. $oLog->DBInsertNoReload();
  950. }
  951. catch(Exception $e)
  952. {
  953. IssueLog::Error("Failed to log issue into the DB");
  954. }
  955. }
  956. IssueLog::Error($e->getMessage());
  957. }
  958. // For debugging only
  959. //throw $e;
  960. }
  961. catch(Exception $e)
  962. {
  963. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  964. $oP = new SetupWebPage(Dict::S('UI:PageTitle:FatalError'));
  965. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  966. $oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
  967. $oP->output();
  968. if (MetaModel::IsLogEnabledIssue())
  969. {
  970. if (MetaModel::IsValidClass('EventIssue'))
  971. {
  972. try
  973. {
  974. $oLog = new EventIssue();
  975. $oLog->Set('message', $e->getMessage());
  976. $oLog->Set('userinfo', '');
  977. $oLog->Set('issue', 'PHP Exception');
  978. $oLog->Set('impact', 'Page could not be displayed');
  979. $oLog->Set('callstack', $e->getTrace());
  980. $oLog->Set('data', array());
  981. $oLog->DBInsertNoReload();
  982. }
  983. catch(Exception $e)
  984. {
  985. IssueLog::Error("Failed to log issue into the DB");
  986. }
  987. }
  988. IssueLog::Error($e->getMessage());
  989. }
  990. }
  991. ?>