Hi i need to add multiple minimum minimum_order_amount for other postcodes - function

i'm using this code that i found here! the problem is i need to add multiple minimum minimum_order_amount for other postcodes! Help!
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
$minimum = 20; // Set the minimum order value
$postcodes = array('26224', '26222', '26442', '26443'); // Define your targeted postcodes in the array
$postcode = ''; // Initializing
if ( isset($_POST['shipping_postcode']) && ! empty($_POST['shipping_postcode']) ) {
$postcode = $_POST['shipping_postcode'];
if ( empty($postcode) && isset($_POST['billing_postcode']) && ! empty($_POST['billing_postcode']) ) {
$postcode = $_POST['billing_postcode'];
}
} elseif ( $postcode = WC()->customer->get_shipping_postcode() ) {
if ( empty($postcode) ) {
$postcode = WC()->customer->get_billing_postcode();
}
}
if ( WC()->cart->total < $minimum && ! empty($postcode) && in_array( $postcode, $postcodes ) ) {
$error_notice = sprintf( 'Η παραγγελία σου είναι %s - Ελάχιστη Παραγγελία %s ' ,
wc_price( WC()->cart->total ),
wc_price( $minimum )
);
if( is_cart() ) {
wc_print_notice( $error_notice, 'error' );
} else {
wc_add_notice( $error_notice, 'error' );
}
}
}

Related

Find time name between two dates

Is there any function that will give me the name of passed time with two dates in mysql? for example, after i've wrote a post then the page redirects me to the post page it must say " posted 4 seconds before", and afte five minutes later it will say posted 5 minutes before". If the time bigger than 60 minutes it will say xx hours before ...
15 days later it must say 2 weeks ago.
Something like wordpress meta info.
Same as time on my nick name at to right bottom of this post
I suggest you to write this on scripting side. If you are using PHP you can use the following code block to convert unixtime to relative phrase.
function relative_date($date)
{
$diff = time() - $date;
if ($diff < 0) {
return "just now";
} else {
$app = "ago";
}
$t_diff = $diff;
$days = floor($diff / 3600 / 24);
$diff = $diff - ( $days * 3600 * 24 );
$hours = floor($diff / 3600);
$diff = $diff - ( $hours * 3600 );
$minutes = floor($diff / 60);
$diff = $diff - ( $minutes * 60 );
$seconds = $diff;
if ($t_diff > 60 * 60 * 24) {
$str = ( $days . ' days' );
} else if ($t_diff > 60) {
$str = ( $hours ? "{$hours} hours" : "" ) . ( $minutes ? " $minutes minutes" : "" );
} else {
$str = ( $seconds ) . " seconds";
}
$str = $str . " $app";
return $str;
}
This is what I want
function formatDateDiff($start, $end=null) {
if(!($start instanceof DateTime)) {
$start = new DateTime($start);
}
if($end === null) {
$end = new DateTime();
}
if(!($end instanceof DateTime)) {
$end = new DateTime($start);
}
$interval = $end->diff($start);
$doPlural = function($nb,$str){
if ($nb > 1) {
switch ($str) {
case 'Yıl':
case 'Ay':
case 'Gün':
return $str.'e';
case 'Saat':
case 'Dakika':
case 'Saniye':
return $str.'n';
}
} else
return $str;
}; // adds plurals
$format = array();
if($interval->y !== 0) {
$format[] = "%y ".$doPlural($interval->y, "Yıl");
}
if($interval->m !== 0) {
$format[] = "%m ".$doPlural($interval->m, "Ay");
}
if($interval->d !== 0) {
$format[] = "%d ".$doPlural($interval->d, "Gün");
}
if($interval->h !== 0) {
$format[] = "%h ".$doPlural($interval->h, "Saat");
}
if($interval->i !== 0) {
$format[] = "%i ".$doPlural($interval->i, "Dakika");
}
if($interval->s !== 0) {
$format[] = "%s ".$doPlural($interval->s, "Saniye");
}
if(count($format)==0 || (count($format)==1 && $interval->s !== 0)) {
return "Az Önce";
}
// We use the two biggest parts
if(count($format) > 1) {
$format = array_shift($format).", ".array_shift($format);
} else {
$format = array_pop($format);
}
// Prepend 'since ' or whatever you like
return $interval->format($format);
}
Reference Address: https://www.php.net/manual/en/dateinterval.format.php
Thank you so much for your reply.

