예제 #1
0
 /**
  * Get the unique session instance
  *
  * @return http_vars The instance
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new http_vars();
     }
     return self::$instance;
 }
예제 #2
0
 public function setValue($value, $refill = false)
 {
     if ($refill) {
         $vals = http_vars::getInstance()->post($this->name . '_fields');
         $tmpVal = $value;
         $value = array();
         if (is_array($tmpVal)) {
             foreach ($tmpVal as $v) {
                 $curVal = array(db::getCfg('relatedValue') => $v);
                 foreach ($this->cfg->fields as $f) {
                     $curVal[$f['name']] = isset($vals[$v]) && isset($vals[$v][$f['name']]) ? $vals[$v][$f['name']] : null;
                 }
                 $value[] = $curVal;
             }
         }
     }
     parent::setValue($value);
     $this->prepareValuesForValid();
 }
예제 #3
0
 protected function beforeInit()
 {
     $required = array_key_exists('required', $this->cfg->valid) && $this->cfg->getInArray('valid', 'required');
     $htVars = http_vars::getInstance();
     $this->keep = $htVars->getVar($this->name . 'NyroKeep');
     if ($this->keep) {
         $this->cfg->value = $this->keep;
     }
     $prm = array_merge($this->cfg->fileUploadedPrm, array('name' => $this->cfg->name, 'current' => $this->cfg->value, 'helper' => $this->cfg->helper, 'helperPrm' => $this->cfg->helperPrm, 'required' => $required));
     if ($this->cfg->dir) {
         $prm['dir'] = $this->cfg->dir;
     }
     if ($this->cfg->subdir) {
         $prm['subdir'] = $this->cfg->subdir;
     }
     $this->cfg->value = factory::get('form_fileUploaded', $prm);
     if ($this->cfg->autoDeleteOnGet && !$this->cfg->value->isSaved(true) && $htVars->getVar($this->name . 'NyroDel')) {
         $this->cfg->value->delete();
         $this->deleted = true;
     }
     $this->cfg->valid = array_merge($this->cfg->valid, array('callback' => array($this->cfg->value, 'isValid')));
 }
예제 #4
0
	protected function execIndex(array $prm = array()) {
		$this->prepare();
		
		$pattern = FILESROOT.$this->dir.DS.'*';
		$search = http_vars::getInstance()->get('search');
		if ($search) {
			$pattern.= strtolower($search).'*';
			$this->uri.= 'search='.$search.'&';
		}
		
		$delete = http_vars::getInstance()->get('delete');
		if ($delete) {
			$file = FILESROOT.urldecode($delete);
			if (file::exists($file)) {
				file::delete($file);
				file::multipleDelete(substr($file, 0, -strlen(file::getExt($file))-1).'_*');
				response::getInstance()->redirect($this->uri);
			}
		}
		
		$form = $this->getForm();
		
		if (request::isPost()) {
			$form->refill();
			if ($form->isValid())
				response::getInstance()->sendText('ok');
		}
		
		$files = array();
		foreach(file::search($pattern) as $f) {
			if (strpos($f, 'nyroBrowserThumb') === false) {
				$name = basename($f);
				if ($this->type == 'image' && strlen($name) > 15)
					$name = substr($name, 0, 15).'...'.file::getExt($f);
				$files[] = array(
					$f,
					request::uploadedUri(str_replace(FILESROOT, '', $f), $this->myCfg['uploadedUri']),
					$name,
					file::humanSize($f),
					utils::formatDate(filemtime($f)),
					$this->uri.'delete='.urlencode(str_replace(FILESROOT, '', $f)).'&'
				);
			}
		}
		
		$this->setViewVars(array(
			'uri'=>$this->uri,
			'form'=>$form,
			'config'=>$this->config,
			'type'=>$this->type,
			'files'=>$files,
			'searchButton'=>$this->myCfg['search'],
			'search'=>$search,
			'imgHelper'=>$this->myCfg['imgHelper'],
			'filesTitle'=>$this->myCfg['filesTitle'],
			'noFiles'=>$this->myCfg['noFiles'],
			'name'=>$this->myCfg['name'],
			'size'=>$this->myCfg['size'],
			'date'=>$this->myCfg['date'],
			'delete'=>$this->myCfg['delete'],
		));
	}
예제 #5
0
 /**
  * Refill the whole form from the post argument
  */
 public function refill()
 {
     $this->addCaptcha();
     $htVars = http_vars::getInstance();
     foreach ($this->elementsSection as $name => $section) {
         $val = $htVars->getVar(array('name' => str_replace('.', '_', $name), 'method' => $this->cfg->method));
         $this->setValue($name, $val, true);
     }
 }
예제 #6
0
	protected function execScaffoldMultiple() {
		$action = http_vars::getInstance()->post('action');
		if ($action) {
			$fctName = 'multiple'.ucfirst($action);
			$uAction = 'Multiple'.ucfirst($action);
			$this->ids = http_vars::getInstance()->post($this->table->getIdent());
			$this->hook('before'.$uAction);
			$actionConf = $this->cfg->getInArray('multiple', $action);
			$call = null;
			if (is_array($actionConf) && isset($actionConf['callback']) && is_callable($actionConf['callback'])) {
				$call = $actionConf['callback'];
			} else if (is_callable(array($this, $fctName)))
				$call = array($this, $fctName);
			if (!is_null($call))
				call_user_func($call, $this->ids);
			$this->hook('after'.$uAction);
		}
		response::getInstance()->redirect($this->indexPage);
	}