index.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  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. case 'pending':
  639. $aEditAtt = array(
  640. PORTAL_ATTCODE_LOG => '????'
  641. );
  642. $bEditAttachments = true;
  643. // disabled - $bIsEscalateButton = true;
  644. break;
  645. case 'escalated_tto':
  646. case 'escalated_ttr':
  647. $aEditAtt = array(
  648. PORTAL_ATTCODE_LOG => '????'
  649. );
  650. $bEditAttachments = true;
  651. break;
  652. case 'resolved':
  653. $aEditAtt = array();
  654. if (array_key_exists('ev_reopen', MetaModel::EnumStimuli($sClass)))
  655. {
  656. $bIsReopenButton = true;
  657. MakeStimulusForm($oP, $oObj, 'ev_reopen', array(PORTAL_ATTCODE_LOG));
  658. }
  659. $bIsCloseButton = true;
  660. MakeStimulusForm($oP, $oObj, 'ev_close', array('user_satisfaction', PORTAL_ATTCODE_COMMENT));
  661. break;
  662. case 'closed':
  663. case 'closure_requested':
  664. default:
  665. break;
  666. }
  667. }
  668. // REFACTORISER LA MISE EN FORME
  669. $oP->add("<h1 id=\"title_request_details\">".$oObj->GetIcon()."&nbsp;".Dict::Format('Portal:TitleRequestDetailsFor_Request', $oObj->GetName())."</h1>\n");
  670. switch($sClass)
  671. {
  672. case 'UserRequest':
  673. $aAttList = json_decode(PORTAL_TICKET_DETAILS_ZLIST, true);
  674. switch($oObj->GetState())
  675. {
  676. case 'closed':
  677. $aAttList['centered'][] = 'user_satisfaction';
  678. $aAttList['centered'][] = PORTAL_ATTCODE_COMMENT;
  679. }
  680. break;
  681. default:
  682. array('col:left'=> array('ref','service_id','servicesubcategory_id','title','description'),'col:right'=> array('status','start_date'));
  683. break;
  684. }
  685. // Remove the edited attribute from the shown attributes
  686. //
  687. foreach($aEditAtt as $sAttCode => $foo)
  688. {
  689. foreach($aAttList as $col => $aColumn)
  690. {
  691. if (in_array($sAttCode, $aColumn))
  692. {
  693. if(($index = array_search($sAttCode, $aColumn)) !== false)
  694. {
  695. unset($aAttList[$col][$index]);
  696. }
  697. }
  698. }
  699. }
  700. $oP->add("<div class=\"wizContainer\" id=\"form_commment_request\">\n");
  701. $oP->WizardFormStart('request_form', null);
  702. $oP->add('<div id="request_details">');
  703. $oP->add('<table id="request_details_table">');
  704. $oP->add('<tr>');
  705. $oP->add('<td style="vertical-align:top;">');
  706. $oP->DisplayObjectDetails($oObj, $aAttList['col:left']);
  707. $oP->add('</td>');
  708. $oP->add('<td style="vertical-align:top;">');
  709. $oP->DisplayObjectDetails($oObj, $aAttList['col:right']);
  710. $oP->add('</td>');
  711. $oP->add('</tr>');
  712. if (array_key_exists('centered', $aAttList))
  713. {
  714. $oP->add('<tr>');
  715. $oP->add('<td style="vertical-align:top;" colspan="2">');
  716. $oP->DisplayObjectDetails($oObj, $aAttList['centered']);
  717. $oP->add('</td>');
  718. $oP->add('</tr>');
  719. }
  720. // REFACTORISER
  721. $oP->add('<tr>');
  722. $oP->add('<td colspan="2" style="vertical-align:top;">');
  723. $oAttPlugin = new AttachmentPlugIn();
  724. if ($bEditAttachments)
  725. {
  726. $oAttPlugin->EnableDelete(false);
  727. $oAttPlugin->OnDisplayRelations($oObj, $oP, true /* edit */);
  728. }
  729. else
  730. {
  731. $oAttPlugin->OnDisplayRelations($oObj, $oP, false /* read */);
  732. }
  733. $oP->add('</td>');
  734. $oP->add('</tr>');
  735. $oP->add('<tr>');
  736. $oP->add('<td colspan="2" style="vertical-align:top;">');
  737. //$oP->add("<form action=\"../portal/index.php\" id=\"request_form\" method=\"post\">\n");
  738. //$oP->add('<table id=""><tr><td style="vertical-align:top;">');
  739. //$oP->add("<h1 id=\"title_request_details\">".Dict::Format('Portal:CommentsFor_Request', $oObj->GetName())."</h1>\n");
  740. $oP->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">");
  741. $oP->add("<input type=\"hidden\" name=\"id\" value=\"".$oObj->GetKey()."\">");
  742. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"update_request\">");
  743. $oP->add("<input type=\"hidden\" id=\"stimulus_to_apply\" name=\"apply_stimulus\" value=\"\">\n");
  744. $oP->add_script(
  745. <<<EOF
  746. function SetStimulusToApply(sStimulusCode)
  747. {
  748. $('#stimulus_to_apply').val(sStimulusCode);
  749. }
  750. EOF
  751. );
  752. $aEditFields = array(); // Intermediate array to avoid code duplication while splitting btw ticket_log and the rest
  753. foreach($aEditAtt as $sAttCode => $foo)
  754. {
  755. $sValue = $oObj->Get($sAttCode);
  756. $sDisplayValue = $oObj->GetEditValue($sAttCode);
  757. $aArgs = array('this' => $oObj, 'formPrefix' => '');
  758. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  759. $sInputId = 'input_'.$sAttCode;
  760. $sHTMLValue = "<span id=\"field_{$sInputId}\">".cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', 0 /*$iFlags*/, $aArgs).'</span>';
  761. $aEditFields[$sAttCode] = array(
  762. 'label' => MetaModel::GetLabel($sClass, $sAttCode),
  763. 'value' => $sHTMLValue
  764. );
  765. }
  766. foreach($aEditFields as $sAttCode => $aFieldSpec)
  767. {
  768. if ($sAttCode == PORTAL_ATTCODE_LOG)
  769. {
  770. // Skip, the public log will be displayed below the buttons
  771. continue;
  772. }
  773. $oP->add("<div class=\"edit_item\">");
  774. $oP->add('<h1>'.$aFieldSpec['label'].'</h1>');
  775. $oP->add($aFieldSpec['value']);
  776. $oP->add('</div>');
  777. }
  778. if($bIsReopenButton)
  779. {
  780. $sStimulusCode = 'ev_reopen';
  781. $sTitle = addslashes(Dict::S('Portal:Button:ReopenTicket'));
  782. $sOk = addslashes(Dict::S('UI:Button:Ok'));
  783. $oP->p('<input type="button" onClick="RunStimulusDialog(\''.$sStimulusCode.'\', \''.$sTitle.'\', \''.$sOk.'\');" value="'.$sTitle.'...">');
  784. }
  785. if($bIsCloseButton)
  786. {
  787. $sStimulusCode = 'ev_close';
  788. $sTitle = addslashes(Dict::S('Portal:Button:CloseTicket'));
  789. $sOk = addslashes(Dict::S('UI:Button:Ok'));
  790. $oP->p('<input type="button" onClick="RunStimulusDialog(\''.$sStimulusCode.'\', \''.$sTitle.'\', \''.$sOk.'\');" value="'.$sTitle.'...">');
  791. }
  792. elseif (count($aEditAtt) > 0)
  793. {
  794. $oP->p('<input type="submit" value="'.Dict::S('Portal:Button:UpdateRequest').'">');
  795. }
  796. if ($bIsEscalateButton)
  797. {
  798. $sStimulusCode = 'ev_timeout';
  799. $oP->p('<input type="submit" onClick="SetStimulusToApply(\''.$sStimulusCode.'\');" value="'.Dict::S('Portal:ButtonEscalate').'">');
  800. }
  801. $oP->add('</td>');
  802. $oP->add('</tr>');
  803. $oP->add('<tr>');
  804. $oP->add('<td colspan="2" style="vertical-align:top;">');
  805. if (isset($aEditFields[PORTAL_ATTCODE_LOG]))
  806. {
  807. $oP->add("<div class=\"edit_item\">");
  808. $oP->add('<h1>'.$aEditFields[PORTAL_ATTCODE_LOG]['label'].'</h1>');
  809. $oP->add($aEditFields[PORTAL_ATTCODE_LOG]['value']);
  810. $oP->add('</div>');
  811. }
  812. else
  813. {
  814. $oP->add('<h1>'.MetaModel::GetLabel($sClass, PORTAL_ATTCODE_LOG).'</h1>');
  815. $oP->add($oObj->GetAsHTML(PORTAL_ATTCODE_LOG));
  816. }
  817. $oP->add('</td>');
  818. $oP->add('</tr>');
  819. $oP->add('</table>');
  820. $oP->add('</div>');
  821. $oP->WizardFormEnd();
  822. $oP->add('</div>');
  823. }
  824. /**
  825. * Create form to apply a stimulus
  826. * @param WebPage $oP The current web page
  827. * @param Object $oObj The target object
  828. * @param String $sStimulusCode Stimulus that will be applied
  829. * @param Array $aEditAtt List of attributes to edit
  830. * @return void
  831. */
  832. function MakeStimulusForm(WebPage $oP, $oObj, $sStimulusCode, $aEditAtt)
  833. {
  834. static $bHasStimulusForm = false;
  835. $sDialogId = $sStimulusCode."_dialog";
  836. $sFormId = $sStimulusCode."_form";
  837. $sCancelButtonLabel = Dict::S('UI:Button:Cancel');
  838. $oP->add('<div id="'.$sDialogId.'" style="display: none;">');
  839. $sClass = get_class($oObj);
  840. $oP->add('<form id="'.$sFormId.'" method="post">');
  841. $sTransactionId = utils::GetNewTransactionId();
  842. $oP->add("<input type=\"hidden\" id=\"transaction_id\" name=\"transaction_id\" value=\"$sTransactionId\">\n");
  843. $oP->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">");
  844. $oP->add("<input type=\"hidden\" name=\"id\" value=\"".$oObj->GetKey()."\">");
  845. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"update_request\">");
  846. $oP->add("<input type=\"hidden\" id=\"stimulus_to_apply\" name=\"apply_stimulus\" value=\"$sStimulusCode\">\n");
  847. foreach($aEditAtt as $sAttCode)
  848. {
  849. $sValue = $oObj->Get($sAttCode);
  850. $sDisplayValue = $oObj->GetEditValue($sAttCode);
  851. $aArgs = array('this' => $oObj, 'formPrefix' => '');
  852. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  853. $sInputId = 'input_'.$sAttCode;
  854. $sHTMLValue = "<span id=\"field_{$sStimulusCode}_{$sInputId}\">".cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', 0 /*$iFlags*/, $aArgs).'</span>';
  855. $oP->add('<h1>'.MetaModel::GetLabel($sClass, $sAttCode).'</h1>');
  856. $oP->add($sHTMLValue);
  857. }
  858. $oP->add('</form>');
  859. $oP->add('</div>');
  860. if (!$bHasStimulusForm)
  861. {
  862. $bHasStimulusForm = true;
  863. $oP->add_script(
  864. <<<EOF
  865. function RunStimulusDialog(sStimulusCode, sTitle, sOkButtonLabel)
  866. {
  867. $('#'+sStimulusCode+'_dialog').dialog({
  868. height: 'auto',
  869. width: 'auto',
  870. modal: true,
  871. title: sTitle,
  872. buttons: [
  873. { text: sOkButtonLabel, click: function() {
  874. $(this).find('#'+sStimulusCode+'_form').submit();
  875. } },
  876. { text: "$sCancelButtonLabel", click: function() {
  877. $(this).dialog( "close" );
  878. } },
  879. ],
  880. });
  881. }
  882. EOF
  883. );
  884. }
  885. }
  886. /**
  887. * Get The organization of the current user (i.e. the organization of its contact)
  888. * @param WebPage $oP The current page, for errors output
  889. * @return Organization The user's org or null in case of problem...
  890. */
  891. function GetUserOrg()
  892. {
  893. $oOrg = null;
  894. $iContactId = UserRights::GetContactId();
  895. $oContact = MetaModel::GetObject('Contact', $iContactId, false); // false => Can fail
  896. if (is_object($oContact))
  897. {
  898. $oOrg = MetaModel::GetObject('Organization', $oContact->Get('org_id'), false); // false => can fail
  899. }
  900. else
  901. {
  902. throw new Exception(Dict::S('Portal:ErrorNoContactForThisUser'));
  903. }
  904. return $oOrg;
  905. }
  906. /**
  907. * Determine if the current user can be considered as being a portal power user
  908. */
  909. function IsPowerUSer()
  910. {
  911. $iUserID = UserRights::GetUserId();
  912. $sOQLprofile = "SELECT URP_Profiles AS p JOIN URP_UserProfile AS up ON up.profileid=p.id WHERE up.userid = :user AND p.name = :profile";
  913. $oProfileSet = new DBObjectSet(
  914. DBObjectSearch::FromOQL($sOQLprofile),
  915. array(),
  916. array(
  917. 'user' => $iUserID,
  918. 'profile' => PORTAL_POWER_USER_PROFILE,
  919. )
  920. );
  921. $bRes = ($oProfileSet->count() > 0);
  922. return $bRes;
  923. }
  924. ///////////////////////////////////////////////////////////////////////////////
  925. //
  926. // Main program
  927. //
  928. ///////////////////////////////////////////////////////////////////////////////
  929. try
  930. {
  931. require_once(APPROOT.'/application/startup.inc.php');
  932. require_once(APPROOT.'/application/portalwebpage.class.inc.php');
  933. $oAppContext = new ApplicationContext();
  934. $sOperation = utils::ReadParam('operation', '');
  935. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  936. LoginWebPage::DoLogin(false /* bMustBeAdmin */, true /* IsAllowedToPortalUsers */); // Check user rights and prompt if needed
  937. ApplicationContext::SetUrlMakerClass('MyPortalURLMaker');
  938. if (!class_exists('UserRequest'))
  939. {
  940. $oP = new WebPage(Dict::S('Portal:Title'));
  941. $oP->p(dict::Format('Portal:NoRequestMgmt', UserRights::GetUserFriendlyName()));
  942. }
  943. else
  944. {
  945. $oUserOrg = GetUserOrg();
  946. $sCode = $oUserOrg->Get('code');
  947. $sAlternateStylesheet = '';
  948. if (@file_exists("./$sCode/portal.css"))
  949. {
  950. $sAlternateStylesheet = "$sCode";
  951. }
  952. $oP = new PortalWebPage(Dict::S('Portal:Title'), $sAlternateStylesheet);
  953. $oP->EnableDisconnectButton(utils::CanLogOff());
  954. $oP->SetWelcomeMessage(Dict::Format('Portal:WelcomeUserOrg', UserRights::GetUserFriendlyName(), $oUserOrg->GetName()));
  955. if (is_object($oUserOrg))
  956. {
  957. switch($sOperation)
  958. {
  959. case 'show_closed':
  960. $oP->set_title(Dict::S('Portal:ShowClosed'));
  961. DisplayMainMenu($oP);
  962. ShowClosedTickets($oP);
  963. break;
  964. case 'create_request':
  965. $oP->set_title(Dict::S('Portal:CreateNewRequest'));
  966. DisplayMainMenu($oP);
  967. if (!MetaModel::DBIsReadOnly())
  968. {
  969. CreateRequest($oP, $oUserOrg);
  970. }
  971. break;
  972. case 'details':
  973. $oP->set_title(Dict::S('Portal:TitleDetailsFor_Request'));
  974. DisplayMainMenu($oP);
  975. $oObj = $oP->FindObjectFromArgs(array('UserRequest'));
  976. DisplayObject($oP, $oObj, $oUserOrg);
  977. break;
  978. case 'update_request':
  979. $oP->set_title(Dict::S('Portal:TitleDetailsFor_Request'));
  980. DisplayMainMenu($oP);
  981. if (!MetaModel::DBIsReadOnly())
  982. {
  983. $oObj = $oP->FindObjectFromArgs(array('UserRequest'));
  984. switch(get_class($oObj))
  985. {
  986. case 'UserRequest':
  987. $aAttList = array(PORTAL_ATTCODE_LOG, 'user_satisfaction', PORTAL_ATTCODE_COMMENT);
  988. break;
  989. default:
  990. throw new Exception("Implementation issue: unexpected class '".get_class($oObj)."'");
  991. }
  992. try
  993. {
  994. $oP->DoUpdateObjectFromPostedForm($oObj, $aAttList);
  995. $oObj->Reload(); // Make sure the object is in good shape to be displayed
  996. }
  997. catch(TransactionException $e)
  998. {
  999. $oP->add("<h1>".Dict::S('UI:Error:ObjectAlreadyUpdated')."</h1>\n");
  1000. }
  1001. DisplayObject($oP, $oObj, $oUserOrg);
  1002. }
  1003. break;
  1004. case 'show_ongoing':
  1005. default:
  1006. $oP->set_title(Dict::S('Portal:ShowOngoing'));
  1007. DisplayMainMenu($oP);
  1008. ShowOngoingTickets($oP);
  1009. }
  1010. }
  1011. }
  1012. $oP->output();
  1013. }
  1014. catch(CoreException $e)
  1015. {
  1016. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  1017. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  1018. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1019. $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
  1020. //$oP->p($e->getTraceAsString());
  1021. $oP->output();
  1022. if (MetaModel::IsLogEnabledIssue())
  1023. {
  1024. if (MetaModel::IsValidClass('EventIssue'))
  1025. {
  1026. try
  1027. {
  1028. $oLog = new EventIssue();
  1029. $oLog->Set('message', $e->getMessage());
  1030. $oLog->Set('userinfo', '');
  1031. $oLog->Set('issue', $e->GetIssue());
  1032. $oLog->Set('impact', 'Page could not be displayed');
  1033. $oLog->Set('callstack', $e->getTrace());
  1034. $oLog->Set('data', $e->getContextData());
  1035. $oLog->DBInsertNoReload();
  1036. }
  1037. catch(Exception $e)
  1038. {
  1039. IssueLog::Error("Failed to log issue into the DB");
  1040. }
  1041. }
  1042. IssueLog::Error($e->getMessage());
  1043. }
  1044. // For debugging only
  1045. //throw $e;
  1046. }
  1047. catch(Exception $e)
  1048. {
  1049. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  1050. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  1051. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1052. $oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
  1053. //$oP->p($e->getTraceAsString());
  1054. $oP->output();
  1055. if (MetaModel::IsLogEnabledIssue())
  1056. {
  1057. if (MetaModel::IsValidClass('EventIssue'))
  1058. {
  1059. try
  1060. {
  1061. $oLog = new EventIssue();
  1062. $oLog->Set('message', $e->getMessage());
  1063. $oLog->Set('userinfo', '');
  1064. $oLog->Set('issue', 'PHP Exception');
  1065. $oLog->Set('impact', 'Page could not be displayed');
  1066. $oLog->Set('callstack', $e->getTrace());
  1067. $oLog->Set('data', array());
  1068. $oLog->DBInsertNoReload();
  1069. }
  1070. catch(Exception $e)
  1071. {
  1072. IssueLog::Error("Failed to log issue into the DB");
  1073. }
  1074. }
  1075. IssueLog::Error($e->getMessage());
  1076. }
  1077. }
  1078. ?>