diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php index 2a036e121..fe29e8bb8 100644 --- a/application/Address/AddressModel.php +++ b/application/Address/AddressModel.php @@ -414,12 +414,18 @@ class AddressModel { } } - if (array_key_exists("pfm", $filter)) { - $pfm = FronkDB::singleton()->escape($filter["pfm"]); - if ($pfm) { - $where .= " AND (phone like '%$pfm%' OR fax like '%$pfm%' OR mobile like '%$pfm%' )"; + $pfm = preg_replace('/^(43|0)/', '', preg_replace('/[^0-9]/', '', $filter['pfm'] ?? '')); + if (!empty($pfm)) { + $pfmEscaped = FronkDB::singleton()->escape($pfm); + $searchColumns = ['phone', 'fax', 'mobile']; + + $conditions = array_map(function ($column) use ($pfmEscaped) { + $normalizedColumn = "REGEXP_REPLACE(REGEXP_REPLACE(`$column`, '[^0-9]', ''), '^(43|0)', '')"; + return "$normalizedColumn LIKE '%$pfmEscaped%'"; + }, $searchColumns); + + $where .= " AND (" . implode(' OR ', $conditions) . ")"; } - } if (array_key_exists("billing_type", $filter)) { $billing_type = FronkDB::singleton()->escape($filter["billing_type"]); diff --git a/application/User/UserController.php b/application/User/UserController.php index abadd899e..d3e2e3320 100644 --- a/application/User/UserController.php +++ b/application/User/UserController.php @@ -441,6 +441,9 @@ class UserController extends mfBaseController case "setVodiaIdentity": $return = $this->setVodiaIdentityApi(); break; + case "getVodiaCall": + $return = $this->getVodiaCallApi(); + break; default: $return = false; } @@ -528,6 +531,44 @@ class UserController extends mfBaseController } + private function getVodiaCallApi() { + if(!ENABLE_VODIA_IDENTITY_SWITCHER) { + return ["enabled" => false]; + } + + $domain = $this->me->getFlag("vodia_identity_domain")->value(); + $username = $this->me->getFlag("vodia_identity_username")->value(); + + if(!$domain || !$username) { + return ["enabled" => false]; + } + + $vodia = new Vodia_Api(VODIA_API_URL, VODIA_API_ADMIN_USER, VODIA_API_ADMIN_PASS); + + $calls = $vodia->getActiveCalls($domain, $username); + if(!$calls) { + return ["enabled" => true, "calls" => []]; + } + + $from = null; + foreach($calls as $call) { + if(isset($call['from'])) { + $from = $call['from']; + if(preg_match('/]+)>/', $from, $m)) { + $from = $m[1]; + } else { + $from = str_replace('"', '', $from); + } + break; // only return the first call's from number + } + } + + return ["enabled" => true, "number" => $from]; + + } + private function startSuperexpertApi() { $me = new User(); $me->loadMe(); diff --git a/lib/Vodia/Api.php b/lib/Vodia/Api.php index ab894dd8b..baaa0a5fe 100644 --- a/lib/Vodia/Api.php +++ b/lib/Vodia/Api.php @@ -145,4 +145,32 @@ class Vodia_Api { return $user_settings; } + + public function getActiveCalls($domain, $user) { + if(!$this->session_id) { + $this->_authenticate($domain); + } + + $url = $this->baseurl.VODIA_API_EP_GET_USER_CALLS; + $url = str_replace("{DOMAIN}", $domain, $url); + $url = str_replace("{EXT}", $user, $url); + + $ctx_options = [ + "http" => [ + "ignore_errors" => true, + "method" => "GET", + "header" => [ + "Cookie: session=".$this->session_id, + "Accept: application/json", + "Content-Type: application/json", + ], + ] + ]; + + $ctx = stream_context_create($ctx_options); + $output = file_get_contents($url, false, $ctx); + + return json_decode($output, true); + } + } \ No newline at end of file diff --git a/public/assets/js/xinon-vodia-identity.js b/public/assets/js/xinon-vodia-identity.js index 02e00c7db..965a6f640 100644 --- a/public/assets/js/xinon-vodia-identity.js +++ b/public/assets/js/xinon-vodia-identity.js @@ -1,6 +1,14 @@ document.body.insertAdjacentHTML('beforeend', `