email logs; list only

This commit is contained in:
Ricsi
2018-10-23 15:32:08 +02:00
parent 19aaa4a770
commit 85180a91b6
11 changed files with 635 additions and 456 deletions

3
DATABASE.sql Normal file
View File

@@ -0,0 +1,3 @@
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

@@ -4,23 +4,45 @@ class email_log {
private $el_id;
private $el_message;
private $el_subject;
private $el_from_name;
private $el_from_email;
private $el_to_name;
private $el_to_email;
private $el_sent_date;
private $el_exception;
private $el_email_template_et_id;
public function set_et_data_by_id($_id) {
public function set_el_data_by_id($_id) {
global $sql;
$et_data_assoc_array = $sql->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) {
$el_data_assoc_array = $sql->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
@@ -85,19 +107,19 @@ class email_log {
/**
* @return mixed
*/
public function get_el_from_name()
public function get_el_to_name()
{
return $this->el_from_name;
return $this->el_to_name;
}
/**
* @param mixed $el_from_name
* @param mixed $el_to_name
*
* @return self
*/
public function set_el_from_name($el_from_name)
public function set_el_to_name($el_to_name)
{
$this->el_from_name = $el_from_name;
$this->el_to_name = $el_to_name;
return $this;
}
@@ -105,19 +127,19 @@ class email_log {
/**
* @return mixed
*/
public function get_el_from_email()
public function get_el_to_email()
{
return $this->el_from_email;
return $this->el_to_email;
}
/**
* @param mixed $el_from_email
* @param mixed $el_to_email
*
* @return self
*/
public function set_el_from_email($el_from_email)
public function set_el_to_email($el_to_email)
{
$this->el_from_email = $el_from_email;
$this->el_to_email = $el_to_email;
return $this;
}

View File

@@ -184,7 +184,7 @@ class email_template {
{
$matches = null;
preg_match_all('/{\$([a-z0-9\_]+)}/', $_raw, $matches);
print_r($matches);
//print_r($matches);
//[0] {$variable}
//[1] variable

View File

@@ -247,6 +247,14 @@ class page {
# smtp teszt
include('include_smtp_test.php');
break;
case 'emails':
# email log
include('include_emails.php');
break;
case 'email':
# email log details
include('include_email.php');
break;
case 'delete_training_type':
# EDZÉS TÍPUS TÖRLÉS
include('include_delete_training_type.php');

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
<?php
if ($this->is_id()) {
# EMAIL LOG RÉSZLETEK
$email_log = new email_log();
$email_log->set_el_data_by_id($this->get_id());
$smarty->assign('email_log', $email_log);
$smarty->display('email.tpl');
}
else {
}
?>

View File

@@ -0,0 +1,37 @@
<?php
if ($this->is_id()) {
# EMAIL LISTA (50 / oldal)
$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";
$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");
}
?>

View File

@@ -67,6 +67,7 @@ if ($this->is_id()) {
$raw_subject = $emailTemplate->get_et_subject();
$raw_message = $emailTemplate->get_et_message();
//var_dump($kid_array);
foreach ($kid_array as $kid) {
$personalizedSubject = $emailTemplate->personalize($raw_subject, array(
'uk_name' => $kid->get_uk_name(),
@@ -94,7 +95,7 @@ if ($this->is_id()) {
//Recipients
$mail->setFrom($emailTemplate->get_et_from_email(), $emailTemplate->get_et_from_name());
$mail->addBCC('tricsusz@gmail.com', 'Tóth Richárd'); // TEST
$mail->addBCC($kid->get_uk_notify_email(), $kid->get_uk_notify_name());
//$mail->addBCC($kid->get_uk_notify_email(), $kid->get_uk_notify_name());
//Content
@@ -105,8 +106,26 @@ if ($this->is_id()) {
//$mail->send();
//LOG SUCCESS
email_log::create_email_log(
$personalizedMessage,
$personalizedSubject,
$kid->get_uk_notify_name(),
$kid->get_uk_notify_email(),
$emailTemplate->get_et_id()
);
//TODO: Update kids last noti date
} catch (Exception $e) {
//LOG ERROR
email_log::create_email_log(
$personalizedMessage,
$personalizedSubject,
$kid->get_uk_notify_name(),
$kid->get_uk_notify_email(),
$emailTemplate->get_et_id(),
$e
);
}
}

View File

@@ -17,69 +17,69 @@ $fold = true;
//ha nem a gyerek belépéseit kérjük le ÉS létezik postolt logcategory és (nem létezik a cookie VAGY létezik de nem egyenlő az eddigivel)
$selected = "";
if (!isset($_REQUEST['login_kid']) && isset($_REQUEST['log_category']) && (!isset($_COOKIE['log_category']) || (isset($_COOKIE['log_category']) && $_COOKIE['log_category'] != $_REQUEST['log_category']))) {
if ($_REQUEST['log_category'] != 'null') $condition = "WHERE log_log_category_logc_id = " . $_REQUEST['log_category'];
//beállítjuk a cookie-t, rövid élettartammal
setcookie("log_category", $_REQUEST['log_category'], time()+60*60, '/');
$selected = $_REQUEST['log_category'];
$update = true;
if ($_REQUEST['log_category'] != 'null') $condition = "WHERE log_log_category_logc_id = " . $_REQUEST['log_category'];
//beállítjuk a cookie-t, rövid élettartammal
setcookie("log_category", $_REQUEST['log_category'], time()+60*60, '/');
$selected = $_REQUEST['log_category'];
$update = true;
}
elseif (isset($_REQUEST['login_kid'])) {
//lekérjük a gyerek befizetéseit + hideoljuk a lapozót
$condition = "WHERE log_log_category_logc_id = 3 and log_user_id = " . $_REQUEST['login_kid'];
$fold = false;
//lekérjük a gyerek befizetéseit + hideoljuk a lapozót
$condition = "WHERE log_log_category_logc_id = 3 and log_user_id = " . $_REQUEST['login_kid'];
$fold = false;
}
//COOKIE HANDLER - igazából ide kell a condition leírása
if (isset($_COOKIE['log_category']) && $_COOKIE['log_category'] != 'null' && !$update && !isset($_REQUEST['login_kid'])) {
$condition = "WHERE log_log_category_logc_id = " . $_COOKIE['log_category'];
$selected = $_COOKIE['log_category'];
$condition = "WHERE log_log_category_logc_id = " . $_COOKIE['log_category'];
$selected = $_COOKIE['log_category'];
}
foreach ($logc_assoc_array as $logc_array) {
$new_logc = new log_category();
$new_logc->set_logc_data_by_id($logc_array['logc_id']);
$log_categories[] = $new_logc;
$new_logc = new log_category();
$new_logc->set_logc_data_by_id($logc_array['logc_id']);
$log_categories[] = $new_logc;
}
if ($this->is_id()) {
# LOG LIST FILTERED
//50esével megyünk
$from = ($this->get_id() - 1) * 50;
$log_query = "SELECT * FROM log " . (isset($condition)?$condition:"") . " ORDER BY log_date DESC " . ($fold?"LIMIT ".$from.",50;":"");
$log_count = $sql->num_of_rows("SELECT * FROM log ".(isset($condition)?$condition:"")." ORDER BY log_date DESC;");
//echo $log_count;
if ($log_count <= $this->get_id()*50) {
$next_link = false;
}
$smarty->assign('next_id', ($next_link?$this->get_id()+1:false));
$smarty->assign('previous_id', ($this->get_id()>1?$this->get_id()-1:false));
# LOG LIST FILTERED
//50esével megyünk
$from = ($this->get_id() - 1) * 50;
$log_query = "SELECT * FROM log " . (isset($condition)?$condition:"") . " ORDER BY log_date DESC " . ($fold?"LIMIT ".$from.",50;":"");
$log_count = $sql->num_of_rows("SELECT * FROM log ".(isset($condition)?$condition:"")." ORDER BY log_date DESC;");
//echo $log_count;
if ($log_count <= $this->get_id()*50) {
$next_link = false;
}
$smarty->assign('next_id', ($next_link?$this->get_id()+1:false));
$smarty->assign('previous_id', ($this->get_id()>1?$this->get_id()-1:false));
$log_assoc_array = $sql->assoc_array($log_query);
$log_array = array();
foreach ($log_assoc_array as $log_list_array) {
$current_log = new log();
$current_log->set_log_data_by_id($log_list_array['log_id']);
$log_array[] = $current_log;
}
$log_assoc_array = $sql->assoc_array($log_query);
$log_array = array();
foreach ($log_assoc_array as $log_list_array) {
$current_log = new log();
$current_log->set_log_data_by_id($log_list_array['log_id']);
$log_array[] = $current_log;
}
$smarty->assign('selected', $selected);
$smarty->assign('fold', $fold);
$smarty->assign('logc_array', $log_categories);
$smarty->assign('log_array', $log_array);
$smarty->display('log.tpl');
$smarty->assign('selected', $selected);
$smarty->assign('fold', $fold);
$smarty->assign('logc_array', $log_categories);
$smarty->assign('log_array', $log_array);
$smarty->display('log.tpl');
}
else {
# LOG LIST
header("Location: /admin/log/1");
/*
$log_query = "SELECT * FROM log ORDER BY log_date DESC LIMIT 50;";
$previous_link = false;
$smarty->assign('next_id', '2');
*/
# LOG LIST
header("Location: /admin/log/1");
/*
$log_query = "SELECT * FROM log ORDER BY log_date DESC LIMIT 50;";
$previous_link = false;
$smarty->assign('next_id', '2');
*/
}
?>
?>

View File

@@ -0,0 +1,69 @@
{if $fold}
<div class="navigator">
<div class="previous">
{if $previous_id}
<a href="/admin/emails/{$previous_id}">
{/if}
<img src="/_image/previous.png" {if !$previous_id}class="grayscale"{/if}>
{if $previous_id}
</a>
{/if}
</div>
<div class="next">
{if $next_id}
<a href="/admin/emails/{$next_id}">
{/if}
<img src="/_image/previous.png" {if !$next_id}class="grayscale"{/if}>
{if $next_id}
</a>
{/if}
</div>
</div>
{/if}
<div style="overflow-x:auto;">
<table class="log">
<tr>
<th class="left">#ID</th>
<th class="left">Címzett</th>
<th class="left">Kiküldés dátuma</th>
<th class="left">Tárgy</th>
<th class="left">Üzenet</th>
<th class="left">Hibaüzenet</th>
</tr>
{foreach $el_array as $log}
<tr class="email-log{if $log->get_el_exception()} delete{else} tick{/if}">
<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_sent_date()}</td>
<td>{$log->get_el_subject()}</td>
<td>{$log->get_el_message()|truncate:50}</td>
<td>{$log->get_el_exception()|truncate:50}</td>
</tr>
{/foreach}
</table>
</div>
<div class="navigator">
<div class="previous">
{if $previous_id}
<a href="/admin/emails/{$previous_id}">
{/if}
<img src="/_image/previous.png" {if !$previous_id}class="grayscale"{/if}>
{if $previous_id}
</a>
{/if}
</div>
<div class="next">
{if $next_id}
<a href="/admin/emails/{$next_id}">
{/if}
<img src="/_image/previous.png" {if !$next_id}class="grayscale"{/if}>
{if $next_id}
</a>
{/if}
</div>
</div>