/** * Upload image form */ public function edit($force_width = 0, $force_height = 0) { $form = new PHPWS_Form(); $form->setFormId('file-form'); $form->addHidden('module', 'filecabinet'); $form->addHidden('iop', 'post_image_upload'); $form->addHidden('ms', $this->max_size); $form->addHidden('mh', $this->max_height); $form->addHidden('mw', $this->max_width); $form->addHidden('folder_id', $this->folder->id); if ($this->image->id && Current_User::allow('filecabinet', 'edit_folders', $this->folder->id, 'folder', true)) { Cabinet::moveToForm($form, $this->folder); } // if 'im' is set, then we are inside the image manage interface // the post needs to be aware of that to respond correctly if (isset($_GET['im'])) { $form->addHidden('im', 1); } if ($this->image->id) { $form->addHidden('image_id', $this->image->id); $this->title = dgettext('filecabinet', 'Update image'); } else { $this->title = dgettext('filecabinet', 'Upload image'); } $form->addFile('file_name'); $form->setClass('file_name', 'form-control'); $form->setSize('file_name', 30); $form->setMaxFileSize($this->max_size); $form->setLabel('file_name', dgettext('filecabinet', 'Image location')); $form->addText('title', $this->image->title); $form->setLabel('title', dgettext('filecabinet', 'Title')); $form->setClass('title', 'form-control'); $form->addTextArea('description', $this->image->description); $form->setRows('description', 8); $form->setCols('description', 45); $form->setLabel('description', dgettext('filecabinet', 'Description')); if ($this->image->folder_id) { $folder = new Folder($this->image->folder_id); if ($folder->public_folder) { $link_choice['folder'] = dgettext('filecabinet', 'Link to image folder'); } } if ($this->folder->max_image_dimension && $this->folder->max_image_dimension < $this->max_width) { $max_width = $this->folder->max_image_dimension; } else { $max_width = $this->max_width; } if ($force_width && $force_height) { $form->addHidden('fw', $force_width); $form->addHidden('fh', $force_height); $form->addTplTag('RESIZE_LABEL', dgettext('filecabinet', 'Images resized to:')); $form->addTplTag('RESIZE', sprintf('%s x %spx', $force_width, $force_height)); } elseif (!$this->image->id) { $resizes = Cabinet::getResizes($max_width); if (!empty($resizes)) { $form->addSelect('resize', $resizes); $form->setLabel('resize', dgettext('filecabinet', 'Resize image if over')); } } switch (1) { case empty($this->image->url): $form->setMatch('link', 'none'); $form->addTplTag('VISIBLE', 'none'); $form->setValue('url', 'http://'); break; case $this->image->url == 'parent': $form->setMatch('link', 'parent'); $form->addTplTag('VISIBLE', 'none'); break; case $this->image->url == 'folder': $form->setMatch('link', 'folder'); $form->addTplTag('VISIBLE', 'none'); break; default: $form->setMatch('link', 'url'); $form->setValue('url', $this->image->url); $form->addTplTag('VISIBLE', 'table-row'); break; } if (!empty($this->image->id)) { $form->addSubmit('submit', dgettext('filecabinet', 'Update')); } else { $form->addSubmit('submit', dgettext('filecabinet', 'Upload')); } $form->setClass('submit', 'btn btn-primary'); $template = $form->getTemplate(); $template['CANCEL'] = sprintf('<input type="button" value="%s" onclick="javascript:window.close()" />', dgettext('filecabinet', 'Cancel')); if ($this->image->id) { $template['CURRENT_IMAGE_LABEL'] = dgettext('filecabinet', 'Current image'); $template['CURRENT_IMAGE'] = $this->image->getJSView(TRUE); $template['SIZE'] = sprintf('%s x %s', $this->image->width, $this->image->height); } $template['MAX_SIZE_LABEL'] = dgettext('filecabinet', 'Maximum file size'); $template['MAX_DIMENSION_LABEL'] = dgettext('filecabinet', 'Maximum image dimension'); $template['MAX_DIMENSION'] = $this->max_width; $sys_size = str_replace('M', '', ini_get('upload_max_filesize')); $sys_size = $sys_size * 1000000; $form_max = $form->max_file_size; 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; } $template['MAX_SIZE'] = File_Common::humanReadable($max_size); $template['ERRORS'] = $this->image->printErrors(); $this->content = PHPWS_Template::process($template, 'filecabinet', 'Forms/image_edit.tpl'); }
public function editFolder($folder, $js = false) { $form = new PHPWS_Form('file-form'); $form->addHidden('module', 'filecabinet'); $form->addHidden('aop', 'post_folder'); $form->addHidden('ftype', $folder->ftype); if ($js) { $form->addHidden('js', 1); } if ($folder->id) { $form->addHidden('folder_id', $folder->id); } $form->addTextField('title', $folder->title); $form->setLabel('title', dgettext('filecabinet', 'Title')); $form->setClass('title', 'form-control'); if ($folder->ftype == DOCUMENT_FOLDER) { $form->addRadio('public_folder', array(0, 1)); $form->setLabel('public_folder', array(dgettext('filecabinet', 'Indirect links'), dgettext('filecabinet', 'Direct links'))); } $form->setMatch('public_folder', $folder->public_folder); if ($folder->ftype == IMAGE_FOLDER) { $resizes = Cabinet::getResizes(0, true); $form->addSelect('max_image_dimension', $resizes); $form->setLabel('max_image_dimension', dgettext('filecabinet', 'Maximum image upload dimension')); $form->setMatch('max_image_dimension', $folder->max_image_dimension); $form->setClass('max_image_dimension', 'form-control'); } $form->addSubmit('submit', 'Save folder'); $form->setClass('submit', 'btn btn-primary'); $tpl = $form->getTemplate(); return PHPWS_Template::process($tpl, 'filecabinet', 'Forms/edit_folder.tpl'); }