PageRenderTime 36ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/report_feedback_product.inc.php

https://github.com/nicdev007/sitracker
PHP | 286 lines | 189 code | 31 blank | 66 comment | 52 complexity | ca8d46f17bee25e35ecb78f429a1dbeb MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0, BSD-3-Clause
  1. <?php
  2. // SiT (Support Incident Tracker) - Support call tracking system
  3. // Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
  4. //
  5. // This software may be used and distributed according to the terms
  6. // of the GNU General Public License, incorporated herein by reference.
  7. // Prevent script from being run directly (ie. it must always be included
  8. if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME']))
  9. {
  10. exit;
  11. }
  12. echo "<div style='margin: 20px'>";
  13. echo "<h2><a href='{$CONFIG['application_webpath']}reports/feedback.php'>{$strFeedback}</a> {$strScores}: {$strByProduct}</h2>";
  14. echo feedback_between_dates();
  15. echo "<p>{$strCustomerFeedbackReportSiteMsg}:</p>";
  16. $qsql = "SELECT * FROM `{$dbFeedbackQuestions}` WHERE formid='{$formid}' AND type='rating' ORDER BY taborder";
  17. $qresult = mysql_query($qsql);
  18. if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
  19. while ($qrow = mysql_fetch_object($qresult))
  20. {
  21. $q[$qrow->taborder] = $qrow;
  22. }
  23. $msql = "SELECT *, \n";
  24. $msql .= "fr.id AS reportid, \n";
  25. $msql .= "p.id AS productid, p.name AS productname ";
  26. $msql .= "FROM `{$dbFeedbackRespondents}` AS fr, `{$dbIncidents}` AS i, `{$dbProducts}` AS p ";
  27. $msql .= "WHERE fr.incidentid = i.id \n";
  28. $msql .= "AND i.product = p.id ";
  29. $msql .= "AND fr.incidentid > 0 \n";
  30. $msql .= "AND fr.completed = 'yes' \n"; ///////////////////////
  31. if (!empty($startdate))
  32. {
  33. if ($dates == 'feedbackin')
  34. {
  35. $msql .= "AND fr.created >= '{$startdate}' ";
  36. }
  37. elseif ($dates == 'closedin')
  38. {
  39. $msql .= "AND i.closed >= '{$startdate}' ";
  40. }
  41. //echo "DATES {$dates}";
  42. }
  43. if (!empty($enddate))
  44. {
  45. if ($dates == 'feedbackin')
  46. {
  47. $msql .= "AND fr.created <= '{$enddate}' ";
  48. }
  49. elseif ($dates == 'closedin')
  50. {
  51. $msql .= "AND i.closed <= '{$enddate}' ";
  52. }
  53. }
  54. $msql .= "ORDER BY p.name, i.id ASC \n";
  55. $mresult = mysql_query($msql);
  56. if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
  57. if (mysql_num_rows($mresult) >= 1)
  58. {
  59. $previd=0;
  60. $countcontacts=0;
  61. $zero=0;
  62. $ten=0;
  63. $twenty=0;
  64. $thirty=0;
  65. $forty=0;
  66. $fifty=0;
  67. $sixty=0;
  68. $seventy=0;
  69. $eighty=0;
  70. $ninety=0;
  71. $hundred=0;
  72. $surveys=0;
  73. if ($CONFIG['debug']) echo "<h4>$msql</h4>";
  74. $firstrun=0;
  75. while ($mrow = mysql_fetch_object($mresult))
  76. {
  77. // Only print if we have a value ({$previd} / {$mrow->contactid})
  78. if ($previd!=$mrow->productid AND $firstrun!=0)
  79. {
  80. $numones=count($storeone);
  81. // if ($numones<10) $numones=10;
  82. ## echo "<h2><a href='/contact_details.php?id={$mrow->contactid}' title='Jump to Contact'>{$mrow->forenames} {$mrow->surname}</a>, {$mrow->department} &nbsp; <a href='#' title='Jump to site'>{$mrow->sitename}</a></h2>";
  83. ## $html .= "<h3>[[$mrow->contactid]]</h3>";
  84. if ($numones>0)
  85. {
  86. for($c=1;$c<=$numones;$c++)
  87. {
  88. if ($storeone[$c]>0) $qr=number_format($storeone[$c]/$storetwo[$c],2);
  89. else $qr=0;
  90. if ($storeone[$c]>0) $qp=number_format((($qr -1) * (100 / ($CONFIG['feedback_max_score'] -1))), 0);
  91. else $qp=0;
  92. $html .= "Q$c: {$q[$c]->question} {$qr} <strong>({$qp}%)</strong><br />";
  93. $gtotal+=$qr;
  94. }
  95. if ($c>0) $c--;
  96. $total_average=number_format($gtotal/$c,2);
  97. $total_percent=number_format((($total_average -1) * (100 / ($CONFIG['feedback_max_score'] -1))), 0);
  98. ## ($gtotal)($c)
  99. $html .= "<p>{$strPositivity}: {$total_average} <strong>({$total_percent}%)</strong>, ".sprintf($strAfterXSurveys,$surveys)."</p>";
  100. //print_r($storeone);
  101. //print_r($storetwo);
  102. }
  103. else $html = ''; // don't print name where theres no survey data
  104. if ($total_average>0)
  105. {
  106. echo "{$html}";
  107. $countcontacts++;
  108. // Stats
  109. if ($total_percent>0 AND $total_percent < 10) $zero++;
  110. if ($total_percent>=10 AND $total_percent < 20) $ten++;
  111. if ($total_percent>=20 AND $total_percent < 30) $twenty++;
  112. if ($total_percent>=30 AND $total_percent < 40) $thirty++;
  113. if ($total_percent>=40 AND $total_percent < 50) $forty++;
  114. if ($total_percent>=50 AND $total_percent < 60) $fifty++;
  115. if ($total_percent>=60 AND $total_percent < 70) $sixty++;
  116. if ($total_percent>=70 AND $total_percent < 80) $seventy++;
  117. if ($total_percent>=80 AND $total_percent < 90) $eighty++;
  118. if ($total_percent>=90 AND $total_percent < 100) $ninety++;
  119. if ($total_percent>=100) $hundred++;
  120. ## echo "\n<hr />\n";
  121. }
  122. // if ($total_average>0) echo "<code>{$dbg}</code>";
  123. unset($qavgavg);
  124. unset($qanswer);
  125. unset($dbg);
  126. unset($storeone);
  127. unset($storetwo);
  128. unset($gtotal);
  129. $surveys=0;
  130. }
  131. $firstrun=1;
  132. // Loop through reports
  133. $totalresult=0;
  134. $numquestions=0;
  135. $surveys++;
  136. //$html = "<h2>Incident <a href='/incident_details.php?id={$mrow->incidentid}' title='Jump to Incident'>{$mrow->incidentid}</a>: <a href='#' title='Jump to Contact'>{$mrow->forenames} {$mrow->surname}</a>, {$mrow->department}, <a href='#' title='Jump to site'>{$mrow->sitename}</a></h2>";
  137. //$html .= "<p><strong>{$mrow->title}</strong>, opened ".date("l jS F Y @ g:i a", $mrow->opened)." for ".format_seconds($mrow->duration)." and {$mrow->closingstatusname} on ".date("l jS F Y @ g:i a", $mrow->closed)."</p>";
  138. // $html = "<h2><a href='/contact_details.php?id={$mrow->contactid}' title='Jump to Contact'>{$mrow->forenames} {$mrow->surname}</a>, {$mrow->department} &nbsp; <a href='#' title='Jump to site'>{$mrow->sitename}</a></h2>";
  139. //$html = "<h2>{$mrow->department}&nbsp; <a href='site_details.php?id={$mrow->siteid}' title='Jump to site'>{$mrow->sitename}</a></h2>";
  140. $html = "<h2><a href='#?id={$mrow->productid}' title='Jump to product'>{$mrow->productname}</a></h2>";
  141. $qsql = "SELECT * FROM `{$dbFeedbackQuestions}` WHERE formid='{$formid}' AND type='rating' ORDER BY taborder";
  142. $qresult = mysql_query($qsql);
  143. ## echo "$qsql";
  144. if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
  145. while ($qrow = mysql_fetch_object($qresult))
  146. {
  147. $numquestions++;
  148. // $html .= "Q{$qrow->taborder}: {$qrow->question} &nbsp;";
  149. $sql = "SELECT * FROM `{$dbFeedbackRespondents}` AS fr, `{$dbIncidents}` AS i, `{$dbUsers}` AS u, `{$dbFeedbackResults}` AS r ";
  150. $sql .= "WHERE fr.incidentid = i.id ";
  151. $sql .= "AND i.owner = u.id ";
  152. $sql .= "AND fr.id = r.respondentid ";
  153. $sql .= "AND r.questionid = '$qrow->id' ";
  154. $sql .= "AND fr.id = '$mrow->reportid' ";
  155. if (!empty($startdate))
  156. {
  157. if ($dates == 'feedbackin')
  158. {
  159. $sql .= "AND fr.created >= '{$startdate}' ";
  160. }
  161. elseif ($dates == 'closedin')
  162. {
  163. $sql .= "AND i.closed >= '{$startdate}' ";
  164. }
  165. //echo "DATES {$dates}";
  166. }
  167. if (!empty($enddate))
  168. {
  169. if ($dates == 'feedbackin')
  170. {
  171. $sql .= "AND fr.created <= '{$enddate}' ";
  172. }
  173. elseif ($dates == 'closedin')
  174. {
  175. $sql .= "AND i.closed <= '{$enddate}' ";
  176. }
  177. }
  178. $sql .= "ORDER BY i.contact, i.id";
  179. // echo "==== $sql ====";
  180. $result = mysql_query($sql);
  181. if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
  182. $numresults=0;
  183. $cumul=0;
  184. $percent=0;
  185. $average=0;
  186. $answercount=mysql_num_rows($result);
  187. if ($answercount>0)
  188. {
  189. ## echo "[{$mrow->reportid}] ";
  190. //echo "answercount = $answercount <br >";
  191. while ($row = mysql_fetch_object($result))
  192. {
  193. // Loop through the results
  194. if (!empty($row->result))
  195. {
  196. $cumul+=$row->result;
  197. // echo "---&gt; {$mrow->surname} Q{$qrow->taborder} Result: {$row->result}<br />";
  198. $numresults++;
  199. $storeone[$qrow->taborder]+=$row->result;
  200. $storetwo[$qrow->taborder]++;
  201. $storethree[$qrow->taborder]=$qrow->id;
  202. }
  203. }
  204. }
  205. if ($numresults>0) $average=number_format(($cumul/$numresults), 2);
  206. $percent =number_format((($average / 9) * 100), 0);
  207. $totalresult+=$average;
  208. $qanswer[$qrow->taborder]+=$average;
  209. $qavgavg=$qanswer[$qrow->taborder];
  210. //$html .= "{$average} <strong>({$percent}%)</strong>";
  211. //$html .= "<br />";
  212. }
  213. // $answercount Survey(s) Returned -
  214. // $html .= "<p>Positivity: {$total_average} <strong>({$total_percent}%)</strong>, after $numresults surveys</p>";
  215. // $html .= "<hr />\n";
  216. $previd=$mrow->productid;
  217. // echo "Total Avg: {$total_average}<hr />\n";
  218. }
  219. /*
  220. echo "<p>This graph shows different levels of positivity of the contacts shown above:</p>";
  221. // echo $zero+$ten+$twenty+$thirty+$forty+$fifty+$sixty+$seventy+$eighty+$ninety+$hundred;
  222. $adjust=13;
  223. $min=4;
  224. $zero=number_format((($zero / $countcontacts) * 100), 0);
  225. $ten=number_format((($ten / $countcontacts) * 100), 0);
  226. $twenty=number_format((($twenty / $countcontacts) * 100), 0);
  227. $thirty=number_format((($thirty / $countcontacts) * 100), 0);
  228. $forty=number_format((($forty / $countcontacts) * 100), 0);
  229. $fifty=number_format((($fifty / $countcontacts) * 100), 0);
  230. $sixty=number_format((($sixty / $countcontacts) * 100), 0);
  231. $seventy=number_format((($seventy / $countcontacts) * 100), 0);
  232. $eighty=number_format((($eighty / $countcontacts) * 100), 0);
  233. $ninety=number_format((($ninety / $countcontacts) * 100), 0);
  234. $hundred=number_format((($hundred / $countcontacts) * 100), 0);
  235. echo "<div style='background: #B00; color: #FFF; float:left; width: ".($min + ($zero * $adjust))."px;'>&nbsp;</div>&nbsp; 0-9% ({$zero}%)<br />";
  236. echo "<div style='background: #993300; color: #FFF; float:left; width: ".($min + ($ten * $adjust))."px;'>&nbsp;</div>&nbsp; 10-19% ({$ten}%)<br />";
  237. echo "<div style='background: #993300; color: #FFF; float:left; width: ".($min + ($twenty * $adjust))."px;'>&nbsp;</div>&nbsp; 20-29% ({$twenty}%)<br />";
  238. echo "<div style='background: #996600; color: #FFF; float:left; width: ".($min + ($thirty * $adjust))."px;'>&nbsp;</div>&nbsp; 30-39% ({$thirty}%)<br />";
  239. echo "<div style='background: #996600; color: #FFF; float:left; width: ".($min + ($forty * $adjust))."px;'>&nbsp;</div>&nbsp; 40-49% ({$forty}%)<br />";
  240. echo "<div style='background: #999900; color: #000; float:left; width: ".($min + ($fifty * $adjust))."px;'>&nbsp;</div>&nbsp; 50-59% ({$fifty}%)<br />";
  241. echo "<div style='background: #999900; color: #000; float:left; width: ".($min + ($sixty * $adjust))."px;'>&nbsp;</div>&nbsp; 60-69% ({$sixty}%)<br />";
  242. echo "<div style='background: #99CC00; color: #000; float:left; width: ".($min + ($seventy * $adjust))."px;'>&nbsp;</div>&nbsp; 70-79% ({$seventy}%)<br />";
  243. echo "<div style='background: #99CC00; color: #000; float:left; width: ".($min + ($eighty * $adjust))."px;'>&nbsp;</div>&nbsp; 80-89% ({$eighty}%)<br />";
  244. echo "<div style='background: #99FF00; color: #000; float:left; width: ".($min + ($ninety * $adjust))."px;'>&nbsp;</div>&nbsp; 90-99% ({$ninety}%)<br />";
  245. echo "<div style='background: #99FF00; color: #000; float:left; width: ".($min + ($hundred * $adjust))."px;'>&nbsp;</div>&nbsp; 100% ({$hundred}%)<br />";
  246. */
  247. }
  248. else
  249. {
  250. echo user_alert($strNoFeedbackFound, E_USER_WARNING);
  251. }
  252. echo "</div>\n";
  253. ?>