HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: /var/www/html/breadsecret.com/print-label.php
<head>
<style>
	body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        font: 12pt "Tahoma";
    }
    * {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
    }
    .page {
        width: 210mm;
        min-height: 297mm;
        /* padding: 8mm 4mm 7mm 4mm; */
         padding: 7mm 4mm 2mm 4mm; 
        margin: 10mm auto;
		border: 1px solid lightgrey;
    }
    .subpage {
        /*
		padding: 1cm;
        border: 1px lightgrey solid;
        height: 257mm;
        outline: 2cm #FFEAEA solid;
		*/
    }
	.label {
		display: inline-block;
		width: 65mm;
		height: 40mm;
		border: 1px solid white;	
		padding: 10px;
		margin: 0px 2px -2px 2px;	
		font-size: 9px;	
	}
	.label .title {
		font-size: 12px;
		line-height: 13px;
	}

	.label .ingredients {
		font-size: 7px;	
		text-align: justify;		
	}
	
	.label .factory_info {
		font-size: 7px;	
		text-align: justify;		
	}	
	
	.label .production_desc {
		font-size: 7px;	
		text-align: justify;		
	}	
		
	.label .expiry_date {
		font-size: 9px;	
	}	
	
	.label .address {
		font-size: 7px;	
		text-align: justify;
	}	
	
	.label .instruction {
		font-size: 7px;	
		text-align: justify;
	}		
    
    @page {
        size: A4;
        margin: 0;
    }
    @media print {
        html, body {
            width: 210mm;
            height: 297mm;        
        }
        .page {
            margin: 0;
            border: initial;
            border-radius: initial;
            width: initial;
            min-height: initial;
            box-shadow: initial;
            background: initial;
            page-break-after: always;
        }
    }
</style>
</head>
<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

include '/var/www/html/breadsecret.com/wp-load.php';
// set timezone
date_default_timezone_set("Asia/Hong_Kong");
global $wpdb, $current_site, $sitepress;

if($_GET['hash']!=md5("22785700")){
	echo "You are not authorized to use this page";
	exit();
}

	$arr_label = array();
	$count = 0;
	
	$company_name = $_POST['company_name'];
	$company_address = $_POST['company_address'];
	$label_instruction = $_POST['label_instruction'];
	//$date = $_POST['date'];
	$init_label_no = $_POST['init_label_no'];
	
	$arr_empty_sku = array("id"=>"", "sku"=>"", "stock_sku"=>"", "ingredient"=>"", "name"=>"", "name_zh"=>"", "date"=>"");

	for($no=1; $no<$init_label_no; $no++){
		array_push($arr_label, $arr_empty_sku);
		$count++;
	}


	foreach($_POST['sku'] as $productID){	

		$qty = $_POST['qty_'.$productID];
		$date = $_POST['date_'.$productID];
		
		if($qty!="" && $qty!=0){
			if($productID==0){

				$arr_sku = array();
				$arr_sku['id']=$productID;
				$arr_sku['sku']="";
				$arr_sku['stock_sku']="";			
				$arr_sku['ingredient']=$_POST['ingredient_'.$productID];
				$arr_sku['name']=$_POST['nameEN_'.$productID];
				$arr_sku['name_zh']=$_POST['nameHK_'.$productID];
				$arr_sku['expiry_date']=$date;
				for($n=1; $n<=$qty; $n++) {
					array_push(	$arr_label, $arr_sku);
					$count++;
				}				

			} else {
				$product = wc_get_product($productID);
				$sku = $product->get_sku();
				$stock_sku = get_master_sku($sku);
				$init_info = get_sku_init_info($stock_sku);

				$trid = $sitepress->get_element_trid($productID, 'post_product');				
				$translations = $sitepress->get_element_translations($trid, 'product');
				foreach( $translations as $lang=>$translation){
					if($translation->language_code == "zh-hant")
						$zh_post_id = $translation->element_id;
				}			
				
				$arr_sku = array();
				$arr_sku['id']=$productID;
				$arr_sku['sku']=$sku;
				$arr_sku['stock_sku']=$stock_sku;			
				$arr_sku['ingredient']=$init_info->ingredient;
				$arr_sku['name']=$product->get_title();
				$arr_sku['name_zh']=get_the_title($zh_post_id);
				$arr_sku['expiry_date']=$date;
				for($n=1; $n<=$qty; $n++) {
					array_push(	$arr_label, $arr_sku);
					$count++;
				}

			}
			
		}
	}
	

	
	$count_per_page = 21;
	//$count = 40; 
	$page = ceil($count/$count_per_page);
	$remaining = $count%$count_per_page;
	
?>
<div class="book">

	<?php for($p=1; $p<=$page; $p++){ ?>
    <div class="page"> 
        <div class="subpage">
        <?php $start = $count_per_page*($p-1)+1; ?>
        <?php
			if($p==$page){
				if($remaining==0){
					$end = $start + $count_per_page - 1;
				}else{
					$end = $start + $remaining - 1;
				}
			} else {
				$end = $start + $count_per_page - 1;
			}
			
		 //echo $end = $start + ($p==$page?$remaining:$count_per_page)-1; 
		?>        
        <?php for ($i=$start; $i<=$end; $i++) { ; ?>
            <div class="label">
            	<?php if($arr_label[$i-1]['name']!="") { ?>
                <table height="100%" cellpadding="0" cellspacing="0">
                	<tr>
                    	<th colspan="2"><div class="title"><?php echo $arr_label[$i-1]['name'];?><br /><?php echo $arr_label[$i-1]['name_zh'];?></div></th>
                    </tr>
                	<tr>
                    	<td colspan="2"><div class="ingredients">Ingredients: <?php echo $arr_label[$i-1]['ingredient'];?></div></td>
                    </tr> 
                	<tr>
                    	<td colspan="2"><div class="production_desc">Produced in a factory where nuts, gluten, eggs, soyabeans and milk are handled.</div></td>
                    </tr>  
                	<tr>
                        <td style="width: 36mm;"><div class="factory_info">Manufactured by <?php echo $company_name;?><div class="address"><?php echo str_replace("\r\n","<br>",$company_address);?></div></td>
                        <td><div class="expiry_date">Use By <?php echo empty($arr_label[$i-1]['expiry_date'])?"":date("d M Y", strtotime($arr_label[$i-1]['expiry_date']));?></div></td>
                    </tr>                       
                	<tr>
                    	<td colspan="2"><div class="instruction"><?php echo $label_instruction;?></div></td>
                    </tr>                                                                                 
                </table>
                <?php } ?>
            </div>
        <?php } ?>
        </div>    
    </div>
    <?php } ?>
    
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script>
	 $(".page").css("padding","<?php echo $_POST['page_top_padding'];?>mm <?php echo $_POST['page_right_padding'];?>mm <?php echo $_POST['page_bottom_padding'];?>mm <?php echo $_POST['page_left_padding'];?>mm");
	 $(".label").css("padding","<?php echo $_POST['label_top_padding'];?>mm <?php echo $_POST['label_right_padding'];?>mm <?php echo $_POST['label_bottom_padding'];?>mm <?php echo $_POST['label_left_padding'];?>mm");
	 window.print();
</script>