Location: PHPKode > projects > MembersGear > membersgear/admin/admin_user_subscription_m.php
<?php
   require_once "../config/config.php";     
  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";    
   require_once INCLUDE_DIR."/PaygearWebserviceClient.php";  
                                                                             
$objPayGear=new PaygearWebserviceClient();
$users_signup_class=new users_signup_class(); 
$objProclass=new product_class();
$usersignuupObj=new users_signup_class();    
  
/* update by nikunj for list mail pro setting **********************/

$listmailProStatus=false;   
if(function_exists('listmailpro_check_Plugin_structure') and function_exists('listmailpro_getListMailPro_status') and function_exists('listmailpro_getListMailPro_table_Prefix') and function_exists('listmailpro_connect_to_db') and function_exists('listmailpro_disconnect_db') and function_exists('listmailpro_get_list_mailpro_user') and function_exists('listmailpro_get_all_list_mailpro_lists') and function_exists('listmailpro_addUserToListMailPro') and function_exists('listmailpro_updateUserToListMailPro') and function_exists('listmailpro_updateUserToListMailProAndEmail') and function_exists('listmailpro_deleteUserFromListMailPro') and function_exists('listmailpro_unique_id') and function_exists('listmailpro_remlists') and function_exists('listmailpro_getlistopts') and function_exists('listmailpro_addlists'))
 {
    
    $listmailProStatus=listmailpro_getListMailPro_status();
   
 }  
/*******************************************************************/   
 
 $aweberStatus=false;   
if(function_exists('aweber_check_Plugin_structure') and function_exists('aweber_getAweber_status') and function_exists('aweber_adduserToList') )
 {
 
    
    $aweberStatus=aweber_getAweber_status();
   
 }  
/*******************************************************************/  

/* update by nikunj for getresponse setting **********************/
$getresponseStatus=false;   
 if(function_exists('getresponse_check_Plugin_structure') and function_exists('getresponse_getAPI_KEY') and function_exists('getresponse_getGetresponse_status') and function_exists('getresponse_adduserToList') )
 {
    
    $getresponseStatus=getresponse_getGetresponse_status();
   
 }  
/*******************************************************************/   

/* update by nikunj for imnicamail setting **********************/
$imnicamailStatus=false;   
if(function_exists('imnicamail_check_Plugin_structure') and function_exists('imnicamail_getImnicamail_status') and function_exists('imnicamail_adduserToList') )
 {
    
    $imnicamailStatus=imnicamail_getImnicamail_status();
   
 }  
