send email; manage notis and email logs

This commit is contained in:
Tóth Richárd
2018-10-23 21:56:06 +02:00
parent 85180a91b6
commit 7a24fdee51
14 changed files with 217 additions and 98 deletions

View File

@@ -1,3 +0,0 @@
INSERT INTO `badminton_coach`.`setting` (`set_name`, `set_setting_type_st_id`) VALUES ('E-mail küldés log', '3');
INSERT INTO `badminton_coach`.`setting_value` (`setv_id`, `setv_set_date`, `setv_setting_set_id`, `setv_varchar`) VALUES (NULL, '2017-03-14 00:00:00', '7', 'emails');

View File

@@ -255,6 +255,14 @@ class page {
# email log details # email log details
include('include_email.php'); include('include_email.php');
break; break;
case 'notifications':
# értesítések
include('include_notifications.php');
break;
case 'delete_notification':
# ÉRTESÍTÉS TÖRLÉS (NULLÁZÁS)
include('include_delete_notification.php');
break;
case 'delete_training_type': case 'delete_training_type':
# EDZÉS TÍPUS TÖRLÉS # EDZÉS TÍPUS TÖRLÉS
include('include_delete_training_type.php'); include('include_delete_training_type.php');

View File

@@ -50,7 +50,7 @@ class sql extends mysqli {
$i++; $i++;
} }
$this->_query = 'insert into ' . $table . ' (' . $fields . ') values (' . $values . ');'; $this->_query = 'insert into ' . $table . ' (' . $fields . ') values (' . $values . ');';
var_dump($this->_query); //var_dump($this->_query);
self::query($this->_query); self::query($this->_query);
return $this->insert_id; return $this->insert_id;
} }

View File

