static function search($search_options = array(), $limit = -1, $offset = 0) { $sql_options = array('joins' => self::$joins, 'select' => self::$select); $user = new VBX_User(); $users = parent::search(self::$__CLASS__, $user->table, $search_options, $sql_options, $limit, $offset); if (empty($users)) { return $users; } if ($limit == 1) { $users = array($users); } $ci =& get_instance(); $ci->load->model('vbx_device'); foreach ($users as $i => $user) { $users[$i]->devices = VBX_Device::search(array('user_id' => $user->id), 100); } if ($limit == 1 && count($users) == 1) { return $users[0]; } return $users; }
public static function search($search_options = array(), $limit = -1, $offset = 0) { $ci =& get_instance(); $sql_options = array('joins' => self::$joins, 'select' => self::$select); $user = new VBX_User(); $users = parent::search(self::$__CLASS__, $user->table, $search_options, $sql_options, $limit, $offset); if (empty($users)) { return $users; } if ($limit == 1) { $users = array($users); } $ci->load->model('vbx_device'); foreach ($users as $i => $user) { $users[$i]->devices = VBX_Device::search(array('user_id' => $user->id), 100); if ($users[$i]->setting('online') && $users[$i]->setting('online') != 9) { array_unshift($users[$i]->devices, new VBX_Device((object) array('id' => 0, 'name' => 'client', 'value' => 'client:' . $users[$i]->id, 'sms' => 0, 'sequence' => -99, 'is_active' => 1, 'user_id' => $users[$i]->id))); } } if ($limit == 1 && count($users) == 1) { return $users[0]; } return $users; }
protected function after_login_completed($user, $redirect) { $last_seen = $user->last_seen; /* Redirect to flows if this is an admin and his inbox is zero (but not if the caller is hitting the REST api)*/ if ($this->response_type != 'json') { $is_admin = $this->session->userdata('is_admin'); if ($is_admin) { $this->load->model('vbx_incoming_numbers'); $twilio_numbers = array(); try { $twilio_numbers = $this->vbx_incoming_numbers->get_numbers(); if (empty($twilio_numbers)) { $banner = array('id' => 'first-login', 'html' => 'To start setting up OpenVBX, we suggest you start out with building your first <a href="' . site_url('flows') . '">call flow</a>. ', 'title' => 'Welcome to OpenVBX'); setrawcookie('banner', rawurlencode(json_encode($banner)), 0, '/' . ($this->tenant->id > 1 ? $this->tenant->name : '')); return redirect('numbers'); } } catch (VBX_IncomingNumberException $e) { /* Handle gracefully but log it */ error_log($e->getMessage()); } } $devices = VBX_Device::search(array('user_id' => $user->id)); if (empty($devices)) { return redirect('devices'); } } return $this->redirect($redirect); }
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) }
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()); } } } } }
protected function after_login_completed($user, $redirect) { $last_seen = $user->last_seen; // if the redirect would take us back to // the iframe the nuke it if ($redirect == site_url()) { $redirect = ''; } // Redirect to flows if this is an admin and his inbox is zero // (but not if the caller is hitting the REST api) if ($this->response_type != 'json' && empty($redirect)) { $is_admin = $this->session->userdata('is_admin'); if ($is_admin) { $this->load->model('vbx_incoming_numbers'); $twilio_numbers = array(); try { $twilio_numbers = $this->vbx_incoming_numbers->get_numbers(); if (empty($twilio_numbers)) { $banner = array('id' => 'first-login', 'html' => $this->load->view('banners/first-login', array(), true), 'title' => 'Welcome to OpenVBX'); $path = '/' . ($this->tenant->id > 1 ? $this->tenant->name : ''); setrawcookie('banner', rawurlencode(json_encode($banner)), 0, $path); set_last_known_url(site_url('/numbers')); redirect(''); } } catch (VBX_IncomingNumberException $e) { // Handle gracefully but log it log_message('error', $e->getMessage()); } } $devices = VBX_Device::search(array('user_id' => $user->id)); if (empty($devices)) { set_last_known_url(site_url('/devices')); redirect(''); } } set_last_known_url($redirect); $this->redirect(''); }