Example #1
0
 /**
  * Get a list of calls
  *
  * @param string $offset 
  * @param string $page_size 
  * @return void
  */
 public function get_calls($offset = 0, $page_size = 20)
 {
     $output = array();
     $page_cache = 'calls-' . $offset . '-' . $page_size;
     $total_cache = 'calls-total';
     $ci =& get_instance();
     $tenant = $ci->tenant->id;
     if ($cache = $ci->api_cache->get($page_cache, __CLASS__, $tenant) && ($cache_total = $ci->api_cache->get($total_cache, __CLASS__, $tenant))) {
         $this->total = $cache_total;
         return $cache;
     }
     $page = floor(($offset + 1) / $page_size);
     try {
         $account = OpenVBX::getAccount();
         $calls = $account->calls->getIterator($page, $page_size, array());
         if (count($calls)) {
             $this->total = count($calls);
             foreach ($calls as $call) {
                 $output[] = (object) array('id' => $call->sid, 'caller' => format_phone($call->from), 'called' => format_phone($call->to), 'status' => $call->status, 'start' => $call->start_time, 'end' => $call->end_time, 'seconds' => intval($call->recording_duration));
             }
         }
     } catch (Exception $e) {
         throw new VBX_CallException($e->getMessage());
     }
     $ci->api_cache->set($page_cache, $output, __CLASS__, $tenant, self::CACHE_TIME_SEC);
     $ci->api_cache->set($total_cache, $this->total, __CLASS__, $tenant, self::CACHE_TIME_SEC);
     return $output;
 }
Example #2
0
 /**
  * Get SMS Messages
  *
  * @param string $offset 
  * @param string $page_size 
  * @return void
  */
 function get_messages($offset = 0, $page_size = 20)
 {
     $output = array();
     $ci =& get_instance();
     $tenant_id = $ci->tenant->id;
     $page_cache = 'messages-' . $offset . '-' . $page_size;
     $total_cache = 'messages-total';
     if ($cache = $ci->api_cache->get($page_cache, __CLASS__, $tenant_id) && ($cache_total = $ci->api_cache->get($total_cache, __CLASS__, $tenant_id))) {
         $this->total = $cache_total;
         return $cache;
     }
     $page = floor(($offset + 1) / $page_size);
     try {
         $account = OpenVBX::getAccount();
         $messages = $account->messages->getIterator($page, $page_size, array());
         if (count($messages)) {
             $this->total = count($messages);
             foreach ($messages as $message) {
                 $output[] = (object) array('id' => $message->sid, 'from' => format_phone($message->from), 'to' => format_phone($message->to), 'status' => $message->status);
             }
         }
     } catch (Exception $e) {
         throw new VBX_Sms_messageException($e->getMessage());
     }
     $ci->api_cache->set($page_cache, $output, __CLASS__, $tenant_id, self::CACHE_TIME_SEC);
     $ci->api_cache->set($total_cache, $this->total, __CLASS__, $tenant_id, self::CACHE_TIME_SEC);
     return $output;
 }
Example #3
0
 protected function init_browserphone_data($callerid_numbers)
 {
     // defaults
     $browserphone = array('call_using' => 'browser', 'caller_id' => '(000) 000-0000', 'number_options' => array(), 'call_using_options' => array('browser' => array('title' => 'Your Computer', 'data' => array())), 'devices' => array());
     $default_caller_id = false;
     if (is_array($callerid_numbers) && !empty($callerid_numbers)) {
         $numbered = $named = array();
         $default_caller_id = current($callerid_numbers)->phone;
         foreach ($callerid_numbers as $number) {
             if (normalize_phone_to_E164($number->phone) != normalize_phone_to_E164($number->name)) {
                 $named[$number->phone] = $number->name;
             } else {
                 $numbered[$number->phone] = $number->phone;
             }
         }
         ksort($numbered);
         asort($named);
         $browserphone['number_options'] = $named + $numbered;
     }
     $user = VBX_User::get(array('id' => $this->session->userdata('user_id')));
     // User preferences
     $browserphone['caller_id'] = $user->setting('browserphone_caller_id', $default_caller_id);
     $browserphone['call_using'] = $user->setting('browserphone_call_using', 'browser');
     // Wether the user has an active device to use
     if (count($user->devices)) {
         foreach ($user->devices as $device) {
             if (strpos($device->value, 'client:') !== false) {
                 continue;
             }
             $browserphone['call_using_options']['device:' . $device->id] = array('title' => 'Device: ' . $device->name, 'data' => (object) array('number' => format_phone($device->value), 'name' => $device->name));
         }
     }
     return $browserphone;
 }
Example #4
0
 public function testFormatPhone()
 {
     $this->assertSame('+6281802596094', format_phone('081802596094'));
     $this->assertSame('+6281802596094', format_phone('+6281802596094'));
     $this->assertSame('+6281802596094', format_phone('0818 0259 6094'));
     $this->assertSame('+6281802596094', format_phone('0818-025 960-94'));
     $this->assertSame('+62271715877', format_phone('(0271) 715 877'));
     $this->assertSame('+65271715877', format_phone('(0271) 715 877', '+65'));
 }
