diff --git a/OpenVBX/models/vbx_user.php b/OpenVBX/models/vbx_user.php index f37a5b38..edc397e0 100644 --- a/OpenVBX/models/vbx_user.php +++ b/OpenVBX/models/vbx_user.php @@ -90,10 +90,9 @@ static function search($search_options = array(), $limit = -1, $offset = 0) foreach($users as $i => $user) { $users[$i]->devices = VBX_Device::search(array('user_id' => $user->id), 100); - } - if ($users[$i]->online) { - array_unshift($users[$i]->devices, new VBX_Device((object) array( + if ($users[$i]->online && $users[$i]->online != 9) { + array_unshift($users[$i]->devices, new VBX_Device((object) array( 'id' => 0, 'name' => 'client', 'value' => 'client:'.$users[$i]->id, @@ -102,6 +101,7 @@ static function search($search_options = array(), $limit = -1, $offset = 0) 'is_active' => 1, 'user_id' => $users[$i]->id ))); + } } if($limit == 1 diff --git a/plugins/standard/applets/dial/TwimlDial.php b/plugins/standard/applets/dial/TwimlDial.php index 13627e5f..dca4848f 100644 --- a/plugins/standard/applets/dial/TwimlDial.php +++ b/plugins/standard/applets/dial/TwimlDial.php @@ -60,6 +60,27 @@ public function dial($device_or_user) { return $dialed; } + + protected function createDial($number = NULL, $append_to_response = true) { + if (empty($this->dial)) { + $this->dial = new Dial($number, array( + 'action' => current_url(), + 'callerId' => $this->callerId + )); + } + + if ($append_to_response) + $this->appendDial(); + + return $this->dial; + } + + protected function appendDial() { + if (!empty($this->dial) && empty($this->dial_appended)) { + $this->response->append($this->dial); + $this->dial_appended = true; + } + } /** * Add a device to the Dialer @@ -76,19 +97,15 @@ public function dialDevice($device) { 'url' => site_url('twiml/whisper?name='.urlencode($user->first_name)), ); - $dial = new Dial(NULL, array( - 'action' => current_url(), - 'callerId' => $this->callerId - )); + $this->createDial(); if (strpos($device->value, 'client:') !== false) { - $dial->addClient(str_replace('client:', '', $device->value), $call_opts); + $this->dial->addClient(str_replace('client:', '', $device->value), $call_opts); } else { - $dial->addNumber($device->value, $call_opts); + $this->dial->addNumber($device->value, $call_opts); } - $this->response->append($dial); $dialed = true; } return $dialed; @@ -105,10 +122,7 @@ public function dialUser($user) { // get users devices and add all active devices to do simultaneous dialing $dialed = false; if (count($user->devices)) { - $dial = new Dial(NULL, array( - 'action' => current_url(), - 'callerId' => $this->callerId - )); + $this->createDial(NULL, false); $call_opts = array( 'url' => site_url('twiml/whisper?name='.urlencode($user->first_name)), @@ -117,19 +131,18 @@ public function dialUser($user) { foreach ($user->devices as $device) { if ($device->is_active) { if (strpos($device->value, 'client:') !== false) { - $dial->addClient(str_replace('client:', '', $device->value), $call_opts); + $this->dial->addClient(str_replace('client:', '', $device->value), $call_opts); } else { - $dial->addNumber($device->value, $call_opts); + $this->dial->addNumber($device->value, $call_opts); } $dialed = true; - break; } } } if ($dialed) { - $this->response->append($dial); + $this->appendDial(); } return $dialed; } @@ -141,8 +154,8 @@ public function dialUser($user) { * @return bool */ public function dialNumber($number) { - $dialed = false; - $this->response->addDial($number); + $this->createDial($number); + return true; } @@ -328,4 +341,4 @@ public function save_state() { } } -?> \ No newline at end of file +?> diff --git a/plugins/standard/applets/dial/twiml.php b/plugins/standard/applets/dial/twiml.php index 645b1af6..4994edfa 100644 --- a/plugins/standard/applets/dial/twiml.php +++ b/plugins/standard/applets/dial/twiml.php @@ -22,14 +22,14 @@ do { $to_dial = $dial_list->next(); if ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device) { - $dialed = $dialer->dial($to_dial); - if ($dialed) { - $dialer->state = $dial_list->get_state(); - } + $dialed = $dialer->dial($to_dial) || $dialed; } - } while(!$dialed && ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device)); + } while((!$dialed || $dial_list instanceof DialListUser) && ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device)); - if (!$dialed) { + if ($dialed) { + $dialer->state = $dial_list->get_state(); + } + else { // nobody to call, push directly to voicemail $dialer->noanswer(); } @@ -72,7 +72,7 @@ $dialer->state = $dial_list->get_state(); } } - } while(!$dialed && ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device)); + } while((!$dialed || $dial_list instanceof DialListUser) && ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device)); if (!$dialed) { // no users left see what next action is, or go to voicemail