Submit
Path:
~
/
home
/
caratcollect
/
public_html
/
Demo
/
admin
/
barcodegen
/
class
/
File Content:
BCGisbn.barcode.php
<?php /** *-------------------------------------------------------------------- * * Sub-Class - ISBN-10 and ISBN-13 * * You can provide an ISBN with 10 digits with or without the checksum. * You can provide an ISBN with 13 digits with or without the checksum. * Calculate the ISBN based on the EAN-13 encoding. * * The checksum is always displayed. * *-------------------------------------------------------------------- * Copyright (C) Jean-Sebastien Goupil * http://www.barcodephp.com */ include_once('BCGParseException.php'); include_once('BCGArgumentException.php'); include_once('BCGean13.barcode.php'); class BCGisbn extends BCGean13 { const GS1_AUTO = 0; const GS1_PREFIX978 = 1; const GS1_PREFIX979 = 2; private $gs1; /** * Constructor. * * @param int $gs1 */ public function __construct($gs1 = self::GS1_AUTO) { parent::__construct(); $this->setGS1($gs1); } /** * Adds the default label. */ protected function addDefaultLabel() { if ($this->isDefaultEanLabelEnabled()) { $isbn = $this->createISBNText(); $font = $this->font; $topLabel = new BCGLabel($isbn, $font, BCGLabel::POSITION_TOP, BCGLabel::ALIGN_CENTER); $this->addLabel($topLabel); } parent::addDefaultLabel(); } /** * Sets the first numbers of the barcode. * - GS1_AUTO: Adds 978 before the code * - GS1_PREFIX978: Adds 978 before the code * - GS1_PREFIX979: Adds 979 before the code * * @param int $gs1 */ public function setGS1($gs1) { $gs1 = (int)$gs1; if ($gs1 !== self::GS1_AUTO && $gs1 !== self::GS1_PREFIX978 && $gs1 !== self::GS1_PREFIX979) { throw new BCGArgumentException('The GS1 argument must be BCGisbn::GS1_AUTO, BCGisbn::GS1_PREFIX978, or BCGisbn::GS1_PREFIX979', 'gs1'); } $this->gs1 = $gs1; } /** * Check chars allowed. */ protected function checkCharsAllowed() { $c = strlen($this->text); // Special case, if we have 10 digits, the last one can be X if ($c === 10) { if (array_search($this->text[9], $this->keys) === false && $this->text[9] !== 'X') { throw new BCGParseException('isbn', 'The character \'' . $this->text[9] . '\' is not allowed.'); } // Drop the last char $this->text = substr($this->text, 0, 9); } return parent::checkCharsAllowed(); } /** * Check correct length. */ protected function checkCorrectLength() { $c = strlen($this->text); // If we have 13 chars just flush the last one if ($c === 13) { $this->text = substr($this->text, 0, 12); } elseif ($c === 9 || $c === 10) { if ($c === 10) { // Before dropping it, we check if it's legal if (array_search($this->text[9], $this->keys) === false && $this->text[9] !== 'X') { throw new BCGParseException('isbn', 'The character \'' . $this->text[9] . '\' is not allowed.'); } $this->text = substr($this->text, 0, 9); } if ($this->gs1 === self::GS1_AUTO || $this->gs1 === self::GS1_PREFIX978) { $this->text = '978' . $this->text; } elseif ($this->gs1 === self::GS1_PREFIX979) { $this->text = '979' . $this->text; } } elseif ($c !== 12) { throw new BCGParseException('isbn', 'The code parsed must be 9, 10, 12, or 13 digits long.'); } } /** * Creates the ISBN text. * * @return string */ private function createISBNText() { $isbn = ''; if (!empty($this->text)) { // We try to create the ISBN Text... the hyphen really depends the ISBN agency. // We just put one before the checksum and one after the GS1 if present. $c = strlen($this->text); if ($c === 12 || $c === 13) { // If we have 13 characters now, just transform it temporarily to find the checksum... // Further in the code we take care of that anyway. $lastCharacter = ''; if ($c === 13) { $lastCharacter = $this->text[12]; $this->text = substr($this->text, 0, 12); } $checksum = $this->processChecksum(); $isbn = 'ISBN ' . substr($this->text, 0, 3) . '-' . substr($this->text, 3, 9) . '-' . $checksum; // Put the last character back if ($c === 13) { $this->text .= $lastCharacter; } } elseif ($c === 9 || $c === 10) { $checksum = 0; for ($i = 10; $i >= 2; $i--) { $checksum += $this->text[10 - $i] * $i; } $checksum = 11 - $checksum % 11; if ($checksum === 10) { $checksum = 'X'; } $isbn = 'ISBN ' . substr($this->text, 0, 9) . '-' . $checksum; } } return $isbn; } } ?>
Submit
FILE
FOLDER
Name
Size
Permission
Action
drawer
---
0755
BCGArgumentException.php
600 bytes
0644
BCGBarcode.php
14444 bytes
0644
BCGBarcode1D.php
6631 bytes
0644
BCGColor.php
4175 bytes
0644
BCGDrawException.php
486 bytes
0644
BCGDrawing.php
6287 bytes
0644
BCGFont.php
728 bytes
0644
BCGFontFile.php
4849 bytes
0644
BCGFontPhp.php
3451 bytes
0644
BCGLabel.php
7901 bytes
0644
BCGParseException.php
604 bytes
0644
BCGcodabar.barcode.php
3740 bytes
0644
BCGcode11.barcode.php
5234 bytes
0644
BCGcode128.barcode.php
29097 bytes
0644
BCGcode39.barcode.php
5677 bytes
0644
BCGcode39extended.barcode.php
6290 bytes
0644
BCGcode93.barcode.php
9600 bytes
0644
BCGean13.barcode.php
9895 bytes
0644
BCGean8.barcode.php
7411 bytes
0644
BCGgs1128.barcode.php
25845 bytes
0644
BCGi25.barcode.php
5708 bytes
0644
BCGintelligentmail.barcode.php
28550 bytes
0644
BCGisbn.barcode.php
5304 bytes
0644
BCGmsi.barcode.php
5206 bytes
0644
BCGothercode.barcode.php
1834 bytes
0644
BCGpostnet.barcode.php
3758 bytes
0644
BCGs25.barcode.php
4765 bytes
0644
BCGupca.barcode.php
5143 bytes
0644
BCGupce.barcode.php
11973 bytes
0644
BCGupcext2.barcode.php
3670 bytes
0644
BCGupcext5.barcode.php
5736 bytes
0644
JoinDraw.php
5878 bytes
0644
N4ST4R_ID | Naxtarrr