Example #1
0
 function _new()
 {
     global $current_user;
     $current_user->can_throw('books_edit');
     $parent_id = isset(Request::$post['id_parent']) ? Request::$post['id_parent'] : false;
     $parent_id = max(0, (int) $parent_id);
     $title = isset(Request::$post['title']) ? Request::$post['title'] : false;
     $description = isset(Request::$post['description']) ? Request::$post['description'] : false;
     if ($parent_id) {
         $query = 'SELECT `id` FROM `series` WHERE `id`=' . $parent_id;
         if (!Database::sql2single($query)) {
             throw new Exception('No such parent');
         }
     }
     if (!$title) {
         throw new Exception('Empty title');
     }
     $description = prepare_review($description);
     $title = prepare_review($title, '');
     $new = array('description' => $description, 'title' => $title, 'id_parent' => (int) $id_parent);
     $old = array('description' => '', 'title' => '', 'id_parent' => 0);
     Database::query('START TRANSACTION');
     $query = 'INSERT INTO `series` SET `id_parent`=' . $parent_id . ',`title`=' . Database::escape($title) . ', `description`=' . Database::escape($description);
     Database::query($query);
     $id = Database::lastInsertId();
     if (!$id) {
         throw new Exception('Cant save serie');
     }
     SerieLog::addLog($new, $old, $id);
     SerieLog::saveLog($id, BookLog::TargetType_serie, $current_user->id, BiberLog::BiberLogType_serieNew);
     Database::query('COMMIT');
     $event = new Event();
     $event->event_SeriesAdd($current_user->id, $id);
     $event->push();
     ob_end_clean();
     header('Location:' . Config::need('www_path') . '/s/' . $id);
     Database::query('COMMIT');
     $current_user->gainActionPoints(BiberLog::$actionTypes[BiberLog::BiberLogType_serieNew], $sid, BiberLog::TargetType_serie);
     $search = Search::getInstance();
     /* @var $search Search */
     $search->setSerieToFullUpdate($id);
     exit;
 }