index.php 29 KB

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