PageRenderTime 95ms CodeModel.GetById 64ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/www/getdata.php

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