Locale Get Ignored When Sending Mail with Queue - php

I'm looking for an answer. Laravel Framework 5.5.44
and I have a queue that will send an email whenever someone place new order on my website. I used event and listener to accomplish this. My queue successfully sent the email but my locale code does not working. Below is my code :
NewOrderListener.php
public function handle($event)
{
try {
dump('new order registered (listernerrr)');
// dump($event->order);
$email = $event->order['email'];
// $logo_settings_details = Settings::get_logo_settings_details();
// // dump($logo_settings_details);
// $event->order->prepend('logo_settings_details', DB::table('gr_logo_settings')->get());
// array_push($event->order, DB::table('gr_logo_settings')->get());
$event->order['logo_settings_details'] = DB::table('gr_logo_settings')->get();
// $data = [
// 'logo_settings_details' => DB::table('gr_logo_settings')->get(),
// ];
// dd($data);
$get_images = DB::table('gr_no_images')->select('banner_image','restaurant_store_image','restaurant_item_image','product_image','logo_image','landing_image','shop_logo_image','category_image')->first();
if(empty($get_images) === false)
{
$no_item = $get_images->restaurant_item_image;
$event->order['no_item'] = $no_item;
}
$this->general_setting = DB::table('gr_general_setting')->get();
if(count($this->general_setting) > 0){
foreach($this->general_setting as $s){
$event->order['FOOTERNAME'] = $s->footer_text;
}
}
else {
$event->order['FOOTERNAME'] = 'ePickMeUp';
}
// dd($event->order);
Mail::send('email.order_mail_customer', $event->order, function($message) use($email)
{
dump($email);
// $sub_data = (Lang::has(Session::get('front_lang_file').'.FRONT_ORDER_SUCCSESS')) ? trans(Session::get('front_lang_file').'.FRONT_ORDER_SUCCSESS') : trans($this->FRONT_LANGUAGE.'.FRONT_ORDER_SUCCSESS');
// dump($sub_data);
$message->to('googleadmin#gmail.com')->subject('SUCCESSFUL ORDER 😍');
dump('email sent');
});
} catch (\Exception $e) {
// Log Error
// Log::error($e->getMessage());
// Sent Error To Slack
// Dump Error
dump($e->getMessage());
}
}
order_mail_customer.blade.php
<td style="border-top: 5px solid #f7d501;">
<table style="padding:10px;width:100%;">
<tr>
<td align="center">
#php $path = url('').'/public/images/noimage/default_image_logo.jpg'; #endphp
#if(count($logo_settings_details) > 0)
#php
foreach($logo_settings_details as $logo_set_val){ }
#endphp
#if($logo_set_val->admin_logo != '')
#php $filename = public_path('images/logo/').$logo_set_val->admin_logo; #endphp
#if(file_exists($filename))
#php $path = url('').'/public/images/logo/'.$logo_set_val->admin_logo; #endphp
#endif
#endif
#endif
<img src="{{$path}}" alt="#lang(Session::get('front_lang_file').'.ADMIN_LOGO')" class="img-responsive logo" width="100">
</td>
</tr>
</table>
</td>
</tr>
#if($self_pickup==1)
<tr>
<td>
<table style="width:100%;background:url('{{url('public/images/order_image.jpg')}}')no-repeat; padding:56px 20px;">
<tr>
<td colspan="1" style="text-align:center; font-family:cursive; font-size:35px; padding-bottom: 20px; color: #fff;">
#lang(Session::get('front_lang_file').'.FRONT_THANK_ORDER')
</td>
</tr>
<tr>
<td style="text-align:center; font-family:sans-serif; font-size:17px; padding-bottom: 20px; color: #fff; line-height: 25px;">
#lang(Session::get('front_lang_file').'.API_ORDER_PLACED')
</td>
</tr>
<tr>
<td style="text-align:center; font-family:sans-serif; font-size:17px; padding-bottom: 20px; color: #fff; line-height: 25px;">
#lang(Session::get('front_lang_file').'.ADMIN_TRANSACTION_ID') : {{$transaction_id}}
</td>
</tr>
</table>
</td>
</tr>
Why all those #lang(Session::get('front_lang_file') not getting called on queue? Hopefully, someone could help me to solve this problem. Thanks in advance.

