FPDF - Generate multiple pdf in a single creation - php

I am trying to generate multiple (in cluster) pdf reports using fpdf in a single click in a php form.
The test_center is the cluster of separate reports. When the submit button is clicked, it will call the php file of fpdf. And my codes aren't working yet.
So far in my php:
<?php
$program="select distinct test_center from sa_sase_result where school_year = '$content' ";
$prog=mysql_query($program);
while($row = mysql_fetch_array($prog))
{
echo '<option>' .$row['test_center'] . '</option>';
}
$message = null;
if($_SERVER["REQUEST_METHOD"] == "POST") {
if(!isset($_POST['depchair'])) {
} else if($_POST['depchair']=="") {
} else {
$input_depchair = addslashes($_POST['depchair']);
$input_depchair = addslashes($_POST['depchair']);
$pro_email="select control_no from sa_student_infoe y where y.test_center = '$input_depchair'";
$pro_address=mysql_query($pro_email);
$address = mysql_result($pro_address, 0);
}
}
?>
EDIT: Here's the generate_pdf.php file.
<?php
require('fpdf/fpdf.php');
mysql_connect("localhost", "root", "1234") or die(mysql_error());
mysql_select_db("final") or die(mysql_error());
$query = "SELECT * FROM sa_student_infoe, sa_student_edubg, sa_sase_result, sa_accounts";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_BOTH)){
$control_no[] = $row['control_no'];
$surname[] = $row['surname'];
$fname[] = $row['fname'];
$mname[] = $row['mname'];
$app_no[] = $row['activation_code'];
$schoolyear[] = $row['schoolyear'];
$schl[] = $row['high_school'];
$schl_ad[] = $row['address_school'];
$apt[] = $row['aptitude'];
$mth[] = $row['math'];
$lng[] = $row['language'];
$sci[] = $row['science'];
$totgrd[] = $row['total_grade'];
$sx[] = $row['sex'];
}
$ctrl_no = array_shift( $control_no );
$sname = array_shift( $surname );
$firstname = array_shift( $fname );
$midname = array_shift( $mname );
$appno = array_shift( $app_no );
$schyear = array_shift( $schoolyear );
$school = array_shift( $schl );
$school_ad = array_shift( $schl_ad );
$aptitude = array_shift( $apt );
$math = array_shift( $mth );
$lang = array_shift( $lng );
$science = array_shift( $sci );
$gr = array_shift( $totgrd );
$sex = array_shift( $sx );
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','', 12);
$pdf->Cell(0, 0,'Mindanao State University', 0, 1, 'C');
$pdf->Cell(0, 10,'System Admission and Scholarship Examination (SASE)', 0, 1, 'C');
$pdf->Cell(0, 20,'REPORT OF RATING', 0, 1, 'C');
$pdf->Cell(30,5,'Control No:');
$pdf->Cell(100,5,$ctrl_no);
$pdf->Cell(30,5,'School Year:');
$pdf->Cell(-160,5,$schyear);
$pdf->Cell(30,15,'Activation Code:');
$pdf->Cell(10,15,' ' . $appno);
$pdf->Cell(50,40,$sname);
$pdf->Cell(50,40,$firstname);
$pdf->Cell(-120,40,$midname);
$pdf->Cell(15,50,'____________________________________________________________________');
$pdf->Cell(50,60,'LASTNAME');
$pdf->Cell(50,60,'FIRSTNAME');
$pdf->Cell(-50,60,'MIDDLENAME');
$pdf->Cell(-65,90,$school);
$pdf->Cell(67,100,'____________________________________________________________________');
$pdf->Cell(-15,110,'SCHOOL');
$pdf->Cell(-52,140,$school_ad);
$pdf->Cell(57,150,'____________________________________________________________________');
$pdf->Cell(-25,160,'SCHOOL ADDRESS');
$pdf->Cell(.1,190,'--------------------------------------------------------------------');
$pdf->Cell(-35,200,'--------------------------------------------------------------------');
$pdf->Cell(17,230,'AP(30):');
$pdf->Cell(18,230,$aptitude);
$pdf->Cell(17,230,'LU(80):');
$pdf->Cell(18,230,$lang);
$pdf->Cell(17,230,'MA(40):');
$pdf->Cell(18,230,$math);
$pdf->Cell(17,230,'SC(30):');
$pdf->Cell(18,230,$science);
$pdf->Cell(18,230,'GR(180):');
$pdf->Cell(-300,230,$gr);
$pdf->Cell(-10,260,'SEX:');
$pdf->Output("pdf_reports/SASE_report_rating/".$ctrl_no.".pdf", "F");
?>

js:
$("#id_of_generate_it_button").click(function () {
var N = 10;// ten pdf files will be generated and stored to the disk
for (i = 0; i < N; i++) {// 'the loop' -- walk thru all parallel generation processes connected to the event
parameter = N;// just to definite each single generated file
$.get("generate.php?q=parameter", function (data) {// start the ajax process to generate single document
// ?q=parameter i wrote just for passing to the php file some dependent parameter for each single file
// pdf #i generated
});
}// end for parallel generating N pdf files to the disk
});//end click
in generate.php:
$query = "SELECT * FROM sa_student_infoe, sa_student_edubg, sa_sase_result, sa_accounts WHERE some_field = ' . $_REQUEST['q'] . '";// single record from all

