Skip to content

Commit 71cfaae

Browse files
committed
Some edits
1 parent 586fe9d commit 71cfaae

9 files changed

Lines changed: 148 additions & 120 deletions

File tree

Config/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
Router::connect('/support/ajax_create', array('controller' => 'Ticket', 'action' => 'ajax_create', 'plugin' => 'Support', 'admin' => false));
99
Router::connect('/support/ticket/ajax_reply', array('controller' => 'Ticket', 'action' => 'ajax_reply', 'plugin' => 'Support', 'admin' => false));
1010
Router::connect('/support/create', array('controller' => 'Ticket', 'action' => 'create', 'plugin' => 'Support'));
11+
Router::connect('/admin/support/ajax_delete', array('controller' => 'Ticket', 'action' => 'ajax_delete', 'plugin' => 'Support', 'admin' => true));
1112
Router::connect('/support/ticket/*', array('controller' => 'Ticket', 'action' => 'ticket', 'plugin' => 'Support'));
12-

Controller/TicketController.php

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function ajax_create()
7878
if (empty($this->request->data['subject']) || empty($this->request->data['reponse_text']))
7979
return $this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('ERROR__FILL_ALL_FIELDS')]);
8080
$contentTicket = $this->request->data['reponse_text'];
81-
if (strlen($contentTicket) < 255)
81+
if (strlen($contentTicket) < 50)
8282
return $this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('SUPPORT__ERROR_PROBLEM_SHORT')]);
8383

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

97-
function admin_ajax_replya()
97+
function admin_ajax_delete()
9898
{
99-
if (!$this->Permissions->can('MANAGE_TICKETS'))
99+
if (!$this->Permissions->can('DELETE_TICKETS'))
100100
throw new ForbiddenException();
101101
if (!$this->request->is('post'))
102102
throw new BadRequestException();
103103
$ticket = $this->Ticket->find('first', ['conditions' => ['id' => $this->request->data['idTicket']]]);
104104
if (empty($ticket))
105105
throw new NotFoundException();
106-
107-
$contentAnswer = $this->request->data['reponse_text'];
108-
if (strlen($contentAnswer) < 255)
109-
$this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('SUPPORT__ERROR_RESOLVE_SHORT')]);
110-
111106
$this->loadModel('Support.Ticket');
112107
$this->loadModel('Support.ReplyTicket');
113108
$this->loadModel('Notification');
114109

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

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

127-
$this->Notification->setToUser($this->User->getKey('pseudo') . ' ' . $this->Lang->get('SUPPORT__NOTIF_ANSWER') . ' ' . $ticket['Ticket']['id'] . ' !', $ticket['Ticket']['author']);
128-
$this->sendJSON(['statut' => true, 'msg' => $this->Lang->get('SUPPORT__SUCCESS_SEND_ANSWER')]);
126+
$contentAnswer = $this->request->data['reponse_text'];
127+
if (empty($contentAnswer)){
128+
$this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('SUPPORT__ERROR_RESOLVE_EMPTY')]);
129+
return;
130+
}else{
131+
$this->loadModel('Support.Ticket');
132+
$this->loadModel('Support.ReplyTicket');
133+
$this->loadModel('Notification');
134+
135+
$this->Ticket->read(null, $ticket['Ticket']['id']);
136+
$this->Ticket->set(['state' => '1']);
137+
$this->Ticket->save();
138+
139+
$this->ReplyTicket->set([
140+
'ticket_id' => $this->request->data['idTicket'],
141+
'reply' => $contentAnswer,
142+
'author' => $this->User->getKey('id'),
143+
'type' => 1
144+
]);
145+
$this->ReplyTicket->save();
146+
147+
$this->Notification->setToUser($this->User->getKey('pseudo') . ' ' . $this->Lang->get('SUPPORT__NOTIF_ANSWER') . ' ' . $ticket['Ticket']['id'] . ' !', $ticket['Ticket']['author']);
148+
$this->sendJSON(['statut' => true, 'msg' => $this->Lang->get('SUPPORT__SUCCESS_SEND_ANSWER')]);
149+
}
129150
}
130151

