commit | author | age
|
175a52
|
1 |
<?php |
JK |
2 |
class gotowe { |
|
3 |
static $pola = array('autor', 'tytul', 'wydanie', 'miejsce', 'rok', 'wydawnictwo', 'jezyk', 'ISBN', 'ISSN'); |
|
4 |
static $nastrone = 25; |
|
5 |
static $add = ''; |
|
6 |
static $default = FALSE; |
|
7 |
|
|
8 |
static function dodaj_lista($kod, $wlasne, $znalezione=array()) { |
|
9 |
validate::KOD($kod, FALSE); |
|
10 |
|
|
11 |
echo '<p>KOD: <input type="text" name="kod" value="'.$kod.'" readonly="readonly" /></p> |
|
12 |
|
|
13 |
'; |
|
14 |
|
|
15 |
$i = 0; |
|
16 |
?> |
|
17 |
|
|
18 |
<table> |
|
19 |
<tr> <th>Autor</th> <th>Tytuł</th> <th>Wydanie</th> <th>Miejsce</th> <th>Rok</th> <th>Wydawnictwo</th> <th>Język</th> <th>ISBN</th> <th>ISSN</th> <th>Zapisz</th> </tr> |
|
20 |
<?php |
|
21 |
if(!empty($wlasne)) { |
|
22 |
?> |
|
23 |
<tr> <th colspan="10">Zasoby własne</th> </tr> |
|
24 |
|
|
25 |
<?php |
|
26 |
foreach($wlasne as $value) { |
|
27 |
echo '<tr> <form action="add_book.php" method="post"> |
|
28 |
'; |
|
29 |
foreach(self::$pola as $v) { |
|
30 |
echo '<td> <input type="text" name="'.$v.'" value="'.htmlspecialchars($value[$v]).'" /> </td> |
|
31 |
'; |
|
32 |
} |
|
33 |
echo '<td> <input type="hidden" name="id" value="'.$kod.'" readonly="readonly" /> <input type="submit" value="Zapisz" /> </td> |
|
34 |
</form> </tr> |
|
35 |
'; |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
foreach($znalezione as $nazwa => $dane) { |
|
40 |
echo '<tr> <th colspan="10">'.$nazwa.'</th> </tr>'; |
|
41 |
foreach($dane as $value) { |
|
42 |
echo '<tr> <form action="add_book.php" method="post"> |
|
43 |
'; |
|
44 |
foreach(self::$pola as $v) { |
|
45 |
echo '<td> <input type="text" name="'.$v.'" value="'.htmlspecialchars($value[$v]).'" /> </td> |
|
46 |
'; |
|
47 |
} |
|
48 |
echo '<td> <input type="hidden" name="id" value="'.$kod.'" readonly="readonly" /> <input type="submit" value="Zapisz" /> </td> |
|
49 |
</form> </tr> |
|
50 |
'; |
|
51 |
} |
|
52 |
} |
|
53 |
?> |
|
54 |
|
|
55 |
<tr> <th colspan="10">Dodaj własną</th> </tr> |
|
56 |
|
|
57 |
<?php |
|
58 |
echo '<tr> <form action="add_book.php" method="post"> |
|
59 |
'; |
|
60 |
foreach(self::$pola as $v) { |
|
61 |
echo '<td> <input type="text" name="'.$v.'" /> </td> |
|
62 |
'; |
|
63 |
} |
|
64 |
echo '<td> <input type="hidden" name="id" value="'.$kod.'" readonly="readonly" /> <input type="submit" value="Zapisz" /> </td> |
|
65 |
</form> </tr> |
|
66 |
|
|
67 |
</table> |
|
68 |
'; |
|
69 |
} |
|
70 |
|
|
71 |
static function sort($by=NULL, $strona=NULL) { |
|
72 |
if($strona === NULL) { |
|
73 |
$strona = 0; |
|
74 |
} |
|
75 |
|
|
76 |
if($by === NULL) { |
|
77 |
if(!self::$default) { |
|
78 |
$by = $_GET['sort']; |
|
79 |
} |
|
80 |
|
|
81 |
$ord = $_GET['ord']; |
|
82 |
} |
|
83 |
elseif($by == 'default' && self::$default) { |
|
84 |
$ord = self::invert_sort($_GET['ord']); |
|
85 |
} |
|
86 |
elseif($_GET['sort'] == $by && $_GET['ord'] == 'asc') { |
|
87 |
$ord = 'desc'; |
|
88 |
} |
|
89 |
else |
|
90 |
{ |
|
91 |
$ord = 'asc'; |
|
92 |
} |
|
93 |
|
|
94 |
return $_SERVER['PHP_SELF'].'?'.self::$add.'strona='.$strona.'&sort='.$by.'&ord='.$ord; |
|
95 |
} |
|
96 |
|
|
97 |
static function add($what, $size=50) { |
|
98 |
if($_GET[$what]!='') { |
|
99 |
self::$add .= $what.'='.urlencode(substr($_GET[$what], 0, $size)).'&'; |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
static function invert_sort($ord) { |
|
104 |
$ord = strtolower($ord); |
|
105 |
if($ord != 'asc') { |
|
106 |
$ord = 'asc'; |
|
107 |
} |
|
108 |
else |
|
109 |
{ |
|
110 |
$ord = 'desc'; |
|
111 |
} |
|
112 |
return $ord; |
|
113 |
} |
|
114 |
|
381239
|
115 |
static function historia($kod) { |
JK |
116 |
$st = PDOO::Singleton()->prepare( |
|
117 |
'SELECT * FROM pozycz_historia WHERE id=?'."\n" |
|
118 |
.'UNION'."\n" |
|
119 |
.'SELECT *, \'\' AS do FROM pozycz WHERE id=? ORDER BY od ASC' |
|
120 |
); |
|
121 |
$st->execute(array($kod, $kod)); |
|
122 |
$dane = $st->fetchAll(); |
|
123 |
|
|
124 |
$info = '<table id="bhist"> |
|
125 |
<tr> <th>Pożyczający</th> <th>Od</th> <th>Do</th> </tr> |
|
126 |
'; |
|
127 |
|
|
128 |
foreach($dane as $o) { |
|
129 |
$info .= '<tr> <td>'.htmlspecialchars($o['kto']).'</td> <td>'.date('Y-m-d H:i:s', $o['od']).'</td> <td>'.($o['do'] ? date('Y-m-d H:i:s', $o['do']) : '').'</td> </tr>'."\n"; |
|
130 |
} |
|
131 |
|
|
132 |
echo $info.'</table>'; |
|
133 |
} |
|
134 |
|
175a52
|
135 |
static function informacje($kod, $dane=NULL) { |
JK |
136 |
if(is_null($dane)) { |
|
137 |
$dane = ksiazki::szukaj_KOD($kod); |
|
138 |
} |
|
139 |
|
|
140 |
if($dane['wycofana']) { |
|
141 |
$class = 'wyc'; |
|
142 |
$info = '<p>Książka wycofana'.($dane['powod'] ? ' <br /> '.$dane['powod'] : '').'</p>'; |
|
143 |
} |
|
144 |
else |
|
145 |
{ |
|
146 |
if(!pozycz::pozyczona($dane['id'])) { |
|
147 |
$class = 'norm'; |
|
148 |
$info = ' |
|
149 |
|
|
150 |
<fieldset> |
|
151 |
<legend>Wypożyczanie</legend> |
|
152 |
<p>Książka w bibliotece</p> |
|
153 |
<form action="borrow_book.php" method="post" onsubmit="return ffalse(\'step1\')"> |
|
154 |
<p>Pożycz <input type="text" name="kod" value="'.$dane['id'].'" readonly="readonly" /><br /> |
|
155 |
Komu? <input type="text" name="kto" id="step11" required="required" /></p> |
|
156 |
<p><input type="submit" value="Pożycz" /></p> |
|
157 |
|
|
158 |
<script type="text/javascript"> |
|
159 |
document.getElementById(\'step11\').focus(); |
|
160 |
</script> |
|
161 |
</form> |
|
162 |
</fieldset> |
|
163 |
|
|
164 |
'; |
|
165 |
} |
|
166 |
else |
|
167 |
{ |
|
168 |
$class = 'poz'; |
|
169 |
$info = ' |
|
170 |
|
|
171 |
<fieldset> |
|
172 |
<legend>Wypożyczanie</legend> |
|
173 |
<p>Wypożyczył(a) '.$dane['kto'].' w dniu '.date('d.m.Y', $dane['od']).'</p> |
|
174 |
|
|
175 |
<form action="borrow_back.php" method="post"> |
|
176 |
<p><input type="hidden" name="kod" value="'.$dane['id'].'" /> <input type="submit" value="Zwrot" id="step11" /></p> |
|
177 |
|
|
178 |
<script type="text/javascript"> |
|
179 |
document.getElementById(\'step11\').focus(); |
|
180 |
</script> |
|
181 |
</form> |
|
182 |
</fieldset> |
|
183 |
|
|
184 |
'; |
|
185 |
} |
|
186 |
} |
|
187 |
|
|
188 |
// Okładka |
|
189 |
$cover = ksiazki::okladka($dane['id'], $dane['ISBN']); |
|
190 |
|
|
191 |
echo '<div class="'.$class.'" id="book"> |
|
192 |
'.($cover ? '<a href="cover.php?KOD='.$dane['id'].'&ISBN='.$dane['ISBN'].'"><img src="'.$cover.'" alt="Okładka" /></a> |
|
193 |
' : '').'<h4>'.$dane['tytul'].'</h4> |
|
194 |
<h5>'.$dane['autor'].($dane['regal'] ? ' <span>('.$dane['regal'].($dane['polka'] ? '/'.$dane['polka'] : '').($dane['rzad'] ? '/'.$dane['rzad'] : '').')</span>' : '').'</h5> |
|
195 |
'.($dane['wydanie'] ? '<p>Wydanie '.$dane['wydanie'].'</p>' : '').' |
|
196 |
<p>'.($dane['wydawnictwo'] ? $dane['wydawnictwo'].'<br /> |
|
197 |
' : '').$dane['miejsce'].' '.$dane['rok'].($dane['ISBN'] ? '<br /> |
|
198 |
ISBN-13: '.$dane['ISBN'] : '').(substr($dane['ISBN'], 0, 3) == '978' ? '<br /> |
|
199 |
ISBN-10: '.convert::ISBN13_to_ISBN10($dane['ISBN']) : '').($dane['ISSN'] ? '<br /> |
|
200 |
ISSN-13: '.$dane['ISSN'].'<br /> |
|
201 |
ISSN-10: '.convert::ISSN13_to_ISSN8($dane['ISSN']) : '').'</p> |
|
202 |
'.$info.' |
|
203 |
<form action="edit.php" method="get" style="float:left;"> |
|
204 |
<p><input type="hidden" name="kod" value="'.$dane['id'].'" /> <input type="submit" value="Edytuj" /></p> |
|
205 |
</form> |
|
206 |
|
|
207 |
<form action="del.php" method="get" style="float:left;"> |
|
208 |
<p><input type="hidden" name="kod" value="'.$dane['id'].'" /> <input type="submit" value="Usuń" /></p> |
|
209 |
</form> |
|
210 |
'.($dane['od'] ? ' |
|
211 |
<form action="borrow_history.php" method="get" style="float:right;"> |
|
212 |
<p><input type="hidden" name="kod" value="'.$dane['id'].'" /> <input type="submit" value="Historia wypożyczeń" /></p> |
|
213 |
</form>' : '').' |
|
214 |
</div>'; |
|
215 |
} |
|
216 |
|
|
217 |
static function lista() { |
|
218 |
if(!in_array($_GET['sort'], array('id', 'autor', 'tytul', 'miejsce', 'rok', 'wydawnictwo'))) { |
|
219 |
$_GET['sort'] = 'tytul'; |
|
220 |
self::$default = TRUE; |
|
221 |
} |
|
222 |
if($_GET['ord'] != 'desc') { |
|
223 |
$_GET['ord'] = 'asc'; |
|
224 |
} |
|
225 |
if(!ctype_digit($_GET['strona'])) { |
|
226 |
$_GET['strona'] = 0; |
|
227 |
} |
|
228 |
|
|
229 |
if($_GET['id']) { |
|
230 |
self::add('id', 13); |
|
231 |
self::add('polka', 3); |
|
232 |
self::add('rzad', 3); |
|
233 |
} |
|
234 |
else |
|
235 |
{ |
|
236 |
self::add('tytul'); |
|
237 |
self::add('autor'); |
|
238 |
self::add('wydanie', 25); |
|
239 |
self::add('miejsce'); |
|
240 |
self::add('rok', 4); |
|
241 |
self::add('wydawnictwo'); |
|
242 |
} |
|
243 |
|
|
244 |
if(self::$default) { |
|
245 |
$sort = array('revelance' => self::invert_sort($_GET['ord']), $_GET['sort'] => $_GET['ord']); |
|
246 |
} |
|
247 |
else |
|
248 |
{ |
|
249 |
$sort = array($_GET['sort'] => $_GET['ord']); |
|
250 |
} |
|
251 |
|
|
252 |
list($num, $ksiazki, $revelance) = ksiazki::szukaj_info($_GET, $sort, $_GET['strona']*self::$nastrone, self::$nastrone); |
|
253 |
|
|
254 |
if($num==0) { |
adfb2d
|
255 |
errorclass::add('Brak książek spełniających podane kryteria'); |
175a52
|
256 |
} |
JK |
257 |
elseif($num==1 AND !$revelance) { |
|
258 |
self::informacje(NULL, $ksiazki[0]); |
|
259 |
return TRUE; |
|
260 |
} |
|
261 |
|
|
262 |
echo '<table class="width"> |
|
263 |
<tr> <th>Okł.</th> <th> <b><a href="'.self::sort('id').'">Kod</a></b> <br /> Wyd. </th> <th> <a href="'.self::sort('autor').'">Autor</a> <br /> <b><a href="'.self::sort('tytul').'">Tytuł</a></b> </th> <th> <a href="'.self::sort('miejsce').'">Miejsce</a>, <a href="'.self::sort('rok').'">rok</a> <br /> <a href="'.self::sort('wydawnictwo').'">Wydawnictwo</a> </th>'.($revelance ? ' <th><a href="'.self::sort('default').'">Trafność</a></th>' : '').' <th> Wypożyczenie <br /> Opcje </th> </tr> |
|
264 |
'; |
|
265 |
|
|
266 |
foreach($ksiazki as $ksiazka) { |
|
267 |
if($ksiazka['wycofana']) { |
|
268 |
$info = 'Książka wycofana'; |
|
269 |
$class = 'wyc'; |
|
270 |
} |
|
271 |
else |
|
272 |
{ |
|
273 |
if($ksiazka['do']!==NULL OR $ksiazka['od']===NULL) { |
|
274 |
$class = 'norm'; |
|
275 |
$info = 'Książka w bibliotece'; |
|
276 |
} |
|
277 |
else |
|
278 |
{ |
|
279 |
$class = 'poz'; |
|
280 |
$info = $ksiazka['kto']; |
|
281 |
$pozycz = TRUE; |
|
282 |
} |
|
283 |
} |
|
284 |
|
|
285 |
$cover = ksiazki::okladka($ksiazka['id'], $ksiazka['ISBN']); |
|
286 |
|
|
287 |
echo '<tr'.($class ? ' class="'.$class.'"' : '').'> |
|
288 |
<td> |
|
289 |
'.($cover ? '<a href="cover.php?KOD='.$ksiazka['id'].'&ISBN='.$ksiazka['ISBN'].'"><img src="'.$cover.'" alt="Okładka" /></a>' : '').' |
|
290 |
</td> |
|
291 |
<td> |
|
292 |
<b>'.$ksiazka['id'].'</b> <br /> |
|
293 |
'.($ksiazka['wydanie'] ? 'W. '.$ksiazka['wydanie'] : '').' |
|
294 |
</td> |
|
295 |
<td> |
|
296 |
'.$ksiazka['autor']. |
|
297 |
($ksiazka['regal'] ? ' <span>('.$ksiazka['regal']. |
|
298 |
($ksiazka['polka'] ? '/'.$ksiazka['polka'] : ''). |
|
299 |
($ksiazka['rzad'] ? '/'.$ksiazka['rzad'] : ''). |
|
300 |
')</span>' : '').' <br /> |
|
301 |
<b>'.$ksiazka['tytul'].'</b> </td> |
|
302 |
<td> |
|
303 |
'.$ksiazka['miejsce'].' '.$ksiazka['rok'].' <br /> |
|
304 |
'.$ksiazka['wydawnictwo'].' |
|
305 |
</td>'.($revelance ? ' |
|
306 |
<td>'.min(100, (int)($ksiazka['revelance']*10)).'% </td>' : '').' |
|
307 |
<td class="n"> |
|
308 |
'.$info.' <br /> |
|
309 |
<a href="info.php?kod='.$ksiazka['id'].'">Więcej</a> |
|
310 |
<a href="edit.php?kod='.$ksiazka['id'].'">Edycja</a> |
|
311 |
<a href="del.php?kod='.$ksiazka['id'].'">Usuń</a> |
|
312 |
</td> |
|
313 |
</tr> |
|
314 |
'; |
|
315 |
} |
|
316 |
|
|
317 |
echo '</table> |
|
318 |
|
|
319 |
'; |
|
320 |
self::strony($num); |
|
321 |
} |
|
322 |
|
|
323 |
static function strony($elementow) { |
|
324 |
$stron = ceil($elementow / self::$nastrone) - 1; |
|
325 |
|
|
326 |
echo '<p class="paginator"> '; |
|
327 |
for($strona=0; $strona<=$stron; $strona++) { |
|
328 |
if($strona == $_GET['strona']) { |
|
329 |
echo '<b>[ '.($strona+1).' ]</b> '; |
|
330 |
} |
|
331 |
else |
|
332 |
{ |
|
333 |
echo '<a href="'.self::sort(NULL, $strona).'">[ '.($strona+1).' ]</a> '; |
|
334 |
} |
|
335 |
} |
|
336 |
|
|
337 |
echo '</p>'; |
|
338 |
} |
|
339 |
} |
532779
|
340 |
?> |