Ejemplo n.º 1
0
 function zb_AsteriskGetCDR($from, $to)
 {
     global $asteriskHost, $asteriskDb, $asteriskTable, $asteriskLogin, $asteriskPassword, $asteriskCacheTime;
     $from = mysql_real_escape_string($from);
     $to = mysql_real_escape_string($to);
     $asteriskTable = mysql_real_escape_string($asteriskTable);
     $cachePath = 'exports/';
     //caching
     $cacheUpdate = true;
     $cacheName = $from . $to;
     $cacheName = md5($cacheName);
     $cacheName = $cachePath . $cacheName . '.asterisk';
     $cachetime = time() - $asteriskCacheTime * 60;
     if (file_exists($cacheName)) {
         if (filemtime($cacheName) > $cachetime) {
             $rawResult = file_get_contents($cacheName);
             $rawResult = unserialize($rawResult);
             $cacheUpdate = false;
         } else {
             $cacheUpdate = true;
         }
     } else {
         $cacheUpdate = true;
     }
     if ($cacheUpdate) {
         //connect to Asterisk database and fetch some data
         $query = "select * from `" . $asteriskTable . "` where `calldate` BETWEEN '" . $from . " 00:00:00' AND '" . $to . " 23:59:59'";
         $rawResult = zb_AsteriskQuery($query);
         $cacheContent = serialize($rawResult);
         file_put_contents($cacheName, $cacheContent);
     }
     if (!empty($rawResult)) {
         //here is data parsing
         zb_AsteriskParseCDR($rawResult);
     } else {
         show_window(__('Error'), __('Empty reply received'));
     }
 }
Ejemplo n.º 2
0
 /**
  * Gets Asterisk CDR data from database and manage cache
  * 
  * @param string $from - start date
  * @param string $to  - end date
  * 
  * @return void
  */
 function zb_AsteriskGetCDR($from, $to)
 {
     global $asteriskHost, $asteriskDb, $asteriskTable, $asteriskLogin, $asteriskPassword, $asteriskCacheTime;
     global $user_login;
     $from = mysql_real_escape_string($from);
     $to = mysql_real_escape_string($to);
     $asteriskTable = mysql_real_escape_string($asteriskTable);
     $cachePath = 'exports/';
     //caching
     $cacheUpdate = true;
     $cacheName = $from . $to;
     $cacheName = md5($cacheName);
     $cacheName = $cachePath . $cacheName . '.asterisk';
     $cachetime = time() - $asteriskCacheTime * 60;
     if (file_exists($cacheName)) {
         if (filemtime($cacheName) > $cachetime) {
             $rawResult = file_get_contents($cacheName);
             $rawResult = unserialize($rawResult);
             $cacheUpdate = false;
         } else {
             $cacheUpdate = true;
         }
     } else {
         $cacheUpdate = true;
     }
     if (isset($user_login)) {
         //connect to Asterisk database and fetch some data
         $phonesQueryData = zb_LoginByNumberQuery();
         // why? why use this callback three times?
         $phone = $phonesQueryData[$user_login][0];
         $mobile = $phonesQueryData[$user_login][1];
         $dop_mobile = $phonesQueryData[$user_login][2];
         if (!empty($phone) and empty($mobile) and empty($dop_mobile)) {
             $query = "select * from `" . $asteriskTable . "` where `calldate` BETWEEN '" . $from . " 00:00:00' AND '" . $to . " 23:59:59' AND (`src` LIKE '%" . $phone . "' OR `dst` LIKE '%" . $phone . "')";
         } elseif (!empty($mobile) and empty($phone) and empty($dop_mobile)) {
             $query = "select * from `" . $asteriskTable . "` where `calldate` BETWEEN '" . $from . " 00:00:00' AND '" . $to . " 23:59:59' AND (`src` LIKE '%" . $mobile . "' OR `dst` LIKE '%" . $mobile . "')";
         } elseif (!empty($dop_mobile) and empty($phone) and empty($mobile)) {
             $query = "select * from `" . $asteriskTable . "` where `calldate` BETWEEN '" . $from . " 00:00:00' AND '" . $to . " 23:59:59' AND (`src` LIKE '%" . $dop_mobile . "' OR `dst` LIKE '%" . $dop_mobile . "')";
         } elseif (!empty($phone) and !empty($mobile) and empty($dop_mobile)) {
             $query = "select * from `" . $asteriskTable . "` where `calldate` BETWEEN '" . $from . " 00:00:00' AND '" . $to . " 23:59:59' AND (`src` LIKE '%" . $phone . "' OR `dst` LIKE '%" . $phone . "' OR `src` LIKE '%" . $mobile . "' OR `dst` LIKE '%" . $mobile . "')";
         } elseif (!empty($phone) and !empty($dop_mobile) and empty($mobile)) {
             $query = "select * from `" . $asteriskTable . "` where `calldate` BETWEEN '" . $from . " 00:00:00' AND '" . $to . " 23:59:59' AND (`src` LIKE '%" . $phone . "' OR `dst` LIKE '%" . $phone . "' OR `src` LIKE '%" . $dop_mobile . "' OR `dst` LIKE '%" . $dop_mobile . "')";
         } elseif (!empty($mobile) and !empty($dop_mobile) and empty($phone)) {
             $query = "select * from `" . $asteriskTable . "` where `calldate` BETWEEN '" . $from . " 00:00:00' AND '" . $to . " 23:59:59' AND (`src` LIKE '%" . $mobile . "' OR `dst` LIKE '%" . $mobile . "' OR `src` LIKE '%" . $dop_mobile . "' OR `dst` LIKE '%" . $dop_mobile . "')";
         } elseif (!empty($phone) and !empty($mobile) and !empty($dop_mobile)) {
             $query = "select * from `" . $asteriskTable . "` where `calldate` BETWEEN '" . $from . " 00:00:00' AND '" . $to . " 23:59:59' AND (`src` LIKE '%" . $phone . "' OR `dst` LIKE '%" . $phone . "' OR `src` LIKE '%" . $mobile . "' OR `dst` LIKE '%" . $mobile . "' OR `src` LIKE '%" . $dop_mobile . "' OR `dst` LIKE '%" . $dop_mobile . "')";
         }
         $rawResult = zb_AsteriskQuery($query);
         $cacheContent = serialize($rawResult);
     } elseif (wf_CheckPost(array('countnum')) and !isset($user_login)) {
         $query = "select *,count(`src`) as `countnum`  from `" . $asteriskTable . "` where `calldate` BETWEEN '" . $from . " 00:00:00' AND '" . $to . " 23:59:59' GROUP BY `src`";
         $rawResult = zb_AsteriskQuery($query);
         $cacheContent = serialize($rawResult);
     } elseif ($cacheUpdate and !isset($user_login)) {
         $query = "select * from `" . $asteriskTable . "` where `calldate` BETWEEN '" . $from . " 00:00:00' AND '" . $to . " 23:59:59' ORDER BY `calldate` DESC";
         $rawResult = zb_AsteriskQuery($query);
         $cacheContent = serialize($rawResult);
         file_put_contents($cacheName, $cacheContent);
     }
     if (!empty($rawResult)) {
         //here is data parsing
         zb_AsteriskParseCDR($rawResult);
     } else {
         show_error(__('Empty reply received'));
     }
 }