';
var $_file = null;
var $titles = array(
'pre_link' => '',
'pre_empty' => '',
'pre_del' => '',
'pre_file' => '',
'last' => ''
);
var $_emptyTitle = 'No file yet';
var $_linkTitle = 'Download file';
var $_delTitle = 'Delete file';
function HTML_QuickForm_file_db($name=null, $label='', $file = null, $delTitle = null, $attributes=null)
{
$this->HTML_QuickForm_group($name, $label, $attributes);
require_once('class/Arr.php');
if ( Arr::getSubElem($_POST, $this->getName().'[file_name]') ){
$file = Arr::getSubElem($_POST, $this->getName().'[file_name]');
}
if (!is_null( $delTitle) ){
$this->setDelTitle($delTitle);
}
if ('' != $file ){
$this->setFile($file);
}
}
function onQuickFormEvent($event, $arg, &$caller)
{
$defaultValues = $caller->_defaultValues;
switch ($event) {
case 'updateValue':
$this->_elements = array();
$value = $this->_findValue($caller->_constantValues);
if (null === $value) {
$value = $this->_findValue($caller->_submitValues);
if (null === $value) {
$value = $this->_findValue($caller->_defaultValues);
}
}
if (!is_null($value)) {
$this->setFile($value);
}
$defaultValues = $caller->_defaultValues;
$caller->_defaultValues = array();
parent::onQuickFormEvent($event, $arg, $caller);
$caller->_defaultValues = $defaultValues;
break;
default:
parent::onQuickFormEvent($event, $arg, $caller);
}
return true;
}
function setValue($value)
{
$this->setFile($value);
}
function _createElements()
{
$this->_elements = array();
$this->_elements['file_name'] =& HTML_QuickForm::createElement('hidden', 'file_name', $this->getFile());
if ($this->getFile()) {
if ($this->titles['pre_link']){
$this->_elements['pre_link'] =& HTML_QuickForm::createElement('static', 'pre_link', $this->titles['pre_link']);
}
$this->_elements['link'] =& HTML_QuickForm::createElement('link', 'link', null, file_db($this->getFile()), $this->getLinkTitle(), array('target' => '_blank') );
if ($this->getDelTitle()) {
if ($this->titles['pre_del']){
$this->_elements['pre_del'] =& HTML_QuickForm::createElement('static', 'pre_del', $this->titles['pre_del']);
}
$this->_elements['checkbox'] =& HTML_QuickForm::createElement('checkbox', 'del', null, $this->getDelTitle() );
}
}else {
if ($this->titles['pre_empty']){
$this->_elements['pre_empty'] =& HTML_QuickForm::createElement('static', 'pre_empty', $this->titles['pre_empty']);
}
$this->_elements[] =& HTML_QuickForm::createElement('static', 'static', $this->getEmptyTitle() );
}
if ($this->titles['pre_file']){
$this->_elements['pre_file'] =& HTML_QuickForm::createElement('static', 'pre_file', $this->titles['pre_file']);
}
$this->_elements['file'] =& HTML_QuickForm::createElement('file', 'file' );
if ($this->titles['last']){
$this->_elements['last'] =& HTML_QuickForm::createElement('static', 'last', $this->titles['last']);
}
}
function isUploadedFile()
{
$file = $this->_getElemByName('file');
return $file->isUploadedFile();
}
function _getElemByName($name)
{
$elements = $this->getElements();
foreach ($this->getElements() as $elem) {
if ($name == $elem->_attributes['name']){
return $elem;
}
}
return null;
}
function exportValue()
{
return null;
}
function getValue()
{
$file = $this->_getElemByName('file');
$del = $this->_getElemByName('del');
$value = $file->getValue();
if (is_callable(array(&$del, 'getValue'))) {
$value['del'] = $del->getValue();
}
return $value;
}
function _ruleCheckFileName($elementValue, $regex)
{
if (isset($elementValue['file'])){
$elementValue = $elementValue['file'];
}
return HTML_QuickForm_file::_ruleCheckFileName($elementValue, $regex);
}
function _ruleCheckMimeType($elementValue, $mimeType)
{
if (isset($elementValue['file'])){
$elementValue = $elementValue['file'];
}
return HTML_QuickForm_file::_ruleCheckMimeType($elementValue, $mimeType);
}
function _ruleCheckMaxFileSize($elementValue, $maxSize)
{
if (isset($elementValue['file'])){
$elementValue = $elementValue['file'];
}
return HTML_QuickForm_file::_ruleCheckMaxFileSize($elementValue, $maxSize);
}
function _ruleIsUploadedFile($elementValue)
{
if (isset($elementValue['file'])){
$elementValue = $elementValue['file'];
}
return HTML_QuickForm_file::_ruleIsUploadedFile($elementValue);
}
function setFile($file)
{
if (is_scalar($file)){
$this->_file = $file;
}elseif (is_array($file) && isset($file['file_name'])) {
$this->_file = $file['file_name'];
}
return true;
}
function getFile()
{
return $this->_file;
}
function setLinkTitle($title)
{
$this->_linkTitle = $title;
}
function getLinkTitle()
{
return $this->_linkTitle;
}
function setDelTitle($title)
{
$this->_delTitle = $title;
}
function getDelTitle()
{
return $this->_delTitle;
}
function setEmptyTitle($title)
{
$this->_emptyTitle = $title;
}
function getEmptyTitle()
{
return $this->_emptyTitle;
}
}
?>