Exemplo n.º 1
0
 public function edit_member_roles()
 {
     if (!fse_try_to_login()) {
         header("location:/fse_login");
         return;
     }
     $project_id = $this->post('projectID');
     $area_handle = $this->post('areaHandle');
     $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');
     $member_username = $this->post('memberUsername');
     $member_display_name = $this->post('memberDisplayName');
     $member_desc = $this->post('memberDescription');
     $member_roles = array('g-mmb');
     for ($i = 0; $i < ProjectInfo::NR_ROLES; $i++) {
         $role = $this->post("memberRole{$i}");
         if (in_array($role, ProjectInfo::$mMemberRoleList)) {
             $member_roles[] = $role;
         }
     }
     $member_roles = array_unique($member_roles);
     $role_description = '';
     $doc_lang = substr($project_id, -2);
     foreach ($member_roles as $role) {
         $role_description .= ProjectInfo::$mRoleDescriptions[$doc_lang][$role];
         $role_description .= ' ';
     }
     $member_roles = implode('|', $member_roles);
     $page_path = ProjectInfo::assemblePath($project_id, $domain_handle, $volume_handle, $part_handle, $chapter_handle);
     error_log("Edit Member: {$page_path}\n", 3, '/var/tmp/fsen.log');
     $page_id = Page::getByPath($page_path)->getCollectionID();
     if ($page_id <= 0) {
         header('Location: /');
         return;
     }
     if (!fse_try_to_login()) {
         set_page_action_status($page_id, t('Add/Edit Member Roles'), 'error', t('You do not sign in or session expired.'));
         header("Location: {$page_path}");
         return;
     }
     $curr_fse_id = $_SESSION['FSEInfo']['fse_id'];
     $curr_rights = ProjectInfo::getUserRights($project_id, $curr_fse_id);
     if ($curr_rights[0] != 't') {
         set_page_action_status($page_id, t('Add/Edit Member Roles'), 'error', t('You have no right to edit member roles.'));
         header("Location: {$page_path}");
         return;
     }
     $fse_info = FSEInfo::getBasicProfile($member_username);
     if ($fse_info == false) {
         set_page_action_status($page_id, t('Add/Edit Member Roles'), 'error', t('No such user!'));
         header("Location: {$page_path}");
         return;
     }
     if (strlen($member_display_name) == 0) {
         $member_display_name = $fse_info['nick_name'];
     }
     $member_rights = ProjectInfo::setUserRoles($project_id, $fse_info['fse_id'], $member_display_name, $member_desc, $member_roles);
     if (substr($member_rights, 0, 3) == 'ttt') {
         $style = "primary";
     } else {
         if ($member_rights[0] == 't') {
             $style = "success";
         } else {
             if ($member_rights[1] == 't') {
                 $style = "info";
             } else {
                 if ($member_rights[2] == 't') {
                     $style = "warning";
                 } else {
                     $style = "default";
                 }
             }
         }
     }
     $type_handle = "member:markdown_safe:{$member_username}:{$style}:none";
     $section_content = sprintf(self::MEMBER_MARKDOWN_TEXT, $member_display_name, $fse_info['user_name'], $role_description, h5($member_desc), h5($fse_info['self_desc']), $fse_info['avatar_url']);
     $section_manager = new DocSectionManager();
     $res = $section_manager->addNewSectionVersion($project_id, $curr_fse_id, $domain_handle, $section_id, $type_handle, '', $section_content, '[]');
     if ($res != DocSectionManager::EC_OK) {
         set_page_action_status($page_id, t('Add/Edit Member Roles'), 'error', t('Failed to add/edit member roles: %s', $section_manager->getErrorMessage($res)));
         header("Location: {$page_path}");
         return;
     }
     set_page_action_status($page_id, t('Add/Edit Member Roles'), 'success', t('Succeed to edit the member roles.'));
     header("Location: {$page_path}");
 }