131152
function ajax_reply()
@@ -138,29 +159,31 @@ function ajax_reply()
138159
$ticket = $this->Ticket->find('first', ['conditions' => ['id' => $this->request->data['idTicket'], 'author' => $this->User->getKey('id')]]);
139160
if (empty($ticket))
140161
throw new NotFoundException();
141-
142162
$contentAnswer = $this->request->data['reponse_text'];
143-
if (strlen($contentAnswer) < 255)
144-
$this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('SUPPORT__ERROR_RESOLVE_SHORT')]);
145-
146-
$this->loadModel('Support.Ticket');
147-
$this->loadModel('Support.ReplyTicket');
148-
$this->loadModel('Notification');
149-
150-
$this->Ticket->read(null, $ticket['Ticket']['id']);
151-
$this->Ticket->set(['state' => 0]);
152-
$this->Ticket->save();
153-
154-
$this->ReplyTicket->set([
155-
'ticket_id' => $this->request->data['idTicket'],
156-
'reply' => $contentAnswer,
157-
'author' => $this->User->getKey('id'),
158-
'type' => 0
159-
]);
160-
$this->ReplyTicket->save();
163+
if ($contentAnswer != null){
164+
$this->loadModel('Support.Ticket');
165+
$this->loadModel('Support.ReplyTicket');
166+
$this->loadModel('Notification');
167+
168+
$this->Ticket->read(null, $ticket['Ticket']['id']);
169+
$this->Ticket->set(['state' => 0]);
170+
$this->Ticket->save();
171+
172+
$this->ReplyTicket->set([
173+
'ticket_id' => $this->request->data['idTicket'],
174+
'reply' => $contentAnswer,
175+
'author' => $this->User->getKey('id'),
176+
'type' => 0
177+
]);
178+
$this->ReplyTicket->save();
179+
180+
$this->Notification->setToAdmin($this->User->getKey('pseudo') . ' ' . $this->Lang->get('SUPPORT__NOTIF_ANSWER') . ' ' . $ticket['Ticket']['id'] . ' !');
181+
$this->sendJSON(['statut' => true, 'msg' => $this->Lang->get('SUPPORT__SUCCESS_SEND_ANSWER')]);
182+
}else{
183+
$this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('SUPPORT__ERROR_RESOLVE_EMPTY')]);
184+
return;
185+
}
161186

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

166189
function ajax_clos()

SQL/schema.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ public function after($event = array()) {
99
}
1010

1111
public $support__reply_tickets = array(
12-
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false, 'key' => 'primary'),
13-
'ticket_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false),
14-
'reply' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
15-
'author' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false,),
16-
'created' => array('type' => 'string', 'length' => 50, 'null' => false, 'default' => null),
17-
'type' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 11, 'unsigned' => false),
18-
'indexes' => array(
19-
'PRIMARY' => array('column' => 'id', 'unique' => 1)
20-
),
21-
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB')
22-
);
12+
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false, 'key' => 'primary'),
13+
'ticket_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false),
14+
'reply' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
15+
'author' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false,),
16+
'created' => array('type' => 'string', 'length' => 50, 'null' => false, 'default' => null),
17+
'type' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 11, 'unsigned' => false),
18+
'indexes' => array(
19+
'PRIMARY' => array('column' => 'id', 'unique' => 1)
20+
),
21+
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB')
22+
);
2323

2424
public $support__tickets = array(
2525
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false, 'key' => 'primary'),

