commit | author | age
|
175a52
|
1 |
<?php |
JK |
2 |
class ksiazki_cache { |
|
3 |
static $cache = array(); |
|
4 |
|
|
5 |
static function cache_get($kod) { |
|
6 |
$kod = (int)$kod; |
|
7 |
|
|
8 |
if(!isset(self::$cache[(int)$kod])) { |
|
9 |
self::cache_update($kod); |
|
10 |
} |
|
11 |
|
|
12 |
return self::$cache[(int)$kod]; |
|
13 |
} |
|
14 |
|
|
15 |
static function cache_add($kod, &$dane) { |
|
16 |
if($dane['od2']) { |
|
17 |
$dane['od'] = $dane['od2']; |
|
18 |
unset($dane['od2']); |
|
19 |
} |
|
20 |
self::$cache[(int)$kod] = $dane; |
|
21 |
} |
|
22 |
|
|
23 |
static function cache_addarray(&$dane) { |
|
24 |
foreach($dane as &$r) { |
|
25 |
self::cache_add($r['id'], $r); |
|
26 |
} |
|
27 |
} |
|
28 |
|
|
29 |
static function cache_clear($id=NULL) { |
|
30 |
if(is_null($id)) { |
|
31 |
self::$cache = array(); |
|
32 |
} |
|
33 |
else |
|
34 |
{ |
|
35 |
unset(self::$cache[(int)$id]); |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
static function cache_update($kod) { |
|
40 |
$dane = db2::escape_data(sql::fetchone(sql::query('SELECT *, (SELECT MAX(`od`) FROM `pozycz` WHERE `pozycz`.`id`=`ksiazki`.`id`) as `od2`, (SELECT `do` FROM `pozycz` WHERE `pozycz`.`id`=`ksiazki`.`id` AND `od`=`od2`) as `do`, (SELECT `kto` FROM `pozycz` WHERE `pozycz`.`id`=`ksiazki`.`id` AND `od`=`od2`) as `kto` FROM `ksiazki` WHERE `id`=\''.sql::escape($kod).'\''))); |
|
41 |
self::cache_add($kod, $dane); |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
class ksiazki extends ksiazki_cache { |
|
46 |
static function okladka($KOD, $ISBN) { |
|
47 |
return okladki::znajdz($KOD, $ISBN, 'covers'); |
|
48 |
} |
|
49 |
|
|
50 |
static function okladka_big($KOD, $ISBN) { |
|
51 |
return okladki::znajdz($KOD, $ISBN, 'covers_big'); |
|
52 |
} |
|
53 |
|
|
54 |
static function dodaj(&$dane) { |
|
55 |
validate::KOD($dane['id'], FALSE); |
|
56 |
|
|
57 |
if($dane['ISBN']) { |
|
58 |
$t = validate::type($dane['ISBN']); |
|
59 |
if($t!='ISBN') { |
|
60 |
error::add('W polu ISBN znajduje się '.$t); |
|
61 |
} |
|
62 |
} |
|
63 |
if($dane['ISSN']) { |
|
64 |
$t = validate::type($dane['ISSN']); |
|
65 |
if($t!='ISSN') { |
|
66 |
error::add('W polu ISSN znajduje się '.$t); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
if($dane['jezyk']=='pol') { |
|
71 |
$dane['jezyk'] = 'polski'; |
|
72 |
} |
|
73 |
|
|
74 |
unset($_POST['okladka']); |
|
75 |
|
|
76 |
okladki::upload($_FILES['okladka'], $dane['id'], $dane['ISBN']); |
|
77 |
|
|
78 |
db2::add('ksiazki', $dane); |
|
79 |
self::cache_update($dane['id']); |
|
80 |
} |
|
81 |
|
|
82 |
static function exists($kod) { |
|
83 |
$info = self::cache_get($kod); |
|
84 |
if(isset($info['id'])) { |
|
85 |
return TRUE; |
|
86 |
} |
|
87 |
else |
|
88 |
{ |
|
89 |
return FALSE; |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
static function edytuj(&$dane) { |
|
94 |
validate::KOD($dane['id']); |
|
95 |
$kod = $dane['id']; |
|
96 |
|
|
97 |
$old = self::szukaj_KOD($kod); |
|
98 |
|
|
99 |
if($dane['id']=='' OR empty($dane['autor']) OR empty($dane['tytul']) OR empty($dane['jezyk'])) { |
|
100 |
error::add('Brak wymaganych danych o książce (kod, autor, tytuł, język)'); |
|
101 |
} |
|
102 |
|
|
103 |
if($dane['nid']!='') { |
|
104 |
validate::KOD($dane['nid']); |
|
105 |
$dane['id'] = $dane['nid']; |
|
106 |
} |
|
107 |
|
|
108 |
unset($dane['nid']); |
|
109 |
|
|
110 |
if($dane['ISBN']) { |
|
111 |
$t = validate::type($dane['ISBN']); |
|
112 |
if($t!='ISBN') { |
|
113 |
error::add('W polu ISBN znajduje się '.$t); |
|
114 |
} |
|
115 |
} |
|
116 |
if($dane['ISSN']) { |
|
117 |
$t = validate::type($dane['ISSN']); |
|
118 |
if($t!='ISSN') { |
|
119 |
error::add('W polu ISSN znajduje się '.$t); |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
if(!$dane['wycofana']) { |
|
124 |
$dane['wycofana'] = 0; |
|
125 |
$dane['powod'] = NULL; |
|
126 |
} |
|
127 |
|
|
128 |
okladki::przenies($old['id'], $old['ISBN'], $dane['id'], $dane['ISBN']); |
|
129 |
|
|
130 |
unset($_POST['okladka']); |
|
131 |
|
|
132 |
// Nowa okładka |
|
133 |
if(isset($_POST['okladka_del']) || (isset($_FILES['okladka']) && is_uploaded_file($_FILES['okladka']['tmp_name']))) { |
|
134 |
okladki::usun($dane['id'], $dane['ISBN']); |
|
135 |
unset($_POST['okladka_del']); |
|
136 |
} |
|
137 |
|
|
138 |
okladki::upload($_FILES['okladka'], $dane['id'], $dane['ISBN']); |
|
139 |
|
|
140 |
db2::edit('ksiazki', $dane, array('id' => $kod)); |
|
141 |
self::cache_update($kod); |
|
142 |
if($dane['id']!=$kod) { |
|
143 |
self::cache_update($dane['id']); |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
static function miejsce($regal, $polka, $rzad, $where) { |
|
148 |
db2::edit('ksiazki', array('regal' => strtoupper($regal), 'polka' => $polka, 'rzad' => $rzad), $where); |
|
149 |
self::cache_clear(); |
|
150 |
} |
|
151 |
|
|
152 |
static function usun(&$kod) { |
|
153 |
validate::KOD($kod); |
|
154 |
|
|
155 |
$dane = self::szukaj_KOD($kod); |
|
156 |
|
|
157 |
okladki::usun($dane['id'], $dane['ISBN']); |
|
158 |
|
|
159 |
db2::del('ksiazki', array('id' => $kod)); |
|
160 |
self::cache_clear($kod); |
|
161 |
} |
|
162 |
|
|
163 |
static function szukaj_KOD($kod) { |
|
164 |
validate::KOD($kod, TRUE); |
|
165 |
|
|
166 |
return self::cache_get($kod); |
|
167 |
} |
|
168 |
|
|
169 |
static function szukaj_ISBN($ISBN) { |
|
170 |
validate::EAN($ISBN); |
|
171 |
|
|
172 |
return db2::get('ksiazki', '*', array('ISBN' => $ISBN), NULL, 10); |
|
173 |
} |
|
174 |
|
|
175 |
static function szukaj_ISSN($ISSN) { |
|
176 |
validate::EAN($ISSN); |
|
177 |
|
|
178 |
return db2::get('ksiazki', '*', array('ISSN' => $ISSN), NULL, 10); |
|
179 |
} |
|
180 |
|
|
181 |
static function szukaj_info($dane, $order=NULL, $start=NULL, $limit=30) { |
|
182 |
$allow = array('id', 'tytul', 'autor', 'wydawnictwo', 'miejsce', 'rok', 'wydanie', 'wycofana'); |
|
183 |
$replace = array('tytul' => 'tytul~~', 'autor' => 'autor~~', 'wydawnictwo' => 'wydawnictwo~~'); |
|
184 |
|
|
185 |
$where = array(); |
|
186 |
|
|
187 |
foreach($dane as $key => $value) { |
|
188 |
if(!in_array($key, $allow) OR $value==='') { |
|
189 |
continue; |
|
190 |
} |
|
191 |
|
|
192 |
if($replace[$key]) { |
|
193 |
$key = $replace[$key]; |
|
194 |
} |
|
195 |
|
|
196 |
$where[$key] = $value; |
|
197 |
} |
|
198 |
|
|
199 |
if($where['id']) { |
|
200 |
validate::$kod = TRUE; |
|
201 |
switch(validate::type($where['id'])) { |
|
202 |
case 'ISBN': |
|
203 |
$where['ISBN'] = $where['id']; |
|
204 |
unset($where['id']); |
|
205 |
break; |
|
206 |
case 'ISSN': |
|
207 |
$where['ISSN'] = $where['id']; |
|
208 |
unset($where['id']); |
|
209 |
break; |
|
210 |
case 'MSC': |
|
211 |
$where['regal'] = $where['id']; |
|
212 |
if($dane['polka']) { |
|
213 |
$where['polka'] = $dane['polka']; |
|
214 |
} |
|
215 |
if($dane['rzad']) { |
|
216 |
$where['rzad'] = $dane['rzad']; |
|
217 |
} |
|
218 |
unset($where['id']); |
|
219 |
break; |
|
220 |
} |
|
221 |
validate::$kod = FALSE; |
|
222 |
} |
|
223 |
|
|
224 |
if(!$where['regal']) { |
|
225 |
unset($where['polka']); |
|
226 |
unset($where['rzad']); |
|
227 |
} |
|
228 |
|
|
229 |
if($where['id']) { |
|
230 |
$ret[] = self::szukaj_KOD($where['id']); |
|
231 |
$num = count($ret); |
|
232 |
} |
|
233 |
else |
|
234 |
{ |
|
235 |
if($dane['do']) { |
|
236 |
$num = db2::num('pozycz', 'id', array('do' => NULL)); |
|
237 |
if($num==0) { |
|
238 |
$ret = array(); |
|
239 |
} |
|
240 |
else |
|
241 |
{ |
|
242 |
$ret = db2::get(array('pozycz', array('J', 'ksiazki', 'USING', 'id')), '*', array('do' => NULL), $order, $start, $limit); |
|
243 |
} |
|
244 |
} |
|
245 |
else |
|
246 |
{ |
|
247 |
$num = db2::num('ksiazki', 'id', $where); |
|
248 |
if($num==0) { |
|
249 |
$ret = array(); |
|
250 |
} |
|
251 |
else |
|
252 |
{ |
|
253 |
$where = db2::__combine_where($where, TRUE); |
|
254 |
$ret = db2::escape_data(sql::fetch(sql::query('SELECT *, (SELECT MAX(`od`) FROM `pozycz` WHERE `pozycz`.`id`=`ksiazki`.`id`) as `od2`, (SELECT `do` FROM `pozycz` WHERE `pozycz`.`id`=`ksiazki`.`id` AND `od`=`od2`) as `do`, (SELECT `kto` FROM `pozycz` WHERE `pozycz`.`id`=`ksiazki`.`id` AND `od`=`od2`) as `kto`'.(db2::revelance() ? ', '.db2::$revelance : '').' FROM `ksiazki`'.$where.db2::__combine_order($order, TRUE).db2::__combine_limit($start, $limit)))); |
|
255 |
} |
|
256 |
} |
|
257 |
|
|
258 |
self::cache_addarray($ret); |
|
259 |
} |
|
260 |
|
|
261 |
return array($num, $ret, db2::revelance()); |
|
262 |
} |
|
263 |
} |
532779
|
264 |
?> |