@@ -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 ()
0 commit comments