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