diff --git a/_class/class_camp_apply.php b/_class/class_camp_apply.php index 3e04da7..1adad0f 100644 --- a/_class/class_camp_apply.php +++ b/_class/class_camp_apply.php @@ -190,6 +190,53 @@ class camp_apply { global $sql; $sql->update_table('camp_apply', ['capp_status' => $_status_id, 'capp_accept_date' => date('Y-m-d H:i:s')], ['capp_id' => $_apply_id]); + + if (3 == $_status_id) { + $email_template_id = $sql->single_variable('select et_id from email_template where et_name = \'camp_reply\''); + if (null !== $email_template_id) { + $emailTemplate = new email_template(); + $emailTemplate->set_et_data_by_id($email_template_id); + + //felelős kapcstartó emailere küld + $contact = self::get_responsible_contact2($_apply_id); + + $raw_subject = $emailTemplate->get_et_subject(); + $raw_message = $emailTemplate->get_et_message(); + //var_dump($toNotify_array); + //foreach ($toNotify_array as $toNotify) { + $personalizedSubject = $emailTemplate->personalize($raw_subject, [ + ]); + + $personalizedMessage = $emailTemplate->personalize($raw_message, [ + ]); + + $mail = new PHPMailer(true); // Passing `true` enables exceptions + + $mail->SMTPDebug = 0; // Enable verbose debug output + $mail->isSMTP(); // Set mailer to use SMTP + $mail->CharSet = PHPMailer::CHARSET_UTF8; // UTF-8 + $mail->Host = 'mail.livingsport.hu '; // Specify main and backup SMTP servers + $mail->SMTPAuth = true; // Enable SMTP authentication + $mail->Username = 'notify@livingsport.hu'; // SMTP username + $mail->Password = 'dpDiKSqU0V'; // SMTP password + $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted + $mail->Port = 465; + + //Recipients + $mail->setFrom($emailTemplate->get_et_from_email(), $emailTemplate->get_et_from_name()); + $mail->addAddress($contact->get_cc_email(), $contact->get_cc_name()); + //$mail->addAddress('tricsusz@gmail.com', 'Tóth Richárd'); // TEST + + //Content + $mail->isHTML(true); // Set email format to HTML + $mail->Subject = $personalizedSubject; + $mail->Body = $personalizedMessage; + $mail->AltBody = 'Az Ön levelezője nem támogatja a HTML tartalom megjelenítését!'; + + //send mail + $mail->send(); + } + } } public static function has_contact($_capp_id) @@ -231,6 +278,16 @@ class camp_apply return $cc; } + public static function get_responsible_contact2($_id) + { + global $sql; + $cc_id = $sql->single_variable('SELECT cac_camp_contact_cc_id FROM camp_apply_contact WHERE cac_camp_apply_capp_id = '.$_id.' AND cac_is_responsible = 1;'); + $cc = new camp_contact(); + $cc->set_cc_data_by_id($cc_id); + + return $cc; + } + //egy létező jelentkezésnél felelős kapcsolattartóra állít valakit public static function make_contact_responsible($_apply_id, $_cc_id, $_is_responsible = false) { diff --git a/_class/class_email_template.php b/_class/class_email_template.php new file mode 100644 index 0000000..fc93831 --- /dev/null +++ b/_class/class_email_template.php @@ -0,0 +1,200 @@ +assoc_array("select * from email_template where et_id = " . $_id); + $et_data_array = $et_data_assoc_array[0]; + foreach ($et_data_array as $field => $value) { + $function_name = "set_" . $field; + $this->$function_name($value); + } + } + + /** + * @return mixed + */ + public function get_et_id() + { + return $this->et_id; + } + + /** + * @param mixed $et_id + * + * @return self + */ + public function set_et_id($et_id) + { + $this->et_id = $et_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_et_name() + { + return $this->et_name; + } + + /** + * @param mixed $et_name + * + * @return self + */ + public function set_et_name($et_name) + { + $this->et_name = $et_name; + + return $this; + } + + /** + * @return mixed + */ + public function get_et_title() + { + return $this->et_title; + } + + /** + * @param mixed $et_title + * + * @return self + */ + public function set_et_title($et_title) + { + $this->et_title = $et_title; + + return $this; + } + + /** + * @return mixed + */ + public function get_et_deleted() + { + return $this->et_deleted; + } + + /** + * @param mixed $et_deleted + * + * @return self + */ + public function set_et_deleted($et_deleted) + { + $this->et_deleted = $et_deleted; + + return $this; + } + + /** + * @return mixed + */ + public function get_et_message() + { + return $this->et_message; + } + + /** + * @param mixed $et_message + * + * @return self + */ + public function set_et_message($et_message) + { + $this->et_message = $et_message; + + return $this; + } + + /** + * @return mixed + */ + public function get_et_subject() + { + return $this->et_subject; + } + + /** + * @param mixed $et_subject + * + * @return self + */ + public function set_et_subject($et_subject) + { + $this->et_subject = $et_subject; + + return $this; + } + + /** + * @return mixed + */ + public function get_et_from_name() + { + return $this->et_from_name; + } + + /** + * @param mixed $et_from_name + * + * @return self + */ + public function set_et_from_name($et_from_name) + { + $this->et_from_name = $et_from_name; + + return $this; + } + + /** + * @return mixed + */ + public function get_et_from_email() + { + return $this->et_from_email; + } + + /** + * @param mixed $et_from_email + * + * @return self + */ + public function set_et_from_email($et_from_email) + { + $this->et_from_email = $et_from_email; + + return $this; + } + + public function personalize($_raw, $_variable_array) + { + $matches = null; + preg_match_all('/{\$([a-z0-9\_]+)}/', $_raw, $matches); + //print_r($matches); + + //[0] {$variable} + //[1] variable + foreach ($matches[0] as $key => $match) { + $_raw = str_replace($match, $_variable_array[$matches[1][$key]], $_raw); + } + + return $_raw; + } +} + + +?> diff --git a/_image/email_footer.jpg b/_image/email_footer.jpg new file mode 100644 index 0000000..b71d0ea Binary files /dev/null and b/_image/email_footer.jpg differ diff --git a/queries/202104_camp_updates.sql b/queries/202104_camp_updates.sql index fdc0171..6b2b901 100644 --- a/queries/202104_camp_updates.sql +++ b/queries/202104_camp_updates.sql @@ -16,3 +16,5 @@ ALTER TABLE `camp_apply` DROP `capp_shuttle_type`; ALTER TABLE `camp_apply` ADD `capp_money` INT NOT NULL DEFAULT '0' AFTER `capp_camp_id`; + +INSERT INTO `email_template` (`et_id`, `et_name`, `et_title`, `et_deleted`, `et_message`, `et_subject`, `et_from_name`, `et_from_email`) VALUES (NULL, 'camp_reply', 'Tábor visszaigazolás', '0', 'Kedves szülő / regisztráló!
\r\n
\r\nTábor regisztrációja sikeresen beérkezett hozzánk és jóváhagytuk!
\r\n
\r\nA regisztráció véglegesítéséhez kérjük fáradjon be a tábor díjának kiegyenlítésére!
\r\nAmennyiben utalással kíván fizetni, kérjük jelezze felénk az alábbi elérhetőségek valamelyikén!
\r\n
\r\n
\r\nTel: +36204100735 | info@livingsport.hu
\r\n2700 Cegléd, Mizsei út 03/24 Hrsz.
\r\n
\r\nÜdvözlettel,
\r\nLiving Sport csapata', 'Sikeres tábor regisztráció', 'Living Sport', 'notify@livingsport.hu');