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 |
|
|
115 |
static function informacje($kod, $dane=NULL) { |
|
116 |
if(is_null($dane)) { |
|
117 |
$dane = ksiazki::szukaj_KOD($kod); |
|
118 |
} |
|
119 |
|
|
120 |
if($dane['wycofana']) { |
|
121 |
$class = 'wyc'; |
|
122 |
$info = '<p>Książka wycofana'.($dane['powod'] ? ' <br /> '.$dane['powod'] : '').'</p>'; |
|
123 |
} |
|
124 |
else |
|
125 |
{ |
|
126 |
if(!pozycz::pozyczona($dane['id'])) { |
|
127 |
$class = 'norm'; |
|
128 |
$info = ' |
|
129 |
|
|
130 |
<fieldset> |
|
131 |
<legend>Wypożyczanie</legend> |
|
132 |
<p>Książka w bibliotece</p> |
|
133 |
<form action="borrow_book.php" method="post" onsubmit="return ffalse(\'step1\')"> |
|
134 |
<p>Pożycz <input type="text" name="kod" value="'.$dane['id'].'" readonly="readonly" /><br /> |
|
135 |
Komu? <input type="text" name="kto" id="step11" required="required" /></p> |
|
136 |
<p><input type="submit" value="Pożycz" /></p> |
|
137 |
|
|
138 |
<script type="text/javascript"> |
|
139 |
document.getElementById(\'step11\').focus(); |
|
140 |
</script> |
|
141 |
</form> |
|
142 |
</fieldset> |
|
143 |
|
|
144 |
'; |
|
145 |
} |
|
146 |
else |
|
147 |
{ |
|
148 |
$class = 'poz'; |
|
149 |
$info = ' |
|
150 |
|
|
151 |
<fieldset> |
|
152 |
<legend>Wypożyczanie</legend> |
|
153 |
<p>Wypożyczył(a) '.$dane['kto'].' w dniu '.date('d.m.Y', $dane['od']).'</p> |
|
154 |
|
|
155 |
<form action="borrow_back.php" method="post"> |
|
156 |
<p><input type="hidden" name="kod" value="'.$dane['id'].'" /> <input type="submit" value="Zwrot" id="step11" /></p> |
|
157 |
|
|
158 |
<script type="text/javascript"> |
|
159 |
document.getElementById(\'step11\').focus(); |
|
160 |
</script> |
|
161 |
</form> |
|
162 |
</fieldset> |
|
163 |
|
|
164 |
'; |
|
165 |
} |
|
166 |
} |
|
167 |
|
|
168 |
// Okładka |
|
169 |
$cover = ksiazki::okladka($dane['id'], $dane['ISBN']); |
|
170 |
|
|
171 |
echo '<div class="'.$class.'" id="book"> |
|
172 |
'.($cover ? '<a href="cover.php?KOD='.$dane['id'].'&ISBN='.$dane['ISBN'].'"><img src="'.$cover.'" alt="Okładka" /></a> |
|
173 |
' : '').'<h4>'.$dane['tytul'].'</h4> |
|
174 |
<h5>'.$dane['autor'].($dane['regal'] ? ' <span>('.$dane['regal'].($dane['polka'] ? '/'.$dane['polka'] : '').($dane['rzad'] ? '/'.$dane['rzad'] : '').')</span>' : '').'</h5> |
|
175 |
'.($dane['wydanie'] ? '<p>Wydanie '.$dane['wydanie'].'</p>' : '').' |
|
176 |
<p>'.($dane['wydawnictwo'] ? $dane['wydawnictwo'].'<br /> |
|
177 |
' : '').$dane['miejsce'].' '.$dane['rok'].($dane['ISBN'] ? '<br /> |
|
178 |
ISBN-13: '.$dane['ISBN'] : '').(substr($dane['ISBN'], 0, 3) == '978' ? '<br /> |
|
179 |
ISBN-10: '.convert::ISBN13_to_ISBN10($dane['ISBN']) : '').($dane['ISSN'] ? '<br /> |
|
180 |
ISSN-13: '.$dane['ISSN'].'<br /> |
|
181 |
ISSN-10: '.convert::ISSN13_to_ISSN8($dane['ISSN']) : '').'</p> |
|
182 |
'.$info.' |
|
183 |
<form action="edit.php" method="get" style="float:left;"> |
|
184 |
<p><input type="hidden" name="kod" value="'.$dane['id'].'" /> <input type="submit" value="Edytuj" /></p> |
|
185 |
</form> |
|
186 |
|
|
187 |
<form action="del.php" method="get" style="float:left;"> |
|
188 |
<p><input type="hidden" name="kod" value="'.$dane['id'].'" /> <input type="submit" value="Usuń" /></p> |
|
189 |
</form> |
|
190 |
'.($dane['od'] ? ' |
|
191 |
<form action="borrow_history.php" method="get" style="float:right;"> |
|
192 |
<p><input type="hidden" name="kod" value="'.$dane['id'].'" /> <input type="submit" value="Historia wypożyczeń" /></p> |
|
193 |
</form>' : '').' |
|
194 |
</div>'; |
|
195 |
} |
|
196 |
|
|
197 |
static function lista() { |
|
198 |
if(!in_array($_GET['sort'], array('id', 'autor', 'tytul', 'miejsce', 'rok', 'wydawnictwo'))) { |
|
199 |
$_GET['sort'] = 'tytul'; |
|
200 |
self::$default = TRUE; |
|
201 |
} |
|
202 |
if($_GET['ord'] != 'desc') { |
|
203 |
$_GET['ord'] = 'asc'; |
|
204 |
} |
|
205 |
if(!ctype_digit($_GET['strona'])) { |
|
206 |
$_GET['strona'] = 0; |
|
207 |
} |
|
208 |
|
|
209 |
if($_GET['id']) { |
|
210 |
self::add('id', 13); |
|
211 |
self::add('polka', 3); |
|
212 |
self::add('rzad', 3); |
|
213 |
} |
|
214 |
else |
|
215 |
{ |
|
216 |
self::add('tytul'); |
|
217 |
self::add('autor'); |
|
218 |
self::add('wydanie', 25); |
|
219 |
self::add('miejsce'); |
|
220 |
self::add('rok', 4); |
|
221 |
self::add('wydawnictwo'); |
|
222 |
} |
|
223 |
|
|
224 |
if(self::$default) { |
|
225 |
$sort = array('revelance' => self::invert_sort($_GET['ord']), $_GET['sort'] => $_GET['ord']); |
|
226 |
} |
|
227 |
else |
|
228 |
{ |
|
229 |
$sort = array($_GET['sort'] => $_GET['ord']); |
|
230 |
} |
|
231 |
|
|
232 |
list($num, $ksiazki, $revelance) = ksiazki::szukaj_info($_GET, $sort, $_GET['strona']*self::$nastrone, self::$nastrone); |
|
233 |
|
|
234 |
if($num==0) { |
|
235 |
error::add('Brak książek spełniających podane kryteria'); |
|
236 |
} |
|
237 |
elseif($num==1 AND !$revelance) { |
|
238 |
self::informacje(NULL, $ksiazki[0]); |
|
239 |
return TRUE; |
|
240 |
} |
|
241 |
|
|
242 |
echo '<table class="width"> |
|
243 |
<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> |
|
244 |
'; |
|
245 |
|
|
246 |
foreach($ksiazki as $ksiazka) { |
|
247 |
if($ksiazka['wycofana']) { |
|
248 |
$info = 'Książka wycofana'; |
|
249 |
$class = 'wyc'; |
|
250 |
} |
|
251 |
else |
|
252 |
{ |
|
253 |
if($ksiazka['do']!==NULL OR $ksiazka['od']===NULL) { |
|
254 |
$class = 'norm'; |
|
255 |
$info = 'Książka w bibliotece'; |
|
256 |
} |
|
257 |
else |
|
258 |
{ |
|
259 |
$class = 'poz'; |
|
260 |
$info = $ksiazka['kto']; |
|
261 |
$pozycz = TRUE; |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
265 |
$cover = ksiazki::okladka($ksiazka['id'], $ksiazka['ISBN']); |
|
266 |
|
|
267 |
echo '<tr'.($class ? ' class="'.$class.'"' : '').'> |
|
268 |
<td> |
|
269 |
'.($cover ? '<a href="cover.php?KOD='.$ksiazka['id'].'&ISBN='.$ksiazka['ISBN'].'"><img src="'.$cover.'" alt="Okładka" /></a>' : '').' |
|
270 |
</td> |
|
271 |
<td> |
|
272 |
<b>'.$ksiazka['id'].'</b> <br /> |
|
273 |
'.($ksiazka['wydanie'] ? 'W. '.$ksiazka['wydanie'] : '').' |
|
274 |
</td> |
|
275 |
<td> |
|
276 |
'.$ksiazka['autor']. |
|
277 |
($ksiazka['regal'] ? ' <span>('.$ksiazka['regal']. |
|
278 |
($ksiazka['polka'] ? '/'.$ksiazka['polka'] : ''). |
|
279 |
($ksiazka['rzad'] ? '/'.$ksiazka['rzad'] : ''). |
|
280 |
')</span>' : '').' <br /> |
|
281 |
<b>'.$ksiazka['tytul'].'</b> </td> |
|
282 |
<td> |
|
283 |
'.$ksiazka['miejsce'].' '.$ksiazka['rok'].' <br /> |
|
284 |
'.$ksiazka['wydawnictwo'].' |
|
285 |
</td>'.($revelance ? ' |
|
286 |
<td>'.min(100, (int)($ksiazka['revelance']*10)).'% </td>' : '').' |
|
287 |
<td class="n"> |
|
288 |
'.$info.' <br /> |
|
289 |
<a href="info.php?kod='.$ksiazka['id'].'">Więcej</a> |
|
290 |
<a href="edit.php?kod='.$ksiazka['id'].'">Edycja</a> |
|
291 |
<a href="del.php?kod='.$ksiazka['id'].'">Usuń</a> |
|
292 |
</td> |
|
293 |
</tr> |
|
294 |
'; |
|
295 |
} |
|
296 |
|
|
297 |
echo '</table> |
|
298 |
|
|
299 |
'; |
|
300 |
self::strony($num); |
|
301 |
} |
|
302 |
|
|
303 |
static function strony($elementow) { |
|
304 |
$stron = ceil($elementow / self::$nastrone) - 1; |
|
305 |
|
|
306 |
echo '<p class="paginator"> '; |
|
307 |
for($strona=0; $strona<=$stron; $strona++) { |
|
308 |
if($strona == $_GET['strona']) { |
|
309 |
echo '<b>[ '.($strona+1).' ]</b> '; |
|
310 |
} |
|
311 |
else |
|
312 |
{ |
|
313 |
echo '<a href="'.self::sort(NULL, $strona).'">[ '.($strona+1).' ]</a> '; |
|
314 |
} |
|
315 |
} |
|
316 |
|
|
317 |
echo '</p>'; |
|
318 |
} |
|
319 |
} |
532779
|
320 |
?> |