MySQL Forums
Forum List  »  PHP

Re: Migrating IIS, PHP, and MySQL connection from XP to Windows 7 issue
Posted by: Brandon Hofmann
Date: May 08, 2015 07:50AM

Thank you very much for the quick response, hoping you could give me just a little more guidance. Where should I make the changes to the script? I'm assuming you mean to the index.php page (as that is what I'm trying to load), is that accurate?

Below is the contents of that file, in case I'm not as clear as I should be. Thank you again!

<?php
global $debug;
$debug=0;

header("Cache-Control: no-store, no-cache");
set_time_limit(0);

//dl("php_mysql.dll");
$magic_quotes = ini_get('magic_quotes_gpc');

include_once ('includes/db.inc.php');
include_once ('includes/web.inc.php');
include_once ('includes/vars.inc.php');

error_reporting(E_ALL);
$db = new db();


//****************************************
// build the data for the form
//****************************************

$sql = "select * from printer";
$printers = $db->fetchObjectsAsArray($sql);
$printers_select = build_html_select($printers['printer_name'], $printers['printer_desc'], "-1", "--",-1);

$sql = "select * from prefix where prefix_type='I'";
$int_prefixes = $db->fetchObjectsAsArray($sql);
$int_prefixes_select = build_html_select($int_prefixes['prefix_name'], $int_prefixes['prefix_name'], "-1", "--",-1);

$sql = "select * from prefix where prefix_type='E'";
$ext_prefixes = $db->fetchObjectsAsArray($sql);
$ext_prefixes_select = build_html_select($ext_prefixes['prefix_name'], $ext_prefixes['prefix_name'], "-1", "--",-1);

$sql = "select * from label_format";
$label_formats = $db->fetchObjectsAsArray($sql);
$label_formats_select = build_html_select($label_formats['label_format_ZPL'], $label_formats['label_format_name'], "-1", "--",-1);

$yr = date("y");
$yr_minus= date("y", mktime(0,0,0,date("n"), date("j"), date("Y")-1));
$yr_plus = date("y", mktime(0,0,0,date("n"), date("j"), date("Y")+1));
$years = "<option value=$yr_minus>$yr_minus</option><option selected value=$yr>$yr</option><option value=$yr_plus>$yr_plus</option>";

//****************************************
// display the form
//****************************************

$main_template = file_get_contents('templates/main.txt');
$display = str_replace(array("::YEARS::", "::PRINTERS::", "::PREFIX1::","::PREFIX2::","::LABELFORMAT::"), array($years,$printers_select,$int_prefixes_select,$ext_prefixes_select,$label_formats_select), $main_template);
echo $display;

//****************************************
// get form variables
//****************************************

if ($magic_quotes){
$printer = str_replace("\\\\", "\\", $_REQUEST['printer']);
$prefix1 = $_REQUEST['prefix1'];
$prefix2 = $_REQUEST['prefix2'];
$start1 = $_REQUEST['start1'];
$start2 = $_REQUEST['start2'];
$zpl = $_REQUEST['label_format'];
$qty = $_REQUEST['quantity'];
$yr = $_REQUEST['year'];
$idtext = $_REQUEST['idtext'];
}
else{
$printer = $_REQUEST['printer'];
$prefix1 = $db->escape($_REQUEST['prefix1']);
$prefix2 = $db->escape($_REQUEST['prefix2']);
$start1 = $db->escape($_REQUEST['start1']);
$start2 = $db->escape($_REQUEST['start2']);
$zpl = $_REQUEST['label_format'];
$qty = $db->escape($_REQUEST['quantity']);
$yr = $db->escape($_REQUEST['year']);
$idtext = $db->escape($_REQUEST['idtext']);
}

//****************************************
// if they manually printed labels
//****************************************

if ($_REQUEST['manprintme']){
if (is_numeric($start1) && (is_numeric($start2) || $start2=="") ){
//****************************************
// generate each new accesion #
//****************************************
$max1 = $start1-1;
$max2 = $start2-1;
print_labels($qty, $max1, $max2, $prefix1, $prefix2, $yr, $idtext, $zpl, $printer, $db);
}else{
echo "<b>Printer, Internal Prefix, Quantity, Start Values and Label Format must be valid. Please try again.";
exit;
}
}

//****************************************
// if they auto-printed labels.
//****************************************

if ($_REQUEST['printme']){
//****************************************
// check that the form data is valid
//****************************************
if ($printer!=-1 && $prefix1!=-1 && is_numeric($qty) && $zpl!=-1){

//****************************************
// get the maximum accesion number values
//****************************************

$sql = "select max(label_number) m from label where label_prefix='$prefix1' and label_year='$yr'";
$q1 = $db->fetch($sql,true);
if ($debug) echo "Max1 SQL: $sql<br>";
$max1 = $q1['m'];
if ($max1<=0) $max1=0;

if ($prefix2 != -1){
$sql = "select max(label_number) m from label where label_prefix='$prefix2' and label_year='$yr'";
if ($debug) echo "Max2 SQL: $sql<br>";
$q2 = $db->fetch($sql,true);
$max2 = $q2['m'];
if ($max2<=0 || $max2=="") $max2=0;
}
if ($debug) echo "Max1: |$max1| Max2: |$max2|<br>";


//****************************************
// generate each new accesion #
//****************************************
print_labels($qty, $max1, $max2, $prefix1, $prefix2, $yr, $idtext, $zpl, $printer, $db);

//****************************************
// exit if the form data was invalid
//****************************************

}else{
echo "<b>Printer, Internal Prefix, Quantity and Label Format must be valid. Please try again.";
exit;
}
}

function print_label($acc1, $acc2, $idtext, $zpl, $printer){
$idtext = stripslashes($idtext);
$zpl1 =str_replace(array("::NUMBER1::", "::NUMBER2::", "::IDTEXT::"), array($acc1, $acc2, $idtext), $zpl);
$tmpfile = tempnam("", "zpl");
file_put_contents($tmpfile, $zpl1);


$cmd = "copy \"$tmpfile\" \"$printer\"";
$result = exec($cmd);
unlink($tmpfile);
return $result;
}

function print_labels($qty, $max1, $max2, $prefix1, $prefix2, $yr,$idtext, $zpl,$printer, $db){
global $debug;

for ($i=1; $i<=$qty; $i++){
$n1 = $max1+$i;
$acc1 = "$prefix1$yr-$n1";
if ($prefix2 != -1){
$n2 = $max2+$i;
$acc2 = "$prefix2$yr-$n2";

$sql = "insert into label set label_prefix='$prefix2', label_number=$n2, label_year='$yr', idtext='$idtext'";
if (!$debug) $db->query($sql);
else echo "Skipping: $sql<br>";

$sql = "insert into label set label_prefix='$prefix1', label_number=$n1, label_year='$yr', label_external_number='$acc2', idtext='$idtext'";
if (!$debug) $db->query($sql);
else echo "Skipping: $sql<br>";

}else{
$sql = "insert into label set label_prefix='$prefix1', label_number=$n1, label_year='$yr', idtext='$idtext'";
if (!$debug) $db->query($sql);
else echo "Skipping: $sql<br>";
}
print_label($acc1, $acc2, $idtext, $zpl, $printer);
}
}

?>

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.