Example #5
0
function who_called($number)
{
    if (preg_match('|^client:|', $number)) {
        $number = str_replace('client:', '', $number);
        $ret = $number . ' (client)';
    } else {
        $ret = format_phone($number);
    }
    return $ret;
}
 public function who_called($number)
 {
     if (preg_match('|^client:|', $number)) {
         $user_id = str_replace('client:', '', $number);
         $user = VBX_User::get(array('id' => $user_id));
         $ret = $user->first_name . ' ' . $user->last_name . ' (client)';
     } else {
         $ret = format_phone($number);
     }
     return $ret;
 }
 function testFormatPhone()
 {
     $this->equals(format_phone('6154295938'), "(615) 429-5938");
     $this->equals(format_phone('615-429-5938'), "(615) 429-5938");
     $this->equals(format_phone("(615)-429-5938"), "(615) 429-5938");
     $this->equals(format_phone('615.429.5938'), "(615) 429-5938");
     $this->equals(format_phone('4295938'), '429-5938');
     $this->equals(format_phone('429-5938'), '429-5938');
     $this->equals(format_phone('429-5938'), '429-5938');
     $this->equals(format_phone('429.5938'), '429-5938');
     $this->equals(format_phone("429.ASF*^&%AS*^5938"), '429-5938');
 }
 public static function get_all_twilio_numbers()
 {
     global $ApiVersion, $AccountSid, $AuthToken;
     $twilio_numbers = array();
     $client = new TwilioRestClient($AccountSid, $AuthToken);
     $response = $client->request("/{$ApiVersion}/Accounts/{$AccountSid}/IncomingPhoneNumbers", "GET");
     // Get all twilio phone numbers
     foreach ($response->ResponseXml->IncomingPhoneNumbers->IncomingPhoneNumber as $number) {
         $twilio_numbers[format_phone($number->PhoneNumber)] = $number->FriendlyName;
     }
     return $twilio_numbers;
 }
 function testFormatPhone()
 {
     $this->assertEquals("(615) 429-5938", format_phone('6154295938'));
     $this->assertEquals("(615) 429-5938", format_phone('615-429-5938'));
     $this->assertEquals("(615) 429-5938", format_phone("(615)-429-5938"));
     $this->assertEquals("(615) 429-5938", format_phone('615.429.5938'));
     $this->assertEquals('429-5938', format_phone('4295938'));
     $this->assertEquals('429-5938', format_phone('429-5938'));
     $this->assertEquals('429-5938', format_phone('429-5938'));
     $this->assertEquals('429-5938', format_phone('429.5938'));
     $this->assertEquals('429-5938', format_phone("429.ASF*^&%AS*^5938"));
 }
Example #10
0
function get_all_twilio_numbers()
{
    $app = \Jolt\Jolt::getInstance();
    $ApiVersion = "2010-04-01";
    $twilio_numbers = array();
    $client = new Services_Twilio($app->option('twilio.accountsid'), $app->option('twilio.authtoken'));
    // Loop over the list of numbers and echo a property for each one
    foreach ($client->account->incoming_phone_numbers as $number) {
        $twilio_numbers[format_phone($number->phone_number)] = $number->phone_number;
    }
    return $twilio_numbers;
}
 public function render($data = array())
 {
     $hasValue = empty($this->mode) ? false : true;
     $this->load =& load_class('Loader');
     $this->load->model('vbx_audio_file');
     $this->load->model('vbx_device');
     // Get a list of all previously recorded items so we can populate the library
     $ci =& get_instance();
     $ci->db->where('url IS NOT NULL');
     $ci->db->where('tag', $this->tag);
     $ci->db->where('tenant_id', $ci->tenant->id);
     $ci->db->from('audio_files');
     $ci->db->order_by('created DESC');
     $results = $ci->db->get()->result();
     foreach ($results as $i => $result) {
         $results[$i] = new VBX_Audio_File($result);
     }
     // Pre-fill the record text field with the the first device phone number we
     // find for the current user that is active.
     $ci =& get_instance();
     $user = VBX_User::get($ci->session->userdata('user_id'));
     $user_phone = '';
     if (count($user->devices)) {
         foreach ($user->devices as $device) {
             if ($device->is_active) {
                 $user_phone = format_phone($device->value);
                 break;
             }
         }
     }
     // set the caller id for recording via the phone
     $caller_id = '';
     $ci->load->model('vbx_incoming_numbers');
     try {
         $numbers = $ci->vbx_incoming_numbers->get_numbers(false);
         foreach ($numbers as $number) {
             // find the first number that has voice enabled
             // yes, this is a rather paranoid check
             if (isset($number->capabilities->voice) && $number->capabilities->voice > 0) {
                 $caller_id = normalize_phone_to_E164($number->phone);
                 break;
             }
         }
     } catch (VBX_IncomingNumberException $e) {
         // fail silently, for better or worse
         error_log($e->getMessage());
     }
     $data = array_merge(array('name' => $this->name, 'hasValue' => $hasValue, 'mode' => $this->mode, 'say' => $this->say_value, 'play' => $this->play_value, 'tag' => $this->tag, 'library' => $results, 'first_device_phone_number' => $user_phone, 'caller_id' => $caller_id), $data);
     return parent::render($data);
 }