Excluding multiple urls in Strpos- why doesn't it work?

I'm trying to exclude several urls from appending a nofollow rule using strpos but it only works with 1 url, I can't get it to exclude all the urls I need to include.
This is the code that I've tried:
add_filter( 'custom_bbpress_nofollow', 'my_custom_bbpress_nofollow', 15, 2 );
function my_custom_bbpress_nofollow( $nofollow, $href ) {
if ( strpos( $href, 'https://www.examplelink1.com' ) === false && strpos( $href, 'https://www.examplelink2.com' ) === false && strpos( $href, 'https://www.examplelink3.com' ) === false && strpos( $href, 'https://examplelink4.to' ) === false) {
$nofollow = '';
}
return $nofollow;
}
I've tried it with == false and !== false as well and those don't seem to work.
This one DOES work, but it only excludes a single domain, I need to be able to exclude 5 in all.
add_filter( 'custom_bbpress_nofollow', 'my_custom_bbpress_nofollow', 15, 2 );
function my_custom_bbpress_nofollow( $nofollow, $href ) {
if ( strpos( $href, 'http://your-domain.here' ) !== false ) {
$nofollow = 'rel="dofollow"';
}
return $nofollow;
}
What is the correct strpos syntax to include multiple urls,
https://www.examplelink1.com AND/OR
https://www.examplelink2.com AND/OR
https://www.examplelink3.com AND/OR
https://www.examplelink4.com
I believe you want to use || (OR) instead of && (AND) in your if statement.
Your $href will never match ALL conditions, so using AND will never return true. With OR you tell it to set $nofollow = '' if ANY of those URLs is found.
add_filter( 'custom_bbpress_nofollow', 'my_custom_bbpress_nofollow', 15, 2 );
function my_custom_bbpress_nofollow( $nofollow, $href ) {
if ( strpos( $href, 'https://www.examplelink1.com' ) === false || strpos( $href, 'https://www.examplelink2.com' ) === false || strpos( $href, 'https://www.examplelink3.com' ) === false || strpos( $href, 'https://examplelink4.to' ) === false) {
$nofollow = '';
}
return $nofollow;
}
Edit: Actually, I'm not too sure what you're trying to do. Your 2 examples have opposite code, which is confusing. If you wish to return 'rel="nofollow"' if href equals ANY of the 5 urls, then try this:
add_filter( 'custom_bbpress_nofollow', 'my_custom_bbpress_nofollow', 15, 2 );
function my_custom_bbpress_nofollow( $nofollow, $href ) {
$nofollow = '';
if ( strpos( $href, 'http://your-domain.here' ) !== false ||
strpos( $href, 'https://www.examplelink1.com' ) !== false ||
strpos( $href, 'https://www.examplelink2.com' ) !== false ||
strpos( $href, 'https://www.examplelink3.com' ) !== false ||
strpos( $href, 'https://www.examplelink4.com' ) !== false
) {
$nofollow = 'rel="dofollow"';
}
return $nofollow;
}
You should also define $nofollow at the start of the function, otherwise nothing can be returned if the condition doesn't match.
Sorry, I want it to DOFOLLOW those 5 links and NOFOLLOW everything else.
add_filter( 'custom_bbpress_nofollow', 'my_custom_bbpress_nofollow', 15, 2 );
function my_custom_bbpress_nofollow( $nofollow, $href ) {
$nofollow = '';
if ( strpos( $href, 'https://www.link1.com' )!== false ||
strpos( $href, 'https://www.link2.com' ) !== false ||
strpos( $href, 'https://www.link3.com' ) !== false ||
strpos( $href, 'https://www.link4.com' ) === false
) {
$nofollow = 'rel="nofollow" target="_blank"';
}
return $nofollow;
}

Online KML to Google Spreadsheet Script

