index.php 39 KB

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