View/Ticket/admin_index.ctp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
<?php
3-
App::import('Controller', 'TicketController');
2+
<?php
3+
App::import('Controller', 'TicketController');
44
$TicketSupport = new TicketController();
55
?>
66
<section class="content">
@@ -43,14 +43,26 @@ $TicketSupport = new TicketController();
4343
</td>
4444
<td><?= date('d m Y', $ticket['Ticket']['created']); ?></td>
4545
<td>
46+
<div class="col-sm-2">
47+
<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'])); ?>">
48+
<i class="fa fa-eye"></i> Voir
49+
</a>
50+
</div>
4651
<?php if($ticket['Ticket']['state'] == 0 || $ticket['Ticket']['state'] == 1){ ?>
47-
<form method="post" class="form-horizontal" data-ajax="true" data-redirect-url="?" action="<?= $this->Html->url(array('controller' => 'Ticket', 'action' => 'ajax_closa')) ?>">
48-
<a class="btn btn-primary" href="<?= $this->Html->url(array('plugin' => null, 'admin' => true, 'controller' => 'support', 'action' => 'ticket', $ticket['Ticket']['id'])); ?>">Voir</a>
49-
<input type="hidden" name="idTicket" value="<?= $ticket['Ticket']['id']; ?>">
50-
<button type="submit" class="btn btn-success" href="#"><?= $Lang->get('SUPPORT__CLOSE') ?></button>
51-
</form>
52-
<?php }else{ ?>
53-
<a class="btn btn-primary" href="<?= $this->Html->url(array('plugin' => null, 'admin' => true, 'controller' => 'support', 'action' => 'ticket', $ticket['Ticket']['id'])); ?>">Voir</a>
52+
<div class="col-sm-2">
53+
<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')) ?>">
54+
<input type="hidden" name="idTicket" value="<?= $ticket['Ticket']['id']; ?>">
55+
<button type="submit" class="btn btn-success" href="#"><i class="fa fa-bookmark"></i> <?= $Lang->get('SUPPORT__CLOSE') ?></button>
56+
</form>
57+
</div>
58+
<?php }?>
59+
<?php if($Permissions->can('DELETE_TICKETS')){ ?>
60+
<div class="col-sm-2">
61+
<form style="margin-right: 10px;" method="post" data-ajax="true" data-redirect-url="?" action="<?= $this->Html->url(array('controller' => 'Ticket', 'action' => 'ajax_delete')) ?>">
62+
<input type="hidden" name="idTicket" value="<?= $ticket['Ticket']['id']; ?>">
63+
<button type="submit" class="btn btn-danger" href="#"><i class="fa fa-remove"></i> <?= $Lang->get('SUPPORT__DELETE') ?></button>
64+
</form>
65+
</div>
5466
<?php }?>
5567
</td>
5668
</tr>
@@ -61,4 +73,4 @@ $TicketSupport = new TicketController();
6173
</div>
6274
</div>
6375
<div class="clearfix"></div>
64-
</section>
76+
</section>