Would like to use information into spreadsheets from a live Google Map (KML data). The code below handle it, but not as fast as required. It must handle up to 10 layers with about 2000 placemarks, line positions and/or polygon positions in the interesting (parameter "restrict") layer (or all layers). The size of the kml (xml) data is therefore often quite large.
Question 1: How (if possible) can caching and/or some other solution be implemented to handle about 2Mb xml data?
Question 2: How can what improvements be implemented to stream line the code, add flexibility to dynamically handle unknown (in advance) number of columns/rows and lower the execution time?
/**
* Fetch a Google Map and write the data to the spreadsheet (URL and layer).
*
* #param {url} input the URL associated with the Google Map (should contain &forcekml=1).
* #param {restrict} input the Layer name you want to restrict the data to.
* #return a range of data depending on the info in the map
* #customfunction
*/
function IMPORTMAP( url, restrict ) {
/* One key only allow 100k
var cache = CacheService.getPublicCache();
var cached = cache.get( "google-maps-xml" );
var cached = cache.getAll('?'); //Unknown keys in advance that also may change from time to time.
if ( cached != null ) {
return cached;
}*/
var txt = UrlFetchApp.fetch( url ).getContentText();
var sheet = SpreadsheetApp.getActiveSheet();
var width = sheet.getMaxColumns();
var height = sheet.getMaxRows();
var xmlDoc = XmlService.parse( txt );
var root = xmlDoc.getRootElement();
var atom = XmlService.getNamespace( 'http://www.opengis.net/kml/2.2' );
var xml2csv = [[height],[10]];
var labels = [], label = '', counter = 0, o = 0;
var documents = root.getChildren( 'Document', atom );
for( var i = 0; i < documents.length; i++ ) {
var Folders = documents[i].getChildren( 'Folder', atom );
for( var j = 0; j < Folders.length && j <= height; j++ ) {
if( Folders[j].getChild( 'name', atom ).getValue() == restrict ) {
var Placemarks = Folders[j].getChildren( 'Placemark', atom );
for( var k = 0; k < Placemarks.length; k++ ) {
var nodes = Placemarks[k].getChildren();
for( var l = 0; l < nodes.length; l++ ) {
var data = nodes[l].getChildren();
if( data.length > 0 ) {
for( var m = 0; m < data.length && counter <= width; m++ ) {
if( data[m].getAttribute( 'name' ) != null ) {
if( labels[ data[m].getAttribute( 'name' ).getValue().trim() ] == null ) {
labels[ data[m].getAttribute( 'name' ).getValue().trim() ] = counter;
xml2csv[ 0 ][ counter++ ] = data[m].getAttribute( 'name' ).getValue().trim();
}
}
if( data[m].getChild( 'value', atom ) != null ) {
xml2csv[ k + 1 ][ labels[ data[m].getAttribute( 'name' ).getValue().trim() ] ] = data[m].getChild( 'value', atom ).getValue().trim();
} else {
o = labels[ data[m].getName().trim() ];
if( o == null ) {
labels[ data[m].getName().trim() ] = counter;
o = counter;
xml2csv[ 0 ][ counter++ ] = data[m].getName().trim();
}
if( xml2csv[ k + 1 ] == null ) {
xml2csv[ k + 1 ] = new Array( counter );
}
xml2csv[ k + 1 ][ labels[ data[m].getName().trim() ] ] = data[m].getValue().trim();
}
}
} else {
if( label == '' )
label = nodes[l].getName().trim();
o = labels[ nodes[l].getName().trim() ];
if( o == null ) {
labels[ nodes[l].getName().trim() ] = counter;
o = counter;
xml2csv[ 0 ][ counter++ ] = nodes[l].getName().trim();
}
if( xml2csv[ k + 1 ] == null ) {
xml2csv[ k + 1 ] = new Array( counter );
}
xml2csv[ k + 1 ][ o ] = nodes[l].getValue().trim();
}
}
}
}
}
}
//cache.putAll( xml2csv, 1500 ); // cache for 25 minutes
return xml2csv;
}
Please note that code only handle specific kml data in its current form and may not be suitable for a wider audience.

PHP Notice: Undefined offset: 0

