PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/report/quickchart_opencheckbox.php

https://bitbucket.org/3tierlogic/3tl.tabbuilder
PHP | 241 lines | 180 code | 46 blank | 15 comment | 14 complexity | 3d7b6f6e39a1918d482b782959305c06 MD5 | raw file
  1. <?php
  2. require_once("db.php");
  3. $con = mysql_connect($dbhost, $dbuser, $dbpasswd); // connect to database
  4. if (!$con) { // error checking and handling
  5. die('Could not connect: ' . mysql_error());
  6. }
  7. mysql_select_db($dbname);
  8. // add where condition to support date range.
  9. function addCon($original_sql, $s, $e){
  10. // detect where;
  11. $pos = strpos($original_sql, 'where', 1);
  12. if($pos == false){ // try capital again.
  13. $pos = strpos($original_sql, 'WHERE', 1);
  14. }
  15. $sub1 = substr($original_sql,0,$pos+1+4); // "select...where"
  16. //print "sub1: ".$sub1."<br/>";
  17. $sub2 = " cpresult_create_time between '".$s."' and '".$e."' and ";
  18. //print "sub2: ".$sub2."<br/>";
  19. $sub3 = substr($original_sql, $pos+1+4+1); // " ..."
  20. //print "sub3: ".$sub3."<br/>";
  21. $original_sql = "";
  22. $original_sql = $original_sql.$sub1;
  23. $original_sql = $original_sql.$sub2;
  24. $original_sql = $original_sql.$sub3;
  25. return $original_sql;
  26. }
  27. function nichi($raw){
  28. // 11/16 to 2011-11-16
  29. $done = str_replace('/',"-",$raw);
  30. //echo "done = ".$done."<br/>";
  31. $done = "2011-".$done;
  32. //echo "done = ".$done."<br/>";
  33. return $done;
  34. }
  35. // start of code.
  36. $campaignID = $_REQUEST['cid'];
  37. $sDate = $_REQUEST['sdate'];
  38. $eDate = $_REQUEST['edate'];
  39. $chartType = $_REQUEST['ctype'];
  40. $countryCode = $_REQUEST['c'];
  41. $fieldLabel="";
  42. //*** get the checkbox label
  43. $sql = "SELECT cpfldcfg_label FROM sp_campaign_config where campaign_sid='".$campaignID."' and cpfldcfg_is_valid='1' AND cpfldcfg_var_name = '".$chartType."'";
  44. $res = mysql_query($sql, $con);
  45. list($fieldLabel) = mysql_fetch_array($res);
  46. $sql_dyn = "SELECT cpresult_".$chartType.", count(*) FROM sp_campaign_result s where campaign_sid ='".$campaignID."' group by cpresult_".$chartType;
  47. $sql_dyn = addCon($sql_dyn, $sDate, $eDate);
  48. //echo $sql_dyn;
  49. $res_dyn = mysql_query($sql_dyn, $con);
  50. if(mysql_num_rows($res_dyn) > 0) {
  51. $checkboxArray = array();
  52. $checkboxTotalArray = array();
  53. $counter = 0;
  54. while(list($dyn, $num) = mysql_fetch_array($res_dyn)){
  55. if ($dyn == 1){
  56. $dyn = "Yes";
  57. } else if ($dyn == 0) {
  58. $dyn = "No";
  59. } else {
  60. $dyn = "No response";
  61. }
  62. $dynstr_data = $dynstr_data."['".$dyn."', ".$num."],";
  63. $checkboxArray[$counter] = $dyn;
  64. $checkboxTotalArray[$counter] = $num;
  65. $counter++;
  66. }
  67. $dynstr_data = substr($dynstr_data, 0, -1);
  68. }
  69. echo $dynstr_data;
  70. ?>
  71. <html>
  72. <head>
  73. <link href="style.css" rel="stylesheet" type="text/css" />
  74. <style>
  75. div.panel{
  76. height:auto;
  77. display:none;
  78. }
  79. table#user-list tr.hover {
  80. color: #fff;
  81. background-color: #4c95e6;
  82. }
  83. #containergraph {
  84. float: left
  85. width: 33.3%;
  86. /* Min-height: */
  87. min-height: 400px;
  88. height: auto !important;
  89. height: 400px;
  90. }
  91. </style>
  92. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  93. <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
  94. <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
  95. <!-- Charts JS library: START -->
  96. <script type="text/javascript" src="js/highcharts.js"></script>
  97. <script type="text/javascript" src="js/themes/gray.js"></script>
  98. <script type="text/javascript" src="js/modules/exporting.js"></script>
  99. <!-- Charts JS library: END -->
  100. <style type="text/css">
  101. @import "DTmedia/css/demo_page.css";
  102. @import "DTmedia/css/demo_table.css";
  103. </style>
  104. <script class="jsbin" src="http://datatables.net/download/build/jquery.dataTables.js"></script>
  105. <script>
  106. var chart;
  107. var field="<?=$chartType?>";
  108. $(document).ready(function() {
  109. $('#example').dataTable({
  110. "bJQueryUI": true,
  111. <!--"sPaginationType": "full_numbers",-->
  112. "bPaginate": false,
  113. "bFilter": false,
  114. "bLengthChange": false,
  115. "bScrollInfinite": true,
  116. "bScrollCollapse": true,
  117. "sScrollY": "<?php echo $tableHeight ?>px"
  118. });
  119. chart = new Highcharts.Chart({
  120. chart: {
  121. renderTo: 'container',
  122. plotBackgroundColor: null,
  123. plotBorderWidth: null,
  124. plotShadow: false
  125. },
  126. title: {
  127. text: '<?=$fieldLabel?>'
  128. },
  129. tooltip: {
  130. formatter: function() {
  131. return '<b>'+ this.point.name +'</b>: '+ this.y +' entries';
  132. //return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
  133. }
  134. },
  135. plotOptions: {
  136. pie: {
  137. allowPointSelect: true,
  138. cursor: 'pointer',
  139. dataLabels: {
  140. enabled: true,
  141. color: Highcharts.theme.textColor || '#000000',
  142. connectorColor: Highcharts.theme.textColor || '#000000',
  143. formatter: function() {
  144. //return '<b>'+ this.point.name +'</b>: '+ this.y +' entries';
  145. return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 2) +' %';
  146. }
  147. }
  148. }
  149. },
  150. series: [{
  151. type: 'pie',
  152. name: '<?=$fieldLabel?>',
  153. data: [
  154. <?php echo $dynstr_data;?>
  155. ]
  156. }]
  157. });
  158. }); //**** function
  159. </script>
  160. </head>
  161. <body>
  162. <div id="container" style="width: 900px; height: 400px; margin: auto;"></div>
  163. <div id="tableContainer" style="width: 900px; height: 400px; margin: auto;" >
  164. <br><br><br><br>
  165. <?php
  166. echo "<h2>Campaign summary from ".$sDate." to ".$eDate."</h2>";
  167. echo "<table cellpadding='0' cellspacing='0' border='2' class='display' id='example'>"; //id='user-list'>";
  168. echo "<thead><tr><th>Item</th><th>Option</th><th>Total Entries</th></tr></thead>";
  169. echo "<tbody>";
  170. $counter = 0;
  171. $t = 0;
  172. foreach ($checkboxArray as $checkboxlabel) {
  173. if($counter % 2 != 0){
  174. echo "<tr class='odd gradeX'>";
  175. }else{
  176. echo "<tr class='odd gradeA'>";
  177. }
  178. echo "<td class='center'>".($counter+1)."</td>";
  179. echo "<td class='center'>".$checkboxlabel."</td>";
  180. echo "<td class='center'>".$checkboxTotalArray[$counter]."</td>";
  181. echo "</tr>";
  182. $t = $t + $checkboxTotalArray[$counter];
  183. $counter++;
  184. }
  185. echo "<tr class='odd gradeA'>";
  186. echo "<td class='center'>".($counter+1)."</td>";
  187. echo "<td class='center'><b>Total entries</b></td>";
  188. echo "<td class='center'><b>".$t."</b></td>";
  189. echo "</tr>";
  190. echo "</tbody>";
  191. echo "</table>";
  192. ?>
  193. </div>
  194. </body>
  195. </html>