Beispiel #1
0
	protected function addEditForm($action, $id = null) {
		$uAction = ucfirst($action);
		$this->row = $id ? $this->table->find($id) : $this->table->getRow();
		if (!$this->row)
			response::getInstance()->redirect($this->indexPage);
		
		if ($action == 'duplic') {
			$tmp = $this->row;
			$this->row = $this->table->getRow();
			$this->row->setValues($tmp->getValues());
			$this->row->setValues($tmp->getValues('flat'));
			$action = 'add';
		}	
		
		$this->hook($action);

		$this->form = $this->row->getForm($this->getFields($action), array_merge(array('sectionName'=>tr::__('scaffold_'.$action)), $this->cfg->formOpts));
		$this->hook('formInit');
		$this->hook('formInit'.$uAction);

		if (request::isPost()) {
			$this->form->refill();
			$this->hook('formPost'.$uAction);
			if ($this->form->isValid()) {
				$this->row->setValues($this->form->getValues());
				$this->hook('before'.$uAction);
				if ($this->row->save()) {
					$this->hook('after'.$uAction);
					response::getInstance()->redirect($this->indexPage);
				}
			} else
				$this->setViewVar('errors', $this->form->getErrors());
		}

		$this->form->setSubmitText(tr::__('scaffold_'.$action));
		$this->form->setSubmitplus('<a href="'.$this->indexPage.'">'.tr::__('scaffold_back').'</a>');

		$this->hook('form'.$uAction);

		$this->setViewVars(array(
			'row'=>$this->row,
			'form'=>$this->form
		));
	}
Beispiel #2
0
	public function getLoginForm(array $prm = array()) {
		if (!$this->form) {
			$this->form = $this->table->getRow()->getForm(array(
				$this->cfg->getInArray('fields', 'login'),
				$this->cfg->getInArray('fields', 'pass')
			), array_merge($this->cfg->formOptions, $prm, array(
				'action'=>request::uri($this->getPage('login'))
			)), false);
			$this->form->get($this->cfg->getInArray('fields', 'login'))->getValid()->delRule('dbUnique');
			if ($this->cfg->stayConnected) {
				$this->form->add('checkbox', array(
					'name'=>'stayConnected',
					'label'=>false,
					'uniqValue'=>true,
					'valid'=>array('required'=>false),
					'list'=>array(
						1=>utils::htmlOut($this->cfg->labelStayConnected)
					)
				));
			}
		}

		return $this->form;
	}