index.php 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. <?php
  2. // Copyright (C) 2010-2013 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * iTop User Portal main page
  20. *
  21. * @copyright Copyright (C) 2010-2013 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  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. * Displays the portal main menu
  30. * @param WebPage $oP The current web page
  31. * @return void
  32. */
  33. function DisplayMainMenu(WebPage $oP)
  34. {
  35. $oP->AddMenuButton('showongoing', 'Portal:ShowOngoing', '../portal/index.php?operation=show_ongoing');
  36. $oP->AddMenuButton('newrequest', 'Portal:CreateNewRequest', '../portal/index.php?operation=create_request');
  37. $oP->AddMenuButton('showclosed', 'Portal:ShowClosed', '../portal/index.php?operation=show_closed');
  38. if (UserRights::CanChangePassword())
  39. {
  40. $oP->AddMenuButton('change_pwd', 'Portal:ChangeMyPassword', '../portal/index.php?loginop=change_pwd');
  41. }
  42. }
  43. /**
  44. * Displays the current tickets
  45. * @param WebPage $oP The current web page
  46. * @return void
  47. */
  48. function ShowOngoingTickets(WebPage $oP)
  49. {
  50. $oP->add("<div id=\"open_requests\">\n");
  51. $oP->add("<h1 id=\"title_open_requests\">".Dict::S('Portal:OpenRequests')."</h1>\n");
  52. ListOpenRequests($oP);
  53. $oP->add("</div>\n");
  54. $oP->add("<div id=\"#div_resolved_requests\">\n");
  55. $oP->add("<h1 id=\"#resolved_requests\">".Dict::S('Portal:ResolvedRequests')."</h1>\n");
  56. ListResolvedRequests($oP);
  57. $oP->add("</div>\n");
  58. }
  59. /**
  60. * Displays the closed tickets
  61. * @param WebPage $oP The current web page
  62. * @return void
  63. */
  64. function ShowClosedTickets(WebPage $oP)
  65. {
  66. $oP->add("<div id=\"#closed_tickets\">\n");
  67. //$oP->add("<h1 id=\"#closed_tickets\">".Dict::S('Portal:ListClosedTickets')."</h1>\n");
  68. ListClosedTickets($oP);
  69. $oP->add("</div>\n");
  70. }
  71. /**
  72. * Displays the form to select a Service Category Id (among the valid ones for the specified user Organization)
  73. * @param WebPage $oP Web page for the form output
  74. * @param Organization $oUserOrg The organization of the current user
  75. * @return void
  76. */
  77. function SelectServiceCategory($oP, $oUserOrg)
  78. {
  79. $aParameters = $oP->ReadAllParams(PORTAL_ALL_PARAMS.',template_id');
  80. $oSearch = DBObjectSearch::FromOQL(PORTAL_SERVICECATEGORY_QUERY);
  81. $oSearch->AllowAllData(); // In case the user has the rights on his org only
  82. $oSet = new CMDBObjectSet($oSearch, array(), array('org_id' => $oUserOrg->GetKey()));
  83. if ($oSet->Count() == 1)
  84. {
  85. $oService = $oSet->Fetch();
  86. $iSvcCategory = $oService->GetKey();
  87. // Only one Category, skip this step in the wizard
  88. SelectServiceSubCategory($oP, $oUserOrg, $iSvcCategory);
  89. }
  90. else
  91. {
  92. $oP->add("<div class=\"wizContainer\" id=\"form_select_service\">\n");
  93. $oP->WizardFormStart('request_wizard', 1);
  94. $oP->add("<h1 id=\"select_category\">".Dict::S('Portal:SelectService')."</h1>\n");
  95. $oP->add("<table>\n");
  96. while($oService = $oSet->Fetch())
  97. {
  98. $id = $oService->GetKey();
  99. $sChecked = "";
  100. if (isset($aParameters['service_id']) && ($id == $aParameters['service_id']))
  101. {
  102. $sChecked = "checked";
  103. }
  104. $oP->p("<tr><td style=\"vertical-align:top\"><p><input name=\"attr_service_id\" $sChecked type=\"radio\" id=\"service_$id\" value=\"$id\"></p></td><td style=\"vertical-align:top\"><p><b><label for=\"service_$id\">".$oService->GetName()."</label></b></p>");
  105. $oP->p("<p>".$oService->GetAsHTML('description')."</p></td></tr>");
  106. }
  107. $oP->add("</table>\n");
  108. $oP->DumpHiddenParams($aParameters, array('service_id'));
  109. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_request\">");
  110. $oP->WizardFormButtons(BUTTON_NEXT | BUTTON_CANCEL); // NO back button since it's the first step of the Wizard
  111. $oP->WizardFormEnd();
  112. $oP->WizardCheckSelectionOnSubmit(Dict::S('Portal:PleaseSelectOneService'));
  113. $oP->add("</div>\n");
  114. }
  115. }
  116. /**
  117. * Displays the form to select a Service Subcategory Id (among the valid ones for the specified user Organization)
  118. * and based on the page's parameter 'service_id'
  119. * @param WebPage $oP Web page for the form output
  120. * @param Organization $oUserOrg The organization of the current user
  121. * @param $iSvcId Id of the selected service in case of pass-through (when there is only one service)
  122. * @return void
  123. */
  124. function SelectServiceSubCategory($oP, $oUserOrg, $iSvcId = null)
  125. {
  126. $aParameters = $oP->ReadAllParams(PORTAL_ALL_PARAMS.',template_id');
  127. if ($iSvcId == null)
  128. {
  129. $iSvcId = $aParameters['service_id'];
  130. }
  131. else
  132. {
  133. $aParameters['service_id'] = $iSvcId;
  134. }
  135. $iDefaultSubSvcId = isset($aParameters['servicesubcategory_id']) ? $aParameters['servicesubcategory_id'] : 0;
  136. $iDefaultWizNext = 2;
  137. $oSearch = DBObjectSearch::FromOQL(PORTAL_SERVICE_SUBCATEGORY_QUERY);
  138. $oSearch->AllowAllData(); // In case the user has the rights on his org only
  139. $oSet = new CMDBObjectSet($oSearch, array(), array('svc_id' => $iSvcId, 'org_id' => $oUserOrg->GetKey()));
  140. if ($oSet->Count() == 1)
  141. {
  142. // Only one sub service, skip this step of the wizard
  143. $oSubService = $oSet->Fetch();
  144. $iSubSvdId = $oSubService->GetKey();
  145. SelectRequestTemplate($oP, $oUserOrg, $iSvcId, $iSubSvdId);
  146. }
  147. else
  148. {
  149. $oServiceCategory = MetaModel::GetObject('Service', $iSvcId, false, true /* allow all data*/);
  150. if (is_object($oServiceCategory))
  151. {
  152. $oP->add("<div class=\"wizContainer\" id=\"form_select_servicesubcategory\">\n");
  153. $oP->add("<h1 id=\"select_subcategory\">".Dict::Format('Portal:SelectSubcategoryFrom_Service', $oServiceCategory->GetName())."</h1>\n");
  154. $oP->WizardFormStart('request_wizard', $iDefaultWizNext);
  155. $oP->add("<table>\n");
  156. while($oSubService = $oSet->Fetch())
  157. {
  158. $id = $oSubService->GetKey();
  159. $sChecked = "";
  160. if ($id == $iDefaultSubSvcId)
  161. {
  162. $sChecked = "checked";
  163. }
  164. $oP->add("<tr>");
  165. $oP->add("<td style=\"vertical-align:top\">");
  166. $oP->add("<p><input name=\"attr_servicesubcategory_id\" $sChecked type=\"radio\" id=\"servicesubcategory_$id\" value=\"$id\"></p>");
  167. $oP->add("</td>");
  168. $oP->add("<td style=\"vertical-align:top\">");
  169. $oP->add("<p><b><label for=\"servicesubcategory_$id\">".$oSubService->GetName()."</label></b></p>");
  170. $oP->add("<p>".$oSubService->GetAsHTML('description')."</p>");
  171. $oP->add("</td>");
  172. $oP->add("</tr>");
  173. }
  174. $oP->add("</table>\n");
  175. $oP->DumpHiddenParams($aParameters, array('servicesubcategory_id'));
  176. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_request\">");
  177. $oP->WizardFormButtons(BUTTON_BACK | BUTTON_NEXT | BUTTON_CANCEL); //Back button automatically discarded if on the first page
  178. $oP->WizardFormEnd();
  179. $oP->WizardCheckSelectionOnSubmit(Dict::S('Portal:PleaseSelectAServiceSubCategory'));
  180. $oP->add("</div>\n");
  181. }
  182. else
  183. {
  184. $oP->p("Error: Invalid Service: id = $iSvcId");
  185. }
  186. }
  187. }
  188. /**
  189. * Displays the form to select a Template
  190. * @param WebPage $oP Web page for the form output
  191. * @param Organization $oUserOrg The organization of the current user
  192. * @param $iSvcId Id of the selected service in case of pass-through (when there is only one service)
  193. * @param integer $iSubSvcId The identifier of the sub-service (fall through when there is only one sub-service)
  194. * @return void
  195. */
  196. function SelectRequestTemplate($oP, $oUserOrg, $iSvcId = null, $iSubSvcId = null)
  197. {
  198. $aParameters = $oP->ReadAllParams(PORTAL_ALL_PARAMS.',template_id');
  199. if ($iSvcId != null)
  200. {
  201. $aParameters['service_id'] = $iSvcId;
  202. }
  203. if ($iSubSvcId != null)
  204. {
  205. $aParameters['servicesubcategory_id'] = $iSubSvcId;
  206. }
  207. $iDefaultTemplate = isset($aParameters['template_id']) ? $aParameters['template_id'] : 0;
  208. if (MetaModel::IsValidClass('Template'))
  209. {
  210. $oSearch = DBObjectSearch::FromOQL(REQUEST_TEMPLATE_QUERY);
  211. $oSearch->AllowAllData();
  212. $oSet = new CMDBObjectSet($oSearch, array(), array(
  213. 'service_id' => $aParameters['service_id'],
  214. 'servicesubcategory_id' => $aParameters['servicesubcategory_id']
  215. ));
  216. if ($oSet->Count() == 0)
  217. {
  218. RequestCreationForm($oP, $oUserOrg, $aParameters['service_id'], $aParameters['servicesubcategory_id']);
  219. return;
  220. }
  221. elseif ($oSet->Count() == 1)
  222. {
  223. $oTemplate = $oSet->Fetch();
  224. $iTemplateId = $oTemplate->GetKey();
  225. RequestCreationForm($oP, $oUserOrg, $aParameters['service_id'], $aParameters['servicesubcategory_id'], $iTemplateId);
  226. return;
  227. }
  228. $oServiceSubCategory = MetaModel::GetObject('ServiceSubcategory', $aParameters['servicesubcategory_id'], false);
  229. if (is_object($oServiceSubCategory))
  230. {
  231. $oP->add("<div class=\"wizContainer\" id=\"form_select_servicesubcategory\">\n");
  232. $oP->add("<h1 id=\"select_template\">".Dict::Format('Portal:SelectRequestTemplate', $oServiceSubCategory->GetName())."</h1>\n");
  233. $oP->WizardFormStart('request_wizard', 3);
  234. $oP->add("<table>\n");
  235. while($oTemplate = $oSet->Fetch())
  236. {
  237. $id = $oTemplate->GetKey();
  238. $sChecked = "";
  239. if ($id == $iDefaultTemplate)
  240. {
  241. $sChecked = "checked";
  242. }
  243. $oP->add("<tr>");
  244. $oP->add("<td style=\"vertical-align:top\">");
  245. $oP->p("<input name=\"attr_template_id\" $sChecked type=\"radio\" id=\"template_$id\" value=\"$id\">");
  246. $oP->add("</td>");
  247. $oP->add("<td style=\"vertical-align:top\">");
  248. $oP->p("<b><label for=\"template_$id\">".$oTemplate->GetAsHTML('label')."</label></b>");
  249. $oP->p($oTemplate->GetAsHTML('description'));
  250. $oP->add("</td>");
  251. $oP->add("</tr>");
  252. }
  253. $oP->add("</table>\n");
  254. $oP->DumpHiddenParams($aParameters, array('template_id'));
  255. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_request\">");
  256. $oP->WizardFormButtons(BUTTON_BACK | BUTTON_NEXT | BUTTON_CANCEL); //Back button automatically discarded if on the first page
  257. $oP->WizardCheckSelectionOnSubmit(Dict::S('Portal:PleaseSelectATemplate'));
  258. $oP->WizardFormEnd();
  259. $oP->add("</div>\n");
  260. }
  261. else
  262. {
  263. $oP->p("Error: Invalid servicesubcategory_id = ".$aParameters['servicesubcategory_id']);
  264. }
  265. }
  266. else
  267. {
  268. RequestCreationForm($oP, $oUserOrg, $aParameters['service_id'], $aParameters['servicesubcategory_id']);
  269. return;
  270. }
  271. }
  272. /**
  273. * Displays the form for the final step of the UserRequest creation
  274. * @param WebPage $oP The current web page for the form output
  275. * @param Organization $oUserOrg The organization of the current user
  276. * @param integer $iSvcId The identifier of the service (fall through when there is only one service)
  277. * @param integer $iSubSvcId The identifier of the sub-service (fall through when there is only one sub-service)
  278. * @param integer $iTemplateId The identifier of the template (fall through when there is only one template)
  279. * @return void
  280. */
  281. function RequestCreationForm($oP, $oUserOrg, $iSvcId = null, $iSubSvcId = null, $iTemplateId = null)
  282. {
  283. $oP->add_script(
  284. <<<EOF
  285. // Create the object once at the beginning of the page...
  286. var oWizardHelper = new WizardHelper('UserRequest', '');
  287. EOF
  288. );
  289. $aParameters = $oP->ReadAllParams(PORTAL_ALL_PARAMS.',template_id');
  290. if ($iSvcId != null)
  291. {
  292. $aParameters['service_id'] = $iSvcId;
  293. }
  294. if ($iSubSvcId != null)
  295. {
  296. $aParameters['servicesubcategory_id'] = $iSubSvcId;
  297. }
  298. if ($iTemplateId != null)
  299. {
  300. $aParameters['template_id'] = $iTemplateId;
  301. }
  302. // Example: $aList = array('title', 'description', 'impact', 'emergency');
  303. $aList = explode(',', PORTAL_REQUEST_FORM_ATTRIBUTES);
  304. $sDescription = '';
  305. if (isset($aParameters['template_id']) && ($aParameters['template_id'] != 0))
  306. {
  307. $aTemplateFields = array();
  308. $oTemplate = MetaModel::GetObject('Template', $aParameters['template_id'], false);
  309. if (is_object($oTemplate))
  310. {
  311. $oFieldSearch = DBObjectSearch::FromOQL('SELECT TemplateField WHERE template_id = :template_id');
  312. $oFieldSearch->AllowAllData();
  313. $oFieldSet = new DBObjectSet($oFieldSearch, array('order' => true), array('template_id' => $oTemplate->GetKey()));
  314. while($oField = $oFieldSet->Fetch())
  315. {
  316. $sAttCode = $oField->Get('code');
  317. if (isset($aParameters[$sAttCode]))
  318. {
  319. $oField->Set('initial_value', $aParameters[$sAttCode]);
  320. }
  321. $aTemplateFields[$sAttCode] = $oField;
  322. }
  323. }
  324. }
  325. $oServiceCategory = MetaModel::GetObject('Service', $aParameters['service_id'], false, true /* allow all data*/);
  326. $oServiceSubCategory = MetaModel::GetObject('ServiceSubcategory', $aParameters['servicesubcategory_id'], false, true /* allow all data*/);
  327. if (is_object($oServiceCategory) && is_object($oServiceSubCategory))
  328. {
  329. $oRequest = new UserRequest();
  330. $oRequest->Set('org_id', $oUserOrg->GetKey());
  331. $oRequest->Set('caller_id', UserRights::GetContactId());
  332. $oRequest->Set('service_id', $aParameters['service_id']);
  333. $oRequest->Set('servicesubcategory_id', $aParameters['servicesubcategory_id']);
  334. $oAttDef = MetaModel::GetAttributeDef('UserRequest', 'service_id');
  335. $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $oServiceCategory->GetName());
  336. $oAttDef = MetaModel::GetAttributeDef('UserRequest', 'servicesubcategory_id');
  337. $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $oServiceSubCategory->GetName());
  338. $iFlags = 0;
  339. foreach($aList as $sAttCode)
  340. {
  341. $value = '';
  342. if (isset($aParameters[$sAttCode]))
  343. {
  344. $value = $aParameters[$sAttCode];
  345. $oRequest->Set($sAttCode, $value);
  346. }
  347. }
  348. $aFieldsMap = array();
  349. foreach($aList as $sAttCode)
  350. {
  351. $value = '';
  352. $oAttDef = MetaModel::GetAttributeDef(get_class($oRequest), $sAttCode);
  353. $iFlags = $oRequest->GetAttributeFlags($sAttCode);
  354. if (isset($aParameters[$sAttCode]))
  355. {
  356. $value = $aParameters[$sAttCode];
  357. }
  358. $aArgs = array('this' => $oRequest);
  359. $sInputId = 'attr_'.$sAttCode;
  360. $aFieldsMap[$sAttCode] = $sInputId;
  361. $sValue = "<span id=\"field_{$sInputId}\">".$oRequest->GetFormElementForField($oP, get_class($oRequest), $sAttCode, $oAttDef, $value, '', 'attr_'.$sAttCode, '', $iFlags, $aArgs).'</span>';
  362. $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sValue);
  363. }
  364. // The log must be requested in the constant PORTAL_REQUEST_FORM_ATTRIBUTES
  365. // $aDetails[] = array('label' => MetaModel::GetLabel('UserRequest', PORTAL_ATTCODE_LOG), 'value' => '<textarea id="attr_moreinfo" class="resizable ui-resizable" cols="40" rows="8" name="attr_moreinfo" title="" style="margin: 0px; resize: none; position: static; display: block; height: 145px; width: 339px;">'.$sDescription.'</textarea>');
  366. if (!empty($aTemplateFields))
  367. {
  368. foreach ($aTemplateFields as $sAttCode => $oField)
  369. {
  370. if (!in_array($sAttCode, $aList))
  371. {
  372. $sValue = $oField->GetFormElement($oP, get_class($oRequest));
  373. if ($oField->Get('input_type') == 'hidden')
  374. {
  375. $aHidden[] = $sValue;
  376. }
  377. else
  378. {
  379. $aDetails[] = array('label' => $oField->GetAsHTML('label'), 'value' => $sValue);
  380. }
  381. }
  382. }
  383. }
  384. $oP->add_linked_script("../js/json.js");
  385. $oP->add_linked_script("../js/forms-json-utils.js");
  386. $oP->add_linked_script("../js/wizardhelper.js");
  387. $oP->add_linked_script("../js/wizard.utils.js");
  388. $oP->add_linked_script("../js/linkswidget.js");
  389. $oP->add_linked_script("../js/extkeywidget.js");
  390. $oP->add_linked_script("../js/jquery.blockUI.js");
  391. $oP->add("<div class=\"wizContainer\" id=\"form_request_description\">\n");
  392. $oP->add("<h1 id=\"title_request_form\">".Dict::S('Portal:DescriptionOfTheRequest')."</h1>\n");
  393. $oP->WizardFormStart('request_form', 4);
  394. //$oP->add("<table>\n");
  395. $oP->details($aDetails);
  396. $oAttPlugin = new AttachmentPlugIn();
  397. $oAttPlugin->OnDisplayRelations($oRequest, $oP, true /* edit */);
  398. $oP->DumpHiddenParams($aParameters, $aList);
  399. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_request\">");
  400. $oP->WizardFormButtons(BUTTON_BACK | BUTTON_FINISH | BUTTON_CANCEL); //Back button automatically discarded if on the first page
  401. $oP->WizardFormEnd();
  402. $oP->add("</div>\n");
  403. $iFieldsCount = count($aFieldsMap);
  404. $sJsonFieldsMap = json_encode($aFieldsMap);
  405. $oP->add_ready_script(
  406. <<<EOF
  407. oWizardHelper.SetFieldsMap($sJsonFieldsMap);
  408. oWizardHelper.SetFieldsCount($iFieldsCount);
  409. // Starts the validation when the page is ready
  410. CheckFields('request_form', false);
  411. $('#request_form').submit( function() {
  412. return OnSubmit('request_form');
  413. });
  414. EOF
  415. );
  416. }
  417. else
  418. {
  419. // User not authorized to use this service ?
  420. //ShowOngoingTickets($oP);
  421. }
  422. }
  423. /**
  424. * Validate the parameters and create the UserRequest object (based on the page's POSTed parameters)
  425. * @param WebPage $oP The current web page for the output
  426. * @param Organization $oUserOrg The organization of the current user
  427. * @return void
  428. */
  429. function DoCreateRequest($oP, $oUserOrg)
  430. {
  431. $aParameters = $oP->ReadAllParams(PORTAL_ALL_PARAMS.',template_id');
  432. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  433. if (!utils::IsTransactionValid($sTransactionId))
  434. {
  435. $oP->add("<h1>".Dict::S('UI:Error:ObjectAlreadyCreated')."</h1>\n");
  436. //ShowOngoingTickets($oP);
  437. return;
  438. }
  439. // Validate the parameters
  440. // 1) ServiceCategory
  441. $oSearch = DBObjectSearch::FromOQL(PORTAL_VALIDATE_SERVICECATEGORY_QUERY);
  442. $oSearch->AllowAllData(); // In case the user has the rights on his org only
  443. $oSet = new CMDBObjectSet($oSearch, array(), array('id' => $aParameters['service_id'], 'org_id' => $oUserOrg->GetKey()));
  444. if ($oSet->Count() != 1)
  445. {
  446. // Invalid service for the current user !
  447. throw new Exception("Invalid Service Category: id={$aParameters['service_id']} - count: ".$oSet->Count());
  448. }
  449. $oServiceCategory = $oSet->Fetch();
  450. // 2) Service Subcategory
  451. $oSearch = DBObjectSearch::FromOQL(PORTAL_VALIDATE_SERVICESUBCATEGORY_QUERY);
  452. $oSearch->AllowAllData(); // In case the user has the rights on his org only
  453. $oSet = new CMDBObjectSet($oSearch, array(), array('service_id' => $aParameters['service_id'], 'id' =>$aParameters['servicesubcategory_id'],'org_id' => $oUserOrg->GetKey() ));
  454. if ($oSet->Count() != 1)
  455. {
  456. // Invalid subcategory
  457. throw new Exception("Invalid ServiceSubcategory: id={$aParameters['servicesubcategory_id']} for service category ".$oServiceCategory->GetName()."({$aParameters['service_id']}) - count: ".$oSet->Count());
  458. }
  459. $oServiceSubCategory = $oSet->Fetch();
  460. $oRequest = new UserRequest();
  461. $oRequest->Set('org_id', $oUserOrg->GetKey());
  462. $oRequest->Set('caller_id', UserRights::GetContactId());
  463. $aList = array('service_id', 'servicesubcategory_id', 'title', 'description', 'impact');
  464. $oRequest->UpdateObjectFromPostedForm();
  465. if (isset($aParameters['moreinfo']))
  466. {
  467. // There is a template, insert it into the description
  468. $oRequest->Set(PORTAL_ATTCODE_LOG, $aParameters['moreinfo']);
  469. }
  470. if ((PORTAL_ATTCODE_TYPE != '') && (PORTAL_SET_TYPE_FROM != ''))
  471. {
  472. $oRequest->Set(PORTAL_ATTCODE_TYPE, $oServiceSubCategory->Get(PORTAL_SET_TYPE_FROM));
  473. }
  474. if (MetaModel::IsValidAttCode('UserRequest', 'origin'))
  475. {
  476. $oRequest->Set('origin', 'portal');
  477. }
  478. /////$oP->DoUpdateObjectFromPostedForm($oObj);
  479. $oAttPlugin = new AttachmentPlugIn();
  480. $oAttPlugin->OnFormSubmit($oRequest);
  481. list($bRes, $aIssues) = $oRequest->CheckToWrite();
  482. if ($bRes)
  483. {
  484. if (isset($aParameters['template_id']))
  485. {
  486. $oTemplate = MetaModel::GetObject('Template', $aParameters['template_id']);
  487. $oRequest->Set('public_log', $oTemplate->GetPostedValuesAsText($oRequest)."\n");
  488. $oRequest->DBInsertNoReload();
  489. $oTemplate->RecordExtraDataFromPostedForm($oRequest);
  490. }
  491. else
  492. {
  493. $oRequest->DBInsertNoReload();
  494. }
  495. $oP->add("<h1>".Dict::Format('UI:Title:Object_Of_Class_Created', $oRequest->GetName(), MetaModel::GetName(get_class($oRequest)))."</h1>\n");
  496. //DisplayObject($oP, $oRequest, $oUserOrg);
  497. ShowOngoingTickets($oP);
  498. }
  499. else
  500. {
  501. RequestCreationForm($oP, $oUserOrg);
  502. $sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten', implode(', ', $aIssues));
  503. $oP->add_ready_script("alert('".addslashes($sIssueDesc)."');");
  504. }
  505. }
  506. /**
  507. * Prompts the user for creating a new request
  508. * @param WebPage $oP The current web page
  509. * @return void
  510. */
  511. function CreateRequest(WebPage $oP, Organization $oUserOrg)
  512. {
  513. switch($oP->GetWizardStep())
  514. {
  515. case 0:
  516. default:
  517. SelectServiceCategory($oP, $oUserOrg);
  518. break;
  519. case 1:
  520. SelectServiceSubCategory($oP, $oUserOrg);
  521. break;
  522. case 2:
  523. SelectRequestTemplate($oP, $oUserOrg);
  524. break;
  525. case 3:
  526. RequestCreationForm($oP, $oUserOrg);
  527. break;
  528. case 4:
  529. DoCreateRequest($oP, $oUserOrg);
  530. break;
  531. }
  532. }
  533. /**
  534. * Lists all the currently opened User Requests for the current user
  535. * @param WebPage $oP The current web page
  536. * @return void
  537. */
  538. function ListOpenRequests(WebPage $oP)
  539. {
  540. $oUserOrg = GetUserOrg();
  541. $sOQL = 'SELECT UserRequest WHERE org_id = :org_id AND status NOT IN ("closed", "resolved")';
  542. $oSearch = DBObjectSearch::FromOQL($sOQL);
  543. $iUser = UserRights::GetContactId();
  544. if ($iUser > 0 && !IsPowerUser())
  545. {
  546. $oSearch->AddCondition('caller_id', $iUser);
  547. }
  548. $oSet = new CMDBObjectSet($oSearch, array(), array('org_id' => $oUserOrg->GetKey()));
  549. $aZList = explode(',', PORTAL_TICKETS_LIST_ZLIST);
  550. $oP->DisplaySet($oSet, $aZList, Dict::S('Portal:NoOpenRequest'));
  551. }
  552. /**
  553. * Lists all the currently resolved (not yet closed) User Requests for the current user
  554. * @param WebPage $oP The current web page
  555. * @return void
  556. */
  557. function ListResolvedRequests(WebPage $oP)
  558. {
  559. $oUserOrg = GetUserOrg();
  560. $sOQL = 'SELECT UserRequest WHERE org_id = :org_id AND status = "resolved"';
  561. $oSearch = DBObjectSearch::FromOQL($sOQL);
  562. $iUser = UserRights::GetContactId();
  563. if ($iUser > 0 && !IsPowerUser())
  564. {
  565. $oSearch->AddCondition('caller_id', $iUser);
  566. }
  567. $oSet = new CMDBObjectSet($oSearch, array(), array('org_id' => $oUserOrg->GetKey()));
  568. $aZList = explode(',', PORTAL_TICKETS_LIST_ZLIST);
  569. $oP->DisplaySet($oSet, $aZList, Dict::S('Portal:NoOpenRequest'));
  570. }
  571. /**
  572. * Lists all the currently closed tickets
  573. * @param WebPage $oP The current web page
  574. * @return void
  575. */
  576. function ListClosedTickets(WebPage $oP)
  577. {
  578. $aAttSpecs = explode(',', PORTAL_TICKETS_SEARCH_CRITERIA);
  579. $aZList = explode(',', PORTAL_TICKETS_CLOSED_ZLIST);
  580. $oP->DisplaySearchForm('UserRequest', $aAttSpecs, array('operation' => 'show_closed'), 'search_', false /* => not closed */);
  581. $oUserOrg = GetUserOrg();
  582. // UserRequest
  583. $oSearch = $oP->PostedParamsToFilter('UserRequest', $aAttSpecs, 'search_');
  584. if(is_null($oSearch))
  585. {
  586. $oSearch = new DBObjectSearch('UserRequest');
  587. }
  588. $oSearch->AddCondition('org_id', $oUserOrg->GetKey());
  589. $oSearch->AddCondition('status', 'closed');
  590. $iUser = UserRights::GetContactId();
  591. if ($iUser > 0 && !IsPowerUser())
  592. {
  593. $oSearch->AddCondition('caller_id', $iUser);
  594. }
  595. $oSet1 = new CMDBObjectSet($oSearch);
  596. $oP->add("<h1>".Dict::S('Portal:ClosedRequests')."</h1>\n");
  597. $oP->DisplaySet($oSet1, $aZList, Dict::S('Portal:NoClosedRequest'));
  598. }
  599. /**
  600. * Display an object - to be customized
  601. * @param WebPage $oP The current web page
  602. * @param Object $oObj Any kind of object
  603. * @param Object $oUserOrg The organization of the logged in user
  604. * @return void
  605. */
  606. function DisplayObject($oP, $oObj, $oUserOrg)
  607. {
  608. switch(get_class($oObj))
  609. {
  610. case 'UserRequest':
  611. ShowDetailsRequest($oP, $oObj);
  612. break;
  613. default:
  614. throw new Exception("The class ".get_class($oObj)." is not handled through the portal");
  615. }
  616. }
  617. /**
  618. * Displays the details of a request
  619. * @param WebPage $oP The current web page
  620. * @param Object $oObj The target object
  621. * @return void
  622. */
  623. function ShowDetailsRequest(WebPage $oP, $oObj)
  624. {
  625. $sClass = get_class($oObj);
  626. $bIsEscalateButton = false;
  627. $bIsReopenButton = false;
  628. $bIsCloseButton = false;
  629. $bEditAttachments = false;
  630. $aEditAtt = array(); // List of attributes editable in the main form
  631. if (!MetaModel::DBIsReadOnly())
  632. {
  633. switch($oObj->GetState())
  634. {
  635. case 'new':
  636. case 'assigned':
  637. case 'frozen':
  638. $aEditAtt = array(
  639. PORTAL_ATTCODE_LOG => '????'
  640. );
  641. $bEditAttachments = true;
  642. // disabled - $bIsEscalateButton = true;
  643. break;
  644. case 'escalated_tto':
  645. case 'escalated_ttr':
  646. $aEditAtt = array(
  647. PORTAL_ATTCODE_LOG => '????'
  648. );
  649. $bEditAttachments = true;
  650. break;
  651. case 'resolved':
  652. $aEditAtt = array();
  653. if (array_key_exists('ev_reopen', MetaModel::EnumStimuli($sClass)))
  654. {
  655. $bIsReopenButton = true;
  656. MakeStimulusForm($oP, $oObj, 'ev_reopen', array(PORTAL_ATTCODE_LOG));
  657. }
  658. $bIsCloseButton = true;
  659. MakeStimulusForm($oP, $oObj, 'ev_close', array('user_satisfaction', PORTAL_ATTCODE_COMMENT));
  660. break;
  661. case 'closed':
  662. case 'closure_requested':
  663. default:
  664. break;
  665. }
  666. }
  667. // REFACTORISER LA MISE EN FORME
  668. $oP->add("<h1 id=\"title_request_details\">".$oObj->GetIcon()."&nbsp;".Dict::Format('Portal:TitleRequestDetailsFor_Request', $oObj->GetName())."</h1>\n");
  669. switch($sClass)
  670. {
  671. case 'UserRequest':
  672. $aAttList = json_decode(PORTAL_TICKET_DETAILS_ZLIST, true);
  673. switch($oObj->GetState())
  674. {
  675. case 'closed':
  676. $aAttList['centered'][] = 'user_satisfaction';
  677. $aAttList['centered'][] = PORTAL_ATTCODE_COMMENT;
  678. }
  679. break;
  680. default:
  681. array('col:left'=> array('ref','service_id','servicesubcategory_id','title','description'),'col:right'=> array('status','start_date'));
  682. break;
  683. }
  684. // Remove the edited attribute from the shown attributes
  685. //
  686. foreach($aEditAtt as $sAttCode => $foo)
  687. {
  688. foreach($aAttList as $col => $aColumn)
  689. {
  690. if (in_array($sAttCode, $aColumn))
  691. {
  692. if(($index = array_search($sAttCode, $aColumn)) !== false)
  693. {
  694. unset($aAttList[$col][$index]);
  695. }
  696. }
  697. }
  698. }
  699. $oP->add("<div class=\"wizContainer\" id=\"form_commment_request\">\n");
  700. $oP->WizardFormStart('request_form', null);
  701. $oP->add('<div id="request_details">');
  702. $oP->add('<table id="request_details_table">');
  703. $oP->add('<tr>');
  704. $oP->add('<td style="vertical-align:top;">');
  705. $oP->DisplayObjectDetails($oObj, $aAttList['col:left']);
  706. $oP->add('</td>');
  707. $oP->add('<td style="vertical-align:top;">');
  708. $oP->DisplayObjectDetails($oObj, $aAttList['col:right']);
  709. $oP->add('</td>');
  710. $oP->add('</tr>');
  711. if (array_key_exists('centered', $aAttList))
  712. {
  713. $oP->add('<tr>');
  714. $oP->add('<td style="vertical-align:top;" colspan="2">');
  715. $oP->DisplayObjectDetails($oObj, $aAttList['centered']);
  716. $oP->add('</td>');
  717. $oP->add('</tr>');
  718. }
  719. // REFACTORISER
  720. $oP->add('<tr>');
  721. $oP->add('<td colspan="2" style="vertical-align:top;">');
  722. $oAttPlugin = new AttachmentPlugIn();
  723. if ($bEditAttachments)
  724. {
  725. $oAttPlugin->EnableDelete(false);
  726. $oAttPlugin->OnDisplayRelations($oObj, $oP, true /* edit */);
  727. }
  728. else
  729. {
  730. $oAttPlugin->OnDisplayRelations($oObj, $oP, false /* read */);
  731. }
  732. $oP->add('</td>');
  733. $oP->add('</tr>');
  734. $oP->add('<tr>');
  735. $oP->add('<td colspan="2" style="vertical-align:top;">');
  736. //$oP->add("<form action=\"../portal/index.php\" id=\"request_form\" method=\"post\">\n");
  737. //$oP->add('<table id=""><tr><td style="vertical-align:top;">');
  738. //$oP->add("<h1 id=\"title_request_details\">".Dict::Format('Portal:CommentsFor_Request', $oObj->GetName())."</h1>\n");
  739. $oP->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">");
  740. $oP->add("<input type=\"hidden\" name=\"id\" value=\"".$oObj->GetKey()."\">");
  741. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"update_request\">");
  742. $oP->add("<input type=\"hidden\" id=\"stimulus_to_apply\" name=\"apply_stimulus\" value=\"\">\n");
  743. $oP->add_script(
  744. <<<EOF
  745. function SetStimulusToApply(sStimulusCode)
  746. {
  747. $('#stimulus_to_apply').val(sStimulusCode);
  748. }
  749. EOF
  750. );
  751. $aEditFields = array(); // Intermediate array to avoid code duplication while splitting btw ticket_log and the rest
  752. foreach($aEditAtt as $sAttCode => $foo)
  753. {
  754. $sValue = $oObj->Get($sAttCode);
  755. $sDisplayValue = $oObj->GetEditValue($sAttCode);
  756. $aArgs = array('this' => $oObj, 'formPrefix' => '');
  757. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  758. $sInputId = 'input_'.$sAttCode;
  759. $sHTMLValue = "<span id=\"field_{$sInputId}\">".cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', 0 /*$iFlags*/, $aArgs).'</span>';
  760. $aEditFields[$sAttCode] = array(
  761. 'label' => MetaModel::GetLabel($sClass, $sAttCode),
  762. 'value' => $sHTMLValue
  763. );
  764. }
  765. foreach($aEditFields as $sAttCode => $aFieldSpec)
  766. {
  767. if ($sAttCode == PORTAL_ATTCODE_LOG)
  768. {
  769. // Skip, the public log will be displayed below the buttons
  770. continue;
  771. }
  772. $oP->add("<div class=\"edit_item\">");
  773. $oP->add('<h1>'.$aFieldSpec['label'].'</h1>');
  774. $oP->add($aFieldSpec['value']);
  775. $oP->add('</div>');
  776. }
  777. if($bIsReopenButton)
  778. {
  779. $sStimulusCode = 'ev_reopen';
  780. $sTitle = addslashes(Dict::S('Portal:Button:ReopenTicket'));
  781. $sOk = addslashes(Dict::S('UI:Button:Ok'));
  782. $oP->p('<input type="button" onClick="RunStimulusDialog(\''.$sStimulusCode.'\', \''.$sTitle.'\', \''.$sOk.'\');" value="'.$sTitle.'...">');
  783. }
  784. if($bIsCloseButton)
  785. {
  786. $sStimulusCode = 'ev_close';
  787. $sTitle = addslashes(Dict::S('Portal:Button:CloseTicket'));
  788. $sOk = addslashes(Dict::S('UI:Button:Ok'));
  789. $oP->p('<input type="button" onClick="RunStimulusDialog(\''.$sStimulusCode.'\', \''.$sTitle.'\', \''.$sOk.'\');" value="'.$sTitle.'...">');
  790. }
  791. elseif (count($aEditAtt) > 0)
  792. {
  793. $oP->p('<input type="submit" value="'.Dict::S('Portal:Button:UpdateRequest').'">');
  794. }
  795. if ($bIsEscalateButton)
  796. {
  797. $sStimulusCode = 'ev_timeout';
  798. $oP->p('<input type="submit" onClick="SetStimulusToApply(\''.$sStimulusCode.'\');" value="'.Dict::S('Portal:ButtonEscalate').'">');
  799. }
  800. $oP->add('</td>');
  801. $oP->add('</tr>');
  802. $oP->add('<tr>');
  803. $oP->add('<td colspan="2" style="vertical-align:top;">');
  804. if (isset($aEditFields[PORTAL_ATTCODE_LOG]))
  805. {
  806. $oP->add("<div class=\"edit_item\">");
  807. $oP->add('<h1>'.$aEditFields[PORTAL_ATTCODE_LOG]['label'].'</h1>');
  808. $oP->add($aEditFields[PORTAL_ATTCODE_LOG]['value']);
  809. $oP->add('</div>');
  810. }
  811. else
  812. {
  813. $oP->add('<h1>'.MetaModel::GetLabel($sClass, PORTAL_ATTCODE_LOG).'</h1>');
  814. $oP->add($oObj->GetAsHTML(PORTAL_ATTCODE_LOG));
  815. }
  816. $oP->add('</td>');
  817. $oP->add('</tr>');
  818. $oP->add('</table>');
  819. $oP->add('</div>');
  820. $oP->WizardFormEnd();
  821. $oP->add('</div>');
  822. }
  823. /**
  824. * Create form to apply a stimulus
  825. * @param WebPage $oP The current web page
  826. * @param Object $oObj The target object
  827. * @param String $sStimulusCode Stimulus that will be applied
  828. * @param Array $aEditAtt List of attributes to edit
  829. * @return void
  830. */
  831. function MakeStimulusForm(WebPage $oP, $oObj, $sStimulusCode, $aEditAtt)
  832. {
  833. static $bHasStimulusForm = false;
  834. $sDialogId = $sStimulusCode."_dialog";
  835. $sFormId = $sStimulusCode."_form";
  836. $sCancelButtonLabel = Dict::S('UI:Button:Cancel');
  837. $oP->add('<div id="'.$sDialogId.'" style="display: none;">');
  838. $sClass = get_class($oObj);
  839. $oP->add('<form id="'.$sFormId.'" method="post">');
  840. $sTransactionId = utils::GetNewTransactionId();
  841. $oP->add("<input type=\"hidden\" id=\"transaction_id\" name=\"transaction_id\" value=\"$sTransactionId\">\n");
  842. $oP->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">");
  843. $oP->add("<input type=\"hidden\" name=\"id\" value=\"".$oObj->GetKey()."\">");
  844. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"update_request\">");
  845. $oP->add("<input type=\"hidden\" id=\"stimulus_to_apply\" name=\"apply_stimulus\" value=\"$sStimulusCode\">\n");
  846. foreach($aEditAtt as $sAttCode)
  847. {
  848. $sValue = $oObj->Get($sAttCode);
  849. $sDisplayValue = $oObj->GetEditValue($sAttCode);
  850. $aArgs = array('this' => $oObj, 'formPrefix' => '');
  851. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  852. $sInputId = 'input_'.$sAttCode;
  853. $sHTMLValue = "<span id=\"field_{$sStimulusCode}_{$sInputId}\">".cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', 0 /*$iFlags*/, $aArgs).'</span>';
  854. $oP->add('<h1>'.MetaModel::GetLabel($sClass, $sAttCode).'</h1>');
  855. $oP->add($sHTMLValue);
  856. }
  857. $oP->add('</form>');
  858. $oP->add('</div>');
  859. if (!$bHasStimulusForm)
  860. {
  861. $bHasStimulusForm = true;
  862. $oP->add_script(
  863. <<<EOF
  864. function RunStimulusDialog(sStimulusCode, sTitle, sOkButtonLabel)
  865. {
  866. $('#'+sStimulusCode+'_dialog').dialog({
  867. height: 'auto',
  868. width: 'auto',
  869. modal: true,
  870. title: sTitle,
  871. buttons: [
  872. { text: sOkButtonLabel, click: function() {
  873. $(this).find('#'+sStimulusCode+'_form').submit();
  874. } },
  875. { text: "$sCancelButtonLabel", click: function() {
  876. $(this).dialog( "close" );
  877. } },
  878. ],
  879. });
  880. }
  881. EOF
  882. );
  883. }
  884. }
  885. /**
  886. * Get The organization of the current user (i.e. the organization of its contact)
  887. * @param WebPage $oP The current page, for errors output
  888. * @return Organization The user's org or null in case of problem...
  889. */
  890. function GetUserOrg()
  891. {
  892. $oOrg = null;
  893. $iContactId = UserRights::GetContactId();
  894. $oContact = MetaModel::GetObject('Contact', $iContactId, false); // false => Can fail
  895. if (is_object($oContact))
  896. {
  897. $oOrg = MetaModel::GetObject('Organization', $oContact->Get('org_id'), false); // false => can fail
  898. }
  899. else
  900. {
  901. throw new Exception(Dict::S('Portal:ErrorNoContactForThisUser'));
  902. }
  903. return $oOrg;
  904. }
  905. /**
  906. * Determine if the current user can be considered as being a portal power user
  907. */
  908. function IsPowerUSer()
  909. {
  910. $iUserID = UserRights::GetUserId();
  911. $sOQLprofile = "SELECT URP_Profiles AS p JOIN URP_UserProfile AS up ON up.profileid=p.id WHERE up.userid = :user AND p.name = :profile";
  912. $oProfileSet = new DBObjectSet(
  913. DBObjectSearch::FromOQL($sOQLprofile),
  914. array(),
  915. array(
  916. 'user' => $iUserID,
  917. 'profile' => PORTAL_POWER_USER_PROFILE,
  918. )
  919. );
  920. $bRes = ($oProfileSet->count() > 0);
  921. return $bRes;
  922. }
  923. ///////////////////////////////////////////////////////////////////////////////
  924. //
  925. // Main program
  926. //
  927. ///////////////////////////////////////////////////////////////////////////////
  928. try
  929. {
  930. require_once(APPROOT.'/application/startup.inc.php');
  931. require_once(APPROOT.'/application/portalwebpage.class.inc.php');
  932. $oAppContext = new ApplicationContext();
  933. $sOperation = utils::ReadParam('operation', '');
  934. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  935. LoginWebPage::DoLogin(false /* bMustBeAdmin */, true /* IsAllowedToPortalUsers */); // Check user rights and prompt if needed
  936. ApplicationContext::SetUrlMakerClass('MyPortalURLMaker');
  937. if (!class_exists('UserRequest'))
  938. {
  939. $oP = new WebPage(Dict::S('Portal:Title'));
  940. $oP->p(dict::Format('Portal:NoRequestMgmt', UserRights::GetUserFriendlyName()));
  941. }
  942. else
  943. {
  944. $oUserOrg = GetUserOrg();
  945. $sCode = $oUserOrg->Get('code');
  946. $sAlternateStylesheet = '';
  947. if (@file_exists("./$sCode/portal.css"))
  948. {
  949. $sAlternateStylesheet = "$sCode";
  950. }
  951. $oP = new PortalWebPage(Dict::S('Portal:Title'), $sAlternateStylesheet);
  952. $oP->EnableDisconnectButton(utils::CanLogOff());
  953. $oP->SetWelcomeMessage(Dict::Format('Portal:WelcomeUserOrg', UserRights::GetUserFriendlyName(), $oUserOrg->GetName()));
  954. if (is_object($oUserOrg))
  955. {
  956. switch($sOperation)
  957. {
  958. case 'show_closed':
  959. $oP->set_title(Dict::S('Portal:ShowClosed'));
  960. DisplayMainMenu($oP);
  961. ShowClosedTickets($oP);
  962. break;
  963. case 'create_request':
  964. $oP->set_title(Dict::S('Portal:CreateNewRequest'));
  965. DisplayMainMenu($oP);
  966. if (!MetaModel::DBIsReadOnly())
  967. {
  968. CreateRequest($oP, $oUserOrg);
  969. }
  970. break;
  971. case 'details':
  972. $oP->set_title(Dict::S('Portal:TitleDetailsFor_Request'));
  973. DisplayMainMenu($oP);
  974. $oObj = $oP->FindObjectFromArgs(array('UserRequest'));
  975. DisplayObject($oP, $oObj, $oUserOrg);
  976. break;
  977. case 'update_request':
  978. $oP->set_title(Dict::S('Portal:TitleDetailsFor_Request'));
  979. DisplayMainMenu($oP);
  980. if (!MetaModel::DBIsReadOnly())
  981. {
  982. $oObj = $oP->FindObjectFromArgs(array('UserRequest'));
  983. switch(get_class($oObj))
  984. {
  985. case 'UserRequest':
  986. $aAttList = array(PORTAL_ATTCODE_LOG, 'user_satisfaction', PORTAL_ATTCODE_COMMENT);
  987. break;
  988. default:
  989. throw new Exception("Implementation issue: unexpected class '".get_class($oObj)."'");
  990. }
  991. try
  992. {
  993. $oP->DoUpdateObjectFromPostedForm($oObj, $aAttList);
  994. $oObj->Reload(); // Make sure the object is in good shape to be displayed
  995. }
  996. catch(TransactionException $e)
  997. {
  998. $oP->add("<h1>".Dict::S('UI:Error:ObjectAlreadyUpdated')."</h1>\n");
  999. }
  1000. DisplayObject($oP, $oObj, $oUserOrg);
  1001. }
  1002. break;
  1003. case 'show_ongoing':
  1004. default:
  1005. $oP->set_title(Dict::S('Portal:ShowOngoing'));
  1006. DisplayMainMenu($oP);
  1007. ShowOngoingTickets($oP);
  1008. }
  1009. }
  1010. }
  1011. $oP->output();
  1012. }
  1013. catch(CoreException $e)
  1014. {
  1015. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  1016. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  1017. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1018. $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
  1019. //$oP->p($e->getTraceAsString());
  1020. $oP->output();
  1021. if (MetaModel::IsLogEnabledIssue())
  1022. {
  1023. if (MetaModel::IsValidClass('EventIssue'))
  1024. {
  1025. try
  1026. {
  1027. $oLog = new EventIssue();
  1028. $oLog->Set('message', $e->getMessage());
  1029. $oLog->Set('userinfo', '');
  1030. $oLog->Set('issue', $e->GetIssue());
  1031. $oLog->Set('impact', 'Page could not be displayed');
  1032. $oLog->Set('callstack', $e->getTrace());
  1033. $oLog->Set('data', $e->getContextData());
  1034. $oLog->DBInsertNoReload();
  1035. }
  1036. catch(Exception $e)
  1037. {
  1038. IssueLog::Error("Failed to log issue into the DB");
  1039. }
  1040. }
  1041. IssueLog::Error($e->getMessage());
  1042. }
  1043. // For debugging only
  1044. //throw $e;
  1045. }
  1046. catch(Exception $e)
  1047. {
  1048. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  1049. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  1050. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1051. $oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
  1052. //$oP->p($e->getTraceAsString());
  1053. $oP->output();
  1054. if (MetaModel::IsLogEnabledIssue())
  1055. {
  1056. if (MetaModel::IsValidClass('EventIssue'))
  1057. {
  1058. try
  1059. {
  1060. $oLog = new EventIssue();
  1061. $oLog->Set('message', $e->getMessage());
  1062. $oLog->Set('userinfo', '');
  1063. $oLog->Set('issue', 'PHP Exception');
  1064. $oLog->Set('impact', 'Page could not be displayed');
  1065. $oLog->Set('callstack', $e->getTrace());
  1066. $oLog->Set('data', array());
  1067. $oLog->DBInsertNoReload();
  1068. }
  1069. catch(Exception $e)
  1070. {
  1071. IssueLog::Error("Failed to log issue into the DB");
  1072. }
  1073. }
  1074. IssueLog::Error($e->getMessage());
  1075. }
  1076. }
  1077. ?>