public function __construct($vars, $title = '', $name = null) { parent::__construct($vars, $title, $name); $v = $this->addVariable(_("Spam Level:"), 'level', 'int', true, false, _("Messages with a likely spam score greater than or equal to this number will be treated as spam.")); $v->setHelp('spam-level'); $this->folder_var = $this->addVariable(_("Folder to receive spam:"), 'folder', 'ingo_folders', true); $this->folder_var->setHelp('spam-folder'); $this->addHidden('', 'actionID', 'text', false); $this->addHidden('', 'folder_new', 'text', false); $this->setButtons(_("Save")); }
/** * Additional validate of start and end date fields. */ public function validate($vars = null, $canAutoFill = false) { $valid = true; if (!parent::validate($vars, $canAutoFill)) { $valid = false; } if ($this->hasFeature('period')) { $this->_start->getInfo($vars, $start); $this->_end->getInfo($vars, $end); if ($start && $end && $end < $start) { $valid = false; $this->_errors['end'] = _("Vacation end date is prior to start."); } if ($end && $end < mktime(0, 0, 0)) { $valid = false; $this->_errors['end'] = _("Vacation end date is prior to today."); } } return $valid; }
/** * Gets the upload and sets up the upload data array. Either * fetches an upload done with this submit or retrieves stored * upload info. * @param Horde_Variables $vars The form state to check this field for * @param Horde_Form_Variable $var The Form field object to check * */ function _getUpload(&$vars, &$var) { global $session; /* Don't bother with this function if already called and set * up vars. */ if (!empty($this->_img)) { return true; } /* Check if file has been uploaded. */ $varname = $var->getVarName(); try { $GLOBALS['browser']->wasFileUploaded($varname . '[new]'); $this->_uploaded = true; /* A file has been uploaded on this submit. Save to temp dir for * preview work. */ $this->_img['img']['type'] = $this->getUploadedFileType($varname . '[new]'); /* Get the other parts of the upload. */ Horde_Array::getArrayParts($varname . '[new]', $base, $keys); /* Get the temporary file name. */ $keys_path = array_merge(array($base, 'tmp_name'), $keys); $this->_img['img']['file'] = Horde_Array::getElement($_FILES, $keys_path); /* Get the actual file name. */ $keys_path = array_merge(array($base, 'name'), $keys); $this->_img['img']['name'] = Horde_Array::getElement($_FILES, $keys_path); /* Get the file size. */ $keys_path = array_merge(array($base, 'size'), $keys); $this->_img['img']['size'] = Horde_Array::getElement($_FILES, $keys_path); /* Get any existing values for the image upload field. */ $upload = $vars->get($var->getVarName()); if (!empty($upload['hash'])) { $upload['img'] = $session->get('horde', 'form/' . $upload['hash']); $session->remove('horde', 'form/' . $upload['hash']); } /* Get the temp file if already one uploaded, otherwise create a * new temporary file. */ if (!empty($upload['img']['file'])) { $tmp_file = Horde::getTempDir() . '/' . $upload['img']['file']; } else { $tmp_file = Horde::getTempFile('Horde', false); } /* Move the browser created temp file to the new temp file. */ move_uploaded_file($this->_img['img']['file'], $tmp_file); $this->_img['img']['file'] = basename($tmp_file); } catch (Horde_Browser_Exception $e) { $this->_uploaded = $e; /* File has not been uploaded. */ $upload = $vars->get($var->getVarName()); /* File is explicitly removed */ if ($vars->get('remove_' . $var->getVarName())) { $this->_img = null; $session->remove('horde', 'form/' . $upload['hash']); return; } if ($this->_uploaded->getCode() == 4 && !empty($upload['hash']) && $session->exists('horde', 'form/' . $upload['hash'])) { $this->_img['img'] = $session->get('horde', 'form/' . $upload['hash']); $session->remove('horde', 'form/' . $upload['hash']); if (isset($this->_img['error'])) { $this->_uploaded = PEAR::raiseError($this->_img['error']); } } } if (isset($this->_img['img'])) { $session->set('horde', 'form/' . $this->getRandomId(), $this->_img['img']); } }
/** * TODO */ function addHidden($humanName, $varName, $type, $required, $readonly = false, $description = null, $params = array()) { $type = $this->getType($type, $params); $var = new Horde_Form_Variable($humanName, $varName, $type, $required, $readonly, $description); $var->hide(); $this->_hiddenVariables[] =& $var; return $var; }