index.php 29 KB

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