Esempio n. 1
0
 public static function attempt($array, $remember = false)
 {
     //Table::show(self::$hashedFields);
     //
     $hashed = array();
     //
     foreach ($array as $key => $value) {
         if (Table::contains(self::$hashedFields, $key)) {
             Table::add($hashed, Hash::make($array[$key]), $key);
         }
     }
     //
     //Table::show($hashed);
     //
     $where = "";
     $ok = false;
     //
     $i = 0;
     foreach ($array as $key => $value) {
         if ($i > 0) {
             $where .= " and ";
         }
         if (Table::contains(self::$hashedFields, $key)) {
             $where .= "{$key}='" . $hashed[$key] . "' ";
         } else {
             $where .= "{$key}='{$value}' ";
         }
         $i++;
     }
     $sql = "select * from " . self::$table . " where " . $where;
     //echo $sql;
     //
     if (Database::countS($sql) > 0) {
         //returning true value
         $ok = true;
         //
         // session
         $user = Database::read($sql);
         $saved = Config::get('auth.saved_fields');
         //
         $static = array();
         //
         foreach ($user[0] as $key => $value) {
             if (array_key_exists($key, $saved)) {
                 $static[$key] = $value;
             }
         }
         //
         Session::put('auths', $static);
         //
         // remember cookie
         if ($remember) {
             Cookie::create(Config::get('auth.rememeber_cookie'), $user[0]["rememberToken"], time() + 3600 * 24 * 7);
         }
     }
     //
     return $ok;
 }
Esempio n. 2
0
 public function getAll()
 {
     return Database::read('select * from ' . $this->DatabaseTableName());
 }
Esempio n. 3
0
 /**
  * To count rows by where clause
  *
  * @param $where (string) : the where clause
  **/
 public static function count($where)
 {
     $self = self::instance();
     $rows = new ModelArray();
     //
     $sql = "select count(*) as cnt from " . $self->DBtable . " where {$where} ";
     $data = Database::read($sql, 1);
     //
     return $data[0]['cnt'];
 }
Esempio n. 4
0
 public function paginate($RowsPerPage)
 {
     // count data
     $sql = "select count(*) as nbRows from " . $this->name;
     $var = Database::read($sql);
     $this->RowsPerPage = $RowsPerPage;
     $this->nbRows = $var[0]['nbRows'];
     $this->nbPages = ceil($this->nbRows / $RowsPerPage);
     //if isset get
     $this->CurrentPage = 1;
     if (isset($_GET[Config::get('view.pagination_param')]) && !empty($_GET[Config::get('view.pagination_param')])) {
         if ($_GET[Config::get('view.pagination_param')] > 0 && $_GET[Config::get('view.pagination_param')] <= $this->nbPages) {
             $this->CurrentPage = Res::get(Config::get('view.pagination_param'));
         }
     }
     //get Data
     $r = array();
     $sql = "select * from " . $this->name . " Limit " . ($this->CurrentPage - 1) * $this->RowsPerPage . ",{$this->RowsPerPage}";
     $this->data = Database::read($sql);
     //
     return $this;
 }