function create_rss($search, $limit) { $title = 'uBook'; if ($search) { $title .= ' - Suche nach "' . $search . '"'; } $link = WEBDIR; $desc = 'Neue Angebote bei uBook.'; $lang = 'de-de'; $copyright = 'uBook'; $rss = new RssChannel($title, $link, $desc, $lang, $copyright); $imageUrl = 'http://ubook.asta-bielefeld.de/ubook_small.gif'; $rss->addImage($imageUrl, $title, $link); $query = BookQuery::searchQuery($search); $query .= ' order by created desc'; if ($limit > 0) { $query .= ' limit ' . $limit; } $mysqlResult = mysql_query($query); while ($book = Book::fromMySql($mysqlResult)) { $title = $book->get('title'); $desc = 'Neues Buchangebot:' . "\n" . $book->asText(); $desc = nl2br(Parser::text2html($desc)); $id = $link = WEBDIR . 'book.php?id=' . $book->get('id'); $author = 'ubook@asta-bielefeld.de (uBook-Team)'; $date = $book->get('created'); $rss->addItem($id, $title, $desc, $link, $author, $date); } return $rss; }
/** * Sends an E-Mail to the offerer of the book. * * Known usages: * - add.php * - book.php - "Anfrage: " * - Cleaner.php - "Erneuern: " * * @param int $bookId database id of th book, this mail is about * @param string $subjectStart beginning of the subject, the title will * follow * @param string $message some text for the user, greeting will be added * @param string $replyTo mail address for the Reply-To field (optional) * @return bool false on failure */ public static function send($bookId, $subjectStart, $message, $replyTo = null) { include_once 'mysql_conn.php'; $query = 'select mail, id, author, title, price, year, isbn,' . ' description, auth_key from books where id="' . $bookId . '"'; $result = mysql_query($query); if (mysql_num_rows($result) != 1) { return false; } $book = Book::fromMySql($result); $subject = $subjectStart . $book->get('title'); $tmpl = Template::fromFile('view/mail.txt'); $tmpl->assign('message', $message); $tmpl->assign('bookText', $book->asText()); if ($replyTo == null || $replyTo == $book->get('mail')) { $subTmpl = $tmpl->addSubtemplate('editBook'); $link = self::editLink($book->get('id'), $book->get('auth_key')); $subTmpl->assign('editLink', $link); $books = new UsersBooks($book->get('mail')); $subTmpl->assign('usersBooks', $books->toString()); } else { $subTmpl = $tmpl->addSubtemplate('viewBook'); $link = self::bookLink($book->get('id')); $subTmpl->assign('bookLink', $link); } $content = $tmpl->result(); return self::mail($book->get('mail'), $subject, $content, $replyTo); }
public static function query(Isbn $isbn) { include_once 'mysql_conn.php'; $fields = array('author', 'title', 'price', 'year', 'isbn', 'description'); $query = 'select ' . implode(', ', $fields) . ' from books where isbn="' . $isbn->toString() . '"' . ' order by price;'; $result = mysql_query($query); $book = Book::fromMySql($result); if (!$book) { return null; } while ($b = Book::fromMySql($result)) { $isComplete = true; foreach ($fields as $field) { if ($book->get($field)) { continue; } if ($b->get($field)) { $book->set($field, $b->get($field)); continue; } $isComplete = false; } if ($isComplete) { break; } } return $book; }
public function getList() { $mysqlResult = parent::getMysqlResult(); $bookScriptUrl = WEBDIR . 'book.php'; $list = array(); while ($book = Book::fromMySql($mysqlResult)) { $url = $bookScriptUrl . '?id=' . $book->get('id'); $extBook = new ExternalBook($url, $book->get('author'), $book->get('title'), $book->get('price')); $list[] = $extBook; } return $list; }
public function toHtmlRows() { $template = new Template('<tr><td><a href="book.php?id=\'id\'">' . '<!-- begin author -->\'author\': <!-- end author -->' . '\'title\'</a></td>' . '<td>\'price\' €</td></tr>' . "\n"); $html = ''; while ($book = Book::fromMySql($this->getMysqlResult())) { $t = clone $template; $book->assignHtmlToTemplate($t); if ($book->get('author')) { $t->addSubtemplate('author'); } $html .= $t->result(); } return $html; }
/** * Queries the book list from the database and stores it. * @param $userMail A valid mail address. Quits if none given. * @return UsersBooks */ function UsersBooks($userMail) { if (!$userMail) { exit; } $query = 'select id, author, title, price, year, description, auth_key from books where mail="' . addslashes($userMail) . '" order by author, title, price'; $bookListResult = mysql_query($query); $this->bookCount = mysql_num_rows($bookListResult); $listString = "\n"; while ($book = Book::fromMySql($bookListResult)) { $listString .= "\n"; $listString .= $book->get('author') . ': ' . $book->get('title') . "\n"; $listString .= Mailer::editLink($book->get('id'), $book->get('auth_key')) . "\n"; } $this->bookListString = $listString; }
$error = 'not found'; } else { /* we have valid access to this book */ $selectableCategories = new SelectableCategories($id); if (isset($_POST['author'])) { /* update base book data */ $query = 'update books set author = "' . $_POST['author'] . '", title = "' . $_POST['title'] . '", year = "' . $_POST['year'] . '", isbn = "' . $_POST['isbn'] . '", price = "' . str_replace(',', '.', $_POST['price']) . '", description = "' . $_POST['desc'] . '" where id="' . $id . '" and auth_key="' . $key . '"'; mysql_query($query); /* update category relations */ $selectableCategories->update(); /* update expire date and look at the book */ require 'renew.php'; } $book = Book::fromMySql($result); require_once 'tools/Output.php'; require_once 'text/Template.php'; $tmpl = Template::fromFile('view/edit.html'); $book->assignHtmlToTemplate($tmpl); assignSelectableCategories($selectableCategories, $tmpl); $tmpl->assign('id', $_GET['id']); $tmpl->assign('key', $_GET['key']); $output = new Output(); $output->send($tmpl->result()); }
private function selectBook($bookId) { $result = mysql_query('select id, author, title, year, price, isbn,' . ' description, auth_key, mail from books where id="' . $bookId . '"'); if (mysql_num_rows($result) != 1) { $this->tmpl->addSubtemplate('messageNotFound'); $this->output->sendNotFound($this->tmpl->result()); exit; } return Book::fromMySql($result); }