PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/incident_close.php

https://github.com/paulheaney/sitracker
PHP | 615 lines | 490 code | 69 blank | 56 comment | 84 complexity | 0c3d4508019d96bae00d837047b517d7 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0, BSD-3-Clause, GPL-2.0
  1. <?php
  2. // close_incident.php - Display a form for closing an incident
  3. //
  4. // SiT (Support Incident Tracker) - Support call tracking system
  5. // Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
  6. //
  7. // This software may be used and distributed according to the terms
  8. // of the GNU General Public License, incorporated herein by reference.
  9. //
  10. $permission = 18; // Close Incidents
  11. require ('core.php');
  12. require (APPLICATION_LIBPATH . 'functions.inc.php');
  13. require_once (APPLICATION_LIBPATH . 'billing.inc.php');
  14. // This page requires authentication
  15. require (APPLICATION_LIBPATH . 'auth.inc.php');
  16. // External Variables
  17. $id = cleanvar($_REQUEST['id']);
  18. $incidentid = $id;
  19. $title = $strClose;
  20. // No submit detected show closure form
  21. if (empty($_REQUEST['process']))
  22. {
  23. $sql = "SELECT owner FROM `{$dbIncidents}` WHERE id = '{$incidentid}'";
  24. $result = mysql_query($sql);
  25. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  26. list($owner) = mysql_fetch_row($result);
  27. if ($owner == 0)
  28. {
  29. html_redirect("incident_details.php?id={$incidentid}", FALSE, $strCallMustBeAssignedBeforeClosure);
  30. exit;
  31. }
  32. if (count(open_activities_for_incident($incidentid)) > 0)
  33. {
  34. html_redirect("incident_details.php?id={$incidentid}", FALSE, $strMustCompleteActivitiesBeforeClosure);
  35. exit;
  36. }
  37. include (APPLICATION_INCPATH . 'incident_html_top.inc.php');
  38. ?>
  39. <script type="text/javascript">
  40. <!--
  41. function enablekb()
  42. {
  43. // INL 28Nov07 Yes I know a lot of this javascript is horrible
  44. // it's old and I'm tired and can't be bothered right now
  45. // the newer stuff at the bottom is pretty and uses prototype.js
  46. // syntax
  47. if (document.closeform.kbtitle.disabled==true)
  48. {
  49. // Enable KB
  50. document.closeform.kbtitle.disabled=false;
  51. //document.closeform.cust_vis1.disabled=true;
  52. //document.closeform.cust_vis1.checked=true;
  53. //document.closeform.cust_vis2.checked=true;
  54. //document.closeform.cust_vis2.disabled=true;
  55. // Enable KB includes
  56. //document.closeform.incsummary.disabled=false;
  57. document.closeform.summary.disabled=false;
  58. document.closeform.incsymptoms.disabled=false;
  59. document.closeform.symptoms.disabled=false;
  60. document.closeform.inccause.disabled=false;
  61. document.closeform.cause.disabled=false;
  62. document.closeform.incquestion.disabled=false;
  63. document.closeform.question.disabled=false;
  64. document.closeform.incanswer.disabled=false;
  65. document.closeform.answer.disabled=false;
  66. //document.closeform.incsolution.disabled=false;
  67. document.closeform.solution.disabled=false;
  68. document.closeform.incworkaround.disabled=false;
  69. document.closeform.workaround.disabled=false;
  70. document.closeform.incstatus.disabled=false;
  71. document.closeform.status.disabled=false;
  72. document.closeform.incadditional.disabled=false;
  73. document.closeform.additional.disabled=false;
  74. document.closeform.increferences.disabled=false;
  75. document.closeform.references.disabled=false;
  76. $('helptext').innerHTML = strSelectKBSections;
  77. $('helptext').innerHTML = $('helptext').innerHTML + "<br /><strong>" + strKnowledgeBaseArticle + "</strong>:";
  78. // Show the table rows for KB article
  79. $('titlerow').show();
  80. $('distributionrow').show();
  81. $('symptomsrow').show();
  82. $('causerow').show();
  83. $('questionrow').show();
  84. $('answerrow').show();
  85. $('workaroundrow').show();
  86. $('statusrow').show();
  87. $('inforow').show();
  88. $('referencesrow').show();
  89. }
  90. else
  91. {
  92. // Disable KB
  93. document.closeform.kbtitle.disabled=true;
  94. //document.closeform.cust_vis1.disabled=false;
  95. //document.closeform.cust_vis2.disabled=false;
  96. // Disable KB includes
  97. document.closeform.incsymptoms.checked=false;
  98. document.closeform.incsymptoms.disabled=true;
  99. document.closeform.symptoms.disabled=true;
  100. document.closeform.inccause.checked=false;
  101. document.closeform.inccause.disabled=true;
  102. document.closeform.cause.disabled=true;
  103. document.closeform.incquestion.checked=false;
  104. document.closeform.incquestion.disabled=true;
  105. document.closeform.question.disabled=true;
  106. document.closeform.incanswer.checked=false;
  107. document.closeform.incanswer.disabled=true;
  108. document.closeform.answer.disabled=true;
  109. // document.closeform.incsolution.checked=false;
  110. // document.closeform.incsolution.disabled=true;
  111. // document.closeform.solution.disabled=true;
  112. document.closeform.incworkaround.checked=false;
  113. document.closeform.incworkaround.disabled=true;
  114. document.closeform.workaround.disabled=true;
  115. document.closeform.incstatus.checked=false;
  116. document.closeform.incstatus.disabled=true;
  117. document.closeform.status.disabled=true;
  118. document.closeform.incadditional.checked=false;
  119. document.closeform.incadditional.disabled=true;
  120. document.closeform.additional.disabled=true;
  121. document.closeform.increferences.checked=false;
  122. document.closeform.increferences.disabled=true;
  123. document.closeform.references.disabled=true;
  124. document.closeform.incworkaround.checked=false;
  125. document.closeform.incworkaround.disabled=true;
  126. document.closeform.workaround.disabled=true;
  127. $('helptext').innerHTML = strEnterDetailsAboutIncidentToBeStoredInLog;
  128. $('helptext').innerHTML + $('helptext').innerHTML = ' ' + strSummaryOfProblemAndResolution;
  129. $('helptext').innerHTML = $('helptext').innerHTML + "<br /><strong>" + strFinalUpdate + "</strong>:";
  130. // Hide the table rows for KB article
  131. $('titlerow').hide();
  132. $('distributionrow').hide();
  133. $('symptomsrow').hide();
  134. $('causerow').hide();
  135. $('questionrow').hide();
  136. $('answerrow').hide();
  137. $('workaroundrow').hide();
  138. $('statusrow').hide();
  139. $('inforow').hide();
  140. $('referencesrow').hide();
  141. }
  142. }
  143. function editbox(object, boxname)
  144. {
  145. var boxname;
  146. object.boxname.disabled=true;
  147. }
  148. -->
  149. </script>
  150. <?php
  151. echo "<form name='closeform' action='{$_SERVER['PHP_SELF']}' method='post'>";
  152. echo "<table class='vertical' width='100%'>";
  153. echo "<tr><th width='20%'>{$strClose}</th>";
  154. echo "<td><label><input type='radio' name='wait' value='yes' checked='checked' />";
  155. echo "{$strMarkForClosure}</label><br />";
  156. echo "<label><input type='radio' name='wait' value='no' />{$strCloseImmediately}</label></td></tr>\n";
  157. echo "<tr><th>{$strKnowledgeBase}";
  158. echo "</th><td><label><input type='checkbox' name='kbarticle' onchange='enablekb();' value='yes' />";
  159. echo "{$strNewKBArticle}</label></td></tr>\n";
  160. echo "<tr id='titlerow' style='display:none;'><th>{$strTitle}</th>";
  161. echo "<td><input class='required' type='text' name='kbtitle' id='kbtitle' ";
  162. echo "size='30' value='{$incident_title}' disabled='disabled' /> ";
  163. echo "<span class='required'>{$strRequired}</span></td></tr>\n";
  164. echo "<tr id='distributionrow' style='display:none;'><th>{$strDistribution}</th>";
  165. echo "<td>";
  166. echo "<select name='distribution'> ";
  167. echo "<option value='public' selected='selected'>{$strPublic}</option>";
  168. echo "<option value='private' style='color: blue;'>{$strPrivate}</option>";
  169. echo "<option value='restricted' style='color: red;'>{$strRestricted}</option>";
  170. echo "</select> ";
  171. echo help_link('KBDistribution');
  172. echo "</td></tr>\n";
  173. echo "<tr><th>&nbsp;</th><td>";
  174. echo "<span id='helptext'>{$strEnterDetailsAboutIncidentToBeStoredInLog}";
  175. echo "{$strSummaryOfProblemAndResolution}<br /><strong>{$strFinalUpdate}</strong>:</span></td></tr>\n";
  176. echo "<tr><th>{$strSummary}<br /><span class='required'>{$strRequired}\n";
  177. echo "</span><br />";
  178. echo "<input type='checkbox' name='incsummary' onclick=\"if (this.checked) {document.closeform.summary.disabled = false; ";
  179. echo "document.closeform.summary.style.display='';} else { saveValue=document.closeform.summary.value; ";
  180. echo "document.closeform.summary.disabled = true; document.closeform.summary.style.display='none';}\" checked='checked' disabled='disabled' /></th>";
  181. echo "<td>{$strSummaryOfProblem}<br />\n";
  182. echo "<textarea class='required' id='summary' name='summary' cols='40' rows='8' onfocus=\"if (this.enabled) { this.value = saveValue; ";
  183. echo "setTimeout('document.articlform.summary.blur()',1); } else saveValue=this.value;\">";
  184. // style="display: none;"
  185. $sql = "SELECT * FROM `{$dbUpdates}` WHERE incidentid='{$id}' AND type='probdef' ORDER BY timestamp ASC";
  186. $result = mysql_query($sql);
  187. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
  188. while ($row = mysql_fetch_object($result))
  189. {
  190. $bodytext = str_replace("<hr>", "", $row->bodytext);
  191. echo $bodytext;
  192. echo "\n\n";
  193. }
  194. echo "</textarea>\n";
  195. echo "</td></tr>";
  196. echo "<tr id='symptomsrow' style='display:none;'><th><label>{$strSymptoms}<br /><input type='checkbox' name='incsymptoms' onclick=\"if (this.checked) {document.closeform.symptoms.disabled = false; document.closeform.symptoms.style.display=''} else { saveValue=document.closeform.symptoms.value; document.closeform.symptoms.disabled = true; document.closeform.symptoms.style.display='none'}\" disabled='disabled' /></label></th>";
  197. echo "<td><textarea id='symptoms' name='symptoms' cols='40' style='display: none;' rows='8' onfocus=\"if (this.enabled) { this.value = saveValue; setTimeout('document.articlform.symptoms.blur()',1); } else saveValue=this.value;\"></textarea></td></tr>";
  198. echo "<tr id='causerow' style='display:none;'><th><label>{$strCause}<br /><input type='checkbox' name='inccause' onclick=\"if (this.checked) {document.closeform.cause.disabled = false; document.closeform.cause.style.display=''} else { saveValue=document.closeform.cause.value; document.closeform.cause.disabled = true; document.closeform.cause.style.display='none'}\" disabled='disabled' /></label></th>";
  199. echo "<td><textarea id='cause' name='cause' cols='40' rows='8' style='display: none;' onfocus=\"if (this.enabled) { this.value = saveValue; setTimeout('document.articlform.cause.blur()',1); } else saveValue=this.value;\"></textarea></td></tr>";
  200. echo "<tr id='questionrow' style='display:none;'><th><label>{$strQuestion}<br /><input type='checkbox' name='incquestion' onclick=\"if (this.checked) {document.closeform.question.disabled = false; document.closeform.question.style.display=''} else { saveValue=document.closeform.question.value; document.closeform.question.disabled = true; document.closeform.question.style.display='none'}\" disabled='disabled' /></label></th>";
  201. echo "<td><textarea id='question' name='question' cols='40' rows='8' style='display: none;' onfocus=\"if (this.enabled) { this.value = saveValue; setTimeout('document.articlform.question.blur()',1); } else saveValue=this.value;\"></textarea></td></tr>";
  202. echo "<tr id='answerrow' style='display:none;'><th><label>{$strAnswer}<br /><input type='checkbox' name='incanswer' onclick=\"if (this.checked) {document.closeform.answer.disabled = false; document.closeform.answer.style.display=''} else { saveValue=document.closeform.answer.value; document.closeform.answer.disabled = true; document.closeform.answer.style.display='none'}\" disabled='disabled' /></label></th>";
  203. echo "<td><textarea id='answer' name='answer' cols='40' rows='8' style='display: none;' onfocus=\"if (this.enabled) { this.value = saveValue; setTimeout('document.articlform.answer.blur()',1); } else saveValue=this.value;\"></textarea></td></tr>";
  204. echo "<tr><th><label>{$strSolution}</label>";
  205. echo "<br /><span class='required'>{$strRequired}</span><br />";
  206. echo "<input type='checkbox' name='incsolution' onclick=\"if (this.checked) {document.closeform.solution.disabled = false; document.closeform.solution.style.display=''} else { saveValue=document.closeform.solution.value; document.closeform.solution.disabled = true; document.closeform.solution.style.display='none'}\" checked='checked' disabled='disabled' /></th>";
  207. echo "<td><textarea id='solution' name='solution' cols='40' rows='8' onfocus=\"if (this.enabled) { this.value = saveValue; setTimeout('document.articleform.solution.blur()',1); } else saveValue=this.value;\">";
  208. $sql = "SELECT * FROM `{$dbUpdates}` WHERE incidentid='{$id}' AND (type='solution' OR type='actionplan') ORDER BY timestamp DESC";
  209. $result = mysql_query($sql);
  210. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
  211. while ($row = mysql_fetch_object($result))
  212. {
  213. $bodytext = str_replace("<hr>", "", $row->bodytext);
  214. echo trim($bodytext);
  215. echo "\n\n";
  216. }
  217. echo "</textarea>\n";
  218. echo "</td></tr>";
  219. echo "<tr id='workaroundrow' style='display:none;'><th><label>{$strWorkaround}<br /><input type='checkbox' name='incworkaround' onclick=\"if (this.checked) {document.closeform.workaround.disabled = false; document.closeform.workaround.style.display=''} else { saveValue=document.closeform.workaround.value; document.closeform.workaround.disabled = true; document.closeform.workaround.style.display='none'}\" disabled='disabled' /></label></th>";
  220. echo "<td><textarea id='workaround' name='workaround' cols='40' rows='8' style='display: none;' onfocus=\"if (this.enabled) { this.value = saveValue; setTimeout('document.articlform.workaround.blur()',1); } else saveValue=this.value;\"></textarea></td></tr>";
  221. echo "<tr id='statusrow' style='display:none;'><th><label>{$strStatus}<br /><input type='checkbox' name='incstatus' onclick=\"if (this.checked) {document.closeform.status.disabled = false; document.closeform.status.style.display=''} else { saveValue=document.closeform.status.value; document.closeform.status.disabled = true; document.closeform.status.style.display='none'}\" disabled='disabled' /></label></th>";
  222. echo "<td><textarea id='status' name='status' cols='40' rows='8' style='display: none;' onfocus=\"if (this.enabled) { this.value = saveValue; setTimeout('document.articlform.status.blur()',1); } else saveValue=this.value;\"></textarea></td></tr>";
  223. echo "<tr id='inforow' style='display:none;'><th><label>{$strAdditionalInfo}<br /><input type='checkbox' name='incadditional' onclick=\"if (this.checked) {document.closeform.additional.disabled = false; document.closeform.additional.style.display=''} else { saveValue=document.closeform.additional.value; document.closeform.additional.disabled = true; document.closeform.additional.style.display='none'}\" disabled='disabled' /></label></th>";
  224. echo "<td><textarea id='additional' name='additional' cols='40' rows='8' style='display: none;' onfocus=\"if (this.enabled) { this.value = saveValue; setTimeout('document.articlform.additional.blur()',1); } else saveValue=this.value;\"></textarea></td></tr>";
  225. echo "<tr id='referencesrow' style='display:none;'><th><label>{$strReferences}<br /><input type='checkbox' name='increferences' onclick=\"if (this.checked) {document.closeform.references.disabled = false; document.closeform.references.style.display=''} else { saveValue=document.closeform.references.value; document.closeform.references.disabled = true; document.closeform.references.style.display='none'}\" disabled='disabled' /></label></th>";
  226. echo "<td><textarea id='references' name='references' cols='40' rows='8' style='display: none;' onfocus=\"if (this.enabled) { this.value = saveValue; setTimeout('document.articlform.references.blur()',1); } else saveValue=this.value;\"></textarea></td></tr>";
  227. echo "<tr><th>{$strClosingStatus}</th><td>";
  228. echo closingstatus_drop_down("closingstatus", 0, TRUE);
  229. echo " <span class='required'>{$strRequired}</span></td></tr>\n";
  230. echo "<tr><th>".sprintf($strInformX, $strCustomer)."</th>";
  231. echo "<td>{$strSendEmailExplainingIncidentClosure}<br />";
  232. echo "<label><input name='send_email' checked='checked' type='radio' value='no' />{$strNo}</label> ";
  233. echo "<input name='send_email' type='radio' value='yes' />{$strYes}</td></tr>\n";
  234. $externalemail = incident_externalemail($id);
  235. if ($externalemail)
  236. {
  237. echo "<tr><th>".sprintf($strInformX, $strExternalEngineer).":<br />";
  238. printf($strSendEmailExternalIncidentClosure, "<em>{$externalemail}</em>");
  239. echo "</th>";
  240. echo "<td class='shade2'><label><input name='send_engineer_email' type='radio' value='no' />{$strNo}</label> ";
  241. echo "<label><input name='send_engineer_email' type='radio' value='yes' checked='checked' />{$strYes}</label></td></tr>\n";
  242. }
  243. echo "</table>\n";
  244. echo "<p align='center'>";
  245. echo "<input name='type' type='hidden' value='Support' />";
  246. echo "<input name='id' type='hidden' value='$id' />";
  247. echo "<input type='hidden' name='process' value='closeincident' />";
  248. echo "<input name='submit' type='submit' value=\"{$strClose}\" /></p>";
  249. echo "</form>";
  250. include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
  251. }
  252. else
  253. {
  254. // External variables
  255. $closingstatus = cleanvar($_POST['closingstatus']);
  256. $summary = cleanvar($_POST['summary']);
  257. $id = cleanvar($_POST['id']);
  258. $distribution = cleanvar($_POST['distribution']);
  259. $solution = cleanvar($_POST['solution']);
  260. $kbarticle = cleanvar($_POST['kbarticle']);
  261. $kbtitle = cleanvar($_POST['kbtitle']);
  262. $symptoms = cleanvar($_POST['symptoms']);
  263. $cause = cleanvar($_POST['cause']);
  264. $question = cleanvar($_POST['question']);
  265. $answer = cleanvar($_POST['answer']);
  266. $workaround = cleanvar($_POST['workaround']);
  267. $status = cleanvar($_POST['status']);
  268. $additional = cleanvar($_POST['additional']);
  269. $references = cleanvar($_POST['references']);
  270. $wait = cleanvar($_POST['wait']);
  271. $send_email = cleanvar($_POST['send_email']);
  272. $send_engineer_email = cleanvar($_POST['send_engineer_email']);
  273. // Close the incident
  274. $errors = 0;
  275. echo "<script src='{$CONFIG['application_webpath']}scripts/webtrack.js' type='text/javascript'></script>\n";
  276. // check for blank closing status field
  277. if ($closingstatus == 0)
  278. {
  279. $errors = 1;
  280. $error_string = user_alert(sprintf($strFieldMustNotBeBlank, "'{$strClosingStatus}'"), E_USER_ERROR);
  281. }
  282. if ($_REQUEST['summary'] == '' && $_REQUEST['solution'] == '')
  283. {
  284. $errors = 1;
  285. $error_string = user_alert(sprintf($strFieldMustNotBeBlank, "'{$strSummary}' / '$strSolution'"), E_USER_ERROR);
  286. }
  287. plugin_do('pre_incident_closing');
  288. if ($errors == 0)
  289. {
  290. $addition_errors = 0;
  291. // update incident
  292. if ($wait == 'yes')
  293. {
  294. // mark incident as awaiting closure
  295. $sql = "SELECT params FROM `{$dbScheduler}` WHERE action = 'CloseIncidents' LIMIT 1";
  296. $result = mysql_query($sql);
  297. if (mysql_error())
  298. {
  299. trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
  300. $closure_delay = 554400;
  301. }
  302. else
  303. {
  304. list($closure_delay) = mysql_fetch_row($result);
  305. }
  306. $timeofnextaction = $now + $closure_delay;
  307. $sql = "UPDATE `{$dbIncidents}` SET status='7', lastupdated='{$now}', timeofnextaction='{$timeofnextaction}' WHERE id='{$id}'";
  308. $result = mysql_query($sql);
  309. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  310. }
  311. else
  312. {
  313. $bill = close_billable_incident($id);
  314. if (!$bill)
  315. {
  316. $addition_errors = 1;
  317. $addition_errors_string .= "<p class='error'>{$strBilling}: {$strAdditionFail}</p>\n";
  318. }
  319. else
  320. {
  321. // mark incident as closed
  322. $sql = "UPDATE `{$dbIncidents}` SET status='2', closingstatus='{$closingstatus}', lastupdated='{$now}', closed='{$now}' WHERE id='{$id}'";
  323. $result = mysql_query($sql);
  324. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  325. }
  326. }
  327. if (!$result)
  328. {
  329. $addition_errors = 1;
  330. $addition_errors_string .= "<p class='error'>{$strIncident}: {$strUpdateFailed}</p>\n";
  331. }
  332. // add update(s)
  333. if ($addition_errors == 0)
  334. {
  335. $sql = "SELECT owner, status ";
  336. $sql .= "FROM `{$dbIncidents}` WHERE id = {$id}";
  337. $result = mysql_query($sql);
  338. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  339. $currentowner = $sit[2];
  340. $currentstatus = 1;
  341. if (mysql_num_rows($result) > 0)
  342. {
  343. list($currentowner, $currentstatus) = mysql_fetch_row($result);
  344. }
  345. if (strlen($_REQUEST['summary']) > 3)
  346. {
  347. // Problem Definition
  348. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, currentowner, currentstatus, bodytext, timestamp, customervisibility) ";
  349. $sql .= "VALUES ('$id', '$sit[2]', 'probdef', '{$currentowner}', '{$currentstatus}', '$summary', '$now', 'hide')";
  350. $result = mysql_query($sql);
  351. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  352. }
  353. if (strlen($_REQUEST['solution']) > 3)
  354. {
  355. // Final Solution
  356. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, currentowner, currentstatus, bodytext, timestamp, customervisibility) ";
  357. $sql .= "VALUES ('$id', '$sit[2]', 'solution', '{$currentowner}', '{$currentstatus}', '$solution', '$now', 'hide')";
  358. $result = mysql_query($sql);
  359. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  360. }
  361. // Meet service level 'solution'
  362. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) ";
  363. // $sql .= "VALUES ('$id', '{$sit[2]}', '{$now}', '{$currentstatus}', 'slamet', '$now', '{$sit[2]}', 'show', 'solution')";
  364. $sql .= "VALUES ('{$id}', '{$sit[2]}', 'slamet', '{$now}', '{$currentowner}', '{$currentstatus}', 'show', 'solution', '')";
  365. $result = mysql_query($sql);
  366. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  367. //
  368. if ($wait == 'yes')
  369. {
  370. // Update - mark for closure
  371. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, currentowner, currentstatus, bodytext, timestamp) ";
  372. $sql .= "VALUES ('$id', '{$sit[2]}', 'closing', '{$currentowner}', '{$currentstatus}', '{$_SESSION['syslang']['strMarkedforclosure']}', '$now')";
  373. $result = mysql_query($sql);
  374. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  375. }
  376. else
  377. {
  378. // Update - close immediately
  379. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, currentowner, currentstatus, bodytext, timestamp) ";
  380. $sql .= "VALUES ('$id', '{$sit[2]}', 'closing', '{$currentowner}', '{$currentstatus}', '{$_SESSION['syslang']['strIncidentClosed']}', '$now')";
  381. $result = mysql_query($sql);
  382. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  383. }
  384. if (!$result)
  385. {
  386. $addition_errors = 1;
  387. $addition_errors_string .= "<p class='error'>{$strUpdateIncidentFailed}</p>\n";
  388. }
  389. //notify related inicdents this has been closed
  390. $sql = "SELECT distinct (relatedid) AS relateid FROM `{$dbRelatedIncidents}` AS r, `{$dbIncidents}` AS i WHERE incidentid = '$id' ";
  391. $sql .= "AND i.id = r.relatedid AND i.status != ".STATUS_CLOSED." AND i.status != ".STATUS_CLOSING;
  392. $result = mysql_query($sql);
  393. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
  394. $relatedincidents;
  395. while ($a = mysql_fetch_object($result))
  396. {
  397. $relatedincidents[] = $a->relateid;
  398. }
  399. $sql = "SELECT distinct (incidentid) AS relateid FROM `{$dbRelatedIncidents}` AS r, `{$dbIncidents}` AS i WHERE relatedid = '$id' ";
  400. $sql .= "AND i.id = r.incidentid AND i.status != ".STATUS_CLOSED." AND i.status != ".STATUS_CLOSING;
  401. $result = mysql_query($sql);
  402. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
  403. while ($a = mysql_fetch_object($result))
  404. {
  405. $relatedincidents[] = $a->relateid;
  406. }
  407. if (is_array($relatedincidents))
  408. {
  409. $uniquearray = array_unique($relatedincidents);
  410. foreach ($uniquearray AS $relatedid)
  411. {
  412. //dont care if I'm related to myself
  413. if ($relatedid != $id)
  414. {
  415. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, currentowner,currentstatus, bodytext, timestamp) ";
  416. $sql .= "VALUES ('$relatedid', '{$sit[2]}', 'research', '{$currentowner}', '{$currentstatus}', 'New Status: [b]Active[/b]<hr>\nRelated incident [$id] has been closed', '$now')";
  417. $result = mysql_query($sql);
  418. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  419. $sql = "UPDATE `{$dbIncidents}` SET status = ".STATUS_ACTIVE.", lastupdated = '{$now}', timeofnextaction = '0' ";
  420. $sql .= "WHERE id = '{$relatedid}' ";
  421. $result = mysql_query($sql);
  422. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  423. }
  424. }
  425. }
  426. //tidy up temp reassigns
  427. $sql = "DELETE FROM `{$dbTempAssigns}` WHERE incidentid = '$id'";
  428. $result = mysql_query($sql);
  429. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  430. }
  431. $bodytext = "{$SYSLANG['strClosingStatus']}: <b>" . closingstatus_name($closingstatus) . "</b>\n\n" . $bodytext;
  432. if ($addition_errors == 0)
  433. { //maintenceid
  434. $send_feedback = send_feedback(db_read_column('maintenanceid', $dbIncidents, $id));
  435. if ($CONFIG['feedback_form'] != '' AND $CONFIG['feedback_form'] > 0 AND $send_feedback == TRUE)
  436. {
  437. create_incident_feedback($CONFIG['feedback_form'], $id);
  438. }
  439. $notifyexternal = $notifycontact = $awaitingclosure = 0;
  440. if ($send_engineer_email == 'yes')
  441. {
  442. $notifyexternal = 1;
  443. }
  444. if ($send_email == 'yes')
  445. {
  446. $notifycontact = 1;
  447. if ($wait=='yes')
  448. {
  449. $awaitingclosure = 1;
  450. }
  451. else
  452. {
  453. $awaitingclosure = 0;
  454. }
  455. }
  456. trigger('TRIGGER_INCIDENT_CLOSED', array('incidentid' => $incidentid,
  457. 'userid' => $sit[2],
  458. 'notifyexternal' => $notifyexternal,
  459. 'notifycontact' => $notifycontact,
  460. 'awaitingclosure' => $awaitingclosure
  461. ));
  462. // Tidy up drafts i.e. delete
  463. $draft_sql = "DELETE FROM `{$dbDrafts}` WHERE incidentid = {$id}";
  464. mysql_query($draft_sql);
  465. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  466. // Check for knowledge base stuff, prior to confirming:
  467. if ($_REQUEST['kbarticle'] == 'yes')
  468. {
  469. $sql = "INSERT INTO `{$dbKBArticles}` (doctype, title, distribution, author, published, keywords) VALUES ";
  470. $sql .= "('1', ";
  471. $sql .= "'{$kbtitle}', ";
  472. $sql .= "'{$distribution}', ";
  473. $sql .= "'".mysql_real_escape_string($sit[2])."', ";
  474. $sql .= "'".date('Y-m-d H:i:s', mktime(date('H'),date('i'),date('s'),date('m'),date('d'),date('Y')))."', ";
  475. $sql .= "'[$id]') ";
  476. mysql_query($sql);
  477. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  478. $docid = mysql_insert_id();
  479. // Update the incident to say that a KB article was created, with the KB Article number
  480. $update = "<b>{$_SESSION['syslang']['strKnowledgeBaseArticleCreated']}: {$CONFIG['kb_id_prefix']}".leading_zero(4,$docid);
  481. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, bodytext, timestamp) ";
  482. $sql .= "VALUES ('$id', '$sit[2]', 'default', '$update', '$now')";
  483. $result = mysql_query($sql);
  484. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  485. // Get softwareid from Incident record
  486. $sql = "SELECT softwareid FROM `{$dbIncidents}` WHERE id='$id'";
  487. $result=mysql_query($sql);
  488. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  489. list($softwareid)=mysql_fetch_row($result);
  490. if (!empty($_POST['summary'])) $query[] = "INSERT INTO `{$dbKBContent}` (docid, ownerid, headerstyle, header, contenttype, content, distribution) VALUES ('$docid', '".mysql_real_escape_string($sit[2])."', 'h1', 'Summary', '1', '{$summary}', 'public') ";
  491. if (!empty($_POST['symptoms'])) $query[] = "INSERT INTO `{$dbKBContent}` (docid, ownerid, headerstyle, header, contenttype, content, distribution) VALUES ('$docid', '".mysql_real_escape_string($sit[2])."', 'h1', 'Symptoms', '1', '{$symptoms}', 'public') ";
  492. if (!empty($_POST['cause'])) $query[] = "INSERT INTO `{$dbKBContent}` (docid, ownerid, headerstyle, header, contenttype, content, distribution) VALUES ('$docid', '".mysql_real_escape_string($sit[2])."', 'h1', 'Cause', '1', '{$cause}', 'public') ";
  493. if (!empty($_POST['question'])) $query[] = "INSERT INTO `{$dbKBContent}` (docid, ownerid, headerstyle, header, contenttype, content, distribution) VALUES ('$docid', '".mysql_real_escape_string($sit[2])."', 'h1', 'Question', '1', '{$question}', 'public') ";
  494. if (!empty($_POST['answer'])) $query[] = "INSERT INTO `{$dbKBContent}` (docid, ownerid, headerstyle, header, contenttype, content, distribution) VALUES ('$docid', '".mysql_real_escape_string($sit[2])."', 'h1', 'Answer', '1', '{$answer}', 'public') ";
  495. if (!empty($_POST['solution'])) $query[] = "INSERT INTO `{$dbKBContent}` (docid, ownerid, headerstyle, header, contenttype, content, distribution) VALUES ('$docid', '".mysql_real_escape_string($sit[2])."', 'h1', 'Solution', '1', '{$solution}', 'public') ";
  496. if (!empty($_POST['workaround'])) $query[] = "INSERT INTO `{$dbKBContent}` (docid, ownerid, headerstyle, header, contenttype, content, distribution) VALUES ('$docid', '".mysql_real_escape_string($sit[2])."', 'h1', 'Workaround', '1', '{$workaround}', 'public') ";
  497. if (!empty($_POST['status'])) $query[] = "INSERT INTO `{$dbKBContent}` (docid, ownerid, headerstyle, header, contenttype, content, distribution) VALUES ('$docid', '".mysql_real_escape_string($sit[2])."', 'h1', 'Status', '1', '{$status}', 'public') ";
  498. if (!empty($_POST['additional'])) $query[] = "INSERT INTO `{$dbKBContent}` (docid, ownerid, headerstyle, header, contenttype, content, distribution) VALUES ('$docid', '".mysql_real_escape_string($sit[2])."', 'h1', 'Additional Information', '1', '{$additional}', 'public') ";
  499. if (!empty($_POST['references'])) $query[] = "INSERT INTO `{$dbKBContent}` (docid, ownerid, headerstyle, header, contenttype, content, distribution) VALUES ('$docid', '".mysql_real_escape_string($sit[2])."', 'h1', 'References', '1', '{$references}', 'public') ";
  500. if (count($query) < 1) $query[] = "INSERT INTO `{$dbKBContent}` (docid, ownerid, headerstyle, header, contenttype, content, distribution) VALUES ('$docid', '".mysql_real_escape_string($sit[2])."', 'h1', 'Summary', '1', 'Enter details here...', 'restricted') ";
  501. foreach ($query AS $sql)
  502. {
  503. mysql_query($sql);
  504. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  505. }
  506. // Add Software Record
  507. if ($softwareid > 0)
  508. {
  509. $sql = "INSERT INTO `{$dbKBSoftware}` (docid,softwareid) VALUES ('{$docid}', '{$softwareid}')";
  510. mysql_query($sql);
  511. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  512. journal(CFG_LOGGING_NORMAL, 'KB Article Added', "KB Article {$docid} was added", CFG_JOURNAL_KB, $docid);
  513. }
  514. //html_redirect("incident_details.php?id={$id}", TRUE, "Knowledge Base Article {$CONFIG['kb_id_prefix']}{$docid} created");
  515. plugin_do('incident_closing');
  516. echo "<html>";
  517. echo "<head></head>";
  518. echo "<body onload=\"close_page_redirect('incident_details.php?id={$id}');\">";
  519. echo "</body>";
  520. echo "</html>";
  521. }
  522. else
  523. {
  524. plugin_do('incident_closing');
  525. echo "<html>";
  526. echo "<head></head>";
  527. echo "<body onload=\"close_page_redirect('incident_details.php?id={$id}');\">";
  528. echo "</body>";
  529. echo "</html>";
  530. }
  531. }
  532. else
  533. {
  534. include (APPLICATION_INCPATH . 'incident_html_top.inc.php');
  535. echo $addition_errors_string;
  536. include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
  537. }
  538. }
  539. else
  540. {
  541. include (APPLICATION_INCPATH . 'incident_html_top.inc.php');
  542. echo $error_string;
  543. include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
  544. }
  545. }
  546. ?>