final adjustments - ready to test on beta

This commit is contained in:
Daniel Camargo 2014-02-26 17:35:19 -03:00
parent 2f0c88b07c
commit f8a128686e
9 changed files with 129 additions and 58 deletions

View File

@ -2,6 +2,9 @@ ALTER TABLE `support` ADD `id_admin` int(10) unsigned DEFAULT NULL;
ALTER TABLE `support` ADD INDEX ( `id_admin` );
ALTER TABLE `support` ADD CONSTRAINT support_ibfk_6 FOREIGN KEY (id_admin) REFERENCES `admin`(id_admin);
ALTER TABLE support MODIFY COLUMN type ENUM( 'SMS','BOX_NEED_HELP', 'WARNING' );
CREATE TABLE `support_message` (
`id_support_message` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_support` int(11) unsigned DEFAULT NULL,

View File

@ -98,11 +98,11 @@
<restaurant>_PHONE_</restaurant>
</phone>
<text>
<!-- <Judd>_PHONE_</Judd>
<Judd>_PHONE_</Judd>
<David>_PHONE_</David>
<Nick>_PHONE_</Nick>
<Tyler>_PHONE_</Tyler> -->
<Daniel>***REMOVED***</Daniel>
<!-- <Daniel>***REMOVED***</Daniel> -->
<!-- <Daniel>***REMOVED***</Daniel> -->
</text>
<stripe>

View File

@ -11,7 +11,8 @@ class Controller_Support_Plus_Content extends Crunchbutton_Controller_Account {
$resultsPerPage = 15;
$page = ( $_REQUEST[ 'page' ] ) ? $_REQUEST[ 'page' ] : 1;
$status = ( $_REQUEST[ 'status' ] ) ? $_REQUEST[ 'status' ] : '*';
$status = ( $_REQUEST[ 'status' ] ) ? $_REQUEST[ 'status' ] : 'all';
$type = ( $_REQUEST[ 'type' ] ) ? $_REQUEST[ 'type' ] : 'all';
$paginationLink = '/support/plus/content?';
@ -23,11 +24,20 @@ class Controller_Support_Plus_Content extends Crunchbutton_Controller_Account {
$where = ' AND id_restaurant IN( ' . join( $restaurants, ',' ) . ')';
}
if( $status != '*' && $status != '' ){
if( $status != 'all' && $status != '' ){
$where = ' AND status = "' . $status . '"';
$paginationLink .= '&status=' . $status;
}
if( $type != 'all' && $type != '' ){
if( $type == 'warning' ){
$where = ' AND type = "' . Crunchbutton_Support::TYPE_WARNING . '"';
} else if( 'support' ){
$where = ' AND ( type = "' . Crunchbutton_Support::TYPE_BOX_NEED_HELP . '" OR type = "' . Crunchbutton_Support::TYPE_SMS . '" ) ';
}
$paginationLink .= '&type=' . $type;
}
$query = "SELECT * FROM support WHERE 1=1 {$where} ORDER BY id_support DESC LIMIT {$limit}";
$tickets = Support::q( $query );
@ -43,8 +53,9 @@ class Controller_Support_Plus_Content extends Crunchbutton_Controller_Account {
c::view()->tickets = $tickets;
c::view()->total = $total;
c::view()->type = $type;
c::view()->page = $page;
c::view()->status = ( $status == '' || $status == '*' ) ? 'all' : $status;
c::view()->status = ( $status == '' ) ? 'all' : $status;
c::view()->startingAt = $startingAt;
c::view()->endingAt = $endingAt;
c::view()->resultsPerPage = $resultsPerPage;

View File

@ -14,20 +14,12 @@ class Controller_api_Support extends Crunchbutton_Controller_Rest {
$tsess->phone = $this->request()['phone'];
$tsess->data = json_encode( $_REQUEST );
$tsess->save();
$support = new Crunchbutton_Support;
$support->type = Crunchbutton_Support::TYPE_BOX_NEED_HELP;
$support->name = $this->request()['name'];
$support->phone = $this->request()['phone'];
$support->message = $this->request()['message'];
$support->ip = $_SERVER['REMOTE_ADDR'];
$support->id_session_twilio = $tsess->id_session_twilio;
$support->date = date('Y-m-d H:i:s');
if( c::user()->id_user ){
$support->id_user = c::user()->id_user;
}
$support->save();
$support = Crunchbutton_Support::createNewBoxTicket( [ 'phone' => $this->request()['phone'],
'name' => $this->request()['name'],
'body' => $this->request()['message'],
'id_session_twilio' => $tsess->id_session_twilio ] );
echo $support->json();
$support->queNotify();
$support->notify();
break;
case 'say':
$this->say();

View File

@ -32,12 +32,12 @@ class Controller_api_twilio_sms extends Crunchbutton_Controller_Rest {
}
}
foreach ( $sendSMSTo as $supportName => $supportPhone ) {
if ($supportPhone == $phone) {
$type = 'rep';
$rep = $supportName;
Log::debug( [ 'action' => 'rep valid', 'rep' => $supportName, 'rep phone' => $supportPhone, 'type' => 'sms' ] );
}
$admin = Admin::getByPhone( $phone );
if( $admin->id_admin ){
$rep = $admin;
$type = 'rep';
Log::debug( [ 'action' => 'rep valid', 'rep' => $admin->name, 'rep phone' => $admin->phone, 'type' => 'sms' ] );
}
switch ($type) {
@ -45,7 +45,7 @@ class Controller_api_twilio_sms extends Crunchbutton_Controller_Rest {
case 'rep':
foreach ( $sendSMSTo as $supportName => $supportPhone) {
if ($supportName == $rep) continue;
if ($supportPhone == $phone) continue;
$nums[] = $supportPhone;
}
@ -65,7 +65,7 @@ class Controller_api_twilio_sms extends Crunchbutton_Controller_Rest {
if( $body != '' ){
$this->reply( $rsess->id_session_twilio, $phone, $body, $twilio );
} else {
$msg = "$rep is now replying to @".$rsess->id_session_twilio.'. Type a message to respond.';
$msg = $rep->name . " is now replying to @".$rsess->id_session_twilio.'. Type a message to respond.';
}
}
}

View File

@ -91,23 +91,7 @@ class Crunchbutton_Order_Rules extends Cana_Model {
$message = $this->createAlert( $rule[ 'alert' ], $result );
$support = new Crunchbutton_Support();
$support->status = 'open';
$support->id_user = $order->id_user;
$support->id_order = $order->id_order;
$support->id_restaurant = $order->id_restaurant;
$support->name = $message;
$support->phone = $order->phone;
$support->ip = $_SERVER['REMOTE_ADDR'];
$support->datetime = date('Y-m-d H:i:s');
$support->save();
$note = new Support_Note();
$note->id_support = $support->id_support;
$note->text = $message;
$note->from = 'system';
$note->visibility = 'internal';
$note->save();
$support = Crunchbutton_Support::createNewWarning( [ 'id_order' => $order->id_order, 'body' => $message ] );
$message .= ' - ';
$message .= ' U: ' . $order->name;

View File

@ -4,6 +4,7 @@ class Crunchbutton_Support extends Cana_Table {
const TYPE_SMS = 'SMS';
const TYPE_BOX_NEED_HELP = 'BOX_NEED_HELP';
const TYPE_WARNING = 'WARNING';
const STATUS_OPEN = 'open';
const STATUS_CLOSED = 'closed';
@ -75,6 +76,46 @@ class Crunchbutton_Support extends Cana_Table {
return Crunchbutton_Support::o( $support->id_support );
}
public function createNewBoxTicket( $params = [] ){
$messageParams = [];
$support = new Crunchbutton_Support();
$support->type = Crunchbutton_Support::TYPE_BOX_NEED_HELP;
$support->phone = $params[ 'phone' ];
$support->status = Crunchbutton_Support::STATUS_OPEN;
$support->ip = $_SERVER[ 'REMOTE_ADDR' ];
$support->id_session_twilio = $params[ 'id_session_twilio' ];
$support->date = date( 'Y-m-d H:i:s' );
if( c::user()->id_user ){
$support->id_user = c::user()->id_user;
}
$support->save();
// Params to create the new Support message
$messageParams[ 'name' ] = $params[ 'name' ];
$messageParams[ 'phone' ] = $params[ 'phone' ];
$messageParams[ 'body' ] = $params[ 'body' ];
$support->addCustomerMessage( $messageParams );
return Crunchbutton_Support::o( $support->id_support );
}
public function createNewWarning( $params = [] ){
$support = new Crunchbutton_Support();
$support->type = Crunchbutton_Support::TYPE_WARNING;
$support->status = Crunchbutton_Support::STATUS_OPEN;
$support->ip = $_SERVER[ 'REMOTE_ADDR' ];
$support->id_session_twilio = null;
$support->date = date( 'Y-m-d H:i:s' );
if( $params[ 'id_order' ] ) {
$order = Order::o( $params[ 'id_order' ] );
$support->id_order = $order->id_order;
$support->id_restaurant = $order->id_restaurant;
$support->id_user = $order->id_user;
$support->phone = $order->phone;
}
$support->save();
$support->addSystemMessage( $params[ 'body' ] );
return Crunchbutton_Support::o( $support->id_support );
}
public function addCustomerMessage( $params = [] ){
$messageParams[ 'id_admin' ] = NULL;
$messageParams[ 'type' ] = Crunchbutton_Support_Message::TYPE_SMS;
@ -191,6 +232,8 @@ class Crunchbutton_Support extends Cana_Table {
$twilio = new Twilio(c::config()->twilio->{$env}->sid, c::config()->twilio->{$env}->token);
$message = $this->firstMessage();
$message =
"(support-" . $env . "): ".
$support->name.
@ -198,7 +241,7 @@ class Crunchbutton_Support extends Cana_Table {
"phone: ".
$support->phone.
"\n\n".
$support->message;
$message->body;
// Log
Log::debug( [ 'action' => 'support', 'message' => $message, 'type' => 'support' ] );

View File

@ -15,15 +15,26 @@
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Status: <?php echo $this->status; ?> <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" onclick="load('/support/plus/content?status=')">All</a></li>
<li><a href="#" onclick="load('/support/plus/content?status=open')">Open</a></li>
<li><a href="#" onclick="load('/support/plus/content?status=closed')">Closed</a></li>
<li><a href="#" onclick="load('/support/plus/content?type=<?php echo $this->type; ?>&status=all')">All</a></li>
<li><a href="#" onclick="load('/support/plus/content?type=<?php echo $this->type; ?>&status=open')">Open</a></li>
<li><a href="#" onclick="load('/support/plus/content?type=<?php echo $this->type; ?>&status=closed')">Closed</a></li>
</ul>
</div>
</div>
<div class="span10">
<div class="span1">
<br/>
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Type: <?php echo $this->type; ?> <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" onclick="load('/support/plus/content?staus=<?php echo $this->status; ?>&type=all')">All</a></li>
<li><a href="#" onclick="load('/support/plus/content?staus=<?php echo $this->status; ?>&type=support')">Support</a></li>
<li><a href="#" onclick="load('/support/plus/content?staus=<?php echo $this->status; ?>&type=warning')">Warning</a></li>
</ul>
</div>
</div>
<div class="span9">
<br/>
<button onclick="load('/support/plus/content?status=<?php echo $this->status ?>&page=<?php echo $this->page; ?>')" class="btn btn-default"><i class="icon-refresh"></i> Refresh</button>
<button onclick="load('/support/plus/content?type=<?php echo $this->type ?>&status=<?php echo $this->status ?>&page=<?php echo $this->page; ?>')" class="btn btn-default"><i class="icon-refresh"></i> Refresh</button>
</div>
<div class="span1" id="warning-loaded" style="display:none;">
<br/>
@ -37,6 +48,7 @@
<tr>
<td style="width: 60px;"><div>#</div></td>
<td style="width: 140px;"><div>Date</div></td>
<td style="width: 140px;"><div>Type</div></td>
<td style="width: 140px;"><div>Name</div></td>
<td><div>Message</div></td>
<td style="width: 60px;"><div>Status</div></td>
@ -57,6 +69,27 @@
} else {
$class = 'row-green';
}
switch ( $support->type ) {
case Crunchbutton_Support::TYPE_SMS:
case Crunchbutton_Support::TYPE_BOX_NEED_HELP:
$type = 'Support';
$name = $support->name();
$driver = $support->order()->driver()->name;
$message = $support->lastCustomerMessage()->body;
$customer_time = $support->lastCustomerMessage()->relativeTime();
$admin_time = $support->lastAdminMessage()->relativeTime();
$chat = true;
break;
case Crunchbutton_Support::TYPE_WARNING:
$name = '-';
$driver = false;
$type = 'System warning';
$message = $support->lastMessage()->body;
$customer_time = '-';
$admin_time = $support->lastMessage()->relativeTime();
$chat = false;
break;
}
?>
<tr class="<?php echo $class.$zebra; ?>">
<td style="white-space: nowrap;">
@ -65,25 +98,28 @@
</a>
</td>
<td nowrap><?php echo $support->repTime()->format( 'M/d D H:iA' ); ?></td>
<td nowrap><?php echo $support->name(); ?></td>
<td><?php echo $support->lastCustomerMessage()->body; ?></td>
<td nowrap><?php echo $type; ?></td>
<td nowrap><?php echo $name; ?></td>
<td><?php echo $message; ?></td>
<td><?php echo $support->status; ?></td>
<td nowrap=""><?php if( $support->order()->driver()->name ) { ?>
<td nowrap=""><?php if( $driver ) { ?>
<a href="/permissions/users/<?php echo $support->order()->driver()->id_admin ?>">
<?php echo $support->order()->driver()->name; ?>
</a>
<?php } ?>
<?php } else { ?>-<?php } ?>
<td>
<?php echo $support->lastCustomerMessage()->relativeTime(); ?>
<?php echo $customer_time; ?>
</td>
<td>
<?php echo $support->lastAdminMessage()->relativeTime(); ?>
<?php echo $admin_time; ?>
</td>
</td>
<td>
<a href="javascript://" onclick="SupportChats.createChat( '<?php echo $support->id_support; ?>' )"><button class="btn btn-mini btn-default"><i class="icon-comments"></i></button></a>
&nbsp;
<a href="/support/plus/<?= $support->id_support ?>"><button class="btn btn-mini btn-default">View</button></a>
<?php if( $chat ) { ?>
&nbsp;
<a href="javascript://" onclick="SupportChats.createChat( '<?php echo $support->id_support; ?>' )"><button class="btn btn-mini btn-default"><i class="icon-comments"></i></button></a>
<?php } ?>
</td>
</tr>
<?php

View File

@ -41,7 +41,9 @@
<div id="container-chats"></div>
<script type="text/javascript">
var status = 'open';
var type = 'support';
function load( url ){
$.ajax( {
@ -53,7 +55,7 @@ function load( url ){
};
$(function() {
load( '/support/plus/content?status=' + status );
load( '/support/plus/content?status=' + status + '&type=' + type );
} );
$(function() {