PageRenderTime 60ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/www/openacd/stat.php

http://openacd.googlecode.com/
PHP | 609 lines | 534 code | 63 blank | 12 comment | 119 complexity | d3ff77720ceef65b6df93cf0dfea20b0 MD5 | raw file
  1. <?php
  2. include_once("db_connect.php");
  3. $xls = trim ($_GET['xls']);
  4. $xlstype = trim ($_GET['type']);
  5. include_once("include.php");
  6. if($_SESSION['logged']=='admin' || $_SESSION['logged']=='stat') {
  7. include_once("xls.php");
  8. if($xls!=1) include_once("menu.php");
  9. include_once("db_connect.php");
  10. if($xls==1) $_POST=$_GET;
  11. $search = trim ($_POST['search']);
  12. $kouch = trim ($_POST['kouch']);
  13. $service = trim ($_POST['service']);
  14. $call_type = trim ($_POST['call_type']);
  15. $number = trim ($_POST['number']);
  16. $date = trim ($_POST['to_date_from']);
  17. $datet = trim ($_POST['to_date_to']);
  18. $time = trim ($_POST['to_time_from']);
  19. $timet = trim ($_POST['to_time_to']);
  20. $random = trim ($_POST['random']);
  21. $random_count = (isset($_POST['random_count']))?trim($_POST['random_count']):50;
  22. $operators = pg_exec('select * from public.operators ORDER BY opr_name ASC');
  23. $services = pg_exec('SELECT * FROM public.services ORDER BY srv_order DESC');
  24. if($xls==1) {
  25. if(!isset($xlstype)) $xlstype='';
  26. // Send Header
  27. header("Pragma: public");
  28. header("Expires: 0");
  29. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  30. header("Content-Type: application/force-download");
  31. header("Content-Type: application/octet-stream");
  32. header("Content-Type: application/download");;
  33. header("Content-Disposition: attachment;filename=operators-".date("Ymd-His").".xls");
  34. header("Content-Transfer-Encoding: binary ");
  35. xlsBOF();
  36. $i=0;
  37. foreach($_SESSION['xls_table'.$xlstype] as $str) {
  38. $j=0;
  39. foreach ($str as $cell){
  40. if(is_numeric($cell)) xlsWriteNumber($i,$j++,$cell);
  41. else xlsWriteLabel($i,$j++, iconv('utf-8', 'cp1251', $cell));
  42. }
  43. $i++;
  44. }
  45. xlsEOF();
  46. exit();
  47. ?><?
  48. } else {
  49. $_SESSION['xls_table'.$xlstype] = "";
  50. ?>
  51. <script type="text/javascript">
  52. <!--
  53. function dynamicSelect(id1, id2) {
  54. if (document.getElementById && document.getElementsByTagName) {
  55. var sel1 = document.getElementById(id1);
  56. var sel2 = document.getElementById(id2);
  57. var clone = sel2.cloneNode(true);
  58. var clonedOptions = clone.getElementsByTagName("option");
  59. refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
  60. sel1.onchange = function() {
  61. refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
  62. };
  63. }
  64. }
  65. function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
  66. while (sel2.options.length) {
  67. sel2.remove(0);
  68. }
  69. var pattern1 = /( |^)(select)( |$)/;
  70. if(sel1.options[sel1.selectedIndex].value=='none') {
  71. var pattern2 = new RegExp("( |^)(.*?)( |$)");
  72. } else {
  73. var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + "|all)( |$)");
  74. }
  75. for (var i = 0; i < clonedOptions.length; i++) {
  76. if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
  77. sel2.appendChild(clonedOptions[i].cloneNode(true));
  78. }
  79. }
  80. }
  81. function addLoadEvent(func) {
  82. var oldonload = window.onload;
  83. if (typeof window.onload != 'function') {
  84. window.onload = func;
  85. } else {
  86. window.onload = function() {
  87. if (oldonload) {
  88. oldonload();
  89. }
  90. func();
  91. }
  92. }
  93. }
  94. addLoadEvent(function() {
  95. dynamicSelect("kchs", "oprs");
  96. });
  97. //-->
  98. </script>
  99. <h2>?????????</h2>
  100. <form method="post" name="op">
  101. ????:
  102. <select name="kouch" id="kchs">
  103. <option value="none">...</option>
  104. <?
  105. $kouchdb = pg_exec('select * from public.kouch ORDER BY kch_name ASC');
  106. while($t3 = pg_fetch_array($kouchdb)){
  107. echo "<option value=".$t3['kch_id'];
  108. if($kouch==$t3['kch_id']) echo " selected";
  109. echo ">".$t3['kch_name']."</option>";
  110. }
  111. ?>
  112. </select>
  113. <br />
  114. ????????:<br>
  115. <select name="search" id="oprs">
  116. <option class="all" value="all">??? ?????????</option>
  117. <?
  118. while($t = pg_fetch_array($operators)){
  119. echo "<option class=\"".$t['kch_id']."\"";
  120. if($t['opr_password']==$search) echo "selected ";
  121. echo "value=".$t['opr_password'].">".$t['opr_password']." - ".$t['opr_name']."</option>";
  122. }
  123. ?>
  124. </select>
  125. <br />
  126. <script type="text/javascript">
  127. function showElement()
  128. {
  129. if (document.forms.op.search.value == 'all') {
  130. document.getElementById("k").style.display="block";
  131. } else {
  132. document.getElementById("k").style.display="none";
  133. }
  134. }
  135. showElement();
  136. </script>
  137. <table><tr><td>
  138. ???? ?: <input name="to_date_from" id="to_date_from" type="text" size="11" maxlength="11" value="<?=(!empty($date))?$date:Date("Y-m-d");?>">
  139. <a href="javascript:void(null);" id="icon2"><img src="images/calendar.gif" width="16" height="16" border=0 alt="" /></a>
  140. <script type="text/javascript">
  141. new Component.Calendar('to_date_from', {lang: 'en'});
  142. new Component.Calendar('to_date_from', {lang: 'en', click: 'icon2'});
  143. </script>
  144. <br>
  145. ????? ?: <input name="to_time_from" type="text" size="11" maxlength="11" value="<?=(!empty($time))?$time:"07:00:00";?>">
  146. </td><td>
  147. &nbsp;&nbsp;&nbsp;&nbsp;
  148. </td><td>
  149. ???? ??: <input name="to_date_to" id="to_date_to" type="text" size="11" maxlength="11" value="<?=(!empty($datet))?$datet:Date("Y-m-d", strtotime("+1 day"));?>">
  150. <a href="javascript:void(null);" id="icon3"><img src="images/calendar.gif" width="16" height="16" border=0 alt="" /></a>
  151. <script type="text/javascript">
  152. new Component.Calendar('to_date_to', {lang: 'en'});
  153. new Component.Calendar('to_date_to', {lang: 'en', click: 'icon3'});
  154. </script>
  155. <br>
  156. ????? ??: <input name="to_time_to" type="text" size="11" maxlength="11" value="<?=(!empty($timet))?$timet:"06:59:59";?>">
  157. </td></tr></table>
  158. ??????:
  159. <select name="service">
  160. <option value="">???</option>
  161. <?
  162. while($t = pg_fetch_array($services)){
  163. echo "<option ";
  164. if($t['srv_name']==$service) echo "selected ";
  165. echo "value=".$t['srv_name'].">".$t['srv_name']."</option>";
  166. }
  167. ?>
  168. </select>
  169. ??? ??????:
  170. <select name="call_type">
  171. <option value="">???</option>
  172. <option <? if($call_type=="in") echo "selected "; ?> value="in">????????</option>
  173. <option <? if($call_type=="out") echo "selected "; ?> value="out">?????????</option>
  174. </select>
  175. <br />
  176. ????? ????????: <input type="text" name="number" size="11" maxlength="11" value="<?=$number;?>">
  177. <br />
  178. <input type="checkbox" onclick="show_n_hide('show_random');" id="label_random" name="random" value="on" <?if($random=='on') echo 'checked'?> >????????? ???????
  179. <span id="show_random" style="display:none;">
  180. <br>
  181. ?????????? ????????? ??????: <input type="text" name="random_count" size="5" maxlength="5" value="<?=$random_count;?>">
  182. </span>
  183. <script language="JavaScript">
  184. function show_n_hide(what) {
  185. if(document.getElementById('label_random').checked){
  186. document.getElementById(what).style.display='';
  187. } else {
  188. document.getElementById(what).style.display='none';
  189. }
  190. }
  191. show_n_hide('show_random');
  192. </script>
  193. <br /><br />
  194. <input type="submit" value="?????" name="submit"><br />
  195. </form>
  196. <?php
  197. function show_table($logs_new, $hide=array(0,0,0), $xlstype="") {
  198. $j=0;
  199. echo "<table border=1><tr>
  200. <td>???</td>
  201. <td>??????</td>
  202. <td>????</td>";
  203. $tmp = array("???", "??????", "????");
  204. if($hide[0]==0) {
  205. echo"
  206. <td>? ???????</td>
  207. <td>?????</td>";
  208. $tmp = array_merge($tmp, array("? ???????", "?????"));
  209. }
  210. echo "<td>??????????</td>";
  211. echo"<td>??????</td>";
  212. $tmp = array_merge($tmp, array("?????", "??????"));
  213. if($hide[0]==0) echo '<td>?????</td>';
  214. if($hide[1]==0) echo '<td>????????</td>';
  215. if($hide[0]==0) echo '<td>???????</td>';
  216. if($hide[2]==0) echo '<td>????????</td>';
  217. if($hide[0]==0) echo '<td>??????</td>';
  218. if($hide[0]==0) echo '<td>hangup</td>';
  219. if($hide[0]==0) $tmp = array_merge($tmp, array("?????"));
  220. if($hide[1]==0) $tmp = array_merge($tmp, array("????????"));
  221. if($hide[0]==0) $tmp = array_merge($tmp, array("???????"));
  222. if($hide[2]==0) $tmp = array_merge($tmp, array("????????"));
  223. if($hide[0]==0) $tmp = array_merge($tmp, array("??????"));
  224. if($hide[0]==0) $tmp = array_merge($tmp, array("hangup"));
  225. echo"
  226. </tr>";
  227. $_SESSION['xls_table'.$xlstype][] = $tmp;
  228. while($t = pg_fetch_array($logs_new)){
  229. $tmp = array();
  230. echo '<tr>';
  231. echo '<td>'.$t['opr_name'].'</td>';
  232. echo '<td>'.$t['opr_password'].'</td>';
  233. echo '<td>'.substr($t['dt'],0,10).'</td>';
  234. $tmp = array($t['opr_name'], $t['opr_password'], substr($t['dt'],0,10));
  235. if($hide[0]==0) {
  236. echo '<td>'.substr($t['dt_begin'],11,8).'</td>';
  237. echo '<td>'.date("H:i:s", strtotime(substr($t['dt'],11,8)." -".$t['timer']." seconds")).'</td>';
  238. echo '<td>'.substr($t['dt'],11,8).'</td>';
  239. $tmp = array_merge($tmp, array(substr($t['dt_begin'],11,8), date("H:i:s", strtotime(substr($t['dt'],11,8)." -".$t['timer']." seconds")), substr($t['dt'],11,8)));
  240. } else {
  241. echo '<td>'.substr($t['dt'],11,8).'</td>';
  242. $tmp = array_merge($tmp, array(substr($t['dt'],11,8)));
  243. }
  244. if($t['event']==21) echo '<td>????</td>';
  245. elseif($t['event']==22) echo '<td>?????</td>';
  246. elseif($t['event']==10) {echo '<td>????????</td>';$tmp = array_merge($tmp, array("????????"));}
  247. elseif($t['event']==52) {echo '<td><b>??? ??????</b></td>';$tmp = array_merge($tmp, array("??? ??????"));}
  248. elseif($t['event']==53) {echo '<td><b>??????????</b></td>';$tmp = array_merge($tmp, array("??????????"));}
  249. elseif($t['event']==31) {echo '<td>?????????</td>';$tmp = array_merge($tmp, array("?????????"));}
  250. elseif($t['event']==36) {echo '<td>???. ??? ??????</td>';$tmp = array_merge($tmp, array("???. ??? ??????"));}
  251. elseif($t['event']==32) {echo '<td><i><b>????????? ??.</b></i></td>';$tmp = array_merge($tmp, array("????????? ????????"));}
  252. else echo '<td>'.$t['event'].'</td>';
  253. if($hide[0]==0) {echo '<td>'.$t['callid'].'</td>';$tmp = array_merge($tmp, array($t['callid']));}
  254. if($hide[1]==0) {echo '<td>'.$t['timer'].'</td>';$tmp = array_merge($tmp, array($t['timer']));}
  255. if($hide[0]==0) {echo '<td>'.$t['beforeanswertime'].'</td>';$tmp = array_merge($tmp, array($t['beforeanswertime']));}
  256. if($hide[2]==0) {
  257. if($j==0) {
  258. $j=strtotime($t['dt']." -".$t['timer']." seconds")-$t['beforeanswertime'];
  259. echo '<td>0</td>';
  260. $tmp = array_merge($tmp, array(0));
  261. } else {
  262. $m = $j-strtotime($t['dt']);
  263. if($hide[0]!=0) $m=round($m/60);
  264. echo '<td>'.($m).'</td>';
  265. $tmp = array_merge($tmp, array($m));
  266. $j=strtotime($t['dt']." -".$t['timer']." seconds")-$t['beforeanswertime'];
  267. }
  268. echo '</td>';
  269. }
  270. if($hide[0]==0){
  271. echo '<td>'.$t['acdgroup'];
  272. $tmp = array_merge($tmp, array($t['acdgroup']));
  273. echo '</td>';
  274. }
  275. // if($hide[0]==0) echo '<td>'.$t['exten'].'</td>';
  276. if($t['dialstatus']==10) $t['dialstatus']="<b>????????</b>";
  277. else $t['dialstatus']="";
  278. if($hide[0]==0) echo '<td>'.$t['dialstatus'].'</td>';
  279. $tmp = array_merge($tmp, array($t['dialstatus']));
  280. if($t['callid']==0) $t['callid'] = '';
  281. if( $t['record_file_name'] ) echo '<td><a href="sound.php?id='.$t['record_id'].'">?????</a></td>';
  282. echo '</tr>';
  283. $_SESSION['xls_table'.$xlstype][] = $tmp;
  284. }
  285. echo "</table>";
  286. }
  287. function op_info($search, $date, $time, $datet, $timet, $service, $call_type) {
  288. // $where="AND (op.opr_password like '%$search%' OR op.opr_name='$search')";
  289. $where="AND (op.opr_password = '$search')";
  290. // if($kouch!=0) $where.=" AND op.kouch='$kouch'";
  291. if($service!=0) $where.=" AND al.acdgroup='$service'";
  292. if( $call_type ) {
  293. $where.= ($call_type=='in')? " AND (al.event=10)" : " AND (al.event=31)";
  294. }
  295. if(!empty($date) && !empty($date)) $where.=" AND al.dt BETWEEN '$date $time' AND '$datet $timet'";
  296. else $where.=" AND al.dt BETWEEN '".Date("Y-m-d")." 00:00:00' AND '".Date("Y-m-d")." 23:59:59'";
  297. //echo ('select COUNT(*), SUM(al.timer), SUM(al.beforeanswertime) from public.agents_logs al JOIN public.operators op ON (al.agent=op.opr_id) WHERE (al.event=10) '.$where.' GROUP by al.agent');
  298. $logs_new = pg_fetch_array(pg_exec('select COUNT(*), SUM(al.timer), SUM(al.beforeanswertime) from public.agents_logs al JOIN public.operators op ON (al.agent=op.opr_id) WHERE (al.event=10) '.$where.' GROUP by al.agent'));
  299. $recived = ($logs_new[0])?$logs_new[0]:0;
  300. $totaltime = round($logs_new[1]/60);
  301. if($logs_new[0]!=0) {
  302. $answertime = round($logs_new[1]/$logs_new[0]);
  303. $reaction = round($logs_new[2]/$logs_new[0]*100)/100;
  304. } else {
  305. $answertime = $reaction = 0;
  306. }
  307. $logs_new = pg_fetch_array(pg_exec('select COUNT(*) from public.agents_logs al JOIN public.operators op ON (al.agent=op.opr_id) WHERE (al.event=52) '.$where.' GROUP by al.agent'));
  308. $noanswer = ($logs_new[0])?$logs_new[0]:0;
  309. $logs_new = pg_fetch_array(pg_exec('select COUNT(*) from public.agents_logs al JOIN public.operators op ON (al.agent=op.opr_id) WHERE (al.event=53) '.$where.' GROUP by al.agent'));
  310. $lost = ($logs_new[0])?$logs_new[0]:0;
  311. $logs_new = pg_fetch_array(pg_exec('select COUNT(*) from public.agents_logs al JOIN public.operators op ON (al.agent=op.opr_id) WHERE (al.dialstatus=10) '.$where.' GROUP by al.agent'));
  312. $hangup = ($logs_new[0])?$logs_new[0]:0;
  313. $logs_new = pg_fetch_array(pg_exec('select COUNT(*) from public.agents_logs al JOIN public.operators op ON (al.agent=op.opr_id) WHERE (al.event=31 OR al.event=32) '.$where.' GROUP by al.agent'));
  314. $local_count = ($logs_new[0])?$logs_new[0]:0;
  315. $logs_new = pg_fetch_array(pg_exec('select SUM(al.timer) from public.agents_logs al JOIN public.operators op ON (al.agent=op.opr_id) WHERE (al.event=31 OR al.event=32) '.$where.' GROUP by al.agent'));
  316. $local_timer = ($logs_new[0])?round($logs_new[0]/60*100)/100:0;
  317. $total_time=$break_time=0;
  318. $tb=$tp='';
  319. $logs_new = pg_exec('select *, date_trunc(\'second\', al.Dt) as dt from public.agents_logs al JOIN public.operators op ON (al.agent=op.opr_id)
  320. LEFT JOIN public.records r ON (al.record_id=r.record_id)
  321. WHERE (al.event=21 OR al.event=22) '.$where.' order by date_trunc(\'second\', al.Dt) Asc, al.event Desc');
  322. while($t = pg_fetch_array($logs_new)){
  323. if($t['event']==21) {
  324. $tb=$t['dt'];
  325. if ($tp!='') {
  326. $break_time+=strtotime($tb)-strtotime($tp);
  327. $tp='';
  328. }
  329. }
  330. if($t['event']==22 && $tb!='') {
  331. $tp=$t['dt'];
  332. if ($tb!='') {
  333. $total_time+=strtotime($tp)-strtotime($tb);
  334. $tb='';
  335. }
  336. }
  337. }
  338. $timeonline = round($total_time/60);
  339. $timeoffline = round($break_time/60);
  340. return (array($recived, $totaltime, $answertime, $reaction, $noanswer, $lost, $timeonline, $timeoffline, $local_count, $local_timer, $hangup));
  341. }
  342. $more_than_day = ((strtotime($datet." ".$timet)-strtotime($date." ".$time)) > (25*60*60));
  343. if(empty($search) || $search!='all') {
  344. echo '<h3>??????? ?????????</h3>';
  345. // if($search!='all') $where.="AND (op.opr_password like '%$search%' OR op.opr_name='$search')";
  346. if($search!='all') $where.="AND (op.opr_password='$search')";
  347. if(!empty($date) && !empty($date)) $where.=" AND al.dt BETWEEN '$date $time' AND '$datet $timet'";
  348. else $where.=" AND al.dt BETWEEN '".Date("Y-m-d")." 00:00:00' AND '".Date("Y-m-d")." 23:59:59'";
  349. }
  350. echo "<table><tr><td valign='top'>";
  351. $where = "";
  352. if(!empty($search)) {
  353. // if($search!='all') $where.="AND (op.opr_password like '%$search%' OR op.opr_name='$search')";
  354. if($search!='all') $where.="AND (op.opr_password='$search')";
  355. if($kouch!=0 && $search=='all') $where.=" AND op.kch_id='$kouch'";
  356. if(!empty($date) && !empty($date)) $where.=" AND al.dt BETWEEN '$date $time' AND '$datet $timet'";
  357. else $where.=" AND al.dt BETWEEN '".Date("Y-m-d")." 00:00:00' AND '".Date("Y-m-d")." 23:59:59'";
  358. if(!empty($search) && $search!='all' && !$more_than_day && $random!='on') {
  359. list($recived, $totaltime, $answertime, $reaction, $noanswer, $lost, $timeonline, $timeoffline, $local_count, $local_timer, $hangup) = op_info($search, $date, $time, $datet, $timet, $service, $call_type);
  360. echo "<b>????????:</b> $recived<br>";
  361. echo "<b>????????(????), ???:</b> $totaltime<br>";
  362. echo "<b>??????? ????? ??????, ???:</b> $answertime<br>";
  363. echo "<b>??????? ????? ???????, ???:</b> $reaction<br>";
  364. if($timeonline!=0) echo "<b>???????, ??????? ?? ???:</b> ".round($recived/($timeonline/60))."<br>";
  365. echo "<b>??? ??????:</b> $noanswer<br>";
  366. echo "<b>??????????:</b> $lost<br>";
  367. echo "<b>hangup:</b> $hangup<br>";
  368. echo "<b>hangup ?? ????????:</b> ".round($hangup/$recived*100)."%<br>";
  369. echo "<b>????????? ???????:</b> $local_count<br>";
  370. echo "<b>????? ????????? ???????, ???:</b> $local_timer<br>";
  371. echo "<b>????? ?? ?????, ???:</b> $timeonline<br>";
  372. echo "<b>??????? ????? ???????, ???:</b> ".round((($timeonline-$totaltime)*60-5*$recived)/($recived+1))."<br>";
  373. echo "<b>????? ?????????, ???:</b> $timeoffline<br>";
  374. $logs_new = pg_exec('select * from public.agents_logs al JOIN public.operators op ON (al.agent=op.opr_id)
  375. LEFT JOIN public.records r ON (al.record_id=r.record_id)
  376. WHERE (al.event=21 OR al.event=22) '.$where.' order by date_trunc(\'second\', al.Dt_begin) Desc, al.event Asc LIMIT 100');
  377. echo '<h3>????-?????</h3>';
  378. $_SESSION['xls_table2'] = "";
  379. echo '<a href="?xls=1&type=2"><img border=0 src="http://stat.isystems.com.ua/img/admin/xls.gif"> ??????? ? Excel</a>';
  380. show_table($logs_new, array(1,1), 2);
  381. } elseif ( $more_than_day && (!empty($search)) && $random!='on' && empty($number)) {
  382. echo '<h3>??????? ?? ?????????</h3> <a href="?xls=1"><img border=0 src="http://stat.isystems.com.ua/img/admin/xls.gif"> ??????? ? Excel</a>';
  383. echo "<table border=1><tr>
  384. <td></td>
  385. <td>??????</td>
  386. <td>???</td>
  387. <td>????</td>
  388. <td><small>????????</small></td>
  389. <td><small>????, ???</small></td>
  390. <td><small>??????? ?? ???</small></td>
  391. <td><small>??????? t ??????, ???</small></td>
  392. <td><small>???????. ???????, ???</small></td>
  393. <td><small>??? ??????</small></td>
  394. <td><small>??????</small></td>
  395. <td><small>Hangup</small></td>
  396. <td><small>Hangup ?? ????????</small></td>
  397. <td><small>?????????</small></td>
  398. <td><small>?????????, ???</small></td>
  399. <td><small>?? ?????, ???</small></td>
  400. <td><small>???????, ???</small></td>
  401. <td><small>???????, ???????, ???</small></td></tr>
  402. ";
  403. $_SESSION['xls_table'][] = array("","??????", "???", "????", "????????", "????, ???", "??????? ?? ???", "??????? ????? ??????, ???", "???????. ???????, ???", "??? ??????", "??????", "?? ?????, ???", "???????, ???", "???????, ???????, ???");
  404. $operators = pg_exec('select opr_password, opr_name from public.operators op INNER JOIN public.agents_logs al ON (al.agent=op.opr_id) WHERE 1=1 '.$where.' GROUP BY op.opr_password, op.opr_name ORDER BY op.opr_name ASC');
  405. $i=0;
  406. while($t = pg_fetch_array($operators)){
  407. $ij=0;
  408. do {
  409. $now_date = date("Y-m-d", strtotime("$date + $ij day"));
  410. $ij++;
  411. $next_date = date("Y-m-d", strtotime("$date + $ij day"));
  412. $i++;
  413. $opr_password = $t['opr_password'];
  414. list($recived, $totaltime, $answertime, $reaction, $noanswer, $lost, $timeonline, $timeoffline, $local_count, $local_timer, $hangup) = op_info($t['opr_password'], $now_date, '07:00:00', $next_date, '06:59:59', $service, $call_type);
  415. //if($timeonline!=0)
  416. {
  417. echo "<tr>
  418. <td>$i</td>
  419. <td>".$t['opr_password']."</td>
  420. <td><nobr>".$t['opr_name']."</nobr></td>
  421. <td><nobr>$now_date</nobr></td>
  422. <td>$recived</td>
  423. <td>$totaltime</td>
  424. <td>";
  425. echo ($timeonline)?round($recived/($timeonline/60)):0;
  426. echo "</td>
  427. <td>$answertime</td>
  428. <td>$reaction</td>
  429. <td>$noanswer</td>
  430. <td>$lost</td>
  431. <td>$hangup</td>";
  432. if($recived!=0) echo"<td>".round($hangup/$recived*100)."%</td>";
  433. else echo "<td>0%</td>";
  434. echo"<td>$local_count</td>
  435. <td>$local_timer</td>
  436. <td>$timeonline</td>
  437. <td>$timeoffline</td>
  438. <td>".round((($timeonline-$totaltime)*60-5*$recived)/($recived+1))."</td></tr>
  439. ";
  440. $rto = ($timeonline)?round($recived/($timeonline/60)):0;
  441. $_SESSION['xls_table'][] = array($i,$t['opr_password'], $t['opr_name'], $now_date, $recived, $totaltime, $rto, $answertime, $reaction, $noanswer, $lost, $timeonline, $timeoffline, round((($timeonline-$totaltime)*60-5*$recived)/($recived+1)));
  442. }
  443. } while ($now_date<$datet);
  444. }
  445. echo "</table>";
  446. if(pg_num_rows($operators)==1) {
  447. $ij=0;
  448. do {
  449. $now_date = date("Y-m-d", strtotime("$date + $ij day"));
  450. $ij++;
  451. $next_date = date("Y-m-d", strtotime("$date + $ij day"));
  452. $logs_new = pg_exec('select * from public.agents_logs al JOIN public.operators op ON (al.agent=op.opr_id)
  453. LEFT JOIN public.records r ON (al.record_id=r.record_id)
  454. WHERE (op.opr_password=\''.$opr_password.'\') ANd (al.event=21 OR al.event=22) AND al.dt BETWEEN \''.$now_date.' 06:45:00\' AND \''.$next_date.' 07:14:59\' order by date_trunc(\'second\', al.Dt_begin) Desc, al.event Asc LIMIT 100');
  455. if(pg_num_rows($logs_new)) {
  456. echo '<h3>????-????? '.$now_date.'</h3>';
  457. $_SESSION['xls_table2'] = "";
  458. // echo '<a href="?xls=1&type=2"><img border=0 src="http://stat.isystems.com.ua/img/admin/xls.gif"> ??????? ? Excel</a>';
  459. show_table($logs_new, array(1,1), 2);
  460. }
  461. } while ($now_date<$datet);
  462. }
  463. } elseif(empty($number) && $random!='on') {
  464. echo '<h3>??????? ??????????</h3> <a href="?xls=1"><img border=0 src="http://stat.isystems.com.ua/img/admin/xls.gif"> ??????? ? Excel</a>';
  465. echo "<table border=1><tr>
  466. <td></td>
  467. <td>??????</td>
  468. <td>???</td>
  469. <td><small>????????</small></td>
  470. <td><small>????, ???</small></td>
  471. <td><small>??????? t ??????, ???</small></td>
  472. <td><small>???????. ???????, ???</small></td>
  473. <td><small>??? ??????</small></td>
  474. <td><small>??????</small></td>
  475. <td><small>Hangup</small></td>
  476. <td><small>Hangup ?? ????????</small></td>
  477. <td><small>?????????</small></td>
  478. <td><small>?????????, ???</small></td>
  479. <td><small>?? ?????, ???</small></td>
  480. <td><small>???????, ???</small></td>
  481. <td><small>???????, ???????, ???</small></td></tr>
  482. ";
  483. $_SESSION['xls_table'][] = array("","??????", "???", "????????", "????, ???", "??????? ????? ??????, ???", "???????. ???????, ???", "??? ??????", "??????", "?? ?????, ???", "???????, ???", "???????, ???????, ???");
  484. $operators = pg_exec('select opr_password, opr_name from public.operators op INNER JOIN public.agents_logs al ON (al.agent=op.opr_id) WHERE 1=1 '.$where.' GROUP BY op.opr_password, op.opr_name ORDER BY op.opr_name ASC');
  485. $i=0;
  486. while($t = pg_fetch_array($operators)){
  487. list($recived, $totaltime, $answertime, $reaction, $noanswer, $lost, $timeonline, $timeoffline, $local_count, $local_timer, $hangup) = op_info($t['opr_password'], $date, $time, $datet, $timet, $service, $call_type);
  488. if($totaltime) {
  489. $i++;
  490. echo "<tr>
  491. <td>$i</td>
  492. <td>".$t['opr_password']."</td>
  493. <td><nobr>".$t['opr_name']."</nobr></td>
  494. <td>$recived</td>
  495. <td>$totaltime</td>
  496. <td>$answertime</td>
  497. <td>$reaction</td>
  498. <td>$noanswer</td>
  499. <td>$lost</td>
  500. <td>$hangup</td>";
  501. if($recived!=0) echo"<td>".round($hangup/$recived*100)."%</td>";
  502. else echo "<td>0%</td>";
  503. echo"<td>$local_count</td>
  504. <td>$local_timer</td>
  505. <td>$timeonline</td>
  506. <td>$timeoffline</td>
  507. <td>".round((($timeonline-$totaltime)*60-5*$recived)/($recived+1))."</td></tr>
  508. ";
  509. $_SESSION['xls_table'][] = array($i,$t['opr_password'], $t['opr_name'], $recived, $totaltime, $answertime, $reaction, $noanswer, $lost, $timeonline, $timeoffline, round((($timeonline-$totaltime)*60-(5*$recived))/($recived+1)));
  510. }
  511. }
  512. echo "</table>";
  513. }
  514. // if((empty($search) || $search!='all' || !empty($number) || !empty($service))) {
  515. // if((empty($search) || $search!='all' || !empty($number))) {
  516. if(!$more_than_day || $random=='on' || !empty($number))
  517. if( empty($search) || $search!='all' || $random=='on' || !empty($number) ) {
  518. if(!empty($service)) $where.="AND (al.acdgroup = '$service')";
  519. if(!empty($number)) $where.="AND (al.callid = '$number')";
  520. if( $call_type ) {
  521. $where.= ($call_type=='in')? " AND (al.event=10)" : " AND (al.event=31)";
  522. }
  523. $limit = "";
  524. $order_by = "ORDER BY al.Dt_begin DESC, al.Dt Desc";
  525. if($random=="on"){
  526. if(is_numeric($random_count)) $limit = "LIMIT $random_count";
  527. $order_by = "ORDER BY RANDOM()";
  528. }
  529. $logs_new = pg_exec('select * from public.agents_logs al JOIN public.operators op ON (al.agent=op.opr_id)
  530. LEFT JOIN public.records r ON (al.record_id=r.record_id)
  531. WHERE (al.event=10 OR al.event=52 OR al.event=53 OR al.event=31 OR al.event=32) '.$where.' '.$order_by.' '.$limit);
  532. echo '<h3>????????</h3>';
  533. $_SESSION['xls_table'] = "";
  534. echo '<a href="?xls=1"><img border=0 src="http://stat.isystems.com.ua/img/admin/xls.gif"> ??????? ? Excel</a>';
  535. if(!empty($number) || $search=='all') {
  536. show_table($logs_new, array(0,0,1));
  537. } else {
  538. show_table($logs_new);
  539. }
  540. }
  541. }
  542. include_once("db_disconnect.php");
  543. echo "</td></tr></table>";
  544. }
  545. }
  546. ?>