예제 #1
0
 function add_genre()
 {
     global $current_user;
     $this->ca();
     if (is_numeric($_POST['id_genre'])) {
         $id_genre = (int) $_POST['id_genre'];
     } else {
         $id_genre = Database::sql2single('SELECT `id` FROM `genre` WHERE `name`=' . Database::escape($_POST['id_genre']));
     }
     $id_book = (int) $_POST['id'];
     if ($id_genre && $id_book) {
         $query = 'SELECT `id`,`name`,`title` FROM `genre` WHERE id=' . $id_genre . ' AND `id_parent`>0';
         $result = Database::sql2row($query);
         if (!isset($result['id'])) {
             $this->data['success'] = 0;
             $this->data['error'] = 'Нет такого жанра';
             return;
         }
         $query = 'INSERT INTO `book_genre` SET `id_book`=' . $id_book . ' , `id_genre`=' . $id_genre;
         $r = Database::query($query, false);
         if ($r) {
             $this->data['success'] = 1;
             $this->data['item_id'] = $id_genre;
             $this->data['name'] = $result['name'];
             $this->data['title'] = $result['title'];
             BookLog::addLog(array('id_genre' => $id_genre), array('id_genre' => 0), $id_book);
             BookLog::saveLog($id_book, BookLog::TargetType_book, $current_user->id, BiberLog::BiberLogType_bookEditGenre);
             $search = Search::getInstance();
             /* @var $search Search */
             $search->updateBook(new Book($id_book));
             Notify::notifyGenreNewBook($id_genre, $id_book);
         } else {
             $this->data['error'] = 'Жанр уже есть в списке жанров';
         }
         return;
     }
     $this->data['item_id'] = $id_genre;
     $this->data['success'] = 0;
 }