Related

Why the Loop not properly Looping through the data?

<?php
$id = array(
"UC4MubF2asPHQbXN44DVNeXg",
"UCXuDgoo_oiZf8UkIXs3Y_kw",
"UCMnDuOzzJrWzr5tfemDcqlQ",
"UC9FH1mkHLFQuPPEPu9CfR1A",
"UCfyEAw41i7PRetP2erYf9dg",
);
// Getting Emails from DB and Looping with Channel Title and Video Title
$conn = mysqli_connect("localhost","username","password","dbname");
$query = "SELECT * FROM prospects ORDER BY email";
$rows = mysqli_query($conn, $query);
while($row = mysqli_fetch_array($rows)) {
$to[] = $row['email'];
}
$size = sizeof($id);
//echo "<br>Number of channel Ids: ".$size."<br><br>";
// Looping each Url for Each Email to get Data
foreach($to as $t){
echo $t."<br>";
for ($i = 0; $i < $size; $i++) {
$url = "https://www.youtube.com/channel/$id[$i]";
// echo $url."<br>";
$channel = trim(explode('https://www.youtube.com/channel/', $url)[1]);
// echo $channel."<br>";
$rss = "https://www.youtube.com/feeds/videos.xml?channel_id=$channel";
// echo $rss."<br>";
$xml = simplexml_load_file($rss);
$title = $xml->title;
// echo $title."<br>";
$videoTitle = $xml->entry[0]->title;
// echo $videoTitle."<br>";
$id[$i] = $xml->id;
// echo $id[$i]."<br>";
// $idOnly = substr($id[$i] , strpos($id[$i] , "yt:channel:") + 11);
// echo $idOnly."<br>";
$pub[$i] = $xml->entry[0]->published;
// echo $pub[$i]."<br>";
$realDate_ = new DateTime($pub[$i]);
// var_dump($realDate_);
$realDate2_ = $realDate_->format("D, d M Y")."<br>";
//echo $realDate2_;
$today_ = new DateTime();
// $today2_ = $today_->format("D, d M Y")."<br>";
// echo $today2_;
// if ($today2_ == $realDate2_) {
// echo "true";
// This is the Result with Every Email
echo $content = "• <a href='https://bladingflix.com/render.php?email=$t&channel=$idOnly'>".$title." - ".$videoTitle."</a><br>";
// }
}
}
?>
For the First Email the Data Shows Properly but in for the others
Purpose = get collected links add the user email to each url repeat for each.
Please make below changes in your existing code
In the second for() loop you are replacing the $id array as below
$id[$i] = $xml->id;
Instead of replacing the $id[$i] value, create new variable as below
$xmlId = $xml->id;
$idOnly = substr($xmlId, strpos($xmlId , "yt:channel:") + 11);
And please uncomment the $idOnly variable.
It will work. And try to refactor this code.

Using an If statement in PHP but not working

