mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminado
This commit is contained in:
@ -58,14 +58,14 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
|
||||
return view(static::$viewPath . 'viewTicketList', $viewData);
|
||||
}
|
||||
|
||||
private function sendMail($subject,$body,$recipient)
|
||||
private function sendMail($subject, $body, $recipient)
|
||||
{
|
||||
$settings_model = new SettingsModel();
|
||||
$config = $settings_model->first()->toArray();
|
||||
$gateway = $config['email_gateway'];
|
||||
$body = html_entity_decode($body);
|
||||
|
||||
if($gateway == 'smtp'){
|
||||
if ($gateway == 'smtp') {
|
||||
try {
|
||||
//https://codeigniter.com/user_guide/libraries/email.html
|
||||
$email = \Config\Services::email();
|
||||
@ -74,23 +74,22 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
|
||||
$config['SMTPUser'] = $config['email_address'];
|
||||
$config['SMTPPass'] = $config['email_pass'];
|
||||
$config['SMTPPort'] = intval($config['email_port']);
|
||||
$config['SMTPCrypto'] = $config['email_cert']=='none'?'':$config['email_cert'];
|
||||
$config['SMTPCrypto'] = $config['email_cert'] == 'none' ? '' : $config['email_cert'];
|
||||
$config['SMTPTimeout'] = 15;
|
||||
$config['mailType'] = 'html';
|
||||
$config['wordWrap'] = true;
|
||||
|
||||
$email->initialize($config);
|
||||
|
||||
$email->setFrom($config['email_address'], $config['email_name']);
|
||||
$email->setFrom($config['email_address'], $config['email_name']);
|
||||
$email->setTo($recipient);
|
||||
|
||||
$email->setSubject($subject);
|
||||
$email->setMessage($body);
|
||||
|
||||
if (!$email->send())
|
||||
{
|
||||
if (!$email->send()) {
|
||||
return false;
|
||||
}else{
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
@ -105,7 +104,7 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
|
||||
|
||||
//checkPermission('tickets.create', $this->indexRoute);
|
||||
|
||||
if ($this->request->getPost()) :
|
||||
if ($this->request->getPost()):
|
||||
|
||||
$nullIfEmpty = false; // !(phpversion() >= '8.1');
|
||||
|
||||
@ -118,10 +117,10 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
if ($this->canValidate()):
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
@ -135,7 +134,7 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
|
||||
|
||||
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
if ($noException && $successfulResult):
|
||||
|
||||
$id = $this->model->db->insertID();
|
||||
|
||||
@ -145,10 +144,10 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
|
||||
|
||||
$userModel = new \App\Models\UserModel();
|
||||
|
||||
$this->sendMail(lang('Tickets.newTicket'), lang('Tickets.newTicketBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['supportUser'])->email);
|
||||
$this->sendMail(lang('Tickets.newTicket'), lang('Tickets.newTicketBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['user_soporte_id'])->email);
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
if ($thenRedirect):
|
||||
if (!empty($this->indexRoute)):
|
||||
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
|
||||
else:
|
||||
return $this->redirect2listView('successMessage', $message);
|
||||
@ -181,51 +180,63 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
$modelRespuesta = new \App\Models\Soporte\TicketRespuestaModel();
|
||||
|
||||
if ($requestedId == null) :
|
||||
if ($requestedId == null):
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
||||
$ticket = $this->model->find($id);
|
||||
|
||||
if ($ticket == false) :
|
||||
if ($ticket == false):
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Tickets.ticket')), $id]);
|
||||
return $this->redirect2listView('errorMessage', $message);
|
||||
endif;
|
||||
|
||||
if(!auth()->user()->can('Tickets.edit') && auth()->user()->id != $ticket->usuario_id){
|
||||
if (!auth()->user()->can('Tickets.edit') && auth()->user()->id != $ticket->usuario_id) {
|
||||
return redirect()->to(route_to('TicketIndex'))->with('errorMessage', lang('Basic.global.noPermission'));
|
||||
}
|
||||
|
||||
if ($this->request->getPost()) :
|
||||
if ($this->request->getPost()):
|
||||
|
||||
$oldUserSupport = $ticket->user_soporte_id;
|
||||
$oldState = $ticket->estado_id;
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
$sanitizedData = $this->sanitized($postData, false);
|
||||
$sanitizedData = $this->sanitized($postData, false);
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
if ($this->canValidate()) :
|
||||
if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
if ($this->canValidate()):
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
|
||||
|
||||
$this->saveImages($id, $this->request->getFiles());
|
||||
|
||||
if(auth()->user()->can('Tickets.edit')){
|
||||
if (auth()->user()->can('Tickets.edit')) {
|
||||
|
||||
$respuesta = $modelRespuesta->where('ticket_id', $id)->first();
|
||||
if($respuesta == null){
|
||||
$respuesta = $modelRespuesta->where('ticket_id', $id)->first();
|
||||
if ($respuesta == null) {
|
||||
$modelRespuesta->insert([
|
||||
'ticket_id' => $id,
|
||||
'usuario_id' => auth()->user()->id,
|
||||
'mensaje' => $sanitizedData['respuesta_mensaje']
|
||||
]);
|
||||
}else{
|
||||
} else {
|
||||
$modelRespuesta->update($respuesta->id, [
|
||||
'mensaje' => $sanitizedData['respuesta_mensaje'],
|
||||
'usuario_id' => auth()->user()->id,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
// envio de correos
|
||||
$userModel = new \App\Models\UserModel();
|
||||
if ($oldUserSupport != $sanitizedData['supportUser']) {
|
||||
$this->sendMail(lang('Tickets.asgignToChanged'), lang('Tickets.asgignToChangedBody') . base_url(route_to('editTicket', $id)), $userModel->find($sanitizedData['supportUser'])->email);
|
||||
}
|
||||
|
||||
if ($oldState != $sanitizedData['estado_id']) {
|
||||
$this->sendMail(lang('Tickets.stateChange'), lang('Tickets.stateChangeBody') . base_url(route_to('editTicket', $id)), $userModel->find($ticket->usuario_id)->email);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
@ -242,12 +253,12 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
|
||||
|
||||
$thenRedirect = false;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
if ($noException && $successfulResult):
|
||||
$id = $ticket->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
if ($thenRedirect):
|
||||
if (!empty($this->indexRoute)):
|
||||
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
|
||||
else:
|
||||
return $this->redirect2listView('successMessage', $message);
|
||||
@ -295,9 +306,9 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
|
||||
|
||||
$searchValues = get_filter_datatables_columns($reqData);
|
||||
|
||||
if(auth()->user()->can('tickets.edit')){
|
||||
if (auth()->user()->can('tickets.edit')) {
|
||||
$user_id = null;
|
||||
}else{
|
||||
} else {
|
||||
$user_id = auth()->user()->id;
|
||||
}
|
||||
|
||||
@ -359,9 +370,9 @@ class Ticketcontroller extends \App\Controllers\BaseResourceController
|
||||
// Guardar en la base de datos
|
||||
$fileModel->insert([
|
||||
'nombre' => $originalName,
|
||||
'ticket_id' => $ticket_id,
|
||||
'hash' => $fileHash,
|
||||
'path' => 'uploads/tickets/' . $newFileName
|
||||
'ticket_id' => $ticket_id,
|
||||
'hash' => $fileHash,
|
||||
'path' => 'uploads/tickets/' . $newFileName
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user