172 lines
4.8 KiB
PHP
172 lines
4.8 KiB
PHP
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Description of Users_model
|
|
*
|
|
* @author Theo Weijmer
|
|
* @date april 26, 2013 9:56 AM
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
class Users_model extends MY_Model{
|
|
|
|
|
|
protected $tablename = 'tb_users';
|
|
|
|
|
|
function __construct(){
|
|
parent::__construct();
|
|
$models = array('shared/Orgusers_model');
|
|
$this->load->model($models);
|
|
}
|
|
|
|
function get_details($where=FALSE){
|
|
$records = $this->get_records_where($where);
|
|
|
|
if($records){
|
|
$details = $this->get_records_details($records);
|
|
}else{
|
|
$details = FALSE;
|
|
}
|
|
|
|
return $details;
|
|
}
|
|
|
|
function get_records_details($records ){
|
|
if($records){
|
|
|
|
foreach($records as $record){
|
|
$details[] = $this->get_record_details($record);
|
|
}
|
|
}
|
|
|
|
if(!isset($details)) $details = FALSE;
|
|
|
|
return $details;
|
|
}
|
|
|
|
function get_record_details($record){
|
|
$details = new stdClass;
|
|
|
|
$details->id = $record->id;
|
|
$details->username = $record->user_name;
|
|
$details->fullname = $this->get_fullname($record->id);
|
|
$details->orgusers = $this->Orgusers_model->get_details(array('orguser_user_id'=>$record->id), TRUE);
|
|
|
|
return $details;
|
|
}
|
|
|
|
function get_user_detail_by_id($userid){
|
|
$user = $this->get_record_by_id($userid);
|
|
|
|
if($user){
|
|
$details = $this->get_record_details($user);
|
|
}else{
|
|
$details = FALSE;
|
|
}
|
|
|
|
return $details;
|
|
}
|
|
|
|
function get_users_by_organisatie($organisatieid){
|
|
$this->db->join('tb_orgusers', 'tb_users.id = orguser_user_id');
|
|
$this->db->order_by('user_lastname', 'user_firstname');
|
|
$this->db->select('tb_users.*');
|
|
|
|
$where = array('orguser_organisatie_id'=>$organisatieid);
|
|
$records= $this->get_query($where);
|
|
|
|
if($records){
|
|
$details= $this->get_records_details($records);
|
|
}else{
|
|
$details = FALSE;
|
|
}
|
|
|
|
return $details;
|
|
}
|
|
function get_users_by_bg($bgID){
|
|
$this->sql="SELECT u.*
|
|
FROM tb_users u, tb_orgusers ou, tb_organisaties o
|
|
WHERE o.id = o.organisatie_id
|
|
AND ou.orguser_organisatie_id = o.id
|
|
AND u.id= ou.orguser_user_id";
|
|
$records = $this->get_query_result();
|
|
if($records){
|
|
$details = $this ->get_records_details($records);
|
|
}else{
|
|
$details = FALSE;
|
|
}
|
|
return $details;
|
|
}
|
|
function get_user_by_name($username){
|
|
$where = array('UCASE(user_name)' => strtoupper($username));
|
|
$user = $this->get_records_where($where, TRUE);
|
|
|
|
return $user;
|
|
}
|
|
|
|
function get_fullname($userid){
|
|
$user = $this->get_record_by_id($userid);
|
|
|
|
$fullname = $user->user_firstname;
|
|
if(strlen($user->user_midlename)!=0) $fullname.=" ".$user->user_midlename;
|
|
$fullname.= " ".$user->user_lastname;
|
|
|
|
return $fullname;
|
|
}
|
|
|
|
function getgebruikers($orgid){
|
|
$this->sql = "SELECT O.id, user_name,user_firstname AS voornaam,
|
|
user_midlename AS tussenvoegsel,
|
|
user_lastname AS achternaam,
|
|
user_email AS email,
|
|
A.level AS level,
|
|
AT.autorisatietype_naam as autorisatie
|
|
FROM tb_users O
|
|
JOIN tb_orgusers OU ON OU.orguser_user_id = O.id
|
|
left JOIN tb_autorisaties A ON A.orguser_id = OU.id
|
|
left JOIN tb_autorisatietypes AT on AT.autorisatietype_level = A.level
|
|
WHERE OU.orguser_organisatie_id = {$orgid}
|
|
AND actief = 1
|
|
ORDER BY user_lastname";
|
|
return $this->get_query_result();
|
|
}
|
|
function getgebruiker($userid){
|
|
$this->sql = "SELECT O.id, user_name,user_firstname AS voornaam,
|
|
user_midlename AS tussenvoegsel,
|
|
user_lastname AS achternaam,
|
|
user_email AS email,
|
|
A.level AS level,
|
|
AT.autorisatietype_naam as autorisatie
|
|
FROM tb_users O
|
|
JOIN tb_orgusers OU ON OU.orguser_user_id = O.id
|
|
left JOIN tb_autorisaties A ON A.orguser_id = OU.id
|
|
left JOIN tb_autorisatietypes AT on AT.autorisatietype_level = A.level
|
|
WHERE O.id = {$userid}";
|
|
return $this->get_query_row();
|
|
}
|
|
function checkusername ($userid, $gnaam){
|
|
$testuser = $this->Users_model->get_records_where(array("user_name" =>$gnaam), TRUE);
|
|
if ($userid == null && $testuser) { return false; }
|
|
elseif ($testuser && $testuser->id != $userid) { return false;}
|
|
else {return true;};
|
|
}
|
|
function getotherusers($orgid, $orglist, $role,$zoekstring){
|
|
$this->sql = "SELECT U.id, concat_ws(' ', user_firstname, user_midlename, user_lastname, concat('-', ORG.organisatie_naamkort)) AS naam FROM tb_users U
|
|
left JOIN tb_orgusers OU ON OU.orguser_user_id = U.id
|
|
AND (OU.orguser_organisatie_id IN (5, 4, 3, 2, 11) or ($role=1 OR $role =2))
|
|
AND OU.orguser_organisatie_id <> {$orgid}
|
|
left JOIN tb_organisaties ORG on ORG.id = OU.orguser_organisatie_id ";
|
|
|
|
if ($zoekstring){
|
|
$this->sql .=" WHERE UPPER(user_firstname) LIKE '%{$zoekstring}%' OR
|
|
UPPER(user_lastname) LIKE '%{$zoekstring}%' ";
|
|
}
|
|
$this->sql .= " ORDER BY user_lastname
|
|
LIMIT 200";
|
|
return $this->get_query_result();
|
|
}
|
|
} |