What I want to do is When I enter all my information (for client ID 199 in the picture) In my account being submit it, it goes into the database. BUT I want it to change to something and so i added an if statement
Here the code im adding to the existing code already at the BOTTOM of the code
if ($vpr_clid == 199) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
if the ($vpr_clid = 199)
i want the clname to be "Shelley Madsen And Associates" then what is show in the table below instead of "Nice and White Smiles" (that an example of the results look like)
but when i chcek the database it not changing it and still show "Nice and White Smiles :(
I dont see any error, so it might be the placement of the code i have to put the IF statement in the huge php file? Dont know how to fix this issue
Thanks (the code below is the base code before i added the If statement)
I also insert the if statement before the function were called but still didnt work example
if ($vpr_clid == 199) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
$result = InsertIntoPayReminder($link, $vars);
$result = GetVpr_Id($link, $vars);
<?php
session_start();
if ($_SESSION['company'] != "ACB") {
// redirect to the logout page
$redirect = 'logout.php';
include './includes/redirect.php';
}
class variables_obj {
var $vpr_plan = '';
var $vpr_id = '';
var $vpr_clid = '';
var $vpr_cl_name = '';
var $vpr_cl_phone = '';
var $vpr_call_start_date = '';
var $vpr_db_account = '';
var $vpr_db_fname = '';
var $vpr_db_mname = '';
var $vpr_db_lname = '';
var $vpr_rp_fname = '';
var $vpr_rp_mname = '';
var $vpr_rp_lname = '';
var $vpr_rp_address = '';
var $vpr_rp_city = '';
var $vpr_rp_state = '';
var $vpr_rp_zipcode = '';
var $vpr_rp_phonenum = '';
var $vpr_rp_phonetype = '';
var $vpr_date_entered = '';
var $newrecdt = '';
var $vpl_day_offset = '';
var $vpl_action = '';
var $vpr_promocode = '';
}
function ScrubPhone($old_phone_num) {
$phone_length = strlen($old_phone_num);
$new_phone_num = "";
for($i = 0; $i < $phone_length; $i = $i + 1) {
if(is_numeric($old_phone_num[$i])) {
$new_phone_num .= $old_phone_num[$i];
}
}
return $new_phone_num;
}
function ScheduleCreated($link, $vars) {
$query = "UPDATE v_payreminder SET vpr_schedule_created = '1' WHERE vpr_id='".$vars->vpr_id."'";
if (!mysql_query($query,$link)) {
die('Error: ' . mysql_error());
}
return true;
}
function CreateScheduleRow($link, $vars){
// echo "vpl_day_offset: ".$vars->vpl_day_offset."<br>";
// echo "vpl_action: ".$vars->vpl_action."<br>";
$plus_days = " +".$vars->vpl_day_offset." days";
// echo "plus days: ".$plus_days."<br>";
$date_offset = strtotime(date("Y-m-d", strtotime($vars->vpr_date_entered)).$plus_days);
$date_offset = date("Y-m-d", $date_offset);
// echo "date_offset: ".$date_offset."<br>";
// $date_offset = strtotime(date("Y-m-d",strtotime($vars->vpr_date_entered))." +".$vars->vpl_day_offset." days");
// $date_offset = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
// echo "date_offset: ".$date_offset."<br>";
$query = "INSERT INTO v_pr_schedule (
vpr_id,
vsc_plan,
vsc_date_entered,
vsc_action,
vsc_action_date,
vsc_status
) VALUES (
'$vars->vpr_id',
'$vars->vpr_plan',
'$vars->vpr_date_entered',
'$vars->vpl_action',
'$date_offset',
'VACT')";
//echo "query: ".$query."<br>";
if (!mysql_query($query,$link)) {
die('Error: ' . mysql_error());
}
return true;
}
function CreateSchedule($link, &$vars) {
// CREATE SCHEDULE
$query = " SELECT vpl_day_offset, vpl_action, vpl_condition
FROM v_plan
WHERE vpl_plan = '".$vars->vpr_plan."'";
// echo "query: ".$query."<br>";
$qresult = mysql_query($query);
if (!$qresult) {
print(mysql_error());
}
if ($qresult && mysql_num_rows($qresult) > 0 ) {
while ($row = mysql_fetch_array($qresult, MYSQL_ASSOC)) {
$vars->vpl_day_offset = $row['vpl_day_offset'];
$vars->vpl_action = $row['vpl_action'];
if ($row['vpl_condition'] == 'OO') {
CreateScheduleRow($link, $vars);
}
}
}
return true;
}
function InsertIntoPayReminder($link, &$vars) {
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");
//echo "Client Name: ".$vars->vpr_cl_name."<br><br>";
//exit();
$sql="INSERT INTO v_payreminder (
vpr_clid,
vpr_cl_name,
vpr_cl_phone,
vpr_call_start_date,
vpr_db_account,
vpr_db_fname,
vpr_db_mname,
vpr_db_lname,
vpr_rp_fname,
vpr_rp_mname,
vpr_rp_lname,
vpr_rp_phonenum,
vpr_rp_phonetype,
vpr_rp_address,
vpr_rp_city,
vpr_rp_state,
vpr_rp_zipcode,
vpr_promo,
vpr_date_entered) VALUES (
'$vars->vpr_clid',
'$vars->vpr_cl_name',
'$vars->vpr_cl_phone',
'$vars->vpr_call_start_date',
'$vars->vpr_db_account',
'$vars->vpr_db_fname',
'$vars->vpr_db_mname',
'$vars->vpr_db_lname',
'$vars->vpr_rp_fname',
'$vars->vpr_rp_mname',
'$vars->vpr_rp_lname',
'$vars->vpr_rp_phonenum',
'$vars->vpr_rp_phonetype',
'$vars->vpr_rp_address',
'$vars->vpr_rp_city',
'$vars->vpr_rp_state',
'$vars->vpr_rp_zipcode',
'$vars->vpr_promocode',
'$vars->vpr_date_entered')";
if (!mysql_query($sql,$link)) {
die('Error2: ' . mysql_error());
}
return true;
}
function GetVpr_Id($link, &$vars) {
// Find out what vpr_id is
$query = "SELECT vpr_id FROM v_payreminder ";
$query .= "WHERE vpr_clid = '".$vars->vpr_clid."' AND vpr_date_entered = '".$vars->vpr_date_entered."'";
$qresult = mysql_query($query);
if (!$qresult) {
print(mysql_error());
}
if ($qresult && mysql_num_rows($qresult) > 0 ) {
$row = mysql_fetch_array($qresult, MYSQL_ASSOC);
$vars->vpr_id = $row['vpr_id'];
}
}
function InsertInActivity($link, $vars) {
// ENTER INTO ACTIVITY
$vaction_desc = 'PATIENT ENTERED';
$sql = "INSERT INTO v_pr_activity (
vpr_id,
va_plan,
va_action_dttm,
va_action_code,
va_action_desc,
va_disposition_code,
va_disposition_desc,
va_status_code,
va_status_desc
) VALUES (
'$vars->vpr_id',
'$vars->vpr_plan',
'$vars->vpr_date_entered',
'VINIT',
'$vaction_desc',
'SUCCESS',
'SUCCESS',
'VACT',
'ACTIVE'
)";
if (!mysql_query($sql,$link)) {
die('Error: ' . mysql_error());
}
}
include './includes/dblogin.php';
$vars = new variables_obj();
$vars->vpr_plan = 'VP01';
$vars->vpr_clid = $_SESSION['userid'];
//-------------------------------------------------------
// No commas can be in client name or they will
// mess up the Global Connect CSV file.
//-------------------------------------------------------
$vpr_cl_name = $_SESSION['username'];
$vpr_cl_name = str_replace(",", " ", $vpr_cl_name);
$vars->vpr_cl_name = $vpr_cl_name;
//-------------------------------------------------------
//-------------------------------------------------------
$vars->vpr_cl_phone = ScrubPhone($_SESSION['uphone']);
$vars->vpr_call_start_date = '0000-00-00';
$vars->vpr_db_account = $_POST['ndaccnum'];
$vars->vpr_db_fname = $_POST['ndfreqname'];
$vars->vpr_db_mname = $_POST['ndmname'];
$vars->vpr_db_lname = $_POST['ndlreqname'];
$vars->vpr_rp_fname = $_POST['ndrfreqname'];
$vars->vpr_rp_mname = $_POST['ndrmname'];
$vars->vpr_rp_lname = $_POST['ndrlreqname'];
$vars->vpr_rp_address = '';
$vars->vpr_rp_city = '';
$vars->vpr_rp_state = $_POST['ndrstatereqname'];
$vars->vpr_rp_zipcode = $_POST['ndrreqzipcode'];
$phonenumber = $_POST['1ndrreqphone'].$_POST['2ndrreqphone'].$_POST['3ndrreqphone'];
$vars->vpr_rp_phonenum = $phonenumber;
$vars->vpr_rp_phonetype = $_POST['treqphone'];
$vars->vpr_date_entered = date('Y-m-d H:i:s');
$vars->newrecdt = date('Ymd');
$vars->vpr_promocode = $_POST['promocode'];
// echo "vpr_plan: ".$vars->vpr_plan."<br>";
// echo "vpr_date_entered: ".$vars->vpr_date_entered."<br>";
// echo "newrecdt: ".$vars->newrecdt."<br>";
// echo "vpr_clid: ".$vars->vpr_clid."<br>";
// echo "vpr_id: ".$vars->vpr_id."<br>";
$result = InsertIntoPayReminder($link, $vars);
$result = GetVpr_Id($link, $vars);
$result = InsertInActivity($link, $vars);
$result = CreateSchedule($link, $vars);
$result = ScheduleCreated($link, $vars);
// echo "vpr_id: ".$vars->vpr_id."<br>";
mysql_close($link);
// redirect
$redirect = 'vpayremind.php';
include './includes/redirect.php';
?>
okay referencing the following lines..
if ( $vpr_clid == 199 ) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
$result = InsertIntoPayReminder($link, $vars);
...and then:
function InsertIntoPayReminder($link, &$vars) {
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");
so on and so forth... }
it doesnt seem as if you are actually setting the value of the class object. You seem to be setting some arbitrary php variable to the name you want, and then passing a totally different ' $vars ' object into the function. I don't see any reason to believe that the ' $vars ' you are passing into the function call contains the name value you want it to contain. You should be assigning the value of ' $vars ' before passing it in.
For instance:
if ( $vpr_clid == 199 ) {
$vars[ 'vpr_cl_name' ] = "Shelley Madsen And Associates";
}
then you can get rid of this line all together:
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");

