示例#1
0
 /**
  * Handles admin functions outside of file manager.
  * Expects an 'aop' command.
  */
 public function admin()
 {
     $javascript = false;
     // if true, sends to nakedDisplay
     $this->loadPanel();
     if (isset($_REQUEST['aop'])) {
         $aop = $_REQUEST['aop'];
     } else {
         $aop = $this->panel->getCurrentTab();
     }
     if (!Current_User::isLogged()) {
         Current_User::disallow();
         return;
     }
     if ($aop != 'edit_image' && $aop != 'get_images' && !Current_User::allow('filecabinet')) {
         Current_User::disallow();
         return;
     }
     // Requires an unrestricted user
     switch ($aop) {
         case 'delete_folder':
         case 'unpin':
             if (Current_User::isRestricted('filecabinet')) {
                 Current_User::disallow();
             }
     }
     switch ($aop) {
         case 'image':
             $this->panel->setCurrentTab('image');
             $this->title = dgettext('filecabinet', 'Image folders');
             $this->loadForms();
             $this->forms->getFolders(IMAGE_FOLDER);
             break;
         case 'multimedia':
             $this->panel->setCurrentTab('multimedia');
             $this->title = dgettext('filecabinet', 'Multimedia folders');
             $this->loadForms();
             $this->forms->getFolders(MULTIMEDIA_FOLDER);
             break;
         case 'add_folder':
             if (!Current_User::allow('filecabinet', 'edit_folders', null, null, true)) {
                 Current_User::disallow();
             }
             $javascript = true;
             $this->loadFolder();
             $this->addFolder();
             break;
         case 'classify':
             if (!Current_User::isDeity()) {
                 Current_User::errorPage();
             }
             $this->loadForms();
             $this->forms->classifyFileList();
             break;
         case 'classify_action':
             if (!Current_User::isDeity() || !Current_User::verifyAuthKey()) {
                 Current_User::errorPage();
             }
             $this->classifyAction();
             break;
         case 'classify_file':
             if (!Current_User::isDeity() || !Current_User::verifyAuthKey()) {
                 Current_User::disallow();
             }
             $this->loadForms();
             if (!empty($_POST['file_list'])) {
                 $this->forms->classifyFile($_POST['file_list']);
             } elseif (isset($_GET['file'])) {
                 $this->forms->classifyFile($_GET['file']);
             } else {
                 $this->forms->classifyFileList();
             }
             break;
         case 'post_classifications':
             if (!Current_User::isDeity()) {
                 Current_User::errorPage();
             }
             $result = $this->classifyFiles();
             if (is_array($result)) {
                 $this->message = implode('<br />', $result);
             }
             $this->loadForms();
             $this->forms->classifyFileList();
             break;
         case 'unpin':
             if (!Current_User::authorized('filecabinet')) {
                 Current_User::disallow();
             }
             Cabinet::unpinFolder();
             PHPWS_Core::goBack();
             break;
         case 'pin_form':
             $javascript = true;
             @($key_id = (int) $_GET['key_id']);
             if (!$key_id) {
                 javascript('close_refresh', array('refresh' => 0));
                 break;
             }
             $this->loadForms();
             $this->forms->pinFolder($key_id);
             break;
         case 'delete_folder':
             if (!Current_User::authorized('filecabinet', 'delete_folders', null, null, true)) {
                 Current_User::disallow();
             }
             $this->loadFolder();
             $this->folder->delete();
             PHPWS_Core::goBack();
             break;
         case 'delete_incoming':
             if (!Current_User::isDeity()) {
                 Current_User::errorPage();
             }
             $this->deleteIncoming();
             $this->loadForms();
             $this->forms->classifyFileList();
             break;
         case 'document':
             $this->panel->setCurrentTab('document');
             $this->title = dgettext('filecabinet', 'Document folders');
             $this->loadForms();
             $this->forms->getFolders(DOCUMENT_FOLDER);
             break;
         case 'edit_folder_modal':
             $javascript = true;
             $this->loadFolder();
             // permission check in function below
             $this->editFolder(false);
             break;
         case 'edit_folder':
             $javascript = true;
             $this->loadFolder();
             // permission check in function below
             $this->editFolder(true);
             break;
         case 'change_tn':
             $javascript = true;
             $this->changeTN();
             break;
         case 'post_thumbnail':
             $javascript = true;
             if ($this->postTN()) {
                 javascript('close_refresh');
             } else {
                 $this->message = dgettext('filecabinet', 'Could not save thumbnail image.');
                 $this->changeTN();
             }
             break;
         case 'post_folder':
             if (!Current_User::authorized('filecabinet', 'edit_folders')) {
                 Current_User::disallow();
             }
             $this->loadFolder();
             if ($this->folder->post()) {
                 if (!$this->folder->save()) {
                     self::setMessage(dgettext('filecabinet', 'Failed to create folder. Please check your logs.'));
                 }
             } else {
                 self::setMessage(dgettext('filecabinet', 'Failed to create folder. Please check your logs.'));
             }
             if (filter_input(INPUT_POST, 'js') == 1) {
                 javascript('close_refresh');
             } else {
                 PHPWS_Core::goBack();
             }
             break;
         case 'post_allowed_files':
             if (!Current_User::isDeity()) {
                 Current_User::disallow();
             }
             $this->loadForms();
             $this->forms->postAllowedFiles();
             $this->message = dgettext('filecabinet', 'File types saved.');
             $this->title = dgettext('filecabinet', 'Allowed file types');
             $this->content = $this->forms->fileTypes();
             break;
         case 'save_settings':
             if (!Current_User::isDeity()) {
                 Current_User::disallow();
             }
             $this->loadForms();
             $result = $this->forms->saveSettings();
             if (is_array($result)) {
                 $this->message = implode('<br />', $result);
             } else {
                 $this->message = dgettext('filecabinet', 'Settings saved.');
             }
         case 'settings':
             if (!Current_User::isDeity()) {
                 Current_User::disallow();
             }
             $this->loadForms();
             $this->title = dgettext('filecabinet', 'Settings');
             $this->content = $this->forms->settings();
             break;
         case 'view_folder':
             $this->viewFolder();
             break;
         case 'file_types':
             if (!Current_User::isDeity()) {
                 Current_User::disallow();
             }
             $this->loadForms();
             $this->title = dgettext('filecabinet', 'Allowed file types');
             $this->content = $this->forms->fileTypes();
             break;
         case 'fix_document_dir':
             if (!Current_User::isDeity() || !Current_User::verifyAuthKey()) {
                 Current_User::disallow();
             }
             if (strtolower($_GET['confirm']) == 'yes') {
                 $this->fixDocumentDirectories();
             }
             PHPWS_Core::reroute('index.php?module=filecabinet&tab=settings');
     }
     $template['TITLE'] =& $this->title;
     $template['MESSAGE'] =& $this->message;
     $template['CONTENT'] =& $this->content;
     if ($javascript) {
         $main = PHPWS_Template::process($template, 'filecabinet', 'javascript.tpl');
         Layout::nakedDisplay($main);
     } else {
         $main = PHPWS_Template::process($template, 'filecabinet', 'main.tpl');
         $this->panel->setContent($main);
         $finalPanel = $this->panel->display();
         Layout::add(PHPWS_ControlPanel::display($finalPanel));
     }
 }