Because Queue Job run in process which is diffirent from session process, so, you can't access session ( locale in this case ) . You need pass session as argument for constructor of Job. smth like :
NewOrderListener::dispatch(Event $event, Session $session)

Related

Email Blade Got Undefined variable: when using Laravel queue

I tried to queue successful email whenever someone place new order on my website. I used event and listener to accomplish this. Below is my code for sending the email on listener file:
NewOrderListener.php
public function handle($event)
{
try {
dump('new order registered (listernerrr)');
$email = $event->order['email'];
Mail::send('email.order_mail_customer', $event->order, function($message) use($email)
{
dump($email);
$sub_data = (Lang::has(Session::get('front_lang_file').'.FRONT_ORDER_SUCCSESS')) ? trans(Session::get('front_lang_file').'.FRONT_ORDER_SUCCSESS') : trans($this->FRONT_LANGUAGE.'.FRONT_ORDER_SUCCSESS');
dump($sub_data);
$message->to('googleadmin#gmail.com')->subject($sub_data);
dump('email sent');
});
} catch (\Exception $e) {
dump($e->getMessage());
}
}
email.order_mail_customer.blade.php file :
<html>
<body style="margin: 0; padding: 0;">
#if(count($order_details) > 0)
<table cellpadding="0" cellspacing="0" width="600" align="center" style="border:1px solid #ddd;">
<tr>
<td style="border-top: 5px solid #f7d501;">
<table style="padding:10px;width:100%;">
<tr>
<td align="center">
#php $path = url('').'/public/images/noimage/default_image_logo.jpg'; #endphp
#if(count($logo_settings_details) > 0)
#php
foreach($logo_settings_details as $logo_set_val){ }
#endphp
#if($logo_set_val->admin_logo != '')
#php $filename = public_path('images/logo/').$logo_set_val->admin_logo; #endphp
#if(file_exists($filename))
#php $path = url('').'/public/images/logo/'.$logo_set_val->admin_logo; #endphp
#endif
#endif
#endif
<img src="{{$path}}" alt="#lang(Session::get('front_lang_file').'.ADMIN_LOGO')" class="img-responsive logo" width="100">
</td>
</tr>
</table>
</td>
</tr>
Exception message:
Undefined variable: logo_settings_details in email.order_mail_customer.blade.php
Above code running OK when I set queue driver=sync and without queue.
But I got undefined property/variable on order_mail_customer.blade.php when I'm using queue by setting up driver=database and implements ShouldQueue to NewOrderListener file. Hopefully someone could help me to solve this problem. Thanks in advance.
Nevermind, I've found the issue, this variable couldn't be call because of this variable is static variable, it get destroy before the queue got running.

Php Error Message " Uncaught exception 'Exception' with message 'Query Failed:Array"

