Jump to content

have strings in documents


searls03

Recommended Posts

ok, so with the random code thing.......I am trying to expand my idea a bit...............how could I basically make like a barcode that is associated with the ticket.........this one would need to be stored in database with the event...............just trying to make this so it can't be4 forged too easily............can this be done?

Link to comment
Share on other sites

pretty sure I messed this up for the barcode can you help:

require('fpdf.php');

class PDF_EAN13 extends FPDF
{
function EAN13($x, $y, $barcode, $h=16, $w=.35)
{
    $this->Barcode($x,$y,$barcode,$h,$w,13);
}

function UPC_A($x, $y, $barcode, $h=16, $w=.35)
{
    $this->Barcode($x,$y,$barcode,$h,$w,12);
}

function GetCheckDigit($barcode)
{
    //Compute the check digit
    $sum=0;
    for($i=1;$i<=11;$i+=2)
        $sum+=3*$barcode[$i];
    for($i=0;$i<=10;$i+=2)
        $sum+=$barcode[$i];
    $r=$sum%10;
    if($r>0)
        $r=10-$r;
    return $r;
}

function TestCheckDigit($barcode)
{
    //Test validity of check digit
    $sum=0;
    for($i=1;$i<=11;$i+=2)
        $sum+=3*$barcode[$i];
    for($i=0;$i<=10;$i+=2)
        $sum+=$barcode[$i];
    return ($sum+$barcode[12])%10==0;
}

function Barcode($x, $y, $barcode, $h, $w, $len)
{
    //Padding
    $barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT);
    if($len==12)
        $barcode='0'.$barcode;
    //Add or control the check digit
    if(strlen($barcode)==12)
        $barcode.=$this->GetCheckDigit($barcode);
    elseif(!$this->TestCheckDigit($barcode))
        $this->Error('Incorrect check digit');
    //Convert digits to bars
    $codes=array(
        'A'=>array(
            '0'=>'0001101','1'=>'0011001','2'=>'0010011','3'=>'0111101','4'=>'0100011',
            '5'=>'0110001','6'=>'0101111','7'=>'0111011','8'=>'0110111','9'=>'0001011'),
        'B'=>array(
            '0'=>'0100111','1'=>'0110011','2'=>'0011011','3'=>'0100001','4'=>'0011101',
            '5'=>'0111001','6'=>'0000101','7'=>'0010001','8'=>'0001001','9'=>'0010111'),
        'C'=>array(
            '0'=>'1110010','1'=>'1100110','2'=>'1101100','3'=>'1000010','4'=>'1011100',
            '5'=>'1001110','6'=>'1010000','7'=>'1000100','8'=>'1001000','9'=>'1110100')
        );
    $parities=array(
        '0'=>array('A','A','A','A','A','A'),
        '1'=>array('A','A','B','A','B','B'),
        '2'=>array('A','A','B','B','A','B'),
        '3'=>array('A','A','B','B','B','A'),
        '4'=>array('A','B','A','A','B','B'),
        '5'=>array('A','B','B','A','A','B'),
        '6'=>array('A','B','B','B','A','A'),
        '7'=>array('A','B','A','B','A','B'),
        '8'=>array('A','B','A','B','B','A'),
        '9'=>array('A','B','B','A','B','A')
        );
    $code='101';
    $p=$parities[$barcode[0]];
    for($i=1;$i<=6;$i++)
        $code.=$codes[$p[$i-1]][$barcode[$i]];
    $code.='01010';
    for($i=7;$i<=12;$i++)
        $code.=$codes['C'][$barcode[$i]];
    $code.='101';
    //Draw bars
    for($i=0;$i<strlen($code);$i++)
    {
        if($code[$i]=='1')
            $this->Rect($x+$i*$w,$y,$w,$h,'F');
    }
    //Print text uder barcode
    $this->SetFont('Arial','',12);
    $this->Text($x,$y+$h+11/$this->k,substr($barcode,-$len));
}
}
function genRandomString($length = 100) {
     $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
     $string ='';    


    for ($p = 0; $p < $length; $p++) {
         $string .= $characters[mt_rand(0, strlen($characters))];
     }

    return $string;
}



