Skip to content

Commit

Permalink
Some edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Eywek committed Feb 4, 2018
1 parent 586fe9d commit 71cfaae
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
Router::connect('/support/ajax_create', array('controller' => 'Ticket', 'action' => 'ajax_create', 'plugin' => 'Support', 'admin' => false));
Router::connect('/support/ticket/ajax_reply', array('controller' => 'Ticket', 'action' => 'ajax_reply', 'plugin' => 'Support', 'admin' => false));
Router::connect('/support/create', array('controller' => 'Ticket', 'action' => 'create', 'plugin' => 'Support'));
Router::connect('/admin/support/ajax_delete', array('controller' => 'Ticket', 'action' => 'ajax_delete', 'plugin' => 'Support', 'admin' => true));
Router::connect('/support/ticket/*', array('controller' => 'Ticket', 'action' => 'ticket', 'plugin' => 'Support'));

105 changes: 64 additions & 41 deletions Controller/TicketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function ajax_create()
if (empty($this->request->data['subject']) || empty($this->request->data['reponse_text']))
return $this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('ERROR__FILL_ALL_FIELDS')]);
$contentTicket = $this->request->data['reponse_text'];
if (strlen($contentTicket) < 255)
if (strlen($contentTicket) < 50)
return $this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('SUPPORT__ERROR_PROBLEM_SHORT')]);

$this->loadModel('Support.Ticket');
Expand All @@ -94,38 +94,59 @@ function ajax_create()
$this->sendJSON(['statut' => true, 'msg' => $this->Lang->get('SUPPORT__SUCCESS_CREATE')]);
}

function admin_ajax_replya()
function admin_ajax_delete()
{
if (!$this->Permissions->can('MANAGE_TICKETS'))
if (!$this->Permissions->can('DELETE_TICKETS'))
throw new ForbiddenException();
if (!$this->request->is('post'))
throw new BadRequestException();
$ticket = $this->Ticket->find('first', ['conditions' => ['id' => $this->request->data['idTicket']]]);
if (empty($ticket))
throw new NotFoundException();

$contentAnswer = $this->request->data['reponse_text'];
if (strlen($contentAnswer) < 255)
$this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('SUPPORT__ERROR_RESOLVE_SHORT')]);

$this->loadModel('Support.Ticket');
$this->loadModel('Support.ReplyTicket');
$this->loadModel('Notification');

$this->Ticket->read(null, $ticket['Ticket']['id']);
$this->Ticket->set(['state' => '1']);
$this->Ticket->save();
$this->Ticket->delete($ticket['Ticket']['id']);
$this->ReplyTicket->deleteAll(array('ReplyTicket.ticket_id' => $ticket['Ticket']['id']), false);
$this->Notification->setToUser('Votre ticket N° '.$ticket['Ticket']['id'].' a été supprimé !', $ticket['Ticket']['author']);
$this->sendJSON(['statut' => true, 'msg' => $this->Lang->get('SUPPORT__SUCCESS_DELETE')]);
}

$this->ReplyTicket->set([
'ticket_id' => $this->request->data['idTicket'],
'reply' => $contentAnswer,
'author' => $this->User->getKey('id'),
'type' => 1
]);
$this->ReplyTicket->save();
function admin_ajax_replya()
{
if (!$this->Permissions->can('MANAGE_TICKETS'))
throw new ForbiddenException();
if (!$this->request->is('post'))
throw new BadRequestException();
$ticket = $this->Ticket->find('first', ['conditions' => ['id' => $this->request->data['idTicket']]]);
if (empty($ticket))
throw new NotFoundException();

$this->Notification->setToUser($this->User->getKey('pseudo') . ' ' . $this->Lang->get('SUPPORT__NOTIF_ANSWER') . ' ' . $ticket['Ticket']['id'] . ' !', $ticket['Ticket']['author']);
$this->sendJSON(['statut' => true, 'msg' => $this->Lang->get('SUPPORT__SUCCESS_SEND_ANSWER')]);
$contentAnswer = $this->request->data['reponse_text'];
if (empty($contentAnswer)){
$this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('SUPPORT__ERROR_RESOLVE_EMPTY')]);
return;
}else{
$this->loadModel('Support.Ticket');
$this->loadModel('Support.ReplyTicket');
$this->loadModel('Notification');

$this->Ticket->read(null, $ticket['Ticket']['id']);
$this->Ticket->set(['state' => '1']);
$this->Ticket->save();

$this->ReplyTicket->set([
'ticket_id' => $this->request->data['idTicket'],
'reply' => $contentAnswer,
'author' => $this->User->getKey('id'),
'type' => 1
]);
$this->ReplyTicket->save();

$this->Notification->setToUser($this->User->getKey('pseudo') . ' ' . $this->Lang->get('SUPPORT__NOTIF_ANSWER') . ' ' . $ticket['Ticket']['id'] . ' !', $ticket['Ticket']['author']);
$this->sendJSON(['statut' => true, 'msg' => $this->Lang->get('SUPPORT__SUCCESS_SEND_ANSWER')]);
}
}

