Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Hide call and online/offline when no application_sid present #231

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 78 additions & 1 deletion OpenVBX/helpers/twilio_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,84 @@ function validate_rest_request($failure_message = 'Could not validate this reque
}
}

if (!function_exists('generate_capability_token')) {
/**
* Generate a capability token for Twilio Client
*
* @param string $allow_incoming
* @return string
*/
function generate_capability_token($allow_incoming = true) {
$ci =& get_instance();
$capability = new Services_Twilio_Capability($ci->twilio_sid, $ci->twilio_token);

$user_id = intval($ci->session->userdata('user_id'));
$user = VBX_user::get(array('id' => $user_id));

$params = array(
'user_id' => $user->user_id,
);

$token = null;
try {
$capability->allowClientOutgoing($ci->application_sid, $params);
if ($allow_incoming) {
$capability->allowClientIncoming($user->id);
}
$token = $capability->generateToken(VBX_Settings::CLIENT_TOKEN_TIMEOUT);
}
catch (Exception $e) {
log_message('error', $e->getMessage());
}

return $token;
}
}

if (!function_exists('count_callerid_numbers')) {
/**
* Counts the number of Phone numbers available
*
* @return int
*/
function count_callerid_numbers() {
$ci =& get_instance();
$ci->load->model('vbx_incoming_numbers');
$numbers = array();
try
{
/* Retrieve twilio numbers w/o sandbox */
$numbers = $ci->vbx_incoming_numbers->get_numbers();
}
catch(VBX_IncomingNumberException $e)
{
error_log($e->getMessage());
throw new User_ControllerException($e->getMessage());
/* Silent fail */
return 0;
}
return count($numbers);
}
}

if (!function_exists('web_calling_enabled')) {
/**
* Determine if there are numbers and a Twilio Client Application SID available for making a call.
*
* @return boolean
*/
function web_calling_enabled() {
$ci =& get_instance();

$application_sid = $ci->vbx_settings->get('application_sid', $ci->tenant->id);
if(count_callerid_numbers()==0)
return false;
else if(!$application_sid || empty($application_sid))
return false;
return true;
}
}

if (!function_exists('clean_digits')) {
/**
* Cleans Hash and Star characters from returned Digits
Expand Down Expand Up @@ -317,4 +395,3 @@ function set_last_known_url($url, $expires = 0)
}
}

?>
4 changes: 2 additions & 2 deletions OpenVBX/views/dialer/numbers.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
global $dial_disabled;
if (!empty($callerid_numbers) && count($callerid_numbers == 1)): /* callerid_number */ ?>
if (count_callerid_numbers() == 1): /* callerid_number */ ?>

<label class="field-label"><span class="label-text">Caller ID</span>
<?php
Expand All @@ -15,7 +15,7 @@
?>
</label>

<?php elseif (!empty($callerid_numbers) && count($callerid_numbers > 1)): /* callerid_numbers */ ?>
<?php elseif (count_callerid_numbers() > 1): /* callerid_numbers */ ?>

<?php $c = $callerid_numbers[0]; ?>
<?php if(isset($c->trial) && $c->trial == 1): /* is-trail */ ?>
Expand Down
24 changes: 14 additions & 10 deletions OpenVBX/views/layout/content/context_menu.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<div id="vbx-context-menu" class="context-menu">

<div id="vbx-call-sms-buttons">
<button class="call-button twilio-call" data-href="<?php echo site_url('messages/call') ?>"><span>Call</span></button>
<?php if(web_calling_enabled()): ?>
<button class="call-button twilio-call" data-href="<?php echo site_url('messages/call') ?>"><span>Call</span></button>
<?php endif; ?>
<button class="sms-button twilio-sms" data-href="<?php echo site_url('messages/sms') ?>"><span>SMS</span></button>
</div>

<div id="vbx-client-status" class="<?php echo ($user_online == 1 ? 'online' : ''); ?>">
<div class="client-button-wrap">
<button class="client-button twilio-client">
<span class="isoffline">Offline</span><span class="isonline">Online</span>
</button>
<?php if(web_calling_enabled()): ?>
<div id="vbx-client-status" class="<?php echo ($user_online == 1 ? 'online' : ''); ?>">
<div class="client-button-wrap">
<button class="client-button twilio-client">
<span class="isoffline">Offline</span><span class="isonline">Online</span>
</button>
</div>
</div>
</div>

<?php endif; ?>
<div class="sms-dialog">
<a class="close action" href=""><span class="replace">close</span></a>
<h3>Send a Text Message</h3>
Expand All @@ -21,7 +25,7 @@
<label class="field-label left">To
<input class="small" name="to" type="text" placeholder="(555) 867 5309" value="" />
</label>
<?php if(isset($callerid_numbers) && count($callerid_numbers) > 1): ?>
<?php if(count_callerid_numbers() > 1): ?>
<label class="field-label left">From
<select name="from" class="small">
<?php foreach($callerid_numbers as $number):
Expand All @@ -36,7 +40,7 @@
<?php endforeach; ?>
</select>
</label>
<?php elseif(isset($callerid_numbers) && count($callerid_numbers) == 1):
<?php elseif(count_callerid_numbers() == 1):
$c = $callerid_numbers[0]; ?>
<input type="hidden" name="from" value="<?php echo $c->phone ?>" />
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion OpenVBX/views/layout/content/utility_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<li class="vbx-util-item"><span class="username"><?php echo $user->email ?></span></li>
<?php endif; ?>
<!-- Disabled for now...
<?php if(!empty($callerid_numbers)): ?>
<?php if(count_callerid_numbers() > 0): ?>
<?php foreach($callerid_numbers as $i => $number): ?>
<?php if(isset($number->trial) && $number->trial): ?>
<li class="util-menu-item"><p>(Trial Mode)</p></li>
Expand Down
4 changes: 2 additions & 2 deletions OpenVBX/views/layout/flow-editor/context_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@

</div><!-- #vbx-context-menu .context-menu -->

<?php if(!empty($callerid_numbers) && count($callerid_numbers) > 1): ?>
<?php if(count_callerid_numbers() > 1): ?>
<select name="callerid" class="small hide">
<?php foreach($callerid_numbers as $number): ?>
<option value="<?php echo $number->phone ?>"><?php echo $number->phone ?></option>
<?php endforeach; ?>
</select>
<?php elseif(!empty($callerid_numbers) && count($callerid_numbers) == 1): ?>
<?php elseif(count_callerid_numbers() == 1): ?>
<?php $c = $callerid_numbers[0]; ?>
<?php if(isset($c->trial) && $c->trial == 1): ?>
<input type="hidden" name="callerid" value="" class="small" />
Expand Down
2 changes: 1 addition & 1 deletion OpenVBX/views/layout/flow-editor/utility_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<li class="vbx-util-item"><span class="username"><?php echo $user->email ?></span></li>
<?php endif; ?>
<!-- Disabled for now...
<?php if(!empty($callerid_numbers)): ?>
<?php if(count_callerid_numbers() > 0): ?>
<?php foreach($callerid_numbers as $i => $number): ?>
<?php if(isset($number->trial) && $number->trial): ?>
<li class="util-menu-item"><p>(Trial Mode)</p></li>
Expand Down