Go to the documentation of this file.00001 <?php
00010 class form_file extends form_abstract {
00011
00017 protected $deleted = false;
00018
00024 protected $keep;
00025
00026 protected function beforeInit() {
00027 $required = array_key_exists('required', $this->cfg->valid) && $this->cfg->getInArray('valid', 'required');
00028
00029 $htVars = http_vars::getInstance();
00030 $this->keep = $htVars->getVar($this->name.'NyroKeep');
00031 if ($this->keep)
00032 $this->cfg->value = $this->keep;
00033
00034 $prm = array_merge($this->cfg->fileUploadedPrm, array(
00035 'name'=>$this->cfg->name,
00036 'current'=>$this->cfg->value,
00037 'helper'=>$this->cfg->helper,
00038 'helperPrm'=>$this->cfg->helperPrm,
00039 'required'=>$required
00040 ));
00041
00042 if ($this->cfg->dir)
00043 $prm['dir'] = $this->cfg->dir;
00044 if ($this->cfg->subdir)
00045 $prm['subdir'] = $this->cfg->subdir;
00046
00047 $this->cfg->value = factory::get('form_fileUploaded', $prm);
00048
00049 if ($this->cfg->autoDeleteOnGet && !$this->cfg->value->isSaved() && $htVars->getVar($this->name.'NyroDel')) {
00050 $this->cfg->value->delete();
00051 $this->deleted = true;
00052 }
00053
00054 $this->cfg->valid = array_merge($this->cfg->valid, array(
00055 'callback'=>array($this->cfg->value, 'isValid')
00056 ));
00057 }
00058
00059 protected function afterInit() {
00060 parent::afterInit();
00061 if (!$this->isValid())
00062 $this->cfg->classLine.= ' fileError';
00063 }
00064
00065 public function getValue() {
00066 return $this->cfg->value->getCurrent();
00067 }
00068
00069 public function setValue($value, $refill = false) {
00070 if (!$this->deleted && !$refill) {
00071 if ($value || !$this->keep)
00072 $this->cfg->value->setCurrent($value, $refill);
00073 }
00074 }
00075
00083 public function uploadify(array $opt = array(), $hideSubmit = true) {
00084 $resp = response::getInstance();
00085 $resp->addJs('jquery');
00086 $resp->addJs('swfobject');
00087 $resp->addJs('uploadify');
00088 $resp->addCss('uploadify');
00089
00090 $uploadifyOpt = array_merge(array(
00091 'fileDataName'=>$this->name
00092 ), $this->cfg->uploadify, $opt);
00093
00094 if (request::isLocal())
00095 $uploadifyOpt['scriptAccess'] = 'always';
00096
00097 $resp->blockjQuery('$("#'.$this->id.'").uploadify('.utils::jsEncode($uploadifyOpt).');');
00098 if ($hideSubmit)
00099 $resp->blockjQuery('$("#'.$this->id.'").closest("form").find("fieldset.submit").hide();');
00100 }
00101
00102 public function toHtml() {
00103 if ($this->cfg->mode == 'view')
00104 return $this->cfg->value->getView();
00105
00106 $start = $delLink = null;
00107 if ($this->cfg->showPreviewDelete) {
00108 $start = '<p>';
00109 if ($this->cfg->value->getCurrent()) {
00110 $delLink.= '<input type="hidden" name="'.$this->name.'NyroKeep" value="'.$this->cfg->value->getCurrent().'" />';
00111 $delLink.= '<span>
00112 <a href="#" class="deleteFile" id="'.$this->id.'NyroDel">'.$this->cfg->deleteLabel.'</a>'
00113 .$this->cfg->value->getView().'</span></p>';
00114 response::getInstance()->blockJquery('
00115 $("#'.$this->id.'NyroDel").click(function(e) {
00116 e.preventDefault();
00117 $(this).parent("span").replaceWith("<input type=\"hidden\" name=\"'.$this->name.'NyroDel\" value=\"1\" />");
00118 });');
00119 } else
00120 $delLink = '</p>';
00121 }
00122 return $start.utils::htmlTag($this->htmlTagName,
00123 array_merge($this->html, array(
00124 'name'=>$this->name,
00125 'id'=>$this->id,
00126 ))).$delLink;
00127 }
00128
00129 public function toXul() {
00130 return utils::htmlTag($this->xulTagName,
00131 array_merge($this->xul, array(
00132 'id'=>$this->id,
00133 )));
00134 }
00135
00136 }