Exemplo n.º 1
0
 public function edit()
 {
     static $folder;
     if (empty($this->multimedia)) {
         $this->loadMultimedia();
     }
     if (empty($folder)) {
         $folder = new Folder($this->multimedia->folder_id);
     }
     PHPWS_Core::initCoreClass('File.php');
     $form = new PHPWS_FORM();
     $form->setFormId('file-form');
     $form->addHidden('module', 'filecabinet');
     $form->addHidden('mop', 'post_multimedia_upload');
     $form->addHidden('ms', $this->max_size);
     $form->addHidden('folder_id', $this->multimedia->folder_id);
     $form->addFile('file_name');
     $form->setLabel('file_name', dgettext('filecabinet', 'Multimedia location'));
     $form->addText('title', $this->multimedia->title);
     $form->setLabel('title', dgettext('filecabinet', 'Title'));
     $form->setClass('title', 'form-control');
     $form->addTextArea('description', $this->multimedia->description);
     $form->setLabel('description', dgettext('filecabinet', 'Description'));
     $form->setClass('description', 'form-control');
     if ($this->multimedia->id) {
         $this->title = 'Edit multimedia';
         $form->addHidden('multimedia_id', $this->multimedia->id);
         $form->addText('width', $this->multimedia->width);
         $form->setLabel('width', dgettext('filecabinet', 'Width'));
         $form->addText('height', $this->multimedia->height);
         $form->setLabel('height', dgettext('filecabinet', 'Height'));
     } else {
         $this->title = 'Upload multimedia';
     }
     if ($this->multimedia->id && Current_User::allow('filecabinet', 'edit_folders', $this->multimedia->folder_id, 'folder', true)) {
         Cabinet::moveToForm($form, $folder);
     }
     $template = $form->getTemplate();
     if ($this->multimedia->id) {
         $template['CURRENT_MULTIMEDIA_LABEL'] = dgettext('filecabinet', 'Current multimedia');
         $template['CURRENT_MULTIMEDIA_ICON'] = $this->multimedia->getThumbnail();
         $template['CURRENT_MULTIMEDIA_FILE'] = $this->multimedia->file_name;
         $ow['address'] = PHPWS_Text::linkAddress('filecabinet', array('aop' => 'change_tn', 'type' => 'mm', 'id' => $this->multimedia->id), true);
         $ow['label'] = 'Change thumbnail';
         $ow['width'] = 400;
         $ow['height'] = 250;
         $template['EDIT_THUMBNAIL'] = javascript('open_window', $ow);
     }
     $template['MAX_SIZE_LABEL'] = dgettext('filecabinet', 'Maximum file size');
     $size_max = Cabinet::getMaxSizes();
     $sys_size =& $size_max['system'];
     $form_max =& $size_max['form'];
     if ($form_max < $sys_size && $form_max < $this->max_size) {
         $max_size =& $form_max;
     } elseif ($sys_size < $form_max && $sys_size < $this->max_size) {
         $max_size =& $sys_size;
     } else {
         $max_size =& $this->max_size;
     }
     if ($max_size >= 1000000) {
         $template['MAX_SIZE'] = sprintf(dgettext('filecabinet', '%dMB (%d bytes)'), floor($max_size / 1000000), $max_size);
     } elseif ($max_size >= 1000) {
         $template['MAX_SIZE'] = sprintf(dgettext('filecabinet', '%dKB (%d bytes)'), floor($max_size / 1000), $max_size);
     } else {
         $template['MAX_SIZE'] = sprintf(dgettext('filecabinet', '%d bytes'), $max_size);
     }
     if ($this->message) {
         $template['ERROR'] = $this->message;
     }
     $this->content = PHPWS_Template::process($template, 'filecabinet', 'Forms/multimedia_edit.tpl');
 }
 /**
  * @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'));
 }