diff --git a/src/API/App/v1/RapportinoIntervento.php b/src/API/App/v1/RapportinoIntervento.php new file mode 100644 index 000000000..d79778581 --- /dev/null +++ b/src/API/App/v1/RapportinoIntervento.php @@ -0,0 +1,67 @@ +first(); + $module = $template->module; + + $body = $module->replacePlaceholders($id_record, $template['body']); + $subject = $module->replacePlaceholders($id_record, $template['subject']); + $email = $module->replacePlaceholders($id_record, '{email}'); + + $prints = $database->fetchArray('SELECT id, title, EXISTS(SELECT id_print FROM em_print_template WHERE id_template = '.prepare($template['id']).' AND em_print_template.id_print = zz_prints.id) AS selected FROM zz_prints WHERE id_module = '.prepare($module->id).' AND enabled = 1'); + + return [ + 'email' => $email, + 'subject' => $subject, + 'body' => $body, + 'prints' => $prints, + ]; + } + + public function create($request) + { + $data = $request['data']; + $id_record = $data['id']; + + $template = Template::where('name', 'Rapportino intervento')->first(); + $mail = Mail::build($this->getUser(), $template, $id_record); + + // Rimozione allegati predefiniti + $mail->resetPrints(); + + // Destinatari + $receivers = $data['receivers']; + foreach ($receivers as $receiver) { + $mail->addReceiver($receiver['email'], $receiver['tipo']); + } + + // Contenuti + $mail->subject = $data['subject']; + $mail->content = $data['body']; + + // Stampe da allegare + $prints = $data['prints']; + foreach ($prints as $print_id) { + $mail->addPrint($print_id); + } + + $mail->save(); + + return [ + ]; + } +} diff --git a/update/2_4_16.sql b/update/2_4_16.sql index f98bfed63..65bdfca6d 100644 --- a/update/2_4_16.sql +++ b/update/2_4_16.sql @@ -172,7 +172,10 @@ INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `e (NULL, 'app-v1', 'update', 'sessione', 'API\\App\\v1\\Sessioni', '1'), (NULL, 'app-v1', 'create', 'riga-intervento', 'API\\App\\v1\\Righe', '1'), (NULL, 'app-v1', 'update', 'riga-intervento', 'API\\App\\v1\\Righe', '1'), -(NULL, 'app-v1', 'delete', 'riga-intervento', 'API\\App\\v1\\Righe', '1'); +(NULL, 'app-v1', 'delete', 'riga-intervento', 'API\\App\\v1\\Righe', '1'), + +(NULL, 'app-v1', 'retrieve', 'email-rapportino', 'API\\App\\v1\\RapportinoIntervento', '1'), +(NULL, 'app-v1', 'create', 'email-rapportino', 'API\\App\\v1\\RapportinoIntervento', '1'); -- Impostazioni relative all'applicazione INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES