Ejemplo n.º 1
0
 public function edit_section()
 {
     if (!fse_try_to_login()) {
         header("location:/fse_login");
         return;
     }
     $project_id = $this->post('projectID');
     $domain_handle = $this->post('domainHandle');
     $volume_handle = $this->post('volumeHandle');
     $part_handle = $this->post('partHandle');
     $chapter_handle = $this->post('chapterHandle');
     $section_id = $this->post('sectionID');
     $content_type = $this->post('contentType');
     $content_format = $this->post('contentFormat');
     $content_code_lang = $this->post('contentCodeLang');
     $content_wrapper = $this->post('contentWrapper');
     $content_style = $this->post('contentStyle');
     $content_alignment = $this->post('contentAlignment');
     $section_subject = $this->post('sectionSubject');
     $section_content = $this->post('sectionContent');
     $page_path = ProjectInfo::assemblePath($project_id, $domain_handle, $volume_handle, $part_handle, $chapter_handle);
     $page_id = Page::getByPath($page_path)->getCollectionID();
     $fse_id = $_SESSION['FSEInfo']['fse_id'];
     $form_token_name = $this->post('formTokenName');
     if (isset($form_token_name)) {
         $form_token = $this->post('formToken');
         if ($_SESSION[$form_token_name] != $form_token) {
             unset($_SESSION[$form_token_name]);
             set_page_action_status($page_id, t('Edit Section'), 'error', t('Bad request or session expired!'));
             header("Location: {$page_path}");
             return;
         }
         unset($_SESSION[$form_token_name]);
     } else {
         if (!isset($_SESSION['FSEInfo'])) {
             set_page_action_status($page_id, t('Edit Section'), 'error', t('You do not sign in or session expired.'));
             header("Location: {$page_path}");
             return;
         }
         $project_info = ProjectInfo::getBasicInfo($project_id);
         if ($project_info == false) {
             set_page_action_status($page_id, t('Edit Section'), 'error', t('No such project!'));
             header("Location: {$page_path}");
             return;
         }
         if (substr(ProjectInfo::getUserRights($project_id, $fse_id), 1, 1) != 't') {
             set_page_action_status($page_id, t('Edit Section'), 'error', t('You have no right to edit the content of this project.'));
             header("Location: {$page_path}");
             return;
         }
     }
     $type_handle = DocSectionManager::getContentTypeHandle($content_type, $content_format, $content_code_lang, $content_wrapper, $content_style, $content_alignment);
     if ($type_handle == false) {
         set_page_action_status($page_id, t('Edit Section'), 'error', t('Bad content type.'));
         header("Location: {$page_path}");
         return;
     }
     if (mb_strlen($section_content) < self::MIN_CONTENT_LEN) {
         set_page_action_status($page_id, t('Edit Section'), 'error', t('Too short content!'));
         header("Location: {$page_path}");
         return;
     }
     $attached_files = '[';
     for ($i = 0; $i < DocSectionManager::MAX_ATTACHED_FILES; $i++) {
         $attached_file_id = (int) $this->post("attachmentFile{$i}");
         if ($attached_file_id > 0) {
             $attached_files .= "{$attached_file_id}, ";
         }
     }
     $attached_files = rtrim($attached_files, ', ');
     $attached_files .= ']';
     $section_manager = new DocSectionManager();
     $res = $section_manager->addNewSectionVersion($project_id, $fse_id, $domain_handle, $section_id, $type_handle, $section_subject, $section_content, $attached_files);
     if ($res != DocSectionManager::EC_OK) {
         set_page_action_status($page_id, t('Edit Section'), 'error', t('Failed to add a new version: %s', $section_manager->getErrorMessage($res)));
         header("Location: {$page_path}");
         return;
     }
     set_page_action_status($page_id, t('Edit Section'), 'success', t('Succeed to add a new section version.'), $form_token_name);
     header("Location: {$page_path}");
 }