function ajax_reply()
Expand All @@ -138,29 +159,31 @@ function ajax_reply()
$ticket = $this->Ticket->find('first', ['conditions' => ['id' => $this->request->data['idTicket'], 'author' => $this->User->getKey('id')]]);
if (empty($ticket))
throw new NotFoundException();

$contentAnswer = $this->request->data['reponse_text'];
if (strlen($contentAnswer) < 255)
$this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('SUPPORT__ERROR_RESOLVE_SHORT')]);

$this->loadModel('Support.Ticket');
$this->loadModel('Support.ReplyTicket');
$this->loadModel('Notification');

$this->Ticket->read(null, $ticket['Ticket']['id']);
$this->Ticket->set(['state' => 0]);
$this->Ticket->save();

$this->ReplyTicket->set([
'ticket_id' => $this->request->data['idTicket'],
'reply' => $contentAnswer,
'author' => $this->User->getKey('id'),
'type' => 0
]);
$this->ReplyTicket->save();
if ($contentAnswer != null){
$this->loadModel('Support.Ticket');
$this->loadModel('Support.ReplyTicket');
$this->loadModel('Notification');

$this->Ticket->read(null, $ticket['Ticket']['id']);
$this->Ticket->set(['state' => 0]);
$this->Ticket->save();

$this->ReplyTicket->set([
'ticket_id' => $this->request->data['idTicket'],
'reply' => $contentAnswer,
'author' => $this->User->getKey('id'),
'type' => 0
]);
$this->ReplyTicket->save();

$this->Notification->setToAdmin($this->User->getKey('pseudo') . ' ' . $this->Lang->get('SUPPORT__NOTIF_ANSWER') . ' ' . $ticket['Ticket']['id'] . ' !');
$this->sendJSON(['statut' => true, 'msg' => $this->Lang->get('SUPPORT__SUCCESS_SEND_ANSWER')]);
}else{
$this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('SUPPORT__ERROR_RESOLVE_EMPTY')]);
return;
}

$this->Notification->setToAdmin($this->User->getKey('pseudo') . ' ' . $this->Lang->get('SUPPORT__NOTIF_ANSWER') . ' ' . $ticket['Ticket']['id'] . ' !');
$this->sendJSON(['statut' => true, 'msg' => $this->Lang->get('SUPPORT__SUCCESS_SEND_ANSWER')]);
}

function ajax_clos()
Expand Down
22 changes: 11 additions & 11 deletions SQL/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ public function after($event = array()) {
}

public $support__reply_tickets = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false, 'key' => 'primary'),
'ticket_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false),
'reply' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'author' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false,),
'created' => array('type' => 'string', 'length' => 50, 'null' => false, 'default' => null),
'type' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 11, 'unsigned' => false),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1)
),
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB')
);
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false, 'key' => 'primary'),
'ticket_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false),
'reply' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'author' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false,),
'created' => array('type' => 'string', 'length' => 50, 'null' => false, 'default' => null),
'type' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 11, 'unsigned' => false),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1)
),
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB')
);

