Location: PHPKode > projects > Opensheet > opensheet/classes/users.class.php
<?php 
#include ('../functions/base.functions.php');
#include ('drawPage.class.php');
#include ('../functions/base.functions.php');
#ini_set('display_errors',1);
#error_reporting(E_ALL);
#echo HI;

class users  extends Base{
  	private $login;
  	private $passwd;
	protected  $id;
	
	
	public $uTypes = array('user','admin','pm','dm','fd');

		   		
		   		
	function set_login($login){
		$this->login = $login;
	return $this;		
	}
	
	
	
	
			function set_id($id){
				$this->id = $id;
			return $this;		
			}
 		
		   		
	 		
		   		

		public function __destruct(){
		unset($this->queue);
	}
	

	
    public function getValue($queue){
    	return parent::dbQuery($queue);
	}
	
	
						
					#ready
				function getPermission(){
				    $query = "SELECT admin,pm,dm,fd,user FROM permissions WHERE `user_id` = '$this->id'";
					return parent::dbQueryAssoc($query);
			        } 
				
			    function setPermission($array){
			    #	db_connect();
			    	foreach($array as $uid=>$value){
				    	$query = "INSERT INTO `timesheet`.`permissions` (`user_id`, `admin`, `pm`, `dm`,`fd`, `user`) VALUES ('$uid', '$value[admin]', '$value[pm]', '$value[dm]', '$value[fd]','$value[user]') ON DUPLICATE  KEY UPDATE admin = '$value[admin]',pm = '$value[pm]',dm ='$value[dm]',fd='$value[fd]',user='$value[user]'";
							
				    #	$result = mysql_query($query) or die("Invalid query: " . mysql_error());
				    					    	parent::dbQuery($query);
			    	#				  return $query;
			    		}
			    	}     
			        
			        
				function getUidPerm($uid){
				    $query = "SELECT admin,pm,dm,fd,user FROM permissions WHERE `user_id` = '$uid'";
					return parent::dbQueryAssoc($query);
			        }   
			        
			        #ready
				function getRealName($id){
				    $query = "SELECT real_name FROM users WHERE `id` = '$id'";
					return parent::dbQueryRow($query);
					#return $query;
			        }
			        
			        #ready
			    function getUserVars(){
			        $query = "SELECT user_name,real_name,id,status,start,`group_id`,email FROM `users` WHERE `id` = '$this->id'";
				    return parent::dbQueryAssoc($query);
				   # return $query;
			        }
				
			        
			        #ready
			     function getUsersbyType($type){
					
			     	$query = "SELECT real_name,user_name,id,status,start,`group_id`,email FROM `users` WHERE id=ANY(SELECT user_id from permissions where $type ='1')";
			     	
			     	#$list = parent::dbQuery($query);
					foreach(parent::dbQuery($query) as $num=>$key) {
					$answer[$key['id']] = array('real_name'=>$key['real_name'],'id'=>$key['id'],'user_name'=>$key['user_name'],'group_id'=>$key['group_id'],'status'=>$key['status'],'email'=>$key['email'],'start'=>$key['start']);	
						 	}
				   	asort($answer);
				   	return $answer;
				    
			        }
				   
			        #ready
				  	function getUsersArray($status){
				  	if ($status == "active"){	
			    	$query = "SELECT id,user_name,real_name,status,start,`group_id`,email,passwd,ldap FROM `users` WHERE `status` = 'Y' ORDER BY `real_name`  DESC ";
				  	}elseif($status == "nope"){
			    	$query = "SELECT id,user_name,real_name,status,start,`group_id`,email,passwd,ldap FROM `users` WHERE `status` = 'N' ORDER BY `real_name`  DESC ";
				  	} else {
				  	$query = "SELECT id,user_name,real_name,status,start,`group_id`,email,passwd,ldap FROM `users` ORDER BY `real_name`  DESC ";
				  					  	}
			    	foreach(parent::dbQuery($query) as $num=>$key) {
					$answer[$key['id']] = array('real_name'=>$key['real_name'],'user_name'=>$key['user_name'],'group'=>$key['group_id'],'status'=>$key['status'],'email'=>$key['email'],'start'=>$key['start'],'ldap'=>$key['ldap']);	
						 	}
				   	asort($answer);
				    return $answer;
    }         
			        
			        
	    
			        
			        
 			public function getTypes() {
 				
                return $this->uTypes;
        }
        			
        
   

					 #?
				    function setUserValue($user_index,$value_name,$value){
			    	db_connect();
			    	$query = "UPDATE  `timesheet`.`users` SET  `$value_name` = '".$value."' WHERE `users`.`id` = '".$user_index."'";	
			    	$result = mysql_query($query) or die("Invalid query: " . mysql_error());
					 }   
		        