I tried to render a table from MS-SQL Database to Webpage and i get this error.
I'm still new in PHP. Please help
Useraccess.php
<?php
$path = dirname(__FILE__);
require_once(dirname(__FILE__)."/simpleusers/config.inc.php");
$SimpleUsers = new SimpleUsers();
$users = $SimpleUsers->getUsers();
class SimpleUsers
{
private $mysqli , $stmt;
private $conn;
private $sessionName = "SimpleUsers";
public $logged_in = false;
public $userdata;
public $uPassword;
public $salt;
public function getUsers()
{
$sql = "SELECT DISTINCT userId, uUsername, uActivity, uCreated FROM users ORDER BY uUsername ASC";
$stmt = sqlsrv_query($this->conn, $sql);
if( $stmt == false){
throw new Exception("Query Failed:".sqlsrv_errors());
}
$stmt->execute();
$stmt->store_result();
if( $stmt->num_rows == 0){
return array();
}
$users = array();
$i = 0;
while( $stmt->fetch() )
{
$users[$i]["userId"] = $userId;
$users[$i]["uUsername"] = $username;
$users[$i]["uActivity"] = $activity;
$users[$i]["uCreated"] = $created;
$i++;
}
}
}
?>
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<style type="text/css">
* { margin: 0px; padding: 0px; }
body
{
padding: 30px;
font-family: Calibri, Verdana, "Sans Serif";
font-size: 12px;
}
table
{
width: 800px;
margin: 0px auto;
}
th, td
{
padding: 3px;
}
.right
{
text-align: right;
}
h1
{
color: #FF0000;
border-bottom: 2px solid #000000;
margin-bottom: 15px;
}
p { margin: 10px 0px; }
p.faded { color: #A0A0A0; }
</style>
</head>
<body>
<h1>User administration</h1>
<table cellpadding="0" cellspacing="0" border="1">
<thead>
<tr>
<th>Username</th>
<th>Last activity</th>
<th>Created</th>
<th></th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4" class="right">
Create new user | Logout
</td>
</tr>
</tfoot>
<tbody>
<?php foreach
( $users as $user ): ?>
<tr>
<td><?php echo $user["uUsername"]; ?></td>
<td class="right"><?php echo $user["uActivity"]; ?></td>
<td class="right"><?php echo $user["uCreated"]; ?></td>
<td class="right">Delete | User info | Change password</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
config.inc.php
<?php
$GLOBALS["serverName"] = "DESKTOP-KRF6KT7\SQLEXPRESS";
$GLOBALS["database"] = "SimpleUsers";
$GLOBALS["uid"] = "sa";
$GLOBALS["pwd"] = "twinz0000";
$GLOBALS["connectionInfo"] = array(
"Database"=>$GLOBALS["database"],
"UID"=>$GLOBALS["uid"],
"PWD"=>$GLOBALS["pwd"])
?>
Error Displayed
Warning: sqlsrv_query() expects parameter 1 to be resource, null given in C:\Users\Adam\Desktop\SimpleUsers MSSQL\Useraccess.php on line 26
Notice: Array to string conversion in C:\Users\Adam\Desktop\SimpleUsers MSSQL\Useraccess.php on line 29
Fatal error: Uncaught exception 'Exception' with message 'Query Failed:Array' in C:\Users\Adam\Desktop\SimpleUsers MSSQL\Useraccess.php:29 Stack trace: #0 C:\Users\Adam\Desktop\SimpleUsers MSSQL\Useraccess.php(8): SimpleUsers->getUsers() #1 {main} thrown in C:\Users\Adam\Desktop\SimpleUsers MSSQL\Useraccess.php on line 29
Your conn class property is not set.
Before you call $stmt = sqlsrv_query($this->conn, $sql); you must set it up in sqlsrv_connect.
Try adding construct:
public function __construct()
{
$this->conn = sqlsrv_connect($GLOBALS["serverName"], $GLOBALS["connectionInfo"]);
}
Useraccess.php
<?php
$path = dirname(__FILE__);
require_once(dirname(__FILE__)."/simpleusers/config.inc.php");
$SimpleUsers = new SimpleUsers();
$users = $SimpleUsers->getUsers();
class SimpleUsers
{
private $mysqli , $stmt;
private $conn;
private $sessionName = "SimpleUsers";
public $logged_in = false;
public $userdata;
public $uPassword;
public $salt;
public $conn=$GLOBALS["conn"] ;
public function getUsers()
{
$sql = "SELECT DISTINCT userId, uUsername, uActivity, uCreated FROM users ORDER BY uUsername ASC";
$stmt = sqlsrv_query($this->conn, $sql);
if( $stmt == false){
throw new Exception("Query Failed:".sqlsrv_errors());
}
$stmt->execute();
$stmt->store_result();
if( $stmt->num_rows == 0){
return array();
}
$users = array();
$i = 0;
while( $stmt->fetch() )
{
$users[$i]["userId"] = $userId;
$users[$i]["uUsername"] = $username;
$users[$i]["uActivity"] = $activity;
$users[$i]["uCreated"] = $created;
$i++;
}
}
}
?>
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<style type="text/css">
* { margin: 0px; padding: 0px; }
body
{
padding: 30px;
font-family: Calibri, Verdana, "Sans Serif";
font-size: 12px;
}
table
{
width: 800px;
margin: 0px auto;
}
th, td
{
padding: 3px;
}
.right
{
text-align: right;
}
h1
{
color: #FF0000;
border-bottom: 2px solid #000000;
margin-bottom: 15px;
}
p { margin: 10px 0px; }
p.faded { color: #A0A0A0; }
</style>
</head>
<body>
<h1>User administration</h1>
<table cellpadding="0" cellspacing="0" border="1">
<thead>
<tr>
<th>Username</th>
<th>Last activity</th>
<th>Created</th>
<th></th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4" class="right">
Create new user | Logout
</td>
</tr>
</tfoot>
<tbody>
<?php foreach
( $users as $user ): ?>
<tr>
<td><?php echo $user["uUsername"]; ?></td>
<td class="right"><?php echo $user["uActivity"]; ?></td>
<td class="right"><?php echo $user["uCreated"]; ?></td>
<td class="right">Delete | User info | Change password</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
config.inc.php
<?php
$GLOBALS["serverName"] = "DESKTOP-KRF6KT7\SQLEXPRESS";
$GLOBALS["database"] = "SimpleUsers";
$GLOBALS["uid"] = "sa";
$GLOBALS["pwd"] = "twinz0000";
$GLOBALS["connectionInfo"] = array(
"Database"=>$GLOBALS["database"],
"UID"=>$GLOBALS["uid"],
"PWD"=>$GLOBALS["pwd"]);
$GLOBALS["conn"] = sqlsrv_connect($GLOBALS["serverName"], $GLOBALS["connectionInfo"] );
?>
Hope it will help.
I have these two items in my php.ini file enabled:
extension=php_pdo_sqlsrv_53_ts.dll
extension=php_sqlsrv_53_ts.dll
Which is what I had before. Using Wamp Server. PHP 5.3.13 all the same as before. What else am I missing that is not allowing this to connect to the SQL server.
After connection file code.
<?php
$GLOBALS["serverName"] = "localhost";
$GLOBALS["database"] = "SimpleUsers";
$GLOBALS["uid"] = "root";
$GLOBALS["pwd"] = "";
$GLOBALS["connectionInfo"] = array(
"Database"=>$GLOBALS["database"],
"UID"=>$GLOBALS["uid"],
"PWD"=>$GLOBALS["pwd"]);
$conn = sqlsrv_connect($GLOBALS["serverName"], $GLOBALS["connectionInfo"]);
?>

In MVC, the update action doesn't work and stores the values

I took over a job from a friend. Now I am working on a MVC, I have made a Form that looks like his:
<form method="post" action="QA/public/index.php?controller=QA&action=shabUpdate">
<table class="clean">
{data}
<tr style="display:{display};">
<td class="label">Specific:</td>
<td>{remarks}</td>
</tr>
</table>
{back}
<input type="submit" />
</form>
In my controller I made the following shabUpdateAction:
protected function shabUpdateAction()
{
$_POST['titel'] = $_POST['titel'];
/*$_POST['inspectie'] = 'so sorry';
$_POST['extraDocument'] = 'newIMG';*/
$this->dbh->setShab($_POST, $_POST['partId']);
$_SESSION['page'] = './QA/public/index';
$_SESSION['getIndex'] = '?controller=QA&action=showInspectionDocument&templateId='.$_POST['templateId'];
header('Location: http://stuffff/something/');
exit();
}
this is suppose to update my form and when I visit the form page I should be able to see the new information (new changes that was made).
However the update action doesn't work and it doesn't redirect to a correct page.
this is the part from my Model:
public function updateSshab($sdr)
{
$sql = "UPDATE `qa_template`
SET `inspection_requirement` = :requirement
WHERE `part_id` = :partId AND `title` = :title;";
$statement = $this->dbh->prepare($sql);
$statement->bindParam(':requirement', $sdr['defectDescription']);
$statement->bindParam(':partId', $sdr['partId']);
$statement->bindValue(':title', 'SDR nummer: SDR' .$sdr['nr']);
$statement->execute();
}
and finally my view:
public function renderShowInspectionDocument()
{
setLastPage();
$dochtml = '';
$url = str_replace(end(explode('/', $_SERVER['HTTP_REFERER'])), '', $_SERVER['HTTP_REFERER']);
//Template
$template = file_get_contents('templates/inspectionDetails.tpl');
//shab
if(isset($this->data['shab']))
{
$shab= $this->data['shab'];
$dochtml .= '
<tr>
<td class="label">Inspection:</td>
<td>
<input type="hidden" name="templateId" value="'.$shab['id'].'" />
<div id="testDiv" style="width:420px; font-weight:normal; border-left:1px solid black; border-bottom:1px solid black; padding:5px;">'. nl2br($shab['inspection_requirement']) .'</div>
<div id="testDiv2" style="display=none">
<textarea name="inspection" class="width">'. nl2br($shab['inspection_requirement']) .'</textarea>
</div>
</td>
</tr>
<tr>
<td class="label">Inspection-tools:</td>
<td>
<input type="hidden" name="templateId" value="'.$shab['id'].'" />
<div id="testDiv22" style="width:420px; font-weight:normal; border-left:1px solid black; border-bottom:1px solid black; padding:5px;">'. nl2br($shab['inspection_resources']) .'</div>
<div id="testDiv222" style="display=none">
<textarea name="InspectieResources" class="width">'. nl2br($shab['inspection_resources']) .'</textarea>
</div>
</td>
</tr>
';
}
$template = str_replace('{data}', $dochtml, $template);
$template = str_replace('{terug}', backButtonQA(), $template);
$template = str_replace('{display}', 'none', $template);
echo $template;
}
my update function doesn't work correctly. I didn't write nu I am working on it and I cant seem to figure out the problem with update Action, is there something I am missing??

Use tr:nth-child(odd) and tr:nth-child(even) selectors only on nested top tables

I want a zebra striped table.
The data is extracted from the database and every instance creates a new table.
I want the zebra-striped on the <table> level. this would mean that every other <table> element gets a different color.
I tried to add a class to my <table class="oddeven"> but this still does the changing on every tr.
Here is the code I use it on:
<?php
global $wpdb;
$sql = "SELECT * FROM $wpdb->postmeta WHERE meta_key = 'group' AND meta_value='$group'";
$results = $wpdb->get_results($sql) or die(mysql_error());
echo'<table cellpadding="0" cellspacing="0" border="0" width="100%">';
foreach( $results as $result )
{
$post_id = $result->post_id;
$company_name = get_post_meta($post_id, 'company_name', true);
$address = get_post_meta($post_id, 'address', true);
$postal_code = get_post_meta($post_id, 'postal_code', true);
$city = get_post_meta($post_id, 'city', true);
$phone = get_post_meta($post_id, 'phone', true);
echo '
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="oddeven">
<tr>
<td width="75%">
<strong>'.$company_name.'</strong>
</td>
<td rowspan="4"><img class="table_image" src="'.get_bloginfo('template_directory').'/images/arrow.png"></td>
</tr>
<tr>
<td>
'.$address.'
</td>
</tr>
<tr>
<td>
'.$postal_code.' '.$city.'
</td>
</tr>
<tr>
<td>
'.$phone.'
</td>
</tr>
</table>
</td>
</tr>';
}
echo '</table>';
?>
This is the styling:
(while typing this I realise that this is on tr:level)
.oddeven tr:nth-child(odd){
background: #ffffff;
}
.oddeven tr:nth-child(even){
background: #000000;
}
I hope I make myself clear
If you change your foreach loop to a for loop like this:
for($i = 0; $i < count($results); $i++) {
$result = $results[$i];
...
Then you can figure out if the current row is even or odd by testing if $i % 2 == 0. If that evaluates to true, then add an 'even' class; else add an 'odd' class.
If you do not want to propagate the change to child tables, you can also enforce the same color on the children :
.top tr:nth-child(odd) {
background-color: red;
}
.top tr:nth-child(odd) tr {
background-color: red;
}
.top tr:nth-child(even) {
background-color: yellow;
}
.top tr:nth-child(even) tr {
background-color: yellow;
}
I assume that's what your want since you already have stripped rows on your nested tables
Or maybe I got it wrong, you might have to explain what the <table> level is, since your have nested tables.

List files in folder sub-directory

I have a script that when clients create a pdf file, it is placed in a folder named with there own code. This is in a main folder called 'destcerts' and the folder structure ends up looking like the illustration below. What I need to do as admin is have access to these files and the only way I can do that at the moment is to hard code the sub-directory in the code and that is not practical for obvious reasons.
What I thought I could do is, have a select dropdown with a list of clients which when selected could trigger perhaps a change event which would say loop for the chosen client and display the files. Unfortunately, my php or jquery is not good enough to achieve this and I would be grateful if someone could show me the way to go forward with this. Many thanks
php code
<div id="viewCerts" style="display:none;">
<?php
$sub = 'destcerts/';
// READ THE NAMES OF FILES IN THE SUB-DIRECTORY
$fff = new DirectoryIterator($sub);
$sss = array();
foreach ($fff as $filedata)
{
// SKIP THE "DOT" FILES
if ($filedata->isDot()) continue;
// ACTIVATE THIS LINE TO RESTRICT IT TO PDF FILES ONLY
if ($filedata->getExtension() != 'pdf') continue;
// CREATE LINKS TO THESE FILES
$nom = $filedata->getFilename();
$lnk
= '<img src="destcerts/PDF_icon_100.png" style="margin-bottom: 15px; margin-top:15px;"><br /><a href="'
. $sub
. '/'
. $nom
. '" style="color:#0099FF; text-decoration:none; font-size:12px; font-family: Verdana, Geneva, sans-serif;">'
. $nom
. '</a>'
;
// COLLECT THE LINKS HERE
$sss[] = $lnk;
}
// ACCUMULATE THE TABLE ROWS HERE
$trs = NULL;
// COLLECT GROUPS OF FOUR
If(!empty($sss)){
while (!empty($sss))
{
$td1 = array_shift($sss) or NULL;
$td2 = array_shift($sss) or NULL;
$td3 = array_shift($sss) or NULL;
$td4 = array_shift($sss) or NULL;
// USE HEREDOC TO INSERT THESE INTO A TABLE ROW
$tr = <<<EOD
<tr>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td1</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td2</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td3</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td4</td>
</tr>
EOD;
// APPEND THE TABLE ROW TO THE OTHER ROWS
$trs .= $tr;
}
}
else{
$msg = "There are no files to display";
$tr = <<<EOD
<tr>
<td style="text-align:center; padding: 10px !important; font-weight: normal;">$msg</td>
</tr>
EOD;
$trs .= $tr;
}
// USE HEREDOC TO INSERT THE TABLE ROWS INTO THE TABLE
$tab = <<<EOD
<table id="pdfDownload" width="97%" align="center" border="1" cellspacing="10" cellpadding="0" style="border:1px solid grey; padding-bottom: 10px; margin-bottom:20px;">
<th style="text-align:center; padding: 10px !important; padding-bottom: 20px; border:1px solid black; background-color: #3399FF; color: white; font-size: 18px !important;" colspan="4">Destruction Certificates Download</th>
<tr>
<th></th>
</tr>
$trs
</table>
EOD;
// SHOW THE WORK PRODUCT
echo $tab;
?>
</div>
directory structure
.
..
destcerts
client1
client2
client3
etc

Categories