diff --git a/RELEASE b/RELEASE index 6ee560ca4..e4d713d45 100644 --- a/RELEASE +++ b/RELEASE @@ -1 +1 @@ -0.7.9 rev 5174 +0.7.9 rev 5176 diff --git a/modules/general/asterisk/index.php b/modules/general/asterisk/index.php index 24f8ff0c4..cbd1f3ec8 100755 --- a/modules/general/asterisk/index.php +++ b/modules/general/asterisk/index.php @@ -1,483 +1,648 @@ getAlter(); +$mysqlcfg = rcms_parse_ini_file(CONFIG_PATH . "mysql.ini"); if ($altcfg['ASTERISK_ENABLED']) { - -/* - * Get numbers aliases from database, or set default empty array - * - * @return array - */ - function zb_AsteriskGetNumAliases() { - $result=array(); - $rawAliases= zb_StorageGet('ASTERISK_NUMALIAS'); - if (empty($rawAliases)) { - $newAliasses= serialize($result); - $newAliasses= base64_encode($newAliasses); - zb_StorageSet('ASTERISK_NUMALIAS', $newAliasses); - } else { - $readAlias= base64_decode($rawAliases); - $readAlias= unserialize($readAlias); - $result=$readAlias; + if (isset($_GET['username'])) { + $user_login = vf($_GET['username']); + // Profile: + $profile = new UserProfile($user_login); + show_window(__('User profile'), $profile->render()); + if ($altcfg['ADCOMMENTS_ENABLED'] and isset($_GET['addComments'])) { + $adcomments = new ADcomments('ASTERISK'); + show_window(__('Additional comments'), $adcomments->renderComments($_GET['addComments'])); + } } - return ($result); -} -/* - * Gets Asterisk config from DB, or sets default values - * - * @return array - */ -function zb_AsteriskGetConf() { - $result=array(); - $emptyArray=array(); - //getting url - $host= zb_StorageGet('ASTERISK_HOST'); - if (empty($host)) { - $host='localhost'; - zb_StorageSet('ASTERISK_HOST', $host); - } - //getting login - $login= zb_StorageGet('ASTERISK_LOGIN'); - if (empty($login)) { - $login='asterisk'; - zb_StorageSet('ASTERISK_LOGIN', $login); - } - - //getting DB name - $db= zb_StorageGet('ASTERISK_DB'); - if (empty($db)) { - $db='asteriskdb'; - zb_StorageSet('ASTERISK_DB', $db); - } - //getting CDR table name - $table= zb_StorageGet('ASTERISK_TABLE'); - if (empty($table)) { - $table='cdr'; - zb_StorageSet('ASTERISK_TABLE', $table); - } - - //getting password - $password= zb_StorageGet('ASTERISK_PASSWORD'); - if (empty($password)) { - $password='password'; - zb_StorageSet('ASTERISK_PASSWORD', $password); - } - //getting caching time - $cache= zb_StorageGet('ASTERISK_CACHETIME'); - if (empty($cache)) { - $cache='1'; - zb_StorageSet('ASTERISK_CACHETIME', $cache); + /** + * Get numbers aliases from database, or set default empty array + * + * @return array + */ + function zb_AsteriskGetNumAliases() { + $result = array(); + $rawAliases = zb_StorageGet('ASTERISK_NUMALIAS'); + if (empty($rawAliases)) { + $newAliasses = serialize($result); + $newAliasses = base64_encode($newAliasses); + zb_StorageSet('ASTERISK_NUMALIAS', $newAliasses); + } else { + $readAlias = base64_decode($rawAliases); + $readAlias = unserialize($readAlias); + $result = $readAlias; + } + return ($result); } - - $result['host']=$host; - $result['db']=$db; - $result['table']=$table; - $result['login']=$login; - $result['password']=$password; - $result['cachetime']=$cache; - return ($result); -} -/* - * Converts per second time values to human-readable format - * - * @param $seconds - time interval in seconds - * - * @return string - */ -function zb_AsteriskFormatTime($seconds) { -$init=$seconds; -$hours = floor($seconds / 3600); -$minutes = floor(($seconds / 60) % 60); -$seconds = $seconds % 60; - -if ($init<3600) { - //less than 1 hour - if ($init<60) { - //less than minute - $result=$seconds.' '.__('sec.'); - } else { - //more than one minute - $result=$minutes.' '.__('minutes').' '.$seconds.' '.__('seconds'); + /** + * Gets Asterisk config from DB, or sets default values + * + * @return array + */ + function zb_AsteriskGetConf() { + $result = array(); + $emptyArray = array(); + //getting url + $host = zb_StorageGet('ASTERISK_HOST'); + if (empty($host)) { + $host = 'localhost'; + zb_StorageSet('ASTERISK_HOST', $host); + } + //getting login + $login = zb_StorageGet('ASTERISK_LOGIN'); + if (empty($login)) { + $login = 'asterisk'; + zb_StorageSet('ASTERISK_LOGIN', $login); + } + + //getting DB name + $db = zb_StorageGet('ASTERISK_DB'); + if (empty($db)) { + $db = 'asteriskdb'; + zb_StorageSet('ASTERISK_DB', $db); + } + //getting CDR table name + $table = zb_StorageGet('ASTERISK_TABLE'); + if (empty($table)) { + $table = 'cdr'; + zb_StorageSet('ASTERISK_TABLE', $table); + } + + //getting password + $password = zb_StorageGet('ASTERISK_PASSWORD'); + if (empty($password)) { + $password = 'password'; + zb_StorageSet('ASTERISK_PASSWORD', $password); + } + //getting caching time + $cache = zb_StorageGet('ASTERISK_CACHETIME'); + if (empty($cache)) { + $cache = '1'; + zb_StorageSet('ASTERISK_CACHETIME', $cache); + } + + $result['host'] = $host; + $result['db'] = $db; + $result['table'] = $table; + $result['login'] = $login; + $result['password'] = $password; + $result['cachetime'] = $cache; + return ($result); } - -} else { - //more than hour - $result=$hours.' '.__('hour').' '.$minutes.' '.__('minutes').' '.$seconds.' '.__('seconds'); -} -return ($result); -} + /** + * Converts per second time values to human-readable format + * + * @param int $seconds - time interval in seconds + * + * @return string + */ + function zb_AsteriskFormatTime($seconds) { + $init = $seconds; + $hours = floor($seconds / 3600); + $minutes = floor(($seconds / 60) % 60); + $seconds = $seconds % 60; + + if ($init < 3600) { + //less than 1 hour + if ($init < 60) { + //less than minute + $result = $seconds . ' ' . __('sec.'); + } else { + //more than one minute + $result = $minutes . ' ' . __('minutes') . ' ' . $seconds . ' ' . __('seconds'); + } + } else { + //more than hour + $result = $hours . ' ' . __('hour') . ' ' . $minutes . ' ' . __('minutes') . ' ' . $seconds . ' ' . __('seconds'); + } + return ($result); + } -/* - * Returns human readable alias from phone book by phone number - * - * @param $number - phone number - * - * @return string - */ -function zb_AsteriskGetNumAlias($number) { - global $numAliases; - - if (!empty($numAliases)) { - if (isset($numAliases[$number])) { - return($number.' - '.$numAliases[$number]); + /** + * Returns human readable alias from phone book by phone number + * + * @param string $number - phone number + * + * @return string + */ + function zb_AsteriskGetNumAlias($number) { + global $numAliases; + + if (!empty($numAliases)) { + if (isset($numAliases[$number])) { + return($number . ' - ' . $numAliases[$number]); + } else { + return ($number); + } } else { return ($number); } - } else { - return ($number); } -} -/* - * Checks first digit in some number by some prefix - * - * @param $prefix - search prefix - * @param $callerid - phone number - * - * @return bool - */ -function zb_AsteriskCheckPrefix($prefix,$callerid) { - if (substr($callerid, 0, 1)==$prefix) { - return (true); - } else { - return (false); + /** + * Checks first digit in some number by some prefix + * + * @param string $prefix - search prefix + * @param string $callerid - phone number + * + * @return bool + */ + function zb_AsteriskCheckPrefix($prefix, $callerid) { + if (substr($callerid, 0, 1) == $prefix) { + return (true); + } else { + return (false); + } } -} -/* - * Parse Asterisk RAW CDR data - * - * @param data - raw CDR - * - * @return void - */ - -//need review with real CDR data -function zb_AsteriskParseCDR($data) { - global $altcfg; - $normalData=$data; - - - if (!empty($normalData)) { - $totalTime=0; - $callsCounter=0; - $cells= wf_TableCell('#'); - $cells.= wf_TableCell(__('Time')); - $cells.= wf_TableCell(__('From')); - $cells.= wf_TableCell(__('To')); - $cells.= wf_TableCell(__('Type')); - $cells.= wf_TableCell(__('Status')); - $cells.= wf_TableCell(__('Talk time')); - - $rows= wf_TableRow($cells, 'row1'); - - foreach ($normalData as $io=>$each) { - $callsCounter++; - $debugData= wf_tag('pre').print_r($each, true). wf_tag('pre', true); - - $startTime= explode(' ', $each['calldate']); - @$startTime=$startTime[1]; - $tmpTime= strtotime($each['calldate']); - $endTime=$tmpTime+$each['duration']; - $endTime=date("H:i:s",$endTime); - $answerTime=$tmpTime+($each['duration']-$each['billsec']); - $answerTime=date("H:i:s",$answerTime); - $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=''; - - - - $cells= wf_TableCell(wf_modal($callsCounter, $callsCounter, $debugData, '', '500', '600'),'','','sorttable_customkey="'.$callsCounter.'"'); - $cells.= wf_TableCell($sessionTimeStats,'','','sorttable_customkey="'. $tmpTime.'"'); - $cells.= wf_TableCell(zb_AsteriskGetNumAlias($each['src'])); - $cells.= wf_TableCell(zb_AsteriskGetNumAlias($each['dst'])); - $CallType=__('Dial'); - if (ispos($each['lastapp'], 'internal-caller-transfer')) { - $CallType=__('Call transfer'); - } - - - - - $cells.= wf_TableCell($CallType); - - $callStatus=$each['disposition']; - $statusIcon=''; - if (ispos($each['disposition'], 'ANSWERED')) { - $callStatus=__('Answered'); - $statusIcon= wf_img('skins/calls/phone_green.png'); - } - if (ispos($each['disposition'], 'NO ANSWER')) { - $callStatus=__('No answer'); - $statusIcon= wf_img('skins/calls/phone_red.png'); - } - - if (ispos($each['disposition'], 'BUSY')) { - $callStatus=__('Busy'); - $statusIcon= wf_img('skins/calls/phone_yellow.png'); - } - - if (ispos($each['disposition'], 'FAILED')) { - $callStatus=__('Failed'); - $statusIcon= wf_img('skins/calls/phone_fail.png'); - } - - $cells.= wf_TableCell($statusIcon.' '.$callStatus); - $speekTime=$each['billsec']; - $totalTime=$totalTime+$each['billsec']; - $speekTime= zb_AsteriskFormatTime($speekTime); - - - - $cells.= wf_TableCell($speekTime,'','','sorttable_customkey="'.$each['billsec'].'"'); - - - $rows.= wf_TableRow($cells, 'row3'); - } - - $result= wf_TableBody($rows, '100%', '0', 'sortable'); - $result.=__('Time spent on calls').': '. zb_AsteriskFormatTime($totalTime). wf_tag('br'); - $result.=__('Total calls').': '.$callsCounter; - show_window('',$result); - } -} + /** + * Function add by Pautina - nice and what it do? + * + * @return array + */ + function zb_LoginByNumberQuery() { + global $mysqlcfg; + global $user_login; + global $result_a; + if (!isset($result_a) and empty($result_a)) { + $loginDB = new mysqli($mysqlcfg['server'], $mysqlcfg['username'], $mysqlcfg['password'], $mysqlcfg['db']); + if ($loginDB->connect_error) { + die('Ошибка подключения (' . $loginDB->connect_errno . ') ' + . $loginDB->connect_error); + } + if (isset($user_login)) { + $query = "SELECT `phones`.`login`,`phone`,`mobile`,`content` FROM `phones` LEFT JOIN `cfitems` ON `phones`.`login`=`cfitems`.`login` WHERE `phones`.`login`='" . $user_login . "'"; + } else { + $query = "SELECT `phones`.`login`,`phone`,`mobile`,`content` FROM `phones` LEFT JOIN `cfitems` ON `phones`.`login`=`cfitems`.`login`"; + } + $result = $loginDB->query($query); + $result_a = array(); + while ($row = $result->fetch_assoc()) { + $result_a[$row['login']] = array($row['phone'], $row['mobile'], $row['content']); + } + mysqli_free_result($result); + $loginDB->close(); + //nahera eto? + //echo $test_count; + //undefined variable + //$test_count++; + } + return ($result_a); + } -/* - * Another database query execution - * - * @param $query - query to execute - * - * @return array - */ - -function zb_AsteriskQuery($query) { - global $asteriskHost,$asteriskDb,$asteriskTable,$asteriskLogin,$asteriskPassword,$asteriskCacheTime; - $asteriskDB=new DbConnect($asteriskHost, $asteriskLogin, $asteriskPassword, $asteriskDb, $error_reporting = true, $persistent = false); - $asteriskDB->open() or die($asteriskDB->error()); - $result = array(); - $asteriskDB->query('SET NAMES utf8;'); - $asteriskDB->query($query); - while ($row = $asteriskDB->fetchassoc()) { - $result[] = $row; + /** + * Gets Ubilling user login by number mobile + * + * @pram string $number - start date + * + * @return void + */ + $allrealnames = zb_UserGetAllRealnames(); + $alladdress = zb_AddressGetFulladdresslist(); + + /** + * Gets user login by phone number + * + * @global array $allrealnames + * @global array $alladdress + * @param string $number + * @return string + */ + function zb_AsteriskGetLoginByNumber($number) { + global $allrealnames; + global $alladdress; + if (strlen($number) == 13 or strlen(substr($number, -10)) == 10) { + $number_cut = substr($number, -10); + $LoginByNumberQueryArray = zb_LoginByNumberQuery(); + foreach ($LoginByNumberQueryArray as $num => $loginArray) { + if (in_array($number_cut, $loginArray)) { + $user_by_number = $num; + break; + } + } + $result = array(); + if (!empty($user_by_number)) { + $result['link'] = wf_Link('?module=userprofile&username=' . $user_by_number, $number, false); + $result['login'] = $user_by_number; + $result['name'] = @$allrealnames[$user_by_number]; + $result['adres'] = @$alladdress[$user_by_number]; + return ($result); + } else { + $result['link'] = $number; + $result['login'] = ''; + $result['name'] = ''; + $result['adres'] = ''; + return ($result); + } + } else { + $result['link'] = zb_AsteriskGetNumAlias($number); + $result['login'] = ''; + $result['name'] = ''; + $result['adres'] = ''; + return ($result); + } } - $asteriskDB->close(); - return ($result); -} -/* - * Gets Asterisk CDR data from database and manage cache - * - * @pram $from - start date - * @param $to - end date - * - * @return void - */ + /** + * Function add by Pautina - - nice and what it do? + * + * @return ??? + */ + function zb_CheckCommentsForUser($scope, $idComments) { + global $mysqlcfg; + $loginDB = new mysqli($mysqlcfg['server'], $mysqlcfg['username'], $mysqlcfg['password'], $mysqlcfg['db']); + $loginDB->set_charset("utf8"); + if ($loginDB->connect_error) { + die('Ошибка подключения (' . $loginDB->connect_errno . ') ' + . $loginDB->connect_error); + } + if (isset($scope) and isset($idComments)) { + $query = "SELECT `text` from `adcomments` WHERE `scope`='" . $scope . "' AND `item`='" . $idComments . "' ORDER BY `date` ASC LIMIT 1;"; + + $result = $loginDB->query($query); + //$result_a = array(); + while ($row = $result->fetch_assoc()) { + $comments = $row["text"]; + } + mysqli_free_result($result); + $loginDB->close(); + return ($comments); + } + } -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/'; + /** + * Parse Asterisk RAW CDR data + * + * @param array $data - raw CDR + * + * @return void + */ + function zb_AsteriskParseCDR($data) { + global $altcfg; + $normalData = $data; + + if (!empty($normalData)) { + $totalTime = 0; + $callsCounter = 0; + $cells = wf_TableCell('#'); + $cells.= wf_TableCell(__('Time')); + $cells.= wf_TableCell(__('From')); + $cells.= wf_TableCell(__('Real Name')); + $cells.= wf_TableCell(__('Address')); + $cells.= wf_TableCell(__('To')); + $cells.= wf_TableCell(__('Type')); + $cells.= wf_TableCell(__('Status')); + $cells.= wf_TableCell(__('Talk time')); + $cells.= wf_TableCell(__('Comments')); + + $rows = wf_TableRow($cells, 'row1'); + + foreach ($normalData as $io => $each) { + + if (isset($normalData[$io - 1]['src'])) { + if ($normalData[$io]['src'] == $normalData[$io - 1]['src'] and $normalData[$io - 1]['disposition'] == 'NO ANSWER' and $normalData[$io]['disposition'] != 'ANSWERED') + continue; + if ($normalData[$io]['src'] == $normalData[$io - 1]['src'] and $normalData[$io - 1]['dst'] == 'hangup') + continue; + if ($normalData[$io]['src'] == $normalData[$io - 1]['src'] and $normalData[$io - 1]['dst'] == 'musiconhold') + continue; + } + + $callsCounter++; + $AsteriskGetLoginByNumberAraySrc = array(zb_AsteriskGetLoginByNumber($each['src'])); + foreach ($AsteriskGetLoginByNumberAraySrc as $data) { + $link_src = $data['link']; + $login = $data['login']; + $name_src = $data['name']; + $adres_src = $data['adres']; + } + $debugData = wf_tag('pre') . print_r($each, true) . wf_tag('pre', true); + + $startTime = $each['calldate']; + //$startTime= explode(' ', $each['calldate']); + //@$startTime=$startTime[1]; + $tmpTime = strtotime($each['calldate']); + $endTime = $tmpTime + $each['duration']; + $endTime = date("H:i:s", $endTime); + $answerTime = $tmpTime + ($each['duration'] - $each['billsec']); + $answerTime = date("H:i:s", $answerTime); + $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 = ''; + + $cells = wf_TableCell(wf_modal($callsCounter, $callsCounter, $debugData, '', '500', '600'), '', '', 'sorttable_customkey="' . $callsCounter . '"'); + $cells.= wf_TableCell($sessionTimeStats, '', '', 'sorttable_customkey="' . $tmpTime . '"'); + $cells.= wf_TableCell($link_src); + $cells.= wf_TableCell($name_src); + $cells.= wf_TableCell($adres_src); + + $AsteriskGetLoginByNumberArayDst = array(zb_AsteriskGetLoginByNumber($each['dst'])); + foreach ($AsteriskGetLoginByNumberArayDst as $data) { + $link_dst = $data['link']; + if (!empty($data['login'])) { + $login = $data['login']; + } + } + //$cells.= wf_TableCell(zb_AsteriskGetNumAlias($each['dst'])); + $cells.= wf_TableCell($link_dst); + + $CallType = __('Dial'); + if (ispos($each['lastapp'], 'internal-caller-transfer')) { + $CallType = __('Call transfer'); + } + + $cells.= wf_TableCell($CallType); + + $callStatus = $each['disposition']; + $statusIcon = ''; + if (ispos($each['disposition'], 'ANSWERED')) { + $callStatus = __('Answered'); + $statusIcon = wf_img('skins/calls/phone_green.png'); + } + if (ispos($each['disposition'], 'NO ANSWER')) { + $callStatus = __('No answer'); + $statusIcon = wf_img('skins/calls/phone_red.png'); + } + + if (ispos($each['disposition'], 'BUSY')) { + $callStatus = __('Busy'); + $statusIcon = wf_img('skins/calls/phone_yellow.png'); + } + + if (ispos($each['disposition'], 'FAILED')) { + $callStatus = __('Failed'); + $statusIcon = wf_img('skins/calls/phone_fail.png'); + } + + $cells.= wf_TableCell($statusIcon . ' ' . $callStatus); + $speekTime = $each['billsec']; + $totalTime = $totalTime + $each['billsec']; + $speekTime = zb_AsteriskFormatTime($speekTime); + + $cells.= wf_TableCell($speekTime, '', '', 'sorttable_customkey="' . $each['billsec'] . '"'); + + if (!empty($login)) { + $itemId = $each['uniqueid'] . $each['disposition']{0}; + $adcomments = new ADcomments('ASTERISK'); + if ($adcomments->haveComments($itemId)) { + $link_text = '