userGen($UserID); if($Profile) { foreach ($Profile as $prKey => $UserProfile) : if($prKey == 'role_id') continue; $UserProf['Profile'][$prKey] = $UserProfile; endforeach; $UserProf['Profile']['Role'] = $this->userRole($Profile['role_id']); } $MetaInfo = \Db::getResult("select * from sp_users_meta where userid='{$UserID}'"); if($MetaInfo) { foreach($MetaInfo as $mKey => $Meta) { $jMetaBody = json_decode($Meta['metval']); foreach($jMetaBody as $MetValKey => $MetVal) : $UserProf['Profile']['Meta'][$Meta['keyval']][$MetValKey] = $MetVal; endforeach; } } $OrgRelation = $this->OrgRelationship($UserID); if($OrgRelation) { foreach($OrgRelation as $OrgRkey => $OrgRel) : // \Debug::print_array($OrgRelation); $UserProf['Profile']['ManageOrgs'][$OrgRkey] = $OrgRel; // $UserProf['Profile']['ManageOrgs'][$OrgRkey]['Role'] = $this->userRole($OrgRel['Role']); endforeach; } $Subscription = $this->Subscription($UserID); if($Subscription){ foreach($Subscription as $SubKey => $SubVal) : $UserProf['Profile']['Subscription'][$SubKey] = $SubVal; endforeach; } return $UserProf; } public function userGen($uid ='') { $Return = \Db::getRow("select * from sp_users where userid='{$uid}'"); return $Return; } public function userInfoMeta($uid ='', $type='') { $Return = \Db::getRow("select * from sp_users_meta where userid='{$uid}' and keyval='{$type}'"); $jBody = $Return['metval']; return $jBody; } public function OrgRelationship($uid='', $OrgAdmin=false){ if($OrgAdmin) { $SQLWhere .= " AND a.orgadmin='1'"; } if($uid) { $SQLWhere .= " AND a.userid='{$uid}'"; } $SQL = "SELECT a.userid AS UserID, b.orgid AS OrgID, b.name AS OrgName, a.orgadmin AS OrgAdmin FROM sp_orgs_users_join a JOIN sp_orgs b ON a.orgid=b.orgid WHERE 1 {$SQLWhere} ORDER BY OrgAdmin DESC"; $Return = \Db::getResult($SQL); return $Return; } public function getRoles(){ $Return = \Db::getResult("select * from sp_roles"); return $Return; } public function userRole($RoleID){ $Return = \Db::getRow("select * from sp_roles where role_id='{$RoleID}'"); return $Return; } public function Subscription($userid=''){ // echo "SELECT * FROM sp_saas_subscription a JOIN sp_saas_plans b ON a.planid=b.planid WHERE a.userid='{$userid}' AND a.active='1'"; $Return = \Db::getRow("SELECT * FROM sp_saas_subscription a JOIN sp_saas_plans b ON a.planid=b.planid WHERE a.userid='{$userid}' AND a.active='1'"); return $Return; } // this gets all the users in the system that's connected to an organization. // TODO: need to put a check in the system to make sure every user is connected to an organization. # This gets all users in the system that's associated to an org. # If SuperAdmin is logged in it'll retrieve ALL users # if OrgAdmin Logged: Retrieve all to organization that OrgAdmin is Admin to. If orgadmin is only a user to an org than it shouldn't show up // Get Users by UserID public function getUsers($uid=''){ $UserOrgs = $this->OrgRelationship($uid, true); $array = array_column($UserOrgs, 'OrgID'); if(empty($array)) die('Something Went Wrong.. You\'re Not Assigned to Any Organizations. Please Contact Your System Administrator. Code: GmF2deT0aQIv'); $sql = "SELECT a.userid FROM sp_users a JOIN sp_roles b ON a.role_id=b.role_id JOIN sp_orgs_users_join c ON c.userid=a.userid INNER JOIN sp_orgs d ON c.orgid=d.orgid WHERE 1 AND c.orgid IN (". implode(',',$array).") GROUP BY a.userid"; $Return = \Db::getResult($sql); foreach($Return as $OrgUserID) { $Profile = $this->Profile($OrgUserID['userid']); $Array[$Profile['Profile']['userid']] = $Profile; } return $Array; } // get Users by OrgID public function getUsersbyOrgID(){ $SQLWhere = ''; if($this->OrgID) { $SQLWhere .= " AND c.orgid ='{$this->OrgID}'"; } if($this->Team === '0' || $this->Team === '1') { $SQLWhere .= " AND b.onteam ='{$this->Team}'"; } $SQL = "SELECT a.userid FROM sp_users a JOIN sp_roles b ON a.role_id=b.role_id JOIN sp_orgs_users_join c ON c.userid=a.userid INNER JOIN sp_orgs d ON c.orgid=d.orgid WHERE 1 {$SQLWhere} GROUP BY a.userid "; // \Debug::print_array($SQL); // die(); $Return = \Db::getResult($SQL); foreach($Return as $OrgUserID) { $Profile = $this->Profile($OrgUserID['userid']); $Array[$Profile['Profile']['userid']] = $Profile; } return $Array; } public function create($data=""){ Return \Db::insert('sp_users', $data); } public function update($data="", $userid=""){ return \Db::update('sp_users', $data, "userid='{$userid}'"); } public function addMeta($data=""){ Return \Db::insert('sp_users_meta', $data); } }