Example #12
0
 function index($message_id = false)
 {
     try {
         $content = substr($this->input->post('content'), 0, 160);
         $to = preg_replace('/[^0-9]*/', '', $this->input->post('to'));
         $from = $this->input->post('from');
         $numbers = array();
         if (empty($from)) {
             try {
                 $numbers = $this->vbx_incoming_numbers->get_numbers();
                 if (empty($numbers)) {
                     throw new Message_TextException("No SMS Enabled numbers");
                 }
                 $from = $numbers[0]->phone;
             } catch (VBX_IncomingNumberException $e) {
                 throw new Message_TextException("Unable to retrieve numbers: " . $e->getMessage());
             }
         }
         if (empty($from)) {
             $this->load->model('device');
             $devices = $this->device->get_by_user($this->user_id);
             if (!empty($devices[0])) {
                 $from = $devices[0]->value;
             }
         }
         $rest_access = $this->make_rest_access();
         $json['error'] = false;
         $json['message'] = '';
         try {
             $this->vbx_sms_message->send_message($from, $to, $content);
             if ($message_id) {
                 error_log("SMS Message ID: {$message_id}");
                 $annotation_id = $this->vbx_message->annotate($message_id, $this->user_id, "{$from} to " . format_phone($to) . ": {$content}", 'sms');
             }
         } catch (VBX_Sms_MessageException $e) {
             throw new Message_TextException($e->getMessage());
         }
     } catch (Message_TextException $e) {
         $json['message'] = $e->getMessage();
         $json['error'] = true;
     }
     $data['json'] = $json;
     if ($this->response_type == 'html') {
         redirect('messages/inbox');
     }
     $this->respond('', 'message_sms', $data);
 }
Example #13
0
 function get_calls($offset = 0, $page_size = 20)
 {
     $output = array();
     $page_cache_key = $this->cache_key . "_{$offset}_{$page_size}";
     $total_cache_key = $this->cache_key . '_total';
     if (function_exists('apc_fetch')) {
         $success = FALSE;
         $total = apc_fetch($total_cache_key, $success);
         if ($total and $success) {
             $this->total = $total;
         }
         $data = apc_fetch($page_cache_key, $success);
         if ($data and $success) {
             $output = @unserialize($data);
             if (is_array($output)) {
                 return $output;
             }
         }
     }
     $page = floor(($offset + 1) / $page_size);
     $params = array('num' => $page_size, 'page' => $page);
     $response = $this->twilio->request("Accounts/{$this->twilio_sid}/Calls", 'GET', $params);
     if ($response->IsError) {
         throw new VBX_CallException($response->ErrorMessage, $response->HttpStatus);
     } else {
         $this->total = (string) $response->ResponseXml->Calls['total'];
         $records = $response->ResponseXml->Calls->Call;
         foreach ($records as $record) {
             $item = new stdClass();
             $item->id = (string) $record->Sid;
             $item->caller = format_phone($record->From);
             $item->called = format_phone($record->To);
             $item->status = (string) $record->Status;
             $item->start = isset($record->StartTime) ? strtotime($record->StartTime) : null;
             $item->end = isset($record->EndTime) ? strtotime($record->EndTime) : null;
             $item->seconds = isset($record->RecordingDuration) ? (string) $record->RecordingDuration : 0;
             $output[] = $item;
         }
     }
     if (function_exists('apc_store')) {
         apc_store($page_cache_key, serialize($output), self::CACHE_TIME_SEC);
         apc_store($total_cache_key, $this->total, self::CACHE_TIME_SEC);
     }
     return $output;
 }
Example #14
0
 function index()
 {
     $this->admin_only($this->section);
     $this->template->add_js('assets/j/numbers.js');
     $data = $this->init_view_data();
     $numbers = array();
     try {
         $numbers = $this->vbx_incoming_numbers->get_numbers();
     } catch (VBX_IncomingNumberException $e) {
         $this->error_message = ErrorMessages::message('twilio_api', $e->getCode());
     }
     $incoming_numbers = array();
     // now generate table
     if (count($numbers) > 0) {
         $flows = VBX_Flow::search();
         foreach ($numbers as $item) {
             $item_msg = '';
             if (is_object($this->new_number) && $this->new_number->id == $item->id) {
                 $item_msg = 'New';
             }
             $flow_name = '(Not Set)';
             foreach ($flows as $flow) {
                 if ($flow->id == $item->flow_id) {
                     $flow_name = '';
                 }
             }
             $incoming_numbers[] = array('id' => $item->id, 'name' => $item->name, 'trial' => isset($item->trial) && $item->trial == 1 ? 1 : 0, 'phone' => format_phone($item->phone), 'pin' => $item->pin, 'status' => $item_msg, 'flow_id' => $item->flow_id, 'flow_name' => $flow_name, 'flows' => $flows);
         }
     }
     $data['highlighted_numbers'] = array($this->session->flashdata('new-number'));
     $data['items'] = $incoming_numbers;
     $data['twilio_sid'] = $this->twilio_sid;
     if (empty($this->error_message)) {
         $error_message = $this->session->flashdata('error');
         if (!empty($error_message)) {
             $this->error_message = $this->session->flashdata('error');
         }
     }
     if (!empty($this->error_message)) {
         $data['error'] = CI_Template::literal($this->error_message);
     }
     $data['counts'] = $this->message_counts();
     $this->respond('', 'numbers', $data);
 }
Example #15
0
 function get_messages($offset = 0, $page_size = 20)
 {
     $output = array();
     $page_cache_key = $this->cache_key . "_{$offset}_{$page_size}";
     $total_cache_key = $this->cache_key . '_total';
     if (function_exists('apc_fetch')) {
         $success = FALSE;
         $total = apc_fetch($total_cache_key, $success);
         if ($total and $success) {
             $this->total = $total;
         }
         $data = apc_fetch($page_cache_key, $success);
         if ($data and $success) {
             $output = @unserialize($data);
             if (is_array($output)) {
                 return $output;
             }
         }
     }
     $page = floor(($offset + 1) / $page_size);
     $params = array('num' => $page_size, 'page' => $page);
     $response = $this->twilio->request("Accounts/{$this->twilio_sid}/SMS/Messages", 'GET', $params);
     if ($response->IsError) {
         throw new VBX_Sms_messageException($response->ErrorMessage, $response->HttpStatus);
     } else {
         $this->total = (string) $response->ResponseXml->SMSMessages['total'];
         $records = $response->ResponseXml->SMSMessages->SMSMessage;
         foreach ($records as $record) {
             $item = new stdClass();
             $item->id = (string) $record->Sid;
             $item->from = format_phone($record->From);
             $item->to = format_phone($record->To);
             $item->status = Call::get_status((string) $record->Status);
             $output[] = $item;
         }
     }
     if (function_exists('apc_store')) {
         apc_store($page_cache_key, serialize($output), self::CACHE_TIME_SEC);
         apc_store($total_cache_key, $this->total, self::CACHE_TIME_SEC);
     }
     return $output;
 }
Example #16
0
function generate_blind_row($row)
{
    $blind_number = $row['blind_number'];
    $priority = $row['priority'];
    $is_public = $row['is_public'];
    $name = $row['name'];
    $home_phone = format_phone($row['home_phone']);
    $work_phone = format_phone($row['work_phone']);
    $table_row = "<tr>";
    $table_row = $table_row . "<td>" . $blind_number . "</td>";
    $table_row = $table_row . "<td>" . $name . "</td>";
    if ($is_public == "y") {
        $table_row = $table_row . "<td>" . $home_phone . "</td>";
        $table_row = $table_row . "<td>" . $work_phone . "</td>";
    } else {
        $table_row = $table_row . "<td>&nbsp;</td>";
        $table_row = $table_row . "<td>&nbsp;</td>";
    }
    $table_row = $table_row . "<tr>";
    return $table_row;
}
Example #17
0
 /**
  * Get SMS Messages
  *
  * @param string $offset 
  * @param string $page_size 
  * @return void
  */
 function get_messages($offset = 0, $page_size = 20)
 {
     $output = array();
     $page_cache_key = $this->cache_key . "_{$offset}_{$page_size}";
     $total_cache_key = $this->cache_key . '_total';
     if (function_exists('apc_fetch')) {
         $success = FALSE;
         $total = apc_fetch($total_cache_key, $success);
         if ($total and $success) {
             $this->total = $total;
         }
         $data = apc_fetch($page_cache_key, $success);
         if ($data and $success) {
             $output = @unserialize($data);
             if (is_array($output)) {
                 return $output;
             }
         }
     }
     $page = floor(($offset + 1) / $page_size);
     try {
         $account = OpenVBX::getAccount();
         $messages = $account->sms_messages->getIterator($page, $page_size, array());
         if (count($messages)) {
             $this->total = count($messages);
             foreach ($messages as $message) {
                 $output[] = (object) array('id' => $message->sid, 'from' => format_phone($message->from), 'to' => format_phone($message->to), 'status' => $message->status);
             }
         }
     } catch (Exception $e) {
         throw new VBX_Sms_messageException($e->getMessage());
     }
     if (function_exists('apc_store')) {
         apc_store($page_cache_key, serialize($output), self::CACHE_TIME_SEC);
         apc_store($total_cache_key, $this->total, self::CACHE_TIME_SEC);
     }
     return $output;
 }
Example #18
0
 /**
  * Get a list of calls
  *
  * @param string $offset 
  * @param string $page_size 
  * @return void
  */
 function get_calls($offset = 0, $page_size = 20)
 {
     $output = array();
     $page_cache_key = $this->cache_key . "_{$offset}_{$page_size}";
     $total_cache_key = $this->cache_key . '_total';
     if (function_exists('apc_fetch')) {
         $success = FALSE;
         $total = apc_fetch($total_cache_key, $success);
         if ($total and $success) {
             $this->total = $total;
         }
         $data = apc_fetch($page_cache_key, $success);
         if ($data and $success) {
             $output = @unserialize($data);
             if (is_array($output)) {
                 return $output;
             }
         }
     }
     $page = floor(($offset + 1) / $page_size);
     try {
         $account = OpenVBX::getAccount();
         $calls = $account->calls->getIterator($page, $page_size, array());
         if (count($calls)) {
             $this->total = count($calls);
             foreach ($calls as $call) {
                 $output[] = (object) array('id' => $call->sid, 'caller' => format_phone($call->from), 'called' => format_phone($call->to), 'status' => $call->status, 'start' => $call->start_time, 'end' => $call->end_time, 'seconds' => intval($call->recording_duration));
             }
         }
     } catch (Exception $e) {
         throw new VBX_CallException($e->getMessage());
     }
     if (function_exists('apc_store')) {
         apc_store($page_cache_key, serialize($output), self::CACHE_TIME_SEC);
         apc_store($total_cache_key, $this->total, self::CACHE_TIME_SEC);
     }
     return $output;
 }
 public function render($data = array())
 {
     $hasValue = empty($this->mode) ? false : true;
     $this->load =& load_class('Loader');
     $this->load->model('vbx_audio_file');
     $this->load->model('vbx_device');
     // Get a list of all previously recorded items so we can populate the library
     $ci =& get_instance();
     $ci->db->where('url IS NOT NULL');
     $ci->db->where('tag', $this->tag);
     $ci->db->where('tenant_id', $ci->tenant->id);
     $ci->db->from('audio_files');
     $ci->db->order_by('created DESC');
     $results = $ci->db->get()->result();
     foreach ($results as $i => $result) {
         $results[$i] = new VBX_Audio_File($result);
     }
     // Pre-fill the record text field with the the first device phone number we
     // find for the current user that is active.
     $ci =& get_instance();
     $first_phone_number = $ci->db->where('user_id', $ci->session->userdata('user_id'))->where('is_active', 1)->from('numbers')->order_by('sequence')->limit(1)->get()->result();
     $data = array_merge(array('name' => $this->name, 'hasValue' => $hasValue, 'mode' => $this->mode, 'say' => $this->say_value, 'play' => $this->play_value, 'tag' => $this->tag, 'library' => $results, 'first_device_phone_number' => count($first_phone_number) == 0 ? "" : format_phone($first_phone_number[0]->value)), $data);
     return parent::render($data);
 }
