File: /home/halcosmu/public_html/nationalcashfunding.com/includes/user.php
<?php
class User
{
public $id;
public $username;
public $firstname;
public $last_name;
public $type;
public static function find_all_users()
{
global $database;
return self::find_this_query("select * from users");
}
public static function find_user_by_id($user_id)
{
global $database;
$the_result_array=self::find_this_query("select * from users where id=$user_id LIMIT 1");
return !empty($the_result_array)? array_shift($the_result_array) : false;
}
public static function find_this_query($sql)
{
global $database;
$result_set=$database->query($sql);
$the_object_array= array();
while($row=mysqli_fetch_array($result_set))
{
$the_object_array[]= self::instatiation($row);
}
return $the_object_array;
}
public static function verify_user($username,$password)
{
global $database;
$username=$database->escape_string($username);
$password=$database->escape_string($password);
$password=md5($password);
$sql=" select * from users where ";
$sql.=" username = '{$username}' ";
$sql.=" and password = '{$password}' ";
$sql.=" LIMIT 1 ";
$the_result_array=self::find_this_query($sql);
return !empty($the_result_array)? array_shift($the_result_array) : false;
}
private function has_the_attribute($the_attribute)
{
$object_properties= get_object_vars($this);
return array_key_exists($the_attribute,$object_properties);
}
public static function instatiation($the_record)
{
$the_object = new self;
/*$the_object ->id= $found_user['id'];
$the_object ->username= $found_user['username'];
$the_object ->first_name= $found_user['first_name'];
$the_object ->last_name= $found_user['last_name'];
return $the_object;*/
foreach($the_record as $the_attribute=>$value)
{
if($the_object->has_the_attribute($the_attribute))
{
$the_object->$the_attribute=$value;
}
}
return $the_object;
}
}
?>