diff --git a/mail.php b/mail.php index 7e08b5075..181766cec 100755 --- a/mail.php +++ b/mail.php @@ -8,9 +8,6 @@ $template = Template::find(get('id')); $module = $template->module; $smtp = $template->account; -$body = $template['body']; -$subject = $template['subject']; - $body = $module->replacePlaceholders($id_record, $template['body']); $subject = $module->replacePlaceholders($id_record, $template['subject']); @@ -45,7 +42,7 @@ echo '
- + diff --git a/modules/interventi/src/API/v1/Impianti.php b/modules/interventi/src/API/v1/Impianti.php index f8c22add4..c7ed69140 100755 --- a/modules/interventi/src/API/v1/Impianti.php +++ b/modules/interventi/src/API/v1/Impianti.php @@ -10,7 +10,7 @@ use API\Resource; use Modules; use Modules\Anagrafiche\Anagrafica; -class Impianti extends Resource implements RetrieveInterface +class Impianti extends Resource implements RetrieveInterface, CreateInterface { public function retrieve($request) { @@ -25,4 +25,23 @@ class Impianti extends Resource implements RetrieveInterface 'parameters' => $parameters, ]; } + + public function create($request) + { + $data = $request['data']; + $id_record = $data['id_intervento']; + + $database = database(); + $database->query('DELETE FROM my_impianti_interventi WHERE `idintervento` = :id_intervento', [ + ':id_intervento' => $id_record, + ]); + + $impianti = $data['impianti']; + foreach ($impianti as $impianto) { + $database->insert('my_impianti_interventi', [ + 'idintervento' => $id_record, + 'idimpianto' => $impianto, + ]); + } + } } diff --git a/modules/interventi/src/API/v1/Rapportino.php b/modules/interventi/src/API/v1/Rapportino.php index 7cbe050b9..2f5683933 100755 --- a/modules/interventi/src/API/v1/Rapportino.php +++ b/modules/interventi/src/API/v1/Rapportino.php @@ -10,6 +10,7 @@ use API\Resource; use Modules; use Modules\Anagrafiche\Anagrafica; use Modules\Emails\Template; +use Modules\Emails\Mail; class Rapportino extends Resource implements RetrieveInterface, CreateInterface { @@ -21,9 +22,6 @@ class Rapportino extends Resource implements RetrieveInterface, CreateInterface $template = Template::where('name', 'Rapportino intervento')->first(); $module = $template->module; - $body = $template['body']; - $subject = $template['subject']; - $body = $module->replacePlaceholders($id_record, $template['body']); $subject = $module->replacePlaceholders($id_record, $template['subject']); $email = $module->replacePlaceholders($id_record, '{email}'); @@ -40,6 +38,34 @@ class Rapportino extends Resource implements RetrieveInterface, CreateInterface public function create($request) { - // TODO: Implement create() method. + $id_record = $request['id_intervento']; + + $template = Template::where('name', 'Rapportino intervento')->first(); + $mail = Mail::build($this->getUser(), $template, $id_record); + + // Rimozione allegati predefiniti + $mail->resetPrints(); + + // Destinatari + $receivers = $request['receivers']; + foreach ($receivers as $receiver) { + $mail->addReceiver($receiver['email'], $receiver['tipo']); + } + + // Contenuti + $mail->subject = $request['subject']; + $mail->content = $request['body']; + + // Stampe da allegare + $prints = $request['prints']; + foreach ($prints as $print) { + $mail->addPrint($print['id']); + } + + $mail->save(); + + return [ + + ]; } } diff --git a/update/2_4_14.sql b/update/2_4_14.sql index 0d69812c0..db7bb1df8 100755 --- a/update/2_4_14.sql +++ b/update/2_4_14.sql @@ -485,5 +485,6 @@ UPDATE `zz_views` SET `query` = 'qta', `format` = 1 WHERE `id_module` = (SELECT INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `enabled`) VALUES (NULL, 'v1', 'retrieve', 'impianti', 'Modules\\Impianti\\API\\v1\\Impianti', '1'), (NULL, 'v1', 'retrieve', 'impianti_intervento', 'Modules\\Interventi\\API\\v1\\Impianti', '1'), +(NULL, 'v1', 'create', 'impianti_intervento', 'Modules\\Interventi\\API\\v1\\Impianti', '1'), (NULL, 'v1', 'retrieve', 'rapportino', 'Modules\\Interventi\\API\\v1\\Rapportino', '1'), (NULL, 'v1', 'create', 'rapportino', 'Modules\\Interventi\\API\\v1\\Rapportino', '1');