Example #20
0
    echo "<br />\n";
    echo "" . $text['description-info'] . "\n";
    echo "</td>\n";
    echo "</tr>\n";
}
echo "\t<tr>\n";
echo "\t\t<td colspan='2' align='right'>\n";
echo "\t\t\t<br>";
if ($action == "update") {
    if (if_group("user")) {
        echo "\t<input type='hidden' name='fax_name' value=\"{$fax_name}\">\n";
        echo "\t<input type='hidden' name='fax_extension' value=\"{$fax_extension}\">\n";
        echo "\t<input type='hidden' name='fax_destination_number' value=\"{$fax_destination_number}\">\n";
        echo "\t<input type='hidden' name='fax_caller_id_name' value=\"{$fax_caller_id_name}\">\n";
        echo "\t<input type='hidden' name='fax_caller_id_number' value=\"{$fax_caller_id_number}\">\n";
        echo "\t<input type='hidden' name='fax_forward_number' value=\"" . (is_numeric($fax_forward_number) ? format_phone($fax_forward_number) : $fax_forward_number) . "\">\n";
        echo "\t<input type='hidden' name='fax_description' value=\"{$fax_description}\">\n";
    }
    echo "\t\t<input type='hidden' name='fax_uuid' value='{$fax_uuid}'>\n";
    echo "\t\t<input type='hidden' name='dialplan_uuid' value='{$dialplan_uuid}'>\n";
}
echo "\t\t\t<input type='submit' name='submit' class='btn' value='" . $text['button-save'] . "'>\n";
echo "\t\t</td>\n";
echo "\t</tr>";
echo "</table>";
echo "<br />\n";
if (permission_exists('fax_extension_advanced') && function_exists("imap_open") && file_exists("fax_files_remote.php")) {
    echo "<div id='advanced_email_connection' " . ($fax_email_connection_host == '' ? "style='display: none;'" : null) . ">\n";
    echo "<b>" . $text['label-advanced_settings'] . "</b><br><br>";
    echo $text['description-advanced_settings'] . "<br><br>";
    echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
Example #21
0
 /**
  * Set the phone number to AU format  (mutator)
  */
 public function setPhoneAttribute($value)
 {
     $this->attributes['phone'] = format_phone('au', $value);
 }
Example #22
0
                     $dir_icon = 'inbound';
                 }
             }
         }
     } else {
         if ($ext['state'] == 'CS_CONSUME_MEDIA' || $ext['state'] == 'CS_EXCHANGE_MEDIA') {
             if ($ext['state'] == 'CS_CONSUME_MEDIA' && $ext['callstate'] == 'RINGING' && $ext['direction'] == 'outbound') {
                 $ext_state = 'ringing';
             } else {
                 if ($ext['state'] == 'CS_EXCHANGE_MEDIA' && $ext['callstate'] == 'ACTIVE' && $ext['direction'] == 'outbound') {
                     $ext_state = 'active';
                 }
             }
             $dir_icon = 'inbound';
             $call_name = $activity[(int) $ext['cid_num']]['effective_caller_id_name'];
             $call_number = format_phone((int) $ext['cid_num']);
         } else {
             unset($ext_state, $dir_icon, $call_name, $call_number);
         }
     }
 }
 //determine block style by state (if any)
 $style = $ext_state != '' ? "op_state_" . $ext_state : null;
 //determine the call identifier passed on drop
 if ($ext['uuid'] == $ext['call_uuid'] && $ext['variable_bridge_uuid'] == '') {
     // transfer an outbound internal call
     $call_identifier = $activity[$call_number]['uuid'];
 } else {
     if (($ext['variable_call_direction'] == 'outbound' || $ext['variable_call_direction'] == 'local') && $ext['variable_bridge_uuid'] != '') {
         // transfer an outbound external call
         $call_identifier = $ext['variable_bridge_uuid'];
Example #23
0
 function add_from_twilio_recording()
 {
     $json = array('error' => false, 'message' => '');
     $to = preg_replace('/[^0-9]*/', '', $this->input->post('to'));
     $callerid = preg_replace('/[^0-9]*/', '', $this->input->post('callerid'));
     if (strlen($to) == 0) {
         $json['error'] = true;
         $json['message'] = "You must provide a number to call.";
     } else {
         if (strlen($callerid) == 0) {
             $json['error'] = true;
             $json['message'] = "You must have an incoming number to record a greeting. <a href=\"" . site_url('numbers') . "\">Get a Number</a>";
         } else {
             $rest_access_token = $this->make_rest_access();
             $twilio = new TwilioRestClient($this->twilio_sid, $this->twilio_token, $this->twilio_endpoint);
             $path = 'audiofiles!prompt_for_recording_twiml';
             $recording_url = stripslashes(site_url("twiml/redirect/" . $path . "/{$rest_access_token}"));
             $response = $twilio->request("Accounts/{$this->twilio_sid}/Calls", 'POST', array("Caller" => $callerid, "Called" => $to, "Url" => $recording_url));
             if ($response->IsError) {
                 $json['message'] = $response->ErrorMessage;
                 $json['error'] = true;
             } else {
                 $callSid = $response->ResponseXml->Call->Sid[0];
                 $ci =& get_instance();
                 // Create a place holder for our recording
                 $audioFile = new VBX_Audio_File();
                 $audioFile->label = "Recording with " . format_phone($to);
                 $audioFile->user_id = intval($this->session->userdata('user_id'));
                 $audioFile->recording_call_sid = "{$callSid}";
                 $audioFile->tag = $this->input->post('tag');
                 $audioFile->save();
                 $json['id'] = $audioFile->id;
             }
         }
     }
     $data = array();
     $data['json'] = $json;
     $this->response_type = 'json';
     $this->respond('', null, $data);
 }
Example #24
0
 /**
  * Add a dialplan for call center
  * @var string $domain_uuid		the multi-tenant id
  * @var string $value	string to be cached
  */
 public function dialplan()
 {
     //normalize the fax forward number
     if (strlen($this->fax_forward_number) > 3) {
         //$fax_forward_number = preg_replace("~[^0-9]~", "",$fax_forward_number);
         $this->fax_forward_number = str_replace(" ", "", $this->fax_forward_number);
         $this->fax_forward_number = str_replace("-", "", $this->fax_forward_number);
     }
     //set the forward prefix
     if (strripos($this->fax_forward_number, '$1') === false) {
         $this->forward_prefix = '';
         //not found
     } else {
         $this->forward_prefix = $this->forward_prefix . $this->fax_forward_number . '#';
         //found
     }
     //delete previous dialplan
     if (strlen($this->dialplan_uuid) > 0) {
         //delete the previous dialplan
         $sql = "delete from v_dialplans ";
         $sql .= "where dialplan_uuid = '" . $this->dialplan_uuid . "' ";
         $sql .= "and domain_uuid = '" . $this->domain_uuid . "' ";
         $this->db->exec($sql);
         $sql = "delete from v_dialplan_details ";
         $sql .= "where dialplan_uuid = '" . $this->dialplan_uuid . "' ";
         $sql .= "and domain_uuid = '" . $this->domain_uuid . "' ";
         $this->db->exec($sql);
         unset($sql);
     }
     unset($prep_statement);
     //build the dialplan array
     $dialplan["app_uuid"] = "24108154-4ac3-1db6-1551-4731703a4440";
     $dialplan["domain_uuid"] = $this->domain_uuid;
     $dialplan["dialplan_name"] = $this->fax_name != '' ? $this->fax_name : format_phone($this->destination_number);
     $dialplan["dialplan_number"] = $this->fax_extension;
     $dialplan["dialplan_context"] = $_SESSION['context'];
     $dialplan["dialplan_continue"] = "false";
     $dialplan["dialplan_order"] = "310";
     $dialplan["dialplan_enabled"] = "true";
     $dialplan["dialplan_description"] = $this->fax_description;
     $dialplan_detail_order = 10;
     //add the public condition
     $y = 1;
     $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
     $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition";
     $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number";
     $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "^" . $this->destination_number . "\$";
     $dialplan["dialplan_details"][$y]["dialplan_detail_break"] = "";
     $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1";
     $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
     $y++;
     $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
     $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
     $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "answer";
     $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "";
     $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1";
     $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
     $y++;
     $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
     $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
     $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set";
     $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "fax_uuid=" . $this->fax_uuid;
     $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1";
     $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
     $y++;
     $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
     $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
     $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set";
     $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "api_hangup_hook=lua app/fax/resources/scripts/hangup_rx.lua";
     $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1";
     $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
     $y++;
     foreach ($_SESSION['fax']['variable'] as $data) {
         $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
         $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
         $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set";
         if (substr($data, 0, 8) == "inbound:") {
             $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = substr($data, 8, strlen($data));
         } elseif (substr($data, 0, 9) == "outbound:") {
         } else {
             $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $data;
         }
         $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1";
         $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
         $y++;
     }
     $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
     $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
     $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set";
     if (strlen($_SESSION['fax']['last_fax']['text']) > 0) {
         $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "last_fax=" . $_SESSION['fax']['last_fax']['text'];
     } else {
         $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "last_fax=\${caller_id_number}-\${strftime(%Y-%m-%d-%H-%M-%S)}";
     }
     $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1";
     $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
     $y++;
     $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
     $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
     $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "playback";
     $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "silence_stream://2000";
     $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1";
     $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
     $y++;
     $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
     $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
     $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "rxfax";
     $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $_SESSION['switch']['storage']['dir'] . '/fax/' . $_SESSION['domain_name'] . '/' . $this->fax_extension . '/inbox/' . $this->forward_prefix . '${last_fax}.tif';
     $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1";
     $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
     $y++;
     $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
     $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
     $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "hangup";
     $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "";
     $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1";
     $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
     $y++;
     //add the dialplan permission
     $p = new permissions();
     $p->add("dialplan_add", 'temp');
     $p->add("dialplan_detail_add", 'temp');
     $p->add("dialplan_edit", 'temp');
     $p->add("dialplan_detail_edit", 'temp');
     //save the dialplan
     $orm = new orm();
     $orm->name('dialplans');
     $orm->save($dialplan);
     $dialplan_response = $orm->message;
     $this->dialplan_uuid = $dialplan_response['uuid'];
     //if new dialplan uuid then update the call center queue
     $sql = "update v_fax ";
     $sql .= "set dialplan_uuid = '" . $this->dialplan_uuid . "' ";
     $sql .= "where fax_uuid = '" . $this->fax_uuid . "' ";
     $sql .= "and domain_uuid = '" . $this->domain_uuid . "' ";
     $this->db->exec($sql);
     unset($sql);
     //remove the temporary permission
     $p->delete("dialplan_add", 'temp');
     $p->delete("dialplan_detail_add", 'temp');
     $p->delete("dialplan_edit", 'temp');
     $p->delete("dialplan_detail_edit", 'temp');
     //synchronize the xml config
     save_dialplan_xml();
     //clear the cache
     $cache = new cache();
     $cache->delete("dialplan:" . $_SESSION['context']);
     //return the dialplan_uuid
     return $dialplan_response;
 }
Example #25
0
 /**
  * Refresh the user's devices list in the dialer
  *
  * @return json
  */
 public function refresh_dialer()
 {
     $user = VBX_User::get(array('id' => $this->session->userdata('user_id')));
     $browserphone = array('call_using_options' => array());
     if (count($user->devices)) {
         foreach ($user->devices as $device) {
             if (strpos($device->value, 'client:') !== false) {
                 continue;
             }
             $browserphone['call_using_options']['device:' . $device->id] = array('title' => 'Device: ' . $device->name, 'data' => (object) array('number' => format_phone($device->value), 'name' => $device->name));
         }
     }
     $data = array('browserphone' => $browserphone);
     $html = $this->load->view('dialer/devices', $data, true);
     $response['json'] = array('error' => false, 'html' => $html);
     $this->respond('', 'dialer/devices', $response);
 }
Example #26
0
     $cmd_pdf2tif = "gs -q -sDEVICE=tiffg3 -r" . $gs_r . " -g" . $gs_g . " -dNOPAUSE -sOutputFile=" . $file_name . "_temp.tif -- " . $file_name . ".pdf -c quit";
     //echo $cmd_pdf2tif."<br>";
     exec($cmd_pdf2tif);
     //convert pdf to tif
     @unlink($dir_fax_temp . '/' . $file_name . ".pdf");
     $cmd_tif2pdf = "tiff2pdf -i -u i -p " . $page_size . " -w " . $page_width . " -l " . $page_height . " -f -o " . $dir_fax . '/' . $file_name . ".pdf " . $dir_fax_temp . '/' . $file_name . "_temp.tif";
     //echo $cmd_tif2pdf."<br>";
     exec($cmd_tif2pdf);
     @unlink($dir_fax_temp . '/' . $file_name . "_temp.tif");
 }
 echo "</td></tr>";
 echo "<tr " . $tr_link . ">\n";
 echo "\t<td valign='top' class='" . $row_style[$c] . "'>" . $row['fax_caller_id_name'] . "&nbsp;</td>\n";
 echo "\t<td valign='top' class='" . $row_style[$c] . "'>" . format_phone($row['fax_caller_id_number']) . "&nbsp;</td>\n";
 if ($_REQUEST['box'] == 'sent') {
     echo "\t<td valign='top' class='" . $row_style[$c] . "'>" . format_phone($row['fax_destination']) . "&nbsp;</td>\n";
 }
 echo "  <td class='" . $row_style[$c] . "' ondblclick=\"\">\n";
 if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) {
     echo "\t  <a href=\"fax_files.php?id=" . $fax_uuid . "&a=download&type=fax_inbox&t=bin&ext=" . urlencode($fax_extension) . "&filename=" . urlencode($file) . "\">\n";
 }
 if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) {
     echo "\t  <a href=\"fax_files.php?id=" . $fax_uuid . "&a=download&type=fax_sent&t=bin&ext=" . urlencode($fax_extension) . "&filename=" . urlencode($file) . "\">\n";
 }
 echo "    \t{$file_name}";
 echo "\t  </a>";
 echo "  </td>\n";
 echo "  <td class='" . $row_style[$c] . "' ondblclick=''>\n";
 if ($_REQUEST['box'] == 'inbox') {
     $dir_fax = $dir_fax_inbox;
 }