					function updateUser($user_index,$login,$real_name,$group,$status,$email,$ldap,$password){
			    	   	$query = "UPDATE `timesheet`.`users` SET `ldap` = '$ldap',`user_name` = '$login',`real_name`='$real_name',`group_id`='$group',`status`='$status',`email`='$email',`crypt`=MD5('$password'),`passwd`='$password'  WHERE `users`.`id` =$user_index";	
						parent::dbQuery($query);
					}   
					 
					function addUser($login,$real_name,$group,$status,$email,$ldap,$password,$created){
			    	   	$query = "INSERT INTO `timesheet`.`users` (`id`, `group_id`, `user_name`, `crypt`, `passwd`, `status`, `email`,`start`, `end`, `real_name`, `ldap`) VALUES (NULL, '$group', '$login',MD5('$password'), '$password','$status', '$email','$created', '', '$real_name', '$ldap');";	
						parent::dbQuery($query);
					}  
					 
					 
					 #ready
			 function getUserGroup($user_index){
        			#$query="SELECT `group_name` FROM `groups` where `group_index`=ANY(SELECT `group` FROM `users` where `user_id` = '$user_index')";
			        $query="SELECT `group_name` FROM `groups` where `id`=(SELECT `group_id` FROM `users` where `id` = '$user_index')";
        			
        			 return parent::dbQueryRow($query); 
			        #return $query;
			         
			 }
			 
			 #ready
			function getIDfromLogin(){
        			$query="SELECT `id` FROM `users` where `user_name`= '$this->login'";
			         return parent::dbQueryRow($query); 
			        #return $query;
			         
			 }
			 
			function loginToUid($login){
        			$query="SELECT `id` FROM `users` where `user_name`= '$login'";
			         return parent::dbQueryRow($query); 
			        #return $query;
			         
			 }
			 
			 
			 #ready
			 function check_user($login,$passwd){
				 $passwd = mysql_real_escape_string($passwd);
			   	$query="SELECT `ldap` FROM `users` WHERE `user_name`='$login' AND `status` = 'Y'";
			  #	$echo =  $this->dbQueryRow($query);
			  	if ($this->dbQueryRow($query) == 'Y') {
			 	 		if (ad_auth($login,$passwd)!= '1'){
			 			return FALSE;
			 		}else{
			 			return TRUE;
			 		} 
			 	 	}else {
			 		$query = " SELECT `user_name` FROM  `users` WHERE  `user_name` = '$login' AND `passwd` = '$passwd' AND  `status` = 'Y' ";
			 		if ($this->dbQueryRow($query) == $login) {	
			 		return TRUE;
			 		}else{
			 		return FALSE;	
			 		}
			 		
			 	}
			 	
			 }
			 
			function getProjectUsers($pid){
        			$query="select u.real_name,p.user_id from users_projects as p,users as u where p.user_id=u.id and p.project_id='$pid' and p.status = 'Y'";
			         return parent::dbQuery($query); 
			             
			 }
			 
			function updateProjectStatus($uid,$pid,$status){
        			#$query="UPDATE `timesheet`.`users_projects` SET `status` = '$status' WHERE `users_projects`.`user_id` =$uid AND `users_projects`.`project_id`=$pid ";
			        $query="INSERT INTO  `timesheet`.`users_projects` (`user_id` ,`project_id` ,`status`) VALUES ('$uid','$pid', '$status') ON DUPLICATE  KEY UPDATE `status` = '$status'";
        			parent::dbQuery($query); 
			       #return $query;      
			 } 
			 
			function updateTaskStatus($uid,$tid,$status){
        			#$query="UPDATE `timesheet`.`users_projects` SET `status` = '$status' WHERE `users_projects`.`user_id` =$uid AND `users_projects`.`project_id`=$pid ";
			        $query="INSERT INTO  `timesheet`.`users_tasks` (`user_id` ,`task_id` ,`status`) VALUES ('$uid','$tid', '$status') ON DUPLICATE  KEY UPDATE `status` = '$status'";
        			parent::dbQuery($query); 
			       #return $query;      
			 } 	
			 
				#summ of hours in project for user
				 function getUserProjectSummByMonth($project_id,$user_id,$year){
				    $query = "select sum(t.hours) from projects as p,timesteps as t where p.id = t.project_id and t.user_id=$user_id and t.project_id =$project_id and year(t.date)=$year";
			    	#foreach(parent::dbQuery($query) as $num=>$key) {
					#$answer[$key['id']] = array('proj_name'=>$key['proj_name'],'proj_index'=>$key['proj_index'],'summ'=>$key['sum(t.hours)']);	
				   #	}
 				   	#return  $answer;	
 				   	return parent::dbQueryRow($query); 
				    }
			 
}




?>
Return current item: Opensheet