<?php 
$path_to_root="../../..";
$page_security = 'SA_OPEN';
include_once($path_to_root . "/includes/db_pager.inc");
include($path_to_root . "/includes/session.inc");
include($path_to_root . "/includes/ui.inc");
include($path_to_root . "/modules/KvcodesCRM/includes/crm.inc");
page("Email Log");
simple_page_mode(true);

function status_($row){
	return ($row["status"] == 0 ? 'Not Send' : ($row['status'] == 1 ? 'Sent' : '' ));
}

function FA_date_Format($row){
	return sql2date(date('Y-m-d', strtotime($row['date_time']))) .date(' H i:s', strtotime($row['date_time']));
}

start_form();

$sql =GetDataJoin("email_log As log", 
						[array('join' => 'LEFT', 'table_name' => 'users AS usr', 'conditions' => 'usr.id = log.user_id')], 

						['log.name', 'log.email', 'log.slug', 'log.subject', 'log.status', 'log.date_time', 'usr.real_name'], null, null, ['log.id desc'], false, true);

$cols = array(
	_("To Name"),
	 //'fun' => 'user_name_'), 
	_("Email"), 
	_("Slug") => array('name'=>'slug'),
	_("Subject") => array('name'=>'subject'), 
	_("Status") => array('name'=>'status', 'fun' => 'status_'),
	_("Date") => array('name'=>'date_time', 'fun' => 'FA_date_Format'), 
	_("Sent by User") => array('name' => 'real_name'),
	// _("Date_time") => array(sql2date('date_time'))
	);

		$table =& new_db_pager('email_log', $sql, $cols);
		$table->width = "80%";
		display_db_pager($table);

end_form();
end_page();