Example #27
0
 $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
 $result_count = count($result);
 if ($result_count > 0) {
     foreach ($result as &$row) {
         if ($row['contact_organization'] != '') {
             $contact_option_label = $row['contact_organization'];
         }
         if ($row['contact_name_given'] != '' || $row['contact_name_family'] != '' || $row['contact_nickname'] != '') {
             $contact_option_label .= $row['contact_organization'] != '' ? "," : null;
             $contact_option_label .= $row['contact_name_given'] != '' ? ($row['contact_organization'] != '' ? " " : null) . $row['contact_name_given'] : null;
             $contact_option_label .= $row['contact_name_family'] != '' ? ($row['contact_organization'] != '' || $row['contact_name_given'] != '' ? " " : null) . $row['contact_name_family'] : null;
             $contact_option_label .= $row['contact_nickname'] != '' ? $row['contact_organization'] != '' || $row['contact_name_given'] != '' || $row['contact_name_family'] != '' ? " (" . $row['contact_nickname'] . ")" : $row['contact_nickname'] : null;
         }
         $contact_option_value_recipient = $contact_option_label;
         $contact_option_value_faxnumber = $row['phone_number'];
         $contact_option_label .= ":&nbsp;&nbsp;" . format_phone($row['phone_number']);
         $contact_labels[] = $contact_option_label;
         $contact_values[] = $contact_option_value_faxnumber . "|" . $contact_option_value_recipient;
         unset($contact_option_label);
     }
     asort($contact_labels, SORT_NATURAL);
     // sort by name(s)
     echo "\t<select class='formfld' style='display: none;' id='fax_recipient_select' onchange='contact_load(this);'>\n";
     echo "\t\t<option value=''></option>\n";
     foreach ($contact_labels as $index => $contact_label) {
         echo "\t<option value=\"" . $contact_values[$index] . "\">" . $contact_label . "</option>\n";
     }
     echo "\t</select>\n";
 }
 unset($prep_statement);
 echo "\t<input type='text' name='fax_recipient' id='fax_recipient' class='formfld' style='max-width: 250px;' value=''>\n";
 private function parseIncomingPhoneNumber($item)
 {
     $num = new stdClass();
     $num->flow_id = null;
     $num->id = $item->sid;
     $num->name = $item->friendly_name;
     $num->phone = format_phone($item->phone_number);
     $num->phone_number = $item->phone_number;
     $num->url = $item->voice_url;
     $num->method = $item->voice_method;
     $num->smsUrl = $item->sms_url;
     $num->smsMethod = $item->sms_method;
     $num->capabilities = $item->capabilities;
     $num->voiceApplicationSid = $item->voice_application_sid;
     // @todo do comparison against url domain, then against 'twiml/start'
     // then include warning when small differences like www/non-www are encountered
     // don't be friendly to other sub-domain matches, only www since that is the
     // only safe variation to assume
     $call_base = site_url('twiml/start') . '/';
     $base_pos = strpos($num->url, $call_base);
     $num->installed = $base_pos !== FALSE;
     $matches = array();
     if ($num->installed && preg_match('/\\/(voice|sms)\\/(\\d+)$/', $num->url, $matches) > 0) {
         $num->flow_id = intval($matches[2]);
     }
     return $num;
 }