php response is taking too long time

I have some problem with getting results from VFP database results... The time which is taking by my php script is veeeery long - about 30 minutes, but it should be much shorter...
So there is the code which is responsible for taking database results:
$connect = odbc_connect("RIS", "", "", SQL_CUR_USE_DRIVER) or die("Error in connection ". odbc_errormsg($connect));
$array = array();
$info = array();
$from = $_GET['from'];
$to = $_GET['to'];
$rez_nap = odbc_exec($connect, "
select
pacientid as pac_pk,
datanapr,
ocered,
rtgapparat,
doctor as doc_naprav,
pk_na,
data_opis,
arst_opis as id_arst_opis
from
napravlenie
where
not arst_opis == '0000' and
not arst_opis == '' and
datanapr between {^".$from."} and {^".$to."}
") or die(odbc_errormsg());
while($row_nap = odbc_fetch_array($rez_nap))
{
echo "<pre>";
var_dump($row_nap);
$rez_opis = odbc_exec($connect, "
select
opis as opisanie,
doctor as doc_opis
from
opisanie_rtg
where
pacientid = '".$row_nap["pac_pk"]."' and
data = '".$row_nap["data_opis"]."' and
ocered = '".$row_nap["ocered"]."'
") or die(odbc_errormsg());
while($row_desc = odbc_fetch_array($rez_opis))
{
$op = explode('##$', $row_desc['opis']);
$opisanie = iconv( "cp1257", "utf-8", trim( addslashes($op[1]) ) );
$t_nr_i = substr($op[0], 12);
$ttt = explode("[", $t_nr_i);
if ( strlen($ttt[0]) > 12 )
{
$tt_nr_is = explode("-", $ttt[0]);
$t_nr_is_t = substr($tt_nr_is[0], 0, 8);
$t_nr_is_t_2 = substr($tt_nr_is[0], 8, 5);
$row_desc["nr_is"] = $t_nr_is_t."-".$t_nr_is_t_2;
}
else
{
$t_nr_is_t = substr($ttt[0], 0, 8);
$t_nr_is_t_2 = substr($ttt[0], 8, 5);
$row_desc["nr_is"] = $t_nr_is_t."-".$t_nr_is_t_2;
}
$row_desc['opis'] = $opisanie;
/////////////////////////////////////////////////////////////////////////////////////////////////////
$rez_apparat = odbc_exec($connect, "
select
kod,
gruppa,
imy,
prefiks
from
apparatura
where
kod = '".$row_nap["rtgapparat"]."'
") or die("Error in apparatura.dbf - ". odbc_errormsg($connect));
while($row_apparat = odbc_fetch_array($rez_apparat))
{
$rez_app_gruppa = odbc_exec($connect, "
select
gruppa,
prefiks,
apparati
from
apparat_gruppa
where
gruppa = '".$row_apparat["gruppa"]."'
") or die(error_logs("Error in apparat_gruppa.dbf - ".odbc_errormsg($connect)));
while($row_app_gruppa = odbc_fetch_array($rez_app_gruppa))
{
$rez_personal = odbc_exec($connect, "
select
s_name as doc_opis_name,
f_name as doc_opis_surname
from
personal
where
number = '".$row_nap["id_doc_opis"]."'
") or die(error_logs("Error in personal.dbf - ".odbc_errormsg($connect)));
while($row_personal = odbc_fetch_array($rez_personal))
{
$row_personal["doc_opis_name"] = iconv("cp1257", "utf-8", trim($row_personal["doc_opis_name"]));
$row_personal["doc_opis_surname"] = iconv("cp1257", "utf-8", trim($row_personal["doc_opis_surname"]));
$row_personal["filial"] = "r15";
$info[] = array_merge($row_nap, $row_desc, $row_apparat, $row_app_gruppa, $row_personal);
}
}
}
}
}
echo json_encode($info);
odbc_close($connect);
the database has about ~80-90k rows with data, and I'm using odbc driver to connect to VFP database, also the database is on the remote server... Any advices what I'm doing wrong? Because I can't figure what I'm doing wrong... Thanks for any advice and help!
P.S Also I need to convert that response into JSON and then save it to MySQL database...
EDIT 1
I have the second indexes:
pacientid, data_opis, ocered into the pacient table, opisanie and napravlenie

Generating PDF dynamically through fpdf

I am trying to generate a PDF dynamically using fpdf, but I am finding it very difficult. Only half of the result I could get. I want to generate my PDF like this:
And now I get a result like this:
Here is the code for PDF:
<?php
require('../fpdf/fpdf.php');
error_reporting(-1);
$id = $_GET['order_id'];
$db = new mysqli('localhost','root','','dbnme'); // use your credentials
class INVPDF extends FPDF
{
var $id;
var $today;
var $widths;
var $heads;
var $aligns;
var $formats;
var $db;
var $invTotal = 0;
var $advancePaid = 0;
//constructor
function INVPDF($invno, $db)
{
parent::fpdf();
$this->id = $invno;
$this->db = $db;
$this->today = date('jS M Y');
$this->heads = array('Item', 'UOM', 'Price', 'Qty', 'Disc %', 'Tax', 'Frt', 'Total' );
$this->widths = array (45, 15, 35, 15, 15, 20, 25, 30);
$this->aligns = array ('L','C','L','C','C','R','C', 'C');
$this->formats = array (0,0,0,0,0,1,0,0);
}
//Page header
function Header()
{
//Arial bold 15
//Title
include("../connect.php");
$ss1 = "select orders.sales_order_id, orders.company_id, lead_address.address, lead_address.address_category, lead_address.country, lead_address.state, lead_address.company_id, lead_address.city,lead_address.pin from orders INNER JOIN lead_address ON orders.company_id=lead_address.company_id where lead_address.address_category='Billing' AND orders.sales_order_id='".$_GET['order_id']."'";
$mq1 = mysql_query($ss1) or die(mysql_error());
$rr1 = mysql_fetch_array($mq1);
$billing = $rr1['address'];
list($line1, $line2, $line3) = explode(',',$billing);
$country = $rr1['country'];
$state = $rr1['state'];
$city = $rr1['city'];
$pin = $rr1['pin'];
//list($line1, $line2, $country, $state, $city, $pin) = explode(',',$address);
$ss2 = "select orders.sales_order_id, orders.company_id, lead_address.address, lead_address.address_category, lead_address.country, lead_address.state, lead_address.company_id, lead_address.city,lead_address.pin from orders INNER JOIN lead_address ON orders.company_id=lead_address.company_id where lead_address.address_category='Shipping' AND orders.sales_order_id='".$_GET['order_id']."'";
$mq2 = mysql_query($ss2) or die(mysql_error());
$rr2 = mysql_fetch_array($mq2);
$shipping = $rr2['address'];
$country1 = $rr2['country'];
$state1 = $rr2['state'];
$city1 = $rr2['city'];
$pin1 = $rr2['pin'];
//$email = $rr1['email'];
// $phone = $rr1['phone'];
// $mobile = $rr1['mobile'];
// $this->SetFont('Arial','B',15);
$this->setXY(10,20);
// $this->Cell(0,10,'INVOICE '.$this->id,0,2,'L');
$this->Image('logo.png',20,6,15);
$this->setXY(12,20);
//
$this->SetFont('OpenSans','',7);
$this->Cell(0,10,'Company Name. ',0,2,'L');
$this->Cell(0,0,'Address1, address2',0,2,'L');
$this->Cell(0,8,'city, stte',0,2,'L');
$this->Cell(0,2,'sales#company.com',0,2,'L');
//$this->Image('images/logo.png',10,6,60);
$this->SetFont('OpenSans','',7);
$this->setXY(12,50);
$this->Cell(0,-2,'Shipping Address',$this->id,0,2,0,'L');
$this->SetFont('OpenSans','',7);
$this->setXY(12,52);
$this ->MultiCell(57,22,'', 'LRTB', 'L', 1);
//$this->Cell(0,8,$name,$this->id,0,2,0,'L');
$this->setXY(12,55);
$this->Cell(0,-1,$shipping,$this->id,0,2,0,'L');
$this->setXY(12,53);
$this->Cell(0,10,$country." , ".$state,$this->id,0,2,0,'L');
$this->setXY(12,52);
$this->Cell(0,20,$city." , ".$pin,$this->id,0,2,0,'L');
$this->SetFont('OpenSans','',7);
$this->setXY(140,52);
$this ->MultiCell(57,22,'', 'LRTB', 'L', 1);
$this->setXY(140,34);
$this->Cell(0,30,'Billing Address',$this->id,0,2,0,'L');
$this->SetFont('OpenSans','',7);
$this->setXY(140,35);
$this->Cell(0,40,$line1." , ".$line2, $this->id,0,2,0,'L');
$this->setXY(140,35);
$this->Cell(0,49,$line3, $this->id,0,2,0,'L');
$this->setXY(140,33);
$this->Cell(0,62,$city1." , ".$pin1,$this->id,0,2,0,'L');
$this->setXY(140,33);
$this->Cell(0,70,$country1." , ".$state1,$this->id,0,2,0,'L');
//$this->setXY(12,65);
// $this->Cell(0,60,$phone,$this->id,0,2,0,'L');
//$this->setXY(12,65);
//$this->Cell(0,70,$mobile,$this->id,0,2,0,'L');
$this->SetFont('OpenSans','',7);
$this->setXY(10,5);
$this->Cell(0,10,'QUOTATION: '.$this->id,0,2,'R');
$this->SetFont('OpenSans','',7);
$until = date ('jS F Y', strtotime($this->today));
$this->Cell(0,0,'Date: '.$until,0,2,'R');
$this->SetFont('OpenSans','',7);
$this->Cell(0,10,'Due Date: Due on receipt',0,2,'R');
//Line break
$this->Ln(60);
for ($i=0; $i<9; $i++)
{
$this->Cell ($this->widths[$i], 8, $this->heads[$i], 1, 0, 'C', 1);
}
$this->Ln(8);
}
//Page footer
function Footer()
{
# $this->SetY(-50); // Uncomment to position at 5 cm from bottom
//Arial italic 8
$this->SetFont('OpenSans','',8);
$w = array_sum(array_slice($this->widths,0,3));
$this->Cell($w,12,'',1);
$this->Cell($this->widths[3],12,'',1,0,'C');
$this->setLeftMargin(45 + array_sum(array_slice($this->widths,0,4)));
$this->Cell($this->widths[5],4,'Sub Total',1);
$this->Cell($this->widths[6],4,number_format($this->invTotal,2),1,0,'R');
$this->Cell($this->widths[7],4,'USD',1,1,'C');
$this->Cell($this->widths[5],4,'Tax',1);
$this->Cell($this->widths[6],4,number_format($this->advancePaid,2),1,0,'R');
$this->Cell($this->widths[7],4,'USD',1,1,'C');
$this->Cell($this->widths[5],4,'Freight',1);
$this->Cell($this->widths[6],4,number_format($this->freight,2),1,0,'R');
$this->Cell($this->widths[7],4,'USD',1,1,'C');
$this->setLeftMargin(10);
$this->Cell($this->widths[5],4,'Total',1);
$this->Cell($this->widths[6],4,number_format($this->invTotal+$this->advancePaid,2),1,0,'R');
$this->Cell($this->widths[7],4,'USD',1,1,'C');
$this->SetFont('OpenSans','',6);
$this->Cell($w,10,'',0,0,'L');
$this->Cell(30,4,'Private Limited Company - TIN: 345sddd - PAN: sf43534',0,0,'C');
//$this->Cell($w,10,'');
$this->Cell(-30,12,'SRVC TAX: gddddddddddd - CIN: sdgdgdgdfgfdgfg',0,0,'C');
$this->Cell(30,20,'This document has been electronically generated and requires no physical signature or stamp.',0,0,'C');
}
function makeInvoice()
{
$sql = "select before_order_line_items.item, before_order_line_items.description, before_order_line_items.uom, before_order_line_items.selling_price, before_order_line_items.quantity, before_order_line_items.discount, before_order_line_items.tax, before_order_line_items.freight, before_order_line_items.tax_amount, before_order_line_items.total, items.name as iname, taxes.tax_id, taxes.name as tname, taxes.rate from before_order_line_items inner join items on before_order_line_items.item=items.item_id inner join taxes on before_order_line_items.tax=taxes.tax_id where before_order_line_items.sales_order_id = '".$_GET['order_id']."' ";
//echo $sql;
$res = $this->db->query($sql) or die($this->db->error);
$this->SetFont('OpenSans','',8);
if ($res->num_rows > 0)
{
while ($r = $res->fetch_row())
{
$this->invTotal += $r[10];
foreach ($r as $c => $value) {
//echo $value;
if ($this->formats[$c]) {
$value = number_format($value);
// echo $value;
}
$this->Cell($this->widths[$c],10,$value,'LR',0, $this->aligns[$c]);
}
$this->Ln();
//$amount = number_format($amount+$value);
}
}
}
} # invpdf class
$invno = $_GET['order_id'];
//Instantiation of inherited class
$pdf = new INVPDF($invno, $db);
$pdf->Open();
$pdf->AliasNbPages();
$pdf->setLeftMargin(10);
$pdf->setRightMargin(10);
$pdf->AddFont('OpenSans','','Opensans-Regular.php');
$pdf->SetFont('OpenSans','',7);
$pdf->SetDrawColor(102);
$pdf->SetFillColor(220);
$pdf->AddPage();
$pdf->makeInvoice();
$pdf->Output();
?>
Can somebody please help me how to do it? or is there any example code for something similar to this?
Looking at your actual pdf and expected pdf.. you are missing the no. column in table header.
This line-
$this->heads = array('Item', 'UOM', 'Price', 'Qty', 'Disc %', 'Tax', 'Frt', 'Total' );
should be-
$this->heads = array('No.', 'Item', 'UOM', 'Price', 'Qty', 'Disc %', 'Tax', 'Frt', 'Total' );

php cron job issue?

i m using the php code to exectue the code using the cron. i have set the cron time and command in cpanel also.
1). But whenever cron runs i receive a mail
/home/letsview/public_html/getfeed.php: line 1: ?php: No such file or directory
/home/letsview/public_html/getfeed.php: line 3: syntax error near unexpected token `'/home/letsview/public_html/wp-config.php''
/home/letsview/public_html/getfeed.php: line 3: `include_once('/home/letsview/public_html/wp-config.php');'
i have set this command in cpanel "/home/letsview/public_html/getfeed.php"
i have also tried this PHP: Error trying to run a script via Cron job and added this command on the top of the file /usr/local/lib/php/ but it still not working
Here is the code of cron file getfeed.php
<?php
#!/usr/local/lib/php/
include_once('/home/letsview/public_html/wp-config.php');
include_once('/home/letsview/public_html/wp-includes/wp-db.php');
include_once('/home/letsview/public_html/wp-admin/includes/file.php');
include_once('/home/letsview/public_html/wp-admin/includes/image.php');
include_once('/home/letsview/public_html/wp-admin/includes/media.php');
global $wpdb;
//property_type
$xml = simplexml_load_file("/home/letsview/public_html/letsviewproperties.xml",'SimpleXMLElement', LIBXML_NOCDATA);
$TotalPostadded = 0;
$TotalUseradded = 0;
foreach($xml as $child)
{
//Insert Post
$postdata = array();
$postdata['post_title'] = trim($child->title);
$postdata['post_content'] = trim($child->content);
//$postdata['guid'] = trim($child->url);
$postdata['post_status'] = 'publish';
$postdata['post_type'] = 'post';
$postdata['post_date'] = date('Y-m-d H:i:s');
//Insert Post Meta
$postmetadata = array();
$addresstext = trim($child->FullAddress->address1);
if($addresstext != ''){
$addresstext .= ', ';
}
$addresstext .= trim($child->FullAddress->address2);
if($addresstext != ''){
$addresstext .= ', ';
}
$addresstext .= trim($child->FullAddress->address3);
if($addresstext != ''){
$addresstext .= ', ';
}
$addresstext .= trim($child->FullAddress->address4);
$postmetadata['price'] = trim($child->price);
$postmetadata['property_type'] = trim($child->type);
$postmetadata['bed_rooms'] = trim($child->rooms);
$postmetadata['bath_rooms'] = trim($child->bathrooms);
$postmetadata['address'] = $addresstext;
$postmetadata['add_city'] = trim($child->city);
$postmetadata['add_state'] = trim($child->FullAddress->region);
$postmetadata['add_country'] = trim($child->FullAddress->country);
$postmetadata['add_zip_code'] = trim($child->postcode);
$postmetadata['other_guid'] = trim($child->url);
$postmetadata['post_from_feed'] = true;
//Insert Author(agent)
$authordata = array();
$authormetadata = array();
if(!empty($child->agent->agent_name)){
//Author data
$authordata['user_login'] = trim(pg_create_string($child->agent->agent_name));
$authordata['user_nicename'] = trim($child->agent->agent_name);
$authordata['display_name'] = trim($child->agent->agent_name);
$authordata['user_email'] = trim($child->agent->agent_email);
$authordata['user_url'] = trim($child->url);
$authordata['role'] = trim('agent');
$authordata['user_registered'] = date('Y-m-d H:i:s');
//Author meta data
$authormetadata['user_phone'] = trim($child->agent->agent_phone);
$authormetadata['user_address'] = trim($child->agent->agent_address);
}
foreach($child->pictures as $pictures)
{
$postimagedata = array();
$imageloop = 0;
foreach($pictures as $picture)
{
$postimagedata[$imageloop] = (string)$picture->picture_url;
$imageloop++;
}
}
$postmetadata['post_from_feed_images'] = serialize($postimagedata);
if($postdata['post_title'] != ''){
$sql = "select count(post_title) as post from ".$wpdb->prefix."posts where post_title = '".$postdata['post_title']."' and post_status = '".$postdata['post_status']."'";
$sqlresult = $wpdb->get_results($sql);
foreach ( $sqlresult as $post ) {
if($post->post == 0)
{
if(!empty($authordata)){
$user_id = wp_insert_user( $authordata );
if(!empty($user_id) && empty($user_id->errors)){
$TotalUseradded++;
echo "User added = ".$user_id."<br />";
if(!empty($authormetadata)){
foreach($authormetadata as $meta_key=>$meta_value){
add_user_meta( $user_id, $meta_key, $meta_value);
echo "User Meta = ".$meta_key." Inserted<br />";
}
}
}elseif(!empty($user_id->errors)){
$userdata = get_user_by('email', $authordata['user_email']);
$user_id = $userdata->ID;
echo "User fetched = ".$user_id."<br />";
}
$postdata['post_author'] = $user_id;
}
$post_id = wp_insert_post($postdata);
if(!empty($post_id)){
$TotalPostadded++;
echo "<br />"."Post Inserted = ".$post_id;
$properties_category_id = 109;
$cat = "INSERT INTO wp_term_relationships ( object_id, term_taxonomy_id ) VALUES ( '".$post_id."','".$properties_category_id."' )";
$catid = $wpdb->query($cat);
echo "<br />"."Post attached to Category ID = ".$properties_category_id."<br />";
if(!empty($postmetadata)){
foreach($postmetadata as $key=>$value){
add_post_meta($post_id, $key,$value, true);
echo "Post Meta = ".$key." Inserted<br />";
}
}
}
}
}
}
}
$cron = "<br />"."Corn Done";
$cron .= "<br />"."Total Post added = ".$TotalPostadded;
$cron .= "<br />Total User added = ".$TotalUseradded;
echo $cron;
mail('xxxxxx#xxxxx.com','Lets view Properties Corn',$cron);
function pg_create_string($text)
{
// replace all non letters or digits with -
$text = preg_replace('/\W+/', '-', $text);
// trim and lowercase
$text = strtolower(trim($text, '-'));
return $text;
}
?>
Can any one help me??
The start of the file should be:
#!/usr/bin/php
<?php
This assumes that your PHP binary is in the folder /usr/bin. If it isn't, then change the #! line appropriately.
Even better:
#!/usr/bin/env php
<?php
will almost certainly work as it uses the system's env command to work out where php is.
Add this to the very top of your file and chmod the file to execute rights (555 or 775) etc.
#!/usr/local/lib/php
<?php
// your code
Where /usr/local/lib/php is the path to php.
Or if that doesn't work you can change the cron command:
/usr/local/lib/php /home/letsview/public_html/getfeed.php
#!/usr/local/lib/php
<?php
// php code
And you sure the php cli in /usr/local/lib

Categories