Exemple #1
0
	public function logout($prm = null) {
		if ($this->isLogged()) {
			$this->session->del('cryptic');
			$this->logged = false;
			// Clear the cookie
			$cook = factory::get('http_cookie', $this->cfg->cookie);
			$cook->del();
		}
		$this->hook('logout');
		return $this->logged == false;
	}
Exemple #2
0
	/**
	 * Set a Flash var
	 *
	 * @param array|string $name Array to set multiple vars or string for the Flash var name
	 * @param mixed $val The value if set a single var
	 */
	public static function setFlash($name, $val=null) {
		self::initFlash();
		if (is_array($name)) {
			foreach($name as $k=>$v)
				self::setFlash($k, $v);
		} else {
			self::$flash->set(array(
				'name'=>$name,
				'val'=>$val
			));
		}
	}
 /**
  * Get the where clause
  *
  * @return db_where The where clause
  */
 public function getWhere()
 {
     $where = $this->table->getWhere();
     foreach ($this->form->getValues() as $name => $val) {
         $field = strpos($name, '.') === false ? $this->table->getName() . '.' . $name : $name;
         if (!is_null($val) && ($val || $val === '0')) {
             if (is_array($val)) {
                 if (array_key_exists('min', $val) || array_key_exists('max', $val)) {
                     $min = array_key_exists('min', $val) && !empty($val['min']) ? $val['min'] : null;
                     $max = array_key_exists('max', $val) && !empty($val['max']) ? $val['max'] : null;
                     if ($min) {
                         $where->add(array('field' => $field, 'val' => $min, 'op' => '>='));
                     }
                     if ($max) {
                         $where->add(array('field' => $field, 'val' => $max, 'op' => '<='));
                     }
                 } else {
                     $fieldRel = $this->table->getRelated($name);
                     $where->add(array('field' => $fieldRel ? $fieldRel['tableLink'] . '.' . $fieldRel['fk2']['name'] : $field, 'val' => array_map(array($this->table->getDb(), 'quoteValue'), $val), 'op' => 'IN'));
                 }
             } else {
                 if (strpos($name, '_file')) {
                     $where->add(array('field' => $field, 'val' => '', 'op' => '<>'));
                 } else {
                     $f = $this->table->getField($name);
                     if (is_array($f) && (!array_key_exists('text', $f) || $f['text'])) {
                         $tmp = explode(' ', $val);
                         array_walk($tmp, create_function('&$v', '$v = trim($v);'));
                         $tmp = array_filter($tmp);
                         foreach ($tmp as $t) {
                             $where->add(array('field' => $field, 'val' => '%' . $t . '%', 'op' => 'LIKE'));
                         }
                     } else {
                         if ($this->table->hasI18n() && db::isI18nName($name) && ($f = $this->table->getI18nTable()->getField(db::unI18nName($name)))) {
                             $tblName = $this->table->getI18nTable()->getName();
                             $prim = $this->table->getI18nTable()->getPrimary();
                             $field = $tblName . '.' . db::unI18nName($name);
                             $clause = '(' . $this->table->getName() . '.' . $this->table->getIdent() . ' IN (SELECT ' . $tblName . '.' . $prim[0] . ' FROM ' . $tblName . ' WHERE ';
                             $tmpWhere = $this->table->getI18nTable()->getWhere(array('op' => 'OR'));
                             if (!array_key_exists('text', $f) || $f['text']) {
                                 $tmp = explode(' ', $val);
                                 array_walk($tmp, create_function('&$v', '$v = trim($v);'));
                                 $tmp = array_filter($tmp);
                                 foreach ($tmp as $t) {
                                     $tmpWhere->add(array('field' => $field, 'val' => '%' . $t . '%', 'op' => 'LIKE'));
                                 }
                             } else {
                                 $tmpWhere->add(array('field' => $field, 'val' => $val));
                             }
                             $clause .= $tmpWhere . '))';
                             $where->add($clause);
                         } else {
                             $where->add(array('field' => $field, 'val' => $val));
                         }
                     }
                 }
             }
             $this->session->set(array('name' => $name, 'val' => $val));
         }
     }
     if (count($where)) {
         return $where;
     }
     return null;
 }
