diff --git a/_ajax/send_notify.php b/_ajax/send_notify.php new file mode 100644 index 0000000..7af2f8b --- /dev/null +++ b/_ajax/send_notify.php @@ -0,0 +1,113 @@ + $value) { + trigger_error($_SERVER['HTTP_HOST'], E_USER_NOTICE); +} +*/ +include('../_include/include_db_conn.php'); + +if (empty($_POST['uk_id'])) { + echo json_encode(null); +} else { + $toNotify = new user_kid(); + $toNotify->set_user_data_by_id($_POST['uk_id']); + + if (null === $toNotify->get_uk_parent_1()->get_up_email() || null === $toNotify->get_uk_parent_1()->get_up_name()) { + echo json_encode('missing-data'); + } else { + $email_template_id = $sql->single_variable('select et_id from email_template where et_name = \'below_zero\''); + if (null !== $email_template_id) { + $emailTemplate = new email_template(); + $emailTemplate->set_et_data_by_id($email_template_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, array( + 'uk_name' => $toNotify->get_uk_name(), + )); + + $personalizedMessage = $emailTemplate->personalize($raw_message, array( + 'notify_name' => $toNotify->get_uk_parent_1()->get_up_name(), + 'uk_name' => $toNotify->get_uk_name(), + )); + + $mail = new PHPMailer(true); // Passing `true` enables exceptions + try { + //Server settings + $mail->SMTPDebug = 4; // 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($toNotify->get_uk_parent_1()->get_up_email(), $toNotify->get_uk_parent_1()->get_up_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(); + //LOG SUCCESS + email_log::create_email_log( + $personalizedMessage, + $personalizedSubject, + $toNotify->get_uk_parent_1()->get_up_name(), + $toNotify->get_uk_parent_1()->get_up_email(), + $emailTemplate->get_et_id() + ); + + //Update kids last noti date + $sql->update_table('user_kid', array('uk_last_notification' => date('Y-m-d H:i:s')), array('uk_id' => $toNotify->get_uk_id())); + + echo json_encode('success'); + + } catch (Exception $e) { + //LOG ERROR + email_log::create_email_log( + $personalizedMessage, + $personalizedSubject, + $toNotify->get_uk_parent_1()->get_up_name(), + $toNotify->get_uk_parent_1()->get_up_email(), + $emailTemplate->get_et_id(), + mysql_escape_string($e) + ); + + echo json_encode(null); + } + + //} + } + } +} + +?> + diff --git a/_class/class_camp_apply.php b/_class/class_camp_apply.php index efaa739..165312d 100644 --- a/_class/class_camp_apply.php +++ b/_class/class_camp_apply.php @@ -221,7 +221,7 @@ class camp_apply $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->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 diff --git a/_class/class_email_log.php b/_class/class_email_log.php new file mode 100644 index 0000000..4c31a58 --- /dev/null +++ b/_class/class_email_log.php @@ -0,0 +1,212 @@ +assoc_array("select * from email_log where el_id = " . $_id); + $el_data_array = $el_data_assoc_array[0]; + foreach ($el_data_array as $field => $value) { + $function_name = "set_" . $field; + $this->$function_name($value); + if ('el_email_template_et_id' == $field) { + $new_et = new email_template(); + $new_et->set_et_data_by_id($value); + $this->set_el_email_template_et_id($new_et); + } + } + } + + public static function create_email_log($_message, $_subject, $_name, $_email, $_et, $_exc = 'null', $_date = null) + { + global $sql; + + if (null === $_date) { + $_date = date('Y-m-d H:i:s'); + } + + return $sql->insert_into('email_log', array( + 'el_message' => $_message, + 'el_subject' => $_subject, + 'el_to_name' => $_name, + 'el_to_email' => $_email, + 'el_email_template_et_id' => $_et, + 'el_exception' => $_exc, + 'el_sent_date' => $_date + )); + } + + /** + * @return mixed + */ + public function get_el_id() + { + return $this->el_id; + } + + /** + * @param mixed $el_id + * + * @return self + */ + public function set_el_id($el_id) + { + $this->el_id = $el_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_el_message() + { + return $this->el_message; + } + + /** + * @param mixed $el_message + * + * @return self + */ + public function set_el_message($el_message) + { + $this->el_message = $el_message; + + return $this; + } + + /** + * @return mixed + */ + public function get_el_subject() + { + return $this->el_subject; + } + + /** + * @param mixed $el_subject + * + * @return self + */ + public function set_el_subject($el_subject) + { + $this->el_subject = $el_subject; + + return $this; + } + + /** + * @return mixed + */ + public function get_el_to_name() + { + return $this->el_to_name; + } + + /** + * @param mixed $el_to_name + * + * @return self + */ + public function set_el_to_name($el_to_name) + { + $this->el_to_name = $el_to_name; + + return $this; + } + + /** + * @return mixed + */ + public function get_el_to_email() + { + return $this->el_to_email; + } + + /** + * @param mixed $el_to_email + * + * @return self + */ + public function set_el_to_email($el_to_email) + { + $this->el_to_email = $el_to_email; + + return $this; + } + + /** + * @return mixed + */ + public function get_el_sent_date() + { + return $this->el_sent_date; + } + + /** + * @param mixed $el_sent_date + * + * @return self + */ + public function set_el_sent_date($el_sent_date) + { + $this->el_sent_date = $el_sent_date; + + return $this; + } + + /** + * @return mixed + */ + public function get_el_exception() + { + return $this->el_exception; + } + + /** + * @param mixed $el_exception + * + * @return self + */ + public function set_el_exception($el_exception) + { + $this->el_exception = $el_exception; + + return $this; + } + + /** + * @return mixed + */ + public function get_el_email_template_et_id() + { + return $this->el_email_template_et_id; + } + + /** + * @param mixed $el_email_template_et_id + * + * @return self + */ + public function set_el_email_template_et_id($el_email_template_et_id) + { + $this->el_email_template_et_id = $el_email_template_et_id; + + return $this; + } +} + + +?> + diff --git a/_class/class_user_kid.php b/_class/class_user_kid.php index 441fb8c..ec9d723 100644 --- a/_class/class_user_kid.php +++ b/_class/class_user_kid.php @@ -128,6 +128,11 @@ class user_kid extends user_parent { public function get_uk_shirt_size() { return $this->user_shirt_size; } + + public function get_uk_is_active() { + return $this->user_is_active; + } + public function get_uk_shirt_size_name() { global $sql; if ($this->user_shirt_size) return $sql->single_variable("select shirt_name from shirt where shirt_id = " . $this->user_shirt_size); @@ -375,6 +380,11 @@ class user_kid extends user_parent { $city->set_school_city_data_by_id($value); $this->set_uk_address($city); } + if ($field == 'uk_parent_1' && !empty($value)) { + $parent = new user_parent(); + $parent->set_user_data_by_id($value); + $this->set_uk_parent_1($parent); + } //$this->set_ua_type(2); //kid típus beállítása } $this->set_login(true); diff --git a/_css/default.css b/_css/default.css index 42e6537..e26e1e4 100644 --- a/_css/default.css +++ b/_css/default.css @@ -759,6 +759,10 @@ form#auto_filters > div > label { background-color: cadetblue; } +.notification-text.disabled { + opacity: 0.5; +} + .notification-text.in-progress { background-color: #f5ea16; } diff --git a/_include/include_email.php b/_include/include_email.php new file mode 100644 index 0000000..387890f --- /dev/null +++ b/_include/include_email.php @@ -0,0 +1,17 @@ +is_id()) { + + # EMAIL LOG RÉSZLETEK + + $email_log = new email_log(); + $email_log->set_el_data_by_id($this->get_id()); + + $smarty->assign('email', $email_log); + $smarty->display('email.tpl'); +} else { + +} + +?> + diff --git a/_include/include_emails.php b/_include/include_emails.php new file mode 100644 index 0000000..f11a983 --- /dev/null +++ b/_include/include_emails.php @@ -0,0 +1,37 @@ +is_id()) { + + # EMAIL LISTA (50 / oldal) + + $all_emails_query = "SELECT count(DISTINCT el_id) FROM email_log"; + $emails_query = "SELECT * FROM email_log ORDER BY el_sent_date DESC LIMIT " . ($this->is_id() ? ($this->get_id() - 1) * 50 : "0") . ",50"; + $el_assoc_array = $sql->assoc_array($emails_query); + $el_count = $sql->single_variable($all_emails_query); + $next_link = true; + + $el_array = array(); + foreach ($el_assoc_array as $key => $el) { + $new_el = new email_log(); + $new_el->set_el_data_by_id($el['el_id']); + $el_array[] = $new_el; + } + + $fold = $el_count > 50; + + if ($el_count <= $this->get_id() * 50) { + $next_link = false; + } + + $smarty->assign('el_array', $el_array); + $smarty->assign('fold', $fold); + $smarty->assign('next_id', $next_link ? $this->get_id() + 1 : false); + $smarty->assign('previous_id', ($this->get_id() > 1 ? $this->get_id() - 1 : false)); + + $smarty->display('emails.tpl'); +} else { + header("Location: /admin/emails/1"); +} + +?> + diff --git a/queries/20250525_email_logs.sql b/queries/20250525_email_logs.sql new file mode 100644 index 0000000..0b5b3c9 --- /dev/null +++ b/queries/20250525_email_logs.sql @@ -0,0 +1,7 @@ +INSERT INTO `setting` (`set_id`, `set_name`, `set_setting_type_st_id`) VALUES (NULL, 'Email küldés log', '3'); + +INSERT INTO `setting_value` (`setv_id`, `setv_set_date`, `setv_setting_set_id`, `setv_int`, `setv_varchar`, `setv_text`, `setv_date`) VALUES (NULL, '2025-05-24 15:18:09.000000', '6', NULL, 'emails', NULL, NULL); + + CREATE TABLE `email_log` ( `el_id` int(11) NOT NULL, `el_email_template_et_id` int(11) NOT NULL, `el_to_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_hungarian_ci DEFAULT NULL, `el_to_email` varchar(255) CHARACTER SET utf8 COLLATE utf8_hungarian_ci DEFAULT NULL, `el_subject` varchar(255) CHARACTER SET utf8 COLLATE utf8_hungarian_ci DEFAULT NULL, `el_message` text CHARACTER SET utf8 COLLATE utf8_hungarian_ci, `el_sent_date` datetime DEFAULT NULL, `el_exception` text CHARACTER SET utf8 COLLATE utf8_hungarian_ci ) ENGINE=InnoDB DEFAULT CHARSET=latin1 + + INSERT INTO `email_template` (`et_id`, `et_name`, `et_title`, `et_deleted`, `et_message`, `et_subject`, `et_from_name`, `et_from_email`) VALUES (NULL, 'below_zero', 'Értesítés negatív egyenlegről', '0', 'Kedves {$notify_name}!
\r\n
\r\nNyilvántartásunk szerint {$uk_name} tollaslabda edzésdíj egyenlege 0 Ft alá csökkent.
\r\n
\r\nLiving Sport
\r\n
\r\nui.: Ez egy automatikusan generált üzenet, amelyre nem várunk választ.', 'Értesítés negatív egyenlegről', 'Living Sport', 'notify@livingsport.hu'); \ No newline at end of file diff --git a/template/templates/email.tpl b/template/templates/email.tpl new file mode 100644 index 0000000..b27c137 --- /dev/null +++ b/template/templates/email.tpl @@ -0,0 +1,37 @@ +
+
+ +
{$email->get_el_to_name()}
<{$email->get_el_to_email()}>
+
+
+ +
{$email->get_el_subject()}
+
+
+ +
{$email->get_el_sent_date()}
+
+
+ +
{$email->get_el_message()}
+
+ + {if $email->get_el_exception()} +
+ +
{$email->get_el_exception()}
+
+ {/if} + + +
\ No newline at end of file diff --git a/template/templates/emails.tpl b/template/templates/emails.tpl new file mode 100644 index 0000000..f79f760 --- /dev/null +++ b/template/templates/emails.tpl @@ -0,0 +1,75 @@ +{if $fold} + + + +{/if} + +
+ + + + + + + + + + {foreach $el_array as $log} + + + + + + + + + {/foreach} +
#IDCímzettKiküldés dátumaTárgyÜzenetHibaüzenet
+ +
+ + + + \ No newline at end of file diff --git a/template/templates/user_balance_list.tpl b/template/templates/user_balance_list.tpl index 8452cdd..665cfa1 100644 --- a/template/templates/user_balance_list.tpl +++ b/template/templates/user_balance_list.tpl @@ -7,14 +7,67 @@ + +
{foreach $user_kids as $user} - -
+ +
{$user->get_uk_name()} + {if $user->get_uk_last_notification() && $page_id >= 2} + ({$user->get_uk_last_notification()}) + {/if} + {if $user->get_uk_balance() < 0 && $page_id >= 2} + {if $user->get_uk_parent_1() == null} + Értesítő e-mail + {else} + Értesítő e-mail + {/if} + {/if} {$user->get_uk_balance()|number_format:0:'':' '} Ft
{/foreach}
+