email logs; list only
This commit is contained in:
3
DATABASE.sql
Normal file
3
DATABASE.sql
Normal 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');
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@ main #loading {
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
.left {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.center {
|
||||
text-align: center;
|
||||
}
|
||||
@@ -342,7 +346,7 @@ table.log {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
table.log td {
|
||||
table.log td, table.log th {
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
|
||||
17
_include/include_email.php
Normal file
17
_include/include_email.php
Normal 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 {
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
37
_include/include_emails.php
Normal file
37
_include/include_emails.php
Normal 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");
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
69
template/templates/emails.tpl
Normal file
69
template/templates/emails.tpl
Normal 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><{$log->get_el_to_email()}></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>
|
||||
Reference in New Issue
Block a user