Browse Source

Fixed $db calls

tags/v1.3^2
Teknikode 6 years ago
parent
commit
a2b010a848

+ 2
- 7
includes/classes/Role.class.php View File

@@ -8,14 +8,9 @@ class Role
}
// return a role object with associated permissions
public static function getRolePerms($role_id, $db) {
public static function getRolePerms($role_id, $db)
{
$role = new Role();
$sql = "SELECT t2.perm_desc FROM role_perm as t1
JOIN permissions as t2 ON t1.perm_id = t2.perm_id
WHERE t1.role_id = :role_id";
$sth = $GLOBALS["DB"]->prepare($sql);
$sth->execute(array(":role_id" => $role_id));
$db->select_raw("role_perm as rp JOIN permissions as p ON rp.perm_id = p.perm_id", "WHERE rp.role_id=?", array($role_id), "p.perm_desc");
foreach ($results as $result)
{

+ 3
- 3
includes/classes/User.class.php View File

@@ -20,7 +20,7 @@ class User {
//Constructor is called whenever a new object is created.
//Takes an associative array with the DB row as an argument.
function __construct($data) {
function __construct($data, $db) {
$this->id = (isset($data['id'])) ? $data['id'] : "";
$this->username = (isset($data['username'])) ? $data['username'] : "";
$this->hashedPassword = (isset($data['password'])) ? $data['password'] : "";
@@ -37,11 +37,11 @@ class User {
$this->blog_title = (isset($data['blog_title'])) ? $data['blog_title'] : "";
$this->blog_desc = (isset($data['blog_desc'])) ? $data['blog_desc'] : "";
$this->roles = array();
$results = $this->db->select("user_role as ur JOIN roles as r ON ur.role_id = r.role_id", "WHERE ur.user_id=?", array($this->id), "ur.role_id, r.role_name");
$results = $db->select("user_role as ur JOIN roles as r ON ur.role_id = r.role_id", "WHERE ur.user_id=?", array($this->id), "ur.role_id, r.role_name");
$users = array();
foreach ($results as $result)
{
$this->roles[$result["role_name"]] = Role::getRolePerms($result["role_id"], $this->db);
$this->roles[$result["role_name"]] = Role::getRolePerms($result["role_id"], $db);
}
}

+ 7
- 7
includes/classes/UserTools.class.php View File

@@ -18,7 +18,7 @@ class UserTools {
$result = $this->db->select("users", "username=? AND password=?", array($username, $password));
if($result)
{
$user = new User($result);
$user = new User($result, $this->db);
$_SESSION[$CONF['session_prefix']."user"] = serialize($user);
$_SESSION[$CONF['session_prefix']."logged_in"] = 1;
if ($remember_me)
@@ -97,7 +97,7 @@ class UserTools {
public function getUser($username)
{
$result = $this->db->select('users', "username=?", array($username));
return new User($result);
return new User($result, $this->db);
}
//Grab all of the users from a select group
@@ -109,9 +109,9 @@ class UserTools {
{
if (!is_array($result))
{
return array(new User($results));
return array(new User($results, $this->db));
}
$users[] = new User($result);
$users[] = new User($result, $this->db);
}
return $users;
}
@@ -125,9 +125,9 @@ class UserTools {
{
if (!is_array($result))
{
return array(new User($results));
return array(new User($results, $this->db));
}
array_push($users, new User($result));
array_push($users, new User($result, $this->db));
}
return $users;
}
@@ -137,7 +137,7 @@ class UserTools {
public function get($id)
{
$result = $this->db->select('users', "id=?", array($id));
return new User($result);
return new UserUser($result, $this->db);
}
// check if user has a specific privilege

Loading…
Cancel
Save