verifica_sip().":".$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['SIP']; if ($fromNumber == $params['to']){ return $this->getLang("You can't call yourself"); } if (preg_match('/^\([0-9]{2}\)[0-9]{4}\-[0-9]{4}$/',$fromNumber) == 0){ return $this->getLang("you extension number is incorect"); } if (preg_match('/^\([0-9]{2}\)[0-9]{4}\-[0-9]{4}$/',$params['to']) == 0){ return $this->getLang("The extension ".$params['to']." is incorrect."); } if ($this->verifica_sip()){ $tipo="sip"; $fromNumber = substr($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'],1,2).$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['SIP']; }else{ $tipo="ramal"; $fromNumber = substr($fromNumber,1,2).substr($fromNumber,strlen($fromNumber) - 4, strlen($fromNumber) - 1); } $toNumber = $params['to'] ? substr($params['to'],1,2).substr($params['to'],strlen($params['to']) - 4, strlen($params['to']) - 1) : 0; //return $fromNumber.$toNumber; } //se convencional if($params['typePhone'] == 'com'){ $fromNumber = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number']; if(!$fromNumber) return false; $fromNumber = substr($fromNumber,strlen($fromNumber) - 4, strlen($fromNumber) - 1); $toNumber = $params['to'] ? substr($params['to'],strlen($params['to']) - 4, strlen($params['to']) - 1) : 0; } // Se for celular, passa os digitos do n�mero e conecta com outro VoIP Server..... if($params['typePhone'] == 'mob'){ $toNumber = $params['to']; } $url = "&acao=liga&tipo=".$tipo."&ramal=".$fromNumber."&numero=".$toNumber; $resp = $this->connectVoip($url); return $this->getLang("Calling extension: ").$resp; } function set_followme($params){ $ramal = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number']; $ramal = substr($ramal,1,2).substr($ramal,strlen($ramal) - 4, strlen($ramal) - 1); $url="&acao=set_followme&ramal=".$ramal.'&siga='.$params['follow']; $resp = $this->connectVoip($url); return $resp; } function get_followme($params){ $ramal = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number']; $ramal = substr($ramal,1,2).substr($ramal,strlen($ramal) - 4, strlen($ramal) - 1); $url="&acao=get_followme&ramal=".$ramal; $resp = $this->connectVoip($url); if(trim($resp) == "FALSE") return FALSE; $telefones = unserialize($resp); foreach($telefones as $tel) { $Ultimosquatro = substr($tel,-4); if($Ultimosquatro == substr($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'],-4)) $resposta['exten'] = $tel; elseif($Ultimosquatro == substr($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['mobile'],-4)) $resposta['mobile'] = $tel; elseif($tel == $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['SIP']) $resposta['sip'] = $tel; else $resposta['other'] = $tel; } return $resposta; } function verifica_sip(){ if(isset($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['SIP'])){ $ramal = substr($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'],1,2).$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['SIP']; $url="&acao=verifica_sip&ramal=".$ramal; $resp = $this->connectVoip($url); if(trim($resp) == "true") return TRUE; } return FALSE; } function connectVoip($param){ $voipServer= $_SESSION['phpgw_info']['expressomail']['server']['voip_server']; $voipUrl = $_SESSION['phpgw_info']['expressomail']['server']['voip_url']; $voipPort = $_SESSION['phpgw_info']['expressomail']['server']['voip_port']; if(!$voipServer || !$voipUrl || !$voipPort){ return false;} $url = "http://".$voipServer.":".$voipPort.$voipUrl."?magic=1333&".$param; $sMethod = 'GET '; $crlf = "\r\n"; $sRequest = " HTTP/1.1" . $crlf; $sRequest .= "Host: localhost" . $crlf; $sRequest .= "Accept: */* " . $crlf; $sRequest .= "Connection: Close" . $crlf . $crlf; $sRequest = $sMethod . $url . $sRequest; $sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if (!$sockHttp) { return "socket_create falhou"; } $resSocketConnect = socket_connect($sockHttp, $voipServer, $voipPort); if (!$resSocketConnect) { return "socket_connect falhou"; } $resSocketWrite = socket_write($sockHttp, $sRequest, strlen($sRequest)); if (!$resSocketWrite) { return "socket_write falhou"; } $sResponse = ''; while ($sRead = socket_read($sockHttp, 512)) { $sResponse .= $sRead; } socket_close($qsockHttp); $pos = strpos($sResponse, $crlf . $crlf); $resp = substr($sResponse, $pos + 2 * strlen($crlf)); return $resp; } function getDirContents($dir){ //$dir = dirname($dir); if (!is_dir($dir)) { return 'Error: Cannot load files in :'. $dir.' !'; } if ($root=@opendir($dir)) { while ($file=readdir($root)) { if($file!="." && $file!="..") $files[]=$dir."/".$file; } } return $files; } function getFilesJs($includeFiles = '', $update_version = ''){ $files = $this -> getDirContents('js'); $str_files = ''; if($includeFiles) { $includeFiles = explode(",",trim($includeFiles)); // Bug fixed for array_search function $includeFiles[count($includeFiles)] = $includeFiles[0]; $includeFiles[0] = null; // End Bug fixed. } for($i = 0; $i < count($files); $i++) { if(count(explode('.js',$files[$i])) > 1) { if($includeFiles && array_search(trim($files[$i]),$includeFiles)){ $str_files .= ""; } } } return $str_files; } function getReturnExecuteForm(){ $response = $_SESSION['response']; $_SESSION['response'] = null; return $response; } function getLang($key){ if ($_SESSION['phpgw_info']['expressomail']['lang'][$key]) return $_SESSION['phpgw_info']['expressomail']['lang'][$key]; else return ($key . '*'); } function get_preferences() { return $_SESSION['phpgw_info']['user']['preferences']['expressoMail']; } } ?>