PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/incident_email.php

https://github.com/paulheaney/sitracker
PHP | 908 lines | 748 code | 95 blank | 65 comment | 122 complexity | df7252923a9bfa57e7b631e3c44d169f MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0, BSD-3-Clause, GPL-2.0
  1. <?php
  2. // incident_email.php
  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 = 33; // Send Emails
  11. require ('core.php');
  12. require (APPLICATION_LIBPATH . 'functions.inc.php');
  13. // include ('mime.inc.php');
  14. // This page requires authentication
  15. require (APPLICATION_LIBPATH . 'auth.inc.php');
  16. // External variables
  17. $step = cleanvar($_REQUEST['step']);
  18. $id = cleanvar($_REQUEST['id']);
  19. $menu = cleanvar($_REQUEST['menu']);
  20. $incidentid = $id;
  21. $draftid = cleanvar($_REQUEST['draftid']);
  22. if (empty($draftid)) $draftid = -1;
  23. $title = $strEmail;
  24. if (empty($step))
  25. {
  26. $action = $_REQUEST['action'];
  27. if ($action == "deletedraft")
  28. {
  29. if ($draftid != -1)
  30. {
  31. $sql = "DELETE FROM `{$dbDrafts}` WHERE id = {$draftid}";
  32. $result = mysql_query($sql);
  33. if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR);
  34. }
  35. html_redirect("incident_email.php?id={$id}");
  36. exit;
  37. }
  38. $sql = "SELECT * FROM `{$dbDrafts}` WHERE type = 'email' AND userid = '{$sit[2]}' AND incidentid = '{$id}'";
  39. $result = mysql_query($sql);
  40. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  41. if (mysql_num_rows($result) > 0)
  42. {
  43. include (APPLICATION_INCPATH . 'incident_html_top.inc.php');
  44. echo "<h2>{$title}</h2>";
  45. echo display_drafts('email', $result);
  46. echo "<p align='center'><a href='".$_SERVER['PHP_SELF']."?step=1&amp;id={$id}'>{$strNewEmail}</a></p>";
  47. include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
  48. exit;
  49. }
  50. else
  51. {
  52. $step = 1;
  53. }
  54. }
  55. switch ($step)
  56. {
  57. case 1:
  58. // show form 1
  59. include (APPLICATION_INCPATH . 'incident_html_top.inc.php');
  60. ?>
  61. <script type="text/javascript">
  62. //<![CDATA[
  63. function deleteOption(object)
  64. {
  65. var Current = object.updatetype.selectedIndex;
  66. object.updatetype.options[Current] = null;
  67. }
  68. function notarget(object)
  69. {
  70. // remove last option
  71. var length = object.updatetype.length;
  72. if (length > 6)
  73. {
  74. object.updatetype.selectedIndex=6;
  75. var Current = object.updatetype.selectedIndex;
  76. object.updatetype.options[Current] = null;
  77. }
  78. object.priority.value=object.storepriority.value;
  79. object.priority.disabled=true;
  80. object.updatetype.selectedIndex=0;
  81. object.updatetype.disabled=false;
  82. }
  83. function initialresponse(object)
  84. {
  85. // remove last option
  86. var length = object.updatetype.length;
  87. if (length > 6)
  88. {
  89. object.updatetype.selectedIndex=6;
  90. var Current = object.updatetype.selectedIndex;
  91. object.updatetype.options[Current] = null;
  92. }
  93. object.priority.value=object.storepriority.value;
  94. object.priority.disabled=true;
  95. object.updatetype.selectedIndex=0;
  96. object.updatetype.disabled=false;
  97. }
  98. function actionplan(object)
  99. {
  100. // remove last option
  101. var length = object.updatetype.length;
  102. if (length > 6)
  103. {
  104. object.updatetype.selectedIndex=6;
  105. var Current = object.updatetype.selectedIndex;
  106. object.updatetype.options[Current] = null;
  107. }
  108. var defaultSelected = true;
  109. var selected = true;
  110. var optionName = new Option('Action Plan', 'actionplan', defaultSelected, selected);
  111. var length = object.updatetype.length;
  112. object.updatetype.options[length] = optionName;
  113. object.priority.value=object.storepriority.value;
  114. object.priority.disabled=true;
  115. object.updatetype.disabled=true;
  116. }
  117. function reprioritise(object)
  118. {
  119. // remove last option
  120. var length = object.updatetype.length;
  121. if (length > 6)
  122. {
  123. object.updatetype.selectedIndex=6;
  124. var Current = object.updatetype.selectedIndex;
  125. object.updatetype.options[Current] = null;
  126. }
  127. // add new option
  128. var defaultSelected = true;
  129. var selected = true;
  130. var optionName = new Option('Reprioritise', 'solution', defaultSelected, selected);
  131. var length = object.updatetype.length;
  132. object.updatetype.options[length] = optionName;
  133. object.priority.disabled=false;
  134. object.updatetype.disabled=true;
  135. }
  136. function probdef(object)
  137. {
  138. // remove last option
  139. var length = object.updatetype.length;
  140. if (length > 6)
  141. {
  142. object.updatetype.selectedIndex=6;
  143. var Current = object.updatetype.selectedIndex;
  144. object.updatetype.options[Current] = null;
  145. }
  146. var defaultSelected = true;
  147. var selected = true;
  148. var optionName = new Option('Problem Definition', 'probdef', defaultSelected, selected);
  149. var length = object.updatetype.length;
  150. object.updatetype.options[length] = optionName;
  151. object.priority.value=object.storepriority.value;
  152. object.priority.disabled=true;
  153. object.updatetype.disabled=true;
  154. }
  155. function replaceOption(object)
  156. {
  157. var Current = object.updatetype.selectedIndex;
  158. object.updatetype.options[Current].text = object.currentText.value;
  159. object.updatetype.options[Current].value = object.currentText.value;
  160. }
  161. //]]>
  162. </script>
  163. <?php
  164. echo "<h2>".icon('email', 32)." {$strSendEmail}</h2>";
  165. echo "<form action='{$_SERVER['PHP_SELF']}?id={$id}' name='updateform' method='post'>";
  166. echo "<table align='center' class='vertical'>";
  167. echo "<tr><th>{$strTemplate}</th><td>".emailtemplate_drop_down("emailtype", 1, 'incident')."</td></tr>";
  168. echo "<tr><th>{$strDoesThisUpdateMeetSLA}:</th><td>";
  169. $target = incident_get_next_target($id);
  170. echo "<select name='target' class='dropdown'>\n";
  171. echo "<option value='none' onclick='notarget(this.form)'>{$strNo}</option>\n";
  172. switch ($target->type)
  173. {
  174. //FIXME can this be put into the style sheets?
  175. case 'initialresponse':
  176. echo "<option value='initialresponse' style='text-indent: 15px;";
  177. echo " height: 17px; background-image: ";
  178. echo "url({$CONFIG['application_webpath']}/images/icons/";
  179. echo "{$iconset}/16x16/initialresponse.png); background-repeat:";
  180. echo " no-repeat;' onclick='initialresponse(this.form)' >";
  181. echo "{$strInitialResponse}</option>\n";
  182. echo "<option value='probdef' style='text-indent: 15px; height:";
  183. echo " 17px; background-image: ";
  184. echo "url({$CONFIG['application_webpath']}/images/icons/";
  185. echo "{$iconset}/16x16/probdef.png); background-repeat: ";
  186. echo "no-repeat;' onclick='probdef(this.form)'>";
  187. echo "{$strProblemDefinition}</option>\n";
  188. echo "<option value='actionplan' style='text-indent: 15px; ";
  189. echo "height: 17px; background-image: ";
  190. echo "url({$CONFIG['application_webpath']}/images/icons/";
  191. echo "{$iconset}/16x16/actionplan.png); background-repeat: ";
  192. echo "no-repeat;' onclick='actionplan(this.form)'>";
  193. echo "{$strActionPlan}</option>\n";
  194. echo "<option value='solution' style='text-indent: 15px; ";
  195. echo "height: 17px; background-image: ";
  196. echo "url({$CONFIG['application_webpath']}/images/icons/";
  197. echo "{$iconset}/16x16/solution.png); background-repeat: ";
  198. echo "no-repeat;' onclick='reprioritise(this.form)'>";
  199. echo "{$strResolutionReprioritisation}</option>\n";
  200. break;
  201. case 'probdef':
  202. echo "<option value='probdef' style='text-indent: 15px; height:";
  203. echo " 17px; background-image: ";
  204. echo "url({$CONFIG['application_webpath']}/images/icons/";
  205. echo "{$iconset}/16x16/probdef.png); background-repeat: ";
  206. echo "no-repeat;' onclick='probdef(this.form)'>";
  207. echo "{$strProblemDefinition}</option>\n";
  208. echo "<option value='actionplan' style='text-indent: 15px; ";
  209. echo "height: 17px; background-image: ";
  210. echo "url({$CONFIG['application_webpath']}/images/icons/";
  211. echo "{$iconset}/16x16/actionplan.png); background-repeat: ";
  212. echo "no-repeat;' onclick='actionplan(this.form)'>";
  213. echo "{$strActionPlan}</option>\n";
  214. echo "<option value='solution' style='text-indent: 15px; ";
  215. echo "height: 17px; background-image: ";
  216. echo "url({$CONFIG['application_webpath']}/images/icons/";
  217. echo "{$iconset}/16x16/solution.png); background-repeat: ";
  218. echo "no-repeat;' onclick='reprioritise(this.form)'>";
  219. echo "{$strResolutionReprioritisation}</option>\n";
  220. break;
  221. case 'actionplan':
  222. echo "<option value='actionplan' style='text-indent: 15px; ";
  223. echo "height: 17px; background-image: ";
  224. echo "url({$CONFIG['application_webpath']}/images/icons/";
  225. echo "{$iconset}/16x16/actionplan.png); background-repeat: ";
  226. echo "no-repeat;' onclick='actionplan(this.form)'>";
  227. echo "{$strActionPlan}</option>\n";
  228. echo "<option value='solution' style='text-indent: 15px; ";
  229. echo "height: 17px; background-image: ";
  230. echo "url({$CONFIG['application_webpath']}/images/icons/";
  231. echo "{$iconset}/16x16/solution.png); background-repeat: ";
  232. echo "no-repeat;' onclick='reprioritise(this.form)'>";
  233. echo "{$strResolutionReprioritisation}</option>\n";
  234. break;
  235. case 'solution':
  236. echo "<option value='solution' style='text-indent: 15px; ";
  237. echo "height: 17px; background-image: ";
  238. echo "url({$CONFIG['application_webpath']}/images/icons/";
  239. echo "{$iconset}/16x16/solution.png); background-repeat: ";
  240. echo "no-repeat;' onclick='reprioritise(this.form)'>";
  241. echo "{$strResolutionReprioritisation}</option>\n";
  242. break;
  243. }
  244. echo "</select>\n</td></tr>";
  245. if ($CONFIG['auto_chase'] == TRUE)
  246. {
  247. $sql = "SELECT * FROM `{$dbUpdates}` WHERE incidentid = {$id} ";
  248. $sql .= "ORDER BY timestamp DESC LIMIT 1";
  249. $result = mysql_query($sql);
  250. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
  251. $obj = mysql_fetch_object($result);
  252. if ($obj->type == 'auto_chase_phone')
  253. {
  254. echo "<tr><th>{$strCustomerChaseUpdate}</th><td>";
  255. echo "<label><input type='radio' name='chase_customer' ";
  256. echo "value='no' checked='yes' />{$strNo}</label> ";
  257. echo "<label><input type='radio' name='chase_customer' ";
  258. echo "value='yes' />{$strYes}</label>";
  259. echo "</td></tr>";
  260. }
  261. if ($obj->type == 'auto_chase_manager')
  262. {
  263. echo "<tr><th>{$strManagerChaseUpdate}</th>";
  264. echo "<label><input type='radio' name='chase_manager' ";
  265. echo "value='no' checked='yes' />{$strNo}</label> ";
  266. echo "<label><input type='radio' name='chase_manager' ";
  267. echo "value='yes' />{$strYes}</label>";
  268. echo "</td></tr>";
  269. }
  270. }
  271. echo "<tr><th>{$strNewIncidentStatus}:</th><td>";
  272. echo incidentstatus_drop_down("newincidentstatus", incident_status($id));
  273. echo "</td></tr>\n";
  274. echo "<tr><th>{$strTimeToNextAction}:</th>";
  275. echo "<td>";
  276. echo show_next_action('updateform');
  277. echo "</td>";
  278. echo "<br />";
  279. echo "</td></tr>";
  280. plugin_do('incident_email_form1');
  281. echo "</table>";
  282. echo "<p align='center'>";
  283. echo "<input type='hidden' name='step' value='2' />";
  284. echo "<input type='hidden' name='menu' value='$menu' />";
  285. echo "<input name='submit1' type='submit' value='{$strContinue}' /></p>";
  286. echo "</form>\n";
  287. include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
  288. break;
  289. case 2:
  290. // show form 2
  291. if ($draftid != -1)
  292. {
  293. $draftsql = "SELECT * FROM `{$dbDrafts}` WHERE id = {$draftid}";
  294. $draftresult = mysql_query($draftsql);
  295. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  296. $draftobj = mysql_fetch_object($draftresult);
  297. $metadata = explode("|",$draftobj->meta);
  298. }
  299. include (APPLICATION_INCPATH . 'incident_html_top.inc.php');
  300. ?>
  301. <script type='text/javascript'>
  302. //<![CDATA[
  303. function confirm_send_mail()
  304. {
  305. return window.confirm('<?php echo $strAreYouSureSendEmail ?>');
  306. }
  307. function urlencode(str) {
  308. str = escape(str);
  309. str = str.replace('+', '%2B');
  310. str = str.replace('%20', '+');
  311. str = str.replace('*', '%2A');
  312. str = str.replace('/', '%2F');
  313. str = str.replace('@', '%40');
  314. return str;
  315. }
  316. <?php
  317. echo "var draftid = {$draftid};";
  318. ?>
  319. // Auto save
  320. function save_content(){
  321. var xmlhttp=false;
  322. if (!xmlhttp && typeof XMLHttpRequest!='undefined')
  323. {
  324. try
  325. {
  326. xmlhttp = new XMLHttpRequest();
  327. }
  328. catch (e)
  329. {
  330. xmlhttp=false;
  331. }
  332. }
  333. if (!xmlhttp && window.createRequest)
  334. {
  335. try
  336. {
  337. xmlhttp = window.createRequest();
  338. }
  339. catch (e)
  340. {
  341. xmlhttp=false;
  342. }
  343. }
  344. var toPass = $('bodytext').value;
  345. //alert(toPass.value);
  346. /*
  347. Format of meta data
  348. $emailtype|$newincidentstatus|$timetonextaction_none|$timetonextaction_days|$timetonextaction_hours|$timetonextaction_minutes|$day|$month|$year|$target|$chase_customer|$chase_manager|$from|$replyTo|$ccemail|$bccemail|$toemail|$subject|$body
  349. */
  350. var meta = $('emailtype').value+"|"+$('newincidentstatus').value+"|"+$('timetonextaction_none').value+"|";
  351. meta = meta+$('timetonextaction_days').value+"|"+$('timetonextaction_hours').value+"|";
  352. meta = meta+$('timetonextaction_minutes').value+"||||";
  353. meta = meta+$('target').value+"|"+$('chase_customer').value+"|";
  354. meta = meta+$('chase_manager').value+"|"+$('fromfield').value+"|"+$('replytofield').value+"|";
  355. meta = meta+$('ccfield').value+"|"+$('bccfield').value+"|"+$('tofield').value+"|";
  356. meta = meta+urlencode($('subjectfield').value)+"|"+urlencode($('bodytext').value)+"|"
  357. meta = meta+$('date').value+"|"+$('timeoffset').value;
  358. if (toPass != '')
  359. {
  360. /*
  361. xmlhttp.open("GET", "ajaxdata.php?action=auto_save&userid="+<?php echo $_SESSION['userid']; ?>+
  362. "&type=email&incidentid="+<?php echo $id; ?>+
  363. "&draftid="+draftid+"&meta="+meta+"&content="+
  364. escape(toPass), true);
  365. */
  366. var url = "ajaxdata.php";
  367. var params = "action=auto_save&userid="+<?php echo $_SESSION['userid']; ?>+"&type=email&incidentid="+<?php echo $id; ?>+"&draftid="+draftid+"&meta="+meta+"&content="+escape(toPass);
  368. xmlhttp.open("POST", url, true)
  369. xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  370. xmlhttp.setRequestHeader("Content-length", params.length);
  371. xmlhttp.setRequestHeader("Connection", "close");
  372. xmlhttp.onreadystatechange=function()
  373. {
  374. if (xmlhttp.readyState==4)
  375. {
  376. if (xmlhttp.responseText != '')
  377. {
  378. if (draftid == -1)
  379. {
  380. draftid = xmlhttp.responseText;
  381. }
  382. var currentTime = new Date();
  383. var hours = currentTime.getHours();
  384. var minutes = currentTime.getMinutes();
  385. if (minutes < 10)
  386. {
  387. minutes = "0" + minutes;
  388. }
  389. var seconds = currentTime.getSeconds();
  390. if (seconds < 10)
  391. {
  392. seconds = "0" + seconds;
  393. }
  394. $('updatestr').innerHTML = '<?php echo "<a href=\"javascript:save_content();\">".icon('save', 16, $GLOBALS['strSaveDraft'])."</a> ".icon('info', 16, $GLOBALS['strDraftLastSaved'])." "; ?>' + hours + ':' + minutes + ':' + seconds;
  395. $('draftid').value = draftid;
  396. }
  397. }
  398. }
  399. xmlhttp.send(params);
  400. }
  401. }
  402. setInterval("save_content()", 10000); //every 10 seconds
  403. //]]>
  404. </script>
  405. <?php
  406. // External vars
  407. if ($draftid == -1)
  408. {
  409. $emailtype = cleanvar($_REQUEST['emailtype']);
  410. $newincidentstatus = cleanvar($_REQUEST['newincidentstatus']);
  411. $timetonextaction_none = cleanvar($_REQUEST['timetonextaction_none']);
  412. $timetonextaction_days = cleanvar($_REQUEST['timetonextaction_days']);
  413. $timetonextaction_hours = cleanvar($_REQUEST['timetonextaction_hours']);
  414. $timetonextaction_minutes = cleanvar($_REQUEST['timetonextaction_minutes']);
  415. $day = cleanvar($_REQUEST['day']);
  416. $month = cleanvar($_REQUEST['month']);
  417. $year = cleanvar($_REQUEST['year']);
  418. $target = cleanvar($_REQUEST['target']);
  419. $chase_customer = cleanvar($_REQUEST['chase_customer']);
  420. $chase_manager = cleanvar($_REQUEST['chase_manager']);
  421. $date = cleanvar($_REQUEST['date']);
  422. $timeoffset = cleanvar($_REQUEST['timeoffset']);
  423. }
  424. else
  425. {
  426. $emailtype = $metadata[0];
  427. $newincidentstatus = $metadata[1];
  428. $timetonextaction_none = $metadata[2];
  429. $timetonextaction_days = $metadata[3];
  430. $timetonextaction_hours = $metadata[4];
  431. $timetonextaction_minutes = $metadata[5];
  432. $day = $metadata[6];
  433. $month = $metadata[7];
  434. $year = $metadata[8];
  435. $target = $metadata[9];
  436. $chase_customer = $metadata[10];
  437. $chase_manager = $metadata[11];
  438. $date = $metadata[12];
  439. $timeoffset = $metadata[13];
  440. }
  441. if ($draftid == -1)
  442. {
  443. // Grab the template
  444. $tsql = "SELECT * FROM `{$dbEmailTemplates}` WHERE id=$emailtype LIMIT 1";
  445. $tresult = mysql_query($tsql);
  446. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  447. if (mysql_num_rows($tresult) > 0) $template = mysql_fetch_object($tresult);
  448. $paramarray = array('incidentid' => $id, 'triggeruserid' => $sit[2]);
  449. $from = replace_specials($template->fromfield, $paramarray);
  450. $replyto = replace_specials($template->replytofield, $paramarray);
  451. $ccemail = replace_specials($template->ccfield, $paramarray);
  452. $bccemail = replace_specials($template->bccfield, $paramarray);
  453. $toemail = replace_specials($template->tofield, $paramarray);
  454. $subject = replace_specials($template->subjectfield, $paramarray);
  455. $body = replace_specials($template->body, $paramarray);
  456. }
  457. else
  458. {
  459. $from = $metadata[12];
  460. $replyto = $metadata[13];
  461. $ccemail = $metadata[14];
  462. $bccemail = $metadata[15];
  463. $toemail = $metadata[16];
  464. $subject = $metadata[17];
  465. $body = $metadata[18];
  466. }
  467. echo "<form action='{$_SERVER['PHP_SELF']}?id={$id}' method='post' ";
  468. echo "enctype='multipart/form-data' onsubmit='return confirm_send_mail();' >";
  469. echo "<table align='center' class='vertical' width='95%'>";
  470. echo "<tr><th width='30%'>{$strFrom}</th><td><input maxlength='100' ";
  471. echo "name='fromfield' id='fromfield' size='40' value=\"{$from}\" /></td></tr>\n";
  472. echo "<tr><th>{$strReplyTo}</th><td><input maxlength='100' name='replytofield' ";
  473. echo "id='replytofield' size='40' value=\"{$replyto}\" /></td></tr>\n";
  474. if (trim($ccemail) == ",") $ccemail = '';
  475. if (substr($ccemail, 0, 1) == ",") $ccfield = substr($ccemail, 1, strlen($ccemail));
  476. echo "<tr><th>{$strCC}</th><td><input maxlength='100' name='ccfield' ";
  477. echo "id='ccfield' size='40' value=\"{$ccemail}\" /></td></tr>\n";
  478. echo "<tr><th>{$strBCC}</th><td><input maxlength='100' name='bccfield' ";
  479. echo "id='bccfield' size='40' value=\"{$bccemail}\" /></td></tr>\n";
  480. echo "<tr><th>{$strTo}</th><td><input maxlength='100' name='tofield' ";
  481. echo "id='tofield' size='40' value=\"{$toemail}\" /></td></tr>\n";
  482. echo "<tr><th>{$strSubject}</th><td><input maxlength='255' ";
  483. echo "name='subjectfield' id='subjectfield' size='40' value=\"{$subject}\" /></td></tr>\n";
  484. echo "<tr><th>{$strAttachment}";
  485. $file_size = readable_file_size($CONFIG['upload_max_filesize']);
  486. echo "(&lt; $file_size)";
  487. echo "</th><td>";
  488. echo "<input type='hidden' name='MAX_FILE_SIZE' value='{$CONFIG['upload_max_filesize']}' />";
  489. echo "<input type='file' name='attachment' size='40' maxfilesize='{$CONFIG['upload_max_filesize']}' />";
  490. echo "</td></tr>";
  491. echo "<tr><th>{$strMessage}</th><td>";
  492. echo "<textarea name='bodytext' id='bodytext' rows='20' cols='65'>";
  493. echo $body;
  494. echo "</textarea>";
  495. echo "<div id='updatestr'><a href='javascript:save_content();'>".icon('save', 16, $strSaveDraft)."</a></div>";
  496. echo "</td></tr>";
  497. plugin_do('incident_email_form2');
  498. echo "</table>";
  499. echo "<p align='center'>";
  500. echo "<input name='newincidentstatus' id='newincidentstatus' type='hidden' value='{$newincidentstatus}' />";
  501. echo "<input name='timetonextaction_none' id='timetonextaction_none' type='hidden' value='{$timetonextaction_none}' />";
  502. echo "<input name='timetonextaction_days' id='timetonextaction_days' type='hidden' value='{$timetonextaction_days}' />";
  503. echo "<input name='timetonextaction_hours' id='timetonextaction_hours' type='hidden' value='{$timetonextaction_hours}' />";
  504. echo "<input name='timetonextaction_minutes' id='timetonextaction_minutes' type='hidden' value='{$timetonextaction_minutes}' />";
  505. echo "<input name='chase_customer' id='chase_customer' type='hidden' value='{$chase_customer}' />";
  506. echo "<input name='chase_manager' id='chase_manager' type='hidden' value='{$chase_manager}' />";
  507. echo "<input name='date' id='date' type='hidden' value='{$date}' />";
  508. echo "<input name='timeoffset' id='timeoffset' type='hidden' value='{$timeoffset}' />";
  509. echo "<input name='target' id='target' type='hidden' value='{$target}' />";
  510. echo "<input type='hidden' id='step' name='step' value='3' />";
  511. echo "<input type='hidden' id='emailtype' name='emailtype' value='{$emailtype}' />";
  512. echo "<input type='hidden' id='draftid' name='draftid' value='{$draftid}' />";
  513. echo "<input name='submit2' type='submit' value='{$strSendEmail}' />";
  514. echo "</p>\n</form>\n";
  515. include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
  516. break;
  517. case 3:
  518. // show form 3 or send email and update incident
  519. // External variables
  520. $bodytext = $_REQUEST['bodytext'];
  521. $tofield = cleanvar($_REQUEST['tofield']);
  522. $fromfield = cleanvar($_REQUEST['fromfield']);
  523. $replytofield = cleanvar($_REQUEST['replytofield']);
  524. $ccfield = cleanvar($_REQUEST['ccfield']);
  525. $bccfield = cleanvar($_REQUEST['bccfield']);
  526. $subjectfield = cleanvar($_REQUEST['subjectfield'], FALSE, TRUE, FALSE);
  527. $emailtype = cleanvar($_REQUEST['emailtype']);
  528. $newincidentstatus = cleanvar($_REQUEST['newincidentstatus']);
  529. $timetonextaction_none = cleanvar($_REQUEST['timetonextaction_none']);
  530. $timetonextaction_days = cleanvar($_REQUEST['timetonextaction_days']);
  531. $timetonextaction_hours = cleanvar($_REQUEST['timetonextaction_hours']);
  532. $timetonextaction_minutes = cleanvar($_REQUEST['timetonextaction_minutes']);
  533. $date = cleanvar($_REQUEST['date']);
  534. $timeoffset = cleanvar($_REQUEST['timeoffset']);
  535. $year = cleanvar($_REQUEST['year']);
  536. $target = cleanvar($_REQUEST['target']);
  537. $chase_customer = cleanvar($_REQUEST['chase_customer']);
  538. $chase_manager = cleanvar($_REQUEST['chase_manager']);
  539. // move attachment to a safe place for processing later
  540. if ($_FILES['attachment']['name'] != '') // Should be using this format throughout TPG 13/08/2002
  541. {
  542. $umask = umask(0000);
  543. $mk = TRUE;
  544. if (!file_exists($CONFIG['attachment_fspath'].$id))
  545. {
  546. $mk = mkdir($CONFIG['attachment_fspath'].$id, 0770, TRUE);
  547. if (!$mk)
  548. {
  549. trigger_error('Failed creating incident attachment directory: '.$CONFIG['attachment_fspath'].$id, E_USER_WARNING);
  550. }
  551. }
  552. $name = $_FILES['attachment']['name'];
  553. $size = filesize($_FILES['attachment']['tmp_name']);
  554. $sql = "INSERT INTO `{$dbFiles}`(filename, size, userid, usertype) ";
  555. $sql .= "VALUES('{$name}', '{$size}', '{$sit[2]}', '1')";
  556. mysql_query($sql);
  557. if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
  558. $fileid = mysql_insert_id();
  559. $filename = $CONFIG['attachment_fspath'].$id.$fsdelim.$fileid."-".$name;
  560. $mv = rename($_FILES['attachment']['tmp_name'], $filename);
  561. if (!mv) trigger_error("Problem moving attachment from temp directory: {$filename}", E_USER_WARNING);
  562. $attachmenttype = $_FILES['attachment']['type'];
  563. }
  564. $errors = 0;
  565. // check to field
  566. if ($tofield == '')
  567. {
  568. $errors = 1;
  569. $error_string .= "<p class='error'>".sprintf($strFieldMustNotBeBlank, $strTo)."</p>\n";
  570. }
  571. // check from field
  572. if ($fromfield == '')
  573. {
  574. $errors = 1;
  575. $error_string .= "<p class='error'>".sprintf($strFieldMustNotBeBlank, $strFrom)."</p>\n";
  576. }
  577. // check reply to field
  578. if ($replytofield == '')
  579. {
  580. $errors = 1;
  581. $error_string .= "<p class='error'>".sprintf($strFieldMustNotBeBlank, $strReplyTo)."</p>\n";
  582. }
  583. // Store email body in session if theres been an error
  584. if ($errors > 0) $_SESSION['temp-emailbody'] = $bodytext;
  585. else unset($_SESSION['temp-emailbody']);
  586. // send email if no errors
  587. if ($errors == 0)
  588. {
  589. $extra_headers = "Reply-To: $replytofield\nErrors-To: ".user_email($sit[2])."\n";
  590. $extra_headers .= "X-Mailer: {$CONFIG['application_shortname']} {$application_version_string}/PHP " . phpversion() . "\n";
  591. $extra_headers .= "X-Originating-IP: {$_SERVER['REMOTE_ADDR']}\n";
  592. if ($ccfield != '') $extra_headers .= "CC: $ccfield\n";
  593. if ($bccfield != '') $extra_headers .= "BCC: $bccfield\n";
  594. $extra_headers .= "\n"; // add an extra crlf to create a null line to separate headers from body
  595. // this appears to be required by some email clients - INL
  596. $mime = new MIME_mail($fromfield, $tofield, html_entity_decode($subjectfield), '', $extra_headers, $mailerror);
  597. // INL 5 Aug 09, quoted-printable seems to split lines in unexpected places, base64 seems to work ok
  598. $mime -> attach($bodytext, 'bodytext', "text/plain; charset={$GLOBALS['i18ncharset']}", 'quoted-printable', 'inline');
  599. // check for attachment
  600. // if ($_FILES['attachment']['name']!='' || strlen($filename) > 3)
  601. if ($filename != '' && strlen($filename) > 3)
  602. {
  603. // if (!isset($filename)) $filename = $attachment_fspath.$_FILES['attachment']['name']; ??? TPG 13/08/2002
  604. if (!file_exists($filename)) trigger_error("File did not exist upon processing attachment: {$filename}", E_USER_WARNING);
  605. if ($filename == '') trigger_error("Filename was blank upon processing attachment: {$filename}", E_USER_WARNING);
  606. // Check file size before sending
  607. if (filesize($filename) > $CONFIG['upload_max_filesize'] || filesize($filename)==FALSE)
  608. {
  609. trigger_error("User Error: Attachment too large or file upload error, filename: $filename, perms: ".fileperms($filename).", size:",filesize($filename), E_USER_WARNING);
  610. // throwing an error isn't the nicest thing to do for the user but there seems to be no way of
  611. // checking file sizes at the client end before the attachment is uploaded. - INL
  612. }
  613. if (preg_match("!/x\-.+!i", $attachmenttype)) $type = OCTET;
  614. else $type = str_replace("\n","",$attachmenttype);
  615. $disp = "attachment; filename=\"$name\"; name=\"$name\";";
  616. $mime -> fattach($filename, "Attachment for incident $id", $type, 'base64', $disp);
  617. }
  618. // Lookup the email template (we need this to find out if the update should be visible or not)
  619. $sql = "SELECT * FROM `{$dbEmailTemplates}` WHERE id='$emailtype' ";
  620. $result = mysql_query($sql);
  621. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
  622. if (mysql_num_rows($result) < 1) trigger_error("Email template '{$meailtype}' not found",E_USER_WARNING);
  623. $emailtype = mysql_fetch_object($result);
  624. // actually send the email
  625. $mailok = $mime -> send_mail();
  626. if ($mailok == FALSE)
  627. {
  628. trigger_error("Internal error sending email: send_mail() failed", E_USER_WARNING);
  629. }
  630. if ($mailok == TRUE)
  631. {
  632. // update incident status if necessary
  633. switch ($timetonextaction_none)
  634. {
  635. case 'none':
  636. $timeofnextaction = 0;
  637. break;
  638. case 'time':
  639. $timeofnextaction = calculate_time_of_next_action($timetonextaction_days, $timetonextaction_hours, $timetonextaction_minutes);
  640. break;
  641. case 'date':
  642. // kh: parse date from calendar picker, format: 200-12-31
  643. $date=explode("-", $date);
  644. $timeofnextaction=mktime(8 + $timeoffset,0,0,$date[1],$date[2],$date[0]);
  645. $now = time();
  646. if ($timeofnextaction < 0) $timeofnextaction = 0;
  647. break;
  648. default:
  649. $timeofnextaction = 0;
  650. break;
  651. }
  652. $oldtimeofnextaction = incident_timeofnextaction($id);
  653. if ($newincidentstatus != incident_status($id))
  654. {
  655. $sql = "UPDATE `{$dbIncidents}` SET status='$newincidentstatus', lastupdated='$now', timeofnextaction='$timeofnextaction' WHERE id='$id'";
  656. mysql_query($sql);
  657. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  658. $updateheader = "New Status: <b>" . incidentstatus_name($newincidentstatus) . "</b>\n\n";
  659. }
  660. else
  661. {
  662. mysql_query("UPDATE `{$dbIncidents}` SET lastupdated='$now', timeofnextaction='$timeofnextaction' WHERE id='$id'");
  663. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  664. }
  665. $timetext = '';
  666. if ($timeofnextaction != 0)
  667. {
  668. $timetext = "Next Action Time: ";
  669. if (($oldtimeofnextaction-$now) < 1)
  670. {
  671. $timetext .= "None";
  672. }
  673. else
  674. {
  675. $timetext .= date("D jS M Y @ g:i A", $oldtimeofnextaction);
  676. }
  677. $timetext .= " -&gt; <b>";
  678. if ($timeofnextaction < 1)
  679. {
  680. $timetext .= "None";
  681. }
  682. else
  683. {
  684. $timetext .= date("D jS M Y @ g:i A", $timeofnextaction);
  685. }
  686. $timetext .= "</b>\n\n";
  687. //$bodytext = $timetext.$bodytext;
  688. }
  689. // add update
  690. $bodytext = htmlentities($bodytext, ENT_COMPAT, 'UTF-8');
  691. $updateheader .= "{$SYSLANG['strTo']}: [b]{$tofield}[/b]\n";
  692. $updateheader .= "{$SYSLANG['strFrom']}: [b]{$fromfield}[/b]\n";
  693. $updateheader .= "{$SYSLANG['strReplyTo']}: [b]{$replytofield}[/b]\n";
  694. if ($ccfield != '' AND $ccfield != ",") $updateheader .= "CC: [b]{$ccfield}[/b]\n";
  695. if ($bccfield != '') $updateheader .= "BCC: [b]{$bccfield}[/b]\n";
  696. if ($filename != '') $updateheader .= "{$SYSLANG['strAttachment']}: [b][[att={$fileid}]]".$name."[[/att]][/b]\n";
  697. $updateheader .= "{$SYSLANG['strSubject']}: [b]{$subjectfield}[/b]\n";
  698. if (!empty($updateheader)) $updateheader .= "<hr>";
  699. $updatebody = $timetext . $updateheader . $bodytext;
  700. $updatebody = mysql_real_escape_string($updatebody);
  701. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, bodytext, type, timestamp, currentstatus, customervisibility) ";
  702. $sql .= "VALUES ({$id}, {$sit[2]}, '{$updatebody}', 'email', '{$now}', '{$newincidentstatus}', '{$emailtype->customervisibility}')";
  703. mysql_query($sql);
  704. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  705. $updateid = mysql_insert_id();
  706. $sql = "INSERT INTO `{$dbLinks}`(linktype, origcolref, linkcolref, direction, userid) ";
  707. $sql .= "VALUES (5, '{$updateid}', '{$fileid}', 'left', '{$sit[2]}')";
  708. mysql_query($sql);
  709. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  710. $owner = incident_owner($id);
  711. // Handle meeting of service level targets
  712. switch ($target)
  713. {
  714. case 'none':
  715. // do nothing
  716. $sql = '';
  717. break;
  718. case 'initialresponse':
  719. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) ";
  720. $sql .= "VALUES ('{$id}', '{$sit[2]}', 'slamet', '{$now}', '{$owner}', '{$newincidentstatus}', 'show', 'initialresponse','{$SYSLANG['strInitialResponseHasBeenMade']}')";
  721. break;
  722. case 'probdef':
  723. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) ";
  724. $sql .= "VALUES ('{$id}', '{$sit[2]}', 'slamet', '{$now}', '{$owner}', '{$newincidentstatus}', 'show', 'probdef','{$SYSLANG['strProblemHasBeenDefined']}')";
  725. break;
  726. case 'actionplan':
  727. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) ";
  728. $sql .= "VALUES ('{$id}', '{$sit[2]}', 'slamet', '{$now}', '{$owner}', '{$newincidentstatus}', 'show', 'actionplan','{$SYSLANG['strActionPlanHasBeenMade']}')";
  729. break;
  730. case 'solution':
  731. $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) ";
  732. $sql .= "VALUES ('{$id}', '{$sit[2]}', 'slamet', '{$now}', '{$owner}', '{$newincidentstatus}', 'show', 'solution','{$SYSLANG['strIncidentResolved']}')";
  733. break;
  734. }
  735. if (!empty($sql))
  736. {
  737. mysql_query($sql);
  738. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  739. }
  740. if ($target != 'none')
  741. {
  742. // Reset the slaemail sent column, so that email reminders can be sent if the new sla target goes out
  743. $sql = "UPDATE `{$dbIncidents}` SET slaemail='0', slanotice='0' WHERE id='$id' LIMIT 1";
  744. mysql_query($sql);
  745. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  746. }
  747. if (!empty($chase_customer))
  748. {
  749. $sql_insert = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, currentowner, currentstatus, bodytext, timestamp, customervisibility) ";
  750. $sql_insert .= "VALUES ('{$id}','{$sit['2']}','auto_chased_phone', '{$owner}', '{$newincidentstatus}', '{$SYSLANG['strCustomerHasBeenCalledToChase']}','{$now}','hide')";
  751. mysql_query($sql_insert);
  752. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  753. $sql_update = "UPDATE `{$dbIncidents}` SET lastupdated = '{$now}' WHERE id = {$id}";
  754. mysql_query($sql_update);
  755. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  756. }
  757. if (!empty($chase_manager))
  758. {
  759. $sql_insert = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, currentowner, currentstatus, bodytext, timestamp, customervisibility) ";
  760. $sql_insert .= "VALUES ('{$id}','{$sit['2']}','auto_chased_manager', '{$owner}', '{$newincidentstatus}', 'Manager has been called to chase','{$now}','hide')";
  761. mysql_query($sql_insert);
  762. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  763. $sql_update = "UPDATE `{$dbIncidents}` SET lastupdated = '{$now}' WHERE id = {$id}";
  764. mysql_query($sql_update);
  765. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  766. }
  767. if ($draftid != -1)
  768. {
  769. $sql = "DELETE FROM `{$dbDrafts}` WHERE id = {$draftid}";
  770. mysql_query($sql);
  771. if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR);
  772. }
  773. journal(CFG_LOGGING_FULL, $SYSLANG['strEmailSent'], "{$SYSLANG['strSubject']}: $subjectfield, {$SYSLANG['strIncident']}: $id", CFG_JOURNAL_INCIDENTS, $id);
  774. // FIXME i18n, maybe have a function that prints a dialog and then closes the window?
  775. echo "<html>";
  776. echo "<head>";
  777. ?>
  778. <script type="text/javascript">
  779. function confirm_close_window()
  780. {
  781. if (window.confirm('The email was sent successfully, click OK to close this window'))
  782. {
  783. window.opener.location='incident_details.php?id=<?php echo $id; ?>';
  784. window.close();
  785. }
  786. }
  787. </script>
  788. <?php
  789. echo "</head>";
  790. echo "<body onload=\"confirm_close_window();\">";
  791. echo "</body>";
  792. echo "</html>";
  793. }
  794. else
  795. {
  796. include (APPLICATION_INCPATH . 'incident_html_top.inc.php');
  797. echo "<p class='error'>{$SYSLANG['strErrorSendingEmail']}: $mailerror</p>\n";
  798. include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
  799. }
  800. }
  801. else
  802. {
  803. // there were errors
  804. include (APPLICATION_INCPATH . 'incident_html_top.inc.php');
  805. echo $error_string;
  806. include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
  807. }
  808. break;
  809. default:
  810. trigger_error("{$SYSLANG['strInvalidParameter']}: $step", E_USER_ERROR);
  811. break;
  812. } // end switch step
  813. ?>