I have error on Wordpress. Help please )
PHP Notice: Undefined offset: 0 in /home/userpro/public_html/wp-content/themes/hoon/inc/tweaks.php on line 602
/**
* Display Future Posts
*
* Display future post in the events category to all users.
*/
function hoon_show_all_future_posts( $posts ) {
global $wp_query, $wpdb;
if ( is_single() && $wp_query->post_count == 0 ) {
$events_cat = hoon_option( 'events_category' );
$request = $wpdb->get_results( $wp_query->request );
// below line 602 //
if ( post_is_in_descendant_category( $events_cat, $request[0]->ID ) || in_category( $events_cat, $request[0]->ID ) ) {
$posts = $request;
}
}
return $posts;
}
add_filter( 'the_posts', 'hoon_show_all_future_posts' );

FPDF performance worse on live server than localhost

I have the following php script below that reads in about 2300 products with images etc from 20 categories using WAMP; the problem is that it take over 3 mins to create a pdf of 213 pages; based on the code is there a way of improving performance. I have already implemented these changes:
In php.ini
Find:
post_max_size = 8M
upload_max_filesize = 2M
max_execution_time = 30
max_input_time = 60
memory_limit = 8M
Change to:
post_max_size = 750M
upload_max_filesize = 750M
max_execution_time = 5000
max_input_time = 5000
memory_limit = 1000M
And add this to C:\wamp\bin\mysql\mysql5.0.45\my.ini:
max_allowed_packet = 200M
this has stopped the outOfMemory exception I was getting & also when I run it on my VPS cloud server with the same settings it can up to over 10 minutes! any help please?(I know it's a big script file)(there is also a business rule of 12 products per page, 4 rows by 3)
<?php
// Database connection information
require ('fpdf/fpdf.php');
class catalogue {
var $pdf;
var $x;
var $y;
var $catName;
var $pageAdded;
var $headerAdded;
var $myFont = "futuram";
var $bgColor;
var $fontColor;
var $headerImage;
var $aTozArray;
var $pageAlreadyAdded;
// Constructor to generate a PDF of the catalogue
function catalogue() {
global $pdf, $y;
define ( 'EURO', chr ( 128 ) );
$pdf = new FPDF ();
$y = 0;
$connect = mysql_connect ( 'localhost', 'xxxxxx', 'xxxxx' );
if (! $connect)
die ( 'Unable to connect to database' );
$select = mysql_select_db ( 'XXXXXXXXXXXX' );
if (! $select)
die ( 'Unable to select database' );
$pdf->SetFillColor ( 255, 255, 255 );
$pdf->SetMargins ( 0, 0, 0 );
$this->addPage ();
$pdf->AddFont ( 'futuram', '', 'futuram.php' );
$pdf->AddFont ( 'futurastdbold', '', 'futurastdbold.php' );
$pdf->AddFont ( 'futurastdboldoblique', '', 'futurastdboldoblique.php' );
$pdf->AddFont ( 'futurastdbook', '', 'futurastdbook.php' );
$pdf->AddFont ( 'futurastdbookoblique', '', 'futurastdbookoblique.php' );
$pdf->AddFont ( 'futurastdcondensed', '', 'futurastdcondensed.php' );
$pdf->AddFont ( 'futurastdcondensedbold', '', 'futurastdcondensedbold.php' );
$pdf->AddFont ( 'futurastdcondensedboldobl', '', 'futurastdcondensedboldobl.php' );
$pdf->AddFont ( 'futurastdcondensedextrabd', '', 'futurastdcondensedextrabd.php' );
$pdf->AddFont ( 'futurastdcondensedlight.php', '', 'futurastdcondensedlight.php' );
$pdf->AddFont ( 'futurastdcondensedlightobl', '', 'futurastdcondensedlightobl.php' );
$pdf->AddFont ( 'futurastdcondensedoblique', '', 'futurastdcondensedoblique.php' );
$pdf->AddFont ( 'futurastdcondensedboldobl', '', 'futurastdcondensedboldobl.php' );
$pdf->AddFont ( 'futurastdcondextraboldobl', '', 'futurastdcondextraboldobl.php' );
$pdf->AddFont ( 'futurastdheavy', '', 'futurastdheavy.php' );
$pdf->AddFont ( 'futurastdheavyoblique', '', 'futurastdheavyoblique.php' );
$pdf->AddFont ( 'futurastdlight', '', 'futurastdlight.php' );
$pdf->AddFont ( 'futurastdlightoblique', '', 'futurastdlightoblique.php' );
$pdf->AddFont ( 'futurastdmedium', '', 'futurastdmedium.php' );
$pdf->AddFont ( 'futurastdmediumoblique', '', 'futurastdmediumoblique.php' );
/*
$pdf->AddFont ( 'Georgia', '', 'georgia.php' );
$pdf->AddFont ( 'Georgia', 'I', 'georgiai.php' );
$pdf->AddFont ( 'Georgia', 'B', 'georgiab.php' );
*/
$pdf->SetAutoPageBreak ( true, 0 );
// add the front pages
$filename = 'http://localhost/images/Welcome_page_pic_fin-01.jpg';
$pdf->Image ( $filename, 0, 0, 210, 297 );
$this->addPage ();
$this->getParent ();
$pdf->Output ();
// actually outputs the PDF. Can be automatically output to a file on
// the server.
}
// Get parent categories
function getParent() {
global $pdf, $x, $y, $page, $catName, $bgColor, $fontColor, $headerImage, $pageAlreadyAdded;
$query = "SELECT * FROM categories";
// This query returns all categories, but not sub categories
$result = mysql_query ( $query );
$numrows = mysql_num_rows ( $result );
// For each category...
for($i = 0; $i < $numrows; $i ++) {
$pdf->SetFont ( 'futuram', '', 40 );
if ($page == 2) {
$x = 15;
$y = 20;
$pdf->setX ( $x );
$pdf->setY ( $y );
// setY defines the y coordinate
$page ++;
// adds a page
} else {
//$this->addPage ();
}
$array = mysql_fetch_array ( $result );
// puts the actual category names into an $array
$id = $array ['category_id'];
$catName = $array ['category_name'];
$image = $array ['category_icon'];
$sql = "SELECT category_colour1, category_colour2, category_icon FROM categories WHERE category_id=$id";
$coloursResult = mysql_query ( $sql );
$coloursArray = mysql_fetch_array ( $coloursResult );
$fontColor = $coloursArray ['category_colour1'];
$bgColor = $coloursArray ['category_colour2'];
$leaderImage = $coloursArray ['category_icon'];
$pdf->setX ( 18.5 );
// setX defines the x coordinate
$pdf->SetFillColor ( 255, 255, 255 );
$pdf->setTextColor ( 0, 71, 53 );
// $pdf->Cell ( 15, 20, $catName );
if (#GetImageSize ( $image )) {
//$filename = $leaderImage;
// add in for test
$filename = $image;
} else {
$filename = 'http://localhost/images/blank.jpg';
}
$pdf->Image ( $filename, 0, 0, 210, 297 );
// creates a cell in the page. Notes:
// http://www.fpdf.org/en/doc/cell.htm
// If automatic page breaking is enabled and the cell goes beyond
// the limit, a page break is done BEFORE outputting.
$this->addPage ();
$filename = 'http://localhost/images/blank.jpg';
$this->getChildren ( $id, $catName);
// calls the getChildren() function to gather the sub categories of
// the given category being used
}
}
// Get children
function getChildren($parent, $catName) {
global $pdf, $y;
$query = "SELECT * FROM shop_categories where parent_id = $parent ORDER BY category_id";
$result = mysql_query ( $query );
$numrows = mysql_num_rows ( $result );
// $array = mysql_fetch_array($result);
// fix the case with $numrows = 0
$catList = array ();
while ( $array = mysql_fetch_array ( $result ) ) {
array_push ( $catList, array (
$array ['name'],
$array ['category_id']
) );
}
$this->getProducts ( $catList,$catName );
}
// Get products in categories
function getProducts($catList,$catName) {
global $pdf;
$prodList = array ();
$numSubCategories = count ( $catList );
for($i = 0; $i < $numSubCategories; $i ++) {
$catid = $catList [$i] [1];
$query = "SELECT product_id,ProductName, WeightQuantity, PriceUnit, Euro, Pound, Code, Image FROM products where category_id = $catid order by product_id asc";
$result = mysql_query ( $query );
$numResults = mysql_num_rows($result);
if($numResults > 0) {
array_push ( $prodList, $result );
}
}
// If category is a parent send it back to getChildren
if (count ( $prodList ) != 0) {
$this->processPage ( $catList, $prodList,$catName );
}
}
function processPage($catList, $prodList, $catName) {
global $pdf, $catName, $page, $pageAdded, $myFont, $fontColor, $pageAlreadyAdded;
$pdf->SetFillColor ( 255, 255, 255 );
$itemsPerRow = 3;
$rowsPerPage = 4;
$currentRow = 0;
$numItems = 0;
$totalRows = 0;
$numberRowsUsed = 0;
for($i = 0; $i < count ( $prodList ); $i ++) {
$items = mysql_num_rows ( $prodList [$i] );
$totalRows += ceil ( $items / $itemsPerRow );
}
// changed this from $prodList[i] to $prodList
for($i = 0; $i < count ( $prodList ); $i ++) {
$subCatHeadName = $catList [$i] [0];
if ($i > 0) {
$numberOfitems = mysql_num_rows ( $prodList [$i - 1] );
$numberRowsUsed += ( int ) ceil ( $numberOfitems / $itemsPerRow );
}
$pdf->SetFont ( 'futuram', '', 28 );
$fonts = explode ( ",", $fontColor );
$pdf->SetTextColor ( 122, 114, 102 ); // grey
$p = 0;
$q = 0;
$pdf->SetX ( 0 );
$pdf->SetY ( 10 );
$pdf->SetLeftMargin ( 0 );
$pdf->SetRightMargin ( 0 );
$pdf->cMargin = 100;
$p1 = 0;
$q1 = 0;
$pdf->SetX ( 0 );
$numItems = mysql_num_rows ( $prodList [$i] ); // 5
$numRows = ceil ( $numItems / $itemsPerRow ); // 2
$remItems = $numItems % $itemsPerRow; // 2
if ($numItems > 0) {
for($j = 0; $j < $numRows; $j ++) {
$this->processRow ( $itemsPerRow, $prodList [$i], $j, $currentRow,$subCatHeadName,$catName );
$currentRow ++;
if ($currentRow % $rowsPerPage == 0) {
$this->addPage ();
$pageAlreadyAdded = true;
}
}
}
}
}
function processRow($numItems, $result, $rowNum, $currentRow,$subCatHeadName,$catName) {
global $pdf;
$pdf->SetX ( 0 );
$pdf->SetY ( 20 );
$this->header ();
$this->footer ();
if ($numItems > 0) {
for($i = 0; $i < $numItems; $i ++) {
$this->processItem ( $result, $rowNum, $i, $currentRow,$subCatHeadName,$catName );
}
}
}
function processItem($result, $rowNum, $itemNum, $currentRow,$subCatHeadName, $catName) {
global $pdf, $x, $y;
$p1 = 0;
$q1 = 0;
$pdf->SetX ( 0 );
$pdf->SetY ( $q1 + 10 );
$pdf->SetFont ( 'futurastdmedium', '', 40 );
$pdf->Cell ( 200, 16, $catName, 0, 5, 'C', true );
$pdf->SetX ( 0 );
$pdf->SetY ( $q1 + 25 );
$pdf->SetFont ( 'futurastdmedium', '', 10 );
$pdf->Cell ( 200, 8, $subCatHeadName, 0, 10, 'C', true );
$a = 18.5;
$b = 0;
if ($currentRow % 4 == 0) {
$rowNum = 0;
} else if ($currentRow % 4 == 1) {
$rowNum = 1;
} else if ($currentRow % 4 == 2) {
$rowNum = 2;
} else if ($currentRow % 4 == 3) {
$rowNum = 3;
}
$pdf->SetX ( $a );
$pdf->SetY ( $b );
$marginX = 0;
$marginY = 30;
$pdf->SetFont ( 'futuram', '', 6 );
$array = mysql_fetch_array ( $result );
$id = $array ['product_id'];
$name = $array ['ProductName'];
$price = $array ['PriceUnit'];
$UKprice = $array ['Pound'];
$Europrice = $array ['Euro'];
$code = $array ['Code'];
$weight = $array ['WeightQuantity'];
$deltaX = 62.5;
$deltaY = 64;
$a = $marginX + ($itemNum * $deltaX);
$b = $marginY + ($rowNum * $deltaY);
$image = $array ['Image'];
$imageName = ltrim ($image,':');
if( $imageName == "" || $imageName == null) {
$imageName = 'blank.jpg';
}
$filename = 'http://localhost/images/'.$imageName;
// check if the image exists on the server; replaces it with a
// placeholder otherwise
if (#GetImageSize ( 'http://localhost/images/'.$imageName )) {
$filename = 'http://localhost/images/'.$imageName;
} else {
$filename = 'http://localhost/images/blank.jpg';
}
if ($name != null) {
$pdf->Image ( $filename, $a + 20, ($b), 55, 25 );
}
$pdf->setY ( $b + 30 );
$pdf->setX ( $a + 5 ); // price is placed where coordinate x=150
$pdf->setTextColor ( 122, 114, 102 );
$pdf->SetFont ( 'futurastdheavy', '', 8.5 );
$line1 = "";
$line2 = "";
if ($name != null) {
if (strlen ( trim ( $name ) ) > 30) {
$name = substr ( $name, 0, 30 );
$pdf->setX ( $a + 35 );
$pdf->Cell ( 10, 10, trim ( $name ), 0, 0, 'C' );
} else {
$pdf->setX ( $a + 35 );
$pdf->Cell ( 10, 10, trim ( $name ), 0, 0, 'C' );
}
}
$pdf->setY ( $b + 33 );
$pdf->setX ( $a + 35 ); // price is placed where coordinate x=150
//$pdf->setTextColor ( 0, 0, 0, 0 );
$pdf->SetFont ( 'futurastdlightoblique', '', 7 );
if ($name != null) {
$pdf->Cell ( 10, 10, 'Weight/Quantity '.$weight." ".$price, 0, 0, 'C' );
}
$pdf->setY ( $b + 36 );
$pdf->setX ( $a + 35 ); // price is placed where coordinate x=150
//$pdf->setTextColor ( 0, 0, 0, 0 );
$pdf->SetFont ( 'futurastdlightoblique', '', 7 );
if ($name != null) {
$pdf->Cell ( 10, 10, 'Price Unit <Euro> <Pound>', 0, 0, 'C' );
}
$pdf->setY ( $b + 39 );
$pdf->setX ( $a + 35 ); // price is placed where coordinate x=150
// $pdf->setTextColor ( 0, 0, 0, 0 );
$pdf->SetFont ( 'futurastdbook', '', 7 );
$UKprice = utf8_decode("£" . number_format($UKprice, 2));
$Europrice = utf8_decode("EUR" . number_format($Europrice, 2));
if ($name != null) {
// $this->cell(10,10,iconv("UTF-8", "ISO-8859-1", "£"). $money,0);
$pdf->Cell ( 10, 10, "PRICE: ".$Europrice ." ".$UKprice, 0, 0, 'C' );
}
$pdf->setY ( $b + 42 );
$pdf->setX ( $a + 35 ); // price is placed where coordinate x=150
//$pdf->setTextColor ( 0, 0, 0, 0 );
$pdf->SetFont ( 'futurastdbold', '', 8.5 );
if ($code != null) {
$pdf->Cell ( 10, 10, "CODE: ".trim($code), 0, 0, 'C' ); // the product code
// goes
// here, in
}
//$pdf->setTextColor ( 0, 0, 0, 0 );
$pdf->SetFont ( 'futurastdbold', '', 8.5 );
// $y += 10; //move the y location down 10 (pixels...?)
$pdf->setXY ( $a, $b + 32.5 ); // place the 'cursor' at these coordinates
$pdf->SetLeftMargin ( 0 );
$pdf->SetRightMargin ( 0 );
$pdf->setY ( 0 );
$pdf->setX ( 0 ); // price is placed where coordinate x=150
}
// Function to add a page to the PDF
function addPage() {
global $pdf, $page, $y, $pageAdded;
$pdf->AddPage ();
// NOTE: this could have been $pdf->AddPage(P, A4) where P=portrait and
// A4 is page size.
// See http://www.fpdf.org/en/doc/addpage.htm
$pdf->Rect ( 0, 0, 250, 350, 'F' ); // The 'F' here means 'filled'. could
// also be
// 'D' for drawn border-only or DF for
// drawn and
// filled
$y = 5;
$pdf->setY ( $y );
$page ++;
$pageAdded = true;
}
function header() {
global $pdf, $catName, $pageAdded, $headerAdded, $myFont, $fontColor, $bgColor, $headerImage;
if ($pageAdded == true) {
$pdf->SetLeftMargin ( 68.5 );
$pdf->SetRightMargin ( 0 );
$pdf->SetFont ( 'futuram', '', 10 );
$pdf->SetX ( 0 );
$pdf->SetY ( 0 );
$pdf->SetFillColor ( 255, 0, 0 ); // grey
$pdf->Cell ( 77, 3, '', 0, 5, 'C', true );
$pdf->SetLeftMargin ( 0 );
$pdf->SetRightMargin ( 0 );
$title = $catName;
$image = $headerImage;
$pdf->SetFont ( 'futuram', '', 40 );
$pdf->SetX ( 0 );
$pdf->SetY ( 3 );
$fonts = explode ( ",", $fontColor );
$bg = explode ( ",", $bgColor );
$pdf->SetFillColor ( 255, 255, 255 ); // pure white
$pdf->SetLineWidth ( 1 );
$pdf->cMargin = 15;
$pdf->Ln ( 10 );
$headerAdded = true;
}
$pageAdded = false;
$pdf->SetFont ( 'futuram', '', 14 );
$pdf->SetFillColor ( 255, 255, 255 ); // white
}
function footer() {
global $pdf, $headerAdded, $myFont, $fontColor, $bgColor;
if ($headerAdded == true) {
$pdf->SetLeftMargin ( 0 );
$pdf->SetRightMargin ( 0 );
$pdf->SetFont ( 'futurastdlight', '', 9 );
$pdf->SetX ( 0 );
$pdf->SetY ( - 18 );
$fonts = explode ( ",", $fontColor );
$bg = explode ( ",", $bgColor );
$pdf->SetFillColor ( 255, 255, 255 ); // grey
$pdf->SetTextColor ( 122,114,102 ); // whitesmoke
// $pdf->Cell ( 0, 3, 'PRICES SUBJECT TO FLUCTUATION', 0, 1, 'C', true );
$pdf->SetX ( 18.5 );
$pdf->SetLeftMargin ( 0 );
$pdf->SetRightMargin ( 0 );
$pdf->SetX ( 4 );
$pdf->SetY ( -0.05 );
$pdf->SetFillColor ( 255, 0, 0 ); // grey
$pdf->Cell ( 28, -4, $pdf->PageNo (), 0, 0, 'C', true );
$pdf->SetFillColor ( 255, 255, 255 ); // grey
$pdf->SetLeftMargin ( 68.5 );
$pdf->SetRightMargin ( 0 );
$pdf->SetX ( 50 );
$pdf->SetY ( - 3 );
$pdf->SetFillColor ( 255, 0, 0 ); // grey
$pdf->Cell ( 77, 3, '', 0, 5, 'C', true );
$pdf->SetFillColor ( 255, 255, 255 ); // grey
$pdf->SetLeftMargin ( 184 );
$pdf->SetRightMargin ( 0 );
$pdf->SetX ( 4 );
$pdf->SetY ( -0.05 );
$pdf->SetFillColor ( 255, 0, 0 ); // grey
$pdf->Cell ( 28, -4, $pdf->PageNo (), 0, 0, 'C', true );
$pdf->SetFillColor ( 255, 255, 255 ); // grey
}
$headerAdded = false;
$pdf->SetFont ( $myFont, '', 14 );
$pdf->SetFillColor ( 255, 255, 255 );
}
}
$catalogue = new catalogue ();
?>