Location: PHPKode > projects > MembersGear > membersgear/includes/users_class.php
<?php

 require_once "peardb_class.php";
 require_once INCLUDE_DIR."/roles_class.php";
 require_once INCLUDE_DIR."/usersinroles_class.php";
  require_once INCLUDE_DIR."/master_class.php";
  require_once INCLUDE_DIR."/users_signup_class.php"; 
  require_once INCLUDE_DIR."/folderProtection.php";  
 
 $userinrole=new usersinroles_class();

 class users_class extends peardb_class
 {  
 
    var $UserID='0';
    var $UserName='';
    var $UserInRoles='';
    var $UserInProducts='';
    var $IsAdmin=false;
    var $Admin_UserID='0';
    var $Admin_UserName='';
    var $LastLoginDate=0;
    
    function __construct() 
    {   
        
        if(isset($_SESSION[SESSION_PREFIX.'UserID']))
            $this->UserID=$_SESSION[SESSION_PREFIX.'UserID'];
            
        if(isset($_SESSION[SESSION_PREFIX.'UserName']))
            $this->UserName=$_SESSION[SESSION_PREFIX.'UserName'];
            
        if(isset($_SESSION[SESSION_PREFIX.'UserInRoles']))
            $this->UserInRoles=$_SESSION[SESSION_PREFIX.'UserInRoles'];
            
        if(isset($_SESSION[SESSION_PREFIX.'UserInProducts']))
            $this->UserInProducts=$_SESSION[SESSION_PREFIX.'UserInProducts'];
            
        if(isset($_SESSION[SESSION_PREFIX.'IsAdmin']))           
            $this->IsAdmin=$_SESSION[SESSION_PREFIX.'IsAdmin'];

        if(isset($_SESSION[SESSION_PREFIX.'Admin_UserID']))           
            $this->Admin_UserID=$_SESSION[SESSION_PREFIX.'Admin_UserID'];
        
        if(isset($_SESSION[SESSION_PREFIX.'Admin_UserName']))           
            $this->Admin_UserName=$_SESSION[SESSION_PREFIX.'Admin_UserName'];
            
        if(isset($_SESSION[SESSION_PREFIX.'lastlogindate']))
            $this->LastLoginDate = $_SESSION[SESSION_PREFIX.'lastlogindate'];
            
            
    }
    
    
    function IncreaseLoginAttemps($pUserName)
    {
        $pUserName = trim($pUserName);
        
        $liResult=0;
        
        //If user changes username for every invalid attamp then reset count of invalid attemps
        if(isset($_SESSION[SESSION_PREFIX.'TempUserName']))
        {
            if($pUserName != (string)$_SESSION[SESSION_PREFIX.'TempUserName'])
                $_SESSION[SESSION_PREFIX.'LoginAttempt'] = 0;
        }
        $_SESSION[SESSION_PREFIX.'TempUserName'] = $pUserName;
        
        //Set counter for invalid login attemps
        if(isset($_SESSION[SESSION_PREFIX.'LoginAttempt']))
        {
            if(is_integer($_SESSION[SESSION_PREFIX.'LoginAttempt']))
            {
                $_SESSION[SESSION_PREFIX.'LoginAttempt'] += 1;
                $liResult += $_SESSION[SESSION_PREFIX.'LoginAttempt'];
            }
            else
                $liResult = 1;
        }
        else
        {
            $_SESSION[SESSION_PREFIX.'LoginAttempt'] = 1;
            $liResult = 1;    
        }
        
        return $liResult;
    }
    
    function GetLoginAttemps()
    {
        $liResult;
        if(isset($_SESSION[SESSION_PREFIX.'LoginAttempt']))
        {
            if(is_integer($_SESSION[SESSION_PREFIX.'LoginAttempt']))
                $liResult = $_SESSION[SESSION_PREFIX.'LoginAttempt'] * 1;
            else
                $liResult = 0;
        }            
        else
        {
            if($_SERVER['REQUEST_METHOD']=='POST') 
            {
             //   $_SESSION[SESSION_PREFIX.'LoginAttempt'] = 1;
                $liResult = 1;
            }
            else
                $liResult = 0;
        }
       
        return $liResult;         
    }
    function ClearLoginAttemps()
    {
        
        if(isset($_SESSION[SESSION_PREFIX.'LoginAttempt']))
        {
            unset($_SESSION[SESSION_PREFIX.'LoginAttempt']);
               
        }    
        
    }     
       
    
        
    function View($pQuery, $pValues=false, $types=true, $pStart=0, $pEnd=0)
    {
        /*
        global $mdb2;    
        $result;  
 
        $query      = 'SELECT * FROM tbluser1 t limit 10;';
        $resultset  = $mdb2->query($query);
        
        if(PEAR::isError($resultset)) 
        {
            die("Failed to issue query, error message : " . $resultset->getMessage());
        }
        
        while($row = $resultset->fetchRow(MDB2_FETCHMODE_ASSOC))
        {
            $result[] = $row;
        }
                                                                                                                 
        return  $result;   
        */
        //print_r($pParameters);
        
        return $this->BaseView($pQuery,$pValues,$types,$pStart,$pEnd);
        
    }
    
    function Update($pQuery, $pValues=false, $types=true)
    { 
       
        return $this->BaseUpdate($pQuery, $pValues, $types);
    
    }

    
    function Insert($pQuery, $pValues=false, $types=true)
    { 
    
        return $this->BaseInsert($pQuery, $pValues, $types);
    
    }
    function IsUserAvailable($pQuery, $pValues=false, $types=true, $pStart=0, $pEnd=0)
    {
    
       return $this->View($pQuery,$pValues,$types,$pStart,$pEnd);  
  
    }
     function delete($pQuery, $pValues=false, $types=true)
    {
        
      return $this->BaseDelete($pQuery, $pValues,null);
        
    } 
    function GetadminPermission($pPermissiontype="1")
    {
           if($pPermissiontype=="1")
           {
            $query= "SELECT   mv.`value` as permission,mv.id as permissionid   FROM ".TABLE_PREFIX."master_values mv join        ".TABLE_PREFIX."master m on m.id = mv.masterID where m.Name = 'permissions' and   mv.id=(SELECT mv.id as permissionid  FROM ".TABLE_PREFIX."master_values mv join ".TABLE_PREFIX."master m on m.id = mv.masterID where m.Name = 'permissions' and   mv.value ='Super Admin') ";  
           }
           else if($pPermissiontype=="2")
           {
                $query= "SELECT   mv.`value` as permission,mv.id as permissionid   FROM ".TABLE_PREFIX."master_values mv join        ".TABLE_PREFIX."master m on m.id = mv.masterID where m.Name = 'permissions' and  mv.id!=(SELECT mv.id as permissionid  FROM ".TABLE_PREFIX."master_values mv join ".TABLE_PREFIX."master m on m.id = mv.masterID where m.Name = 'permissions' and   mv.value ='Super Admin') "; 
               
           } 
           $result = $this->View($query);    
          return $result;
    }   
    function GetadminStatus()
    {
        
         $query= "SELECT   mv.`value` as statusname,mv.id as statusid   FROM ".TABLE_PREFIX."master_values mv join        ".TABLE_PREFIX."master m on m.id = mv.masterID where m.Name = 'adminstatus' ";  
         
         $result = $this->View($query);  
         
           return $result;       
    } 
    function GetUserStatus()
    {
        
           
         $query= "SELECT   mv.`value` as statusname,mv.id as statusid   FROM ".TABLE_PREFIX."master_values mv join        ".TABLE_PREFIX."master m on m.id = mv.masterID where m.Name = 'userstatus' ";  
         
         $result = $this->View($query);  
         
           return $result;
        
    }    
    
   function getSecretsalt($puserName)
    {
        $queryGetUserKey="select secretsalt from ".TABLE_PREFIX."users where username='$puserName'";
        $result = $this->View($queryGetUserKey);
        $key=$result[0]['secretsalt'];
        return $key;
    
    }
    
     function getUserId($puserName)
    {
        $queryGetUserId="select id from ".TABLE_PREFIX."users where username='$puserName'";
        $result = $this->View($queryGetUserId);
        $id=$result[0]['id'];
        return $id;
    
    }
    
   function getSecretsaltById($pUserId)
    {
        $queryGetUserKey="select secretsalt from ".TABLE_PREFIX."users where id=$pUserId";
        $result = $this->View($queryGetUserKey);
        $key=$result[0]['secretsalt'];
        return $key;
    
    } 
    
    function GetLastLoginDate($pUserName) {
        
        if(isset($_SESSION[SESSION_PREFIX.'lastlogindate']))
            return $_SESSION[SESSION_PREFIX.'lastlogindate'];
        
      //  $query = "select IFNULL(MAX(visitedon),0) as `visitedon` from ".TABLE_PREFIX."users_log i
//                    where id=(SELECT max(id) FROM ".TABLE_PREFIX."users_log p
//                                where p.userid = (select id from ".TABLE_PREFIX."users where username='$pUserName' limit 1));";
       // print $query;
        
        $query="select last_login_date 'visitedon'  from ".TABLE_PREFIX."users where username='$pUserName' limit 1";
        
        $result = $this->View($query);
      
        $result = $result[0]['visitedon'];
      
        if($result == 0 || $result == '0')
            return time();
    
       if(isset($_SESSION[SESSION_PREFIX.'lastlogindate']))
        $this->LastLoginDate = $_SESSION[SESSION_PREFIX.'lastlogindate'];
          
        $_SESSION[SESSION_PREFIX.'lastlogindate'] = $result;
    
        return $result;
        
    }
    
    
    
    function ValidateUser($pUserName, $pPassword,$pencrypt='')
    {
        
        $key=$this->getSecretsalt($pUserName);
        if($pUserName != '' && $pPassword != '')
        {

            $lauserinfo[]=$pUserName;
            if($pencrypt=='')
            {
                $lauserinfo[]=encrypt($pPassword,$key); 
            }
            else
            {
               $lauserinfo[]=$pPassword;
            }    
            
            $query="select u.*,
                        (select `name` from ".TABLE_PREFIX."roles  where id=ur.roleid) as role  
                    from ".TABLE_PREFIX."users  u join ".TABLE_PREFIX."users_in_roles ur on u.id=ur.userid 
                    where u.username=? 
                        and CAST(u.password AS BINARY)=? 
                        and u.isapproved=1 and u.islockedout!=1";
                          
            $loginresult = $this->View($query,$lauserinfo,null);

            if(is_array($loginresult))
            {
                if(sizeof($loginresult)>0)
                {
                    $userid=$loginresult[0]['id'];               
                    $username=$loginresult[0]['username'];
                    $iauserinroles=array();
                    $i=0;
                   
                    foreach($loginresult as $key=>$value)
                    {
                        $iauserinroles[$i]=$value['role']; 
                        $i++;
                    }
                   
                    $lsIsadmin=false; 
                    foreach($iauserinroles as $key=>$value)
                    {
                       
                        if(strtolower($value)=='admin')
                        {
                            $lsIsadmin=true;
                            break; 
                        } 
                        else
                        {
                            $lsIsadmin=false;
                        }   
                       
                    }
                    
                    
                    if(!$lsIsadmin) 
                    {   
                        $_SESSION[SESSION_PREFIX.'UserID']=$userid;                 //string
                        $_SESSION[SESSION_PREFIX.'UserName']=$username;             //string
                        $_SESSION[SESSION_PREFIX.'UserInRoles']=$iauserinroles;     //array
                        $_SESSION[SESSION_PREFIX.'UserInProducts']='';              //array
                        
                        $this->UserID           = $userid;
                        $this->UserName         = $username; 
                        $this->UserInRoles      = $iauserinroles; 
  
                       // setcookie('membersite_userid',  $_SESSION[SESSION_PREFIX.'UserID'],time()+3600,'/');
                        //setcookie('membersite_username',$_SESSION[SESSION_PREFIX.'UserName'],time()+3600,'/');
                    }
                    else
                    {       
                        $_SESSION[SESSION_PREFIX.'IsAdmin']=$lsIsadmin;             //boolean  
                        $_SESSION[SESSION_PREFIX.'Admin_UserID']=$userid;           //string
                        $_SESSION[SESSION_PREFIX.'Admin_UserName']=$username;       //string
                        
                        
                        $this->IsAdmin          = true;
                        $this->Admin_UserID     = $userid;
                        $this->Admin_UserName   = $username; 
                       // setcookie('membersite_admin_userid',$_SESSION[SESSION_PREFIX.'Admin_UserID'],time()+3600,'/');
                      //  setcookie('membersite_admin_username',$_SESSION[SESSION_PREFIX.'Admin_UserName'],time()+3600,'/');
                    }
                    
                    $this->GetLastLoginDate($username);
                     
                    $result = true;
                }
            }
        }
            
        
        return $result;
        
    }
    
    function Do_Global_Smarty_Assignment($user) {
        //echo $smarty;die;
       // if(isset($smarty)) {
            global $smarty;
            
            if($this->IsAuthenticated(false)) {
                $smarty->assign('MEMBERSITE_USERID',             $this->UserID); 
                $smarty->assign('MEMBERSITE_USERNAME',           $this->UserName); 
                $smarty->assign('MEMBERSITE_USER_LASTLOGGEDINTIME',   date('M d, Y h:i:sA', $this->LastLoginDate)); 
                $url=WEB_URL."/member/user_logout.php";
                $url=urlencode($url);
               // $glogoutlink="<a href=\"".WEB_URL."/member/user_rotete_logout.php?url=".$url."\">Logout</a>";
                $glogoutlink=WEB_URL."/member/user_rotete_logout.php?url=".$url;  
                $smarty->assign('MEMBERSITE_LOGINSTATUS','logout');
                $smarty->assign('MEMBERSITE_LOGINSTATUS_LINK',$glogoutlink);
             
                
            }
            else
            {
            
               // $gloginlink="<a href=\"".WEB_URL."/user_login.php\">Login</a>";
                 $gloginlink=WEB_URL."/user_login.php"; 
                $smarty->assign('MEMBERSITE_LOGINSTATUS','login'); 
                $smarty->assign('MEMBERSITE_LOGINSTATUS_LINK',$gloginlink); 
                
            }   
           // $gsignuplink="<a href=\"".WEB_URL."/user_signup.php\">Signup</a>";
             $gsignuplink=WEB_URL."/user_signup.php";
            $smarty->assign('MEMBERSITE_SIGNUP',$gsignuplink);
          //  $gsupportlink="<a href=\"".WEB_URL."/member/user_support.php\">Support</a>";
            $gsupportlink=WEB_URL."/member/user_support.php";
            $smarty->assign('MEMBERSITE_SUPPORT',$gsupportlink);
            //$ghomelink="<a href=\"".WEB_URL."/member/user_default_page.php\">Home</a>";
            $ghomelink=WEB_URL."/member/user_default_page.php";    
            $smarty->assign('MEMBERSITE_HOME',$ghomelink);
           // $gchangepassword="<a href=\"".WEB_URL."/member/user_change_password.php\">Change Password</a>";
            $gchangepassword=WEB_URL."/member/user_change_password.php";
            $smarty->assign('MEMBERSITE_CHANGEPASSWORD',$gchangepassword);
          //  $geditprofile="<a href=\"".WEB_URL."/member/user_edit_profile.php\">Edit Profile</a>";
            $geditprofile=WEB_URL."/member/user_edit_profile.php";
            $smarty->assign('MEMBERSITE_EDITPROFILE',$geditprofile);
             
            
            if($this->IsAuthenticated(true)) {
                $smarty->assign('MEMBERSITE_ADMIN_USERID',       $this->Admin_UserID);    
                $smarty->assign('MEMBERSITE_ADMIN_USERNAME',     $this->Admin_UserName);
                $smarty->assign('MEMBERSITE_ADMIN_LASTLOGGEDINTIME',   date('M d, Y h:i:sA', $this->LastLoginDate));  
            }    

            return true;            
        //}
        
        return false;
        
    }
    
    
    function userLogout()
     {
         
          if(isset($_SESSION[SESSION_PREFIX.'UserID']))
            unset($_SESSION[SESSION_PREFIX.'UserID']);
            
        
        if(isset($_SESSION[SESSION_PREFIX.'UserName']))
            unset($_SESSION[SESSION_PREFIX.'UserName']);
            
        
        if(isset($_SESSION[SESSION_PREFIX.'UserInRoles']))
            unset($_SESSION[SESSION_PREFIX.'UserInRoles']);
            
        
        if(isset($_SESSION[SESSION_PREFIX.'UserInProducts']))
            unset($_SESSION[SESSION_PREFIX.'UserInProducts']);
            
        setcookie('membersite_userid','',time()-3600,'/');
        setcookie('membersite_username','',time()-3600,'/');
             
         
     }
    function Logout()
    {
        if(isset($_SESSION[SESSION_PREFIX.'UserID']))
            unset($_SESSION[SESSION_PREFIX.'UserID']);
            
        
        if(isset($_SESSION[SESSION_PREFIX.'UserName']))
            unset($_SESSION[SESSION_PREFIX.'UserName']);
            
        
        if(isset($_SESSION[SESSION_PREFIX.'UserInRoles']))
            unset($_SESSION[SESSION_PREFIX.'UserInRoles']);
            
        
        if(isset($_SESSION[SESSION_PREFIX.'UserInProducts']))
            unset($_SESSION[SESSION_PREFIX.'UserInProducts']);
            
        
        if(isset($_SESSION[SESSION_PREFIX.'IsAdmin']))           
            unset($_SESSION[SESSION_PREFIX.'IsAdmin']);

        if(isset($_SESSION[SESSION_PREFIX.'Admin_UserID']))           
            unset($_SESSION[SESSION_PREFIX.'Admin_UserID']);
  
        if(isset($_SESSION[SESSION_PREFIX.'Admin_UserName']))           
            unset($_SESSION[SESSION_PREFIX.'Admin_UserName']);
            
                        
        setcookie('membersite_userid','',time()-3600,'/');
        setcookie('membersite_username','',time()-3600,'/');

        setcookie('membersite_admin_userid','',time()-3600,'/');
        setcookie('membersite_admin_username','',time()-3600,'/');
        
        session_destroy();
        
    }
    function  ValidateUserName($pUserName)
    {
         if($pUserName != '')
         {
           $lauserinfo[]=$pUserName;
           //$lauserinfo[]=encrypt($pPassword); 
             
           $query="select username from ".TABLE_PREFIX."users where username=?";
           
           $loginresult = $this->View($query,$lauserinfo,null);
           
            if(is_array($loginresult))
            {
                if(sizeof($loginresult)>0)
               {
                    return true;
               }
                else
                {
                
                   return  false;
                } 
        
            }
             else
             {
                return false;
                
             } 
           
        }
    } 
    
    function UserLockout($pUserName)
    {
       if($pUserName!='')
       {
           $checkstatus=false;
           $lauserinfo[]=$pUserName;
              
           $query="select u.username as username,u.id as userid,u.isapproved as isapproved,u.islockedout as islockedout,
                        (select `name` from ".TABLE_PREFIX."roles  where id=ur.roleid) as role
                    from ".TABLE_PREFIX."users  u join ".TABLE_PREFIX."users_in_roles ur on u.id=ur.userid
                    where u.username=?";
           
           $lauserlockoutinfo = $this->View($query,$lauserinfo,null);
           if(is_array($lauserlockoutinfo))
           {
                 if(sizeof($lauserlockoutinfo)>0)
                 {
                        $userid=$lauserlockoutinfo[0]['userid'];               
                        $username=$lauserlockoutinfo[0]['username'];
                        $isapproved=$lauserlockoutinfo[0]['isapproved'];
                        $lockedout=$lauserlockoutinfo[0]['islockedout'];               
                        if($lockedout!=2)
                        {
                            $query="update ".TABLE_PREFIX."users set isapproved=?  where id=?";
                            $laupdateisapproved[]=0;  
                            $laupdateisapproved[]= $userid;
                            $liisapprovedupdate = $this->Update($query,$laupdateisapproved,null);
                            if($liisapprovedupdate>0)
                            {
                                   $query="update ".TABLE_PREFIX."users set islockedout=?  where id=?";
                                   $laupdateislocked[]=1;  
                                   $laupdateislocked[]= $userid;
                                   $liuserislockedpdate = $this->Update($query,$laupdateislocked,null); 
                                   if($liuserislockedpdate>0)
                                   {
                                       if(isset($_SESSION[SESSION_PREFIX.'LoginAttempt']))
                                       {
                                           unset($_SESSION[SESSION_PREFIX.'LoginAttempt']);
                                       } 
                                       return true;
                                   }
                                   else
                                   {
                                      return false;
                                   }    
                                   
                                   
                            }
                            else
                            {
                                  return false;
                                      
                            }    
                        }   
                 }    
                            
           }   
                   
       }    
       
       else
       {
        return false;
       
       } 
        
    }  
    function IsLockedout($pUserName)
    {
        $lauserinfo[]=$pUserName;         
        $query="select *  from ".TABLE_PREFIX."users where username=?"; 
        $lauserlockoutinfo = $this->View($query,$lauserinfo,null);
        if($lauserlockoutinfo[0]['islockedout']==1)
        {
            return true;   
            
        }   
        else
        {
            return false;
        
        } 
        
    
    }
    function IsApproved($pUserName)
    {
        $lauserinfo[]=$pUserName;         
        $query="select *  from ".TABLE_PREFIX."users where username=?"; 
        $lauserlockoutinfo = $this->View($query,$lauserinfo,null);
        if($lauserlockoutinfo[0]['isapproved']==1)
        {
            return true;   
            
        }   
        else
        {
            return false;
        
        } 
    
    }
    
    
    //This function will also be used in config file to validate users and admin
    function IsAuthenticated($pIsAdmin=false)
    {
        if(!$pIsAdmin)
        {
            if($this->UserID != '' && $this->UserName != '')
                return true;
        }   
        else
        {
            if($this->IsAdmin && $this->Admin_UserID != '' && $this->Admin_UserName != '')
                return true;
            
        }            
        
        return false;    
        
    }
    
     function getUserNamePassword($pSearchValue,$temp = '')
    {
        $condition = ''; 
        $query="select u.username,u.password from ".TABLE_PREFIX."users u where ";
        $lauserinfo = array();
        
        if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $pSearchValue))
        {
            $query .= 'u.email=? ';
        }
        else
        {
            $query .= 'u.username=? ';       
        }
         $lauserinfo[]=$pSearchValue;
         /*
         if(isset($puserName) and $puserName != '' and $puserName != 'Enter your User Name')
         {
                $query .= 'u.username=? ';
                $lauserinfo[]=$puserName;
                $condition = 'and ';       
         }
         
         if(isset($pEmail) and $pEmail != '' and $pEmail != 'Enter your Email Address')
         {
                $query .= $condition.'u.email=?';
                $lauserinfo[]=$pEmail;       
         }*/
         if($pSearchValue != 'Enter Username / E-mail Address')
         {
            $forgotpassResult = $this->View($query,$lauserinfo,null);
         }
            
         return $forgotpassResult;            
     }   

 
  function GetRoleByUsername($pUserName)
{
    $lauserinfo[]=$pUserName;         
    $query="select u.*,
                        (select `name` from ".TABLE_PREFIX."roles  where id=ur.roleid) as role  
                    from ".TABLE_PREFIX."users  u join ".TABLE_PREFIX."users_in_roles ur on u.id=ur.userid 
                    where u.username=? ";
      $laroleeresult = $this->View($query,$lauserinfo,null);

            if(is_array($laroleeresult))
            {
                if(sizeof($laroleeresult)>0)
                {
                    $userid=$laroleeresult[0]['id'];               
                    $username=$laroleeresult[0]['username'];
                    $iauserinroles=array();
                    $i=0;
                   
                    foreach($laroleeresult as $key=>$value)
                    {
                        $iauserinroles[$i]=$value['role']; 
                        $i++;
                    }
                }
            }
                     
         return $iauserinroles;                
       
} 

    function createAdminIfNotExist()
    {
  
         $query="select username from ".TABLE_PREFIX ."users where username='administrator'";
         $lsusern=users_class::View($query);
         $lsIfUserExist=$lsusern[0]['username'];
         if(!isset($lsIfUserExist) or $lsIfUserExist=="" or $lsIfUserExist==NULL )
          {
                        $lstokenKey=createToken();
                        $query="INSERT INTO ".TABLE_PREFIX ."users (username,`password`,secretsalt,firstname,lastname, Email,country,state, city, address1,address2, zipcode,phone_main,createdon, createdby,createdipaddress,isapproved,islockedout) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";         $lsValues = array();
                         $lsValues[]='administrator';
                         $lsValues[]=encrypt('123456',$lstokenKey);
                         $lsValues[]=$lstokenKey;
                         $lsValues[]='admin ';
                         $lsValues[]='admin ' ;
                         $lsValues[]='hide@address.com';
                         $lsValues[]='23';
                         $lsValues[]='789';
                         $lsValues[]='surat';
                         $lsValues[]='surat';
                         $lsValues[]='surat';
                         $lsValues[]='394164';
                         $lsValues[]='1235451';
                         $lsValues[]=mktime();
                         $lsValues[]=0;
                         $lsValues[]=$_SERVER['REMOTE_ADDR'];
                         $lsValues[]=1;
                         $lsValues[]=0;
                         $lsInsertedrows = users_class::Insert($query,$lsValues,null);
                         if($lsInsertedrows>0)
                         {   
                               $lauserinfovalue=array();
                               $lauserinfovalue[0] = 'administrator'; 
                               $lauserinfo =  users_class::view("SELECT id FROM ".TABLE_PREFIX ."users where username=?",$lauserinfovalue,null);
                             
                               $lsValuesrole=array();
                               $lsValuesrole[0]='admin';
                               
                                $userrole=new roles_class();
                                $laroleid=$userrole->GetRoleID($lsValuesrole,null);
                             
                                $userinrole=new usersinroles_class();
                               $lauserinrolevalue=array();
                               $lauserinrolevalue[0]=$lauserinfo[0]['id'];
                               $lauserinrolevalue[1]=$laroleid[0]['id'];
                               $lauserinrolevalue[2]=mktime();
                               $lauserinrolevalue[3]=0;
                               $lauserinrolevalue[4]=$_SERVER['REMOTE_ADDR'];   
                               $user= $userinrole->Insert('',$lauserinrolevalue,null);
                               
                                 $query= "INSERT INTO ".TABLE_PREFIX."users_permissions (userid, permission, createdon, 
                                 createdby, createdipaddress)VALUES(?,?,?,?,?)"; 

                                 
                                $mastclass=new master_class();
                                $masterId=$mastclass->getMasterId('permissions');
                                $adminPerID=$mastclass->getMasterValuesId('Super Admin',$masterId);
                                $lapermission[0]=$lauserinfo[0]['id']; 
                                $lapermission[1]=$adminPerID ;  
                                $lapermission[2]=mktime();
                                $lapermission[3]=0;
                                $lapermission[4]=$_SERVER['REMOTE_ADDR']; 
                                $lsInsertedrows = users_class::Insert($query,$lapermission,null); 
                             
                         } 
         
         }

    }
    
     function getAffiliateSettings($userid)
     {
        $Query="SELECT * FROM ".TABLE_PREFIX."product_users_affiliate puu left join
        ".TABLE_PREFIX."product_users p  on p.id=puu.product_users_id where puu.isactive=1 and
        p.userid=$userid "; 
        $res=$this->View($Query);
        return $res; 
   
      }
      
   function getAffiliateSettings_inactive($userid)
     {
        $Query="SELECT puu.id FROM ".TABLE_PREFIX."product_users_affiliate puu left join
        ".TABLE_PREFIX."product_users p  on p.id=puu.product_users_id where  
        p.userid=$userid ";
        $res=$this->View($Query);
        return $res; 
   
      }   
            
    function getSpecificUserInfoById($puserId) 
    {
        
         $query="select * from ".TABLE_PREFIX ."users where id=$puserId";
         $lsusern=users_class::View($query);
         return $lsusern;
        
    }
    function IsAdminhavePermission($pUserID,$pPermisiion)
    {
         $lsadministrator=trim($_SESSION[SESSION_PREFIX.'Admin_UserName']);
         if($lsadministrator=='administrator')
         {
            $result=true; 
         }
         else
         {    
             $mastclass=new master_class();
             $masterId=$mastclass->getMasterId('permissions');
             $superadminperID=$mastclass->getMasterValuesId('Super Admin',$masterId);
             $lauserinfo[]=$pUserID; 
             $lauserinfo[]=$superadminperID;        
             $query="select * from ".TABLE_PREFIX."users_permissions  where userid=?  and permission=? ";
             $lapermisionrsult = $this->View($query,$lauserinfo,null);

                if(is_array($lapermisionrsult))
                {
                    if(sizeof($lapermisionrsult)>0)
                    {
                         
                          $result=true;
                    }
        
                }
                else
                {
                     $adminperID=$mastclass->getMasterValuesId($pPermisiion,$masterId);
                     $lauserinfo=array();
                     $lauserinfo[]=$pUserID; 
                     $lauserinfo[]=$adminperID;        
                     $query="select * from ".TABLE_PREFIX."users_permissions  where userid=?  and permission=? ";
                     $laadminperresult = $this->View($query,$lauserinfo,null); 
                       if(is_array($laadminperresult))
                       {
                            if(sizeof($laadminperresult)>0)
                            {
                                 
                                     $result=true;  
                            }
                       }
                       else
                       {
                             $result=false; 
                           
                       }    
                    
                } 
         } 
            return $result;  
    }
    function GetUserSubscriptiondataForDashboard()
    { 
        $sql=" select count(*) as totalcount from ".TABLE_PREFIX."product_users";
        
        $result1=$this->View($sql);  
        if(is_array($result1) && sizeof($result1))
        {
            $lstotalcount=$result1[0]['totalcount'];   
        }
        else
        {
            $lstotalcount='';
        }    
        
        
        $sql=" select count(*) as activecount   from ".TABLE_PREFIX."product_users where  productmembershipstatusid
           =(SELECT mv.id as permissionid  FROM ".TABLE_PREFIX."master_values mv join
                                    ".TABLE_PREFIX."master m on m.id = mv.masterID where
                                     m.Name = 'productmembershipstatus' and   mv.value ='Active')";
        $result1=$this->View($sql);  
        if(is_array($result1) && sizeof($result1))
        {
            $lsActivecount=$result1[0]['activecount'];   
        }
        else
        {
            $lsActivecount='';
        }    
        



       $sql=" select count(*) as inactivecount   from ".TABLE_PREFIX."product_users where  productmembershipstatusid
        =(SELECT mv.id as permissionid  FROM ".TABLE_PREFIX."master_values mv join
                                    ".TABLE_PREFIX."master m on m.id = mv.masterID where
                                     m.Name = 'productmembershipstatus' and   mv.value ='Inactive')";
                                     
        $result1=$this->View($sql);                              
        if(is_array($result1) && sizeof($result1))
        {
            $lsInActivecount=$result1[0]['inactivecount'];   
        }
        else
        {
            $lsInActivecount='';
        }                                  
                                     
       $sql=" select count(*) as pendingcount   from ".TABLE_PREFIX."product_users where  productmembershipstatusid
        =(SELECT mv.id as permissionid  FROM ".TABLE_PREFIX."master_values mv join
                                    ".TABLE_PREFIX."master m on m.id = mv.masterID where
                                     m.Name = 'productmembershipstatus' and   mv.value ='Pending')";
                                     
        $result1=$this->View($sql);                              
        if(is_array($result1) && sizeof($result1))
        {
            $lspendingcount=$result1[0]['pendingcount'];   
        }
        else
        {
            $lspendingcount='';
        }                                     
                                     
       $sql=" select count(*) as expirecount   from ".TABLE_PREFIX."product_users where  productmembershipstatusid
        =(SELECT mv.id as permissionid  FROM ".TABLE_PREFIX."master_values mv join
                                    ".TABLE_PREFIX."master m on m.id = mv.masterID where
                                     m.Name = 'productmembershipstatus' and   mv.value ='Expire')";                               
        $result1=$this->View($sql);                              
        if(is_array($result1) && sizeof($result1))
        {
            $lsexpirecount=$result1[0]['expirecount'];   
        }
        else
        {
            $lsexpirecount='';
            
        }  
        
    $currenttime=mktime();
       // from_unixtime($currenttime,"%m/%d/%Y")
        $sql="select count(*) as usercountfortoday  from ".TABLE_PREFIX."users_log where from_unixtime(visitedon,'%m/%d/%Y')= from_unixtime(".$currenttime.",'%m/%d/%Y') ";
        $result1=$this->View($sql);                              
        if(is_array($result1) && sizeof($result1))
        {
            $lsusercountfortoday=$result1[0]['usercountfortoday'];   
        }
        else
        {
            $lsusercountfortoday='';
            
        }   
        
        $sql="select count(*) as emaillogfortoday  from ".TABLE_PREFIX."emails_log where from_unixtime(createdon,'%m/%d/%Y')= from_unixtime(".$currenttime.",'%m/%d/%Y') ";
        $result1=$this->View($sql);                              
        if(is_array($result1) && sizeof($result1))
        {
            $lsemaillogfortoday=$result1[0]['emaillogfortoday'];   
        }
        else
        {
            $lsemaillogfortoday='';
            
        }   
        $ladashborduserdata =array();
        $ladashborduserdata['totalcount']=$lstotalcount;
        $ladashborduserdata['activecount']=$lsActivecount;
        $ladashborduserdata['inactivecount']=$lsInActivecount;
        $ladashborduserdata['pendingcount']=$lspendingcount;
        $ladashborduserdata['expirecount'] =$lsexpirecount;
        $ladashborduserdata['usercountfortoday']=$lsusercountfortoday;
        $ladashborduserdata['emaillogfortoday']=$lsemaillogfortoday;  
        
        return  $ladashborduserdata;
            
    
    
 }
 function deleteuser($pUserid)
 {
     
      $userTablequery = "DELETE FROM ".TABLE_PREFIX."users WHERE id in ($pUserid)";
              $usersinrolesTableQuery = "DELETE FROM ".TABLE_PREFIX."users_in_roles WHERE userid in ($pUserid)";
              $tempproductusersTableQuery = "DELETE FROM ".TABLE_PREFIX."product_users WHERE userid in ($pUserid)";
              
              $laUserID = array($pUserid);
              //$isDeleted = $this->delete($userTablequery,$laUserID,null);
               $isDeleted = $this->delete($userTablequery);
              if($isDeleted > 0)
              {
                       $isDeleted = $this->delete($usersinrolesTableQuery);
                       if($isDeleted > 0)
                       {
                                 $query="delete from ".TABLE_PREFIX."emails_log  where sentto_userid in ($pUserid)";
                                 $lsdeletedrows = $this->delete($query);
                                 $query="delete from  ".TABLE_PREFIX."users_log where userid in ($pUserid)";
                                 $lsdeletedrows = $this->delete($query);
                                 /*update by nikunj for htacess user delete */
                                 
                                 $usersubscribedProd="select productid from ".TABLE_PREFIX."product_users where userid in ($pUserid)" ;
                                 $resultProd=$this->View($usersubscribedProd);
                                 
                                 if(is_array($resultProd))
                                  {
                                         foreach($resultProd as $key=>$val)
                                         {
                                               $objSignupclass=new users_signup_class();
                                                $objProtecfolderProtection_Class=new ProtecfolderProtection_Class(); 
                                                 $larrProtectedFoldersForProduct = $objSignupclass->getProtectedFoldersForProduct($val['productid']);
                                                 $masterclassObj=new master_class();
                               
                                                  
                                                  if(is_array($larrProtectedFoldersForProduct)) 
                                                    {
                                                        foreach($larrProtectedFoldersForProduct as $key=>$folderpath) 
                                                          {
                                                          //print $folderpath['folder'].'<br />';
                                                             $lsUrl=trim(PHYSICAL_DIR.$folderpath['folder']."/");  
                                                             
                                                              $mastervalue=$masterclassObj->getValueFromID($folderpath['protection_method']); 
                                                              if($mastervalue=='.htaccess')
                                                               {
                                                                  $objProtecfolderProtection_Class->createHtaccess($lsUrl);
                                                                  $products=$objSignupclass->getAllowedProductsFromProtectedFolder($folderpath['folder']);
                                                                  $objProtecfolderProtection_Class->createPasswdfile($lsUrl,$products); 
                                                               }  
                                                     
                                                          }
                                                  }
                                         
                                         }
                                  }      
                                 
                                 $isDeleted1 = $this->delete($tempproductusersTableQuery);   
                                 $query="delete from ".TABLE_PREFIX."signupformdata where userid  in ($pUserid)";
                                 $isDeleted1 = $this->delete($query);
                                    
                       }
              }
              return $isDeleted;  
     
 }    
    
 
}                                                                                        
   
?>
Return current item: MembersGear