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


        require_once "config/config.php";
        require_once "config/db.php";
        

         //**********************************************Begin Page code**********************************************     
        require_once INCLUDE_DIR."/users_class.php"; 
        require_once INCLUDE_DIR."/users_signup_class.php"; 
        require_once INCLUDE_DIR."/master_class.php";
        require_once INCLUDE_DIR."/folderProtection.php";  
        require_once INCLUDE_DIR."/product_class.php";  
        
        $users=new users_class();
        $productobj=new product_class();
        $users_signup_class=new users_signup_class();
        //$key="projMemsite"; 
        //echo encrypt('nik00726',$key)."<br>" ;
        //echo decrypt('',$key) ;die;   
        if(isset($_GET['secSalt']))
           $lsuser  = trim($_GET['secSalt']);
        else
           $lsuser  = $_POST['username']; 
            
        //$_action    = $_GET['action'];
        $_action    = strtoupper($_action);
        $lsUserName = $lsuser;
        $key="";
        $user=decrypt($lsuser,$key);  
        $lsUserid=$user;
        $lsValues =array();     
        $lsValues[]=$lsUserid;
        
        $userQuery = 'SELECT * FROM '.TABLE_PREFIX.'users WHERE id=?';
        $lsUsersValues = array($lsUserid);
        $prod_clss_obj=new product_class();
        $laUserData = $prod_clss_obj->View($userQuery,$lsUsersValues,null);
        $isApproved=$laUserData[0]['isapproved'];

        if($isApproved==0)
        {
             $query="update ".TABLE_PREFIX ."users set isapproved=1 where id=?";  
             $lsUpdatedrows = $users->Update($query,$lsValues,null);
             if($users_signup_class->phpbbStatuscheck())
              {
                    $phpBBProduct=phpBB_get_product_id();
                    mysql_select_db(MEMBERSGEAR_DB_NAME);  
                    $proId=$productobj->checkForActiveSubscription($lsUserid,$phpBBProduct);
                    if($phpBBProduct==$proId)
                    {
                      phpBB_activate_deactivate_user($laUserData[0]['username'],0);
                      mysql_select_db(MEMBERSGEAR_DB_NAME);  
                    }
              }
               
               
               if($users_signup_class->wordpressStatuscheck()){
                                                             
                  $wordpressReqquiredFile= wordpress_physical_path();
                
                  if(file_exists($wordpressReqquiredFile)){
                  
                        require_once($wordpressReqquiredFile);
                         assign_sessions(); 
                         $plainpass=decrypt($laUserData[0]['password'],$laUserData[0]['secretsalt']); 
                          
                          $createdUserId = wordpress_username_exists( $laUserData[0]['username'] );  
                          $isemailExist=wordpress_email_exists($laUserData[0]['email']);
                          if(!$createdUserId and !$isemailExist ){ 
                                    
                                     $createdUserId=wordpress_Register_User($laUserData[0]['username'],$plainpass,$laUserData[0]['email']);
                                     if(!is_array($createdUserId) and !is_object($createdUserId) ){
                                     
                                         wordpress_add_user_meta( $createdUserId, 'first_name', $laUserData[0]['firstname'],false);
                                         wordpress_add_user_meta( $createdUserId, 'last_name', $laUserData[0]['lastname'],false);
                                         wordpress_add_user_meta( $createdUserId, 'nickname', $laUserData[0]['username'],false);
                                         
                                         $savedRoles=wordpress_get_option('membersgear_roles'); 
                                         $wp_role=array('subscriber'=>0,'contributor'=>1,'author'=>4,'editor'=>7,'administrator'=>10);
                                         $wp_role_byname=array(0=>'subscriber',1=>'contributor',4=>'author',7=>'editor',10=>'administrator');
                                        
                                         $userSubscribedProducts=$users_signup_class->getAlluserSubscribedProduct($lsUserid);
                                         $rolArr=array();
                                          if(count($userSubscribedProducts) > 0 and $userSubscribedProducts!=false)
                                          {
                                             for($i=0;$i<=count($userSubscribedProducts)-1;$i++)
                                              {
                                                  if(array_key_exists($userSubscribedProducts[$i]['id'],$savedRoles)){
                                                  
                                                    if(array_key_exists($savedRoles[$userSubscribedProducts[$i]['id']],$wp_role)){
                                                    
                                                        $rolArr[]=$wp_role[$savedRoles[$userSubscribedProducts[$i]['id']]];
                                                    
                                                     }
                                                  
                                                  }
                                              }
                                          } 
                                         $maxRole=max($rolArr);
                                         $roleName=$wp_role_byname[$maxRole];  
                                            
                                         if($roleName!=''){
                                         
                                            wordpress_add_user_role($createdUserId,$roleName);
                                            

                                         }
                                        else{
                                        
                                            wordpress_add_user_role($createdUserId,'subscriber');
                                        
                                          }
                                         
                                            
                                     }
                             
                          }
                         else{
                         
                         
                                  if($createdUserId==null)
                                    $createdUserId= $isemailExist;
                                    
                                  $savedRoles=wordpress_get_option('membersgear_roles'); 
                                  $wp_role=array('subscriber'=>0,'contributor'=>1,'author'=>4,'editor'=>7,'administrator'=>10);
                                  $wp_role_byname=array(0=>'subscriber',1=>'contributor',4=>'author',7=>'editor',10=>'administrator');
                                
                                   $userSubscribedProducts=$users_signup_class->getAlluserSubscribedProduct($lsUserid);
                                   $rolArr=array();
                                   if(count($userSubscribedProducts) > 0 and $userSubscribedProducts!=false)
                                   {
                                     for($i=0;$i<=count($userSubscribedProducts)-1;$i++)
                                      {
                                          if(array_key_exists($userSubscribedProducts[$i]['id'],$savedRoles)){
                                          
                                            if(array_key_exists($savedRoles[$userSubscribedProducts[$i]['id']],$wp_role)){
                                            
                                                $rolArr[]=$wp_role[$savedRoles[$userSubscribedProducts[$i]['id']]];
                                            
                                             }
                                          
                                          }
                                      }
                                    } 
                                     $maxRole=max($rolArr);
                                     $roleName=$wp_role_byname[$maxRole];  
                                        
                                     if($roleName!=''){
                                     
                                        wordpress_add_user_role($createdUserId,$roleName);
                                        

                                     }
                                    else{
                                    
                                        wordpress_add_user_role($createdUserId,'subscriber');
                                    
                                      }
                         
                         
                         
                         } 
                   } 
                      
           }

 
  

        
        /* update by nikunj for htacess add new user*/
               
       /*-------------------------------------------------------------------------------------------*/
           $objSignupclass=new users_signup_class();
           
           $getProdIdQuery="select productid from ".TABLE_PREFIX."product_users where userid=".$lsUserid;
           $resultProdQuery=$objSignupclass->View($getProdIdQuery);
           $productId=$resultProdQuery[0]['productid'];
           
           $objProtecfolderProtection_Class=new ProtecfolderProtection_Class(); 
           $larrProtectedFoldersForProduct = $objSignupclass->getProtectedFoldersForProduct($productId);
           $masterclassObj=new master_class();
                               
                                                  
             if(is_array($larrProtectedFoldersForProduct)) 
             {
                 foreach($larrProtectedFoldersForProduct as $key=>$folderpath) 
                    {
                                                 
                           $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); 
                            }  
                     }
                }

                
         
                
            //if($lsUpdatedrows>0)
            {
                $msg="Your Account is validated successfully.....  <br><br>
                <input type='button' id='btnLogin' name='btnLogin' value='Click here to Login...' onclick=\"javascript:location.href='./user_login.php';\" class=\"bigger-button\">";
               
                $smarty->assign('msg',$msg);
              
            } 
        }
     else
       {
                 $msg="You are already activated<br><br>
                <input type='button' id='btnLogin' name='btnLogin' value='Click here to Login...' onclick=\"javascript:location.href='./user_login.php';\" class=\"bigger-button\">";
               
                $smarty->assign('msg',$msg);
       
       }  
                 
        /*else
        {  
           $smarty->assign('msg','Your Account is not Validated');
        } */           
        $VALIDATEUSER = $smarty->fetch('user_validate.tpl');
            
        //**********************************************End Page code**********************************************
        //Common Line

        $smarty->assign('USER_CONTENT',     $VALIDATEUSER);
        $smarty->display('user_page_main.tpl');


?>
Return current item: MembersGear