Example #29
0
function drawStaffRow($r, $searchterms = false)
{
    global $isAdmin, $locale;
    if ($searchterms) {
        global $fields;
        foreach ($fields as $f) {
            if (isset($r[$f])) {
                $r[$f] = format_hilite($r[$f], $searchterms);
            }
        }
    }
    $return = '<tr height="38">';
    $return .= '<td class="image"><a href="/staff/view.php?id=' . $r["userID"] . '">' . drawImg($r["userID"]) . '</a></td>';
    $return .= '<td><nobr><a href="view.php?id=' . $r["userID"] . '">' . $r["lastname"] . ', ' . $r["firstname"] . '</a>';
    //if (!$r["isMain"]) $return .= "<br>" . $r["office"];
    $return .= '</nobr></td><td>';
    if ($r["title"]) {
        $return .= $r["title"] . '<br>';
    }
    if ($r["departmentName"]) {
        $return .= '<i>' . $r["departmentName"] . '</i><br>';
    }
    if ($r["corporationName"]) {
        $return .= '<a href="/staff/organizations.php?id=' . $r["corporationID"] . '">' . $r["corporationName"] . '</a>';
    }
    $return .= '</td>
		<td class="r"><nobr>' . format_phone($r["phone"]) . '</nobr></td>
		';
    if ($isAdmin) {
        $return .= '<td class="delete"><a href="javascript:promptRedirect(\'' . url_query_add(array("action" => "delete", "staffID" => $r["userID"]), false) . '\', \'Delete this staff member?\');"><i class="glyphicon glyphicon-remove"></i></a></td>';
    }
    return $return . '</tr>';
}
 private function parseIncomingPhoneNumber($item)
 {
     $num = new stdClass();
     $num->flow_id = null;
     $num->id = (string) isset($item->Sid) ? (string) $item->Sid : 'Sandbox';
     $num->name = (string) $item->FriendlyName;
     $num->phone = format_phone($item->PhoneNumber);
     $num->pin = isset($item->Pin) ? (string) $item->Pin : null;
     $num->sandbox = isset($item->Pin) ? true : false;
     $num->url = (string) $item->Url;
     $num->method = (string) $item->Method;
     $num->smsUrl = (string) $item->SmsUrl;
     $num->smsMethod = (string) $item->SmsMethod;
     $call_base = site_url('twiml/start') . '/';
     $base_pos = strpos($num->url, $call_base);
     $num->installed = $base_pos !== FALSE;
     $matches = array();
     if (!preg_match('/\\/(voice|sms)\\/(\\d+)$/', $num->url, $matches) == 0) {
         $num->flow_id = intval($matches[2]);
     } else {
         error_log("Skipping unexpected URL pattern: '" . $num->url . "'");
     }
     return $num;
 }