Advertisement
Guest User

Untitled

a guest
Jan 15th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. <?PHP
  2.  
  3. include('fpdfmysql1.php');
  4.  
  5. $now_from = $_POST['from'];
  6. $now_to = $_POST['to'];
  7. $province = $_POST['Province'];
  8. $cancer = $_POST['Cancer'];
  9. $gender = $_POST['Gender'];
  10. $nature = $_POST['Nature'];
  11. $age = $_POST['Age'];
  12. $received = $_POST['Received'];
  13. $documentType= $_POST['docType'];
  14.  
  15.  
  16.  
  17. $DB_Server = "";
  18. $DB_Username = "";
  19. $DB_Password = "";
  20. $DB_DBName = "";
  21. $DB_TBLName = "";
  22.  
  23.  
  24. $provinceFilterSql = "";
  25. $cancerTypeSql = "";
  26. $genderTypeSql = "";
  27. $natureTypeSql = "";
  28. $ageTypeSql = "";
  29. $receivedTypeSql ="";
  30. $column_province ="";
  31. $column_cancer ="";
  32. $column_gender ="";
  33. $column_nature ="";
  34. $column_age = "";
  35.  
  36.  
  37. if ($province!="") {
  38. $provinceFilterSql = " and (`Province`='$province') ";
  39. }
  40.  
  41. if ($cancer!="") {
  42. $cancerTypeSql = " and (`Cancer Type`='$cancer')";
  43. }
  44. if ($gender!="") {
  45. $genderTypeSql = " and (`Gender`='$gender')";
  46. }
  47. if ($nature!="") {
  48. $natureTypeSql = " and (`Nature of call`='$nature')";
  49. }
  50. if ($age!="") {
  51. $ageTypeSql = " and (`Age`='$age')";
  52. }
  53. if ($received!="") {
  54. $receivedTypeSql = " and (`Received Via`='$received')";
  55. }
  56.  
  57. $sql ="SELECT * ";
  58. $sql .=" FROM $DB_TBLName";
  59. $sql .=" WHERE (`Call date` BETWEEN '$now_from' AND '$now_to' ) ";
  60. $sql .= $provinceFilterSql;
  61. $sql .= $cancerTypeSql;
  62. $sql .= $genderTypeSql;
  63. $sql .= $natureTypeSql;
  64. $sql .= $ageTypeSql;
  65. $sql .= $receivedTypeSql;
  66.  
  67.  
  68. if ($result=mysql_query($sql))
  69. {
  70.  
  71. $rowcount=mysql_num_rows($result);
  72.  
  73.  
  74. mysql_free_result($result);
  75. }
  76.  
  77.  
  78. $Use_Title = 0;
  79.  
  80. $title = "Dump For Table $DB_TBLName from Database $DB_DBName
  81. on $now_from";
  82.  
  83. $Connect = @MYSQL_CONNECT($DB_Server, $DB_Username, $DB_Password)
  84. or DIE("Couldn't connect to MySQL:<br>" . MYSQL_ERROR() . "<br>"
  85. .MYSQL_ERRNO());
  86.  
  87. $Db = @MYSQL_SELECT_DB($DB_DBName, $Connect)
  88. or DIE("Couldn't select database:<br>" . MYSQL_ERROR(). "<br>"
  89. .MYSQL_ERRNO());
  90.  
  91. $result = @MYSQL_QUERY($sql,$Connect)
  92. or DIE("Couldn't execute query:<br>" . MYSQL_ERROR(). "<br>"
  93. . MYSQL_ERRNO());
  94.  
  95. switch ($documentType) {
  96. case 'excel':
  97. $file_type = "vnd.ms-excel";
  98. $file_ending = "xls";
  99.  
  100. IF ($Use_Title == 1)
  101. {
  102. ECHO("$titlen");
  103. }
  104.  
  105. $sep = "t";
  106.  
  107.  
  108. FOR ($i = 0; $i < MYSQL_NUM_FIELDS($result); $i++)
  109. {
  110. ECHO MYSQL_FIELD_NAME($result,$i) . "t";
  111. }PRINT "Total Records:$rowcount";
  112. PRINT("n");
  113.  
  114.  
  115. WHILE($row = MYSQL_FETCH_ROW($result))
  116. {
  117.  
  118. $schema_insert = "";
  119. FOR($j=0; $j<mysql_num_fields($result);$j++)
  120. {
  121. IF(!ISSET($row[$j]))
  122. $schema_insert .= "NULL".$sep;
  123. ELSEIF ($row[$j] != "")
  124. $schema_insert .= "$row[$j]".$sep;
  125. ELSE
  126. $schema_insert .= "".$sep;
  127. }
  128. $schema_insert = STR_REPLACE($sep."$", "", $schema_insert);
  129. $schema_insert = PREG_REPLACE("/rn|nr|n|r/", " ",
  130. $schema_insert);
  131. $schema_insert .= "t";
  132. PRINT(TRIM($schema_insert));
  133. PRINT "n";
  134. }
  135.  
  136. HEADER("Content-Type: application/$file_type");
  137. HEADER("Content-Disposition: attachment;
  138. filename=CANSA_DB_$now_from.$file_ending");
  139. HEADER("Pragma: no-cache");
  140. HEADER("Expires: 0");
  141. break;
  142. case 'word':
  143. $file_type = "doc";
  144. $file_ending = "doc";
  145.  
  146.  
  147. IF ($Use_Title == 1)
  148. {
  149. ECHO("$titlenn");
  150. }
  151.  
  152. $sep = "n";
  153.  
  154. WHILE($row = MYSQL_FETCH_ROW($result))
  155. {
  156.  
  157. $schema_insert = "";
  158. FOR($j=0; $j<mysql_num_fields($result);$j++)
  159. {
  160.  
  161. $field_name = MYSQL_FIELD_NAME($result,$j);
  162. //will show name of fields
  163. $schema_insert .= "$field_name:t";
  164. IF(!ISSET($row[$j])) {
  165. $schema_insert .= "NULL".$sep;
  166. }
  167. ELSEIF ($row[$j] != "") {
  168. $schema_insert .= "$row[$j]".$sep;
  169. }
  170. ELSE {
  171. $schema_insert .= "".$sep;
  172. }
  173. }
  174. $schema_insert = STR_REPLACE($sep."$", "", $schema_insert);
  175. $schema_insert .= "t";
  176. PRINT(TRIM($schema_insert));
  177.  
  178. PRINT
  179. "n----------------------------------------------------n";
  180. }
  181.  
  182.  
  183. HEADER("Content-Type: application/$file_type");
  184. HEADER("Content-Disposition: attachment;
  185. filename=CANSA_DB_$now_from.$file_ending");
  186. HEADER("Pragma: no-cache");
  187. HEADER("Expires: 0");
  188. break;
  189. case 'pdf':
  190. $file_type = "pdf";
  191. $file_ending = "pdf";
  192.  
  193. BuildFpdfOutput($result);
  194.  
  195. break;
  196.  
  197.  
  198.  
  199.  
  200. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement