/** * Get a DialList object try * Pass in a VBX_User or VBX_Group object to begin * * @param object users_or_group * @return object DialList */ public static function get($users_or_group) { $users = array(); $class = 'DialList'; switch (true) { case is_array($users_or_group): if (current($users_or_group) instanceof VBX_User) { // list of users, set as users list and continue $users = $users_or_group; } else { // list of user ids, populate list $users = VBX_User::get_users($users_or_group); } break; case $users_or_group instanceof VBX_Group: if (!empty($users_or_group->users)) { foreach ($users_or_group->users as $user) { array_push($users, VBX_User::get($user->user_id)); } } break; case $users_or_group instanceof VBX_User: $class = 'DialListUser'; // individual user, add to list and continue array_push($users, $users_or_group); break; } return new $class($users); }
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; }
public function reset() { $this->template->write('title', 'Reset Password'); $data = array(); $email = $this->input->post('email'); if (empty($email)) { $data['error'] = $this->session->flashdata('error'); return $this->respond('', 'reset', $data, 'login-wrapper', 'layout/login'); } $user = VBX_User::get(array('email' => $email, 'is_active' => 1)); if (empty($user)) { $this->session->set_flashdata('error', 'No active account found.'); redirect('auth/reset'); } if ($user->auth_type == 'google') { header('Location: http://www.google.com/support/accounts/bin/answer.py?answer=48598&hl=en&ctx=ch_Login&fpUrl=https%3A%2F%2Fwww.google.com%2Faccounts%2FForgotPasswd%3FfpOnly%3D1%26continue%3Dhttp%253A%252F%252Fwww.google.com%252F%26hl%3Den'); return; } else { $emailSent = $user->send_reset_notification(); if ($emailSent) { $this->session->set_flashdata('error', 'To complete the password reset, check your inbox.'); } else { $this->session->set_flashdata('error', 'The email was not sent. Contact your admin.'); } redirect('auth/login'); } redirect('auth/reset'); }
/** * Display the popup for making calls with Twilio Client * * @return void */ public function client() { $caller_id = $this->input->get('callerid'); if (empty($caller_id)) { // grab user's default device $user = VBX_User::get($this->session->userdata['user_id']); $devices = $this->vbx_device->get_by_user($this->user_id); if (!empty($devices)) { $caller_id = $devices[0]->value; } } $client_params = array('callerid' => normalize_phone_to_E164($caller_id), 'application_id' => 'client'); if ($this->input->get('outgoing')) { // functionality for using the "dial" modal to initiate a call $to = normalize_phone_to_E164($this->input->get('to')); if (empty($to)) { $to = htmlspecialchars($this->input->get('to')); } $client_params = array_merge($client_params, array('to' => $to)); } elseif ($this->input->get('incoming')) { $client_params = array_merge($client_params, array('incoming' => true)); } $client_data = array('client_params' => json_encode($client_params)); $javascript = $this->load->view('client_js', $client_data, true); $this->template->add_js($javascript, 'embed', true); $data = array('title' => 'dialer', 'client_params' => $client_params); $this->respond('Dialer', 'call', $data, '', 'layout/dialer'); }
public function __construct() { parent::__construct(); $this->user = VBX_User::get($this->session->userdata('user_id')); if (!$this->user->is_admin) { throw new SiteCachesException('Action not allowed to non-administrators'); } }
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; }
public function testVoicemailUserSay() { ob_start(); $this->CI->voice(1, 'f274cd'); $out = ob_get_clean(); $xml = simplexml_load_string($out); $this->assertInstanceOf('SimpleXMLElement', $xml); $user = VBX_User::get($this->user_id); // this regex match is cheap, need better reg-fu to match possible // language and voice attributes that could appear in any order $this->assertRegExp('|(<Say(.*?)>' . $user->voicemail . '</Say>)|', $out); $this->assertRegExp('|(<Record transcribeCallback="(.*?)"/>)|', $out); }
public function setUp() { parent::setUp(); // set the user's voicemail to be a recording $this->user = VBX_User::get($this->user_id); $this->user->voicemail = $this->upload_prefix . $this->filename; $this->user->save(); $this->setFlow(array('id' => 1, 'user_id' => 1, 'created' => NULL, 'updated' => NULL, 'data' => '{"start":{"name":"Call Start","data":{"next":"start/59c7d7"},"id":"start","type":"standard---start"},"59c7d7":{"name":"Voicemail","data":{"prompt_say":"","prompt_play":"","prompt_mode":"","prompt_tag":"global","number":"","library":"","permissions_id":"' . $this->user_id . '","permissions_type":"user"},"id":"59c7d7","type":"standard---voicemail"}}', 'sms_data' => NULL, 'tenant_id' => 1)); // set up our request $this->setPath('/twiml/applet/voice/1/59c7d7'); $this->setRequestMethod('POST'); // prepare the header token for request validation $this->setRequestToken(); }
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); }
/** * Add a device to the Dialer * * @param VBX_Device $device * @return bool */ public function dialDevice($device) { $dialed = false; if ($device->is_active) { $user = VBX_User::get($device->user_id); $call_opts = array('url' => site_url('twiml/whisper?name=' . urlencode($user->first_name))); $dial = new Dial(NULL, array('action' => current_url(), 'callerId' => $this->callerId)); if (strpos($device->value, 'client:') !== false) { $dial->addClient(str_replace('client:', '', $device->value), $call_opts); } else { $dial->addNumber($device->value, $call_opts); } $this->response->append($dial); $dialed = true; } return $dialed; }
public function testUserDialClient() { $this->setFlowVar('data', '{"start":{"name":"Call Start","data":{"next":"start/4a7eed"},"id":"start","type":"standard---start"},"4a7eed":{"name":"Dial","data":{"dial-whom-selector":"user-or-group","dial-whom-user-or-group_id":"' . $this->dial_user_id . '","dial-whom-user-or-group_type":"user","dial-whom-number":"","callerId":"","no-answer-action":"voicemail","no-answer-group-voicemail_say":"","no-answer-group-voicemail_play":"","no-answer-group-voicemail_mode":"","no-answer-group-voicemail_tag":"global","no-answer-group-voicemail_caller_id":"+14158774003","number":"","library":"","no-answer-redirect":"","no-answer-redirect-number":"start/4a7eed/e18b35","version":"3"},"id":"4a7eed","type":"standard---dial"},"e18b35":{"name":"Hangup","data":{},"id":"e18b35","type":"standard---hangup"}}'); $user = VBX_User::get($this->dial_user_id); $user->online = 1; $user->save(); ob_start(); $this->CI->voice('1', '4a7eed'); $out = ob_get_clean(); // test valid xml $xml = simplexml_load_string($out); $this->assertInstanceOf('SimpleXMLElement', $xml); // test valid user number item $user_name = $user->first_name; $user_phone = $user->devices[0]->value; $regexp = '|<Number url="(.*?)/twiml/whisper\\?name=' . $user_name . '">\\' . $user_phone . '</Number>|'; $this->assertRegExp($regexp, $out); // test valid user client item $regexp2 = '|<Client url="(.*?)/twiml/whisper\\?name=' . $user_name . '">' . $user->id . '</Client>|'; $this->assertRegExp($regexp2, $out); }
private function save_greeting() { $data['json'] = array('error' => false, 'message' => ''); $user = VBX_User::get($this->user_id); $user->voicemail = $this->input->post('voicemail'); try { $user->save(); } catch (VBX_UserException $e) { $data['json'] = array('error' => true, 'message' => $e->getMessage()); } return $data; }
public function client_status() { $data = array('json' => array('error' => true, 'message' => 'Invalid Request')); if ($this->input->post('clientstatus')) { $online = $this->input->post('online') == 1; $user = VBX_User::get($this->session->userdata('user_id')); try { $user->setting_set('online', $online); $data['json'] = array('error' => false, 'message' => 'status updated', 'client_status' => $online ? 'online' : 'offline'); } catch (VBX_UserException $e) { $data['json'] = array('error' => true, 'message' => $e->getMessage()); } } $this->respond('', null, $data); }
public static function getUserGroupPickerValue($name = 'userGroupPicker') { $ci =& get_instance(); $ci->load->model('vbx_user'); $ci->load->model('vbx_group'); $owner_id = self::getValue($name . '_id'); $owner_type = self::getValue($name . '_type'); $owner = null; switch ($owner_type) { case 'group': $owner = VBX_Group::get(array('id' => $owner_id)); break; case 'user': $owner = VBX_User::get($owner_id); break; } return $owner; }
public function __construct() { parent::__construct(); $this->config_check(); $this->config->load('openvbx'); // check for required configuration values $this->load->database(); $this->load->library('ErrorMessages'); // deprecated in 1.2 $this->load->model('vbx_rest_access'); $this->load->model('vbx_message'); // When we're in testing mode, allow access to set Hiccup configuration $this->testing_mode = !empty($_REQUEST['vbx_testing_key']) ? $_REQUEST['vbx_testing_key'] == $this->config->item('testing-key') : false; $this->config->set_item('sess_cookie_name', $this->tenant->id . '-' . $this->config->item('sess_cookie_name')); $this->load->library('session'); $keys = array('base_url', 'salt'); foreach ($keys as $key) { $item[$key] = $this->config->item($key); if (empty($item[$key])) { redirect('install'); } } /* Rest API Authentication - one time pass only */ $singlepass = $this->input->cookie('singlepass'); if (!empty($singlepass)) { $ra = new VBX_Rest_Access(); $user_id = $ra->auth_key($singlepass); unset($_COOKIE['singlepass']); if ($user_id) { $this->session->set_userdata('user_id', $user_id); $this->session->set_userdata('loggedin', true); $this->session->set_userdata('signature', VBX_User::signature($user_id)); } } $user_id = $this->session->userdata('user_id'); // Signature check if (!empty($user_id)) { $signature = $this->session->userdata('signature'); if (!VBX_User::check_signature($user_id, $signature)) { $this->session->set_flashdata('error', 'Your session has expired'); $this->session->set_userdata('loggedin', false); } } if ($this->response_type == 'json') { $this->attempt_digest_auth(); } if (!$this->session->userdata('loggedin') && $this->response_type != 'json') { $redirect = site_url($this->uri->uri_string()); if (!empty($_COOKIE['last_known_url'])) { $redirect = $_COOKIE['last_known_url']; set_last_known_url('', time() - 3600); } return redirect('auth/login?redirect=' . urlencode($redirect)); } $this->user_id = $this->session->userdata('user_id'); $this->set_request_method(); /* Mark the user as seen */ if (!empty($this->user_id)) { try { $user = VBX_User::get($this->user_id); $user->setting_set('last_seen', new MY_ModelLiteral('UTC_TIMESTAMP()')); } catch (VBX_UserException $e) { /* Handle this gracefully, but report the error. */ error_log($e->getMessage()); } $this->connect_check(); /* Check for first run */ if ($this->session->userdata('is_admin') && $this->uri->segment(1) != 'welcome') { $this->welcome_check(); } /* Check for updates if an admin */ if ($this->session->userdata('is_admin') && $this->uri->segment(1) != "upgrade") { $this->upgrade_check(); } } }
protected function template_respond($title, $section, $payload, $layout, $layout_dir = 'content') { if (isset($payload['json'])) { unset($payload['json']); } $theme = $this->getTheme(); if (empty($payload['user'])) { $payload['user'] = VBX_user::get(array('id' => $this->session->userdata('user_id'))); } $css = array("themes/{$theme}/style"); $theme_config = $this->getThemeConfig($theme); $payload['session_id'] = $this->session->userdata('session_id'); $payload['theme'] = $theme; $payload['site_title'] = isset($theme_config['site_title']) ? $theme_config['site_title'] : ''; $payload['css'] = $css; $payload['is_admin'] = $this->session->userdata('is_admin'); $payload['email'] = $this->session->userdata('email'); $payload['logged_in'] = $this->session->userdata('loggedin'); $payload['site_rev'] = $this->config->item('site_rev'); $payload['asset_root'] = ASSET_ROOT; $payload['layout'] = $layout; if ($layout == 'yui-t2') { $payload['layout_override'] = 'yui-override-main-margin'; } else { $payload['layout_override'] = ''; } if ($user = VBX_User::get($this->session->userdata('user_id'))) { if ($user->setting('online') == 9) { $payload['user_online'] = 'client-first-run'; } else { $payload['user_online'] = (bool) $user->setting('online'); } } $navigation = $this->get_navigation($this->session->userdata('loggedin'), $this->session->userdata('is_admin')); $payload = array_merge($payload, $navigation); $payload = $this->template->clean_output($payload); $template_regions = $this->template->get_regions(); foreach (array_keys($template_regions) as $region) { if (strpos($region, '_') === 0) { continue; } if ($region == 'title') { $this->template->write('title', $title); continue; } $view = $layout_dir . '/' . $region; $content = $payload; if ($region == 'content_main') { $content = array('content' => $this->template->render('content')); $view = $layout_dir . '/content_main'; } elseif ($region == 'content') { $view = $section; } $this->template->write_view($region, $view, $content); } if ($this->input->get_post('no_layout') == 1) { return $this->template->render('content_main'); } if ($this->input->get_post('barebones') == 1) { $this->template->render('content'); } return $this->template->render(); }
function notify_message($message, $notify = false) { error_log("Notify message: " . ($notify ? 'true' : 'false')); if ($notify === false) { return; } $ci =& get_instance(); $ci->load->model('vbx_user'); $ci->load->model('vbx_group'); $recording_host = $ci->settings->get('recording_host', VBX_PARENT_TENANT); $vm_url = $message->content_url; if (trim($recording_host) != '') { $vm_url = str_replace('api.twilio.com', trim($recording_host), $vm_url); } $message->content_url = $vm_url; $users = array(); if ($message->owner_type == 'user') { $user = VBX_User::get($message->owner_id); if (!empty($user->email)) { $notify[] = $user->email; } } $group_users = array(); if ($message->owner_type == 'group') { $user_ids = $ci->vbx_group->get_user_ids($message->owner_id); $group = $ci->vbx_group->get_by_id($message->owner_id); $owner = $group->name; } else { if ($message->owner_type == 'user') { $user_ids = array($message->owner_id); $owner = 'Personal'; } } foreach ($user_ids as $user_id) { $user = VBX_User::get($user_id); $ci->load->model('vbx_device'); $ci->load->model('vbx_sms_message'); $numbers = VBX_Device::search(array('user_id' => $user_id)); $message_type = 'Voicemail'; if ($message->type == 'sms') { $message_type = 'SMS'; $owner = ''; } if ($message->type == 'voice') { openvbx_mail($user->email, "New {$owner} {$message_type} Notification - {$message->caller}", 'message', compact('message')); error_log("message queued for {$user->email}"); } foreach ($numbers as $number) { error_log($number->value); error_log(var_export($number->values, true)); if ($number->value && $number->sms) { try { $ci->vbx_sms_message->send_message($message->called, $number->value, $this->tiny_notification_message($message)); error_log("sms queued for {$number->value}"); } catch (Sms_messageException $e) { error_log("unable to send sms alert, reason: " . $e->getMessage()); } } } } }
private function delete_user() { $id = intval($this->input->post('id')); $user = VBX_User::get($id); $user->is_active = FALSE; $success = true; $errors = array(); try { $user->save(); $this->vbx_group->remove_user($id); } catch (VBX_UserException $e) { $success = false; $errors = array($e->getMessage()); } $json = compact('success', 'errors'); $data['json'] = $json; $this->respond('', 'accounts', $data); // TODO: delete it }
public static function signature($user) { if (is_numeric($user)) { $user = VBX_User::get($user); } if (!$user || !is_object($user)) { return null; } $list = implode(',', array($user->id, $user->password, $user->tenant_id, $user->is_admin)); return self::salt_encrypt($list, true); }
public function save_voicemail() { $data['json'] = array('error' => false, 'message' => ''); $user = VBX_User::get($this->user_id); $user->voicemail = $this->input->post('voicemail'); try { $user->save(); } catch (VBX_UserException $e) { $data['json']['error'] = true; $data['json']['message'] = $e->getMessage(); } return $data; }
function notify_message($message) { $ci =& get_instance(); $ci->load->model('vbx_user'); $ci->load->model('vbx_group'); $ci->load->model('vbx_incoming_numbers'); $recording_host = $ci->settings->get('recording_host', VBX_PARENT_TENANT); $vm_url = $message->content_url; if (!empty($recording_host) && trim($recording_host) != '') { $vm_url = str_replace('api.twilio.com', trim($recording_host), $vm_url); } $message->content_url = $vm_url; $users = array(); $notify = array(); if ($message->owner_type == 'user') { $user = VBX_User::get($message->owner_id); if (!empty($user->email)) { $notify[] = $user->email; } } $group_users = array(); if ($message->owner_type == 'group') { $user_ids = $ci->vbx_group->get_user_ids($message->owner_id); $group = $ci->vbx_group->get_by_id($message->owner_id); $owner = $group->name; } else { if ($message->owner_type == 'user') { $user_ids = array($message->owner_id); $owner = 'Personal'; } } $notification_setting = 'email_notifications_' . $message->type; $email_notify = $ci->vbx_settings->get($notification_setting, $ci->tenant->id); // check the incoming number's capabilities and don't even try to send // an SMS notification if the number is not allowed to send SMS messages $incoming_number = VBX_Incoming_numbers::get(array('phone_number' => normalize_phone_to_E164($message->called))); if (!empty($incoming_number) && $incoming_number->capabilities->sms == 1) { $sms_notify = true; } if ($email_notify || $sms_notify) { foreach ($user_ids as $user_id) { $user = VBX_User::get($user_id); $ci->load->model('vbx_device'); $ci->load->model('vbx_sms_message'); $numbers = VBX_Device::search(array('user_id' => $user_id)); $message_type = 'Voicemail'; if ($message->type == 'sms') { $message_type = 'SMS'; $owner = ''; } if ($email_notify) { $email_subject = "New {$owner} {$message_type} Notification - {$message->caller}"; openvbx_mail($user->email, $email_subject, 'message', compact('message')); } if ($sms_notify) { foreach ($numbers as $number) { if ($number->value && $number->sms) { try { $ci->vbx_sms_message->send_message($message->called, $number->value, $this->tiny_notification_message($message)); } catch (VBX_Sms_messageException $e) { log_message('error', 'unable to send sms alert, reason: ' . $e->getMessage()); } } } } // if ($sms_notify) } } // if ($email_notify || $sms_notify) }
private function update_details($message_id) { $message_ids = explode(',', $message_id); $archived = $this->input->post('archived'); $assigned = $this->input->post('assigned'); $ticket_status = strtolower($this->input->post('ticket_status')); $this->load->model('vbx_user'); $messages = array(); $data['json'] = array('message' => '', 'error' => false); try { foreach ($message_ids as $message_id) { try { $messages[] = $this->vbx_message->get_message($message_id); } catch (MessageException $e) { throw new DetailsException($e->getMessage()); } } foreach ($messages as $message) { if (empty($message)) { throw new DetailsException("Message[{$message_id}] does not exist"); } if ($assigned) { $assignee = VBX_User::get($assigned); } } foreach ($messages as $message) { try { if ($assigned) { $this->vbx_message->assign($message->id, $this->user_id, $assignee); } if (!empty($archived)) { $this->vbx_message->archive($message->id, $this->user_id, $archived); } if (!empty($ticket_status)) { $this->vbx_message->ticket_status($message->id, $this->user_id, $ticket_status); } } catch (MessageException $e) { throw new DetailsException($e->getMessage()); } } } catch (DetailsException $e) { $data['json'] = array('error' => true, 'message' => $e->getMessage()); } if ($this->response_type == 'html') { redirect('messages/details/' . $message_id); } $this->respond('', 'messages', $data); }
protected function template_respond($title, $section, $payload, $layout, $layout_dir = 'content') { $this->template->write('title', $title); if (isset($payload['json'])) { unset($payload['json']); } $theme = $this->getTheme(); if (empty($payload['user'])) { $payload['user'] = VBX_user::get(array('id' => $this->session->userdata('user_id'))); } $css = array("themes/{$theme}/style"); $theme_config = $this->getThemeConfig($theme); $payload['session_id'] = $this->session->userdata('session_id'); $payload['theme'] = $theme; $payload['site_title'] = isset($theme_config['site_title']) ? $theme_config['site_title'] : ''; $payload['css'] = $css; $payload['is_admin'] = $this->session->userdata('is_admin'); $payload['email'] = $this->session->userdata('email'); $payload['logged_in'] = $this->session->userdata('loggedin'); $payload['site_rev'] = $this->config->item('site_rev'); $payload['asset_root'] = ASSET_ROOT; $payload['layout'] = $layout; if ($layout == 'yui-t2') { $payload['layout_override'] = 'yui-override-main-margin'; } else { $payload['layout_override'] = ''; } if ($user = VBX_User::get($this->session->userdata('user_id'))) { if ($user->setting('online') == 9) { $payload['user_online'] = 'client-first-run'; } else { $payload['user_online'] = (bool) $user->setting('online'); } } $navigation = $this->get_navigation($this->session->userdata('loggedin'), $this->session->userdata('is_admin')); $payload = array_merge($payload, $navigation); $payload = $this->template->clean_output($payload); $this->template->write_view('wrapper_header', $layout_dir . '/wrapper_header', $payload); $this->template->write_view('header', $layout_dir . '/header', $payload); $this->template->write_view('utility_menu', $layout_dir . '/utility_menu', $payload); $this->template->write_view('context_menu', $layout_dir . '/context_menu', $payload); $this->template->write_view('content_header', $layout_dir . '/content_header', $payload); $this->template->write_view('content_sidebar', $layout_dir . '/content_sidebar', $payload); $this->template->write_view('content_footer', $layout_dir . '/content_footer', $payload); $this->template->write_view('footer', $layout_dir . '/footer', $payload); $this->template->write_view('wrapper_footer', $layout_dir . '/wrapper_footer', $payload); $this->template->write_view('error_dialog', $layout_dir . '/error_dialog', $payload); $this->template->write_view('analytics', $layout_dir . '/analytics', $payload); $this->template->write_view('content', $section, $payload); $content = $this->template->render('content'); $this->template->write_view('content_main', $layout_dir . '/content_main', compact('content')); if ($this->input->get_post('no_layout') == 1) { echo $this->template->render('content_main'); return; } if ($this->input->get_post('barebones') == 1) { echo $this->template->render('content'); return; } return $this->template->render(); }
public static function signature($user_id) { $user = VBX_User::get($user_id); if (!$user) { return null; } $list = implode(',', array($user->id, $user->password, $user->tenant_id, $user->is_admin)); return self::salt_encrypt($list); }
/** * 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); }
/** * Add a device to the Dialer * * @param VBX_Device $device * @return bool */ public function dialDevice($device) { $dialed = false; if ($device->is_active) { $user = VBX_User::get($device->user_id); $dial = $this->getDial(); $call_opts = $this->callOpts(array('whisper_to' => $user->first_name)); if (strpos($device->value, 'client:') !== false) { $dial->client(str_replace('client:', '', $device->value), $call_opts); } else { $dial->number($device->value, $call_opts); } $this->state = 'calling'; $dialed = true; } return $dialed; }
/** * Dial a user identified by their email address * * Uses $user->online to determine if user "wants" to be contacted via * Twilio Client. Passed in "online" status via $_POST can override the * attempt to dial Twilio Client even if the person has set their status * to online. The $_POST var should be representative of the Presence * Status of the user being dialed (if known). * * @param string $user_email * @param array $options * @return void */ protected function dial_user_by_email($user_email, $options) { $user = VBX_User::get(array('email' => $user_email)); if ($user instanceof VBX_User) { $dial_client = $user->online == 1; /** * Only override the user status if we've been given * an explicit opinion on the user's online status */ $client_status = $this->input->get_post('online'); if (!empty($client_status) && $client_status == 'offline') { $dial_client = false; } if (count($user->devices)) { $options['sequential'] = 'true'; $dial = $this->response->dial(NULL, $options); foreach ($user->devices as $device) { if ($device->is_active) { if (strpos($device->value, 'client:') !== false && $dial_client) { if ($dial_client) { $dial->client($user->id); } } else { $dial->number($device->value); } } } } else { $this->response->say("We're sorry, this user is currently not reachable." . " Goodbye."); } } else { $this->response->say("We're sorry, that user doesn't exist in our system." . " Please contact your system administrator. Goodbye."); } }
$dial_whom_instance = null; if (is_object($dial_whom_user_or_group)) { $dial_whom_instance = get_class($dial_whom_user_or_group); } switch ($dial_whom_instance) { case 'VBX_User': foreach ($dial_whom_user_or_group->devices as $device) { if ($device->is_active == 1) { $numbers[] = $device->value; } } $voicemail = $dial_whom_user_or_group->voicemail; break; case 'VBX_Group': foreach ($dial_whom_user_or_group->users as $user) { $user = VBX_User::get($user->user_id); foreach ($user->devices as $device) { if ($device->is_active == 1) { $numbers[] = $device->value; } } } $voicemail = $no_answer_group_voicemail; break; default: $response->addSay('Missing user or group to dial'); break; } } else { if ($dial_whom_selector === 'number') { $numbers[] = $dial_whom_number;
public static function getCurrentUser() { $ci =& get_instance(); $user_id = $ci->session->userdata('user_id'); return VBX_User::get($user_id); }
function dial() { $rest_access = $this->input->get_post('rest_access'); $to = $this->input->get_post('to'); $callerid = $this->input->get_post('callerid'); if (!$this->session->userdata('loggedin') && !$this->login_call($rest_access)) { $this->response->addSay("Unable to authenticate this call.\tGoodbye"); $this->response->addHangup(); $this->response->Respond(); return; } /* Response */ log_message('info', $rest_access . ':: Session for phone call: ' . var_export($this->session->userdata('user_id'), true)); $user = VBX_User::get($this->session->userdata('user_id')); $name = ''; if (empty($user)) { log_message('error', 'Unable to find user: '******'user_id')); } else { $name = $user->first_name; } if ($this->request->Digits !== false && $this->request->Digits == 1) { $options = array('action' => site_url("twiml/dial_status") . '?' . http_build_query(compact('to')), 'callerId' => $callerid); $dial_client = false; $to = normalize_phone_to_E164($to); if (!is_numeric($to)) { //$to = htmlspecialchars($this->input->get_post('to')); // look up user by email address $user = VBX_User::get(array('email' => $this->input->get_post('to'))); if (!empty($user)) { $dial_client = true; $to = $user->id; } } if (!$dial_client) { $this->response->addDial($to, $options); } else { $dial = new Dial(NULL, $options); $dial->append(new Client($to)); $this->response->append($dial); } } else { $gather = $this->response->addGather(array('numDigits' => 1)); $gather->addSay("Hello {$name}, this is a call from v b x" . ", to accept, press 1."); } $this->response->Respond(); }