PageRenderTime 86ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 1ms

/report/detail.php

https://bitbucket.org/3tierlogic/3tl.tabbuilder
PHP | 265 lines | 197 code | 49 blank | 19 comment | 21 complexity | 0277609b257ac653b766daa56e60474c 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 codeToField($currentArray, $currentCode) {
  28. $codeFound = false;
  29. $counter = 0;
  30. $totalArray = count($currentArray);
  31. $thisCode = "";
  32. while (($codeFound == false) && ($counter <= $totalArray)) {
  33. if ($currentArray[$counter][0] == $currentCode) {
  34. $codeFound = true;
  35. $thisCode = $currentArray[$counter][1];
  36. }
  37. $counter++;
  38. }
  39. return $thisCode;
  40. }
  41. $arrayFieldCode[] = array( 'firstname', 'cpresult_first_name');
  42. $arrayFieldCode[] = array( 'lastname', 'cpresult_last_name');
  43. $arrayFieldCode[] = array( 'birthdayyear', 'cpresult_birth_year');
  44. $arrayFieldCode[] = array( 'birthdaymonth', 'cpresult_birth_month');
  45. $arrayFieldCode[] = array( 'birthdayday', 'cpresult_birth_date');
  46. $arrayFieldCode[] = array( 'email', 'cpresult_email');
  47. $arrayFieldCode[] = array( 'mobilephone', 'cpresult_mobile');
  48. $arrayFieldCode[] = array( 'gender', 'cpresult_gender_sid');
  49. $arrayFieldCode[] = array( 'zipcode', 'cpresult_zip_code');
  50. $arrayFieldCode[] = array( 'emailopt', 'cpresult_email_opt');
  51. $arrayFieldCode[] = array( 'mobilecarrier', 'cpresult_carrier');
  52. $arrayFieldCode[] = array( 'phonenumber', 'cpresult_home_phone');
  53. $arrayFieldCode[] = array( 'address', 'cpresult_address');
  54. $arrayFieldCode[] = array( 'city', 'cpresult_city');
  55. $arrayFieldCode[] = array( 'state', 'cpresult_states');
  56. $arrayFieldCode[] = array( 'country', 'cpresult_country_sid');
  57. $arrayFieldCode[] = array( 'smsopt', 'cpresult_sms_post');
  58. $arrayFieldCode[] = array( 'opencheckbox_1', 'cpresult_opencheckbox_1');
  59. $arrayFieldCode[] = array( 'opencheckbox_2', 'cpresult_opencheckbox_2');
  60. // start of code.
  61. $campid = $_REQUEST['campid'];
  62. $date = $_REQUEST['date'];
  63. if($_REQUEST['date'] != "Total"){
  64. $date = $_REQUEST['date'];
  65. }
  66. $tord = $_REQUEST['tord'];
  67. $sdate = $_REQUEST['sdate'];
  68. $edate = $_REQUEST['edate'];
  69. $csv_output = ""; // init var for csv.
  70. $csv_hdr = ""; //create csv header.
  71. $fieldList = "";
  72. $fieldLabelsArray = array();
  73. $fieldVariablesArray = array();
  74. $counter=0;
  75. /*
  76. $sql = SELECT campaign_sid as campID, cpresult_user_id as facebookID, cpresult_first_name as firstname, cpresult_last_name as lastname, cpresult_mobile as mobileNumber, cpresult_email as emailAddress
  77. FROM facebook.sp_campaign_result
  78. where campaign_sid='CAMP0000000169' and date_format(cpresult_create_time,'%Y-%m-%d') = '2011-11-16'
  79. */
  80. //*** Select the available fields for the current campaign
  81. $sql_fields = "SELECT cpfldcfg_label, cpfldcfg_var_name, cpfldcfg_country_sid, cpfldcfg_is_mandatory FROM sp_campaign_config where campaign_sid='".$campid ."' and cpfldcfg_is_valid=1";
  82. $res_fields = mysql_query($sql_fields, $con);
  83. $totalFields = mysql_num_rows($res_fields);
  84. while (list($field_label, $field_varname, $field_country, $field_mandatory) = mysql_fetch_array($res_fields)) {
  85. $field_varname = codeToField($arrayFieldCode,$field_varname);
  86. if ($field_varname !="") {
  87. $fieldList = $fieldList.$field_varname.",";
  88. $fieldLabelsArray[$counter]=$field_label;
  89. $fieldVariablesArray[$counter]=$field_varname;
  90. $csv_hdr .= $fieldLabelsArray[$counter].",";
  91. $counter++;
  92. }
  93. }
  94. $csv_hdr .= "Entry Date\n"; //ensure the last column entry starts a new line
  95. $fieldList= $fieldList."cpresult_create_time";
  96. $fieldVariablesArray[$counter]="cpresult_create_time";
  97. $totalFields +=1;
  98. $sql = "SELECT ".$fieldList;
  99. $sql = $sql." ";
  100. $sql = $sql."FROM sp_campaign_result";
  101. $sql = $sql." ";
  102. if($date == "Total"){
  103. $sql = $sql."where campaign_sid='".$campid."'";
  104. }
  105. else {
  106. $sql = $sql."where campaign_sid='".$campid."' and date_format(cpresult_create_time,'%Y-%m-%d') = '".$date."'";
  107. }
  108. if($tord == "d"){
  109. $sql = $sql." group by cpresult_user_id";
  110. }
  111. if(($sdate != null)&&($edate != null) ){
  112. $sql = addCon($sql, $sdate, $edate);
  113. }
  114. ?>
  115. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  116. <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
  117. <head profile="http://gmpg.org/xfn/11">
  118. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  119. <title>3 Tier Logic - Sweepstakes Tracker V1.0</title>
  120. <style type="text/css">
  121. table#user-list tr.hover {
  122. color: #fff;
  123. background-color: #4c95e6;
  124. }
  125. .pos_fixed{
  126. position:absolute;
  127. top:60px;
  128. left:150px;
  129. }
  130. </style>
  131. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  132. <script type="text/javascript">
  133. $(document).ready(function() {
  134. $('tr').hover(
  135. function () {
  136. $(this).addClass('hover');
  137. },
  138. function () {
  139. $(this).removeClass('hover');
  140. }
  141. );
  142. // We don't want the hover effect on our table header, so we unbind the event for our table row containing the th elements
  143. // $("tr.table-header").unbind('mouseenter mouseleave');
  144. });
  145. </script>
  146. <!-- ****** Tables ************* -->
  147. <style type="text/css">
  148. @import "DTmedia/css/demo_page.css";
  149. @import "DTmedia/css/demo_table.css";
  150. </style>
  151. <script class="jsbin" src="http://datatables.net/download/build/jquery.dataTables.js"></script>
  152. <script type="text/javascript">
  153. $(document).ready(function(){
  154. $('#example').dataTable({
  155. "bJQueryUI": true,
  156. <!--"sPaginationType": "full_numbers",-->
  157. "bPaginate": false,
  158. "bFilter": true,
  159. "bLengthChange": false,
  160. "bScrollInfinite": true
  161. <!--"bScrollCollapse": true,-->
  162. <!--"sScrollY": "<?php echo $tableHeight ?>px"-->
  163. });
  164. $(".panel").slideToggle("slow");
  165. $(".flip").click(function(){
  166. $(".panel").slideToggle("slow");
  167. });
  168. });
  169. </script>
  170. </head>
  171. <body>
  172. <?php
  173. //echo $sql."<br/>";
  174. echo "<div id='div_table' align='center'>";
  175. // run the sql again to get data...
  176. $res = mysql_query($sql, $con);
  177. if (mysql_num_rows($res) > 0) {
  178. //echo "<h4>total entry: ".mysql_num_rows($res)."</h4>";
  179. echo "<div align='center'>";
  180. echo "<table cellpadding='0' cellspacing='0' border='2' class='display' id='user-list'>";
  181. echo "<thead><tr>";
  182. //*** Dynamically generate the columns
  183. foreach ($fieldLabelsArray as $fieldLabel) {
  184. echo "<th style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000'>".$fieldLabel."</th>";
  185. }
  186. echo "<th style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000'>Entry Date</th>";
  187. echo "</thead>";
  188. echo "<tbody>";
  189. while($row = mysql_fetch_array($res)){
  190. echo "<tr>";
  191. foreach ($fieldVariablesArray as $fieldVariable) {
  192. echo "<td class='center'><p style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000'>".$row[$fieldVariable]."</td>";
  193. $currentFieldValue = $row[$fieldVariable];
  194. $currentFieldValue = str_replace('"', "", $currentFieldValue);
  195. $currentFieldValue = str_replace(',', "-", $currentFieldValue);
  196. $csv_output .= $currentFieldValue . ", ";
  197. }
  198. $csv_output .= "\n"; //ensure the last column entry starts a new line
  199. echo "</tr>";
  200. $i++;
  201. }
  202. echo "</tbody>";
  203. echo "</table>";
  204. echo "</div>";
  205. }
  206. //echo "</div>";
  207. ?>
  208. <!--<form class="pos_fixed" name="export" action="export.php" method="post">-->
  209. <form name="export" action="export.php" method="post">
  210. <input type="submit" value="Export table to CSV">
  211. <input type="hidden" value="<? echo $csv_hdr; ?>" name="csv_hdr">
  212. <input type="hidden" value="<? echo $csv_output; ?>" name="csv_output">
  213. </form>
  214. </div>
  215. </body>
  216. </html>