Location: PHPKode > projects > MembersGear > membersgear/member/affiliateSettings.php
<?php
   require_once "../config/config.php";
   require_once INCLUDE_DIR."/users_class.php";   
   require_once INCLUDE_DIR."/product_class.php";
   $loProductClass = new product_class();  
   $users=new users_class(); 

   $PaygearWebserviceClient=new PaygearWebserviceClient();
            
    if(isset($_POST['btnsubmit']))
     {
        if(isset($_POST['vendor']) and isset($_POST['productPaymentOption']) and isset($_POST['product_users_affiliate_id']) )
         {
             
           $vendor=trim($_POST['vendor']);  
           $productPaymentOption=$_POST['productPaymentOption'] ;
           $paygearVendor=$PaygearWebserviceClient->getPaygearAffiliate($vendor);
           $paygearVendor=$paygearVendor['GetUserIdByUserNameResult'];
           $product_users_affiliate_id=$_POST['product_users_affiliate_id'];
           if($paygearVendor>0)
           {
                  $urlAffiliateLink=$PaygearWebserviceClient->getPaygearAffiliateLink($productPaymentOption,$vendor);  
                  $urlAffiliateLink=$urlAffiliateLink['GetAffiliateCampaignLinkResult'];
                  
                  
                   
                  if($urlAffiliateLink==false)
                   {
                     $message->SetMessage('No such user found at PayGear.com. Please enter valid username.');
                     redirect($_SERVER['HTTP_REFERER']) ;
                   } 
                  else
                   {
                     $isactive=1;  
                     $link=urlencode($urlAffiliateLink);
                     $query="update ".TABLE_PREFIX."product_users_affiliate set paygear_campaign_link='$link', 
                              isactive=$isactive where id=$product_users_affiliate_id ";
                              
                     $update=$users->Update($query,false,false);
                     redirect("affiliateSettings.php");   
                   }
             
              }
             else
              {
                   $message->SetMessage('No such user found at PayGear.com. Please enter valid username.'); 
                   redirect("affiliateSettings.php");
               }
                 
         
         }   
         
         
         
     }
   else
     {
        
         $query_for_product = 
         "SELECT *
        FROM (
        SELECT p.id, p.name, pu.paygear_paidon,pu.id as product_user_id
        FROM  ".TABLE_PREFIX."products p
        JOIN ".TABLE_PREFIX."product_users pu ON pu.productid = p.id
        LEFT JOIN ".TABLE_PREFIX."productupsells pus ON pus.mainproductid != p.id
        WHERE ifnull( pu.paygear_paidon, 0 ) !=0 and pu.userid =".  $_SESSION[SESSION_PREFIX."UserID"]."
        LIMIT 1
        UNION
        SELECT p.id, p.name, pu.paygear_paidon,pu.id as product_user_id
        FROM  ".TABLE_PREFIX."products p
        JOIN ".TABLE_PREFIX."product_users pu ON pu.productid = p.id
        LEFT JOIN ".TABLE_PREFIX."productupsells pus ON pus.mainproductid = p.id
        WHERE ifnull( pu.paygear_paidon, 0 ) !=0 and pu.userid =". $_SESSION[SESSION_PREFIX."UserID"]."
        LIMIT 1
        )t
        ORDER BY t.paygear_paidon ASC
        LIMIT 1" ;
        
        $liProductRsult = $loProductClass->View($query_for_product,null,null); 
         
        $productId=$liProductRsult[0]['id']; 
        
        $affiliateSettings=$users->getAffiliateSettings_inactive($_SESSION[SESSION_PREFIX."UserID"]); 
        if($productId!=false and $productId!="" and $productId!=null)
        {
            $query = 'SELECT paygear_productpaymentoptionid FROM '.TABLE_PREFIX.'productpaymentoptions WHERE productid='.$productId;
            $liProductPaymentOptionID = $loProductClass->View($query,null,null);
            $liProductPaymentOptionID=$liProductPaymentOptionID[0]['paygear_productpaymentoptionid'];
            $datetime=mktime();
            $isactive=0;
            $ip=$_SERVER['REMOTE_ADDR'];
            $proUserId=$liProductRsult[0][product_user_id];
           
           if(is_array($affiliateSettings))
           {
             $lastInsertedId=$affiliateSettings[0]['id'];
            
           }
          else
           {
           
             $query="insert into ".TABLE_PREFIX."product_users_affiliate(`product_users_id`,`isactive`,`createdon`,`ipaddress`)
                     values($proUserId,$isactive,$datetime,'$ip')";
             $users->Insert($query,false,false);
             $lastInsertedId=$mdb2->lastInsertId(TABLE_PREFIX."product_users_affiliate", 'id');           
           } 
            $smarty->assign('product_users_affiliate_id',$lastInsertedId); 
            $smarty->assign('productId',     $productId);    
            $smarty->assign('productPaymentOption',     $liProductPaymentOptionID);    
            $smarty->assign('product_user_id',     $liProductRsult[0]['product_user_id']);    
                
            
        }
       else
           $smarty->assign('msgErr','No product subscription found.');     
      
       
        $affiliateSettings=$users->getAffiliateSettings($_SESSION[SESSION_PREFIX."UserID"]); 
        if(is_array($affiliateSettings))
         {
           $smarty->assign('affiliate_text','Your Affiliate Link');     
           $smarty->assign('is_activated_affiliate','yes'); 
           $referalUrl="<a href='".WEB_URL."/?thankyou-page=".$lastInsertedId ."' target='_blank' >".WEB_URL."/?thankyou-page=".$lastInsertedId."</a>";
           $smarty->assign('affiliateSettings',$referalUrl); 
               
         }
        else
        {
          $smarty->assign('affiliate_text','Become An Affiliate');     
          $smarty->assign('is_activated_affiliate','no');     
        }  
         $lsmsg=$message->GetMessage();
         $smarty->assign('msg',     $lsmsg); 
        $affiliate_page = $smarty->fetch('make_affiliate.tpl');
        $smarty->assign('USER_CONTENT',     $affiliate_page); 
        $smarty->display('user_page_main.tpl'); 

     }  
?>
Return current item: MembersGear