public function addFolder()
 {
     $form = new Form('form-addfolder', Router::getInstance()->build('BrowserController', 'addFolder'));
     $fieldset = new Fieldset(System::getLanguage()->_('AddFolder'));
     $name = new Text('name', System::getLanguage()->_('FolderName'), true);
     $parent = new Select('parent', System::getLanguage()->_('ParentFolder'), Folder::getAll());
     $parent->selected_value = Utils::getGET('parent', 0);
     $fieldset->addElements($name, $parent);
     $form->addElements($fieldset);
     if (Utils::getPOST('submit', false) !== false) {
         if ($form->validate()) {
             try {
                 $folder = new Folder($parent->selected_value);
                 $folder->addFolder($name->value);
                 if ($folder->id == 0) {
                     System::forwardToRoute(Router::getInstance()->build('BrowserController', 'index'));
                 } else {
                     System::forwardToRoute(Router::getInstance()->build('BrowserController', 'show', $folder->id));
                 }
                 exit;
             } catch (InvalidFolderNameException $e) {
                 $name->error = System::getLanguage()->_('ErrorInvalidFolderName');
             } catch (FolderAlreadyExistsException $e) {
                 $name->error = System::getLanguage()->_('ErrorFolderAlreadyExists');
             } catch (Exception $e) {
                 $name->error = System::getLanguage()->_('ErrorInvalidParameter');
             }
         }
     }
     $form->setSubmit(new Button(System::getLanguage()->_('Create'), 'icon icon-new-folder'));
     $smarty = new Template();
     $smarty->assign('title', System::getLanguage()->_('AddFolder'));
     $smarty->assign('form', $form->__toString());
     $smarty->display('form.tpl');
 }
예제 #2
0
 /**
  * Gets a list of folders incl. subfolders
  * @return object[]
  */
 public static function getAll($parent = NULL, $keys = true, $exclude = array(), $prefix = ' / ')
 {
     $list = array();
     // Add root folder if necessary
     if ($parent == NULL) {
         $list[] = $prefix;
     }
     $folders = Folder::find('parent', $parent);
     if ($folders != NULL) {
         if (!is_array($folders)) {
             $folders = array($folders);
         }
         if (count($folders) > 0) {
             foreach ($folders as $folder) {
                 if (!in_array($folder->id, $exclude)) {
                     if ($keys == true) {
                         $list[$folder->id] = $prefix . $folder->name;
                     } else {
                         $list[] = $prefix . $folder->name;
                     }
                     $list += Folder::getAll($folder->id, $keys, $exclude, $prefix . $folder->name . ' / ');
                 }
             }
         }
     }
     return $list;
 }
 public function upload()
 {
     $form = new Form('form-upload', Router::getInstance()->build('UploadController', 'upload'));
     $form->setAttribute('data-noajax', 'true');
     $form->setEnctype();
     $fieldset = new Fieldset(System::getLanguage()->_('General'));
     $folderInput = new Select('folder', System::getLanguage()->_('ChooseFolder'), Folder::getAll());
     $folderInput->selected_value = Utils::getGET('parent', NULL);
     $fieldset->addElements($folderInput);
     $form->addElements($fieldset);
     $fieldset = new Fieldset(System::getLanguage()->_('FileUpload'));
     $fileInput = new FileUpload('file', System::getLanguage()->_('ChooseFile'), false);
     $fieldset->addElements($fileInput);
     $form->addElements($fieldset);
     if (DOWNLOAD_VIA_SERVER) {
         $fieldset = new Fieldset(System::getLanguage()->_('UploadFromURL'));
         $url = new Text('url', System::getLanguage()->_('EnterURL'), false);
         $name = new Text('name', System::getLanguage()->_('Name'), false);
         $name->setValue(System::getLanguage()->_('DownloadedFile'));
         $fieldset->addElements($url, $name);
         $form->addElements($fieldset);
     }
     $fieldset = new Fieldset(System::getLanguage()->_('PermissionSetting'));
     $permissionInput = new Select('permissions', System::getLanguage()->_('Permission'), FilePermissions::getAll());
     $permissionInput->selected_value = DEFAULT_FILE_PERMISSION;
     $password = new Password('password', System::getLanguage()->_('Password'), false);
     $fieldset->addElements($permissionInput, $password);
     $form->addElements($fieldset);
     if (Utils::getPOST('submit', false) != false) {
         if ($permissionInput->selected_value == 2 && empty($password->value)) {
             $password->error = System::getLanguage()->_('ErrorEmptyTextfield');
         } else {
             if ($form->validate() && (!empty($url->value) || !empty($fileInput->uploaded_file))) {
                 // Specify input control for error display
                 $err = empty($url->value) ? $fileInput : $url;
                 try {
                     $folder = Folder::find('_id', $folderInput->selected_value);
                     $file = new File();
                     $file->folder = $folder;
                     $file->permission = $permissionInput->selected_value;
                     $file->password = $password->value;
                     if (empty($url->value)) {
                         $file->filename = $fileInput->filename;
                         $file->upload($fileInput->uploaded_file);
                     } else {
                         $file->filename = $name->value;
                         $file->remote($url->value);
                     }
                     $file->save();
                     System::forwardToRoute(Router::getInstance()->build('BrowserController', 'show', $folder));
                     exit;
                 } catch (UploadException $e) {
                     $fileInput->filename = '';
                     $fileInput->uploaded_file = '';
                     $err->error = $e->getMessage();
                     if ($e->getCode() != 0) {
                         $err->error .= ' Code: ' . $e->getCode();
                     }
                 } catch (QuotaExceededException $e) {
                     $err->error = System::getLanguage()->_('ErrorQuotaExceeded');
                 } catch (Exception $e) {
                     $fileInput->filename = '';
                     $fileInput->uploaded_file = '';
                     $err->error = System::getLanguage()->_('ErrorWhileUpload') . ' ' . $e->getMessage();
                 }
             }
         }
     }
     $form->setSubmit(new Button(System::getLanguage()->_('Upload'), 'open'));
     if ($folderInput->selected_value == 0) {
         $form->addButton(new Button(System::getLanguage()->_('Cancel'), '', Router::getInstance()->build('BrowserController', 'index')));
     } else {
         $form->addButton(new Button(System::getLanguage()->_('Cancel'), '', Router::getInstance()->build('BrowserController', 'show', new Folder($folderInput->selected_value))));
     }
     $smarty = new Template();
     $smarty->assign('title', System::getLanguage()->_('Upload'));
     $smarty->assign('heading', System::getLanguage()->_('FileUpload'));
     $smarty->assign('form', $form->__toString());
     $smarty->assign('BODY_CLASS', 'preventreload');
     $smarty->requireResource('upload');
     $smarty->display('form.tpl');
 }