View/Ticket/admin_ticket.ctp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<?php
2-
App::import('Controller', 'TicketController');
1+
<?php
2+
App::import('Controller', 'TicketController');
33
$TicketSupport = new TicketController();
44
?>
5-
<?= $this->Html->css('Support.jquery.cleditor.css'); ?>
65
<section class="content">
76
<div class="container">
87
<div class="row">
@@ -44,10 +43,21 @@ $TicketSupport = new TicketController();
4443
<hr style="border-top: 1px solid #dedede;">
4544
<div class="box">
4645
<div class="box-body">
47-
<?php if(!$ticket['Ticket']['state'] == 2){ ?>
46+
<?php if($ticket['Ticket']['state'] != 2){ ?>
4847
<form method="post" class="form-horizontal" data-ajax="true" data-redirect-url="../" action="<?= $this->Html->url(array('controller' => 'Ticket', 'action' => 'ajax_replya')) ?>">
4948
<input type="hidden" name="idTicket" value="<?= $ticket['Ticket']['id']; ?>">
50-
<textarea id="input" name="reponse_text"></textarea>
49+
<?= $this->Html->script('admin/tinymce/tinymce.min.js') ?>
50+
<script type="text/javascript">
51+
tinymce.init({
52+
selector: "textarea",
53+
height : 300,
54+
width : '100%',
55+
language : 'fr_FR',
56+
plugins: "textcolor code image link",
57+
toolbar: "fontselect fontsizeselect bold italic underline strikethrough link image forecolor backcolor alignleft aligncenter alignright alignjustify cut copy paste bullist numlist outdent indent blockquote code"
58+
});
59+
</script>
60+
<textarea id="editor" name="reponse_text" cols="30" rows="10"></textarea>
5161
<br>
5262
<button class="btn btn-primary" type="submit"><?= $Lang->get('SUPPORT__REPLY') ?></button>
5363
</form>
@@ -60,5 +70,3 @@ $TicketSupport = new TicketController();
6070
</div>
6171
</div>
6272
</section>
63-
<?= $this->Html->script('Support.jquery.cleditor.min.js'); ?>
64-
<script>$(document).ready(function() { $("#input").cleditor(); }); </script>

View/Ticket/create.ctp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?= $this->Html->css('Support.jquery.cleditor.css'); ?>
21
<div class="container">
32
<div class="row">
43
<h1 style="display: inline-block;"><?= $Lang->get('SUPPORT__CREATE') ?> - <?= $Lang->get('SUPPORT__SUPPORT') ?></h1>
@@ -7,11 +6,20 @@
76
<label><?= $Lang->get('SUPPORT__SUBJECT') ?></label>
87
<input type="text" name="subject" class="form-control">
98
<label><?= $Lang->get('SUPPORT__YOURPROBLEM') ?></label>
10-
<textarea id="input" name="reponse_text"></textarea>
9+
<?= $this->Html->script('admin/tinymce/tinymce.min.js') ?>
10+
<script type="text/javascript">
11+
tinymce.init({
12+
selector: "textarea",
13+
height : 300,
14+
width : '100%',
15+
language : 'fr_FR',
16+
plugins: "textcolor code image link",
17+
toolbar: "fontselect fontsizeselect bold italic underline strikethrough link image forecolor backcolor alignleft aligncenter alignright alignjustify cut copy paste bullist numlist outdent indent blockquote code"
18+
});
19+
</script>
20+
<textarea id="editor" name="reponse_text" cols="30" rows="10"></textarea>
1121
<hr>
1222
<button class="btn btn-primary" type="submit"><?= $Lang->get('SUPPORT__CREATETICKET') ?></button>
1323
</form>
1424
</div>
1525
</div>
16-
<?= $this->Html->script('Support.jquery.cleditor.min.js'); ?>
17-
<script>$(document).ready(function() { $("#input").cleditor(); }); </script>

View/Ticket/ticket.ctp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<?php
2-
App::import('Controller', 'TicketController');
1+
<?php
2+
App::import('Controller', 'TicketController');
33
$TicketSupport = new TicketController();
44
?>
5-
<?= $this->Html->css('Support.jquery.cleditor.css'); ?>
65
<div class="container">
76
<div class="row">
87
<div class="col-sm-12">
@@ -49,10 +48,21 @@ $TicketSupport = new TicketController();
4948
</h3>
5049
</div>
5150
<div class="box-body">
52-
<?php if(!$ticket['Ticket']['state'] == 2){ ?>
51+
<?php if($ticket['Ticket']['state'] != 2){ ?>
5352
<form method="post" class="form-horizontal" data-ajax="true" data-redirect-url="../" action="<?= $this->Html->url(array('controller' => 'Ticket', 'action' => 'ajax_reply')) ?>">
5453
<input type="hidden" name="idTicket" value="<?= $ticket['Ticket']['id']; ?>">
55-
<textarea id="input" name="reponse_text"></textarea>
54+
<?= $this->Html->script('admin/tinymce/tinymce.min.js') ?>
55+
<script type="text/javascript">
56+
tinymce.init({
57+
selector: "textarea",
58+
height : 300,
59+
width : '100%',
60+
language : 'fr_FR',
61+
plugins: "textcolor code image link",
62+
toolbar: "fontselect fontsizeselect bold italic underline strikethrough link image forecolor backcolor alignleft aligncenter alignright alignjustify cut copy paste bullist numlist outdent indent blockquote code"
63+
});
64+
</script>
65+
<textarea id="editor" name="reponse_text" cols="30" rows="10"></textarea>
5666
<br>
5767
<button class="btn btn-primary" type="submit"><?= $Lang->get('SUPPORT__REPLY') ?></button>
5868
</form>
@@ -64,5 +74,3 @@ $TicketSupport = new TicketController();
6474
</div>
6575
</div>
6676
</div>
67-
<?= $this->Html->script('Support.jquery.cleditor.min.js'); ?>
68-
<script>$(document).ready(function() { $("#input").cleditor(); }); </script>

0 commit comments

Comments
 (0)