PodglÄ…d pliku: / books_opac / includes / ksiazki.php
<?php
/*****************************************************
* System biblioteczny - Modul OPAC *
*****************************************************
* Wersja: 1.2 Stable *
* Data: 21.08.2010 (13:45) *
* Autor: Jacek Kowalski (http://jacekk.info) *
* *
* Strona WWW: http://dev.jacekk.net/books *
* *
* Utwor rozprowadzany na licencji *
* http://creativecommons.org/licenses/by-nc-sa/2.5/ *
*****************************************************/
class ksiazki_cache {
static $cache = array();
static function cache_get($kod) {
$kod = (int)$kod;
if(!isset(self::$cache[(int)$kod])) {
self::cache_update($kod);
}
return self::$cache[(int)$kod];
}
static function cache_add($kod, &$dane) {
if($dane['od2']) {
$dane['od'] = $dane['od2'];
unset($dane['od2']);
}
self::$cache[(int)$kod] = $dane;
}
static function cache_addarray(&$dane) {
foreach($dane as &$r) {
self::cache_add($r['id'], $r);
}
}
static function cache_clear($id=NULL) {
if(is_null($id)) {
self::$cache = array();
}
else
{
unset(self::$cache[(int)$id]);
}
}
static function cache_update($kod) {
$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).'\'')));
self::cache_add($kod, $dane);
}
}
class ksiazki extends ksiazki_cache {
static $LT_API = '';
static function okladka($KOD, $ISBN) {
return okladki::znajdz($KOD, $ISBN, 'covers');
}
static function okladka_big($KOD, $ISBN) {
return okladki::znajdz($KOD, $ISBN, 'covers_big');
}
static function exists($kod) {
$info = self::cache_get($kod);
if(isset($info['id'])) {
return TRUE;
}
else
{
return FALSE;
}
}
static function szukaj_KOD($kod) {
validate::KOD($kod, TRUE);
return self::cache_get($kod);
}
static function szukaj_info($dane, $order, $start=NULL, $limit=30) {
$allow = array('id', 'tytul', 'autor', 'wydawnictwo', 'miejsce', 'rok', 'wydanie');
$replace = array('tytul' => 'tytul~~', 'autor' => 'autor~~', 'wydawnictwo' => 'wydawnictwo~~');
$where = array();
foreach($dane as $key => $value) {
if(!in_array($key, $allow) OR $value==='') {
continue;
}
if($replace[$key]) {
$key = $replace[$key];
}
$where[$key] = $value;
}
if($where['id']) {
validate::$kod = TRUE;
switch(validate::type($where['id'])) {
case 'ISBN':
$where['ISBN'] = $where['id'];
unset($where['id']);
break;
case 'ISSN':
$where['ISBN'] = $where['id'];
unset($where['id']);
break;
case 'MSC':
$where['regal'] = $where['id'];
$where['polka'] = $dane['polka'];
$where['rzad'] = $dane['rzad'];
unset($where['id']);
break;
}
validate::$kod = FALSE;
}
if(!$where['regal']) {
unset($where['polka']);
unset($where['rzad']);
}
if($where['id']) {
$ret[] = self::szukaj_KOD($where['id']);
$num = count($ret);
}
else
{
$num = db2::num('ksiazki', 'id', $where);
$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` FROM `ksiazki`'.db2::__combine_where($where).db2::__combine_order($order).db2::__combine_limit($start, $limit))));
self::cache_addarray($ret);
}
return array($num, $ret, db2::revelance());
}
}
?>
Browse Code © 2010 by Jacek Kowalski