Beispiel #1
0
 /**
  * Askozia PBX data fetching and processing
  * 
  * @return void
  */
 protected function preprocessAskoziaData()
 {
     if ($this->askoziaFlag) {
         if (!empty($this->askoziaUrl) and !empty($this->askoziaLogin) and !empty($this->askoziaPassword)) {
             $callsTmp = array();
             $normalCalls = array();
             //working time setup
             $rawWorkTime = $this->altCfg['WORKING_HOURS'];
             $rawWorkTime = explode('-', $rawWorkTime);
             $workStartTime = $rawWorkTime[0];
             $workEndTime = $rawWorkTime[1];
             $fields = array('extension_number' => 'all', 'cdr_filter' => 'incomingoutgoing', 'period_from' => $this->curmonth . '-01', 'period_to' => curdate(), 'date_format' => 'Y-m-d', 'time_format' => 'H:i:s', 'page_format' => 'A4', 'SubmitCSVCDR' => 'Download CSV');
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_URL, $this->askoziaUrl . '/status_cdr.php');
             curl_setopt($ch, CURLOPT_USERPWD, $this->askoziaLogin . ":" . $this->askoziaPassword);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
             $rawResult = curl_exec($ch);
             curl_close($ch);
             if (!empty($rawResult)) {
                 $callsTmp = explodeRows($rawResult);
                 if (!empty($callsTmp)) {
                     foreach ($callsTmp as $eachline) {
                         $explode = explode(';', $eachline);
                         //in 2.2.8 delimiter changed from ," to ;
                         if (!empty($eachline)) {
                             $normalCalls[] = str_replace('"', '', $explode);
                         }
                     }
                 }
                 if (!empty($normalCalls)) {
                     unset($normalCalls[0]);
                     foreach ($normalCalls as $io => $each) {
                         if ($each[16] != 'outbound') {
                             $startTime = explode(' ', $each[9]);
                             @($startTime = $startTime[1]);
                             //only working time
                             if (zb_isTimeBetween($workStartTime, $workEndTime, $startTime)) {
                                 if (ispos($each[14], 'ANSWERED') and !ispos($each[7], 'VoiceMail')) {
                                     $this->storeTmp['a_totalanswered']++;
                                 }
                                 $this->storeTmp['a_totalcalls']++;
                                 //call duration in seconds increment
                                 $this->storeTmp['a_totalcallsduration'] += $each[13];
                             }
                         }
                     }
                     //average calls duration
                     $this->storeTmp['a_averagecallduration'] = $this->storeTmp['a_totalcallsduration'] / $this->storeTmp['a_totalanswered'];
                 }
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Renders parsed calls data
  * 
  * @global array $altcfg
  * @param string $data
  * 
  * @return void
  */
 function zb_AskoziaParseCallHistory($data)
 {
     global $altcfg;
     $debugFlag = false;
     $answeredFlag = true;
     $prevTimeStart = '';
     $prevTimeEnd = '';
     if (isset($altcfg['ASKOZIA_DEBUG'])) {
         if ($altcfg['ASKOZIA_DEBUG']) {
             $debugFlag = true;
         }
     }
     //working time setup
     $rawWorkTime = $altcfg['WORKING_HOURS'];
     $rawWorkTime = explode('-', $rawWorkTime);
     $workStartTime = $rawWorkTime[0];
     $workEndTime = $rawWorkTime[1];
     $normalData = array();
     $callersData = array();
     $data = explodeRows($data);
     if (!empty($data)) {
         foreach ($data as $eachline) {
             $explode = explode(';', $eachline);
             //in 2.2.8 delimiter changed from ," to ;
             if (!empty($eachline)) {
                 $normalData[] = str_replace('"', '', $explode);
             }
         }
     }
     //custom caller options
     if (isset($altcfg['ASKOZIA_CUSTOM'])) {
         if (!empty($altcfg['ASKOZIA_CUSTOM'])) {
             // 0 - internal peers
             // 1 - external gateways
             // 2 - group prefix
             // 3 - parking
             $customCfg = explode(',', $altcfg['ASKOZIA_CUSTOM']);
         } else {
             $customCfg = array();
         }
     } else {
         $customCfg = array();
     }
     if (!empty($normalData)) {
         $totalTime = 0;
         $callsCounter = 0;
         $answerCounter = 0;
         $noAnswerCounter = 0;
         $WorkHoursAnswerCounter = 0;
         $WorkHoursNoAnswerCounter = 0;
         $busycount = 0;
         $chartData = array();
         $cells = wf_TableCell('#');
         $cells .= wf_TableCell(__('Time'));
         $cells .= wf_TableCell(__('From'));
         $cells .= wf_TableCell(__('To'));
         $cells .= wf_TableCell(__('Picked up'));
         $cells .= wf_TableCell(__('Type'));
         $cells .= wf_TableCell(__('Status'));
         $cells .= wf_TableCell(__('Talk time'));
         $rows = wf_TableRow($cells, 'row1');
         foreach ($normalData as $io => $each) {
             //fix parsing for askozia 2.2.8
             if ($each[0] != 'accountcode') {
                 $callsCounter++;
                 $debugData = wf_tag('pre') . print_r($each, true) . wf_tag('pre', true);
                 $startTime = explode(' ', $each[9]);
                 @($startDate = $startTime[0]);
                 @($startTime = $startTime[1]);
                 @($startHour = date("H:00:00", strtotime($startTime)));
                 $endTime = explode(' ', $each[11]);
                 @($endTime = $endTime[1]);
                 $answerTime = explode(' ', $each[10]);
                 @($answerTime = $answerTime[1]);
                 $tmpStats = __('Taken up the phone') . ': ' . $answerTime . "\n";
                 $tmpStats .= __('End of call') . ': ' . $endTime;
                 $sessionTimeStats = wf_tag('abbr', false, '', 'title="' . $tmpStats . '"');
                 $sessionTimeStats .= $startTime;
                 $sessionTimeStats .= wf_tag('abbr', true);
                 $callDirection = '';
                 if ($each[16] == 'outbound') {
                     $toNumber = $each[2];
                     $callDirection = wf_img('skins/calls/outgoing.png') . ' ';
                 } else {
                     $toNumber = $each[18];
                     $callDirection = wf_img('skins/calls/incoming.png') . ' ';
                 }
                 if ($debugFlag) {
                     $callIdData = wf_modal($callsCounter, $callsCounter, $debugData, '', '500', '600');
                 } else {
                     $callIdData = $callsCounter;
                 }
                 $cells = wf_TableCell($callIdData, '', '', 'sorttable_customkey="' . $callsCounter . '"');
                 $cells .= wf_TableCell($callDirection . $sessionTimeStats, '', '', 'sorttable_customkey="' . strtotime($each[9]) . '"');
                 $cells .= wf_TableCell(zb_AskoziaGetNumAlias($each[1]));
                 $cells .= wf_TableCell(zb_AskoziaGetNumAlias($toNumber));
                 $receiveCid = '';
                 if (!empty($each[6])) {
                     $tmpRcid = explode('-', $each[6]);
                     @($receiveCid = vf($tmpRcid[0], 3));
                 }
                 $cells .= wf_TableCell(zb_AskoziaGetNumAlias($receiveCid));
                 $CallType = __('Dial');
                 if (ispos($each[3], 'internal-caller-transfer')) {
                     $CallType = __('Call transfer');
                 }
                 if (ispos($each[7], 'VoiceMail')) {
                     $CallType = __('Voice mail');
                 }
                 $cells .= wf_TableCell($CallType);
                 $callStatus = $each[14];
                 $statusIcon = '';
                 if (ispos($each[14], 'ANSWERED') and !ispos($each[7], 'VoiceMail')) {
                     $answeredFlag = true;
                     $callStatus = __('Answered');
                     $statusIcon = wf_img('skins/calls/phone_green.png');
                     $answerCounter++;
                     //work time controls
                     if (zb_isTimeBetween($workStartTime, $workEndTime, $startTime)) {
                         $WorkHoursAnswerCounter++;
                     }
                     if (isset($chartData[$startDate . ' ' . $startHour]['answered'])) {
                         $chartData[$startDate . ' ' . $startHour]['answered']++;
                     } else {
                         $chartData[$startDate . ' ' . $startHour]['answered'] = 1;
                     }
                 }
                 if (ispos($each[14], 'NO ANSWER') or ispos($each[7], 'VoiceMail')) {
                     $answeredFlag = false;
                     $callStatus = __('No answer');
                     $statusIcon = wf_img('skins/calls/phone_red.png');
                     //only incoming calls is unanswered
                     if ($each[16] != 'outbound') {
                         $noAnswerCounter++;
                         if (zb_isTimeBetween($workStartTime, $workEndTime, $startTime)) {
                             $WorkHoursNoAnswerCounter++;
                         }
                     }
                     if (isset($chartData[$startDate . ' ' . $startHour]['noanswer'])) {
                         $chartData[$startDate . ' ' . $startHour]['noanswer']++;
                     } else {
                         $chartData[$startDate . ' ' . $startHour]['noanswer'] = 1;
                     }
                 }
                 if (ispos($each[14], 'BUSY')) {
                     $callStatus = __('Busy');
                     $statusIcon = wf_img('skins/calls/phone_yellow.png');
                 }
                 if (ispos($each[14], 'FAILED')) {
                     $callStatus = __('Failed');
                     $statusIcon = wf_img('skins/calls/phone_fail.png');
                 }
                 $cells .= wf_TableCell($statusIcon . ' ' . $callStatus);
                 $speekTimeRaw = $each[13];
                 $totalTime = $totalTime + $each[13];
                 $speekTime = zb_AskoziaFormatTime($speekTimeRaw);
                 //current caller stats
                 if (isset($callersData[$each[1]])) {
                     $callersData[$each[1]]['calls'] = $callersData[$each[1]]['calls'] + 1;
                     $callersData[$each[1]]['time'] = $callersData[$each[1]]['time'] + $speekTimeRaw;
                 } else {
                     $callersData[$each[1]]['calls'] = 1;
                     $callersData[$each[1]]['time'] = $speekTimeRaw;
                 }
                 if (isset($callersData[$each[2]])) {
                     $callersData[$each[2]]['calls'] = $callersData[$each[2]]['calls'] + 1;
                     $callersData[$each[2]]['time'] = $callersData[$each[2]]['time'] + $speekTimeRaw;
                 } else {
                     $callersData[$each[2]]['calls'] = 1;
                     $callersData[$each[2]]['time'] = $speekTimeRaw;
                 }
                 if (!empty($receiveCid)) {
                     if (isset($callersData[$receiveCid])) {
                         $callersData[$receiveCid]['calls'] = $callersData[$receiveCid]['calls'] + 1;
                         $callersData[$receiveCid]['time'] = $callersData[$receiveCid]['time'] + $speekTimeRaw;
                     } else {
                         $callersData[$receiveCid]['calls'] = 1;
                         $callersData[$receiveCid]['time'] = $speekTimeRaw;
                     }
                 }
                 $cells .= wf_TableCell($speekTime, '', '', 'sorttable_customkey="' . $each[13] . '"');
                 //default rowclass
                 $rowClass = 'row3';
                 //non answered calls coloring
                 if ($answeredFlag == false) {
                     $rowClass = 'ukvbankstadup';
                 }
                 //time range processing
                 $curTimeStart = date("H:i:s", strtotime($each[9]));
                 $curTimeEnd = date("H:i:s", strtotime($each[11]));
                 if (empty($prevTimeStart) and empty($prevTimeEnd)) {
                     $prevTimeStart = $curTimeStart;
                     $prevTimeEnd = $curTimeEnd;
                 } else {
                     if ($answeredFlag == false) {
                         if (zb_isTimeBetween($prevTimeStart, $prevTimeEnd, $curTimeStart, true)) {
                             $rowClass = 'undone';
                             if (zb_isTimeBetween($workStartTime, $workEndTime, $startTime)) {
                                 $busycount++;
                             }
                         }
                     }
                     $prevTimeStart = $curTimeStart;
                     if (strtotime($curTimeEnd) > strtotime($prevTimeEnd)) {
                         $prevTimeEnd = $curTimeEnd;
                     }
                 }
                 $rows .= wf_TableRow($cells, $rowClass);
             }
         }
         if (!empty($callersData)) {
             if (!empty($customCfg)) {
                 $gcells = wf_TableCell(__('Phone'));
                 $gcells .= wf_TableCell(__('Total calls'));
                 $gcells .= wf_TableCell(__('Time'));
                 $grows = wf_TableRow($gcells, 'row1');
             }
             foreach ($callersData as $cix => $eachcdat) {
                 if (!empty($customCfg)) {
                     if (zb_AskoziaCheckPrefix($customCfg[0], $cix) and strlen($cix) < 4) {
                         $gcells = wf_TableCell(zb_AskoziaGetNumAlias($cix));
                         $gcells .= wf_TableCell($eachcdat['calls']);
                         $gcells .= wf_TableCell(zb_AskoziaFormatTime($eachcdat['time']), '', '', 'sorttable_customkey="' . $eachcdat['time'] . '"');
                         $grows .= wf_TableRow($gcells, 'row3');
                     }
                 }
             }
         }
         //total time stats
         $result = '';
         if (!empty($chartData)) {
             if (sizeof($chartData) >= 2) {
                 $gdata = __('Date') . ',' . __('Total') . ',' . __('Answered') . ',' . __('No answer') . "\n";
                 foreach ($chartData as $io => $each) {
                     @($gdata .= $io . ',' . ($each['answered'] + $each['noanswer']) . ',' . $each['answered'] . ',' . $each['noanswer'] . "\n");
                 }
                 $result .= wf_tag('div', false, '', '');
                 $result .= wf_tag('h2') . __('Stats') . wf_tag('h2', true) . wf_tag('br');
                 $result .= wf_Graph($gdata, '800', '200', false);
                 $result .= wf_tag('div', true);
                 $result .= wf_delimiter();
             }
         }
         $result .= __('Time spent on calls') . ': ' . zb_AskoziaFormatTime($totalTime) . wf_tag('br');
         $result .= __('Total') . ': ' . __('Answered') . ' / ' . __('No answer') . ': ' . $answerCounter . ' / ' . $noAnswerCounter . ' (' . zb_AskoziaPercentValue($answerCounter + $noAnswerCounter, $answerCounter) . '%)' . wf_tag('br');
         $result .= wf_tag('b') . __('Working hours') . ': ' . __('Answered') . ' / ' . __('No answer') . ': ' . $WorkHoursAnswerCounter . ' / ' . $WorkHoursNoAnswerCounter . ' (' . zb_AskoziaPercentValue($WorkHoursAnswerCounter + $WorkHoursNoAnswerCounter, $WorkHoursAnswerCounter) . '%)' . wf_tag('b', true) . wf_tag('br');
         $result .= __('Not working hours') . ': ' . __('Answered') . ' / ' . __('No answer') . ': ' . ($answerCounter - $WorkHoursAnswerCounter) . ' / ' . ($noAnswerCounter - $WorkHoursNoAnswerCounter) . ' (' . zb_AskoziaPercentValue($answerCounter - $WorkHoursAnswerCounter + ($noAnswerCounter - $WorkHoursNoAnswerCounter), $answerCounter - $WorkHoursAnswerCounter) . '%)' . wf_tag('br');
         $result .= __('Missing calls because of overlap with the previous by time') . ' (' . __('Working hours') . '): ' . $busycount . wf_tag('br');
         $result .= __('Total calls') . ': ' . $callsCounter;
         if (!empty($customCfg)) {
             @($result .= wf_delimiter() . wf_TableBody($grows, '100%', '0', 'sortable') . wf_delimiter());
         }
         $result .= wf_TableBody($rows, '100%', '0', 'sortable');
         show_window('', $result);
     }
 }