index.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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. define('SERVICECATEGORY_QUERY', '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');
  29. define('SERVICE_SUBCATEGORY_QUERY', 'SELECT ServiceSubcategory WHERE service_id = :svc_id');
  30. define('VALIDATE_SERVICECATEGORY_QUERY', '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 = :id');
  31. define('VALIDATE_SERVICESUBCATEGORY_QUERY', 'SELECT ServiceSubcategory AS Sub JOIN Service AS Svc ON Sub.service_id = Svc.id WHERE Sub.id=:id');
  32. define('ALL_PARAMS', 'from_service_id,org_id,caller_id,service_id,servicesubcategory_id,title,description,impact,urgency,workgroup_id,moreinfo,caller_id,start_date,end_date,duration,impact_duration');
  33. /**
  34. * Displays the portal main menu
  35. * @param WebPage $oP The current web page
  36. * @return void
  37. */
  38. function DisplayMainMenu(WebPage $oP)
  39. {
  40. $oP->AddMenuButton('showongoing', 'Portal:ShowOngoing', '../portal/index.php?operation=show_ongoing');
  41. $oP->AddMenuButton('newrequest', 'Portal:CreateNewRequest', '../portal/index.php?operation=create_request');
  42. $oP->AddMenuButton('showclosed', 'Portal:ShowClosed', '../portal/index.php?operation=show_closed');
  43. if (UserRights::CanChangePassword())
  44. {
  45. $oP->AddMenuButton('change_pwd', 'Portal:ChangeMyPassword', '../portal/index.php?loginop=change_pwd');
  46. }
  47. }
  48. /**
  49. * Displays the current tickets
  50. * @param WebPage $oP The current web page
  51. * @return void
  52. */
  53. function ShowOngoingTickets(WebPage $oP)
  54. {
  55. $oP->add("<div id=\"open_requests\">\n");
  56. $oP->add("<h1 id=\"title_open_requests\">".Dict::S('Portal:OpenRequests')."</h1>\n");
  57. ListOpenRequests($oP);
  58. $oP->add("</div>\n");
  59. $oP->add("<div id=\"#div_resolved_requests\">\n");
  60. $oP->add("<h1 id=\"#resolved_requests\">".Dict::S('Portal:ResolvedRequests')."</h1>\n");
  61. ListResolvedRequests($oP);
  62. $oP->add("</div>\n");
  63. }
  64. /**
  65. * Displays the closed tickets
  66. * @param WebPage $oP The current web page
  67. * @return void
  68. */
  69. function ShowClosedTickets(WebPage $oP)
  70. {
  71. $oP->add("<div id=\"#closed_tickets\">\n");
  72. //$oP->add("<h1 id=\"#closed_tickets\">".Dict::S('Portal:ListClosedTickets')."</h1>\n");
  73. ListClosedTickets($oP);
  74. $oP->add("</div>\n");
  75. }
  76. /**
  77. * Displays the form to select a Service Category Id (among the valid ones for the specified user Organization)
  78. * @param WebPage $oP Web page for the form output
  79. * @param Organization $oUserOrg The organization of the current user
  80. * @return void
  81. */
  82. function SelectServiceCategory($oP, $oUserOrg)
  83. {
  84. $aParameters = $oP->ReadAllParams(ALL_PARAMS);
  85. $oP->add("<div class=\"wizContainer\" id=\"form_select_service\">\n");
  86. $oP->WizardFormStart('request_wizard', 1);
  87. $oP->add("<h1 id=\"select_category\">".Dict::S('Portal:SelectService')."</h1>\n");
  88. $oP->add("<table>\n");
  89. $oSearch = DBObjectSearch::FromOQL(SERVICECATEGORY_QUERY);
  90. $oSet = new CMDBObjectSet($oSearch, array(), array('org_id' => $oUserOrg->GetKey()));
  91. while($oService = $oSet->Fetch())
  92. {
  93. $id = $oService->GetKey();
  94. $sChecked = "";
  95. if (isset($aParameters['service_id']) && ($id == $aParameters['service_id']))
  96. {
  97. $sChecked = "checked";
  98. }
  99. $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>");
  100. $oP->p("<p>".$oService->GetAsHTML('description')."</p></td></tr>");
  101. }
  102. $oP->add("</table>\n");
  103. $oP->DumpHiddenParams($aParameters, array('service_id'));
  104. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_request\">");
  105. $oP->WizardFormButtons(BUTTON_BACK | BUTTON_NEXT | BUTTON_CANCEL);
  106. $oP->WizardFormEnd();
  107. $oP->WizardCheckSelectionOnSubmit(Dict::S('Portal:PleaseSelectOneService'));
  108. $oP->add("</div>\n");
  109. }
  110. /**
  111. * Displays the form to select a Service Subcategory Id (among the valid ones for the specified user Organization)
  112. * and based on the page's parameter 'service_id'
  113. * @param WebPage $oP Web page for the form output
  114. * @param Organization $oUserOrg The organization of the current user
  115. * @return void
  116. */
  117. function SelectServiceSubCategory($oP, $oUserOrg)
  118. {
  119. $aParameters = $oP->ReadAllParams(ALL_PARAMS);
  120. $iSvcId = $aParameters['service_id'];
  121. $iDefaultSubSvcId = isset($aParameters['servicesubcategory_id']) ? $aParameters['servicesubcategory_id'] : 0;
  122. $iDefaultWizNext = 2;
  123. $oSearch = DBObjectSearch::FromOQL(SERVICE_SUBCATEGORY_QUERY);
  124. $oSet = new CMDBObjectSet($oSearch, array(), array('svc_id' => $iSvcId, 'org_id' => $oUserOrg->GetKey()));
  125. $oServiceCategory = MetaModel::GetObject('Service', $iSvcId, false);
  126. if (is_object($oServiceCategory))
  127. {
  128. $oP->add("<div class=\"wizContainer\" id=\"form_select_servicesubcategory\">\n");
  129. $oP->add("<h1 id=\"select_subcategory\">".Dict::Format('Portal:SelectSubcategoryFrom_Service', $oServiceCategory->GetName())."</h1>\n");
  130. $oP->WizardFormStart('request_wizard', $iDefaultWizNext);
  131. $oP->add("<table>\n");
  132. while($oSubService = $oSet->Fetch())
  133. {
  134. $id = $oSubService->GetKey();
  135. $sChecked = "";
  136. if ($id == $iDefaultSubSvcId)
  137. {
  138. $sChecked = "checked";
  139. }
  140. $oP->add("<tr>");
  141. $oP->add("<td style=\"vertical-align:top\">");
  142. $oP->add("<p><input name=\"attr_servicesubcategory_id\" $sChecked type=\"radio\" id=\"servicesubcategory_$id\" value=\"$id\"></p>");
  143. $oP->add("</td>");
  144. $oP->add("<td style=\"vertical-align:top\">");
  145. $oP->add("<p><b><label for=\"servicesubcategory_$id\">".$oSubService->GetName()."</label></b></p>");
  146. $oP->add("<p>".$oSubService->GetAsHTML('description')."</p>");
  147. $oP->add("</td>");
  148. $oP->add("</tr>");
  149. }
  150. $oP->add("</table>\n");
  151. $oP->DumpHiddenParams($aParameters, array('servicesubcategory_id'));
  152. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_request\">");
  153. $oP->WizardFormButtons(BUTTON_BACK | BUTTON_NEXT | BUTTON_CANCEL);
  154. $oP->WizardFormEnd();
  155. $oP->WizardCheckSelectionOnSubmit(Dict::S('Portal:PleaseSelectAServiceSubCategory'));
  156. $oP->add("</div>\n");
  157. }
  158. else
  159. {
  160. $oP->p("Error: Invalid Service: id = $iSvcId");
  161. }
  162. }
  163. /**
  164. * Displays the form for the final step of the UserRequest creation
  165. * @param WebPage $oP The current web page for the form output
  166. * @param Organization $oUserOrg The organization of the current user
  167. * @return void
  168. */
  169. function RequestCreationForm($oP, $oUserOrg)
  170. {
  171. $oP->add_ready_script(
  172. <<<EOF
  173. // Create the object once at the beginning of the page...
  174. var oWizardHelper = new WizardHelper('UserRequest', '');
  175. EOF
  176. );
  177. $aParameters = $oP->ReadAllParams(ALL_PARAMS);
  178. $aList = array('title', 'description', 'impact', 'urgency', 'workgroup_id');
  179. $sDescription = '';
  180. if (isset($aParameters['template_id']))
  181. {
  182. $oTemplate = MetaModel::GetObject('Template', $aParameters['template_id'], false);
  183. if (is_object($oTemplate))
  184. {
  185. $sDescription = htmlentities($oTemplate->Get('template'), ENT_QUOTES, 'UTF-8');
  186. }
  187. }
  188. $oServiceCategory = MetaModel::GetObject('Service', $aParameters['service_id'], false);
  189. $oServiceSubCategory = MetaModel::GetObject('ServiceSubcategory', $aParameters['servicesubcategory_id'], false);
  190. if (is_object($oServiceCategory) && is_object($oServiceSubCategory))
  191. {
  192. $oRequest = new UserRequest();
  193. $oRequest->Set('org_id', $oUserOrg->GetKey());
  194. $oRequest->Set('caller_id', UserRights::GetContactId());
  195. $oRequest->Set('service_id', $aParameters['service_id']);
  196. $oRequest->Set('servicesubcategory_id', $aParameters['servicesubcategory_id']);
  197. $oAttDef = MetaModel::GetAttributeDef('UserRequest', 'service_id');
  198. $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $oServiceCategory->GetName());
  199. $oAttDef = MetaModel::GetAttributeDef('UserRequest', 'servicesubcategory_id');
  200. $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $oServiceSubCategory->GetName());
  201. $iFlags = 0;
  202. foreach($aList as $sAttCode)
  203. {
  204. $value = '';
  205. if (isset($aParameters[$sAttCode]))
  206. {
  207. $value = $aParameters[$sAttCode];
  208. $oRequest->Set($sAttCode, $value);
  209. }
  210. }
  211. $aFieldsMap = array();
  212. foreach($aList as $sAttCode)
  213. {
  214. $value = '';
  215. $oAttDef = MetaModel::GetAttributeDef(get_class($oRequest), $sAttCode);
  216. $iFlags = $oRequest->GetAttributeFlags($sAttCode);
  217. if (isset($aParameters[$sAttCode]))
  218. {
  219. $value = $aParameters[$sAttCode];
  220. }
  221. $aArgs = array('this' => $oRequest);
  222. $aFieldsMap[$sAttCode] = 'attr_'.$sAttCode;
  223. $sValue = $oRequest->GetFormElementForField($oP, get_class($oRequest), $sAttCode, $oAttDef, $value, '', 'attr_'.$sAttCode, '', $iFlags, $aArgs);
  224. $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sValue);
  225. }
  226. $aDetails[] = array('label' => Dict::S('Class:Ticket/Attribute:ticket_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>');
  227. $oP->add_linked_script("../js/json.js");
  228. $oP->add_linked_script("../js/forms-json-utils.js");
  229. $oP->add_linked_script("../js/wizardhelper.js");
  230. $oP->add_linked_script("../js/wizard.utils.js");
  231. $oP->add_linked_script("../js/linkswidget.js");
  232. $oP->add_linked_script("../js/extkeywidget.js");
  233. $oP->add_linked_script("../js/jquery.blockUI.js");
  234. $oP->add("<div class=\"wizContainer\" id=\"form_request_description\">\n");
  235. $oP->add("<h1 id=\"title_request_form\">".Dict::S('Portal:DescriptionOfTheRequest')."</h1>\n");
  236. $oP->WizardFormStart('request_form', 3);
  237. //$oP->add("<table>\n");
  238. $oP->details($aDetails);
  239. $oAttPlugin = new AttachmentPlugIn();
  240. $oAttPlugin->OnDisplayRelations($oRequest, $oP, true /* edit */);
  241. $oP->DumpHiddenParams($aParameters, $aList);
  242. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_request\">");
  243. $oP->WizardFormButtons(BUTTON_BACK | BUTTON_FINISH | BUTTON_CANCEL);
  244. $oP->WizardFormEnd();
  245. $oP->add("</div>\n");
  246. $iFieldsCount = count($aFieldsMap);
  247. $sJsonFieldsMap = json_encode($aFieldsMap);
  248. $oP->add_ready_script(
  249. <<<EOF
  250. oWizardHelper.SetFieldsMap($sJsonFieldsMap);
  251. oWizardHelper.SetFieldsCount($iFieldsCount);
  252. // Starts the validation when the page is ready
  253. CheckFields('request_form', false);
  254. $('#request_form').submit( function() {
  255. return OnSubmit('request_form');
  256. });
  257. EOF
  258. );
  259. }
  260. else
  261. {
  262. // User not authorized to use this service ?
  263. //ShowOngoingTickets($oP);
  264. }
  265. }
  266. /**
  267. * Validate the parameters and create the UserRequest object (based on the page's POSTed parameters)
  268. * @param WebPage $oP The current web page for the output
  269. * @param Organization $oUserOrg The organization of the current user
  270. * @return void
  271. */
  272. function DoCreateRequest($oP, $oUserOrg)
  273. {
  274. $aParameters = $oP->ReadAllParams(ALL_PARAMS);
  275. $sTransactionId = utils::ReadPostedParam('transaction_id', '');
  276. if (!utils::IsTransactionValid($sTransactionId))
  277. {
  278. $oP->add("<h1>".Dict::S('UI:Error:ObjectAlreadyCreated')."</h1>\n");
  279. //ShowOngoingTickets($oP);
  280. return;
  281. }
  282. // Validate the parameters
  283. // 1) ServiceCategory
  284. $oSearch = DBObjectSearch::FromOQL(VALIDATE_SERVICECATEGORY_QUERY);
  285. $oSet = new CMDBObjectSet($oSearch, array(), array('id' => $aParameters['service_id'], 'org_id' => $oUserOrg->GetKey()));
  286. if ($oSet->Count() != 1)
  287. {
  288. // Invalid service for the current user !
  289. throw new Exception("Invalid Service Category: id={$aParameters['service_id']} - count: ".$oSet->Count());
  290. }
  291. $oServiceCategory = $oSet->Fetch();
  292. // 2) Service Subcategory
  293. $oSearch = DBObjectSearch::FromOQL(VALIDATE_SERVICESUBCATEGORY_QUERY);
  294. $oSet = new CMDBObjectSet($oSearch, array(), array('service_id' => $aParameters['service_id'], 'id' =>$aParameters['servicesubcategory_id'],'org_id' => $oUserOrg->GetKey() ));
  295. if ($oSet->Count() != 1)
  296. {
  297. // Invalid subcategory
  298. throw new Exception("Invalid ServiceSubcategory: id={$aParameters['servicesubcategory_id']} for service category ".$oServiceCategory->GetName()."({$aParameters['service_id']}) - count: ".$oSet->Count());
  299. }
  300. $oServiceSubCategory = $oSet->Fetch();
  301. $oRequest = new UserRequest();
  302. $oRequest->Set('org_id', $oUserOrg->GetKey());
  303. $oRequest->Set('caller_id', UserRights::GetContactId());
  304. $aList = array('service_id', 'servicesubcategory_id', 'title', 'description', 'impact');
  305. $oRequest->UpdateObjectFromPostedForm();
  306. if (isset($aParameters['moreinfo']))
  307. {
  308. // There is a template, insert it into the description
  309. $oRequest->Set('ticket_log', $aParameters['moreinfo']);
  310. }
  311. /////$oP->DoUpdateObjectFromPostedForm($oObj);
  312. $oAttPlugin = new AttachmentPlugIn();
  313. $oAttPlugin->OnFormSubmit($oRequest);
  314. list($bRes, $aIssues) = $oRequest->CheckToWrite();
  315. if ($bRes)
  316. {
  317. $oRequest->DBInsert();
  318. $oP->add("<h1>".Dict::Format('UI:Title:Object_Of_Class_Created', $oRequest->GetName(), MetaModel::GetName(get_class($oRequest)))."</h1>\n");
  319. //DisplayObject($oP, $oRequest, $oUserOrg);
  320. ShowOngoingTickets($oP);
  321. }
  322. else
  323. {
  324. RequestCreationForm($oP, $oUserOrg);
  325. $sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten', implode(', ', $aIssues));
  326. $oP->add_ready_script("alert('".addslashes($sIssueDesc)."');");
  327. }
  328. }
  329. /**
  330. * Prompts the user for creating a new request
  331. * @param WebPage $oP The current web page
  332. * @return void
  333. */
  334. function CreateRequest(WebPage $oP, Organization $oUserOrg)
  335. {
  336. switch($oP->GetWizardStep())
  337. {
  338. case 0:
  339. default:
  340. SelectServiceCategory($oP, $oUserOrg);
  341. break;
  342. case 1:
  343. SelectServiceSubCategory($oP, $oUserOrg);
  344. break;
  345. case 2:
  346. RequestCreationForm($oP, $oUserOrg);
  347. break;
  348. case 3:
  349. DoCreateRequest($oP, $oUserOrg);
  350. break;
  351. }
  352. }
  353. /**
  354. * Lists all the currently opened User Requests for the current user
  355. * @param WebPage $oP The current web page
  356. * @return void
  357. */
  358. function ListOpenRequests(WebPage $oP)
  359. {
  360. $oUserOrg = GetUserOrg();
  361. $sOQL = 'SELECT UserRequest WHERE org_id = :org_id AND status NOT IN ("closed")';
  362. $oSearch = DBObjectSearch::FromOQL($sOQL);
  363. $iUser = UserRights::GetContactId();
  364. if ($iUser > 0)
  365. {
  366. $oSearch->AddCondition('caller_id', $iUser);
  367. }
  368. $oSet = new CMDBObjectSet($oSearch, array(), array('org_id' => $oUserOrg->GetKey()));
  369. $aZList = array('finalclass', 'title', 'start_date', 'status', 'servicesubcategory_id', 'priority', 'caller_id');
  370. $oP->DisplaySet($oSet, $aZList, Dict::S('Portal:NoOpenRequest'));
  371. }
  372. /**
  373. * Lists all the currently resolved (not yet closed) User Requests for the current user
  374. * @param WebPage $oP The current web page
  375. * @return void
  376. */
  377. function ListResolvedRequests(WebPage $oP)
  378. {
  379. $oUserOrg = GetUserOrg();
  380. $sOQL = 'SELECT UserRequest WHERE org_id = :org_id AND status = "resolved"';
  381. $oSearch = DBObjectSearch::FromOQL($sOQL);
  382. $iUser = UserRights::GetContactId();
  383. if ($iUser > 0)
  384. {
  385. $oSearch->AddCondition('caller_id', $iUser);
  386. }
  387. $oSet = new CMDBObjectSet($oSearch, array(), array('org_id' => $oUserOrg->GetKey()));
  388. $aZList = array('finalclass', 'title', 'start_date', 'status', 'servicesubcategory_id', 'priority', 'caller_id');
  389. $oP->DisplaySet($oSet, $aZList, Dict::S('Portal:NoOpenRequest'));
  390. }
  391. /**
  392. * Lists all the currently closed tickets
  393. * @param WebPage $oP The current web page
  394. * @return void
  395. */
  396. function ListClosedTickets(WebPage $oP)
  397. {
  398. $aAttSpecs = array('ref', 'start_date', 'close_date', 'service_id', 'caller_id');
  399. $aZList = array('title', 'start_date', 'close_date', 'servicesubcategory_id');
  400. $oP->DisplaySearchForm('UserRequest', $aAttSpecs, array('operation' => 'show_closed'), 'search_', false /* => not closed */);
  401. $oUserOrg = GetUserOrg();
  402. // UserRequest
  403. $oSearch = $oP->PostedParamsToFilter('UserRequest', $aAttSpecs, 'search_');
  404. if(is_null($oSearch))
  405. {
  406. $oSearch = new DBObjectSearch('UserRequest');
  407. }
  408. $oSearch->AddCondition('org_id', $oUserOrg->GetKey());
  409. $oSearch->AddCondition('status', 'closed');
  410. $iUser = UserRights::GetContactId();
  411. if ($iUser > 0)
  412. {
  413. $oSearch->AddCondition('caller_id', $iUser);
  414. }
  415. $oSet1 = new CMDBObjectSet($oSearch);
  416. $oP->add("<p>\n");
  417. $oP->add("<h1>".Dict::S('Portal:ClosedRequests')."</h1>\n");
  418. $oP->DisplaySet($oSet1, $aZList, Dict::S('Portal:NoClosedRequest'));
  419. $oP->add("</p>\n");
  420. }
  421. /**
  422. * Display an object - to be customized
  423. * @param WebPage $oP The current web page
  424. * @param Object $oObj Any kind of object
  425. * @param Object $oUserOrg The organization of the logged in user
  426. * @return void
  427. */
  428. function DisplayObject($oP, $oObj, $oUserOrg)
  429. {
  430. switch(get_class($oObj))
  431. {
  432. case 'UserRequest':
  433. ShowDetailsRequest($oP, $oObj);
  434. break;
  435. default:
  436. throw new Exception("The class ".get_class($oObj)." is not handled through the portal");
  437. }
  438. }
  439. /**
  440. * Displays the details of a request
  441. * @param WebPage $oP The current web page
  442. * @param Object $oObj The target object
  443. * @return void
  444. */
  445. function ShowDetailsRequest(WebPage $oP, $oObj)
  446. {
  447. $sClass = get_class($oObj);
  448. $bIsEscalateButton = false;
  449. $bIsCloseButton = false;
  450. $bEditAttachments = false;
  451. switch($oObj->GetState())
  452. {
  453. case 'new':
  454. case 'assigned':
  455. case 'frozen':
  456. $aEditAtt = array(
  457. 'ticket_log' => '????'
  458. );
  459. $bEditAttachments = true;
  460. // disabled - $bIsEscalateButton = true;
  461. break;
  462. case 'escalated_tto':
  463. case 'escalated_ttr':
  464. $aEditAtt = array(
  465. 'ticket_log' => '????'
  466. );
  467. $bEditAttachments = true;
  468. break;
  469. case 'resolved':
  470. $aEditAtt = array(
  471. // non, read-only dans cet etat - 'ticket_log' => '????',
  472. 'user_satisfaction' => '????',
  473. 'user_commment' => '????',
  474. );
  475. $bIsCloseButton = true;
  476. break;
  477. case 'closed':
  478. case 'closure_requested':
  479. default:
  480. $aEditAtt = array();
  481. break;
  482. }
  483. // REFACTORISER LA MISE EN FORME
  484. $oP->add("<h1 id=\"title_request_details\">".$oObj->GetIcon()."&nbsp;".Dict::Format('Portal:TitleRequestDetailsFor_Request', $oObj->GetName())."</h1>\n");
  485. switch($sClass)
  486. {
  487. case 'UserIssue':
  488. //$aAttList = array('ref', 'status', 'title', 'description', 'start_date', 'caller_id', 'servicesubcategory_id', 'impact', 'priority', 'agent_id', 'close_date', 'last_update', 'assignment_date', 'resolution_code', 'solution', 'origin', 'time_spent', 'respected_gtr', 'gtr_overdue', 'user_satisfaction', 'user_commment', 'freeze_reason', 'ticket_log');
  489. $aAttList = array('col:0'=> array('ref','caller_id','impact','perimeter','servicesubcategory_id','title'),'col:1'=> array('status','priority','start_date','resolution_date','last_update','agent_id'));
  490. break;
  491. case 'UserRequest':
  492. //$aAttList = array('ref', 'status', 'title', 'description', 'requesttype', 'start_date', 'caller_id', 'servicesubcategory_id', 'priority', 'agent_id', 'close_date', 'last_update', 'assignment_date', 'user_satisfaction', 'user_commment', 'freeze_reason', 'ticket_log');
  493. $aAttList = array('col:0'=> array('ref','caller_id','servicesubcategory_id','title'),'col:1'=> array('status','priority','start_date','resolution_date','last_update','agent_id'));
  494. break;
  495. default:
  496. //$aAttList = array('ref');
  497. array('col:0'=> array('ref','service_id','servicesubcategory_id','title'),'col:1'=> array('status','start_date'));
  498. break;
  499. }
  500. // Remove the edited attribute from the shown attributes
  501. //
  502. foreach($aEditAtt as $sAttCode => $foo)
  503. {
  504. foreach($aAttList as $col => $aColumn)
  505. {
  506. if (in_array($sAttCode, $aColumn))
  507. {
  508. if(($index = array_search($sAttCode, $aColumn)) !== false)
  509. {
  510. unset($aAttList[$col][$index]);
  511. }
  512. }
  513. }
  514. }
  515. $oP->add("<div class=\"wizContainer\" id=\"form_commment_request\">\n");
  516. $oP->WizardFormStart('request_form', null);
  517. $oP->add('<div id="request_details">');
  518. $oP->add('<table id="request_details_table">');
  519. $oP->add('<tr>');
  520. $oP->add('<td style="vertical-align:top;">');
  521. $oP->DisplayObjectDetails($oObj, $aAttList['col:0']);
  522. $oP->add('</td>');
  523. $oP->add('<td style="vertical-align:top;">');
  524. $oP->DisplayObjectDetails($oObj, $aAttList['col:1']);
  525. $oP->add('</td>');
  526. $oP->add('</tr>');
  527. // REFACTORISER
  528. $oP->add('<tr>');
  529. $oP->add('<td colspan="2" style="vertical-align:top;">');
  530. $oAttPlugin = new AttachmentPlugIn();
  531. if ($bEditAttachments)
  532. {
  533. $oAttPlugin->EnableDelete(false);
  534. $oAttPlugin->OnDisplayRelations($oObj, $oP, true /* edit */);
  535. }
  536. else
  537. {
  538. $oAttPlugin->OnDisplayRelations($oObj, $oP, false /* read */);
  539. }
  540. $oP->add('</td>');
  541. $oP->add('</tr>');
  542. if (count($aEditAtt) > 0)
  543. {
  544. $oP->add('<tr>');
  545. $oP->add('<td colspan="2" style="vertical-align:top;">');
  546. //$oP->add("<form action=\"../portal/index.php\" id=\"request_form\" method=\"post\">\n");
  547. //$oP->add('<table id=""><tr><td style="vertical-align:top;">');
  548. //$oP->add("<h1 id=\"title_request_details\">".Dict::Format('Portal:CommentsFor_Request', $oObj->GetName())."</h1>\n");
  549. $oP->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">");
  550. $oP->add("<input type=\"hidden\" name=\"id\" value=\"".$oObj->GetKey()."\">");
  551. $oP->add("<input type=\"hidden\" name=\"operation\" value=\"update_request\">");
  552. $oP->add("<input type=\"hidden\" id=\"stimulus_to_apply\" name=\"apply_stimulus\" value=\"\">\n");
  553. $oP->add_script(
  554. <<<EOF
  555. function SetStimulusToApply(sStimulusCode)
  556. {
  557. $('#stimulus_to_apply').val(sStimulusCode);
  558. }
  559. EOF
  560. );
  561. $aEditFields = array(); // Intermediate array to avoid code duplication while splitting btw ticket_log and the rest
  562. foreach($aEditAtt as $sAttCode => $foo)
  563. {
  564. $sValue = $oObj->Get($sAttCode);
  565. $sDisplayValue = $oObj->GetEditValue($sAttCode);
  566. $aArgs = array('this' => $oObj, 'formPrefix' => '');
  567. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  568. $sInputId = 'input_'.$sAttCode;
  569. $sHTMLValue = "<span id=\"field_{$sInputId}\">".cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', 0 /*$iFlags*/, $aArgs).'</span>';
  570. $aEditFields[$sAttCode] = array(
  571. 'label' => MetaModel::GetLabel($sClass, $sAttCode),
  572. 'value' => $sHTMLValue
  573. );
  574. }
  575. foreach($aEditFields as $sAttCode => $aFieldSpec)
  576. {
  577. if ($sAttCode == 'ticket_log')
  578. {
  579. // Skip, the public log will be displayed below the buttons
  580. continue;
  581. }
  582. $oP->add("<div class=\"edit_item\">");
  583. $oP->add('<h1>'.$aFieldSpec['label'].'</h1>');
  584. $oP->add($aFieldSpec['value']);
  585. $oP->add('</div>');
  586. }
  587. // $oP->p('<textarea id="user_request_commment" name="commment"></textarea>');
  588. if($bIsCloseButton)
  589. {
  590. $sStimulusCode = 'ev_close';
  591. $oP->p('<input type="submit" onClick="SetStimulusToApply(\''.$sStimulusCode.'\');" value="'.Dict::S('Portal:Button:CloseTicket').'">');
  592. }
  593. else
  594. {
  595. $oP->p('<input type="submit" value="'.Dict::S('Portal:Button:UpdateRequest').'">');
  596. }
  597. if ($bIsEscalateButton)
  598. {
  599. $sStimulusCode = 'ev_timeout';
  600. $oP->p('<input type="submit" onClick="SetStimulusToApply(\''.$sStimulusCode.'\');" value="'.Dict::S('Portal:ButtonEscalate').'">');
  601. }
  602. $oP->add('</td>');
  603. $oP->add('</tr>');
  604. }
  605. $oP->add('<tr>');
  606. $oP->add('<td colspan="2" style="vertical-align:top;">');
  607. if (isset($aEditFields['ticket_log']))
  608. {
  609. $oP->add("<div class=\"edit_item\">");
  610. $oP->add('<h1>'.$aEditFields['ticket_log']['label'].'</h1>');
  611. $oP->add($aEditFields['ticket_log']['value']);
  612. $oP->add('</div>');
  613. }
  614. else
  615. {
  616. $oP->add('<h1>'.MetaModel::GetLabel($sClass, 'ticket_log').'</h1>');
  617. $oP->add($oObj->GetAsHTML('ticket_log'));
  618. }
  619. $oP->add('</td>');
  620. $oP->add('</tr>');
  621. $oP->add('</table>');
  622. $oP->add('</div>');
  623. $oP->WizardFormEnd();
  624. $oP->add('</div>');
  625. }
  626. /**
  627. * Get The organization of the current user (i.e. the organization of its contact)
  628. * @param WebPage $oP The current page, for errors output
  629. * @return Organization The user's org or null in case of problem...
  630. */
  631. function GetUserOrg()
  632. {
  633. $oOrg = null;
  634. $iContactId = UserRights::GetContactId();
  635. $oContact = MetaModel::GetObject('Contact', $iContactId, false); // false => Can fail
  636. if (is_object($oContact))
  637. {
  638. $oOrg = MetaModel::GetObject('Organization', $oContact->Get('org_id'), false); // false => can fail
  639. }
  640. else
  641. {
  642. throw new Exception(Dict::S('Portal:ErrorNoContactForThisUser'));
  643. }
  644. return $oOrg;
  645. }
  646. ///////////////////////////////////////////////////////////////////////////////
  647. //
  648. // Main program
  649. //
  650. ///////////////////////////////////////////////////////////////////////////////
  651. try
  652. {
  653. require_once(APPROOT.'/application/startup.inc.php');
  654. require_once(APPROOT.'/application/portalwebpage.class.inc.php');
  655. $oAppContext = new ApplicationContext();
  656. $sOperation = utils::ReadParam('operation', '');
  657. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  658. LoginWebPage::DoLogin(false /* bMustBeAdmin */, true /* IsAllowedToPortalUsers */); // Check user rights and prompt if needed
  659. ApplicationContext::SetUrlMakerClass('MyPortalURLMaker');
  660. $oUserOrg = GetUserOrg();
  661. $sCode = $oUserOrg->Get('code');
  662. $sAlternateStylesheet = '';
  663. if (@file_exists("./$sCode/portal.css"))
  664. {
  665. $sAlternateStylesheet = "$sCode";
  666. }
  667. $oP = new PortalWebPage(Dict::S('Portal:Title'), $sAlternateStylesheet);
  668. $oP->EnableDisconnectButton(utils::CanLogOff());
  669. $oP->SetWelcomeMessage(Dict::Format('Portal:WelcomeUserOrg', UserRights::GetUserFriendlyName(), $oUserOrg->GetName()));
  670. if (is_object($oUserOrg))
  671. {
  672. switch($sOperation)
  673. {
  674. case 'show_closed':
  675. DisplayMainMenu($oP);
  676. ShowClosedTickets($oP);
  677. break;
  678. case 'create_request':
  679. DisplayMainMenu($oP);
  680. CreateRequest($oP, $oUserOrg);
  681. break;
  682. case 'details':
  683. DisplayMainMenu($oP);
  684. $oObj = $oP->FindObjectFromArgs(array('UserRequest'));
  685. DisplayObject($oP, $oObj, $oUserOrg);
  686. break;
  687. case 'update_request':
  688. DisplayMainMenu($oP);
  689. $oObj = $oP->FindObjectFromArgs(array('UserRequest'));
  690. switch(get_class($oObj))
  691. {
  692. case 'UserRequest':
  693. $aAttList = array('ticket_log', 'user_satisfaction', 'user_commment');
  694. break;
  695. default:
  696. throw new Exception("Implementation issue: unexpected class '".get_class($oObj)."'");
  697. }
  698. try
  699. {
  700. $oP->DoUpdateObjectFromPostedForm($oObj, $aAttList);
  701. }
  702. catch(TransactionException $e)
  703. {
  704. $oP->add("<h1>".Dict::S('UI:Error:ObjectAlreadyUpdated')."</h1>\n");
  705. }
  706. DisplayObject($oP, $oObj, $oUserOrg);
  707. break;
  708. case 'show_ongoing':
  709. default:
  710. DisplayMainMenu($oP);
  711. ShowOngoingTickets($oP);
  712. }
  713. }
  714. $oP->output();
  715. }
  716. catch(CoreException $e)
  717. {
  718. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  719. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  720. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  721. $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
  722. $oP->output();
  723. if (MetaModel::IsLogEnabledIssue())
  724. {
  725. if (MetaModel::IsValidClass('EventIssue'))
  726. {
  727. try
  728. {
  729. $oLog = new EventIssue();
  730. $oLog->Set('message', $e->getMessage());
  731. $oLog->Set('userinfo', '');
  732. $oLog->Set('issue', $e->GetIssue());
  733. $oLog->Set('impact', 'Page could not be displayed');
  734. $oLog->Set('callstack', $e->getTrace());
  735. $oLog->Set('data', $e->getContextData());
  736. $oLog->DBInsertNoReload();
  737. }
  738. catch(Exception $e)
  739. {
  740. IssueLog::Error("Failed to log issue into the DB");
  741. }
  742. }
  743. IssueLog::Error($e->getMessage());
  744. }
  745. // For debugging only
  746. //throw $e;
  747. }
  748. catch(Exception $e)
  749. {
  750. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  751. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  752. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  753. $oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
  754. $oP->output();
  755. if (MetaModel::IsLogEnabledIssue())
  756. {
  757. if (MetaModel::IsValidClass('EventIssue'))
  758. {
  759. try
  760. {
  761. $oLog = new EventIssue();
  762. $oLog->Set('message', $e->getMessage());
  763. $oLog->Set('userinfo', '');
  764. $oLog->Set('issue', 'PHP Exception');
  765. $oLog->Set('impact', 'Page could not be displayed');
  766. $oLog->Set('callstack', $e->getTrace());
  767. $oLog->Set('data', array());
  768. $oLog->DBInsertNoReload();
  769. }
  770. catch(Exception $e)
  771. {
  772. IssueLog::Error("Failed to log issue into the DB");
  773. }
  774. }
  775. IssueLog::Error($e->getMessage());
  776. }
  777. }
  778. ?>