class PDF {
//Page header
function Header()
{

	global $name;
	global $total;


	 // get the variable $name1 into the scope of this function
    //Logo
    //Arial bold 15
    $this->SetFont('Arial','B',15);
    //Move to the right
    $this->Cell(70);
    //Title
    $this->Cell(0,0,'Please bring this to the next Scout Meeting',0,0,C);
    //Line break
    $this->Ln(20);
$this->Cell(0,0,'',1,0);
$this->Ln(20);
$this->cell(50,10, 'Registrant:', 1,0);
$this->cell(50,10, 'Events:', 1,0);
$this->cell(50,10, 'Price:', 1,0);
$this->Ln(10);
$this->cell(50,10,$name, 1,0);
$this->cell(50,10, $events, 1,0);
$this->cell(50,10,"$$total", 1,0);
}

//Page footer
function Footer()
{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','I',12);
    //Page number
$this->Cell(0,10,genRandomString(),0,0,'C');}
}

//Instanciation of inherited class
require('ean13.php');
$pdf=new PDF_EAN13();

$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->EAN13(80,40,'123456789012');
$pdf->Output();
$pdf->SetFont('Times','',10);
$pdf->Output('ticket.pdf', 'I');

Link to comment
Share on other sites

Looks like the titles are stored in the database as title1, title2, ect.

 

Dose this not work:

 

<?php
      $sql = ("SELECT * FROM Events WHERE eventid='$eventid' && userid='$userid'");
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$event = $row['event'];
$startdate = $row['startdate'];
$enddate = $row['enddate'];
$description = $row['description'];
$location = $row['location'];
$subevent1 = $row['title1'];
$subevent1 = $row['title2'];
$subevent3 = $row['title3'];
$subevent4 = $row['title4'];
$subevent5 = $row['title5'];
$subevent6 = $row['title6'];
}

if (!empty($subevent1)) { echo  "<br/>$subevent1"; }
if (!empty($subevent2)) { echo  "<hr><br/>$subevent2" ; }
if (!empty($subevent3)) { echo  "<hr><br/>$subevent3"; }
if (!empty($subevent4)) { echo  "<hr><br/>$subevent4"; }
if (!empty($subevent5)) { echo  "<hr><br/>$subevent5"; }
if (!empty($subevent6)) { echo  "<hr> <br/>$subevent6"; }
if (!empty($title7)) { echo  "<hr><br/>$title7"; }
if (!empty($title8)) { echo  "<hr><br/>$title8"; }
?> 

Link to comment
Share on other sites

The previous page stores it in the DB here:

 

$sql = "REPLACE INTO Events (name, event, eventid, userid, title1, title2, title3, title4, title5, title6, title7, title8, email, id, price1, price2, price3, price4, price5, price6, price7, price8) 
	VALUES('$name','$event','$eventid','$userid','$title1','$title2','$title3','$title4','$title5','$title6','$title7','$title8','$email','$id','$price1', '$price2', '$price3','$price4','$price5','$price6','$price7','$price8')";

 

So you should be able to just select it out of the DB on the next page.

 

For the barcode:

<?php
// code to popualte $total, ect. here.

