static function wypozyczenie($kod, $kto) { if (self::pozyczona($kod) !== FALSE) { error::add('Książka jest już wypożyczona!'); } db2::add('pozycz', array('id' => $kod, 'kto' => $kto, 'od' => time())); ksiazki::cache_clear($kod); }
function __construct() { parent::__construct(); }
static function __combine_where($keys, $revelance = FALSE) { self::$revelance = FALSE; $implode = ' AND '; if (!is_array($keys) or empty($keys)) { return ''; } if (self::$SAFE_MODE_WHERE) { foreach ($keys as $key => $value) { if (is_null($value)) { $a[] = self::__combine_keyn($key) . ' IS NULL'; } else { $a[] = self::__combine_keyn($key) . '=' . sql::escape($value); } } } else { $a = array(); foreach ($keys as $key => $v) { if (!is_array($v)) { $v = array($v); } foreach ($v as $value) { if ($key === 'OR') { $implode = ' OR '; } elseif (substr($key, -1) == '!' and is_null($value) or $value === '') { $a[] = self::__combine_keyn(substr($key, 0, -1)) . ' IS NOT NULL'; } elseif (is_null($value) or $value === '') { $a[] = self::__combine_keyn($key) . ' IS NULL'; } elseif (substr($key, -1) == '!') { $a[] = self::__combine_keyn(substr($key, 0, -1)) . '!=' . sql::escape($value); } elseif ($key == '^') { $a[] = 'MAX(' . self::__combine_keyn($value) . ')'; } elseif (substr($key, -2) == '~~') { $temp = 'MATCH (' . self::__combine_keyn(substr($key, 0, -2)) . ') AGAINST (' . sql::escape($value) . ')'; if ($revelance) { self::$revelance = $temp . ' AS `revelance`'; } $a[] = $temp; } elseif (substr($key, -1) == '~') { $a[] = self::__combine_keyn(substr($key, 0, -1)) . ' LIKE ' . sql::escape($value); } elseif (substr($key, -2) == '>=') { $a[] = self::__combine_keyn(substr($key, 0, -2)) . '>=' . sql::escape($value); } elseif (substr($key, -2) == '<=') { $a[] = self::__combine_keyn(substr($key, 0, -2)) . '<=' . sql::escape($value); } elseif (substr($key, -1) == '>') { $a[] = self::__combine_keyn(substr($key, 0, -1)) . '>' . sql::escape($value); } elseif (substr($key, -1) == '<') { $a[] = self::__combine_keyn(substr($key, 0, -1)) . '<' . sql::escape($value); } else { $a[] = self::__combine_keyn($key) . '=' . sql::escape($value); } } } } return ' WHERE ' . implode($implode, $a) . $addon; }
static function to_database($kod, $MARC) { if (!$MARC['020']) { $MARC['020'] = array(); } foreach ($MARC['020'] as $value) { $value = (int) $value['a']; if (strlen($value) > strlen($ISBN)) { $ISBN = $value; } } if (!$MARC['022']) { $MARC['022'] = array(); } foreach ($MARC['022'] as $value) { $value = (int) $value['a']; if (strlen($value) > strlen($ISSN)) { $ISSN = $value; } } db2::add('ksiazki', array('id' => $kod, 'tytul' => $MARC['245'][0]['a'], 'autor' => $MARC['100'][0]['a'], 'rok' => $MARC['260'][0]['c'], 'miejsce' => $MARC['260'][0]['a'], 'wydawnictwo' => $MARC['260'][0]['b'], 'wydanie' => $MARC['250'][0]['a'], 'jezyk' => $MARC['041'][0]['a'], 'ISBN' => $ISBN, 'ISSN' => $ISSN)); }
} ?> </td> </tr> <tr> <th>Tabela książek</th> <td><?php $num = db2::num('ksiazki', '*', NULL); if ($mysql === FALSE) { echo NT; } elseif ($num === FALSE) { echo FAIL; } else { echo OK; } ?> </td> </tr> <tr> <th>Tabela wypożyczeń</th> <td><?php $num = db2::num('pozycz', '*', NULL); if ($mysql === FALSE) { echo NT; } elseif ($num === FALSE) { echo FAIL; } else { echo OK; } ?> </td> </tr> <tr> <th class="head" colspan="2">Zewnętrzne bazy danych</th> </tr> <tr> <th>Rozszerzenie YAZ</th> <td><?php if (!extension_loaded('yaz')) { echo SFAIL;
static function szukaj_info($dane, $order = NULL, $start = NULL, $limit = 30) { $allow = array('id', 'tytul', 'autor', 'wydawnictwo', 'miejsce', 'rok', 'wydanie', 'wycofana'); $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['ISSN'] = $where['id']; unset($where['id']); break; case 'MSC': $where['regal'] = $where['id']; if ($dane['polka']) { $where['polka'] = $dane['polka']; } if ($dane['rzad']) { $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 { if ($dane['do']) { $num = db2::num('pozycz', 'id'); if ($num == 0) { $ret = array(); } else { $ret = db2::get(array('pozycz', array('J', 'ksiazki', 'USING', 'id')), '*', NULL, $order, $start, $limit); } } else { $num = db2::num('ksiazki', 'id', $where); if ($num == 0) { $ret = array(); } else { $where = db2::__combine_where($where, TRUE); $ret = db2::escape_data(sql::fetch(sql::query('SELECT `ksiazki`.*, `pozycz`.`od`, `pozycz`.`kto`' . (db2::revelance() ? ', ' . db2::$revelance : '') . ' FROM `ksiazki` LEFT OUTER JOIN `pozycz` ON `pozycz`.`id`=`ksiazki`.`id` ' . $where . db2::__combine_order($order, TRUE) . db2::__combine_limit($start, $limit)))); } } self::cache_addarray($ret); } return array($num, $ret, db2::revelance()); }