public $support__tickets = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false, 'key' => 'primary'),
Expand Down
32 changes: 22 additions & 10 deletions View/Ticket/admin_index.ctp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<?php
App::import('Controller', 'TicketController');
<?php
App::import('Controller', 'TicketController');
$TicketSupport = new TicketController();
?>
<section class="content">
Expand Down Expand Up @@ -43,14 +43,26 @@ $TicketSupport = new TicketController();
</td>
<td><?= date('d m Y', $ticket['Ticket']['created']); ?></td>
<td>
<div class="col-sm-2">
<a style="margin-right: 10px;" class="btn btn-primary" href="<?= $this->Html->url(array('plugin' => null, 'admin' => true, 'controller' => 'support', 'action' => 'ticket', $ticket['Ticket']['id'])); ?>">
<i class="fa fa-eye"></i> Voir
</a>
</div>
<?php if($ticket['Ticket']['state'] == 0 || $ticket['Ticket']['state'] == 1){ ?>
<form method="post" class="form-horizontal" data-ajax="true" data-redirect-url="?" action="<?= $this->Html->url(array('controller' => 'Ticket', 'action' => 'ajax_closa')) ?>">
<a class="btn btn-primary" href="<?= $this->Html->url(array('plugin' => null, 'admin' => true, 'controller' => 'support', 'action' => 'ticket', $ticket['Ticket']['id'])); ?>">Voir</a>
<input type="hidden" name="idTicket" value="<?= $ticket['Ticket']['id']; ?>">
<button type="submit" class="btn btn-success" href="#"><?= $Lang->get('SUPPORT__CLOSE') ?></button>
</form>
<?php }else{ ?>
<a class="btn btn-primary" href="<?= $this->Html->url(array('plugin' => null, 'admin' => true, 'controller' => 'support', 'action' => 'ticket', $ticket['Ticket']['id'])); ?>">Voir</a>
<div class="col-sm-2">
<form style="margin-right: 10px;" method="post" class="form-horizontal" data-ajax="true" data-redirect-url="?" action="<?= $this->Html->url(array('controller' => 'Ticket', 'action' => 'ajax_closa')) ?>">
<input type="hidden" name="idTicket" value="<?= $ticket['Ticket']['id']; ?>">
<button type="submit" class="btn btn-success" href="#"><i class="fa fa-bookmark"></i> <?= $Lang->get('SUPPORT__CLOSE') ?></button>
</form>
</div>
<?php }?>
<?php if($Permissions->can('DELETE_TICKETS')){ ?>
<div class="col-sm-2">
<form style="margin-right: 10px;" method="post" data-ajax="true" data-redirect-url="?" action="<?= $this->Html->url(array('controller' => 'Ticket', 'action' => 'ajax_delete')) ?>">
<input type="hidden" name="idTicket" value="<?= $ticket['Ticket']['id']; ?>">
<button type="submit" class="btn btn-danger" href="#"><i class="fa fa-remove"></i> <?= $Lang->get('SUPPORT__DELETE') ?></button>
</form>
</div>
<?php }?>
</td>
</tr>
Expand All @@ -61,4 +73,4 @@ $TicketSupport = new TicketController();
</div>
</div>
<div class="clearfix"></div>
</section>
</section>
22 changes: 15 additions & 7 deletions View/Ticket/admin_ticket.ctp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
App::import('Controller', 'TicketController');
<?php
App::import('Controller', 'TicketController');
$TicketSupport = new TicketController();
?>
<?= $this->Html->css('Support.jquery.cleditor.css'); ?>
<section class="content">
<div class="container">
<div class="row">
Expand Down Expand Up @@ -44,10 +43,21 @@ $TicketSupport = new TicketController();
<hr style="border-top: 1px solid #dedede;">
<div class="box">
<div class="box-body">
<?php if(!$ticket['Ticket']['state'] == 2){ ?>
<?php if($ticket['Ticket']['state'] != 2){ ?>
<form method="post" class="form-horizontal" data-ajax="true" data-redirect-url="../" action="<?= $this->Html->url(array('controller' => 'Ticket', 'action' => 'ajax_replya')) ?>">
<input type="hidden" name="idTicket" value="<?= $ticket['Ticket']['id']; ?>">
<textarea id="input" name="reponse_text"></textarea>
<?= $this->Html->script('admin/tinymce/tinymce.min.js') ?>
<script type="text/javascript">
tinymce.init({
selector: "textarea",
height : 300,
width : '100%',
language : 'fr_FR',
plugins: "textcolor code image link",
toolbar: "fontselect fontsizeselect bold italic underline strikethrough link image forecolor backcolor alignleft aligncenter alignright alignjustify cut copy paste bullist numlist outdent indent blockquote code"
});
</script>
<textarea id="editor" name="reponse_text" cols="30" rows="10"></textarea>
<br>
<button class="btn btn-primary" type="submit"><?= $Lang->get('SUPPORT__REPLY') ?></button>
</form>
Expand All @@ -60,5 +70,3 @@ $TicketSupport = new TicketController();
</div>
</div>
</section>
<?= $this->Html->script('Support.jquery.cleditor.min.js'); ?>
<script>$(document).ready(function() { $("#input").cleditor(); }); </script>
16 changes: 12 additions & 4 deletions View/Ticket/create.ctp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?= $this->Html->css('Support.jquery.cleditor.css'); ?>
<div class="container">
<div class="row">
<h1 style="display: inline-block;"><?= $Lang->get('SUPPORT__CREATE') ?> - <?= $Lang->get('SUPPORT__SUPPORT') ?></h1>
Expand All @@ -7,11 +6,20 @@
<label><?= $Lang->get('SUPPORT__SUBJECT') ?></label>
<input type="text" name="subject" class="form-control">
<label><?= $Lang->get('SUPPORT__YOURPROBLEM') ?></label>
<textarea id="input" name="reponse_text"></textarea>
<?= $this->Html->script('admin/tinymce/tinymce.min.js') ?>
<script type="text/javascript">
tinymce.init({
selector: "textarea",
height : 300,
width : '100%',
language : 'fr_FR',
plugins: "textcolor code image link",
toolbar: "fontselect fontsizeselect bold italic underline strikethrough link image forecolor backcolor alignleft aligncenter alignright alignjustify cut copy paste bullist numlist outdent indent blockquote code"
});
</script>
<textarea id="editor" name="reponse_text" cols="30" rows="10"></textarea>
<hr>
<button class="btn btn-primary" type="submit"><?= $Lang->get('SUPPORT__CREATETICKET') ?></button>
</form>
</div>
</div>
<?= $this->Html->script('Support.jquery.cleditor.min.js'); ?>
<script>$(document).ready(function() { $("#input").cleditor(); }); </script>
22 changes: 15 additions & 7 deletions View/Ticket/ticket.ctp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
App::import('Controller', 'TicketController');
<?php
App::import('Controller', 'TicketController');
$TicketSupport = new TicketController();
?>
<?= $this->Html->css('Support.jquery.cleditor.css'); ?>
<div class="container">
<div class="row">
<div class="col-sm-12">
Expand Down Expand Up @@ -49,10 +48,21 @@ $TicketSupport = new TicketController();
</h3>
</div>
<div class="box-body">
<?php if(!$ticket['Ticket']['state'] == 2){ ?>
<?php if($ticket['Ticket']['state'] != 2){ ?>
<form method="post" class="form-horizontal" data-ajax="true" data-redirect-url="../" action="<?= $this->Html->url(array('controller' => 'Ticket', 'action' => 'ajax_reply')) ?>">
<input type="hidden" name="idTicket" value="<?= $ticket['Ticket']['id']; ?>">
<textarea id="input" name="reponse_text"></textarea>
<?= $this->Html->script('admin/tinymce/tinymce.min.js') ?>
<script type="text/javascript">
tinymce.init({
selector: "textarea",
height : 300,
width : '100%',
language : 'fr_FR',
plugins: "textcolor code image link",
toolbar: "fontselect fontsizeselect bold italic underline strikethrough link image forecolor backcolor alignleft aligncenter alignright alignjustify cut copy paste bullist numlist outdent indent blockquote code"
});
</script>
<textarea id="editor" name="reponse_text" cols="30" rows="10"></textarea>
<br>
<button class="btn btn-primary" type="submit"><?= $Lang->get('SUPPORT__REPLY') ?></button>
</form>
Expand All @@ -64,5 +74,3 @@ $TicketSupport = new TicketController();
</div>
</div>
</div>
<?= $this->Html->script('Support.jquery.cleditor.min.js'); ?>
<script>$(document).ready(function() { $("#input").cleditor(); }); </script>
Loading

0 comments on commit 71cfaae

Please sign in to comment.