menu authorities
This commit is contained in:
@@ -19,6 +19,7 @@ class user {
|
||||
private $user_admin;
|
||||
private $logged_in;
|
||||
private $user_type;
|
||||
private $authorities = array();
|
||||
private $user_deleted;
|
||||
|
||||
public function set_ua_id($_uid) {
|
||||
@@ -92,6 +93,16 @@ class user {
|
||||
$this->logged_in = $_login;
|
||||
}
|
||||
|
||||
public function add_ua_authority($_a_id) {
|
||||
$this->authorities[] = $_a_id;
|
||||
}
|
||||
|
||||
public function remove_ua_authority($_a_id) {
|
||||
if (($key = array_search($del_val, $messages)) !== false) {
|
||||
unset($messages[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
public function set_user_data_by_id($_ua_id) {
|
||||
global $sql, $user;
|
||||
$user_data_assoc_array = $sql->assoc_array("select * from user_coach where ua_id = " . $_ua_id);
|
||||
@@ -103,6 +114,11 @@ class user {
|
||||
$this->set_login(true);
|
||||
}
|
||||
|
||||
$authorities_aa = $sql->assoc_array('SELECT * FROM user_authority WHERE ua_user_kid_uk_id = ' . $_ua_id);
|
||||
|
||||
foreach($authorities_aa as $key => $authority) {
|
||||
$this->add_ua_authority($authority['ua_authority_a_id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,40 +151,77 @@ class user {
|
||||
return $sql->single_variable('select count(distinct trc_id) from training_coach join training on tr_id = trc_training_tr_id where year(tr_date) = '.$_year.' and month(tr_date) = '.$_month.' and trc_coach_uc_id = '.$this->get_ua_id().' and tr_deleted = 0;');
|
||||
}
|
||||
|
||||
public static function create_user($_name, $_password) {
|
||||
public function has_authority($a_id) {
|
||||
global $sql;
|
||||
return $sql->insert_into('user_coach', array(
|
||||
return $sql->num_of_rows('SELECT * FROM user_authority WHERE ua_user_kid_uk_id = ' . $this->get_ua_id() . ' AND ua_authority_a_id = ' . $a_id. ';');
|
||||
}
|
||||
|
||||
public function has_authority_by_name($a_name) {
|
||||
global $sql;
|
||||
return $sql->num_of_rows("SELECT * FROM user_authority JOIN authority ON a_id = ua_authority_a_id WHERE ua_user_kid_uk_id = " . $this->get_ua_id() . " AND (a_name = '" . $a_name. "' OR a_name = 'admin');");
|
||||
}
|
||||
|
||||
public function get_authorities() {
|
||||
return $this->authorities;
|
||||
}
|
||||
|
||||
public static function create_user($_name, $_password, $_authorities = array()) {
|
||||
global $sql;
|
||||
$new_user_id = $sql->insert_into('user_coach', array(
|
||||
'ua_name' => $_name,
|
||||
'ua_password' => $_password
|
||||
)
|
||||
);
|
||||
|
||||
if (is_array($_authorities) && !empty($_authorities)) {
|
||||
foreach ($_authorities as $key => $authority_id) {
|
||||
$sql->insert_into('user_authority', array(
|
||||
'ua_user_kid_uk_id' => $new_user_id,
|
||||
'ua_authority_a_id' => $authority_id,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return $new_user_id;
|
||||
}
|
||||
|
||||
public static function update_user($_name, $_password, $_admin, $_ua_id) {
|
||||
public static function update_user($_name, $_password, $_admin, $_ua_id, $_authorities = array()) {
|
||||
global $sql;
|
||||
if ($_password != "-1") {
|
||||
return $sql->update_table('user_coach',
|
||||
$sql->update_table('user_coach',
|
||||
array(
|
||||
'ua_name' => $_name,
|
||||
'ua_admin' => ($_admin?1:0),
|
||||
'ua_password' => $_password
|
||||
'ua_name' => $_name,
|
||||
'ua_admin' => ($_admin?1:0),
|
||||
'ua_password' => $_password
|
||||
),
|
||||
array(
|
||||
'ua_id' => $_ua_id
|
||||
'ua_id' => $_ua_id
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
return $sql->update_table('user_coach',
|
||||
$sql->update_table('user_coach',
|
||||
array(
|
||||
'ua_name' => $_name,
|
||||
'ua_admin' => ($_admin?1:0),
|
||||
'ua_name' => $_name,
|
||||
'ua_admin' => ($_admin?1:0),
|
||||
),
|
||||
array(
|
||||
'ua_id' => $_ua_id
|
||||
'ua_id' => $_ua_id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$sql->execute_query('DELETE FROM user_authority WHERE ua_user_kid_uk_id = ' . $_ua_id);
|
||||
if (is_array($_authorities) && !empty($_authorities)) {
|
||||
foreach ($_authorities as $key => $authority_id) {
|
||||
$sql->insert_into('user_authority', array(
|
||||
'ua_user_kid_uk_id' => $_ua_id,
|
||||
'ua_authority_a_id' => $authority_id,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user