First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* Holds all type of barcodes
|
||||
* You must call init().
|
||||
* You can use get_im() to add other kind of form not held into these classes.
|
||||
*/
|
||||
class BarCode {
|
||||
protected $maxHeight;
|
||||
protected $color1,$color2;
|
||||
protected $positionX, $positionY, $res;
|
||||
public $lastX, $lastY;
|
||||
private $error;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
*/
|
||||
protected function __construct($maxHeight,FColor $color1,FColor $color2,$res){
|
||||
$this->maxHeight = $maxHeight;
|
||||
$this->color1 = $color1;
|
||||
$this->color2 = $color2;
|
||||
$this->res = $res;
|
||||
$this->error = 0;
|
||||
$this->positionY = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index in $keys (useful for checksum)
|
||||
*
|
||||
* @param mixed $var
|
||||
* @return mixed
|
||||
*/
|
||||
protected function findIndex($var){
|
||||
return array_search($var,$this->keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code of the char (useful for drawing bars)
|
||||
*
|
||||
* @param mixed $var
|
||||
* @return string
|
||||
*/
|
||||
protected function findCode($var){
|
||||
return $this->code[$this->findIndex($var)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a Bar of $color depending of the resolution
|
||||
*
|
||||
* @param ressource $img
|
||||
* @param FColor $color
|
||||
*/
|
||||
protected function DrawSingleBar($im,FColor $color){
|
||||
$bar_color = (is_null($color))?NULL:$color->allocate($im);
|
||||
if(!is_null($bar_color))
|
||||
for($i=0;$i<$this->res;$i++)
|
||||
imageline($im,$this->positionX+$i,$this->positionY,$this->positionX+$i,$this->positionY+$this->maxHeight,$bar_color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the Error on the picture
|
||||
*
|
||||
* @param ressource $img
|
||||
* @param string $text
|
||||
*/
|
||||
protected function DrawError($im,$text){
|
||||
$text_color = (is_null($this->color1))?NULL:$this->color1->allocate($im);
|
||||
imagestring($im,5,0,$this->error*15,$text,$text_color);
|
||||
$this->error++;
|
||||
$this->lastX = (imagefontwidth(5)*strlen($text)>$this->lastX)?imagefontwidth(5)*strlen($text):$this->lastX;
|
||||
$this->lastY = $this->error*15;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moving the pointer right to write a bar
|
||||
*/
|
||||
protected function nextX(){
|
||||
$this->positionX+=$this->res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws all chars thanks to $code. if $start==1, the line begins by a bar.
|
||||
* if $start==2, the line begins by a space.
|
||||
*
|
||||
* @param ressource $im
|
||||
* @param string $code
|
||||
* @param int $start
|
||||
*/
|
||||
protected function DrawChar($im,$code,$start=1){
|
||||
$currentColor = ($start==1)?$this->color1:$this->color2;
|
||||
$colornumber = $start;
|
||||
for($i=0;$i<strlen($code);$i++){
|
||||
for($j=0;$j<intval($code[$i])+1;$j++){
|
||||
$this->DrawSingleBar($im,$currentColor);
|
||||
$this->nextX();
|
||||
}
|
||||
if($colornumber==1){
|
||||
$currentColor=$this->color2;
|
||||
$colornumber=2;
|
||||
}
|
||||
else{
|
||||
$currentColor=$this->color1;
|
||||
$colornumber=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the label under the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
protected function DrawText($im) {
|
||||
if($this->textfont != 0) {
|
||||
$xPosition = ($this->positionX / 2) - (strlen($this->text)/2)*imagefontwidth($this->textfont);
|
||||
$text_color = (is_null($this->color1))?NULL:$this->color1->allocate($im);
|
||||
imagestring($im,$this->textfont,$xPosition,$this->maxHeight,$this->text,$text_color);
|
||||
$this->lastY = $this->maxHeight + imagefontheight($this->textfont);
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* Holds Color in RGB Format.
|
||||
*/
|
||||
class FColor {
|
||||
protected $r,$g,$b; // int Hexadecimal Value
|
||||
|
||||
/**
|
||||
* Save RGB value into the classes
|
||||
*
|
||||
* @param int $r
|
||||
* @param int $g
|
||||
* @param int $b
|
||||
*/
|
||||
public function __construct($r,$g,$b){
|
||||
$this->r = $r;
|
||||
$this->g = $g;
|
||||
$this->b = $b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Red Color
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function r(){
|
||||
return $this->r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Green Color
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function g(){
|
||||
return $this->g;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Blue Color
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function b(){
|
||||
return $this->b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the int value for PHP color
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function allocate($im) {
|
||||
return imagecolorallocate($im,$this->r,$this->g,$this->b);
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* Holds the drawing $im and can also holds all forms and texts
|
||||
* You must call init().
|
||||
* You can use get_im() to add other kind of form not held into these classes.
|
||||
*/
|
||||
class FDrawing {
|
||||
private $w, $h; // int
|
||||
private $color; // Fcolor
|
||||
private $filename; // char *
|
||||
private $im; // {object}
|
||||
private $barcode = array();// BarCode *
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $w
|
||||
* @param int $h
|
||||
* @param string filename
|
||||
* @param FColor $color
|
||||
*/
|
||||
public function __construct($w,$h,$filename,Fcolor $color) {
|
||||
$this->w = $w;
|
||||
$this->h = $h;
|
||||
$this->filename = $filename;
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
public function __destruct() {
|
||||
$this->destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init Image and color background
|
||||
*/
|
||||
public function init(){
|
||||
$this->im = imagecreate($this->w, $this->h)
|
||||
or die('Can\'t Initialize the GD Libraty');
|
||||
imagecolorallocate($this->im,$this->color->r(),$this->color->g(),$this->color->b());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ressource
|
||||
*/
|
||||
public function get_im() {
|
||||
return $this->im;
|
||||
}
|
||||
public function set_im($im) {
|
||||
$this->im = $im;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add barcode into the drawing array (for future drawing)
|
||||
*
|
||||
* @param BarCode $barcode
|
||||
*/
|
||||
public function add_barcode(BarCode $barcode) {
|
||||
$this->barcode[] = $barcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw first all forms and after all texts on $im
|
||||
*/
|
||||
public function draw_all() {
|
||||
for($i=0;$i<count($this->barcode);$i++)
|
||||
$this->barcode[$i]->draw($this->im);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save $im into the file (many format available)
|
||||
*
|
||||
* @param int $image_style
|
||||
* @param int $quality
|
||||
*/
|
||||
public function finish($image_style=IMG_FORMAT_PNG,$quality=100) {
|
||||
if($image_style==constant('IMG_FORMAT_PNG')){
|
||||
if(empty($this->filename))
|
||||
imagepng($this->im);
|
||||
else
|
||||
imagepng($this->im,$this->filename);
|
||||
}
|
||||
elseif($image_style==constant('IMG_FORMAT_JPEG'))
|
||||
imagejpeg($this->im,$this->filename,$quality);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the memory of PHP (called also by destructor)
|
||||
*/
|
||||
public function destroy() {
|
||||
imagedestroy($this->im);
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,691 @@
|
||||
<?php
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// table.class.php
|
||||
//--------------------------------------------------------------------
|
||||
//
|
||||
// Class Table - Don't modify this file !
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
// Revision History
|
||||
// $Id: Table.php,v 1.2 2005/01/16 18:26:47 jsgoupil Exp $
|
||||
//--------------------------------------------------------------------
|
||||
// Copyright (C) Jean-Sebastien Goupil
|
||||
// http://other.lookstrike.com/
|
||||
//--------------------------------------------------------------------
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
define( 'TABLE_DEFAULT_ROW_HIDDEN', FALSE );
|
||||
define( 'TABLE_DEFAULT_COL_HIDDEN', FALSE );
|
||||
define( 'TABLE_DEFAULT_CELL_VALUE', ' ' ); // If ' ', a cell will appear, if NULL, no cell will appear
|
||||
define( 'TABLE_DEFAULT_TEMPLATE', 'tpl_LS' );
|
||||
|
||||
include( $class_dir.'/Table_template.php' );
|
||||
class LSTable {
|
||||
// PRIVATE ARGUMENTS
|
||||
private $template; // string
|
||||
private $numRows, $numCols; // int
|
||||
private $title; // string
|
||||
private $text = array(); // string
|
||||
private $cellsAttributes = array(), $rowsAttributes = array(); // string
|
||||
private $hiddenRows = array(), $hiddenCols = array(); // bool
|
||||
private $width; // string
|
||||
|
||||
private $temp_col; // int
|
||||
private $temp_ascending; // bool
|
||||
|
||||
// PUBLIC FUNCTIONS
|
||||
/**
|
||||
* @return
|
||||
* @param int $numRows
|
||||
* @param int $numCols
|
||||
* @param string $width
|
||||
* @param object $parent
|
||||
* @desc Constructor. You can put a $parent object. This will search the first empty place into the parent.
|
||||
**/
|
||||
function __construct ( $numRows, $numCols, $width, &$parent ) {
|
||||
$this->numRows = intval( $numRows );
|
||||
$this->numCols = intval( $numCols );
|
||||
for( $i = 0; $i < $numRows; $i++ )
|
||||
$this->_setVariable( $i );
|
||||
for( $i = 0; $i < $numCols; $i++ )
|
||||
$this->hiddenCols[ $i ] = TABLE_DEFAULT_COL_HIDDEN;
|
||||
$this->title = '';
|
||||
$this->width = strval( $width );
|
||||
|
||||
if( defined( 'TABLE_DEFAULT_TEMPLATE' ) )
|
||||
$this->setTemplate( TABLE_DEFAULT_TEMPLATE );
|
||||
|
||||
// We look for an empty place if $parent isn't null
|
||||
if( is_object( $parent ) ) {
|
||||
$stop = false;
|
||||
for( $i = 0; $i < $parent->numRows; $i++ ) {
|
||||
for( $j = 0; $j < $parent->numCols; $j++ ) {
|
||||
if( $parent->text[ $i ][ $j ] == TABLE_DEFAULT_CELL_VALUE ) {
|
||||
$parent->text[ $i ][ $j ] =& $this;
|
||||
$stop = true;
|
||||
}
|
||||
if( $stop == true )
|
||||
break;
|
||||
}
|
||||
if( $stop == true )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No destructor for PHP4
|
||||
//function __destruct() {
|
||||
//
|
||||
//}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row
|
||||
* @param int $col
|
||||
* @param mixed $string
|
||||
* @desc Writes Text or Object into $row and $col.
|
||||
**/
|
||||
public function setText ( $row, $col, $string ) {
|
||||
if( is_int( $row ) && is_int( $col ) )
|
||||
if( $row < $this->numRows && $col < $this->numCols )
|
||||
$this->text[ $row ][ $col ] = $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row
|
||||
* @param int $col
|
||||
* @param string $attrib
|
||||
* @param mixed $value
|
||||
* @desc Adds a Cell Attribute at $row and $col.
|
||||
**/
|
||||
public function addCellAttribute ( $row, $col, $attrib, $value ) {
|
||||
if( is_int( $row ) && is_int( $col ) && is_string( $attrib ) )
|
||||
if( $row < $this->numRows && $col < $this->numCols )
|
||||
$this->cellsAttributes[ $row ][ $col ][ strtolower( $attrib ) ] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row
|
||||
* @param int $col
|
||||
* @param string $attrib
|
||||
* @desc Deletes a Cell Attribute at $row and $col.
|
||||
**/
|
||||
public function delCellAttribute ( $row, $col, $attrib ) {
|
||||
if( is_int( $row ) && is_int( $col ) && is_string( $attrib ) )
|
||||
if( $row < $this->numRows && $col < $this->numCols )
|
||||
unset( $this->cellsAttributes[ $row ][ $col ][ strtolower( $attrib ) ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row
|
||||
* @param string $attrib
|
||||
* @param mixed $value
|
||||
* @desc Adds a Row Attribute at $row. Will be located in TR.
|
||||
**/
|
||||
public function addRowAttribute ( $row, $attrib, $value ) {
|
||||
if( is_int( $row ) && is_string( $attrib ) )
|
||||
if( $row < $this->numRows )
|
||||
$this->rowsAttributes[ $row ][ strtolower( $attrib ) ] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row
|
||||
* @param string $attrib
|
||||
* @desc Deletes a Row Attribute at $row.
|
||||
**/
|
||||
public function delRowAttribute ( $row, $attrib ) {
|
||||
if( is_int( $row ) && is_string( $attrib ) )
|
||||
if( $row < $this->numRows )
|
||||
unset( $this->rowsAttributes[ $row ][ strtolower( $attrib ) ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row
|
||||
* @param string $attrib
|
||||
* @param mixed $value
|
||||
* @desc Adds a Cell Attribute in all cells located on $row row.
|
||||
**/
|
||||
public function addAllCellsInRowAttribute ( $row, $attrib, $value ) {
|
||||
if( is_int( $row ) && is_string( $attrib ) )
|
||||
if( $row < $this->numRows )
|
||||
for( $i = 0; $i < $this->numCols; $i++ )
|
||||
$this->cellsAttributes[ $row ][ $i ][ strtolower( $attrib ) ] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $col
|
||||
* @param string $attrib
|
||||
* @param mixed $value
|
||||
* @desc Adds a Cell Attribute in all cells located on $col column.
|
||||
**/
|
||||
public function addAllCellsInColAttribute ( $col, $attrib, $value ) {
|
||||
if( is_int( $col ) && is_string( $attrib ) )
|
||||
if( $col < $this->numCols )
|
||||
for( $i = 0; $i < $this->numRows; $i++ )
|
||||
$this->cellsAttributes[ $i ][ $col ][ strtolower( $attrib ) ] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param callback $template
|
||||
* @desc Sets Template (Class)
|
||||
**/
|
||||
public function setTemplate ( $template ) {
|
||||
if( is_string( $template ) )
|
||||
if( class_exists( $template ) )
|
||||
$this->template = strval( $template );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @desc Returns current Template
|
||||
**/
|
||||
public function template () {
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @param int $row
|
||||
* @param int $col
|
||||
* @desc Returns the text or object contained into $row and $col
|
||||
**/
|
||||
public function text ( $row, $col ) {
|
||||
if( is_int( $row ) && is_int( $col ) )
|
||||
if( $row < $this->numRows && $col < $this->numCols )
|
||||
return $this->text[ $row ][ $col ];
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row
|
||||
* @param int $col
|
||||
* @desc Clears the cell located into $row and $col. Keeps the Cell.
|
||||
*/
|
||||
public function clearCell ( $row, $col ) {
|
||||
if( is_int( $row ) && is_int( $col ) ) {
|
||||
if( $row < $this->numRows && $col < $this->numCols ) {
|
||||
$this->text[ $row ][ $col ] = TABLE_DEFAULT_CELL_VALUE;
|
||||
unset( $this->cellsAttributes[ $row ][ $col ] );
|
||||
$this->cellsAttributes[ $row ][ $col ] = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @desc Returns the number of Rows
|
||||
**/
|
||||
public function numRows () {
|
||||
return $this->numRows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @desc Returns the number of Columns
|
||||
**/
|
||||
public function numCols () {
|
||||
return $this->numCols;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $col
|
||||
* @param bool $ascending
|
||||
* @desc Sorts table based on $col.
|
||||
**/
|
||||
public function sortColumn ( $col, $ascending = TRUE ) {
|
||||
if( is_int( $col ) && is_bool( $ascending ) ) {
|
||||
if( $col < $this->numCols ) {
|
||||
$this->temp_col = $col;
|
||||
$this->temp_ascending = $ascending;
|
||||
$this->_sort_merge( $this->text );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $r
|
||||
* @desc Sets the number of rows of the table.
|
||||
**/
|
||||
public function setNumRows ( $r ) {
|
||||
if( is_int( $r ) )
|
||||
if( $r >= 0 )
|
||||
if( $r > $this->numRows )
|
||||
$this->insertRows( $this->numRows, $r - $this->numRows );
|
||||
elseif( $r < $this->numRows )
|
||||
for( $i = $this->numRows; $i > $r; $i-- )
|
||||
$this->removeRow( $i - 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $r
|
||||
* @desc Sets the number of columns of the table.
|
||||
**/
|
||||
public function setNumCols ( $r ) {
|
||||
if( is_int( $r ) )
|
||||
if( $r >= 0 )
|
||||
if( $r > $this->numCols )
|
||||
$this->insertColumns( $this->numCols, $r - $this->numCols );
|
||||
elseif( $r < $this->numCols )
|
||||
for( $i = $this->numCols; $i > $r; $i-- )
|
||||
$this->removeColumn( $i - 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row
|
||||
* @desc Hides a $row from table
|
||||
**/
|
||||
public function hideRow ( $row ) {
|
||||
if( is_int( $row ) )
|
||||
if( $row < $this->numRows )
|
||||
$this->hiddenRows[ $row ] = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $col
|
||||
* @desc Hides a $col from table
|
||||
**/
|
||||
public function hideColumn ( $col ) {
|
||||
if( is_int( $col ) )
|
||||
if( $col < $this->numCols )
|
||||
$this->hiddenCols[ $col ] = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row
|
||||
* @desc Shows a $row from table
|
||||
**/
|
||||
public function showRow ( $row ) {
|
||||
if( is_int( $row ) )
|
||||
if( $row < $this->numRows )
|
||||
$this->hiddenRows[ $row ] = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $col
|
||||
* @desc Shows a $col from table
|
||||
**/
|
||||
public function showColumn ( $col ) {
|
||||
if( is_int( $col ) )
|
||||
if( $col < $this->numCols )
|
||||
$this->hiddenCols[ $col ] = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @param int $row
|
||||
* @desc Returns TRUE if a row is hidden.
|
||||
**/
|
||||
public function isRowHidden ( $row ) {
|
||||
if( is_int( $row ) )
|
||||
if( $row < $this->numRows )
|
||||
return $this->hiddenRows[ $row ];
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @param int $col
|
||||
* @desc Returns TRUE if a col is hidden.
|
||||
**/
|
||||
public function isColumnHidden ( $col ) {
|
||||
if( is_int( $col ) )
|
||||
if( $col < $this->numCols )
|
||||
return $this->hiddenCols[ $col ];
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row1
|
||||
* @param int $row2
|
||||
* @param bool $swapAttributes
|
||||
* @desc Swaps 2 rows. Swaps attributes if $switchAttributes is TRUE.
|
||||
**/
|
||||
public function swapRows ( $row1, $row2, $swapAttributes = FALSE ) {
|
||||
if( is_int( $row1 ) && is_int( $row2 ) && is_bool( $swapAttributes ) ) {
|
||||
if( $row1 < $this->numRows && $row2 < $this->numRows ) {
|
||||
$temp =& $this->text[ $row1 ];
|
||||
$this->text[ $row1 ] =& $this->text[ $row2 ];
|
||||
$this->text[ $row2 ] =& $temp;
|
||||
if( $swapAttributes == TRUE ) {
|
||||
$temp2 = $this->cellsAttributes[ $row1 ];
|
||||
$this->cellsAttributes[ $row1 ] = $this->cellsAttributes[ $row2 ];
|
||||
$this->cellsAttributes[ $row2 ] = $temp2;
|
||||
|
||||
$temp2 = $this->rowsAttributes[ $row1 ];
|
||||
$this->rowsAttributes[ $row1 ] = $this->rowsAttributes[ $row2 ];
|
||||
$this->rowsAttributes[ $row2 ] = $temp2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $col1
|
||||
* @param int $col2
|
||||
* @param bool $swapAttributes
|
||||
* @desc Swaps 2 cols. Swaps attributes if $switchAttributes is TRUE.
|
||||
**/
|
||||
public function swapColumns ( $col1, $col2, $swapAttributes = FALSE ) {
|
||||
if( is_int( $col1 ) && is_int( $col2 ) && is_bool( $swapAttributes ) ) {
|
||||
if( $col1 < $this->numCols && $col2 < $this->numCols ) {
|
||||
for( $i = 0; $i < $this->numRows; $i++ ){
|
||||
$temp =& $this->text[ $i ][ $col1 ];
|
||||
$this->text[ $i ][ $col1 ] =& $this->text[ $i ][ $col2 ];
|
||||
$this->text[ $i ][ $col2 ] =& $temp;
|
||||
if( $swapAttributes == TRUE ) {
|
||||
$temp2 = $this->cellsAttributes[ $i ][ $col1 ];
|
||||
$this->cellsAttributes[ $i ][ $col1 ] = $this->cellsAttributes[ $i ][ $col2 ];
|
||||
$this->cellsAttributes[ $i ][ $col2 ] = $temp2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row1
|
||||
* @param int $col1
|
||||
* @param int $row2
|
||||
* @param int $col2
|
||||
* @param bool $swapAttributes
|
||||
* @desc Swaps 2 cells. Swaps attributes if $switchAttributes is TRUE.
|
||||
**/
|
||||
public function swapCells ( $row1, $col1, $row2, $col2, $swapAttributes = FALSE ) {
|
||||
if( is_int( $row1 ) && is_int( $col1 ) && is_int( $row2 ) && is_int( $col2 ) && is_bool( $swapAttributes ) ) {
|
||||
if( $row1 < $this->numRows && $col1 < $this->numCols && $row2 < $this->numRows && $col2 < $this->numCols ) {
|
||||
$temp =& $this->text[ $row1 ][ $col1 ];
|
||||
$this->text[ $row1 ][ $col1 ] =& $this->text[ $row2 ][ $col2 ];
|
||||
$this->text[ $row2 ][ $col2 ] =& $temp;
|
||||
if( $swapAttributes == TRUE ) {
|
||||
$temp2 = $this->cellsAttributes[ $row1 ][ $col1 ];
|
||||
$this->cellsAttributes[ $row1 ][ $col1 ] = $this->cellsAttributes[ $row2 ][ $col2 ];
|
||||
$this->cellsAttributes[ $row2 ][ $col2 ] = $temp2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row
|
||||
* @param int $count
|
||||
* @desc Inserts $count row at $row position.
|
||||
**/
|
||||
public function insertRows ( $row, $count = 1 ) {
|
||||
if( is_int( $row ) && is_int( $count ) ) {
|
||||
if( $row >= 0 && $row <= $this->numRows ) {
|
||||
for( $i = 0; $i < $count; $i++) {
|
||||
array_splice( $this->text, $row, 0, '' );
|
||||
array_splice( $this->hiddenRows, $row, 0, FALSE );
|
||||
array_splice( $this->cellsAttributes, $row, 0, FALSE );
|
||||
array_splice( $this->rowsAttributes, $row, 0, FALSE );
|
||||
$this->_setVariable( $row );
|
||||
$this->numRows += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $col
|
||||
* @param int $count
|
||||
* @desc Inserts $count columns at $col position.
|
||||
**/
|
||||
public function insertColumns ( $col, $count = 1 ) {
|
||||
if( is_int( $col ) && is_int( $count ) ) {
|
||||
if( $col >= 0 && $col <= $this->numCols ) {
|
||||
for( $i = 0; $i < $this->numRows; $i++ ) {
|
||||
$temp_text = array();
|
||||
$temp_attributes = array();
|
||||
reset($this->text[ $i ]);
|
||||
for( $j = 0; $j <= $this->numCols; $j++ ) {
|
||||
if( $col == $j ) {
|
||||
for( $k = 0; $k < $count; $k++ ){
|
||||
$temp_text[] = '';
|
||||
$temp_attributes[] = array();
|
||||
}
|
||||
}
|
||||
if( $j == $this->numCols )
|
||||
break;
|
||||
$temp_text[] = $this->text[ $i ][ $j ];
|
||||
$temp_attributes[] = $this->cellsAttributes[ $i ][ $j ];
|
||||
}
|
||||
$this->text[ $i ] = $temp_text;
|
||||
$this->cellsAttributes[ $i ] = $temp_attributes;
|
||||
}
|
||||
for( $i = 0; $i < $count; $i++ )
|
||||
array_splice( $this->hiddenCols, $col, 0, FALSE );
|
||||
$this->numCols += $count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $row
|
||||
* @desc Removes $row.
|
||||
**/
|
||||
public function removeRow ( $row ) {
|
||||
if( is_int( $row ) ) {
|
||||
if( $row < $this->numRows ) {
|
||||
array_splice( $this->text, $row, 1 );
|
||||
array_splice( $this->hiddenRows, $row, 1 );
|
||||
array_splice( $this->cellsAttributes, $row, 1 );
|
||||
array_splice( $this->rowsAttributes, $row, 1 );
|
||||
$this->numRows -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $col
|
||||
* @desc Removes $col.
|
||||
**/
|
||||
public function removeColumn ( $col ) {
|
||||
if( is_int( $col ) ) {
|
||||
if( $col < $this->numCols ) {
|
||||
for( $i = 0; $i < $this->numRows; $i++ ) {
|
||||
$temp_text = array();
|
||||
$temp_attributes = array();
|
||||
reset($this->text[ $i ]);
|
||||
while ( list( $key, ) = each( $this->text[ $i ] ) ) {
|
||||
if( $key != $col ) {
|
||||
$temp_text[] = $this->text[ $i ][ $key ];
|
||||
$temp_attributes[] = $this->cellsAttributes[ $i ][ $key ];
|
||||
}
|
||||
}
|
||||
$this->text[ $i ] = $temp_text;
|
||||
$this->cellsAttributes[ $i ] = $temp_attributes;
|
||||
}
|
||||
array_splice( $this->hiddenCols, $col, 1 );
|
||||
$this->numCols -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $width
|
||||
* @desc Sets Table Width.
|
||||
**/
|
||||
public function setWidth ( $width ) {
|
||||
if( is_string( $width ) )
|
||||
$this->width = strval( $width );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @desc Returns Table Width.
|
||||
**/
|
||||
public function width () {
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $title
|
||||
* @desc Sets Table Title.
|
||||
**/
|
||||
public function setTitle ( $title ) {
|
||||
if( is_string( $title ) )
|
||||
$this->title = strval( $title );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @desc Returns Table Title.
|
||||
**/
|
||||
public function title () {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @desc Displays the table with its cells.
|
||||
**/
|
||||
public function draw () {
|
||||
if( $this->template != '' ) {
|
||||
$tpl = new $this->template;
|
||||
$tpl->__header( $this->width, $this->title );
|
||||
$this->_check_rowcol_span();
|
||||
for( $i = 0; $i < $this->numRows; $i++ ) {
|
||||
if( $this->hiddenRows[ $i ] == FALSE ) {
|
||||
$tpl->__row_start( $this->rowsAttributes[ $i ] );
|
||||
for( $j = 0; $j < $this->numCols; $j++ ) {
|
||||
if( $this->hiddenCols[ $j ] == FALSE ) {
|
||||
if( $this->text[ $i ][ $j ] !== NULL ) {
|
||||
if( is_object( $this->text[ $i ][ $j ] ) ) {
|
||||
$tpl->__cell_start( '', $this->cellsAttributes[ $i ][ $j ] );
|
||||
$this->text[ $i ][ $j ]->draw();
|
||||
}
|
||||
else
|
||||
$tpl->__cell_start( $this->text[ $i ][ $j ], $this->cellsAttributes[ $i ][ $j ] );
|
||||
$tpl->__cell_stop( $this->text[ $i ][ $j ], $this->cellsAttributes[ $i ][ $j ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
$tpl->__row_stop( $this->rowsAttributes[ $i ] );
|
||||
}
|
||||
}
|
||||
$tpl->__footer( $this->width, $this->title );
|
||||
}
|
||||
}
|
||||
|
||||
// PRIVATE FUNCTIONS
|
||||
/**
|
||||
* @return void
|
||||
* @desc Sets NULL to cells if colspan or rowspan go on the cells
|
||||
**/
|
||||
private function _check_rowcol_span() {
|
||||
for( $i = 0; $i < $this->numRows; $i++ ) {
|
||||
for( $j = 0; $j < $this->numCols; $j++ ) {
|
||||
if( isset( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] ) )
|
||||
if( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] > 0 )
|
||||
for( $z = 1; $z < intval( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] ); $z++ )
|
||||
$this->text[ $i ][ $j + $z ] = NULL;
|
||||
if( isset( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] ) )
|
||||
if( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] > 0 )
|
||||
for( $z = 1; $z < intval( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] ); $z++ )
|
||||
$this->text[ $i + $z ][ $j ] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $r
|
||||
* @desc Sets Default Variables for row $r.
|
||||
**/
|
||||
private function _setVariable ( $r ) {
|
||||
$this->text[ $r ] = array_fill( 0, $this->numCols, TABLE_DEFAULT_CELL_VALUE );
|
||||
$this->cellsAttributes[ $r ] = array_fill( 0, $this->numCols, array() );
|
||||
$this->rowsAttributes[ $r ] = array();
|
||||
$this->hiddenRows[ $r ] = TABLE_DEFAULT_ROW_HIDDEN;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param int $r
|
||||
* @desc Unsets Default Variables for row $r.
|
||||
**/
|
||||
private function _unsetVariable ( $r ) {
|
||||
unset( $this->text[ $r ] );
|
||||
unset( $this->cellsAttributes[ $r ] );
|
||||
unset( $this->rowsAttributes[ $r ] );
|
||||
unset( $this->hiddenRows[ $r ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param string $tab
|
||||
* @desc Merge Function
|
||||
**/
|
||||
private function _sort_merge ( &$tab ) {
|
||||
if( count( $tab ) <= 1 ) return;
|
||||
else {
|
||||
$tab1 = array();
|
||||
$tab2 = array();
|
||||
|
||||
for( $i = 0; $i < count( $tab ); $i++) {
|
||||
if( $i < ( count( $tab ) ) / 2 )
|
||||
$tab1[] = $tab[ $i ];
|
||||
else
|
||||
$tab2[] = $tab[ $i ];
|
||||
}
|
||||
|
||||
$this->_sort_merge( $tab1 );
|
||||
$this->_sort_merge( $tab2 );
|
||||
|
||||
$this->_merge_all( $tab1, $tab2, $tab );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @param string $tab1
|
||||
* @param string $tab2
|
||||
* @param string $tab
|
||||
* @desc Merge Function
|
||||
**/
|
||||
private function _merge_all ( $tab1, $tab2, &$tab ) {
|
||||
$i = 0;
|
||||
$i1 = $i2 = 0;
|
||||
while( $i1 < count( $tab1 ) && $i2 < count( $tab2 ) ) {
|
||||
if( strcmp( $tab1[ $i1 ][ $this->temp_col ], $tab2[ $i2 ][ $this->temp_col ] ) == (($this->temp_ascending==TRUE)?-1:1) )
|
||||
$tab[ $i ] = $tab1[ $i1++ ];
|
||||
else
|
||||
$tab[ $i ] = $tab2[ $i2++ ];
|
||||
$i++;
|
||||
}
|
||||
|
||||
while( $i1 < count( $tab1 ) ) {
|
||||
$tab[ $i ] = $tab1[ $i1++ ];
|
||||
$i++;
|
||||
}
|
||||
while( $i2 < count( $tab2 ) ) {
|
||||
$tab[ $i ] = $tab2[ $i2++ ];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
class tpl_LS {
|
||||
function __header ( $width, $title ) {
|
||||
echo '<table width="'.$width.'" border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#004163" class="tableline"><tr><th><u>'.$title.'</u>'."\n".'</th></tr><tr><td>'."\n".'<table width="100%" border="0" cellpadding="4" cellspacing="1" align="center">';
|
||||
}
|
||||
|
||||
function __footer ( $width, $title ) {
|
||||
echo '</table>'."\n".'</td></tr></table>'."\n";
|
||||
}
|
||||
|
||||
function __row_start ( $attributes ) {
|
||||
$code = '';
|
||||
$found_class = false;
|
||||
reset( $attributes );
|
||||
while( list( $key, $value ) = each( $attributes ) ) {
|
||||
$code .= ' '.$key.'="'.$value.'"';
|
||||
if( $key == 'class' )
|
||||
$found_class = true;
|
||||
}
|
||||
if( $found_class=== false )
|
||||
$code .= ' class="'.next_color().'"';
|
||||
echo '<tr'.$code.'>';
|
||||
}
|
||||
|
||||
function __row_stop ( $attributes ) {
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
function __cell_start ( $text, $attributes ) {
|
||||
$code = '';
|
||||
reset( $attributes );
|
||||
while( list( $key, $value ) = each( $attributes ) )
|
||||
$code .= ' '.$key.'="'.$value.'"';
|
||||
echo '<td'.$code.'>'.$text;
|
||||
}
|
||||
|
||||
function __cell_stop ( $text, $attributes ) {
|
||||
echo '</td>';
|
||||
}
|
||||
}
|
||||
|
||||
class tpl_BLANK {
|
||||
function __header ( $width, $title ) {
|
||||
echo '<table width="'.$width.'" border="0" cellpadding="0" cellspacing="0" align="center">';
|
||||
}
|
||||
|
||||
function __footer ( $width, $title ) {
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
function __row_start ( $attributes ) {
|
||||
echo '<tr>';
|
||||
}
|
||||
|
||||
function __row_stop ( $attributes ) {
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
function __cell_start ( $text, $attributes ) {
|
||||
$code = '';
|
||||
reset( $attributes );
|
||||
while( list( $key, $value ) = each( $attributes ) )
|
||||
$code .= ' '.$key.'="'.$value.'"';
|
||||
echo '<td'.$code.'>'.$text;
|
||||
}
|
||||
|
||||
function __cell_stop ( $text, $attributes ) {
|
||||
echo '</td>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* codabar.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - Codabar
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class codabar extends BarCode {
|
||||
protected $keys = array(), $code = array();
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9','-','$',':','/','.','+','A','B','C','D');
|
||||
$this->code = array( // 0 added to add an extra space
|
||||
'00000110', /* 0 */
|
||||
'00001100', /* 1 */
|
||||
'00010010', /* 2 */
|
||||
'11000000', /* 3 */
|
||||
'00100100', /* 4 */
|
||||
'10000100', /* 5 */
|
||||
'01000010', /* 6 */
|
||||
'01001000', /* 7 */
|
||||
'01100000', /* 8 */
|
||||
'10010000', /* 9 */
|
||||
'00011000', /* - */
|
||||
'00110000', /* $ */
|
||||
'10001010', /* : */
|
||||
'10100010', /* / */
|
||||
'10101000', /* . */
|
||||
'00111110', /* + */
|
||||
'00110100', /* A */
|
||||
'00010110', /* B */
|
||||
'01010010', /* C */
|
||||
'00011100' /* D */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = strtoupper($text); // Only Capital Letters are Allowed
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Must Start By A, B, C or D
|
||||
if($this->text[0] != 'A' && $this->text[0] != 'B' && $this->text[0] != 'C' && $this->text[0] != 'D') {
|
||||
$this->DrawError($im,'You must start by char A, B, C or D.');
|
||||
$error_stop = true;
|
||||
}
|
||||
// Must Over By A, B, C or D
|
||||
if($this->text[strlen($this->text)-1] != 'A' && $this->text[strlen($this->text)-1] != 'B' && $this->text[strlen($this->text)-1] != 'C' && $this->text[strlen($this->text)-1] != 'D') {
|
||||
$this->DrawError($im,'You must end by char A, B, C or D.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($error_stop == false) {
|
||||
for($i=0;$i<strlen($this->text);$i++)
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* code11.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - Code 11
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class code11 extends BarCode {
|
||||
protected $keys = array(), $code = array();
|
||||
private $starting, $ending;
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->starting = $this->ending = 47;
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9','-');
|
||||
$this->code = array( // 0 added to add an extra space
|
||||
'000010', /* 0 */
|
||||
'100010', /* 1 */
|
||||
'010010', /* 2 */
|
||||
'110000', /* 3 */
|
||||
'001010', /* 4 */
|
||||
'101000', /* 5 */
|
||||
'011000', /* 6 */
|
||||
'000110', /* 7 */
|
||||
'100100', /* 8 */
|
||||
'100000', /* 9 */
|
||||
'001000' /* - */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Starting Code
|
||||
$this->DrawChar($im,'001100',1);
|
||||
// Chars
|
||||
for($i=0;$i<strlen($this->text);$i++)
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),1);
|
||||
// Checksum
|
||||
// First CheckSUM "C"
|
||||
// The "C" checksum character is the modulo 11 remainder of the sum of the weighted
|
||||
// value of the data characters. The weighting value starts at "1" for the right-most
|
||||
// data character, 2 for the second to last, 3 for the third-to-last, and so on up to 20.
|
||||
// After 10, the sequence wraps around back to 1.
|
||||
|
||||
// Second CheckSUM "K"
|
||||
// Same as CheckSUM "C" but we count the CheckSum "C" at the end
|
||||
// After 9, the sequence wraps around back to 1.
|
||||
$sequence_multiplier = array(10,9);
|
||||
$temp_text = $this->text;
|
||||
for($z=0;$z<2;$z++) {
|
||||
// We don't display the K CheckSum if the original text had a length less than 10
|
||||
if(strlen($temp_text)<=10 && $z==1)
|
||||
break;
|
||||
$checksum = 0;
|
||||
for($i=strlen($temp_text),$j=0;$i>0;$i--,$j++) {
|
||||
$multiplier = $i % $sequence_multiplier[$z];
|
||||
if($multiplier==0)
|
||||
$multiplier=$sequence_multiplier[$z];
|
||||
$checksum += $this->findIndex($temp_text[$j]) * $multiplier;
|
||||
}
|
||||
$this->DrawChar($im,$this->findCode($checksum % 11),1);
|
||||
$temp_text .= $this->keys[$checksum % 11];
|
||||
}
|
||||
// Ending Code
|
||||
$this->DrawChar($im,'00110',1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* code128.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - Code 128, A, B, C
|
||||
*
|
||||
* # Code C Working properly only on PHP4 or PHP5.0.3+ due to bug :
|
||||
* http://bugs.php.net/bug.php?id=28862
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class code128 extends BarCode {
|
||||
protected $keys = array(), $keysA = array(), $keysB = array(), $keysC = array(), $code = array();
|
||||
private $starting, $ending, $starting_text;
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
private $currentCode;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
* @param char $start
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont,$start='B') {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
if($start=='A')
|
||||
$this->starting = 103;
|
||||
elseif($start=='B')
|
||||
$this->starting = 104;
|
||||
elseif($start=='C')
|
||||
$this->starting = 105;
|
||||
$this->ending = 106;
|
||||
$this->currentCode = $start;
|
||||
/* CODE 128 A */
|
||||
$this->keysA = array(' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',chr(128),chr(129));
|
||||
|
||||
/* CODE 128 B */
|
||||
$this->keysB = array(' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_','`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','{','|','}','~','','','','',chr(128),'',chr(130));
|
||||
|
||||
/* CODE 128 C */
|
||||
$this->keysC = array();
|
||||
for($i=0;$i<=99;$i++)
|
||||
$this->keysC[] = sprintf('%02d',$i);
|
||||
$this->keysC[] = chr(129);
|
||||
$this->keysC[] = chr(130);
|
||||
|
||||
$this->code = array(
|
||||
'101111', /* 00 */
|
||||
'111011', /* 01 */
|
||||
'111110', /* 02 */
|
||||
'010112', /* 03 */
|
||||
'010211', /* 04 */
|
||||
'020111', /* 05 */
|
||||
'011102', /* 06 */
|
||||
'011201', /* 07 */
|
||||
'021101', /* 08 */
|
||||
'110102', /* 09 */
|
||||
'110201', /* 10 */
|
||||
'120101', /* 11 */
|
||||
'001121', /* 12 */
|
||||
'011021', /* 13 */
|
||||
'011120', /* 14 */
|
||||
'002111', /* 15 */
|
||||
'012011', /* 16 */
|
||||
'012110', /* 17 */
|
||||
'112100', /* 18 */
|
||||
'110021', /* 19 */
|
||||
'110120', /* 20 */
|
||||
'102101', /* 21 */
|
||||
'112001', /* 22 */
|
||||
'201020', /* 23 */
|
||||
'200111', /* 24 */
|
||||
'210011', /* 25 */
|
||||
'210110', /* 26 */
|
||||
'201101', /* 27 */
|
||||
'211001', /* 28 */
|
||||
'211100', /* 29 */
|
||||
'101012', /* 30 */
|
||||
'101210', /* 31 */
|
||||
'121010', /* 32 */
|
||||
'000212', /* 33 */
|
||||
'020012', /* 34 */
|
||||
'020210', /* 35 */
|
||||
'001202', /* 36 */
|
||||
'021002', /* 37 */
|
||||
'021200', /* 38 */
|
||||
'100202', /* 39 */
|
||||
'120002', /* 40 */
|
||||
'120200', /* 41 */
|
||||
'001022', /* 42 */
|
||||
'001220', /* 43 */
|
||||
'021020', /* 44 */
|
||||
'002012', /* 45 */
|
||||
'002210', /* 46 */
|
||||
'022010', /* 47 */
|
||||
'202010', /* 48 */
|
||||
'100220', /* 49 */
|
||||
'120020', /* 50 */
|
||||
'102002', /* 51 */
|
||||
'102200', /* 52 */
|
||||
'102020', /* 53 */
|
||||
'200012', /* 54 */
|
||||
'200210', /* 55 */
|
||||
'220010', /* 56 */
|
||||
'201002', /* 57 */
|
||||
'201200', /* 58 */
|
||||
'221000', /* 59 */
|
||||
'203000', /* 60 */
|
||||
'110300', /* 61 */
|
||||
'320000', /* 62 */
|
||||
'000113', /* 63 */
|
||||
'000311', /* 64 */
|
||||
'010013', /* 65 */
|
||||
'010310', /* 66 */
|
||||
'030011', /* 67 */
|
||||
'030110', /* 68 */
|
||||
'001103', /* 69 */
|
||||
'001301', /* 70 */
|
||||
'011003', /* 71 */
|
||||
'011300', /* 72 */
|
||||
'031001', /* 73 */
|
||||
'031100', /* 74 */
|
||||
'130100', /* 75 */
|
||||
'110003', /* 76 */
|
||||
'302000', /* 77 */
|
||||
'130001', /* 78 */
|
||||
'023000', /* 79 */
|
||||
'000131', /* 80 */
|
||||
'010031', /* 81 */
|
||||
'010130', /* 82 */
|
||||
'003101', /* 83 */
|
||||
'013001', /* 84 */
|
||||
'013100', /* 85 */
|
||||
'300101', /* 86 */
|
||||
'310001', /* 87 */
|
||||
'310100', /* 88 */
|
||||
'101030', /* 89 */
|
||||
'103010', /* 90 */
|
||||
'301010', /* 91 */
|
||||
'000032', /* 92 */
|
||||
'000230', /* 93 */
|
||||
'020030', /* 94 */
|
||||
'003002', /* 95 */
|
||||
'003200', /* 96 */
|
||||
'300002', /* 97 */
|
||||
'300200', /* 98 */
|
||||
'002030', /* 99 */
|
||||
'003020', /* 100*/
|
||||
'200030', /* 101*/
|
||||
'300020', /* 102*/
|
||||
'100301', /* 103*/
|
||||
'100103', /* 104*/
|
||||
'100121', /* 105*/
|
||||
'122000' /*STOP*/
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
$this->usingCode($start);
|
||||
$this->starting_text = $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
private function usingCode($code) {
|
||||
if($code=='A')
|
||||
$this->keys = $this->keysA;
|
||||
elseif($code=='B')
|
||||
$this->keys = $this->keysB;
|
||||
elseif($code=='C')
|
||||
$this->keys = $this->keysC;
|
||||
$this->currentCode = $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
$this->usingCode($this->starting_text);
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if($this->currentCode=='C') {
|
||||
if(isset($this->text[$i+1]) && $this->check_int($this->text[$i+1])) {
|
||||
$value_test = array_search($this->text[$i].$this->text[$i+1],$this->keys);
|
||||
$i++;
|
||||
}
|
||||
else {
|
||||
$this->DrawError($im,'With Code C, you must provide always pair of two integers.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
$value_test = array_search($this->text[$i],$this->keys);
|
||||
if(!is_int($value_test)) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($this->findIndex($this->text[$i]) == 99 && $this->currentCode != 'C')
|
||||
$this->usingCode('C');
|
||||
elseif($this->findIndex($this->text[$i]) == 100 && $this->currentCode != 'B')
|
||||
$this->usingCode('B');
|
||||
elseif($this->findIndex($this->text[$i]) == 101 && $this->currentCode != 'A')
|
||||
$this->usingCode('A');
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// The START-A, START-B, START-C, STOP are not allowed
|
||||
if(is_int(strpos($this->text,chr(135))) || is_int(strpos($this->text,chr(136))) || is_int(strpos($this->text,chr(137))) || is_int(strpos($this->text,chr(138)))) {
|
||||
$this->DrawError($im,'Chars START-A, START-B, START-C, STOP not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($error_stop == false) {
|
||||
$this->usingCode($this->starting_text);
|
||||
// Starting Code
|
||||
$this->DrawChar($im,$this->code[$this->starting],1);
|
||||
// Chars
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if($this->currentCode=='C') {
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i].$this->text[$i+1]),1);
|
||||
$i++;
|
||||
}
|
||||
else
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),1);
|
||||
if($this->findIndex($this->text[$i]) == 99 && $this->currentCode != 'C')
|
||||
$this->usingCode('C');
|
||||
elseif($this->findIndex($this->text[$i]) == 100 && $this->currentCode != 'B')
|
||||
$this->usingCode('B');
|
||||
elseif($this->findIndex($this->text[$i]) == 101 && $this->currentCode != 'A')
|
||||
$this->usingCode('A');
|
||||
}
|
||||
// Checksum
|
||||
// First Char (START)
|
||||
// + Starting with the first data character following the start character,
|
||||
// take the value of the character (between 0 and 102, inclusive) multiply
|
||||
// it by its character position (1) and add that to the running checksum.
|
||||
// Modulated 103
|
||||
if($this->starting == 103)
|
||||
$this->usingCode('A');
|
||||
elseif($this->starting == 104)
|
||||
$this->usingCode('B');
|
||||
elseif($this->starting == 105)
|
||||
$this->usingCode('C');
|
||||
$checksum = 0;
|
||||
$checksum += $this->starting;
|
||||
for($position=1,$i=0;$i<strlen($this->text);$position++,$i++) {
|
||||
if($this->currentCode=='C') {
|
||||
$checksum += intval($this->text[$i].$this->text[$i+1]) * $position;
|
||||
$i++;
|
||||
}
|
||||
else
|
||||
$checksum += $this->findIndex($this->text[$i]) * $position;
|
||||
|
||||
if($this->findIndex($this->text[$i]) == 99 && $this->currentCode != 'C')
|
||||
$this->usingCode('C');
|
||||
elseif($this->findIndex($this->text[$i]) == 100 && $this->currentCode != 'B')
|
||||
$this->usingCode('B');
|
||||
elseif($this->findIndex($this->text[$i]) == 101 && $this->currentCode != 'A')
|
||||
$this->usingCode('A');
|
||||
}
|
||||
$this->DrawChar($im,$this->code[$checksum % 103],1);
|
||||
// Ending Code
|
||||
$this->DrawChar($im,$this->code[$this->ending],1);
|
||||
// Draw a Final Bar
|
||||
$this->DrawChar($im,'1',1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
// Removing Special Code
|
||||
$this->text = ereg_replace(chr(128),'',$this->text);
|
||||
$this->text = ereg_replace(chr(129),'',$this->text);
|
||||
$this->text = ereg_replace(chr(130),'',$this->text);
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function check_int($var) {
|
||||
if(intval($var)>=0 || intval($var)<=9)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* code39.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - Code 39
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* v1.01 7 jul 2004 Jean-Sebastien Goupil Correction + Sign
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class code39 extends BarCode {
|
||||
protected $keys = array(), $code = array();
|
||||
private $starting, $ending;
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
private $checksum;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
* @param bool $checksum
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont,$checksum=false) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->starting = $this->ending = 43;
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','.',' ','$','/','+','%','*');
|
||||
$this->code = array( // 0 added to add an extra space
|
||||
'0001101000', /* 0 */
|
||||
'1001000010', /* 1 */
|
||||
'0011000010', /* 2 */
|
||||
'1011000000', /* 3 */
|
||||
'0001100010', /* 4 */
|
||||
'1001100000', /* 5 */
|
||||
'0011100000', /* 6 */
|
||||
'0001001010', /* 7 */
|
||||
'1001001000', /* 8 */
|
||||
'0011001000', /* 9 */
|
||||
'1000010010', /* A */
|
||||
'0010010010', /* B */
|
||||
'1010010000', /* C */
|
||||
'0000110010', /* D */
|
||||
'1000110000', /* E */
|
||||
'0010110000', /* F */
|
||||
'0000011010', /* G */
|
||||
'1000011000', /* H */
|
||||
'0010011000', /* I */
|
||||
'0000111000', /* J */
|
||||
'1000000110', /* K */
|
||||
'0010000110', /* L */
|
||||
'1010000100', /* M */
|
||||
'0000100110', /* N */
|
||||
'1000100100', /* O */
|
||||
'0010100100', /* P */
|
||||
'0000001110', /* Q */
|
||||
'1000001100', /* R */
|
||||
'0010001100', /* S */
|
||||
'0000101100', /* T */
|
||||
'1100000010', /* U */
|
||||
'0110000010', /* V */
|
||||
'1110000000', /* W */
|
||||
'0100100010', /* X */
|
||||
'1100100000', /* Y */
|
||||
'0110100000', /* Z */
|
||||
'0100001010', /* - */
|
||||
'1100001000', /* . */
|
||||
'0110001000', /* */
|
||||
'0101010000', /* $ */
|
||||
'0101000100', /* / */
|
||||
'0100010100', /* + */
|
||||
'0001010100', /* % */
|
||||
'0100101000' /* * */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
$this->checksum = $checksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = strtoupper($text); // Only Capital Letters are Allowed
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// The * is not allowed
|
||||
if(is_int(strpos($this->text,'*'))) {
|
||||
$this->DrawError($im,'Char \'*\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Starting *
|
||||
$this->DrawChar($im,$this->code[$this->starting],1);
|
||||
// Chars
|
||||
for($i=0;$i<strlen($this->text);$i++)
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),1);
|
||||
// Checksum (rarely used)
|
||||
if($this->checksum == true) {
|
||||
$checksum = 0;
|
||||
for($i=0;$i<strlen($this->text);$i++)
|
||||
$checksum += $this->findIndex($this->text[$i]);
|
||||
$this->DrawChar($im,$this->code[$checksum % 43],1);
|
||||
}
|
||||
// Ending *
|
||||
$this->DrawChar($im,$this->code[$this->ending],1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* code93.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - Code 93
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class code93 extends BarCode {
|
||||
protected $keys = array(), $code = array();
|
||||
private $starting, $ending;
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->starting = $this->ending = 47;
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','.',' ','$','/','+','%','($)','(%)','(/)','(+)','*');
|
||||
$this->code = array(
|
||||
'020001', /* 0 */
|
||||
'000102', /* 1 */
|
||||
'000201', /* 2 */
|
||||
'000300', /* 3 */
|
||||
'010002', /* 4 */
|
||||
'010101', /* 5 */
|
||||
'010200', /* 6 */
|
||||
'000003', /* 7 */
|
||||
'020100', /* 8 */
|
||||
'030000', /* 9 */
|
||||
'100002', /* A */
|
||||
'100101', /* B */
|
||||
'100200', /* C */
|
||||
'110001', /* D */
|
||||
'110100', /* E */
|
||||
'120000', /* F */
|
||||
'001002', /* G */
|
||||
'001101', /* H */
|
||||
'001200', /* I */
|
||||
'011001', /* J */
|
||||
'021000', /* K */
|
||||
'000012', /* L */
|
||||
'000111', /* M */
|
||||
'000210', /* N */
|
||||
'010011', /* O */
|
||||
'020010', /* P */
|
||||
'101001', /* Q */
|
||||
'101100', /* R */
|
||||
'100011', /* S */
|
||||
'100110', /* T */
|
||||
'110010', /* U */
|
||||
'111000', /* V */
|
||||
'001011', /* W */
|
||||
'001110', /* X */
|
||||
'011010', /* Y */
|
||||
'012000', /* Z */
|
||||
'010020', /* - */
|
||||
'200001', /* . */
|
||||
'200100', /* */
|
||||
'210000', /* $ */
|
||||
'001020', /* / */
|
||||
'002010', /* + */
|
||||
'100020', /* % */
|
||||
'010110', /*($)*/
|
||||
'201000', /*(%)*/
|
||||
'200010', /*(/)*/
|
||||
'011100', /*(+)*/
|
||||
'000030' /* * */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = strtoupper($text); // Only Capital Letters are Allowed
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// The * is not allowed
|
||||
if(is_int(strpos($this->text,'*'))) {
|
||||
$this->DrawError($im,'Char \'*\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
|
||||
if($error_stop == false) {
|
||||
// Starting *
|
||||
$this->DrawChar($im,$this->code[$this->starting],1);
|
||||
// Chars
|
||||
for($i=0;$i<strlen($this->text);$i++)
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),1);
|
||||
// Checksum
|
||||
// First CheckSUM "C"
|
||||
// The "C" checksum character is the modulo 47 remainder of the sum of the weighted
|
||||
// value of the data characters. The weighting value starts at "1" for the right-most
|
||||
// data character, 2 for the second to last, 3 for the third-to-last, and so on up to 20.
|
||||
// After 20, the sequence wraps around back to 1.
|
||||
|
||||
// Second CheckSUM "K"
|
||||
// Same as CheckSUM "C" but we count the CheckSum "C" at the end
|
||||
// After 15, the sequence wraps around back to 1.
|
||||
$sequence_multiplier = array(20,15);
|
||||
$temp_text = $this->text;
|
||||
for($z=0;$z<2;$z++) {
|
||||
$checksum = 0;
|
||||
for($i=strlen($temp_text),$j=0;$i>0;$i--,$j++) {
|
||||
$multiplier = $i % $sequence_multiplier[$z];
|
||||
if($multiplier==0)
|
||||
$multiplier = $sequence_multiplier[$z];
|
||||
$checksum += $this->findIndex($temp_text[$j]) * $multiplier;
|
||||
}
|
||||
$this->DrawChar($im,$this->code[$checksum % 47],1);
|
||||
$temp_text .= $this->keys[$checksum % 47];
|
||||
}
|
||||
// Ending *
|
||||
$this->DrawChar($im,$this->code[$this->ending],1);
|
||||
// Draw a Final Bar
|
||||
$this->DrawChar($im,'0',1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* ean13.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - EAN-13
|
||||
*
|
||||
* You can provide a ISBN code (without dash), the code will transform
|
||||
* it into a EAN13 format.
|
||||
* EAN-13 contains
|
||||
* - 2 system digits (1 not displayed but coded with parity)
|
||||
* - 5 manufacturer code digits
|
||||
* - 5 product digits
|
||||
* - 1 checksum digit
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class ean13 extends BarCode {
|
||||
protected $keys = array(), $code = array(), $codeParity = array();
|
||||
private $text;
|
||||
private $textfont;
|
||||
private $book;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
* @param bool $book
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont,$book=false) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
|
||||
// Left-Hand Odd Parity starting with a space
|
||||
// Left-Hand Even Parity is the inverse (0=0012) starting with a space
|
||||
// Right-Hand is the same of Left-Hand starting with a bar
|
||||
$this->code = array(
|
||||
'2100', /* 0 */
|
||||
'1110', /* 1 */
|
||||
'1011', /* 2 */
|
||||
'0300', /* 3 */
|
||||
'0021', /* 4 */
|
||||
'0120', /* 5 */
|
||||
'0003', /* 6 */
|
||||
'0201', /* 7 */
|
||||
'0102', /* 8 */
|
||||
'2001' /* 9 */
|
||||
);
|
||||
// Parity, 0=Odd, 1=Even for manufacturer code. Depending on 1st System Digit
|
||||
$this->codeParity = array(
|
||||
array(0,0,0,0,0), /* 0 */
|
||||
array(0,1,0,1,1), /* 1 */
|
||||
array(0,1,1,0,1), /* 2 */
|
||||
array(0,1,1,1,0), /* 3 */
|
||||
array(1,0,0,1,1), /* 4 */
|
||||
array(1,1,0,0,1), /* 5 */
|
||||
array(1,1,1,0,0), /* 6 */
|
||||
array(1,0,1,0,1), /* 7 */
|
||||
array(1,0,1,1,0), /* 8 */
|
||||
array(1,1,0,1,0) /* 9 */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
$this->book = $book;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text){
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
private function inverse($text,$inverse=1) {
|
||||
if($inverse == 1)
|
||||
$text = strrev($text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
if($this->book == true && strlen($this->text) != 10) {
|
||||
$this->DrawError($im,'Must contains 10 chars if ISBN is true.');
|
||||
$error_stop = true;
|
||||
}
|
||||
|
||||
// If it's a book, we change the code to the right one
|
||||
if($this->book==true && strlen($this->text)==10)
|
||||
$this->text = '978'.substr($this->text,0,strlen($this->text)-1);
|
||||
|
||||
// Must contains 12 chars
|
||||
if(strlen($this->text) != 12) {
|
||||
$this->DrawError($im,'Must contains 12 chars, the 13th digit is automatically added.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Calculating Checksum
|
||||
// Consider the right-most digit of the message to be in an "odd" position,
|
||||
// and assign odd/even to each character moving from right to left
|
||||
// Odd Position = 3, Even Position = 1
|
||||
// Multiply it by the number
|
||||
// Add all of that and do 10-(?mod10)
|
||||
$odd = true;
|
||||
$checksum=0;
|
||||
for($i=strlen($this->text);$i>0;$i--) {
|
||||
if($odd==true) {
|
||||
$multiplier=3;
|
||||
$odd=false;
|
||||
}
|
||||
else {
|
||||
$multiplier=1;
|
||||
$odd=true;
|
||||
}
|
||||
$checksum += $this->keys[$this->text[$i - 1]] * $multiplier;
|
||||
}
|
||||
$checksum = 10 - $checksum % 10;
|
||||
$checksum = ($checksum == 10)?0:$checksum;
|
||||
$this->text .= $this->keys[$checksum];
|
||||
// If we have to write text, we move the barcode to the right to have space to put system digit
|
||||
$this->positionX = ($this->textfont == 0)?0:10;
|
||||
// Starting Code
|
||||
$this->DrawChar($im,'000',1);
|
||||
// Draw Second Code
|
||||
$this->DrawChar($im,$this->findCode($this->text[1]),2);
|
||||
// Draw Manufacturer Code
|
||||
for($i=0;$i<5;$i++)
|
||||
$this->DrawChar($im,$this->inverse($this->findCode($this->text[$i + 2]),$this->codeParity[$this->text[0]][$i]),2);
|
||||
// Draw Center Guard Bar
|
||||
$this->DrawChar($im,'00000',2);
|
||||
// Draw Product Code
|
||||
for($i=7;$i<13;$i++){
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),1);
|
||||
}
|
||||
// Draw Right Guard Bar
|
||||
$this->DrawChar($im,'000',1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded method for drawing special label
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
protected function DrawText($im) {
|
||||
if($this->textfont != 0) {
|
||||
$bar_color = (is_null($this->color1))?NULL:$this->color1->allocate($im);
|
||||
if(!is_null($bar_color)) {
|
||||
$rememberX = $this->positionX;
|
||||
$rememberH = $this->maxHeight;
|
||||
// We increase the bars
|
||||
$this->maxHeight = $this->maxHeight + 9;
|
||||
$this->positionX = 10;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
$this->positionX += $this->res*2;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
// Center Guard Bar
|
||||
$this->positionX += $this->res*44;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
$this->positionX += $this->res*2;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
// Last Bars
|
||||
$this->positionX += $this->res*44;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
$this->positionX += $this->res*2;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
|
||||
$this->positionX = $rememberX;
|
||||
$this->maxHeight = $rememberH;
|
||||
imagechar($im,$this->textfont,1,$this->maxHeight-(imagefontheight($this->textfont)/2),$this->text[0],$bar_color);
|
||||
imagestring($im,$this->textfont,10+(3*$this->res+48*$this->res)/2-imagefontwidth($this->textfont)*(6/2),$this->maxHeight+1,substr($this->text,1,6),$bar_color);
|
||||
imagestring($im,$this->textfont,10+46*$this->res+(3*$this->res+46*$this->res)/2-imagefontwidth($this->textfont)*(6/2),$this->maxHeight+1,substr($this->text,7,6),$bar_color);
|
||||
}
|
||||
$this->lastY = $this->maxHeight + imagefontheight($this->textfont);
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* ean8.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - EAN-8
|
||||
*
|
||||
* EAN-8 contains
|
||||
* - 4 digits
|
||||
* - 3 digits
|
||||
* - 1 checksum
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class ean8 extends BarCode {
|
||||
protected $keys = array(), $code = array();
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
|
||||
// Left-Hand Odd Parity starting with a space
|
||||
// Right-Hand is the same of Left-Hand starting with a bar
|
||||
$this->code = array(
|
||||
'2100', /* 0 */
|
||||
'1110', /* 1 */
|
||||
'1011', /* 2 */
|
||||
'0300', /* 3 */
|
||||
'0021', /* 4 */
|
||||
'0120', /* 5 */
|
||||
'0003', /* 6 */
|
||||
'0201', /* 7 */
|
||||
'0102', /* 8 */
|
||||
'2001' /* 9 */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Must contains 7 chars
|
||||
if(strlen($this->text) != 7) {
|
||||
$this->DrawError($im,'Must contains 7 chars, the 8th digit is automatically added.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Calculating Checksum
|
||||
// Consider the right-most digit of the message to be in an "odd" position,
|
||||
// and assign odd/even to each character moving from right to left
|
||||
// Odd Position = 3, Even Position = 1
|
||||
// Multiply it by the number
|
||||
// Add all of that and do 10-(?mod10)
|
||||
$odd = true;
|
||||
$checksum=0;
|
||||
for($i=strlen($this->text);$i>0;$i--) {
|
||||
if($odd==true) {
|
||||
$multiplier=3;
|
||||
$odd=false;
|
||||
}
|
||||
else {
|
||||
$multiplier=1;
|
||||
$odd=true;
|
||||
}
|
||||
$checksum += $this->keys[$this->text[$i - 1]] * $multiplier;
|
||||
}
|
||||
$checksum = 10 - $checksum % 10;
|
||||
$checksum = ($checksum == 10)?0:$checksum;
|
||||
$this->text .= $this->keys[$checksum];
|
||||
// Starting Code
|
||||
$this->DrawChar($im,'000',1);
|
||||
// Draw First 4 Chars (Left-Hand)
|
||||
for($i=0;$i<4;$i++)
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),2);
|
||||
// Draw Center Guard Bar
|
||||
$this->DrawChar($im,'00000',2);
|
||||
// Draw Last 4 Chars (Right-Hand)
|
||||
for($i=4;$i<8;$i++)
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),1);
|
||||
// Draw Right Guard Bar
|
||||
$this->DrawChar($im,'000',1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded method for drawing special label
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
protected function DrawText($im) {
|
||||
if($this->textfont != 0) {
|
||||
$bar_color = (is_null($this->color1))?NULL:$this->color1->allocate($im);
|
||||
if(!is_null($bar_color)) {
|
||||
$rememberX = $this->positionX;
|
||||
$rememberH = $this->maxHeight;
|
||||
// We increase the bars
|
||||
$this->maxHeight = $this->maxHeight + 9;
|
||||
$this->positionX = 0;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
$this->positionX += $this->res*2;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
// Center Guard Bar
|
||||
$this->positionX += $this->res*30;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
$this->positionX += $this->res*2;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
// Last Bars
|
||||
$this->positionX += $this->res*30;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
$this->positionX += $this->res*2;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
|
||||
$this->positionX = $rememberX;
|
||||
$this->maxHeight = $rememberH;
|
||||
imagestring($im,$this->textfont,(3*$this->res+34*$this->res)/2-imagefontwidth($this->textfont)*(4/2),$this->maxHeight+1,substr($this->text,0,4),$bar_color);
|
||||
imagestring($im,$this->textfont,32*$this->res+(3*$this->res+32*$this->res)/2-imagefontwidth($this->textfont)*(4/2),$this->maxHeight+1,substr($this->text,4,4),$bar_color);
|
||||
}
|
||||
$this->lastY = $this->maxHeight + imagefontheight($this->textfont);
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* i25.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - Interleaved 2 of 5
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class i25 extends BarCode {
|
||||
protected $keys = array(), $code = array();
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
private $checksum;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
* @param bool $checksum
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont,$checksum=false) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
|
||||
$this->code = array(
|
||||
'00110', /* 0 */
|
||||
'10001', /* 1 */
|
||||
'01001', /* 2 */
|
||||
'11000', /* 3 */
|
||||
'00101', /* 4 */
|
||||
'10100', /* 5 */
|
||||
'01100', /* 6 */
|
||||
'00011', /* 7 */
|
||||
'10010', /* 8 */
|
||||
'01010' /* 9 */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
$this->checksum = $checksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Must be even
|
||||
if(strlen($this->text) % 2 != 0 && $this->checksum == false) {
|
||||
$this->DrawError($im,'i25 must be even if checksum is false.');
|
||||
$error_stop = true;
|
||||
}
|
||||
elseif(strlen($this->text) % 2 == 0 && $this->checksum == true) {
|
||||
$this->DrawError($im,'i25 must be odd if checksum is true.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// We calculate checksum first
|
||||
// Odd Number has a weight of 1, even number has a weight of 3
|
||||
// Multiply to position
|
||||
// Sum all of that and mod 10
|
||||
if($this->checksum == true) {
|
||||
$checksum = 0;
|
||||
for($i=1;$i<=strlen($this->text);$i++) {
|
||||
$multiplier = (intval($this->text[$i-1])%2!=0)?1:3;
|
||||
$checksum += $i*$multiplier;
|
||||
}
|
||||
$this->text .= $this->keys[$checksum%10];
|
||||
}
|
||||
// Starting Code
|
||||
$this->DrawChar($im,'0000',1);
|
||||
// Chars
|
||||
for($i=0;$i<strlen($this->text);$i+=2) {
|
||||
$temp_bar = '';
|
||||
for($j=0;$j<strlen($this->findCode($this->text[$i]));$j++) {
|
||||
$temp_bar .= substr($this->findCode($this->text[$i]),$j,1);
|
||||
$temp_bar .= substr($this->findCode($this->text[$i + 1]),$j,1);
|
||||
}
|
||||
$this->DrawChar($im,$temp_bar,1);
|
||||
}
|
||||
// Ending Code
|
||||
$this->DrawChar($im,'100',1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// index.php
|
||||
//--------------------------------------------------------------------
|
||||
//
|
||||
// Holding Constant
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
// Revision History
|
||||
// V1.02 8 mar 2005 Jean-Sebastien Goupil Spreading all Classes in single file
|
||||
// V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
//--------------------------------------------------------------------
|
||||
// Copyright (C) Jean-Sebastien Goupil
|
||||
// http://other.lookstrike.com/barcode/
|
||||
//--------------------------------------------------------------------
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Constants
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
define('IMG_FORMAT_PNG', 1);
|
||||
define('IMG_FORMAT_JPEG', 2);
|
||||
define('IMG_FORMAT_WBMP', 4);
|
||||
define('IMG_FORMAT_GIF', 8);
|
||||
?>
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* msi.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - MSI Plessey
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class msi extends BarCode {
|
||||
protected $keys = array(), $code = array();
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
private $checksum;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
* @param int $checksum
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont,$checksum=0) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
|
||||
$this->code = array(
|
||||
'01010101', /* 0 */
|
||||
'01010110', /* 1 */
|
||||
'01011001', /* 2 */
|
||||
'01011010', /* 3 */
|
||||
'01100101', /* 4 */
|
||||
'01100110', /* 5 */
|
||||
'01101001', /* 6 */
|
||||
'01101010', /* 7 */
|
||||
'10010101', /* 8 */
|
||||
'10010110' /* 9 */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
$this->checksum = $checksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// We calculate checksum first
|
||||
// Forming a new number
|
||||
// If the original number is even, we take all even position
|
||||
// If the original number is odd, we take all odd position
|
||||
// 123456 = 246
|
||||
// 12345 = 135
|
||||
// Multiply by 2
|
||||
// Add up all the digit in the result (270 : 2+7+0)
|
||||
// Add up other digit not used.
|
||||
// 10 - (? Modulo 10). If result = 10, change to 0
|
||||
$last_checksum = $this->checksum;
|
||||
$last_text = $this->text;
|
||||
$checksum = array();
|
||||
for($i=0;$i<$last_checksum;$i++){
|
||||
$new_text = '';
|
||||
$new_number = 0;
|
||||
if(strlen($last_text) % 2 == 0) // Even
|
||||
$starting = 1;
|
||||
else
|
||||
$starting = 0;
|
||||
for($j=$starting;$j<strlen($last_text);$j+=2)
|
||||
$new_text .= $last_text[$j];
|
||||
$new_text = strval(intval($new_text)*2);
|
||||
for($j=0;$j<strlen($new_text);$j++)
|
||||
$new_number += intval($new_text[$j]);
|
||||
for($j=($starting==0)?1:0;$j<strlen($last_text);$j+=2){
|
||||
$new_number += intval($last_text[$j]);
|
||||
}
|
||||
$new_number = 10 - $new_number % 10;
|
||||
$new_number = ($new_number == 10)?0:$new_number;
|
||||
$checksum[] = $new_number;
|
||||
$last_text .= $new_number;
|
||||
}
|
||||
// Starting Code
|
||||
$this->DrawChar($im,'10',1);
|
||||
// Chars
|
||||
for($i=0;$i<strlen($this->text);$i++)
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),1);
|
||||
for($i=0;$i<count($checksum);$i++)
|
||||
$this->DrawChar($im,$this->findCode($checksum[$i]),1);
|
||||
// Ending Code
|
||||
$this->DrawChar($im,'010',1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* othercode.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - othercode
|
||||
*
|
||||
* Other Codes
|
||||
* Starting with a bar and altern to space, bar, ...
|
||||
* 0 is the smallest
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class othercode extends BarCode {
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
private $a1;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
* @param string $a1
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont,$a1='') {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
$this->a1 = $a1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$this->DrawChar($im,$this->text,1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded method for drawing special label
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
protected function DrawText($im) {
|
||||
if($this->textfont != 0 && $this->a1!='') {
|
||||
$bar_color = (is_null($this->color1))?NULL:$this->color1->allocate($im);
|
||||
if(!is_null($bar_color)) {
|
||||
$xPosition = ($this->positionX / 2) - (strlen($this->a1)/2)*imagefontwidth($this->textfont);
|
||||
$text_color = (is_null($this->color1))?NULL:$this->color1->allocate($im);
|
||||
imagestring($im,$this->textfont,$xPosition,$this->maxHeight,$this->a1,$text_color);
|
||||
}
|
||||
$this->lastY = $this->maxHeight + imagefontheight($this->textfont);
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* postnet.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - PostNet
|
||||
*
|
||||
* ################ NOT TESTED ################
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class postnet extends BarCode {
|
||||
protected $keys = array(), $code = array();
|
||||
private $starting, $ending;
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
|
||||
$this->code = array(
|
||||
'11000', /* 0 */
|
||||
'00011', /* 1 */
|
||||
'00101', /* 2 */
|
||||
'00110', /* 3 */
|
||||
'01001', /* 4 */
|
||||
'01010', /* 5 */
|
||||
'01100', /* 6 */
|
||||
'10001', /* 7 */
|
||||
'10010', /* 8 */
|
||||
'10100' /* 9 */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text){
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Must contains 5, 9 or 11 chars
|
||||
if(strlen($this->text) != 5 && strlen($this->text) != 9 && strlen($this->text) != 11) {
|
||||
$this->DrawError($im,'Must contains 5, 9 or 11 chars.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Checksum
|
||||
$checksum = 0;
|
||||
for($i=0;$i<strlen($this->text);$i++)
|
||||
$checksum += intval($this->text[$i]);
|
||||
$checksum = 10-($checksum % 10);
|
||||
|
||||
// Starting Code
|
||||
$this->DrawChar($im,'1',0);
|
||||
// Code
|
||||
for($i=0;$i<strlen($this->text);$i++)
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),0);
|
||||
// Checksum
|
||||
$this->DrawChar($im,$this->findCode($checksum),0);
|
||||
//Ending Code
|
||||
$this->DrawChar($im,'1',1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded method for drawing special barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
* @param string $code
|
||||
* @param int $last
|
||||
*/
|
||||
protected function DrawChar($im,$code,$last=0) {
|
||||
$first_posY = $this->positionY;
|
||||
$bar_color = (is_null($this->color1))?NULL:$this->color1->allocate($im);
|
||||
if(!is_null($bar_color)){
|
||||
for($i=0;$i<strlen($code);$i++){
|
||||
if($code[$i] == '0') {
|
||||
$this->positionY = ($first_posY+$this->maxHeight)/2;
|
||||
$height = $this->positionY+($first_posY+$this->maxHeight)/2;
|
||||
}
|
||||
else {
|
||||
$this->positionY = $first_posY;
|
||||
$height = $first_posY+$this->maxHeight;
|
||||
}
|
||||
|
||||
for($j=0;$j<$this->res;$j++)
|
||||
for($z=0;$z<$this->res;$z++)
|
||||
imageline($im,$this->positionX+$j+$z,$this->positionY,$this->positionX+$j+$z,$height,$bar_color);
|
||||
|
||||
for($j=0;$j<(2*$this->res);$j++)
|
||||
$this->nextX();
|
||||
}
|
||||
$this->positionY = $first_posY;
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* s25.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - Standard 2 of 5
|
||||
*
|
||||
* NOTE: It is really tough to read this barcode !
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class s25 extends BarCode {
|
||||
protected $keys = array(), $code = array();
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
private $checksum;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
* @param bool $checksum
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont,$checksum=false) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
|
||||
$this->code = array(
|
||||
'0000202000', /* 0 */
|
||||
'2000000020', /* 1 */
|
||||
'0020000020', /* 2 */
|
||||
'2020000000', /* 3 */
|
||||
'0000200020', /* 4 */
|
||||
'2000200000', /* 5 */
|
||||
'0020200000', /* 6 */
|
||||
'0000002020', /* 7 */
|
||||
'2000002000', /* 8 */
|
||||
'0020002000' /* 9 */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
$this->checksum = $checksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Must be even
|
||||
if(strlen($this->text) % 2 != 0 && $this->checksum == false) {
|
||||
$this->DrawError($im,'s25 must be even if checksum is false.');
|
||||
$error_stop = true;
|
||||
}
|
||||
elseif(strlen($this->text) % 2 == 0 && $this->checksum == true) {
|
||||
$this->DrawError($im,'s25 must be odd if checksum is true.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// We calculate checksum first
|
||||
// Odd Position has a weight of 1, Even Position has a weight of 3
|
||||
// Multiply to position
|
||||
// Sum all of that and mod 10
|
||||
if($this->checksum == true) {
|
||||
$checksum = 0;
|
||||
for($i=1;$i<=strlen($this->text);$i++) {
|
||||
$multiplier = (($i-1) % 2 != 0)?1:3;
|
||||
$checksum += $i*$multiplier;
|
||||
}
|
||||
$this->text .= $this->keys[$checksum % 10];
|
||||
}
|
||||
// Starting Code
|
||||
$this->DrawChar($im,'101000',1);
|
||||
// Chars
|
||||
for($i=0;$i<strlen($this->text);$i++)
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),1);
|
||||
// Ending Code
|
||||
$this->DrawChar($im,'10001',1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* upca.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - UPC-A
|
||||
*
|
||||
* UPC-A contains
|
||||
* - 2 system digits (1 not provided, a 0 is added automatically)
|
||||
* - 5 manufacturer code digits
|
||||
* - 5 product digits
|
||||
* - 1 checksum digit
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class upca extends BarCode {
|
||||
protected $keys = array(), $code = array(), $codeParity = array();
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
|
||||
// Left-Hand Odd Parity starting with a space
|
||||
// Left-Hand Even Parity is the inverse (0=0012) starting with a space
|
||||
// Right-Hand is the same of Left-Hand starting with a bar
|
||||
$this->code = array(
|
||||
'2100', /* 0 */
|
||||
'1110', /* 1 */
|
||||
'1011', /* 2 */
|
||||
'0300', /* 3 */
|
||||
'0021', /* 4 */
|
||||
'0120', /* 5 */
|
||||
'0003', /* 6 */
|
||||
'0201', /* 7 */
|
||||
'0102', /* 8 */
|
||||
'2001' /* 9 */
|
||||
);
|
||||
// Parity, 0=Odd, 1=Even for manufacturer code. Depending on 1st System Digit
|
||||
$this->codeParity = array(
|
||||
array(0,0,0,0,0), /* 0 */
|
||||
array(0,1,0,1,1), /* 1 */
|
||||
array(0,1,1,0,1), /* 2 */
|
||||
array(0,1,1,1,0), /* 3 */
|
||||
array(1,0,0,1,1), /* 4 */
|
||||
array(1,1,0,0,1), /* 5 */
|
||||
array(1,1,1,0,0), /* 6 */
|
||||
array(1,0,1,0,1), /* 7 */
|
||||
array(1,0,1,1,0), /* 8 */
|
||||
array(1,1,0,1,0) /* 9 */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
private function inverse($text,$inverse=1) {
|
||||
if($inverse == 1)
|
||||
$text = strrev($text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Must contains 11 chars
|
||||
if(strlen($this->text) != 11) {
|
||||
$this->DrawError($im,'Must contains 11 chars, the 12th digit is automatically added.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// The following code is exactly the same as EAN13. We just add a 0 in front of the code !
|
||||
$this->text = '0'.$this->text;
|
||||
|
||||
// Calculating Checksum
|
||||
// Consider the right-most digit of the message to be in an "odd" position,
|
||||
// and assign odd/even to each character moving from right to left
|
||||
// Odd Position = 3, Even Position = 1
|
||||
// Multiply it by the number
|
||||
// Add all of that and do 10-(?mod10)
|
||||
$odd = true;
|
||||
$checksum=0;
|
||||
for($i=strlen($this->text);$i>0;$i--) {
|
||||
if($odd==true) {
|
||||
$multiplier=3;
|
||||
$odd=false;
|
||||
}
|
||||
else {
|
||||
$multiplier=1;
|
||||
$odd=true;
|
||||
}
|
||||
$checksum += $this->keys[$this->text[$i - 1]] * $multiplier;
|
||||
}
|
||||
$checksum = 10 - $checksum % 10;
|
||||
$checksum = ($checksum == 10)?0:$checksum;
|
||||
$this->text .= $this->keys[$checksum];
|
||||
// If we have to write text, we move the barcode to the right to have space to put system digit
|
||||
$this->positionX = ($this->textfont == 0)?0:10;
|
||||
// Starting Code
|
||||
$this->DrawChar($im,'000',1);
|
||||
// Draw Second Code
|
||||
$this->DrawChar($im,$this->findCode($this->text[1]),2);
|
||||
// Draw Manufacturer Code
|
||||
for($i=0;$i<5;$i++)
|
||||
$this->DrawChar($im,$this->inverse($this->findCode($this->text[$i + 2]),$this->codeParity[$this->text[0]][$i]),2);
|
||||
// Draw Center Guard Bar
|
||||
$this->DrawChar($im,'00000',2);
|
||||
// Draw Product Code
|
||||
for($i=7;$i<13;$i++)
|
||||
$this->DrawChar($im,$this->findCode($this->text[$i]),1);
|
||||
// Draw Right Guard Bar
|
||||
$this->DrawChar($im,'000',1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded method for drawing special label
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
protected function DrawText($im) {
|
||||
if($this->textfont != 0) {
|
||||
$bar_color = (is_null($this->color1))?NULL:$this->color1->allocate($im);
|
||||
if(!is_null($bar_color)) {
|
||||
$rememberX = $this->positionX;
|
||||
$rememberH = $this->maxHeight;
|
||||
// We increase the bars
|
||||
|
||||
// First 2 Bars
|
||||
$this->maxHeight = $this->maxHeight + 9;
|
||||
$this->positionX = 10;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
$this->positionX += $this->res*2;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
|
||||
// Attemping to increase the 2 following bars
|
||||
$this->positionX += $this->res;
|
||||
$temp_value = $this->findCode($this->text[1]);
|
||||
$this->DrawChar($im,$temp_value,2);
|
||||
|
||||
// Center Guard Bar
|
||||
$this->positionX += $this->res*38;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
$this->positionX += $this->res*2;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
|
||||
// Attemping to increase the 2 last bars
|
||||
$this->positionX += $this->res*35;
|
||||
$temp_value = $this->findCode($this->text[12]);
|
||||
$this->DrawChar($im,$temp_value,1);
|
||||
|
||||
// Completly last bars
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
$this->positionX += $this->res*2;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
|
||||
|
||||
$this->positionX = $rememberX;
|
||||
$this->maxHeight = $rememberH;
|
||||
imagechar($im,$this->textfont,1,$this->maxHeight-(imagefontheight($this->textfont)/2),$this->text[1],$bar_color);
|
||||
imagestring($im,$this->textfont,10+(10*$this->res+48*$this->res)/2-imagefontwidth($this->textfont)*(5/2),$this->maxHeight+1,substr($this->text,2,5),$bar_color);
|
||||
imagestring($im,$this->textfont,10+46*$this->res+(3*$this->res+42*$this->res)/2-imagefontwidth($this->textfont)*(5/2),$this->maxHeight+1,substr($this->text,7,5),$bar_color);
|
||||
imagechar($im,$this->textfont,1+10+(46+48+3)*$this->res,$this->maxHeight-(imagefontheight($this->textfont)/2),$this->text[12],$bar_color);
|
||||
}
|
||||
$this->lastY = $this->maxHeight + imagefontheight($this->textfont);
|
||||
$this->lastX += 2+imagefontwidth($this->textfont);
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* upce.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - UPC-E
|
||||
*
|
||||
* You can provide a UPC-A code (without dash), the code will transform
|
||||
* it into a UPC-E format if it's possible.
|
||||
* UPC-E contains
|
||||
* - 1 system digits (not displayed but coded with parity)
|
||||
* - 6 digits
|
||||
* - 1 checksum digit (not displayed but coded with parity)
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class upce extends BarCode {
|
||||
protected $keys = array(), $code = array(), $codeParity = array();
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
|
||||
// Odd Parity starting with a space
|
||||
// Even Parity is the inverse (0=0012) starting with a space
|
||||
$this->code = array(
|
||||
'2100', /* 0 */
|
||||
'1110', /* 1 */
|
||||
'1011', /* 2 */
|
||||
'0300', /* 3 */
|
||||
'0021', /* 4 */
|
||||
'0120', /* 5 */
|
||||
'0003', /* 6 */
|
||||
'0201', /* 7 */
|
||||
'0102', /* 8 */
|
||||
'2001' /* 9 */
|
||||
);
|
||||
// Parity, 0=Odd, 1=Even for manufacturer code. Depending on 1st System Digit and Checksum
|
||||
$this->codeParity = array(
|
||||
array(
|
||||
array(1,1,1,0,0,0), /* 0,0 */
|
||||
array(1,1,0,1,0,0), /* 0,1 */
|
||||
array(1,1,0,0,1,0), /* 0,2 */
|
||||
array(1,1,0,0,0,1), /* 0,3 */
|
||||
array(1,0,1,1,0,0), /* 0,4 */
|
||||
array(1,0,0,1,1,0), /* 0,5 */
|
||||
array(1,0,0,0,1,1), /* 0,6 */
|
||||
array(1,0,1,0,1,0), /* 0,7 */
|
||||
array(1,0,1,0,0,1), /* 0,8 */
|
||||
array(1,0,0,1,0,1) /* 0,9 */
|
||||
),
|
||||
array(
|
||||
array(0,0,0,1,1,1), /* 0,0 */
|
||||
array(0,0,1,0,1,1), /* 0,1 */
|
||||
array(0,0,1,1,0,1), /* 0,2 */
|
||||
array(0,0,1,1,1,0), /* 0,3 */
|
||||
array(0,1,0,0,1,1), /* 0,4 */
|
||||
array(0,1,1,0,0,1), /* 0,5 */
|
||||
array(0,1,1,1,0,0), /* 0,6 */
|
||||
array(0,1,0,1,0,1), /* 0,7 */
|
||||
array(0,1,0,1,1,0), /* 0,8 */
|
||||
array(0,1,1,0,1,0) /* 0,9 */
|
||||
)
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
private function inverse($text,$inverse=1) {
|
||||
if($inverse==true)
|
||||
$text = strrev($text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
private function checksum($text) {
|
||||
$odd = true;
|
||||
$checksum=0;
|
||||
for($i=strlen($this->text);$i>0;$i--) {
|
||||
if($odd==true){
|
||||
$multiplier=3;
|
||||
$odd=false;
|
||||
}
|
||||
else{
|
||||
$multiplier=1;
|
||||
$odd=true;
|
||||
}
|
||||
$checksum += $this->keys[$this->text[$i - 1]] * $multiplier;
|
||||
}
|
||||
$checksum = 10 - $checksum % 10;
|
||||
$checksum = ($checksum == 10)?0:$checksum;
|
||||
return $checksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Must contains 11 chars
|
||||
// Must contains 8 chars (if starting with upce directly)
|
||||
// First Chars must be 0 or 1
|
||||
if(strlen($this->text) != 11 && strlen($this->text) != 6) {
|
||||
$this->DrawError($im,'Provide an UPC-A (11 chars) or');
|
||||
$this->DrawError($im,'You can also provide UPC-E directly (6 chars).');
|
||||
$error_stop = true;
|
||||
}
|
||||
elseif($this->text[0] != '0' && $this->text[0] != '1' && strlen($this->text) != 6) {
|
||||
$this->DrawError($im,'Must starts with 0 or 1.');
|
||||
$error_stop = true;
|
||||
}
|
||||
|
||||
if($error_stop == false) {
|
||||
if(strlen($this->text) != 6) {
|
||||
// Checking if UPC-A is convertible
|
||||
$upce = '';
|
||||
if(substr($this->text,3,3) == '000' || substr($this->text,3,3) == '100' || substr($this->text,3,3) == '200') { // manufacturer code ends with 100,200 or 300
|
||||
if(substr($this->text,6,2) == '00') // Product must start with 00
|
||||
$upce = substr($this->text,1,2).substr($this->text,8,3).substr($this->text,3,1);
|
||||
else
|
||||
$error_stop = true;
|
||||
}
|
||||
elseif(substr($this->text,4,2) == '00') { // manufacturer code ends with 00
|
||||
if(substr($this->text,6,3) == '000') // Product must start with 000
|
||||
$upce = substr($this->text,1,3).substr($this->text,9,2).'3';
|
||||
else
|
||||
$error_stop = true;
|
||||
}
|
||||
elseif(substr($this->text,5,1) == '0') { // manufacturer code ends with 0
|
||||
if(substr($this->text,6,4) == '0000') // Product must start with 0000
|
||||
$upce = substr($this->text,1,4).substr($this->text,10,1).'4';
|
||||
else
|
||||
$error_stop = true;
|
||||
}
|
||||
else{ // No zero leading at manufacturer code
|
||||
if(substr($this->text,6,4) == '0000' && intval(substr($this->text,10,1)) >= 5 && intval(substr($this->text,10,1)) <= 9) // Product must start with 0000 and must over by 5,6,7,8 or 9
|
||||
$upce = substr($this->text,1,5).substr($this->text,10,1);
|
||||
else
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
$upce = $this->text;
|
||||
|
||||
if($error_stop == false) {
|
||||
// Calculating Checksum
|
||||
// Consider the right-most digit of the message to be in an "odd" position,
|
||||
// and assign odd/even to each character moving from right to left
|
||||
// Odd Position = 3, Even Position = 1
|
||||
// Multiply it by the number
|
||||
// Add all of that and do 10-(?mod10)
|
||||
if(strlen($this->text) != 6)
|
||||
$checksum = $this->checksum($this->text);
|
||||
else {
|
||||
// We convert UPC-E to UPC-A to find the checksum
|
||||
if($this->text[5] == '0' || $this->text[5] == '1' || $this->text[5] == '2')
|
||||
$upca = substr($this->text,0,2).$this->text[5].'0000'.substr($this->text,2,3);
|
||||
elseif($this->text[5] == '3')
|
||||
$upca = substr($this->text,0,3).'00000'.substr($this->text,3,2);
|
||||
elseif($this->text[5] == '4')
|
||||
$upca = substr($this->text,0,4).'00000'.$this->text[4];
|
||||
else
|
||||
$upca = substr($this->text,0,5).'0000'.$this->text[5];
|
||||
$this->text = '0'.$upca;
|
||||
$checksum = $this->checksum($this->text);
|
||||
}
|
||||
// If we have to write text, we move the barcode to the right to have space to put system digit
|
||||
$this->positionX = ($this->textfont == 0)?0:10;
|
||||
// Starting Code
|
||||
$this->DrawChar($im,'000',1);
|
||||
for($i=0;$i<strlen($upce);$i++)
|
||||
$this->DrawChar($im,$this->inverse($this->findCode($upce[$i]),$this->codeParity[$this->text[0]][$checksum][$i]),2);
|
||||
// Draw Center Guard Bar
|
||||
$this->DrawChar($im,'00000',2);
|
||||
// Draw Right Bar
|
||||
$this->DrawChar($im,'0',1);
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->text = $this->text[0].$upce.$checksum;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
else
|
||||
$this->DrawError($im,'Your UPC-A can\'t be converted to UPC-E.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded method for drawing special label
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
protected function DrawText($im) {
|
||||
if($this->textfont != 0) {
|
||||
$bar_color = (is_null($this->color1))?NULL:$this->color1->allocate($im);
|
||||
if(!is_null($bar_color)) {
|
||||
$rememberX = $this->positionX;
|
||||
$rememberH = $this->maxHeight;
|
||||
// We increase the bars
|
||||
$this->maxHeight = $this->maxHeight + 9;
|
||||
$this->positionX = 10;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
$this->positionX += $this->res*2;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
// Last Bars
|
||||
$this->positionX += $this->res*46;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
$this->positionX += $this->res*2;
|
||||
$this->DrawSingleBar($im,$this->color1);
|
||||
|
||||
$this->positionX = $rememberX;
|
||||
$this->maxHeight = $rememberH;
|
||||
imagechar($im,$this->textfont,1,$this->maxHeight-(imagefontheight($this->textfont)/2),$this->text[0],$bar_color);
|
||||
imagestring($im,$this->textfont,10+(4*$this->res+48*$this->res)/2-imagefontwidth($this->textfont)*(6/2),$this->maxHeight+1,substr($this->text,1,6),$bar_color);
|
||||
imagechar($im,$this->textfont,2+10+(48+4)*$this->res,$this->maxHeight-(imagefontheight($this->textfont)/2),$this->text[7],$bar_color);
|
||||
}
|
||||
$this->lastY = $this->maxHeight + imagefontheight($this->textfont);
|
||||
$this->lastX += 2 + imagefontwidth($this->textfont);
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* upcext2.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - UPC Supplemental Barcode 2 digits
|
||||
*
|
||||
* Working with UPC-A, UPC-E, EAN-13, EAN-8
|
||||
* This includes 2 digits (normaly for publications)
|
||||
* Must be placed next to UPC or EAN Code
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class upcext2 extends BarCode {
|
||||
protected $keys = array(), $code = array(), $codeParity = array();
|
||||
private $starting, $ending;
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
|
||||
$this->code = array(
|
||||
'2100', /* 0 */
|
||||
'1110', /* 1 */
|
||||
'1011', /* 2 */
|
||||
'0300', /* 3 */
|
||||
'0021', /* 4 */
|
||||
'0120', /* 5 */
|
||||
'0003', /* 6 */
|
||||
'0201', /* 7 */
|
||||
'0102', /* 8 */
|
||||
'2001' /* 9 */
|
||||
);
|
||||
// Parity, 0=Odd, 1=Even. Depending on ?%4
|
||||
$this->codeParity = array(
|
||||
array(0,0), /* 0 */
|
||||
array(0,1), /* 1 */
|
||||
array(1,0), /* 2 */
|
||||
array(1,1) /* 3 */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text){
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
private function inverse($text,$inverse=1) {
|
||||
if($inverse == 1)
|
||||
$text = strrev($text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Must contains 2 chars
|
||||
if(strlen($this->text) != 2) {
|
||||
$this->DrawError($im,'Must contains 2 chars.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// If we have to write text, we move the barcode to the bottom to put text
|
||||
$this->positionY = ($this->textfont == 0)?0:15;
|
||||
// Starting Code
|
||||
$this->DrawChar($im,'001',1);
|
||||
// Code
|
||||
for($i=0;$i<2;$i++){
|
||||
$this->DrawChar($im,$this->inverse($this->findCode($this->text[$i]),$this->codeParity[intval($this->text%4)][$i]),2);
|
||||
if($i == 0)
|
||||
$this->DrawChar($im,'00',2); // Inter-char
|
||||
}
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded method for drawing special label
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
protected function DrawText($im) {
|
||||
if($this->textfont != 0) {
|
||||
$bar_color = (is_null($this->color1))?NULL:$this->color1->allocate($im);
|
||||
if(!is_null($bar_color))
|
||||
imagestring($im,$this->textfont,$this->positionX/2-imagefontwidth($this->textfont)*(strlen($this->text)/2),1,$this->text,$bar_color);
|
||||
$this->lastY += 15;
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
|
||||
|
||||
/**
|
||||
* upcext5.php
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Sub-Class - UPC Supplemental Barcode 2 digits
|
||||
*
|
||||
* Working with UPC-A, UPC-E, EAN-13, EAN-8
|
||||
* This includes 5 digits (normaly for suggested retail price)
|
||||
* Must be placed next to UPC or EAN Code
|
||||
* If 90000 -> No suggested Retail Price
|
||||
* If 99991 -> Book Complimentary (normally free)
|
||||
* If 90001 to 98999 -> Internal Purpose of Publisher
|
||||
* If 99990 -> Used by the National Association of College Stores to mark used books
|
||||
* If 0xxxx -> Price Expressed in British Pounds (xx.xx)
|
||||
* If 5xxxx -> Price Expressed in U.S. dollars (US$xx.xx)
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* Revision History
|
||||
* V1.00 17 jun 2004 Jean-Sebastien Goupil
|
||||
*--------------------------------------------------------------------
|
||||
* Copyright (C) Jean-Sebastien Goupil
|
||||
* http://other.lookstrike.com/barcode/
|
||||
*/
|
||||
class upcext5 extends BarCode {
|
||||
protected $keys = array(), $code = array(), $codeParity = array();
|
||||
private $starting, $ending;
|
||||
protected $text;
|
||||
protected $textfont;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $maxHeight
|
||||
* @param FColor $color1
|
||||
* @param FColor $color2
|
||||
* @param int $res
|
||||
* @param string $text
|
||||
* @param int $textfont
|
||||
*/
|
||||
public function __construct($maxHeight,FColor $color1,FColor $color2,$res,$text,$textfont) {
|
||||
BarCode::__construct($maxHeight,$color1,$color2,$res);
|
||||
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
|
||||
$this->code = array(
|
||||
'2100', /* 0 */
|
||||
'1110', /* 1 */
|
||||
'1011', /* 2 */
|
||||
'0300', /* 3 */
|
||||
'0021', /* 4 */
|
||||
'0120', /* 5 */
|
||||
'0003', /* 6 */
|
||||
'0201', /* 7 */
|
||||
'0102', /* 8 */
|
||||
'2001' /* 9 */
|
||||
);
|
||||
// Parity, 0=Odd, 1=Even. Depending Checksum
|
||||
$this->codeParity = array(
|
||||
array(1,1,0,0,0), /* 0 */
|
||||
array(1,0,1,0,0), /* 1 */
|
||||
array(1,0,0,1,0), /* 2 */
|
||||
array(1,0,0,0,1), /* 3 */
|
||||
array(0,1,1,0,0), /* 4 */
|
||||
array(0,0,1,1,0), /* 5 */
|
||||
array(0,0,0,1,1), /* 6 */
|
||||
array(0,1,0,1,0), /* 7 */
|
||||
array(0,1,0,0,1), /* 8 */
|
||||
array(0,0,1,0,1) /* 9 */
|
||||
);
|
||||
$this->setText($text);
|
||||
$this->textfont = $textfont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text){
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
private function inverse($text,$inverse=1) {
|
||||
if($inverse == 1)
|
||||
$text = strrev($text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
public function draw($im) {
|
||||
$error_stop = false;
|
||||
|
||||
// Checking if all chars are allowed
|
||||
for($i=0;$i<strlen($this->text);$i++) {
|
||||
if(!is_int(array_search($this->text[$i],$this->keys))) {
|
||||
$this->DrawError($im,'Char \''.$this->text[$i].'\' not allowed.');
|
||||
$error_stop = true;
|
||||
}
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Must contains 5 chars
|
||||
if(strlen($this->text) != 5) {
|
||||
$this->DrawError($im,'Must contains 5 chars.');
|
||||
$error_stop = true;
|
||||
}
|
||||
if($error_stop == false) {
|
||||
// Calculating Checksum
|
||||
// Consider the right-most digit of the message to be in an "odd" position,
|
||||
// and assign odd/even to each character moving from right to left
|
||||
// Odd Position = 3, Even Position = 9
|
||||
// Multiply it by the number
|
||||
// Add all of that and do 10-(?mod10)
|
||||
$odd = true;
|
||||
$checksum=0;
|
||||
for($i=strlen($this->text);$i>0;$i--) {
|
||||
if($odd==true) {
|
||||
$multiplier=3;
|
||||
$odd=false;
|
||||
}
|
||||
else {
|
||||
$multiplier=9;
|
||||
$odd=true;
|
||||
}
|
||||
$checksum += $this->keys[$this->text[$i - 1]] * $multiplier;
|
||||
}
|
||||
$checksum = intval(substr(strval($checksum),strlen(strval($checksum))-1,1));
|
||||
// If we have to write text, we move the barcode to the bottom to put text
|
||||
$this->positionY = ($this->textfont == 0)?0:15;
|
||||
// Starting Code
|
||||
$this->DrawChar($im,'001',1);
|
||||
// Code
|
||||
for($i=0;$i<5;$i++){
|
||||
$this->DrawChar($im,$this->inverse($this->findCode($this->text[$i]),$this->codeParity[$checksum][$i]),2);
|
||||
if($i < 4)
|
||||
$this->DrawChar($im,'00',2); // Inter-char
|
||||
}
|
||||
$this->lastX = $this->positionX;
|
||||
$this->lastY = $this->maxHeight;
|
||||
$this->DrawText($im);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded method for drawing special label
|
||||
*
|
||||
* @param ressource $im
|
||||
*/
|
||||
protected function DrawText($im) {
|
||||
if($this->textfont != 0) {
|
||||
$bar_color = (is_null($this->color1))?NULL:$this->color1->allocate($im);
|
||||
if(!is_null($bar_color))
|
||||
imagestring($im,$this->textfont,$this->positionX/2-imagefontwidth($this->textfont)*(strlen($this->text)/2),1,$this->text,$bar_color);
|
||||
$this->lastY += 15;
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
Reference in new issue
Block a user