/**
  * @Override FC_Document_Manager::edit()
  *
  * This is a copy and paste of the overridden function
  * except that the module for the form is set to intern.
  * Also, check if the folder has been set. If not create
  * one for the user and load it.
  */
 public function edit()
 {
     if (empty($this->document)) {
         $this->loadDocument();
     }
     // If the folder ID is zero then it was not found
     // when InternFolder::documentUpload() was called.
     // Create one and load it.
     if ($this->folder->id == 0) {
         \PHPWS_Core::requireInc('filecabinet', 'defines.php');
         $folder = new InternFolder();
         $folder->module_created = 'intern';
         $folder->title = 'intern documents';
         $folder->public_folder = FALSE;
         $folder->ftype = DOCUMENT_FOLDER;
         $folder->loadDirectory();
         $folder->save();
         $this->folder = $folder;
     }
     \PHPWS_Core::initCoreClass('File.php');
     $form = new \PHPWS_FORM();
     $form->addHidden('module', 'intern');
     $form->addHidden('internship', $_REQUEST['internship']);
     $form->addHidden('action', 'post_document_upload');
     $form->addHidden('ms', $this->max_size);
     $form->addHidden('folder_id', $this->folder->id);
     $form->addFile('file_name');
     $form->setSize('file_name', 30);
     $form->setLabel('file_name', dgettext('filecabinet', 'Document location'));
     $form->addText('title', $this->document->title);
     $form->setSize('title', 40);
     $form->setLabel('title', dgettext('filecabinet', 'Title'));
     $form->addTextArea('description', $this->document->description);
     $form->setLabel('description', dgettext('filecabinet', 'Description'));
     if ($this->document->id) {
         $form->addTplTag('FORM_TITLE', dgettext('filecabinet', 'Update file'));
         $form->addHidden('document_id', $this->document->id);
         $form->addSubmit('submit', dgettext('filecabinet', 'Update'));
     } else {
         $form->addTplTag('FORM_TITLE', dgettext('filecabinet', 'Upload new file'));
         $form->addSubmit('upload', dgettext('filecabinet', 'Upload'));
     }
     $form->addButton('cancel', dgettext('filecabinet', 'Cancel'));
     $form->setExtra('cancel', 'onclick="window.close()"');
     $form->setExtra('upload', 'onclick="this.style.display=\'none\'"');
     if ($this->document->id && Current_User::allow('filecabinet', 'edit_folders', $this->folder->id, 'folder', true)) {
         Cabinet::moveToForm($form, $this->folder);
     }
     $template = $form->getTemplate();
     if ($this->document->id) {
         $template['CURRENT_DOCUMENT_LABEL'] = dgettext('filecabinet', 'Current document');
         $template['CURRENT_DOCUMENT_ICON'] = $this->document->getIconView();
         $template['CURRENT_DOCUMENT_FILE'] = $this->document->file_name;
     }
     $template['MAX_SIZE_LABEL'] = dgettext('filecabinet', 'Maximum file size');
     $sys_size = str_replace('M', '', ini_get('upload_max_filesize'));
     $sys_size = $sys_size * 1000000;
     if ((int) $sys_size < (int) $this->max_size) {
         $template['MAX_SIZE'] = sprintf(dgettext('filecabinet', '%d bytes (system wide)'), $sys_size);
     } else {
         $template['MAX_SIZE'] = sprintf(dgettext('filecabinet', '%d bytes'), $this->max_size);
     }
     if ($this->document->_errors) {
         $template['ERROR'] = $this->document->printErrors();
     }
     return \PHPWS_Template::process($template, 'filecabinet', 'Forms/document_edit.tpl');
     //        Layout::add(PHPWS_Template::process($template, 'filecabinet', 'document_edit.tpl'));
 }
Exemplo n.º 2
0
 public function edit()
 {
     if (empty($this->document)) {
         $this->loadDocument();
     }
     PHPWS_Core::initCoreClass('File.php');
     $form = new PHPWS_FORM();
     $form->setFormId('file-form');
     $form->addHidden('module', 'filecabinet');
     $form->addHidden('dop', 'post_document_upload');
     $form->addHidden('ms', $this->max_size);
     $form->addHidden('folder_id', $this->folder->id);
     $form->addFile('file_name');
     $form->setLabel('file_name', dgettext('filecabinet', 'Document location'));
     $form->addText('title', $this->document->title);
     $form->setLabel('title', dgettext('filecabinet', 'Title'));
     $form->setClass('title', 'form-control');
     $form->addSubmit('upload', 'Upload document');
     $form->setClass('upload', 'btn btn-primary');
     if ($this->document->id) {
         $this->title = dgettext('filecabinet', 'Update file');
         $form->addHidden('document_id', $this->document->id);
     } else {
         $this->title = dgettext('filecabinet', 'Upload new file');
     }
     if ($this->document->id && Current_User::allow('filecabinet', 'edit_folders', $this->folder->id, 'folder', true)) {
         Cabinet::moveToForm($form, $this->folder);
     }
     $template = $form->getTemplate();
     if ($this->document->id) {
         $template['CURRENT_DOCUMENT_LABEL'] = dgettext('filecabinet', 'Current document');
         $template['CURRENT_DOCUMENT_ICON'] = $this->document->getIconView();
         $template['CURRENT_DOCUMENT_FILE'] = $this->document->file_name;
     }
     $template['MAX_SIZE_LABEL'] = dgettext('filecabinet', 'Maximum file size');
     $sys_size = str_replace('M', '', ini_get('upload_max_filesize'));
     $sys_size = $sys_size * 1000000;
     if ((int) $sys_size < (int) $this->max_size) {
         $template['MAX_SIZE'] = sprintf(dgettext('filecabinet', '%d bytes (system wide)'), $sys_size);
     } else {
         $template['MAX_SIZE'] = sprintf(dgettext('filecabinet', '%d bytes'), $this->max_size);
     }
     $this->content = PHPWS_Template::process($template, 'filecabinet', 'Forms/document_edit.tpl');
 }