<?php include "../../includes/start_ajax.php";?>
<?php include "config_form.php"; ?>

<?php

$print_url="mod/product/print.php";



//------------------data display----------------------
echo "<div class='data_display_content'>";	
	
	
$query_display="SELECT * FROM $form_table_name ";
$query_display=$query_display." WHERE $form_key_id = '".$_REQUEST[$form_key_id]."';";
$result_display=mysqli_query($dbconn,$query_display)or die("Get Data failed- Err msg  ". mysqli_error($dbconn));
			
if($line_display=mysqli_fetch_array($result_display,MYSQLI_ASSOC))
{
	
	
	if($_REQUEST["quantity"]=="")
	{
		$_REQUEST["quantity"]=1;
	}
	  	
	echo "<div class='data_display_separator' >";
		echo "<font size=3><b>Product Info</b></font>";
	echo "</div>";
	
	
	echo "<div class='data_display_row'>";
		echo "<div class='data_display_label'>";
			echo "Product Code";
		echo "</div>";
	
		echo "<div class='data_display_value'>";
			echo $line_display["pdt_code"]."";
		echo "</div>";
	echo "</div>";
	
	
	echo "<div class='data_display_row'>";
		echo "<div class='data_display_label'>";
			echo "Product Name";
		echo "</div>";
	
		echo "<div class='data_display_value'>";
			echo $line_display["pdt_name"]."";
		echo "</div>";
	echo "</div>";
	
	echo "<div class='data_display_row'>";
		echo "<div class='data_display_label'>";
			echo "Barcode";
		echo "</div>";
	
		echo "<div class='data_display_value'>";
			echo $line_display["pdt_barcode"]."";
		echo "</div>";
	echo "</div>";
		
		
	echo "<div class='data_display_row'>";
		echo "<div class='data_display_label'>";
			echo "Price (Standard)";
		echo "</div>";
	
		echo "<div class='data_display_value'>";
			echo $line_display["pdt_price"]."";
		echo "</div>";
	echo "</div>";
		
	//==================================================================================
		
	echo "<div class='data_display_separator' >";
		echo "<font size=3><b>Barcode Printing</b></font>";
	echo "</div>";
	
	
	
	echo "<div class='data_display_row'>";
		echo "<div class='data_display_label'>";
			echo "Print Path";
		echo "</div>";
	
		echo "<div class='data_display_value'>";
				echo $sys_barcode_printer_path;
		echo "</div>";
	echo "</div>";
	
	
	
	
	echo "<div class='data_display_row'>";
		echo "<div class='data_display_label'>";
			echo "Quantity";
		echo "</div>";
	
		echo "<div class='data_display_value'>";
				echo "<input type=text class='textbox textbox-s' name='barcode_print_quantity' id='id_barcode_print_quantity' value='".$_REQUEST["quantity"]."' >";
		echo "</div>";
	echo "</div>";
	
	
	echo "<div class='data_display_row'>";
		echo "<div class='data_display_label'>";
			echo "<br>";
		echo "</div>";
	
		echo "<div class='data_display_value'>";
			//action button
			echo "<div class='fa-stack fa-lg'  style='cursor:pointer;' onclick=\"if(confirm('Print '+document.getElementById('id_barcode_print_quantity').value+' copy(ies) ?')){mon_send_get('$print_url','?$form_key_id=".$line_display[$form_key_id]."&user_action=PRINT&quantity='+document.getElementById('id_barcode_print_quantity').value,'div_display')}\" >";
				echo '<i class="fa fa-square fa-stack-2x color_green"  ></i><i class="fa fa-print fa-stack-1x color_white" ></i>';
			echo "</div>";
			
		echo "</div>";
	echo "</div>";
	
	
	
	if($_REQUEST["user_action"]=="PRINT")
	{
		
		echo "<div class='data_display_row'>";
			echo "<div class='data_display_label'>";
				echo "Printing Status";
			echo "</div>";
		
			echo "<div class='data_display_value'>";
			
			
				//1: get print format:
				$filename_format = "../../barcode_format/default.prn"; 
				$handle_format = fopen($filename_format, "r"); 
				$fsize_format = filesize($filename_format); 
				$contents_format = fread($handle_format, $fsize_format); 	
				
				//2: parse parameter:
				$print_qty=$_REQUEST["quantity"];
				
				$contents_format = str_replace("@pdt_name@",$line_display["pdt_name"],$contents_format);
				$contents_format = str_replace("@pdt_code@",$line_display["pdt_code"],$contents_format);
				$contents_format = str_replace("@pdt_barcode@",$line_display["pdt_barcode"],$contents_format);
				$contents_format = str_replace("@pdt_price@","RM".$line_display["pdt_price"],$contents_format);
				
				
				$contents_format = str_replace("@qty@",$print_qty,$contents_format);
				
				//echo "<textarea cols=80 rows=30 disabled>";
				//echo $contents_format;
				//echo "</textarea>";
				
				
				
				if($sys_barcode_print_mode=="DELEGATE")
				{
					
					//--------------------
					//$hit_url ="http://".$sys_printer_server_ip_address."/print_delegate/print.php?content=".$contents_format;
					$url ="http://".$sys_printer_server_ip_address."/print_delegate/print.php?pdt_name=".$line_display["pdt_name"]."&pdt_code=".$line_display["pdt_code"]."&pdt_barcode=".$line_display["pdt_barcode"]."&pdt_price=RM ".$line_display["pdt_price"]."&qty=".$print_qty."";
					
					
					
					$url=str_replace(" ","%20",$url);
					
					//echo $url;
					
					echo "<iframe src='".$url."' frameborder=0 width=300 height=100 ></iframe>";
					
					
					/*
				    $ch = curl_init($url);  
				    curl_setopt($ch, CURLOPT_TIMEOUT, 3000);  
				    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3000);  
				    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
				    $data = curl_exec($ch);  
				    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);  
				    curl_close($ch);  
				    if($httpcode==200){  
					   $ping_success=true;
				    } else {  
					   $ping_success=false;
				    } 
				    
				    */
				    
				
					//echo $hit_url;
					
					//$lines = file($hit_url);
					
					
					//echo "<br>Result:<br>";
					//echo "<textarea cols=80 rows=30 disabled>";
					//foreach ($lines as $line_num => $line) {
					   //echo "" . htmlspecialchars($line) . "".chr(10);
					//}
					
					//echo "</textarea>";
					
					
					
					
				}
				else {
					
					//from config.php;
					
					$printer = $sys_barcode_printer_path;
					
					$fp = fopen($printer, "w");
					if (!$fp){
					}
					if (!fwrite($fp,$contents_format)){
					}
					fclose($fp);
					
				}
				
				

			
				
				
			echo "</div>";
		echo "</div>";
		
		
		
	}
	

	


					
}	
echo "<div class='data_display_separator' >";
	echo "<br><br><br><br><br><br><br>";
echo "</div>";	
	
echo "</div>";
			

?>




<?php include "../../includes/end_ajax.php";?>