/** * Method to update a file and eventually upload. * * @access public * @param string $fieldName Field that store the file name. * @param array $extensions Allowed extensions. * @param array $options Specific options. * @param string $dir Root folder (can be a pattern). * * @return boolean False on failure or error, true otherwise. */ public function _upload($fieldName, $extensions = null, $options = array(), $dir = null) { //Send the id for eventual name or path parsing in upload $options['id'] = $this->getId(); $config = JComponentHelper::getParams('com_rtiprint'); if (!$dir) { $dir = $config->get('upload_dir_' . $this->view_list . '_' . $fieldName, '[COM_SITE]' . DS . 'files' . DS . $this->view_list . '_' . $fieldName); } $jinput = JFactory::getApplication()->input; //Get the submited files if exists $fileInput = new JInput($_FILES); $files = $fileInput->get('jform', null, 'array'); $uploadFile = array(); //Process a conversion to get the right datas if (!empty($files)) { foreach ($files as $key => $params) { $uploadFile[$key] = $params[$fieldName]; } } $post = $jinput->get('jform', null, 'array'); // Remove parameter $removeVar = $fieldName . "-remove"; $remove = isset($post[$removeVar]) ? $post[$removeVar] : null; // Previous value parameter $previousVar = $fieldName . '-current'; $previous = isset($post[$previousVar]) ? $post[$previousVar] : null; // Upload file name $upload = isset($uploadFile['name']) ? $uploadFile['name'] : null; // New value $fileName = null; //Check method $method = ''; $changed = false; if (!empty($upload)) { $method = 'upload'; $changed = $upload != $previous; } //Check if needed to delete files if (in_array($remove, array('remove', 'delete', 'thumbs', 'trash'))) { $fileName = ""; //Clear DB link (remove) $changed = true; //Process physical removing of the files (All, only thumbs, Move to trash) if (in_array($remove, array('delete', 'thumbs', 'trash'))) { $f = (preg_match("/\\[.+\\]/", $previous) ? "" : $dir . DS) . $previous; if (!RtiprintClassFile::deleteFile($f, $remove)) { JError::raiseWarning(4101, JText::_("RTIPRINT_TASK_RESULT_IMPOSSIBLE_TO_DELETE")); } } } switch ($method) { case 'upload': // Process Upload $uploadClass = new RtiprintClassFileUpload($dir); $uploadClass->setAllowed($extensions); if (!($result = $uploadClass->uploadFile($uploadFile, $options))) { JError::raiseWarning(4100, JText::sprintf("RTIPRINT_TASK_RESULT_IMPOSSIBLE_TO_UPLOAD_FILE", $uploadFile['name'])); return false; } $fileName = $result->filename; $changed = true; break; } if ($changed) { //Store the image file name with path pattern if (!$this->save(array($fieldName => $fileName))) { return false; } } return true; }
* ((((( o < A Component by Morgan Leecy for FGW | * ( o o ) |______________________________________________| * --------oOOO-----(_)-----OOOo------------------------------ www.moledesign.biz --- + * @version 2.2.2 * @package RT iPrint * @subpackage Printermdls * @copyright Copyright FGW 2014, All rights reserved * @author MOLEDesign (Morgan Leecy) - http://www.moledesign.biz - morgan@moledesign.biz * @license GNU/GPL * * .oooO Oooo. * ( ) ( ) * -------------\ (----) /----------------------------------------------------------- + * \_) (_/ */ // no direct access defined('_JEXEC') or die('Restricted access'); $fieldSets = $this->form->getFieldsets(); $fieldSet = $this->form->getFieldset('printermodel.form'); ?> <fieldset class="fieldsform form-horizontal"> <?php // JForms dynamic initialization (Cook Self Service proposal) $fieldSet['jform_manufacturer']->jdomOptions = array('ajaxVars' => array('values' => array($this->item->manufacturer))); $fieldSet['jform_manual']->jdomOptions = array('actions' => array('remove', 'thumbs', 'delete', 'trash'), 'cid' => $this->item->id, 'uploadMaxSize' => RtiprintClassFileUpload::getMaxSize(true)); $fieldSet['jform_image']->jdomOptions = array('actions' => array('remove', 'thumbs', 'delete', 'trash'), 'attrs' => array('format:png'), 'cid' => $this->item->id, 'height' => 100, 'uploadMaxSize' => RtiprintClassFileUpload::getMaxSize(true), 'width' => 100); echo $this->renderFieldset($fieldSet); ?> </fieldset>