commit | author | age
|
175a52
|
1 |
<?php |
JK |
2 |
class validate { |
|
3 |
static $kod = FALSE; |
|
4 |
|
|
5 |
static function KOD(&$kod, $exists=NULL) { |
|
6 |
if(ltrim($kod, '0123456789')!='' OR strlen($kod)>8 OR strlen($kod)<1) { |
bc710e
|
7 |
errorclass::add('Błędny KOD - dozwolone tylko cyfry'); |
175a52
|
8 |
} |
JK |
9 |
|
|
10 |
$kod = str_pad($kod, 8, '0', STR_PAD_LEFT); |
|
11 |
|
|
12 |
if(!is_null($exists)) { |
|
13 |
if($exists!==ksiazki::exists($kod)) { |
bc710e
|
14 |
errorclass::add('Wybrana książka '.($exists ? 'nie' : 'już').' istnieje!'); |
175a52
|
15 |
} |
JK |
16 |
} |
|
17 |
} |
|
18 |
|
|
19 |
static function EAN($kod) { |
|
20 |
if( ltrim($kod, '0123456789') != '' OR strlen($kod) != 13 ) { |
bc710e
|
21 |
errorclass::add('Błędny ISN - dozwolone tylko cyfry'); |
175a52
|
22 |
} |
JK |
23 |
|
|
24 |
if( substr($kod, -1) != checksum::EAN(substr($kod, 0, -1)) ) { |
bc710e
|
25 |
errorclass::add('Podany kod ISN jest błędny'); |
175a52
|
26 |
} |
JK |
27 |
} |
|
28 |
|
|
29 |
static function ISBN(&$kod) { |
|
30 |
$kod = str_replace('-', '', strtoupper($kod)); |
|
31 |
if( ltrim($kod, '0123456789X') != '' OR strlen($kod) != 10 ) { |
bc710e
|
32 |
errorclass::add('Błędny ISBN - dozwolone tylko cyfry i znak X'); |
175a52
|
33 |
} |
JK |
34 |
|
|
35 |
if( substr($kod, -1) != checksum::ISBN(substr($kod, 0, -1)) ) { |
bc710e
|
36 |
errorclass::add('Podany ISBN jest błędny'); |
175a52
|
37 |
} |
JK |
38 |
} |
|
39 |
|
|
40 |
static function ISSN(&$kod) { |
|
41 |
$kod = str_replace('-', '', strtoupper($kod)); |
|
42 |
if( ltrim($kod, '0123456789X') != '' OR strlen($kod) != 8 ) { |
bc710e
|
43 |
errorclass::add('Błędny ISSN - dozwolone tylko cyfry'); |
175a52
|
44 |
} |
JK |
45 |
|
|
46 |
if( substr($kod, -1) != checksum::ISSN(substr($kod, 0, -1)) ) { |
bc710e
|
47 |
errorclass::add('Podany ISSN jest błędny'); |
175a52
|
48 |
} |
JK |
49 |
} |
|
50 |
|
|
51 |
static function MSC(&$kod, $polka=NULL, $rzad=NULL) { |
|
52 |
$kod = strtoupper($kod); |
|
53 |
|
|
54 |
if($polka===NULL) { |
|
55 |
$polka = $_GET['polka']; |
|
56 |
} |
|
57 |
if($rzad===NULL) { |
|
58 |
$rzad = $_GET['rzad']; |
|
59 |
} |
|
60 |
|
|
61 |
if(!ctype_alnum($kod) OR ctype_digit($kod) OR $kod=='' OR strlen($kod)>5) { |
bc710e
|
62 |
errorclass::add('Podany kod miejsca (regał) jest błędny'); |
175a52
|
63 |
} |
JK |
64 |
if($polka!='' AND (!ctype_digit($polka) OR $polka>255)) { |
bc710e
|
65 |
errorclass::add('Podany kod miejsca (półka) jest błędny'); |
175a52
|
66 |
} |
JK |
67 |
if($rzad!='' AND (!ctype_digit($rzad) OR $rzad>255)) { |
bc710e
|
68 |
errorclass::add('Podany kod miejsca (rząd) jest błędny'); |
175a52
|
69 |
} |
JK |
70 |
} |
|
71 |
|
|
72 |
static function type(&$kod) { |
|
73 |
$kod = str_replace('-', '', $kod); |
|
74 |
|
|
75 |
switch(strlen($kod)) { |
|
76 |
case 13: |
|
77 |
self::EAN($kod); |
|
78 |
|
|
79 |
if(substr($kod, 0, 3)=='978' OR substr($kod, 0, 3)=='979') { |
|
80 |
return 'ISBN'; |
|
81 |
} |
|
82 |
elseif(substr($kod, 0, 3)=='977') { |
|
83 |
return 'ISSN'; |
|
84 |
} |
|
85 |
break; |
|
86 |
case 9: |
|
87 |
if(self::$kod) { |
|
88 |
$kod = substr($kod, 1); |
|
89 |
self::ISSN($kod); |
|
90 |
$kod = convert::ISSN8_to_ISSN13($kod); |
|
91 |
return 'ISSN'; |
|
92 |
} |
|
93 |
break; |
|
94 |
case 8: |
|
95 |
if(self::$kod) { |
|
96 |
self::KOD($kod); |
|
97 |
return 'KOD'; |
|
98 |
} |
|
99 |
else |
|
100 |
{ |
|
101 |
self::ISSN($kod); |
|
102 |
$kod = convert::ISSN8_to_ISSN13($kod); |
|
103 |
return 'ISSN'; |
|
104 |
} |
|
105 |
break; |
|
106 |
case 10: |
|
107 |
self::ISBN($kod); |
|
108 |
$kod = convert::ISBN10_to_ISBN13($kod); |
|
109 |
return 'ISBN'; |
|
110 |
break; |
|
111 |
default: |
|
112 |
if(self::$kod AND ctype_digit($kod)) { |
|
113 |
self::KOD($kod); |
|
114 |
return 'KOD'; |
|
115 |
} |
|
116 |
break; |
|
117 |
} |
|
118 |
|
|
119 |
if(self::$kod) { |
|
120 |
self::MSC($kod); |
|
121 |
return 'MSC'; |
|
122 |
} |
|
123 |
|
bc710e
|
124 |
errorclass::add('Nieznany typ kodu'); |
175a52
|
125 |
} |
JK |
126 |
} |
532779
|
127 |
?> |