Exemple #4
0
 protected function afterInit()
 {
     $this->table = $this->cfg->table;
     if (!is_array($this->cfg->query)) {
         $this->cfg->query = array();
     }
     if (empty($this->cfg->module)) {
         $this->cfg->module = utils::getModuleName(debug::callFrom(6, null));
     }
     if ($this->cfg->useSession) {
         $this->session = session::getInstance(array('nameSpace' => 'dataTable_' . ($this->cfg->sessionName ? $this->cfg->sessionName : $this->cfg->name)));
     }
     $paramFromRequest = array('page', 'sortBy', 'sortDir');
     $paramA = request::get('paramA');
     foreach ($paramFromRequest as $pfr) {
         if ($this->cfg->useSession && $this->session->check($pfr)) {
             $this->cfg->set($pfr, $this->session->get($pfr));
         }
         if (array_key_exists($pfr . $this->cfg->nameParam, $paramA)) {
             $val = $paramA[$pfr . $this->cfg->nameParam];
             if ($this->cfg->useSession) {
                 $this->session->set(array('name' => $pfr, 'val' => $val));
             }
             $this->cfg->set($pfr, $val);
         }
     }
     if ($this->cfg->check('sortBy')) {
         if ($this->table->isRelated($this->cfg->sortBy)) {
             $related = $this->table->getRelated($this->cfg->sortBy);
             $tmp = array();
             $fields = array_filter(explode(',', $related['fk2']['link']['fields']));
             $tableName = $related['fk2']['link']['table'];
             foreach ($fields as $f) {
                 $tmp[] = $tableName . '.' . $f;
             }
             $fields = array_filter(explode(',', $related['fk2']['link']['i18nFields']));
             $tableName .= db::getCfg('i18n');
             foreach ($fields as $f) {
                 $tmp[] = $tableName . '.' . $f;
             }
             $this->sortBy = implode(', ', $tmp);
             if (!$this->table->getCfg()->autoJoin) {
                 $f = $related['tableObj']->getRawName();
                 $query = $this->cfg->query;
                 if (!isset($query['join'])) {
                     $query['join'] = array();
                 }
                 $query['join'][] = array('table' => $f, 'dir' => 'left outer', 'on' => $this->table->getRawName() . '.' . $related['fk1']['link']['ident'] . '=' . $f . '.' . $related['fk1']['name']);
                 $query['join'][] = array('table' => $related['table'], 'dir' => 'left outer', 'on' => $f . '.' . $related['fk2']['name'] . '=' . $related['table'] . '.' . $related['fk2']['link']['ident']);
                 if ($related['fk2']['link']['i18nFields']) {
                     $i18nTableName = $related['table'] . db::getCfg('i18n');
                     $i18nTable = db::get('table', $i18nTableName, array('db' => $this->table->getDb()));
                     $primary = $i18nTable->getPrimary();
                     $query['join'][] = array('table' => $i18nTableName, 'dir' => 'left outer', 'on' => $f . '.' . $related['fk2']['name'] . '=' . $i18nTableName . '.' . $primary[0] . ' AND ' . $i18nTableName . '.' . $primary[1] . '="' . request::get('lang') . '"');
                 }
                 $query['group'] = $this->table->getRawName() . '.' . $this->table->getIdent();
                 $this->cfg->query = $query;
             }
         } else {
             if ($this->table->isLinked($this->cfg->sortBy)) {
                 $linked = $this->table->getLinked($this->cfg->sortBy);
                 $tmpSort = array();
                 foreach (explode(',', trim($linked['fields'] . ',' . $linked['i18nFields'], ',')) as $tmp) {
                     $tmpSort[] = $linked['field'] . '.' . $tmp;
                 }
                 $this->sortBy = implode(', ', $tmpSort);
                 if (!$this->table->getCfg()->autoJoin) {
                     $query = $this->cfg->query;
                     if (!isset($query['join'])) {
                         $query['join'] = array();
                     }
                     $alias = $linked['field'];
                     if ($linked['i18nFields']) {
                         $alias1 = $alias . '1';
                         $query['join'][] = array('table' => $linked['table'], 'alias' => $alias1, 'dir' => 'left outer', 'on' => $this->table->getRawName() . '.' . $linked['field'] . '=' . $alias1 . '.' . $linked['ident']);
                         $i18nTableName = $linked['table'] . db::getCfg('i18n');
                         $i18nTable = db::get('table', $i18nTableName, array('db' => $this->table->getDb()));
                         $primary = $i18nTable->getPrimary();
                         $query['join'][] = array('table' => $i18nTableName, 'alias' => $alias, 'dir' => 'left outer', 'on' => $alias1 . '.' . $linked['ident'] . '=' . $alias . '.' . $primary[0] . ' AND ' . $alias . '.' . $primary[1] . '="' . request::get('lang') . '"');
                     } else {
                         $query['join'][] = array('table' => $linked['table'], 'alias' => $alias, 'dir' => 'left outer', 'on' => $this->table->getRawName() . '.' . $linked['field'] . '=' . $alias . '.' . $linked['ident']);
                     }
                     $this->cfg->query = $query;
                 }
             } else {
                 if ($this->cfg->sortBy) {
                     if (strpos($this->cfg->sortBy, $this->table->getName()) !== false || strpos($this->cfg->sortBy, ".") !== false) {
                         $this->sortBy = $this->cfg->sortBy;
                     } else {
                         $this->sortBy = $this->table->getName() . '.' . $this->cfg->sortBy;
                     }
                 }
             }
         }
     }
 }