/*******************************************************************/   

  $objprodcalss=new product_class();  
  $usersignuup=new users_signup_class();    
  $users = new users_class(); 
  if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can browse user profiles')==false)
  {
    Redirect('admin_nopermission.php',true);  
  }
 require_once INCLUDE_DIR."/product_class.php"; 
 require_once INCLUDE_DIR."/location_class.php";  

  if(function_exists('wordpress_check_Plugin_structure') and function_exists('wordpress_getWordpress_status')  )
 {
  
    $wordpressStatus=wordpress_getWordpress_status();
    if($wordpressStatus){

        $dirWordpress=wordpress_physical_path_dir()."wp-config.php";
        if(file_exists($dirWordpress)){
            require_once($dirWordpress);  
            assign_sessions(); 
            
        }
        
     }
   
 }  
    
  switch($_action)
  {
      
       case 'insert':
                $lsValues=array();
                $lsValues[]=trim($_POST['userid']);
                $query="select * from ".TABLE_PREFIX."users where id=?";
                $laresult=$users->View($query,$lsValues,null);
                if(is_array($laresult) && sizeof($laresult)>0)
                {
                      
                        
                        $query="select p.price,p.paygear_productid as paygearproductid,po.paygear_productpaymentoptionid as paygearpaymentoptionid  
                                from ".TABLE_PREFIX ."products p  left join ".TABLE_PREFIX ."productpaymentoptions po on p.id=po.productid where p.id=".trim($_POST['products'])."";                     
                         $laprodresult=$users->View($query,$lsValues,null);
                         if(is_array($laprodresult) && sizeof($laprodresult)>0)
                         {      
                               $locationobj=new location_class();   
                                $lsValues=array();  
                                $lsValues[0]=$laprodresult[0]['paygearproductid'];
                                $lsValues[1]=$laprodresult[0]['paygearpaymentoptionid'];
                                $lsValues[2]=$laresult[0]['firstname'];
                                $lsValues[3]=$laresult[0]['lastname']; 
                                $lsValues[4]=$laresult[0]['email']; 
                                $lsValues[5]=$laresult[0]['address1']!=null?$laresult[0]['address1']:'';
                                $lsValues[6]=$laresult[0]['city']!=null?$laresult[0]['city']:'';
                                $lsValues[7]=$laresult[0]['state']!=null?$locationobj->getCountryStateNameById($laresult[0]['state']):'';
                                $lsValues[8]=$laresult[0]['zipcode']!=null?$laresult[0]['zipcode']:'';
                                $lsValues[9]=$laresult[0]['country']!=null?$locationobj->getCountryStateNameById($laresult[0]['country']):'';  
                                $lsValues[10]=$laresult[0]['phone_main']!=null?$laresult[0]['phone_main']:'';
                                $lsValues[11]=$laresult[0]['billing_address']!=null?$laresult[0]['billing_address']:'';
                                $lsValues[12]=$laresult[0]['billing_city']!=null?$laresult[0]['billing_city']:'';  
                                $lsValues[13]=$laresult[0]['billing_state']!=null?$locationobj->getCountryStateNameById($laresult[0]['billing_state']):'';
                                $lsValues[14]=$laresult[0]['billing_zip']!=null?$laresult[0]['billing_zip']:'';
                                $lsValues[15]=$laresult[0]['billing_country']!=null?$locationobj->getCountryStateNameById($laresult[0]['billing_country']):'';  
                                $lsValues[16]=$laresult[0]['billing_phone']!=null?$laresult[0]['billing_phone']:'';
                                $lsValues[17]=$_SERVER['REMOTE_ADDR'];
                              //  $lsorderid=$PaygearWebserviceClient->AddManualOrderEntry((int)$lsValues[0],(int)$lsValues[1],$lsValues[2],
//                                                                     $lsValues[3],$lsValues[4],$lsValues[5],$lsValues[6],$lsValues[7],
//                                                                     $lsValues[8],$lsValues[9],$lsValues[10],$lsValues[11],$lsValues[12],
//                                                                     $lsValues[13],$lsValues[14],$lsValues[15],$lsValues[16],$lsValues[17]);   
//                         
//                                if($lsorderid!='' && $lsorderid!="0"  && $lsorderid!=null && $lsorderid!=false)
//                                {
//                                    
                                    /*Insert Data in prefix_product_users*/
                                     $product=new product_class();
                                     $product->deleteDuplicateTransaction($_POST['userid'],$_POST['products']);
                                     $lsValues=array(); 
                                     $lsValues[]=trim($_POST['products']);
                                     $lsValues[]=trim($_POST['userid']);   
                                     $masterclassObj =new master_class();
                                     $masterId=$masterclassObj->getMasterId("productmembershipstatus");
                                     $masterValuesId=$masterclassObj->getMasterValuesId("Active",$masterId);
                                     $lsValues[]=$masterValuesId; 
                                     $lsValues[]=$laprodresult[0]['price'];
                                     if($_POST['hdnislifetime']==1)
                                     {
                                          $lsValues[]=strtotime(date("m/d/YH:i:s")); 
                                          $lsValues[]=strtotime(date("m/d/YH:i:s")); 
                                          $lsValues[]=1;
                                     } 
                                     else
                                     {
                                          $lsValues[]=trim($_POST['hdnfromdate']);
                                          $lsValues[]=trim($_POST['hdnuptodate']); 
                                          $lsValues[]=0;
                                     
                                     }
                                      $lsValues[]=0; 
                                      $lsValues[]='N/A';
                                      $lsValues[]=null;
                                      $lsValues[]=$masterclassObj->getPaygerMastervalueId('ePaymentStatus','Completed');
                                      $lsValues[]=$masterclassObj->getPaygerMastervalueId('VendorPaymentStatus','Paid');  
                                      $lsValues[]='CC';
                                      //$lsValues[]=$lsorderid;
                                      $lsValues[]=0;  
                                      $lsValues[]=strtotime(date("Y/m/dH:i:s"));  
                                      $insetQueryTempProdUser ="insert into ".TABLE_PREFIX."product_users
                                                                (productid,userid,productmembershipstatusid,amount,fromdate, uptodate, islifetime,
                                                                paygear_etransactionid,paygear_paymentgetway,paygear_paymentgetwayresponse,
                                                                paygear_epaymentstatus,paygear_vendorpaymentstatus,paygear_paymentmethod,
                                                                paygear_orderid,paygear_paidon)
                                                                values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                                      $laprodtempinsert=$users->Insert($insetQueryTempProdUser,$lsValues,null);
                                      
                                      if($laprodtempinsert>0)
                                      {         
                                          
                                          
                                          /* update by nikunj for htacess add new user*/
                                          /*-------------------------------------------------------------------------------------------*/
                                          
                                          $objSignupclass=new users_signup_class();
                                          $prod_clss_obj=new product_class();  
                                          $objProtecfolderProtection_Class=new ProtecfolderProtection_Class(); 
                                          $larrProtectedFoldersForProduct = $objSignupclass->getProtectedFoldersForProduct($_POST['products']);
                                          $masterclassObj=new master_class();
                               
                                          $userQuery = 'SELECT username,password,secretsalt,email,firstname,lastname,isunsubscribedfromemails,isapproved FROM '.TABLE_PREFIX.'users WHERE id=?';
                                          $lsUsersValues = array(trim($_POST['userid']));
                                          $laUserData = $prod_clss_obj->View($userQuery,$lsUsersValues,null);
                                          $isunsubscribe=$laUserData[0]['isunsubscribedfromemails'];
                                          
                                          
                                          /**********************add free forduct link with main product *********************/
                                               $linkedInPro=$objProclass->getAllLinkedProductsForSpecificProduct($_POST['products']);
                                                $objUserInfo=$users->getSpecificUserInfoById($_POST['userid']);
                        
                       
                                                if($linkedInPro!="" and $linkedInPro!=null)
                                                {
                                                   
                                                     $linkedPro=explode(",",$linkedInPro);
                                                   
                                                      $postedArry=ARRAY();
                                                      $postedArry['pg_amount']='0';
                                                      $postedArry['e_txn_id']='0';
                                                      $postedArry['e_processor_name']='N/A';
                                                      $postedArry['pg_txn_stat']='1';
                                                      $postedArry['payment_type']='N/A';
                                                      $postedArry['pg_order_id']='0';
                                                      $postedArry['payment_date']=date("m/d/Y");  
                                                                
                                                       foreach($linkedPro as $linkedProId)
                                                       {
                                                           
                                                           $res=$objProclass->deleteDuplicateTransaction($_POST['userid'],$linkedProId);  
                                                           $IsActivePro=$objProclass->checkForSameActiveSubscription($_POST['userid'],$linkedProId);
                                                           if($IsActivePro!=$linkedProId)
                                                            {
                                                             //add new subscription of this pro
                                                                                  
                                                                  $results=$objProclass->GetSpecificProductPaymentOptions($linkedProId);
                                                                  
                                                                  if($results!=false)
                                                                  { 
                                                                 
                                                                         $PaymentOptionId=trim($results[0]['paygear_productpaymentoptionid']);
                                                                         
                                                                         $get_product_info=$objProclass->GetSpecificProduct(trim($linkedProId));
                                                                         $paygearProdId=$get_product_info[0]['paygear_productid'] ;
                                                                         $insertToProductUser=$usersignuupObj->insertToProductUser($linkedProId,$_POST['userid']);
                                                                         $FirstName=trim($objUserInfo[0]['firstname']);
                                                                         $LastName=trim($objUserInfo[0]['lastname']);
                                                                         $Email=trim($objUserInfo[0]['email']);
                                                                         $Address=isset($objUserInfo[0]['address1'])?trim($objUserInfo[0]['address1']):''; 
                                                                         $City=isset($objUserInfo[0]['city'])?trim($objUserInfo[0]['city']):''; 
                                                                         $State=$state;
                                                                         $ZiporPostalCode=isset($objUserInfo[0]['zipcode'])?trim($objUserInfo[0]['zipcode']):''; 
                                                                         $Country=$country;
                                                                         $Phone=isset($objUserInfo[0]['phone_main'])?trim($objUserInfo[0]['phone_main']):''; 
                                                                         $spFirstName=trim($objUserInfo[0]['firstname']);
                                                                         $spLastName=trim($objUserInfo[0]['lastname']);
                                                                         $spEmail=trim($objUserInfo[0]['email']);
                                                                         $spAddress=isset($objUserInfo[0]['billing_address'])?trim($objUserInfo[0]['billing_address']):''; 
                                                                         $spCity=isset($objUserInfo[0]['billing_city'])?trim($objUserInfo[0]['billing_city']):''; 
                                                                         $spState=$billing_state;
                                                                         $spZip=isset($_POST['zipcodeSHP'])?trim($_POST['zipcodeSHP']):''; 
                                                                         $spCountry=$billing_country;
                                                                         $spPhone=isset($objUserInfo[0]['billing_phone'])?trim($objUserInfo[0]['billing_phone']):''; 
                                                                         $IPAddress=$_SERVER['REMOTE_ADDR'];
                                                                         
                                                                         $addUserToPaygear=$objPayGear->freePorductEntry($paygearProdId,$PaymentOptionId,$FirstName,
                                                                                                     $LastName,$Email,$Address,$City,$State,
                                                                                                     $ZiporPostalCode,$Country,$Phone,$spFirstName,
                                                                                                     $spLastName,$spEmail,$spAddress,$spCity,$spState,
                                                                                                     $spZip,$spCountry,$spPhone,$IPAddress);  
                                                     
                                                                         if(strtoupper($addUserToPaygear['FreeSaleTransactionEntryResult'])==strtoupper("TRUE"))
                                                                          {   
                                                                             $usersignuupObj=new users_signup_class();
                                                                             $usersignuupObj->updateToProductUser($postedArry,$linkedProId,$_POST['userid']);
                                                                             
                                                                          }   
                                                                  
                                                                   }
                                                           
                                                            }
                                                      
                                                        }
                                                
                                                }
                                          
                                          
                                          
                                          
                                          /***********************************************************************************/
                                                                    
                                           /*       
                                             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); 
                                                               }  
                                                      }
                                                  }
                                                    */
                                                 /*-------------------------------------------------------------------------------------------*/
                                                 
                                                 
                                           //for phpBB settings
                                           
                                           $proId=$_POST['products'];
                                           if($laUserData[0]['isapproved']=="1")
                                           {
                                           
                                               if($users_signup_class->phpbbStatuscheck())
                                                  {
                                                        $phpBBProduct=phpBB_get_product_id();
                                                        mysql_select_db(MEMBERSGEAR_DB_NAME);
                                                        if($phpBBProduct==$proId)
                                                        {
                                                         
                                                          $plainpass=decrypt($laUserData[0]['password'],$laUserData[0]['secretsalt']);
                                                          phpBB_registerUser($laUserData[0]['username'],$plainpass,$laUserData[0]['email'],0);
                                                          phpBB_activate_deactivate_user($laUserData[0]['username'],0);  
                                                          mysql_select_db(MEMBERSGEAR_DB_NAME);
                                                        }
                                                  }
                                            }
                                           else
                                             {
                                                 if($users_signup_class->phpbbStatuscheck())
                                                  {
                                                        $phpBBProduct=phpBB_get_product_id();
                                                        mysql_select_db(MEMBERSGEAR_DB_NAME);
                                                        if($phpBBProduct==$proId)
                                                        {
                                                         
                                                          $plainpass=decrypt($laUserData[0]['password'],$laUserData[0]['secretsalt']);
                                                          phpBB_registerUser($laUserData[0]['username'],$plainpass,$laUserData[0]['email'],1);
                                                          phpBB_activate_deactivate_user($laUserData[0]['username'],1);
                                                          mysql_select_db(MEMBERSGEAR_DB_NAME);
                                                        }
                                                   }
                                           
                                             } 
                                          
                                          //wordpress 
                                           if($users_signup_class->wordpressStatuscheck()){
                                                     
                                                $wordpressReqquiredFile= wordpress_physical_path();
                                              
                                                if(file_exists($wordpressReqquiredFile)){
                                                             
                                                     $user_id = wordpress_username_exists( $laUserData[0]['username'] );
                                                   
                                                     if ( $user_id ) {
                                                     
                                                        $savedRoles=wordpress_get_option('membersgear_roles'); 
                                                         
                                                                 
                                                         if(array_key_exists($proId,$savedRoles)){
                                                         
                                                            $rolename=strtolower($savedRoles[$proId]);
                                                            wordpress_add_user_role($user_id,$rolename);
                                                           
                                                         }
                                                        else{
                                                        
                                                             wordpress_add_user_role($user_id,'subscriber');
                                                          
                                                        }
                                                     
                                                     }  
                                                     else{
                                                            
                                                              $isemailExist=wordpress_email_exists($laUserData[0]['email']);          
                                                              
                                                              if(!$isemailExist){
                                                               
                                                                 $plainpass=decrypt($laUserData[0]['password'],$laUserData[0]['secretsalt']);
                                                                 $createdUserId=wordpress_Register_User($laUserData[0]['username'],$plainpass,$laUserData[0]['email']);
                                                                 if($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'); 
                                                                     
                                                                     if(array_key_exists($proId,$savedRoles)){
                                                                     
                                                                        $rolename=strtolower($savedRoles[$proId]);
                                                                        wordpress_add_user_role($createdUserId,$rolename);
                                                                       
                                                                     }
                                                                    else{
                                                                        
                                                                         wordpress_add_user_role($createdUserId,'subscriber'); 
                                                                        
                                                                    }
                                                                }
                                                                
                                                              }
                                                   
                                                     }

                                                        
                                                 }         
                                                          
                                                          
                                            }   
                                          
                                           /*update by nikunj for listmailpro ******************************************************************/
                                                          if($listmailProStatus)
                                                           { 
                                                                
                                                              
                                                                $getListNum=$prod_clss_obj->getListMailPro_Value_for_product(trim($_POST['products']));
                                                                if($getListNum!=null or $getListNum!="" )
                                                                   {     
                                                                         
                                                                         if($isunsubscribe!=1)
                                                                           {
                                                                                $fname=$laUserData[0]['firstname'];
                                                                                $lname=$laUserData[0]['lastname']; 
                                                                                $email=$laUserData[0]['email'];
                                                                                listmailpro_addUserToListMailPro($getListNum,$fname,$lname,$email);
                                                                                $listopts = listmailpro_getlistopts($getListNum);
                                                                                if($listopts[2]=='1') listmailpro_remlists($email,$getListNum,2);
                                                                                if($listopts[3]=='1') listmailpro_addlists($email,$getListNum,3);                                                             
                                                                                                                             
                                                                            }            
                                                                                                                             
                                                                     }
                                                                      
                                                           
                                                           
                                                                }     
                                                                                                                             
                                            $linkid =@mysql_connect(MEMBERSGEAR_DB_HOST,MEMBERSGEAR_DB_USER,MEMBERSGEAR_DB_PASSWORD);
                                            @mysql_select_db(MEMBERSGEAR_DB_NAME, $linkid);
                                                               
                                           /*************************************************************************************************************/      
                                          /** aweber added by nikunj*****************************************************************/
                                             $prod_clss_obj=new product_class(); 
                                            if($aweberStatus)
                                             {
                                                 if($isunsubscribe!=1)
                                                  {                         
                                                        $getListName=$prod_clss_obj->getAweber_Value_for_product(trim($_POST['products']));
                                                        $fname=$laUserData[0]['firstname'];
                                                        $lname=$laUserData[0]['lastname']; 
                                                        $email=$laUserData[0]['email'];
                                                        if(function_exists('curl_exec'))  
                                                            aweber_adduserToList($email,$fname.' '.$lname,$getListName);
                                                  }   
                                              
                                             }
                                             
                                            
                                            /** imnicamail *****************************************************************/                /** aweber added by nikunj*****************************************************************/
                                             $prod_clss_obj=new product_class(); 
                                            if($imnicamailStatus)
                                             {
                                                 if($isunsubscribe!=1)
                                                  {                         
                                                        $getListName=$prod_clss_obj->getimnicamail_Value_for_product(trim($_POST['products']));
                                                        $fname=$laUserData[0]['firstname'];
                                                        $lname=$laUserData[0]['lastname']; 
                                                        $email=$laUserData[0]['email'];
                                                        if(function_exists('curl_exec'))  
                                                            imnicamail_adduserToList($email,$fname.' '.$lname,$getListName);
                                                  }   
                                              
                                             }
                                             
                                            /** imnicamail *****************************************************************/ 
                                            
                                           
                                            /* getresponse add user *****************************************************/  
                                                if($getresponseStatus)
                                                 {
                                                         if($isunsubscribe!=1)
                                                            {
                                                                $getListName=$prod_clss_obj->getGetResponse_Value_for_product(trim($_POST['products']));
                                                                $fname=$laUserData[0]['firstname'];
                                                                $lname=$laUserData[0]['lastname']; 
                                                                $email=$laUserData[0]['email'];
                                                                $apiKey=getresponse_getAPI_KEY();
                                                                if(function_exists('curl_exec')) 
                                                                     getresponse_adduserToList($email,$fname.' '.$lname,$getListName,$apiKey);
                                                            }    
                                                  
                                                 }
                                            
                                            /***************************************************************************/ 
                                             
                                            
                                           if(trim($_POST['redirect'])=='0')
                                           {
                                              $message->SetMessage('Subscription is successfully inserted.');  
                                             // Redirect("./admin_user_subscription_v.php?userid=".$_POST['userid']."");
                                              header("Location: ./admin_user_subscription_v.php?userid=".$_POST['userid']."");
                                              break;
                                           }
                                           else
                                           {
                                               $message->SetMessage('User is successfully inserted.');  
                                               Redirect('./admin_users_v.php',true); 
                                           }    
                                            
                                      }    
                                      
                                                                             
                                    
                            /*    } */  
                                
                       }
                
                
                }   
       
       break;
       
       
       case 'cancel':
             if(trim($_POST['redirect'])=='0')
               {                             
                  // $message->SetMessage('Subscription is Sucessfully Inserted');  
                   // Redirect("./admin_user_subscription_v.php?userid=".$_POST['userid']."",true);
                      header("Location: ./admin_user_subscription_v.php?userid=".$_POST['userid']."");
                    break;
               }
               else
               {   $message->SetMessage('User is successfully inserted.');  
                   Redirect('./admin_users_v.php',true); 
               }                                
               
       break;  
       case 'update':
             $lsValues=array();
             $masterclassObj =new master_class();
             $masterId=$masterclassObj->getMasterId("productmembershipstatus");
             $masterValuesId=$masterclassObj->getMasterValuesId("Active",$masterId); 
             if(trim($_POST['ddlstatus'])==$masterValuesId)
             {
                    $query="update ".TABLE_PREFIX."product_users  set productmembershipstatusid=?,paygear_paidon=?,paygear_epaymentstatus=? where id=?";
                    $lsValues[]=trim($_POST['ddlstatus']);
                    $lsValues[]=strtotime(date("Y/m/dH:i:s"));
                    $masterclassObj =new master_class();
                    $lsValues[]=$masterclassObj->getPaygerMastervalueId('ePaymentStatus','Completed'); 
                    $lsValues[]=trim($_POST['subuid']); 
                    
                     if($users_signup_class->phpbbStatuscheck())
                      {
                            $userQuery = 'SELECT productid,userid FROM '.TABLE_PREFIX.'product_users WHERE id=?';
                            $lsUsersValues = array(trim($_POST['subuid']));
                            $laUserData = $users_signup_class->View($userQuery,$lsUsersValues,null);
                            $proID=$laUserData[0]['productid'];
                          
                            $phpBBProduct=phpBB_get_product_id();
                            mysql_select_db(MEMBERSGEAR_DB_NAME);
                            if($phpBBProduct==$proID)
                            {
                               $userQuery1 = 'SELECT username FROM '.TABLE_PREFIX.'users WHERE id=?';
                               $lsUsersValues1 = array(trim($laUserData[0]['userid']));
                               $laUserData1 = $users_signup_class->View($userQuery1,$lsUsersValues1,null);
                               $user_name=$laUserData1[0]['username'];
                                         
                               phpBB_activate_deactivate_user($user_name,0);
                               mysql_select_db(MEMBERSGEAR_DB_NAME);
                            }
                      }
                      
                      if($users_signup_class->wordpressStatuscheck()){
                                                     
                            $wordpressReqquiredFile= wordpress_physical_path();
                          
                            if(file_exists($wordpressReqquiredFile)){
                                
                                           
                                $userQuery = 'SELECT productid,userid FROM '.TABLE_PREFIX.'product_users WHERE id=?';
                                $lsUsersValues = array(trim($_POST['subuid']));
                                $laUserData = $users_signup_class->View($userQuery,$lsUsersValues,null);
                                $proID=$laUserData[0]['productid'];   
                                
                                
                                $userQuery1 = 'SELECT * FROM '.TABLE_PREFIX.'users WHERE id=?';
                                $lsUsersValues1 = array(trim($laUserData[0]['userid']));
                                $laUserData1 = $users_signup_class->View($userQuery1,$lsUsersValues1,null);
                                $user_name=$laUserData1[0]['username'];
                                     
                                 $user_id = wordpress_username_exists( $user_name );  

                                 if ( $user_id ) {
                                 
                                    $savedRoles=wordpress_get_option('membersgear_roles'); 
                                     
                                             
                                     if(array_key_exists($proID,$savedRoles)){
                                     
                                        $rolename=strtolower($savedRoles[$proID]);
                                        wordpress_add_user_role($user_id,$rolename);
                                      
                                     }
                                    else{
                                    
                                         wordpress_add_user_role($user_id,'subscriber'); 
                                     
                                     }
                                 
                                 }  
                                 else{
                                        
                                         $prod_clss_obj=new product_class();
                                          $userQuery = 'SELECT username,password,secretsalt,email,firstname,lastname,isunsubscribedfromemails,isapproved FROM '.TABLE_PREFIX.'users WHERE id=?';
                                          $lsUsersValues = array(trim($_POST['userid']));
                                          $laUserData = $prod_clss_obj->View($userQuery,$lsUsersValues,null);
                                        
                                          $isemailExist=wordpress_email_exists($laUserData[0]['email']);          
                                         if(!$isemailExist){ 
                                            
                                             $plainpass=decrypt($laUserData1[0]['password'],$laUserData1[0]['secretsalt']);
                                             $createdUserId=wordpress_Register_User($laUserData1[0]['username'],$plainpass,$laUserData1[0]['email']);
                                             if($createdUserId){
                                             
                                                 wordpress_add_user_meta( $createdUserId, 'first_name', $laUserData1[0]['firstname'],false);
                                                 wordpress_add_user_meta( $createdUserId, 'last_name', $laUserData1[0]['lastname'],false);
                                                 wordpress_add_user_meta( $createdUserId, 'nickname', $laUserData1[0]['username'],false);
                                                 
                                                 $savedRoles=wordpress_get_option('membersgear_roles'); 
                                                 
                                                 if(array_key_exists($proID,$savedRoles)){
                                                 
                                                    $rolename=strtolower($savedRoles[$proID]);
                                                    wordpress_add_user_role($createdUserId,$rolename); 
                                                   
                                                 }
                                                else{
                                                                                                      
                                                     wordpress_add_user_role($createdUserId,'subscriber'); 
                                                
                                                }
                                            }
                                         }  
                               
                                  }

                                    
                             }         
                                                          
                                                            
                      }   
                      
                      
              }
              else
              {
                     $query="update ".TABLE_PREFIX."product_users  set productmembershipstatusid=? where id=?";
                     $lsValues[]=trim($_POST['ddlstatus']);
                     $lsValues[]=trim($_POST['subuid']);
                      if($users_signup_class->phpbbStatuscheck())
                      {
                            $userQuery = 'SELECT productid,userid FROM '.TABLE_PREFIX.'product_users WHERE id=?';
                            $lsUsersValues = array(trim($_POST['subuid']));
                            $laUserData = $users_signup_class->View($userQuery,$lsUsersValues,null);
                            $proID=$laUserData[0]['productid'];
                          
                            $phpBBProduct=phpBB_get_product_id();
                            mysql_select_db(MEMBERSGEAR_DB_NAME);
                            
                            if($phpBBProduct==$proID)
                            {
                               $userQuery1 = 'SELECT username FROM '.TABLE_PREFIX.'users WHERE id=?';
                               $lsUsersValues1 = array(trim($laUserData[0]['userid']));
                               $laUserData1 = $users_signup_class->View($userQuery1,$lsUsersValues1,null);
                               $user_name=$laUserData1[0]['username'];
                                
                               phpBB_activate_deactivate_user($user_name,1);
                               mysql_select_db(MEMBERSGEAR_DB_NAME);
                            }
                      }
                      
                      if($users_signup_class->wordpressStatuscheck()){
                                                     
                            $wordpressReqquiredFile= wordpress_physical_path();
                          
                            if(file_exists($wordpressReqquiredFile)){
                                
                                            
                                $userQuery = 'SELECT productid,userid FROM '.TABLE_PREFIX.'product_users WHERE id=?';
                                $lsUsersValues = array(trim($_POST['subuid']));
                                $laUserData = $users_signup_class->View($userQuery,$lsUsersValues,null);
                                $proID=$laUserData[0]['productid'];   
                                
                                
                                $userQuery1 = 'SELECT * FROM '.TABLE_PREFIX.'users WHERE id=?';
                                $lsUsersValues1 = array(trim($laUserData[0]['userid']));
                                $laUserData1 = $users_signup_class->View($userQuery1,$lsUsersValues1,null);
                                $user_name=$laUserData1[0]['username'];
                                     
                                 $user_id = wordpress_username_exists( $user_name );  

                                 if ( $user_id ) {
                                 
                                    $savedRoles=wordpress_get_option('membersgear_roles'); 
                                     
                                             
                                     if(array_key_exists($proID,$savedRoles)){
                                     
                                        $rolename=strtolower($savedRoles[$proID]);
                                        wordpress_remove_user_role($user_id,$rolename);
                                       
                                      }
                               
                                     $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($laUserData[0]['userid']);
                                     $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)){
                                            
                                               if($userSubscribedProducts[$i]['id']!= $proID){  
                                               
                                                     $rolArr[]=$wp_role[$savedRoles[$userSubscribedProducts[$i]['id']]];
                                               }
                                             }
                                          
                                          }
                                      }
                                    } 
                                    $maxRole=max($rolArr);
                                    $roleName=$wp_role_byname[$maxRole];  

                                    if($roleName!=''){

                                       wordpress_add_user_role($user_id,$roleName);
                                    
                                    }
                                       
                               
                               
                                 
                               }  
                               
                                
                                    
                           }
                                                      
                                                         
                      }
                      
                  
               }
              
         
             $laupdaterecord=$users->Update($query,$lsValues,null);
             
             $query="select productid from ".TABLE_PREFIX."product_users where id=".$_POST['subuid'];
             $laresult=$users->View($query);
             $prodid=$laresult[0]['productid'];
             
               /* update by nikunj for htacess add new user*/
                                          /*-------------------------------------------------------------------------------------------*/
                                          $objSignupclass=new users_signup_class();
                                          $objProtecfolderProtection_Class=new ProtecfolderProtection_Class(); 
                                          $larrProtectedFoldersForProduct = $objSignupclass->getProtectedFoldersForProduct($prodid);
                                          $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); 
                                                               }  
                                                      }
                                                  }
                                      
                                            */
             
           //  if($laupdaterecord>0)
             {
                  $message->SetMessage('subscription is successfully updated.');  
                  // Redirect('./admin_user_subscription_v.php',true);
                    header("Location: ./admin_user_subscription_v.php?userid=".$_POST['uid'].""); 
             }
           
       break;
       case 'delete':  

                 if($users_signup_class->phpbbStatuscheck())
                  {
                        $userQuery = 'SELECT productid,userid FROM '.TABLE_PREFIX.'product_users WHERE id=?';
                        $lsUsersValues = array(trim($_GET['id']));
                        $laUserData = $users_signup_class->View($userQuery,$lsUsersValues,null);
                        $proID=$laUserData[0]['productid'];
                      
                        $phpBBProduct=phpBB_get_product_id();
                        mysql_select_db(MEMBERSGEAR_DB_NAME);
                        
                        if($phpBBProduct==$proID)
                        {
                           $userQuery1 = 'SELECT username FROM '.TABLE_PREFIX.'users WHERE id=?';
                           $lsUsersValues1 = array(trim($laUserData[0]['userid']));
                           $laUserData1 = $users_signup_class->View($userQuery1,$lsUsersValues1,null);
                           $user_name=$laUserData1[0]['username'];
                            
                           phpBB_activate_deactivate_user($user_name,1);
                           mysql_select_db(MEMBERSGEAR_DB_NAME);
                        }
                  } 
                 
                 if($users_signup_class->wordpressStatuscheck()){
                                                             
                        $wordpressReqquiredFile= wordpress_physical_path();
                      
                        if(file_exists($wordpressReqquiredFile)){
                                     
                               
                            $userQuery = 'SELECT productid,userid FROM '.TABLE_PREFIX.'product_users WHERE id=?';
                            $lsUsersValues = array(trim($_GET['id']));
                            $laUserData = $users_signup_class->View($userQuery,$lsUsersValues,null);
                            $proID=$laUserData[0]['productid'];   
                            
                            
                            $userQuery1 = 'SELECT * FROM '.TABLE_PREFIX.'users WHERE id=?';
                            $lsUsersValues1 = array(trim($laUserData[0]['userid']));
                            $laUserData1 = $users_signup_class->View($userQuery1,$lsUsersValues1,null);
                            $user_name=$laUserData1[0]['username'];
                                 
                             $user_id = wordpress_username_exists( $user_name );  

                             if ( $user_id ) {
                             
                                $savedRoles=wordpress_get_option('membersgear_roles'); 
                                 
                                         
                                 if(array_key_exists($proID,$savedRoles)){
                                 
                                    $rolename=strtolower($savedRoles[$proID]);
                                    wordpress_remove_user_role($user_id,$rolename);
                                   
                                  }
                           
                                 $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($laUserData[0]['userid']);
                                 $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)){
                                        
                                            if($userSubscribedProducts[$i]['id']!= $proID){
                                            
                                                $rolArr[]=$wp_role[$savedRoles[$userSubscribedProducts[$i]['id']]];
                                            }
                                         }
                                      
                                      }
                                  }
                                } 
                                $maxRole=max($rolArr);
                                $roleName=$wp_role_byname[$maxRole];  

                                if($roleName!=''){

                                    wordpress_add_user_role($user_id,$roleName);
                              

                                }
                                   
                           
                           
                             
                           }  
                           
                             
                                
                       }
                                                              
                                                                 
                 }
           
              $objUserSClass=new users_class();
              $query= "SELECT   productid   FROM ".TABLE_PREFIX."product_users  where id =". $_GET['id'] ;  
             $resultProduct = $objUserSClass->View($query); 
             $productid=$resultProduct[0]['productid'];
             /*********************************************************************************************/
             $lsValues=array();
             $lsValues[]=trim($_GET['id']);
             $query="delete from ".TABLE_PREFIX."product_users  where id=?";    
             $lidelrecord=$users->delete($query,$lsValues,null);
             
                                           
             $message->SetMessage('subscription is successfully deleted.');  
             header("Location: ./admin_user_subscription_v.php?userid=".$_GET['userid'].""); 
             return $result;  
             break;
       case 'edit':
             $masterclassObj =new master_class();
             $laprodmemstatus=$masterclassObj->View('productmembershipstatus');
          //   print_r($laprodmemstatus);
             $lapdmemstatus=array();
             if(is_array($laprodmemstatus) && sizeof($laprodmemstatus)>0)
             {
                 
                 foreach($laprodmemstatus as $key=>$value)
                 {
                        $lapdmemstatus[$value['id']]=$value['value']; 
                 } 
               
                    
                 $smarty->assign('laprodmemstatus',$lapdmemstatus);
             }    
       
             $lsValues=array();
             $lsValues[]=trim($_GET['userid']);
             $lsValues[]=trim($_GET['id']); 
            
            
             //$query="select username from ".TABLE_PREFIX."users where id=?";
             $query="select tpu.productmembershipstatusid as prodmemshipid,u.username as username from ".TABLE_PREFIX."users u left join ".TABLE_PREFIX."product_users tpu on u.id=tpu.userid where tpu.userid=? and tpu.id=?";
             $laresult=$users->View($query,$lsValues,null);
             $smarty->assign('username',$laresult[0]['username']);
             $smarty->assign('prodmemsubid',$laresult[0]['prodmemshipid']);   
             $smarty->assign('subid',trim($_GET['id']));
             $smarty->assign('IsEdit','yes');
             $smarty->assign('userid',$_GET['userid']);
             $smarty->display('admin_user_subscription_manage.tpl'); 
        break;
       default:
          if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can add users')==false)
          {
                    Redirect('admin_nopermission.php',true);  
                    //break;
          }
          $userid=''; 
          if(isset($_GET['userid']) && $_GET['userid']!='')
          {
                if($_GET['userid'])
                $userid=(int)$_GET['userid'];   
          }
          else
          {
                 if(isset($_SERVER['HTTP_REFERER']))
                {
                     if(strpos($_SERVER['HTTP_REFERER'],'admin_user_subscription_v')>0)
                     {
                         Redirect('admin_user_subscription_v.php',true);         
                     }  
                     else
                     {
                        $message->SetMessage('User is successfully inserted.');   
                        Redirect('admin_users_v.php',true);   
                     } 
                }
                else
                {
                      Redirect('admin_users_v.php',true); 
                }   
            
            }           
            if($userid==0)
            {
                if(isset($_SERVER['HTTP_REFERER']))
                {  
                    if(strpos($_SERVER['HTTP_REFERER'],'admin_user_subscription_v')>0)
                     {
                         Redirect('admin_user_subscription_v.php',true);         
                     }  
                     else
                     {
                        $message->SetMessage('User is successfully inserted.');   
                        Redirect('admin_users_v.php',true);   
                     }   
                }
                else
                {
                    Redirect('admin_users_v.php',true); 
                } 
            }    
            
            /****************Code Started*************************/                  
            $lsredirect='';
            $msg='';
            if(isset($_SERVER['HTTP_REFERER']))
            {
                    if(strpos($_SERVER['HTTP_REFERER'],'admin_user_subscription_v')>0)
                    {
                          $lsredirect='0';        
                    }  
                    else
                    {
                       
                         $lsredirect='1';   
                    } 
            }
            else 
            {
                 $lsredirect='1'; 
                
            }    
              $lsresult=$usersignuup->getAlluserSubscribedProduct($userid);     
            if(is_array($lsresult) && sizeof($lsresult)>0)
            {
                   
                  $arr=$usersignuup->getProductsToSignupInMemberArea($userid);
                 $len=sizeof($arr);
                  $allProducts=array();
                  $counter=0;
                  
                  if($len>0)
                   {
                      foreach($arr as $key=>$val)
                      {
                         $specificProdcut=$objprodcalss->GetSpecificProduct($val);
                         $allProducts[$counter]=$specificProdcut[0];
                         $counter++;
                      } 
                   }
                   else
                   {
                        $msg="No Product Available for Add/ReNew Subscription";
                           
                   }    
                   
                   $productResultModifiedArray="";
         
                    if(is_array($allProducts))
                      {
                         for($i=0;$i<=sizeof($allProducts)-1;$i++)
                           {
                              $productid=$allProducts[$i]['id'];
                              $queryExpireddate="select * from ".TABLE_PREFIX."productpaymentoptions where productid=".$productid;
                              $resultOfExpiredProducts=$usersignuup->View($queryExpireddate); 
                              if($resultOfExpiredProducts[0]['duration_type']=='Exact date (mm-dd-yyyy)')
                                {
                                   $curentTimeStamp= strtotime(date("m/d/YH:i:s")); 
                                   if($resultOfExpiredProducts[0]['duration_exactdate']<$curentTimeStamp)
                                     {
                                         //unset($productResults[$i]);
                                         
                                     }
                                     else
                                      {
                                      $productResultModifiedArray[]=$allProducts[$i];  
                                      }
                                
                                }
                             else
                              {
                                $productResultModifiedArray[]=$allProducts[$i];
                              
                              }   
                             
                           
                           }   
                  
                  } 
          
                 //  $lsredirect='0';
                
            }  
            else
            {
            
                    $priceGroup=0;
                    if(isset($_GET['group']))
                        $priceGroup=$_GET['group'];
                    if(isset($priceGroup))
                       $productResultModifiedArray=$usersignuup->getProducts('Signup',$priceGroup);
                    else
                       $productResultModifiedArray=$usersignuup->getProducts('Signup');
                   // $lsredirect='1';   
                       
            }             //print_r($allProducts);
            if(!(is_array($productResultModifiedArray) && sizeof($productResultModifiedArray)>0))
            {
                 $msg="No Product Available for Add/ReNew Subscription";  
            } 
            $lsValues=array();
            $lsValues[]=trim($userid);
           $query="select username from ".TABLE_PREFIX."users where id=?";
            $laresult=$users->View($query,$lsValues,null);
          // require_once INCLUDE_DIR."/getdata_admin_user_subscription.php"; 
          // phpajax::init();          
           $smarty->assign('products',$productResultModifiedArray);
           $smarty->assign('msg',$msg);
           $smarty->assign('lsuserid',$userid);
           $smarty->assign('lsredirect',$lsredirect);
           $smarty->assign('username',$laresult[0]['username']);
           $smarty->display('admin_user_subscription_m.tpl');      
  }  
     
  
?>
Return current item: MembersGear