Permalink
Browse files

updated plugin with better pagination and support for twilio API vers…

…ion updates
  • Loading branch information...
1 parent 51501ca commit 22b62617bff3f64ae7179707b4ab8b54e5ba1aaa Jonathan Kressaty committed Aug 2, 2011
Showing with 66 additions and 46 deletions.
  1. +66 −46 call_log.php
View
@@ -1,16 +1,20 @@
<?php
$ci = & get_instance();
-
+
$ci->load->helper('format_helper');
+ $ci->load->helper('date_helper');
require_once(APPPATH . 'libraries/twilio.php');
- $ci->twilio = new TwilioRestClient($ci->twilio_sid,
- $ci->twilio_token,
- $ci->twilio_endpoint);
-
- $last = end($ci->uri->segments);
+ $ci->twilio = new TwilioRestClient($ci->twilio_sid,$ci->twilio_token,$ci->twilio_endpoint);
+ if(isset($_GET['p']))
+ {
+ $last = $_GET['p'];
+ }
+ else {
+ $last = null;
+ }
if ($last != null)
{
$page = $last;
@@ -27,64 +31,80 @@
$log_xml = $log->ResponseXml;
- function status_text($status)
+ if(!empty($_POST))
{
-
- if($status == 0)
- {
- return "Not Yet Dialed";
- }
- elseif($status == 1)
- {
- return "In Progress";
- }
- elseif($status == 2)
- {
- return "Completed";
- }
- elseif($status == 3)
- {
- return "Busy";
- }
- elseif($status == 4)
- {
- return "App Error";
- }
- elseif($status == 5)
- {
- return "No Answer";
- }
- else
- {
- return "Status Unknown";
- }
+ PluginData::set('timezone',$_POST['timezones']);
}
+
+ //set initial "is it dst" to false
+ $in_dst=false;
+
+ //set the year of this campaign for use in calculation
+ $yr = date("Y", time());
+
+ //figure out when the march start of dst is in the sending year
+ $mar = strtotime("second sunday", strtotime("march 1 $yr")); // sunday >= 3/7
+
+ //figure out when the november end of dst is in the sending year
+ $nov = strtotime("first sunday", strtotime("nov 1 $yr")); // sunday after 11/1
+
+ //determine if it's dst or not
+ $isDST = time() > $mar && time() < $nov;
+
+
+ $timezone = PluginData::get("timezone",'UM8');
+
?>
<div class="vbx-plugin">
+<script type="text/javascript" src=" https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
+<script type="text/javascript" src="http://static.twilio.com/libs/twiliojs/1.0/twilio.js"></script>
+<script type="text/javascript">
+
+ function new_item(call)
+ {
+ $('#table_body tr:first').before('<tr>'+call['From']+'</tr>');
+ }
+ function formatPhone(phonenum) {
+ var regexObj = /^(?:\+?1[-. ]?)?(?:\(?([0-9]{3})\)?[-. ]?)?([0-9]{3})[-. ]?([0-9]{4})$/;
+
+ var parts = phonenum.match(regexObj);
+ var phone = "";
+ if (parts[1]) { phone += "(" + parts[1] + ") "; }
+ phone += parts[2] + "-" + parts[3];
+ return phone;
+ }
+</script>
+
<h3>Complete Call Log</h3>
+ <div style="width: 100%; height: auto; overflow: hidden;">
+ <br />
+ <form method="POST">
+ <label style="display: inline; float: left; margin-right: 20px; font-size: 16px; font-weight: bold; position: relative; top: 6px;">Set Your Timezone</label><?=timezone_menu(PluginData::get("timezone",'UM8'))?>
+ <button class="submit-button ui-state-focus" style="margin-left: 4px; display: inline; float: left;" type="submit"><span>Set Timezone</span></button>
+
+ </form>
+ </div>
<table>
<thead>
<tr>
<th>Number</th>
<th>Start Time</th>
- <!--<th>End Time</th>-->
<th>Duration</th>
<th>Called</th>
<th>Status</th>
</tr>
</thead>
- <tbody>
+ <tbody id="table_body">
<?php foreach($log_xml->Calls->Call as $call): ?>
- <tr>
- <td><?php echo format_phone($call->Caller);?></td>
- <td><?php echo date('D, M j Y g:i a', strtotime($call->StartTime));?> GMT</td>
- <!--<td><?php echo date('D, M j Y g:i a', strtotime($call->EndTime));?> GMT</td>-->
+ <tr id="<?=$call->Sid?>">
+ <td><?php echo format_phone($call->From);?></td>
+ <td><?php echo date('D, M j Y g:i a', gmt_to_local(strtotime($call->StartTime),$timezone,$isDST));?></td>
<td><?php echo $call->Duration;?> sec</td>
- <td><?php echo format_phone($call->Called);?></td>
- <td><?php echo status_text($call->Status);?></td>
+ <td><?php echo format_phone($call->To);?></td>
+ <td><?php echo $call->Status;?></td>
</tr>
<?php endforeach ?>
</tbody>
@@ -93,12 +113,12 @@ function status_text($status)
<div class="log_pagination" style="float: right;">
<?php if($last != "0" AND $last != ""):?>
- <a href="<?php echo base_url();?>p/call_log/<?php echo ($last - 1);?>">Previous</a>
+ <a href="<?php echo base_url();?>index.php/p/call_log/?p=<?php echo ($last - 1);?>">Previous</a>
<?php endif?>
<?php if($log_xml->Calls['numpages']-1 > $last):?>
- <a href="<?php echo base_url();?>p/call_log/<?php echo ($last + 1);?>">Next</a>
+ <a href="<?php echo base_url();?>index.php/p/call_log/?p=<?php echo ($last + 1);?>">Next</a>
<?php endif?>
</div>

0 comments on commit 22b6261

Please sign in to comment.