|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00025 require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; 00026 00033 class Zend_Validate_Barcode_Code93 extends Zend_Validate_Barcode_AdapterAbstract 00034 { 00039 protected $_length = -1; 00040 00045 protected $_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ -.$/+%'; 00046 00051 protected $_checksum = '_code93'; 00052 00057 protected $_check = array( 00058 '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, 00059 '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 00060 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 00061 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, 00062 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, 00063 'Z' => 35, '-' => 36, '.' => 37, ' ' => 38, '$' => 39, '/' => 40, '+' => 41, 00064 '%' => 42, '!' => 43, '"' => 44, 'ยง' => 45, '&' => 46, 00065 ); 00066 00074 public function __construct() 00075 { 00076 $this->setCheck(false); 00077 } 00078 00085 protected function _code93($value) 00086 { 00087 $checksum = substr($value, -2, 2); 00088 $value = str_split(substr($value, 0, -2)); 00089 $count = 0; 00090 $length = count($value) % 20; 00091 foreach($value as $char) { 00092 if ($length == 0) { 00093 $length = 20; 00094 } 00095 00096 $count += $this->_check[$char] * $length; 00097 --$length; 00098 } 00099 00100 $check = array_search(($count % 47), $this->_check); 00101 $value[] = $check; 00102 $count = 0; 00103 $length = count($value) % 15; 00104 foreach($value as $char) { 00105 if ($length == 0) { 00106 $length = 15; 00107 } 00108 00109 $count += $this->_check[$char] * $length; 00110 --$length; 00111 } 00112 $check .= array_search(($count % 47), $this->_check); 00113 00114 if ($check == $checksum) { 00115 return true; 00116 } 00117 00118 return false; 00119 } 00120 }