@@ -174,6 +174,13 @@ td.create a {
font-size: 18px; font-size: 18px;
} }
.list.noti {
display: flex;
}
a.addbutton.noti {
margin-left: 10px;
}
.list_item table.money { .list_item table.money {
width: 100%; width: 100%;
@@ -387,6 +394,10 @@ table.log tr.delete:hover {
background-color: #f02a2a; background-color: #f02a2a;
} }
table.email.log tr:hover {
cursor: pointer;
}
.date_separator img { .date_separator img {
width: 20px; width: 20px;
float: right; float: right;

View File

@@ -0,0 +1,9 @@
<?php
if ($this->is_id()) {
$sql->update_table('user_kid', array('uk_last_notification' => 'null'), array('uk_id' => $this->get_id()));
header("Location: /admin/notifications");
}
?>

View File

@@ -7,7 +7,7 @@ if ($this->is_id()) {
$email_log = new email_log(); $email_log = new email_log();
$email_log->set_el_data_by_id($this->get_id()); $email_log->set_el_data_by_id($this->get_id());
$smarty->assign('email_log', $email_log); $smarty->assign('email', $email_log);
$smarty->display('email.tpl'); $smarty->display('email.tpl');
} }
else { else {

View File

@@ -5,7 +5,7 @@ if ($this->is_id()) {
# EMAIL LISTA (50 / oldal) # EMAIL LISTA (50 / oldal)
$all_emails_query = "SELECT count(DISTINCT el_id) FROM email_log"; $all_emails_query = "SELECT count(DISTINCT el_id) FROM email_log";
$emails_query = "SELECT * FROM email_log LIMIT ".($this->is_id()?($this->get_id()-1) * 50:"0").",50"; $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_assoc_array = $sql->assoc_array($emails_query);
$el_count = $sql->single_variable($all_emails_query); $el_count = $sql->single_variable($all_emails_query);
$next_link = true; $next_link = true;

View File

@@ -7,7 +7,6 @@ if ($this->is_id()) {
# EDZÉS ZÁROLÁS/FELOLDÁS # EDZÉS ZÁROLÁS/FELOLDÁS
$locked = $sql->single_variable('select tr_locked from training where tr_id =' . $this->get_id()); $locked = $sql->single_variable('select tr_locked from training where tr_id =' . $this->get_id());
/*
$sql->update_table('training', array( $sql->update_table('training', array(
'tr_locked' => ($locked?0:1) 'tr_locked' => ($locked?0:1)
), ),
@@ -16,7 +15,6 @@ if ($this->is_id()) {
) )
); );
log::register(($locked?'training_open':'training_close'), $this->get_id()); log::register(($locked?'training_open':'training_close'), $this->get_id());
*/
//SEND NOTIFICATION //SEND NOTIFICATION
if (!$locked) { if (!$locked) {
@@ -83,8 +81,9 @@ if ($this->is_id()) {
$mail = new PHPMailer(true); // Passing `true` enables exceptions $mail = new PHPMailer(true); // Passing `true` enables exceptions
try { try {
//Server settings //Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output $mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP $mail->isSMTP(); // Set mailer to use SMTP
$mail->CharSet = PHPMailer::CHARSET_UTF8; // UTF-8
$mail->Host = 'mail.gginternet.com '; // Specify main and backup SMTP servers $mail->Host = 'mail.gginternet.com '; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication $mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'hirlevel@tollaslabda.info'; // SMTP username $mail->Username = 'hirlevel@tollaslabda.info'; // SMTP username
@@ -94,8 +93,8 @@ if ($this->is_id()) {
//Recipients //Recipients
$mail->setFrom($emailTemplate->get_et_from_email(), $emailTemplate->get_et_from_name()); $mail->setFrom($emailTemplate->get_et_from_email(), $emailTemplate->get_et_from_name());
$mail->addBCC($kid->get_uk_notify_email(), $kid->get_uk_notify_name());
$mail->addBCC('tricsusz@gmail.com', 'Tóth Richárd'); // TEST $mail->addBCC('tricsusz@gmail.com', 'Tóth Richárd'); // TEST
//$mail->addBCC($kid->get_uk_notify_email(), $kid->get_uk_notify_name());
//Content //Content
@@ -104,7 +103,8 @@ if ($this->is_id()) {
$mail->Body = $personalizedMessage; $mail->Body = $personalizedMessage;
$mail->AltBody = 'Az Ön levelezője nem támogatja a HTML tartalom megjelenítését!'; $mail->AltBody = 'Az Ön levelezője nem támogatja a HTML tartalom megjelenítését!';
//$mail->send(); //send mail
$mail->send();
//LOG SUCCESS //LOG SUCCESS
email_log::create_email_log( email_log::create_email_log(
$personalizedMessage, $personalizedMessage,
@@ -114,7 +114,8 @@ if ($this->is_id()) {
$emailTemplate->get_et_id() $emailTemplate->get_et_id()
); );
//TODO: Update kids last noti date //Update kids last noti date
$sql->update_table('user_kid', array('uk_last_notification' => date('Y-m-d H:i:s')), array('uk_id' => $kid->get_uk_id()));
} catch (Exception $e) { } catch (Exception $e) {
//LOG ERROR //LOG ERROR
@@ -124,7 +125,7 @@ if ($this->is_id()) {
$kid->get_uk_notify_name(), $kid->get_uk_notify_name(),
$kid->get_uk_notify_email(), $kid->get_uk_notify_email(),
$emailTemplate->get_et_id(), $emailTemplate->get_et_id(),
$e mysql_escape_string($e)
); );
} }
@@ -132,7 +133,7 @@ if ($this->is_id()) {
} }
} }
//header('Location: /admin/presence/' . $this->get_id()); header('Location: /admin/presence/' . $this->get_id());
} }
?> ?>

View File

@@ -0,0 +1,36 @@
<?php
# HA NINCS ID, AKKOR ÉRTESÍTÉSEK
if ($this->is_id()) {
}
else {
# ÉRTESÍTÉSEK
//hány óránként küldünk emailt
$notify_hours = $sql->single_variable(' SELECT
setv_int
FROM
setting_value
JOIN
setting ON setv_setting_set_id = set_id
WHERE
set_name = "Értesítések közt eltelt idő";
;');
//akiket értesítettünk az elmúlt x órában
$notifiedKids = $sql->assoc_array('select * from user_kid WHERE DATE_SUB(CURDATE(),INTERVAL '.$notify_hours.' HOUR) <= uk_last_notification order by uk_name ASC;');
$kid_array = array();
foreach ($notifiedKids as $key => $kid) {
$new_kid = new user_kid();
$new_kid->set_user_data_by_id($kid['uk_id']);
$kid_array[] = $new_kid;
}
$smarty->assign('kid_array', $kid_array);
$smarty->display('notifications.tpl');
}
?>

View File

@@ -1,24 +1,24 @@
<div class="form_wrapper"> <div class="form_wrapper">
<form method="post"> <form method="post">
<input type="hidden" name="action" value="city_update"> <input type="hidden" name="action" value="city_update">
<div class="buttons"> <div class="buttons">
<a href="/admin/create/city" class="addbutton add-big">Új település hozzáadása</a> <a href="/admin/create/city" class="addbutton add-big">Új település hozzáadása</a>
</div> </div>
{foreach $scc_assoc_array as $scc} {foreach $scc_assoc_array as $scc}
<div> <div>
<div style="float: left;"> <div style="float: left;">
<input type="text" name="scc_{$scc.scc_id}" id="scc_{$scc.scc_id}" value="{$scc.scc_city}"> <input type="text" name="scc_{$scc.scc_id}" id="scc_{$scc.scc_id}" value="{$scc.scc_city}">
<input type="number" min="0" name="order_{$scc.scc_id}" id="order_{$scc.scc_id}" value="{$scc.scc_order}" size="3"> <input type="number" min="0" name="order_{$scc.scc_id}" id="order_{$scc.scc_id}" value="{$scc.scc_order}" size="3">
<a href="/admin/delete_city/{$scc.scc_id}" class="addbutton delete">Törlés</a> <a href="/admin/delete_city/{$scc.scc_id}" class="addbutton delete">Törlés</a>
</div> </div>
</div> </div>
{/foreach} {/foreach}
<div> <div>
<div style="float: left;"> <div style="float: left;">
<input class="button black" type="submit" value="Mentés"> <input class="button black" type="submit" value="Mentés">
</div> </div>
</div> </div>
</form> </form>
</div> </div>

View File

@@ -0,0 +1,37 @@
<div class="list">
<div class="list_item">
<label class="desc" id="title1" for="tr_duration">
Címzett:
</label>
<div>{$email->get_el_to_name()}<br>&lt;{$email->get_el_to_email()}&gt;</div>
</div>
<div class="list_item">
<label class="desc" id="title1" for="tr_duration">
Tárgy:
</label>
<div>{$email->get_el_subject()}</div>
</div>
<div class="list_item">
<label class="desc" id="title1" for="tr_duration">
Kiküldés dátuma:
</label>
<div>{$email->get_el_sent_date()}</div>
</div>
<div class="list_item">
<label class="desc" id="title1" for="tr_duration">
Üzenet:
</label>
<div>{$email->get_el_message()}</div>
</div>
{if $email->get_el_exception()}
<div class="list_item">
<label class="desc" id="title1" for="tr_duration">
Üzenet:
</label>
<div>{$email->get_el_exception()}</div>
</div>
{/if}
</div>

View File

@@ -24,7 +24,7 @@
{/if} {/if}
<div style="overflow-x:auto;"> <div style="overflow-x:auto;">
<table class="log"> <table class="email log">
<tr> <tr>
<th class="left">#ID</th> <th class="left">#ID</th>
<th class="left">Címzett</th> <th class="left">Címzett</th>
@@ -34,7 +34,7 @@
<th class="left">Hibaüzenet</th> <th class="left">Hibaüzenet</th>
</tr> </tr>
{foreach $el_array as $log} {foreach $el_array as $log}
<tr class="email-log{if $log->get_el_exception()} delete{else} tick{/if}"> <tr class="email-log{if $log->get_el_exception()} delete{else} tick{/if}" data-log-id="{$log->get_el_id()}">
<td>#{$log->get_el_id()}</td> <td>#{$log->get_el_id()}</td>
<td>{$log->get_el_to_name()}<br>&lt;{$log->get_el_to_email()}&gt;</td> <td>{$log->get_el_to_name()}<br>&lt;{$log->get_el_to_email()}&gt;</td>
<td>{$log->get_el_sent_date()}</td> <td>{$log->get_el_sent_date()}</td>
@@ -67,3 +67,9 @@
{/if} {/if}
</div> </div>
</div> </div>
<script type="text/javascript">
$('table.email.log tr.email-log').click(function() {
window.location.href = '/admin/email/'+$(this).data('log-id');
});
</script>

View File

@@ -0,0 +1,14 @@
<div class="list noti">
{if !count($kid_array)}
Nincs találat!
{/if}
{foreach $kid_array as $kid}
<div class="list_item noti">
<label>
{$kid->get_uk_name()}
</label>
<div>{$kid->get_uk_last_notification()}</div>
</div>
<a href="/admin/delete_notification/{$kid->get_uk_id()}" class="addbutton delete noti">Törlés</a>
{/foreach}
</div>

View File

@@ -9,64 +9,64 @@
</div> </div>
<div class="list"> <div class="list">
<div class="list_item"> <div class="list_item">
<label class="desc" id="title1" for="tr_date"> <label class="desc" id="title1" for="tr_date">
<img src="/_image/training.png"> <img src="/_image/training.png">
Dátum: Dátum:
</label> </label>
<div> <div>
{$training->get_tr_date()|substr:0:4}. {$training->get_tr_date()|substr:0:4}.
{$months[$training->get_tr_date()|substr:5:2]} {$months[$training->get_tr_date()|substr:5:2]}
{$training->get_tr_date_day()}. {$training->get_tr_date_day()}.
{$days[$training->get_tr_date_day_of_week()]} {$days[$training->get_tr_date_day_of_week()]}
{$training->get_tr_date_time()} {$training->get_tr_date_time()}
</div>
</div> </div>
</div>
<div class="list_item"> <div class="list_item">
<label class="desc" id="title2" for="tr_training_type_trt_id"> <label class="desc" id="title2" for="tr_training_type_trt_id">
<img src="/_image/tipus.png"> <img src="/_image/tipus.png">
Típus: Típus:
</label> </label>
<div> <div>
{$training->get_tr_type_name_by_id()} {$training->get_tr_type_name_by_id()}
</div>
</div> </div>
</div>
<div class="list_item"> <div class="list_item">
<label class="desc" id="title1" for="tr_duration"> <label class="desc" id="title1" for="tr_duration">
<img src="/_image/time.png"> <img src="/_image/time.png">
Időtartam: Időtartam:
</label> </label>
<div>{$training->get_tr_duration()} perc</div> <div>{$training->get_tr_duration()} perc</div>
</div>
{if $trc_coaches}
<div class="list_item">
<label class="desc" id="title1" for="coaches">
<img src="/_image/coach.png">
Edző(k):
</label>
<div style="display: inline-block;">
{foreach $trc_coaches as $coach}
{$coach->get_ua_name()}<br>
{/foreach}
{foreach $trc_helpers as $coach}
<span class="italic">{$coach->get_ua_name()}</span><br>
{/foreach}
</div> </div>
</div>
{/if}
<div class="list_item"> {if $trc_coaches}
<label class="desc" id="title1" for="tr_headcount"> <div class="list_item">
<img src="/_image/letszam.png"> <label class="desc" id="title1" for="coaches">
Létszám: <img src="/_image/coach.png">
</label> Edző(k):
<div id="headcount"> </label>
{$headcount} <div style="display: inline-block;">
</div> {foreach $trc_coaches as $coach}
</div> {$coach->get_ua_name()}<br>
{/foreach}
{foreach $trc_helpers as $coach}
<span class="italic">{$coach->get_ua_name()}</span><br>
{/foreach}
</div>
</div>
{/if}
<div class="list_item">
<label class="desc" id="title1" for="tr_headcount">
<img src="/_image/letszam.png">
Létszám:
</label>
<div id="headcount">
{$headcount}
</div>
</div>
</div> </div>
@@ -88,9 +88,9 @@
{/if} {/if}
<div class="{if $user->get_uk_presence($tr_id)}name_tag_checked{else}name_tag{/if} width70" id="{$user->get_uk_id()}"> <div class="{if $user->get_uk_presence($tr_id)}name_tag_checked{else}name_tag{/if} width70" id="{$user->get_uk_id()}">
<img src="/_image/shuttlecock.png"> <img src="/_image/shuttlecock.png">
<div>{$user->get_uk_name()}</div> <div>{$user->get_uk_name()}</div>
</div> </div>
{/foreach} {/foreach}
</div> </div>
@@ -100,7 +100,7 @@
{foreach $rest_users as $rest_user} {foreach $rest_users as $rest_user}
<div class="{if $rest_user->get_uk_presence($tr_id)}name_tag_checked{else}name_tag{/if} width70" id="{$rest_user->get_uk_id()}"> <div class="{if $rest_user->get_uk_presence($tr_id)}name_tag_checked{else}name_tag{/if} width70" id="{$rest_user->get_uk_id()}">
<img src="/_image/shuttlecock.png"> <img src="/_image/shuttlecock.png">
<div>{$rest_user->get_uk_name()}</div> <div>{$rest_user->get_uk_name()}</div>
</div> </div>
{/foreach} {/foreach}
</div> </div>
@@ -151,7 +151,7 @@ $('.name_tag').click(function() {
url: '/_ajax/update_presence.php', url: '/_ajax/update_presence.php',
data: { checked : checked, user_id : user_id, tr_id : tr_id, admin_id : admin_id}, data: { checked : checked, user_id : user_id, tr_id : tr_id, admin_id : admin_id},
success: function(data) { success: function(data) {
} }
}); });
@@ -181,13 +181,13 @@ $('.name_tag_checked').click(function() {
//alert(checked); //alert(checked);
var admin_id = $("#admin_id").val(); var admin_id = $("#admin_id").val();
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: '/_ajax/update_presence.php', url: '/_ajax/update_presence.php',
data: { checked : checked, user_id : user_id, tr_id : tr_id, admin_id : admin_id}, data: { checked : checked, user_id : user_id, tr_id : tr_id, admin_id : admin_id},
success: function(data) { success: function(data) {
} }
}); });
@@ -205,4 +205,4 @@ function hexc(colorval) {
} }
</script> </script>