public function actionEdit($book_id, $chap_id)
 {
     $chap_id = (int) $chap_id;
     $book_id = (int) $book_id;
     $ajax = $_GET["ajax"] == 1;
     if ($chap_id != 0) {
         $chap = $this->loadChapter($book_id, $chap_id, false);
         if (!$chap->book->can("read")) {
             throw new CHttpException(403, "Доступ в перевод закрыт его владельцем.");
         }
     } else {
         $chap = new Chapter();
         $chap->book = Book::model()->with("membership")->findByPk($book_id);
         if (!$chap->book) {
             throw new CHttpException(404, "Вы пытаетесь создать новую главу в несуществующем переводе.");
         }
         $chap->book_id = $book_id;
     }
     if (!$chap->book->can("chap_edit")) {
         throw new CHttpException(403, "Вы не можете редактировать оглавление в этом переводе.");
     }
     // $overridedId - ID главы с особыми правами в этом переводе
     if ($chap->isNewRecord && $chap->book->n_chapters == 0 || !$chap->isNewRecord && $chap->book->n_chapters <= 1) {
         $overridedId = -1;
     } elseif ($chap->hasOverride) {
         $overridedId = $chap->id;
     } else {
         $overridedId = Yii::app()->db->createCommand("SELECT id FROM chapters WHERE book_id = :book_id AND (ac_read != '' OR ac_trread != '' OR ac_gen != '' OR ac_rate != '' OR ac_comment != '' OR ac_tr != '')")->queryScalar(array(":book_id" => $chap->book_id));
     }
     if (count($_POST["Chapter"]) > 0) {
         if ($chap_id == 0) {
             // Будущий ord
             if ($_GET["placement"] == -1) {
                 $chap->ord = Yii::app()->db->createCommand("SELECT MIN(ord) FROM chapters WHERE book_id = :book_id")->queryScalar(array(":book_id" => $book_id)) - 1;
             } else {
                 $chap->ord = Yii::app()->db->createCommand("SELECT MAX(ord) FROM chapters WHERE book_id = :book_id")->queryScalar(array(":book_id" => $book_id)) + 1;
             }
         }
         $old_status = $chap->status;
         $chap->setAttributes($_POST["Chapter"]);
         if ($chap->save()) {
             $chap->setModified();
             if ($chap_id == 0 || $old_status != $chap->status) {
                 $notify = User::model()->watchers($chap->book_id)->findAll();
                 foreach ($notify as $u) {
                     if ($chap_id == 0) {
                         $u->Notify(Notice::CHAPTER_ADDED, $chap->book, $chap);
                     } elseif ($old_status != $chap->status) {
                         $u->Notify(Notice::CHAPTER_STATUS, $chap->book, $chap, Yii::app()->params["translation_statuses"][$chap->status]);
                     }
                 }
             }
             $this->redirect($chap->book->url);
         } else {
             Yii::app()->user->setFlash("error", $chap->getErrorsString());
             $this->redirect($chap->book->url . "#ed={$chap->id}");
         }
     }
     $p = array("chap" => $chap, "ajax" => $ajax, "overridedId" => $overridedId);
     if ($ajax) {
         $this->renderPartial("edit", $p);
     } else {
         $this->render("edit", $p);
     }
 }