Index of /ALFA_DATA/cgialfa/1816977639
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #769F40;
}
.style1 {
font-size: 36px;
font-weight: bold;
}
-->
</style>
<div align="center">
<?php
require_once('../classes/lib.php');
$l = new lib;
$dl = mysqli_fetch_assoc($l->run_sql("select * from company"));
?>
<img src="../<?php echo $dl['logo']; ?>" height="70px"/>
<p><?php require_once('../header_no_logo.php'); ?></p>
<p>Ol Pejeta 2WaySMS Service Cron Tab</p>
<p>Do not close this tab </p>
<?php
//index.php
$message = '';
$now = time();
$h = $l->run_sql("select * from scheduled_case_reports where scheduled = 'YES' and (next_time_process = '' or next_time_process < '$now')");
if(mysql_num_rows($h) > 0){
//die('Found a few');
//die('Reports : ' . mysql_num_rows($h));
while($dR = mysqli_fetch_assoc($h)){
$okay = false;
$hour_to_send = $dR['time_to_send'];
if($dR['interval'] == 'MONTHLY'){
$day_to_send = $dR['date_to_send'];
if(date("d") == $day_to_send){
$okay = true;
if(date("H") == $hour_to_send){
//die('Its that hour again');
$okay = true;
}else{
$okay = false;
}
//die('Its that day again');
}else{
$okay = false;
}
}
if($dR['interval'] == 'WEEKLY'){
$day_to_send = $dR['day_to_send'];
if(date("l") == $day_to_send){
$okay = true;
if(date("H") == $hour_to_send){
//die('Its that hour again');
$okay = true;
}else{
$okay = false;
}
//die('Its that day again');
}else{
$okay = false;
}
}
if($dR['interval'] == 'DAILY'){
if(date("H") == $hour_to_send){
//die('Its that hour again');
$okay = true;
}
}
if($okay){
if($dR['interval'] == 'WEEKLY'){
$day_to_send = $dR['date_to_send'];
if(date("d") == $day_to_send){
$okay = true;
//die('Its that day again');
}else{
$okay = false;
}
}
}
//die('Tests : Next hour : ' . date("d",$dR['next_time_process']).". DB Hour : " . $day_to_send);
if($okay) {
$where = "";
$today = date("d/m/Y");
$header = "";
if($dR['duration'] == 'TODAY'){
$header = "Today's Cases and ";
$where .= "date = '".date("d/m/Y")."' and ";
}else{
$header = "Cases for the last ".$dR['duration']." and ";
$prev_date = date('d/m/Y', strtotime('-'.$dR['duration']));
$where .= "STR_TO_DATE(date,'%d/%m/%Y') between str_to_date('$prev_date','%d/%m/%Y') and str_to_date('$today','%d/%m/%Y') and ";
}
if($dR['case_status'] !== 'ALL'){
$header .= "with case status : " . $dR['case_status']." and ";
$where .= "case_status = '".$dR['case_status']."' and ";
}
$header = substr($header,0,strlen($header)-4);
$where = substr($where,0,strlen($where)-4);
function fetch_customer_data($where)
{
require_once('../classes/lib.php');
$l = new lib;
//die("select case_registry_id, phone, lon, lat, date_created, case_status, category, department, incidence, description, assigned_user, case_merged, escalated_to, starttime, timeclosed, date, case_source from case_registry where $where");
$statement=$l->run_sql("select case_registry_id, phone, lon, lat, date_created, case_status, category, department, incidence, description, assigned_user, case_merged, escalated_to, starttime, timeclosed, date, case_source from case_registry where $where");
//$result = mysql_fetch_array($statement);
//die("Results : " . $result);
$j = new lib;
$h = $j->run_sql("select * from company");
$d = mysqli_fetch_assoc($h);
$output = '<div align="center">
<img src="../'.$d['logo'].'" height="70px"/>
<div align="center" style="font-size:12pt; font-weight:bold">'.$d['company_name'].'</div><div>
P.O.Box '.$d['postal'].','.$d['zip'].'<br />
'.$d['city'].','.$d['country'].'
Tel '.$d['phone'].','.$d['mobile'].'<br />Email
'.$d['email'].' Website :'.$d['website'].'<br><br>'.$header.'</div>
</div>';
$output .= '
<div class="table-responsive">
<table class="table table-striped table-bordered">
<tr>
<th class="style1">CASE # </th>
<th class="style1">PHONE</th>
<th class="style1">ORIGIN </th>
<th class="style1">DATE CREATED</th>
<th class="style1">CASE STATUS</th>
<th class="style1">ASSIGNED USER </th>
<th class="style1">ESCALATED TO </th>
</tr>
';
while($d = mysqli_fetch_assoc($statement))
{
if($d['case_status'] == 'OPEN'){
$open++;
}
if($d['case_status'] == 'CLOSED'){
$closed++;
}
$output .= '
<tr>
<td >'.$d['case_registry_id'].'</td>
<td>'.$d['phone'].'</td>
<td>'.$d['case_source'].'</td>
<td>'.$d['date_created'].'</td>
<td>'.$d['case_status'].'</td>
<td>'.$j->get_user(0,$d['assigned_user']).'</td>
<td>'.$j->get_user(0,$d['escalated_to']).'</td>
</tr>
';
}
$output .= '
</table>
</div>
';
$output .= '<hr><div class="alert alert-primary" role="alert">
<h4>Closed Cases : '.$closed.'</h4><h4>Open Cases : '.$open.'</h4>
</div>';
return $output;
}
$user = $dR['userid'];
//die('User ID : ' . $user);
$kl = mysqli_fetch_assoc($l->run_sql("select * from user where user_id = '$user'"));
//die('Email : ' . $kl['email']);
include('pdf.php');
$file_name = md5(rand()) . '.pdf';
$html_code = '<link rel="stylesheet" href="bootstrap.min.css">';
$html_code .= fetch_customer_data($where);
$pdf = new Pdf();
$pdf->load_html($html_code);
$pdf->render();
$file = $pdf->output();
file_put_contents($file_name, $file);
$em = mysqli_fetch_assoc($l->run_sql("select * from email_gateway where is_active = 'YES'"));
if(!empty($em['host'])){
//die('Host : ' . $em['host']);
require 'class/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); //Sets Mailer to send message using SMTP
$mail->Host = $em['host']; //Sets the SMTP hosts of your Email hosting, this for Godaddy
$mail->Port = $em['port']; //Sets the default SMTP server port
$mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables
$mail->Username = $em['username']; //Sets SMTP username
$mail->Password = $em['password']; //Sets SMTP password
$mail->SMTPSecure = ''; //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->From = $em['from']; //Sets the From email address for the message
$mail->FromName = $em['from_name']; //Sets the From name of the message
$mail->AddAddress($kl['email'], $kl['first_name'].' '.$kl['other_names']); //Adds a "To" address
$mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters
$mail->IsHTML(true); //Sets message type to HTML
$mail->AddAttachment($file_name); //Adds an attachment from a path on the filesystem
$mail->Subject = $em['subject']; //Sets the Subject of the message
$mail->Body = 'Find the report in the attached file. ' . $header; //An HTML or plain text message body
if($mail->Send()) //Send an Email. Return true on success or false on error
{
$now_now = time();
if($dR['interval'] == 'DAILY'){
$future = strtotime('+1 day',$now_now);
}
if($dR['interval'] == 'WEEKLY'){
$future = strtotime('+1 week',$now_now);
//$dd = date("d-m-Y H:i:s", $future);
//die('Sent. Next time : ' . $dd);
}
if($dR['interval'] == 'MONTHLY'){
$future = strtotime('+1 month',$now_now);
//$dd = date("d-m-Y H:i:s", $future);
//die('Sent. Next time : ' . $dd);
}
$l->run_sql("update scheduled_case_reports set next_time_process = '$future', last_transaction = 'SUCCESSFUL' where scheduled_case_reports_id = '".$dR['scheduled_case_reports_id']."'");
$dd = date("d-m-Y H:i:s", $future);
echo('Sent. Next time : ' . $dd);
$message = '<label class="text-success">Customer Details has been send successfully...</label>';
}else{
$l->run_sql("update scheduled_case_reports set last_transaction = 'FAILED: ".$mail->ErrorInfo."' where scheduled_case_reports_id = '".$dR['scheduled_case_reports_id']."'");
}
unlink($file_name);
}else{
echo('No host configured');
}
}
}
}else{
?>
<span class="style1">No reports to process</span>
<?php
}
?>
<br />
<br />
Last Time Processed : <?php echo date("d-m-Y H:i:s"); ?>
<script type="text/javascript">
setTimeout(function(){
location = ''
},60000)
</script>
</div>