/www/getdata.php

http://cupsfilter.googlecode.com/ · PHP · 206 lines · 182 code · 16 blank · 8 comment · 12 complexity · cd8651615ebd24acc3b776e8f4b0a1dd MD5 · raw file

  1. <?php
  2. require_once('dbdata.php');
  3. try {
  4. //?????? ?????????
  5. $curPage = $_POST['page'];
  6. $rowsPerPage = $_POST['rows'];
  7. $sortingField = $_POST['sidx'];
  8. $sortingOrder = $_POST['sord'];
  9. $printer_id = $_POST['printer_name'] !='all' ? $_POST['printer_name'] : $printer_id = NULL;
  10. $executor_id = $_POST['executor_fio'] !='all' ? $_POST['executor_fio'] : $executor_id = NULL;
  11. $pressman_id = $_POST['pressman_fio'] !='all' ? $_POST['pressman_fio'] : $pressman_id = NULL;
  12. $marker_id = $_POST['docmarker'] !='all' ? $_POST['docmarker'] : $marker_id = NULL;
  13. $cups_user = $_POST['cupsuser'] !='all' ? $_POST['cupsuser'] : $cups_user = NULL;
  14. #$date = $_POST['datetime'] !='all' ? $_POST['datetime'] : $date = NULL;
  15. #$docname = $_POST['docname'] !='all' ? $_POST['docname'] : $docname = NULL;
  16. $mb_number = $_POST['mb_number'];
  17. $inv_number = $_POST['inv_number'];
  18. $punkt = $_POST['punkt'];
  19. $copynumber = $_POST['copynumber'];
  20. $pagecount = $_POST['pagecount'];
  21. $pagecopy = $_POST['pagecopy'];
  22. //toLog($docname);
  23. //???????????? ? ????
  24. $dbh = new PDO('pgsql:host='.$dbHost.';dbname='.$dbName, $dbUser, $dbPass);
  25. //?????????, ?? ????? ???????????? utf8
  26. $dbh->exec('SET CHARACTER SET utf8');
  27. //?????????? ?????????? ??????? ? ???????
  28. $rows = $dbh->query('SELECT COUNT(reports.id) AS count FROM reports');
  29. $totalRows = $rows->fetch(PDO::FETCH_ASSOC);
  30. $firstRowIndex = $curPage * $rowsPerPage - $rowsPerPage;
  31. $where_str='';
  32. $query_str="SELECT reports.id,printers.printer_name,
  33. reports.copy_number AS copynumber, document_level.marker AS docmarker,
  34. reports.doc_name AS docname, reports.dt AS datetime, reports.mb_number,
  35. reports.page_count AS pagecount, reports.page_copy AS pagecopy,
  36. reports.cups_user AS cupsuser, executors.fio AS executor_fio,
  37. pressman.fio AS pressman_fio, reports.inv_number AS invnumber,
  38. reports.punkt, reports.jobs_id AS jobsid, reports.status,
  39. reports.info_str AS infostr
  40. FROM reports
  41. JOIN printers ON reports.printer_id = printers.id
  42. JOIN document_level ON reports.doc_level_id = document_level.id
  43. JOIN executors ON reports.executor_id = executors.id
  44. JOIN firstpages ON reports.firstpages_id = firstpages.id
  45. JOIN pressman ON reports.pressman_id = pressman.id";
  46. if (IsSet($printer_id)){
  47. if (!$where_str){
  48. $where_str=' WHERE ';
  49. }else{
  50. $where_str.=' AND ';
  51. }
  52. $where_str.= " printers.id = '$printer_id'";
  53. }
  54. if (IsSet($marker_id)){
  55. if (!$where_str){
  56. $where_str=' WHERE ';
  57. }else{
  58. $where_str.=' AND ';
  59. }
  60. $where_str.= " document_level.id = '$marker_id'";
  61. }
  62. if (IsSet($cups_user)){
  63. if (!$where_str){
  64. $where_str=' WHERE ';
  65. }else{
  66. $where_str.=' AND ';
  67. }
  68. $where_str.= " reports.cups_user = '$cups_user'";
  69. }
  70. if (IsSet($executor_id)){
  71. if (!$where_str){
  72. $where_str=' WHERE ';
  73. }else{
  74. $where_str.=' AND ';
  75. }
  76. $where_str.= " reports.executor_id= '$executor_id'";
  77. }
  78. if (IsSet($pressman_id)){
  79. if (!$where_str){
  80. $where_str=' WHERE ';
  81. }else{
  82. $where_str.=' AND ';
  83. }
  84. $where_str.= " reports.pressman_id = '$pressman_id'";
  85. }
  86. if (IsSet($date)){
  87. if (!$where_str){
  88. $where_str=' WHERE ';
  89. }else{
  90. $where_str.=' AND ';
  91. }
  92. #? 0 ????? ????????????? ?????
  93. $where_str.= " reports.datetime >= cast ('$date' as timestamp with time zone)'";
  94. }
  95. if (IsSet($docname)){
  96. if (!$where_str){
  97. $where_str=' WHERE ';
  98. }else{
  99. $where_str.=' AND ';
  100. }
  101. #? 0 ????? ????????????? ?????
  102. $where_str.= " reports.doc_name LIKE '%$docname%'";
  103. }
  104. if (IsSet($mb_number)){
  105. if (!$where_str){
  106. $where_str=' WHERE ';
  107. }else{
  108. $where_str.=' AND ';
  109. }
  110. $where_str.= " reports.mb_number= '$mb_number'";
  111. }
  112. if (IsSet($inv_number)){
  113. if (!$where_str){
  114. $where_str=' WHERE ';
  115. }else{
  116. $where_str.=' AND ';
  117. }
  118. $where_str.= " reports.inv_number= '$inv_number'";
  119. }
  120. if (IsSet($punkt)){
  121. if (!$where_str){
  122. $where_str=' WHERE ';
  123. }else{
  124. $where_str.=' AND ';
  125. }
  126. $where_str.= " reports.punkt= '$punkt'";
  127. }
  128. if (IsSet($copynumber)){
  129. if (!$where_str){
  130. $where_str=' WHERE ';
  131. }else{
  132. $where_str.=' AND ';
  133. }
  134. $where_str.= " reports.copynumber= '$copynumber'";
  135. }
  136. if (IsSet($page_count)){
  137. if (!$where_str){
  138. $where_str=' WHERE ';
  139. }else{
  140. $where_str.=' AND ';
  141. }
  142. $where_str.= " reports.page_count= '$pagecount'";
  143. }
  144. if (IsSet($page_copy)){
  145. if (!$where_str){
  146. $where_str=' WHERE ';
  147. }else{
  148. $where_str.=' AND ';
  149. }
  150. $where_str.= " reports.page_copy= '$pagecopy'";
  151. }
  152. if ($where_str){
  153. $query_str.=$where_str;
  154. }
  155. $query_str.=" ORDER BY $sortingField $sortingOrder LIMIT $rowsPerPage OFFSET $firstRowIndex";
  156. toLog($query_str);
  157. $res = $dbh->query($query_str);
  158. //WHERE repots_dt BETWEEN '.$date_begin.' AND '.$date_end.'
  159. //????????? ????? ??????? ????????, ????? ?????????? ??????? ? ????? ?????????? ???????
  160. $response->page = $curPage;
  161. $response->total = ceil($totalRows['count'] / $rowsPerPage);
  162. $response->records = $totalRows['count'];
  163. $i=0;
  164. while($row = $res->fetch(PDO::FETCH_ASSOC)) {
  165. $response->rows[$i]['id']=$row['id'];
  166. $response->rows[$i]['cell']=array($row['id'],$row['datetime'],$row['printer_name'],
  167. $row['docmarker'],$row['docname'],
  168. $row['mb_number'],$row['inv_number'],$row['punkt'],
  169. $row['copynumber'],$row['pagecount'],$row['pagecopy'],
  170. $row['cupsuser'],$row['executor_fio'],$row['pressman_fio'],
  171. $row['status'],$row['infostr']);
  172. $i++;
  173. }
  174. echo json_encode($response);
  175. }
  176. catch (PDOException $e) {
  177. echo 'Database error: '.$e->getMessage();
  178. }
  179. // end of getdata.php
  180. ?>