class PDF extends FPDF
{
function EAN13($x, $y, $barcode, $h=16, $w=.35)
{
    $this->Barcode($x,$y,$barcode,$h,$w,13);
}

function UPC_A($x, $y, $barcode, $h=16, $w=.35)
{
    $this->Barcode($x,$y,$barcode,$h,$w,12);
}

function GetCheckDigit($barcode)
{
    //Compute the check digit
    $sum=0;
    for($i=1;$i<=11;$i+=2)
        $sum+=3*$barcode[$i];
    for($i=0;$i<=10;$i+=2)
        $sum+=$barcode[$i];
    $r=$sum%10;
    if($r>0)
        $r=10-$r;
    return $r;
}

function TestCheckDigit($barcode)
{
    //Test validity of check digit
    $sum=0;
    for($i=1;$i<=11;$i+=2)
        $sum+=3*$barcode[$i];
    for($i=0;$i<=10;$i+=2)
        $sum+=$barcode[$i];
    return ($sum+$barcode[12])%10==0;
}

function Barcode($x, $y, $barcode, $h, $w, $len)
{
    //Padding
    $barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT);
    if($len==12)
        $barcode='0'.$barcode;
    //Add or control the check digit
    if(strlen($barcode)==12)
        $barcode.=$this->GetCheckDigit($barcode);
    elseif(!$this->TestCheckDigit($barcode))
        $this->Error('Incorrect check digit');
    //Convert digits to bars
    $codes=array(
        'A'=>array(
            '0'=>'0001101','1'=>'0011001','2'=>'0010011','3'=>'0111101','4'=>'0100011',
            '5'=>'0110001','6'=>'0101111','7'=>'0111011','8'=>'0110111','9'=>'0001011'),
        'B'=>array(
            '0'=>'0100111','1'=>'0110011','2'=>'0011011','3'=>'0100001','4'=>'0011101',
            '5'=>'0111001','6'=>'0000101','7'=>'0010001','8'=>'0001001','9'=>'0010111'),
        'C'=>array(
            '0'=>'1110010','1'=>'1100110','2'=>'1101100','3'=>'1000010','4'=>'1011100',
            '5'=>'1001110','6'=>'1010000','7'=>'1000100','8'=>'1001000','9'=>'1110100')
        );
    $parities=array(
        '0'=>array('A','A','A','A','A','A'),
        '1'=>array('A','A','B','A','B','B'),
        '2'=>array('A','A','B','B','A','B'),
        '3'=>array('A','A','B','B','B','A'),
        '4'=>array('A','B','A','A','B','B'),
        '5'=>array('A','B','B','A','A','B'),
        '6'=>array('A','B','B','B','A','A'),
        '7'=>array('A','B','A','B','A','B'),
        '8'=>array('A','B','A','B','B','A'),
        '9'=>array('A','B','B','A','B','A')
        );
    $code='101';
    $p=$parities[$barcode[0]];
    for($i=1;$i<=6;$i++)
        $code.=$codes[$p[$i-1]][$barcode[$i]];
    $code.='01010';
    for($i=7;$i<=12;$i++)
        $code.=$codes['C'][$barcode[$i]];
    $code.='101';
    //Draw bars
    for($i=0;$i<strlen($code);$i++)
    {
        if($code[$i]=='1')
            $this->Rect($x+$i*$w,$y,$w,$h,'F');
    }
    //Print text uder barcode
    $this->SetFont('Arial','B',12);
    $this->Text($x,$y+$h+11/$this->k,substr($barcode,-$len));
}

//Page header
function Header()
{

	global $name;
	global $total;

	 // get the variable $name1 into the scope of this function
    //Logo
    //Arial bold 15
    $this->SetFont('Arial','B',15);
    //Move to the right
    $this->Cell(70);
    //Title
    $this->Cell(0,0,'Please bring this to the next Scout Meeting',0,0,C);
    //Line break
    $this->Ln(20);
$this->Cell(0,0,'',1,0);
$this->Ln(20);
$this->cell(50,10, 'Registrant:', 1,0);
$this->cell(50,10, 'Events:', 1,0);
$this->cell(50,10, 'Price:', 1,0);
$this->Ln(10);
$this->cell(50,10,$name, 1,0);
$this->cell(50,10, $events, 1,0);
$this->cell(50,10, $total, 1,0);
}

//Page footer
function Footer()
{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','B',;
    //Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}

//Instanciation of inherited class
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->EAN13(10, 120, '38927923');
$pdf->SetFont('Arial','B',12);
$pdf->Output('ticket.pdf', 'I');
?> 

 

 

Link to comment
Share on other sites

is this where globals should be?  oh and error:

Fatal error: Class 'FPDF' not found in /home/a6254834/public_html/ticket.php on line 51

 

class PDF extends FPDF
{
function EAN13($x, $y, $barcode, $h=16, $w=.35)
{
global $name;
global $total;
global $events; 
    $this->Barcode($x,$y,$barcode,$h,$w,13);
}

Link to comment
Share on other sites

ok, so with the barcode thing, how do I make it so that the 0 at start don't show up and the random number at end doesn't display.  will use a form to submit 13 numbers to database that is generated when the form is submitted and then I use those numbers to make the barcode, but I need to get rid of the 5(i believe) randomly generated numbers at beginning and end.  does this make sense?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.