Location: PHPKode > projects > MembersGear > membersgear/admin/admin_product_m.php
<?php
 require_once "../config/config.php";
require_once INCLUDE_DIR."/product_class.php";
require_once INCLUDE_DIR."/cannedemail_class.php"; 
require_once INCLUDE_DIR."/users_class.php";

if($_SERVER['REQUEST_METHOD']=="GET")
        $_SESSION[SESSION_PREFIX.'page_referrer']=$_SERVER['HTTP_REFERER'];
/* update by nikunj for list mail pro setting **********************/
//$listMailProPlugin=PHYSICAL_DIR."/admin/plugins/listmailpro/plugin.php";
$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();
   
 }  
/*******************************************************************/   
 
 

/* 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 aweber setting **********************/
$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 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();
   
 }  
/*******************************************************************/   

 
$users = new users_class();
if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can view products and thankyou page tracking')==false)
{
        Redirect('admin_nopermission.php',true);  
} 
if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can manage products and thankyou page tracking')==false)
{
        Redirect('admin_nopermission.php',true);     
} 
$product=new  product_class();
$loCannedEmail = new cannedemail_class();

//$liVendorID=decrypt(PAYGEAR_USERID);   
define('CONST_IPNURL',WEB_URL."/ipn.php");
switch($_action)
{
    case 'insert':
                 
                   
                 $cate=$_POST['Categories'];
                 $len=sizeof($cate);                                             
                                
                 $strCatatgories=addslashes('<categories>');
                 
                 for($i=0;$i<$len;$i++)
                  {
                      $strCatatgories.=addslashes("<category id=")."\"".$cate[$i]."\"".addslashes('/>');
                     
                  
                  }
                  $strCatatgories.=addslashes('</categories>');
                  
                  //echo   $strCatatgories;die;
                        
                 //echo  print_r($_POST['Categories']);
                  /*****Start  Add Product in prefix_products***********/  
                
                /* update by nikunj for listmailpro integration */ 
                 if($listmailProStatus)
                 {
                   $query="insert into ".TABLE_PREFIX ."products 
                     (price,vendorid,name,
                     description,productstatusid,isallaffiliateapprovedbydefault,
                     isrequiredshippingInformation,isrequiredpersonalinformation,
                     ipnurl,ipnsecretcode,categories,displaylogooncheckoutpage,
                     IsApproved,IsDeleted,createdby,
                     createddatetime,ipaddress,islinkedwithpaygear,
                     paygear_productid,protectedurl,scop,
                     sortorder,pricegroup,
                     displayagreement,requiredanothersubscription,disallowedsubscriptions,
                     singupemail,expirationemail,singupemail_cannedemailid,expirationemail_cannedemailid,keywords,isonetimeoffer,onetimeofferproductid,paypalpagestyle,listmail_groupid,aweber_listname,getresponse_listname,imnica_listname,is_donotlink,linked_products_id)values
                     (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
                     ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; 
                 
                 }
                 else
                 { 
                     $query="insert into ".TABLE_PREFIX ."products 
                     (price,vendorid,name,
                     description,productstatusid,isallaffiliateapprovedbydefault,
                     isrequiredshippingInformation,isrequiredpersonalinformation,
                     ipnurl,ipnsecretcode,categories,displaylogooncheckoutpage,
                     IsApproved,IsDeleted,createdby,
                     createddatetime,ipaddress,islinkedwithpaygear,
                     paygear_productid,protectedurl,scop,
                     sortorder,pricegroup,                                                              
                     displayagreement,requiredanothersubscription,disallowedsubscriptions,
                     singupemail,expirationemail,singupemail_cannedemailid,expirationemail_cannedemailid,keywords,isonetimeoffer,onetimeofferproductid,paypalpagestyle,aweber_listname,getresponse_listname,imnica_listname,is_donotlink,linked_products_id)values
                     (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
                     ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; 
                 }    
                /**********************************************************************************************/
                 $liVendorID=decrypt(PAYGEAR_USERID); 
                 $lsValues = array();
                 $lsValues[]=$_POST['txtprice'];
                 $lsValues[]=$liVendorID;
                 $lsValues[]=$_POST['txttitle'];
                 $lsValues[]=$_POST['txtdesc'];
                 $lsValues[]=$_POST['rbldispprodin'];
                 if($_POST['chkallaffiliate']==1)
                 {   
                        $lsValues[]=$_POST['chkallaffiliate'];
                 }
                 else
                 {
                    $lsValues[]=0; 
                 }
                 if($_POST['chkbuyershipaddr']==1)
                 {
                    $lsValues[]=$_POST['chkbuyershipaddr'];
                 }
                 else
                 {
                     $lsValues[]=0;
                 }
                 if($_POST['chkextracontact']==1)
                 {
                    $lsValues[]=$_POST['chkextracontact'];
                 }
                 else
                 {
                     $lsValues[]=0;
                 }
                 $lsValues[]=CONST_IPNURL;//$_POST['txtipnurl'];
                 $lsValues[]=$_POST['txtipnseccode'];
                 $lsValues[]=$strCatatgories; /*Catagerories*/
                 $lsValues[]=($_POST['chkDisplayLogo']) ? 1 : 0;
              //   if($_POST['isapproved']!='')/*Is Apporoved*/ 
//                 {
//                        $lsValues[]=$_POST['isapproved'];
//                 }
//                 else
//                 {
//                       $lsValues[]=0;
//                 } 
                
                 $lsValues[]=1;
                 $lsValues[]=0; /*isdeleted*/
                 $lsValues[]= $_SESSION[SESSION_PREFIX.'Admin_UserID'];   
                 $lsValues[]=mktime(); 
                 $lsValues[]=$_SERVER['REMOTE_ADDR'];
                 $lsValues[]=$_POST['linkwithpaygear'];
                 $lsValues[]=0;/*Pay Gear Product ID*/
                
                 $prodUrl=$_POST['txtprodurl'];
                 /*$prodFile=$_POST['filename'];
                 //$prodUrl.="/$prodFile";                                             
                  //$prodUrl=$prodUrl."/".$prodFile; 
                 $prodUrl=$prodUrl;    */
                 $lsValues[]=$prodUrl;
                 
                 $lsValues[]=$_POST['ddlscope'];
                 $lsValues[]=trim($_POST['txtsortorder']);
                 $lsValues[]=trim($_POST['txtpricegpid']);
                 //$lsValues[]=$_POST['txtrenewalgp'];
                 if($_POST[chkneed_agreement]==1)
                 { 
                    $lsValues[]=$_POST[chkneed_agreement];
                 }
                 else
                 {
                    $lsValues[]=0;
                     
                 }
                 if(is_array($_POST['ddlrequire_other']))
                 {
                 
                    $lsrequiredanothersubscription=implode(',',$_POST['ddlrequire_other']);   
                 
                 }
                 else
                 {
                    $lsrequiredanothersubscription=$_POST['ddlrequire_other'];
                 } 
                 $lsValues[]=$lsrequiredanothersubscription;
                  if(is_array($_POST['prevent_if_other']))
                 {
                 
                    $lsdisallowedsubscriptions=implode(',',$_POST['prevent_if_other']);   
                 
                 }
                 else
                 {
                    $lsdisallowedsubscriptions=$_POST['prevent_if_other'];
                 } 
                 $lsValues[]=$lsdisallowedsubscriptions;
                 $lsValues[]=$_POST['chkCustomized_Signup'];
                 $lsValues[]=$_POST['chkexpnotification'];
                 
                 if($_POST['chkCustomized_Signup'] == 'CUSTOMIZEDEMAIL'  and $_POST['chkCustomized_Signup'] == 'DONOTSEND')
                 {
                        $lsValues[] = $_POST['hdnSignupTemplateID'];
                 }
                 elseif($_POST['chkCustomized_Signup'] == 'DEFAULT')
                 {
                        $templateQuery = 'SELECT id FROM '.TABLE_PREFIX.'email_templates WHERE name=\'Product signup completed\' AND productid=0';
                        $lsTemplateID = $loCannedEmail->View($templateQuery);
                        
                        $lsValues[] = $lsTemplateID[0]['id'];
                 }
                 
                 if($_POST['chkexpnotification'] == 'CUSTOMIZEDEMAIL' and $_POST['chkexpnotification'] == 'DONOTSEND')
                 {
                        $lsValues[] = $_POST['hdnExpireNotifyTemplateID'];
                 }
                 elseif($_POST['chkexpnotification'] == 'DEFAULT')
                 {
                       //Subscription expired;
                       $templateQuery = 'SELECT id FROM '.TABLE_PREFIX.'email_templates WHERE name=\'Subscription expired\' AND productid=0';
                        $lsTemplateID = $loCannedEmail->View($templateQuery);
                        
                        $lsValues[] = $lsTemplateID[0]['id'];
                 }
                 $lsValues[]=trim($_POST['txtkeyword']);
                 $lsValues[]=$_POST['isonetimeoffer']; 
                 $lsValues[]=0;  
                 $lsValues[]=$_POST['txtpaypalpagestyle'];  
                 
                 /*update by nikunj for listmail pro **************/
                  if($listmailProStatus)
                 {
                    $lsValues[]=$_POST['listmailpro'];
                 } 
                /***************************************************/ 
               
                
                /* update by nikunj for aweber */
                
                 $lsValues[]=$_POST['txtaweber'];
                
                /***************************************************/               
                
                /* update by nikunj for getresponse */
                
                 $lsValues[]=$_POST['txtgetresponse'];
                
                /***************************************************/
                
               /* update by nikunj for emnicamail */
                
                 $lsValues[]=$_POST['txtimnicamail'];
                 
                 if(isset($_POST['donotlink']))
                 $lsValues[]=1;
                else
                  $lsValues[]=0;  
                
                $formatedPrice=$_POST['txtprice'];
         
               
                if(isset($_POST['linkedinPro']) and $formatedPrice>0)
                {
                  if(is_array($_POST['linkedinPro']))
                  {
                    $strImploded= implode(',',$_POST['linkedinPro']); 
                    $lsValues[]=$strImploded;
                  }
                 else if($formatedPrice>0)
                   $lsValues[]=$_POST['linkedinPro'];  
                }
                else
                  $lsValues[]='';        
                
                /***************************************************/
                 
                 //$lsValues[]= ($_POST['chkCustomized_Signup'] == 'CUSTOMIZEDEMAIL') ? $_POST['hdnSignupTemplateID'] : '';
                 //$lsValues[]= ($_POST['chkexpnotification'] == 'CUSTOMIZEDEMAIL') ? $_POST['hdnExpireNotifyTemplateID'] : '';
                 
                 $lirecordcount=$product->Insert($query,$lsValues,null); 
                 /*****End  Add Product in prefix_products***********/
                 
                 if($lirecordcount>0)
                 {
                            $query="SELECT LAST_INSERT_ID() as id from  ".TABLE_PREFIX ."products"; 
                            $laproductid=$product->View($query);
                            if(is_array($laproductid))
                            {
                                if(sizeof($laproductid)>0)
                                {
                                    $lsValuesrenaval = array();
                                    $lsValuesrenaval[]=$laproductid[0]['id'];
                                    $lsValuesrenaval[]=$laproductid[0]['id']; 
                                    $query="update ".TABLE_PREFIX ."products set renewalgroup=? where id=?";
                                    $product->Update($query,$lsValuesrenaval,null);
                               /**************************For Store logo*************************************/                  
                                     if($_FILES['imgfile']['size'] > 0)
                                     {
                                            $fileName= $_FILES['imgfile']['name']; // image file name
                                            $ext= explode('.',$fileName);
                                            $fileType=end($ext);
                                            $ext=strchr($fileName,'.');
                                            $AllowedExtensions = array('.gif','.jpeg','.jpg','.png');
                                            if(in_array($ext,$AllowedExtensions) and strlen($fileName)>0)
                                            {
                                                $fileSize= $_FILES['imgfile']['size']; // size of the uploaded file
                                                          
                                                if($fileSize<99999999)
                                                {
                                                    $tmpName= move_uploaded_file($_FILES['imgfile']['tmp_name'],"image.img"); // name of the temporary stored file name
                                                    if($tmpName){
                                                            
                                                            $fp= fopen("image.img", "r"); // open a file handle of the temporary file
                                                            $imgContent =addslashes(fread($fp, filesize("image.img"))); // read the temp file
                                                            fclose($fp); // close the file handle
                                                            
                                                             
                                                             //echo $lsValues[11];die;
                                                            $query123 = "UPDATE ".TABLE_PREFIX."products SET logo='$imgContent' WHERE id=".$laproductid[0]['id'];
                                                            //echo $query123;die;
                                                            $res=mysql_query($query123) or die(mysql_error());                 
                                                    }
                                                    else
                                                    {
                                                            $tempMessage = 'Can\'t Read temparary image file';
                                                    }                
                                                }
                                                else
                                                {
                                                    $tempMessage = 'Too big size image upload. Please select small size image';   
                                                }
                                            }
                                            else
                                            {
                                                $tempMessage = '"File is not a image"';
                                            }
                                    }
                                    else
                                    {
                                            $tempMessage = '"Image is not select"';
                                    }
                            
                                 /*********************************************************************************************************************/   
                                 /*************************Is Link With Payger(Add Entry In Payger Product table*************************/
                                 //$liVendorID=decrypt(PAYGEAR_USERID);
                                $paygearlink=true;
                                if($_POST['linkwithpaygear']==1)
                                { 
                                     if($imgContent!=null)
                                     {
                                        $imgContent=getByteArrayformStirng($imgContent);   
                                     }    
                                    $resultpaygeraaddproduct=$PaygearWebserviceClient->AddPaygearProduct($lsValues[1],$lsValues[0],$lsValues[2],$imgContent,trim($_POST['txtkeyword']),$lsValues[3],'',
                                                                                     '',$lsValues[4],$lsValues[5],$lsValues[6],$lsValues[7],$lsValues[8],
                                                                                      $lsValues[9],'',$lsValues[11],$lsValues[12],'',$liVendorID,$lsValues[16],$lsValues[13],1,$lsValues[10],$lsValues[33]);
                                
                                }
                               
                                  /***********************End Is Link With Payger***********************************************************/    
                    
                   
                                if($resultpaygeraaddproduct!='' &&  $resultpaygeraaddproduct!=null && $resultpaygeraaddproduct!=false)
                                {
                                    $lapaygearprodupdate=array();
                                    $lapaygearprodupdate[]=$resultpaygeraaddproduct;
                                    $lapaygearprodupdate[]=$laproductid[0]['id'];
                                    $lspaygear_product_id=$laproductid[0]['id'];
                                    $query = "UPDATE ".TABLE_PREFIX."products SET paygear_productid=? WHERE id=?";
                                    $lipaygear_productid=$product->Update($query,$lapaygearprodupdate,null);
                                   // if($lipaygear_productid>0)
                                        $paygearlink=true;
                                } 
                                else
                                {
                                     if($_POST['linkwithpaygear']==1)
                                     {
                                        $paygearlink=false; 
                                     }
                                } 
                             
                                 
                               $query="insert into ".TABLE_PREFIX ."productpaymentoptions 
                                (productid,salespageurl,thankyoupageurl,price,
                                issubscription,RecurringChargePeriod,RecurringChargePeriodTypeID,RecurringTimes,
                                RecurringPrice,ProductTrialAmount,ProductTrialPeriod,ProductTrialPeriodTypeID,
                                IsTrialSubscription,ProductTrialRecurringTimes,ProductTrialRecurringPrice,IsPaypalAvailable,
                                IsAuthorizeAvailable,Is2CheckoutAvailable,IsGoogleCheckoutAvailable,IsActive,
                                IsDefault,CreatedBy,CreatedDateTime,IpAddress,IsLifeTime,duration,duration_type,duration_exactdate)
                                values
                                (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                                $lsValues = array();
                                $lsValues[0]=$laproductid[0]['id'];
                                $lsValues[1]=$_POST['txtsalepageurl'];
                               // http://www.highervalue.net/thankyou.php?productid=10&thankyoupageurl=http://www.google.com
                            
                                $lsthankyoupageurl=WEB_URL."/thankyou.php?productid=".$laproductid[0]['id']."&thankyoupageurl=".trim($_POST['txtthkpageurl']);
                               // $lsValues[2]=$_POST['txtthkpageurl'];
                                 $lsValues[2]= urlencode($lsthankyoupageurl); 
                                $lsValues[3]=$_POST['txtprice'];
                                if($_POST['chkrecurring']==1)
                                {
                                    $lsValues[4]=$_POST['chkrecurring'];
                                }    
                                else
                                {
                                   $lsValues[4]=0; 
                                }   
                                $lsValues[5]=$_POST['txtduration'];
                                $lsValues[6]=$_POST['ddlduration'];  
                                $lsValues[7]=$_POST['txtrecuuringtime'];
                                $lsValues[8]=$_POST['txtprice'];/* Recurring Price*/
                                $lsValues[9]=$_POST['txttotprice1'];
                                $lsValues[10]=$_POST['txttotduration1'];
                                $lsValues[11]=$_POST['ddltotduration1'];
                                if($_POST['txttotprice1']!='' && $_POST['ddltotduration1']!='')
                                {
                                    $lsValues[12]=1;
                                }
                                else
                                {
                                     $lsValues[12]=0; 
                                } 
                                $lsValues[13]=0; /*ProductTrialRecurringTimes*/
                                $lsValues[14]=0; /*ProductTrialRecurringPrice*/
                                $lsValues[]= ($_POST['chkIsPaypalAvailable'] != '') ? $_POST['chkIsPaypalAvailable'] : 0; /*IsPaypalAvailable */
                                $lsValues[]= ($_POST['chkIsAuthorizeAvailable'] != '') ? $_POST['chkIsAuthorizeAvailable'] : 0; /*IsAuthorizeAvailable*/
                                $lsValues[]= ($_POST['chkIs2CheckoutAvailable'] != '') ? $_POST['chkIs2CheckoutAvailable'] : 0; /*Is2CheckoutAvailable*/
                                $lsValues[]= ($_POST['chkIsGoogleCheckoutAvailable'] != '') ? $_POST['chkIsGoogleCheckoutAvailable'] : 0; /*IsGoogleCheckoutAvailable*/
                             //   if($_POST['isapproved']!='')/*Is Apporoved*/ 
//                                {
//                                        $lsValues[19]=$_POST['isapproved'];
//                                }
//                                else
//                                {
//                                        $lsValues[19]=0;
//                                }    
                                  $lsValues[19]=1;
                                //  if($_POST['isdefault']!='')/*Is default*/ 
//                                   {
//                                        $lsValues[20]=$_POST['isdefault'];
//                                   }
//                                   else
//                                   {
//                                        $lsValues[20]=0;
//                                   } 
                                 $lsValues[20]=1;/* Is default*/  
                                 $lsValues[21]=$_SESSION[SESSION_PREFIX.'Admin_UserID']; 
                                 $lsValues[22]=mktime(); 
                                $lsValues[23]=$_SERVER['REMOTE_ADDR']; 
                                $lsValues[24]=$_POST['product_lftime'];
                                if($_POST['product_lftime']=="1")
                                {
                                      $lsValues[25]=0;
                                      $lsValues[26]=0;
                                      $lsValues[27]=0;
                                      
                                } 
                                else 
                                {
                                    $lsValues[25]=$_POST['ddlliftimeduration']=='Exact date (mm-dd-yyyy)'?0:trim($_POST['txtlifetimeduration']);
                                    $lsValues[26]=$_POST['ddlliftimeduration'];
                                    $lsValues[27]=$_POST['ddlliftimeduration']=='Exact date (mm-dd-yyyy)'?strtotime(trim(str_replace('-','/',$_POST['txtlifetimeduration']))." ".date('H:i:s')):0; 
                                    
                                }    
                                $lirecordcount=$product->Insert($query,$lsValues,null); 
                                $paygearpayoptionlink=true;
                                if($lirecordcount>0)
                                {
                                    /*************************Is Link With Payger(Add Entry In Payger Productpaymentoption table*************************/
                                     if($_POST['linkwithpaygear']==1)
                                    { 
                                        $respropayop=$PaygearWebserviceClient->AddPaygearProductPaymentOptions((int)$resultpaygeraaddproduct,(double)$lsValues[3],(int)$lsValues[4],
                                                                               (int)$lsValues[5],(int)$lsValues[6],(int)$lsValues[7],(double)$lsValues[3],(double)$lsValues[9],(int)$lsValues[10],
                                                                               (int)$lsValues[11],(int)$lsValues[12],(int)$lsValues[13],(double)$lsValues[14],(int)$lsValues[19],(int)$lsValues[20],
                                                                               $lsValues[1],$lsValues[2],(int)$lsValues[15],(int)$lsValues[16],(int)$lsValues[17],(int)$lsValues[18],(int)$liVendorID,$lsValues[23]); 
                                    }
                                    if($respropayop!='' &&  $respropayop!=null && $respropayop!=false)
                                    {
                                            $lapaygearprodupdate=array();
                                            $lapaygearprodupdate[]=$respropayop;
                                            $lapaygearprodupdate[]=$laproductid[0]['id'];
                                            /* Added By Asmita On 2009/09/07  for Affiliate  commision*/
                                            
                                            $lipaygear_productpaymentoptionid_affiliateComm=$respropayop; 
                                            $query = "UPDATE ".TABLE_PREFIX."productpaymentoptions SET paygear_productpaymentoptionid=? WHERE productid=?";
                                            $lipaygear_productpaymentoptionid=$product->Update($query,$lapaygearprodupdate,null);
                                            //if($lipaygear_productpaymentoptionid>0)
                                            $paygearpayoptionlink=true;
                                            
                                            /************Code Is For Onetimeoffer payger thakyou page url update*/
                                          //  $lsvalue=array();
//                                            $lsvalue[]=trim($_POST['isonetimeoffer']);
//                                            $query="SELECT p.`paygear_productpaymentoptionid`, p.`thankyoupageurl` ,p.`productid`
//                                                        FROM ".TABLE_PREFIX."productpaymentoptions p where p.productid=?";
//                                            $laoneofferparent=$product->View($query,$lsvalue,null);
//                                            if(is_array($laoneofferparent) && sizeof($laoneofferparent)>0)
//                                            {  
//                                                $lionetimeofferpaygearprodpaymentoptionid=$laoneofferparent[0]['paygear_productpaymentoptionid'];
//                                                $lsonetimeofferthkpageurl=$laoneofferparent[0]['thankyoupageurl']; 
//                                                $lionetimeofferproductid=$laoneofferparent[0]['productid'];    
//                                                            
//                                            }  
//                                           if(IS_ENABLE_ONE_TIME_OFFER=="true" && $_POST['isonetimeoffer']!="0")
//                                           {     
//                                              
//                                               $lswebservicethkpageurl=WEB_URL."/user_onetimeoffer_signup.php?productid=".$lionetimeofferproductid;
//                                           
//                                           }   
//                                           else
//                                           {
//                                               $lswebservicethkpageurl=$lsonetimeofferthkpageurl;  
//                                           
//                                           }    
//                                            
//                                         
//                                            $lbupthkurl=$PaygearWebserviceClient->UpdateOneTimeOfferProductThankPageUrl((int)$lionetimeofferpaygearprodpaymentoptionid,$lswebservicethkpageurl);
//                                            /********************End Code*************************************/
                                    } 
                                    else
                                    {
                                         if($_POST['linkwithpaygear']==1)
                                         {
                                            $paygearpayoptionlink=false; 
                                         }
                                    }  
                                     
                                     /*************************End Payger Productpaymentoption table*************************/ 
                                }     
                        }    
                       if($paygearlink==false or $paygearpayoptionlink==false)   
                       {
                                    $lapaygearprodupdate=array();
                                    $lapaygearprodupdate[]=0;
                                    $lapaygearprodupdate[]=$laproductid[0]['id']; 
                                    $query = "UPDATE ".TABLE_PREFIX."products SET islinkedwithpaygear=? WHERE id=?"; 
                                    $liuplinkwithpaygear=$product->Update($query,$lapaygearprodupdate,null);
                       }    
                        
                    }
                    
                    $lsmessage=($paygearlink==false or $paygearpayoptionlink==false)?'Product is Inserted but not Link with paygear':'Product is Successfully Inserted';     
                    $message->SetMessage($lsmessage);
                    if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
                    {
                           /* added By Asmita for New Affiliate Commision changes*/  
                        if($_POST['linkwithpaygear']==1)
                        {     
                             $_SESSION[SESSION_PREFIX.'chkrecurring']=trim($_POST['chkrecurring']);
                             $_SESSION[SESSION_PREFIX.'paygear_productpaymentoptionid']=$lipaygear_productpaymentoptionid_affiliateComm;  
                             $_SESSION[SESSION_PREFIX.'productname']=trim($_POST['txttitle']); 
                             $_SESSION[SESSION_PREFIX.'productprice']=trim($_POST['txtprice']);
                             $_SESSION[SESSION_PREFIX.'paygear_productid']=trim($lspaygear_product_id); 
                              
                             Redirect('./admin_product_payment_option_m.php'); 
                              
                        }
                        else
                        {
                            Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);    
                            
                        }
                     //   Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
                     
                  
                    }
                    else  
                    {    /* added By Asmita for New Affiliate Commision changes*/   
                       if($_POST['linkwithpaygear']==1)
                        {
                            $_SESSION[SESSION_PREFIX.'chkrecurring']=trim($_POST['chkrecurring']);
                            $_SESSION[SESSION_PREFIX.'paygear_productpaymentoptionid']=trim($lipaygear_productpaymentoptionid_affiliateComm);
                            $_SESSION[SESSION_PREFIX.'productname']=trim($_POST['txttitle']);
                            $_SESSION[SESSION_PREFIX.'productprice']=trim($_POST['txtprice']);
                            $_SESSION[SESSION_PREFIX.'paygear_productid']=trim($lspaygear_product_id); 
                            Redirect('./admin_product_payment_option_m.php');
                           
                        }
                        else
                        {
                            Redirect('./admin_product_v.php');               
                            
                        }  
//                        Redirect('./admin_product_v.php'); 
                      
                    
                               
                    }
                 }    
                 break;
    
    case 'update':
                  
                 $liVendorID=decrypt(PAYGEAR_USERID);
                 $cate=$_POST['Categories'];
                 $len=sizeof($cate);                                             
                                
                 $strCatatgories=addslashes('<categories>');
                 
                 for($i=0;$i<$len;$i++)
                  {
                      $strCatatgories.=addslashes("<category id=")."\"".$cate[$i]."\"".addslashes('/>');
                     
                  
                  }
                  $strCatatgories.=addslashes('</categories>');
               
               
               /** update for linked product */
               
               $prodidForCheck=(int)$_POST['hdn_product_id'];
               $beforeSaveGetPro=$product->GetSpecificProduct($prodidForCheck);
               
               $priceBefore=$beforeSaveGetPro[0]['price'];
               $formatedPrice=number_format($priceBefore, 2, '.', ''); 
               if($formatedPrice=='0.00'){
               
                    $getAllMainLinkedPro=$product->getAllLinkedProductWithMainProduct();
                    if($getAllMainLinkedPro!="" and is_array($getAllMainLinkedPro)){
                      foreach($getAllMainLinkedPro as $pro){            
                             $prId=$pro['id'];
                             $proArr=explode(",",$pro['linked_products_id']) ;
                             foreach($proArr as $key=>$pr){
                              if($pr==$prodidForCheck)
                               unset($proArr[$key]);
                             }
                            if(sizeof($proArr)>0)
                              $imploededPro=implode(",",$proArr); 
                            else
                             $imploededPro="";
                             $updateQuery="update ".TABLE_PREFIX."products set linked_products_id='$imploededPro' where id=$prId";
                             $query=$product->Update($updateQuery,null,null);
                                 
                          }
                      
                     }
                    
                }
               
               
              /******************************* */
               
                
                /* update by nikunj for listmailPro ***********************************************/  
        
                $query="update  ".TABLE_PREFIX ."products set
                 price=?,vendorid=?,name=?,
                 description=?,productstatusid=?,isallaffiliateapprovedbydefault=?,
                 isrequiredshippingInformation=?,isrequiredpersonalinformation=?,
                 ipnurl=?,ipnsecretcode=?,categories=?,displaylogooncheckoutpage=?,
                 IsApproved=?,IsDeleted=?,modifiedby=?,
                 modifieddatetime=?,ipaddress=?,islinkedwithpaygear=?,
                 paygear_productid=?,protectedurl=?,scop=?,
                 sortorder=?,pricegroup=?,
                 displayagreement=?,requiredanothersubscription=?,disallowedsubscriptions=?,
                 singupemail=?,expirationemail=?,renewalgroup=?,singupemail_cannedemailid=?,expirationemail_cannedemailid=?,keywords=?,isonetimeoffer=?,onetimeofferproductid=?,paypalpagestyle=?,listmail_groupid=?,aweber_listname=?,getresponse_listname=?,imnica_listname=?,is_donotlink=?,linked_products_id=? where id=?";
         
         
                 
                 $lsValues = array();
                 $lsValues[0]=$_POST['txtprice'];
                 $lsValues[1]=$liVendorID;/*Verdoerid*/
                 $lsValues[2]=$_POST['txttitle'];
                 $lsValues[3]=$_POST['txtdesc'];
                 $lsValues[4]=$_POST['rbldispprodin'];
                 if($_POST['chkallaffiliate']==1)
                 {   
                        $lsValues[5]=$_POST['chkallaffiliate'];
                 }
                 else
                 {
                    $lsValues[5]=0; 
                 }
                 if($_POST['chkbuyershipaddr']==1)
                 {
                    $lsValues[6]=$_POST['chkbuyershipaddr'];
                 }
                 else
                 {
                     $lsValues[6]=0;
                 }
                 if($_POST['chkextracontact']==1)
                 {
                    $lsValues[7]=$_POST['chkextracontact'];
                 }
                 else
                 {
                     $lsValues[7]=0;
                 }
                 $lsValues[8]=CONST_IPNURL;//$_POST['txtipnurl'];
                 $lsValues[9]=$_POST['txtipnseccode'];
                 $lsValues[10]=$strCatatgories; /*Catagerories*/
                 
                 /******************************************************************************************************************************/
                 
                 $lsValues[11] = ($_POST['chkDisplayLogo']) ? 1 : 0;
                 
                // if($_POST['isapproved']!='')/*Is Apporoved*/ 
//                 {
//                        $lsValues[12]=$_POST['isapproved'];
//                 }
//                 else
//                 {
//                        $lsValues[12]=0;
//                 }
                 $lsValues[12]=$_POST['hdn_isapproved'];
                 if($_POST['isdeleted']!='')/*Is delteted*/ 
                 {
                        $lsValues[13]=$_POST['isdeleted'];
                 }
                 else
                 {
                        $lsValues[13]=0;
                 }    
                 $lsValues[14]= $_SESSION[SESSION_PREFIX.'Admin_UserID'];   
                 $lsValues[15]=mktime(); 
                 $lsValues[16]=$_SERVER['REMOTE_ADDR'];
                 $lsValues[17]=$_POST['linkwithpaygear'];
                 $lsValues[18]=$_POST['hdn_paygearproduct_id'];/*pay Gear Product Id*/ 
                 $prodUrl=$_POST['txtprodurl'];
                 /*$prodFile=$_POST['filename'];
               //  $prodUrl.="/$prodFile";
                 $prodUrl= $prodUrl."/".$prodFile;  */
                 $lsValues[19]=$prodUrl;
                 $lsValues[20]=$_POST['ddlscope'];
                 $lsValues[21]=trim($_POST['txtsortorder']);
                 $lsValues[22]=trim($_POST['txtpricegpid']);
                 //$lsValues[]=$_POST['txtrenewalgp'];
                 if($_POST['chkneed_agreement']==1)
                 { 
                    $lsValues[23]=$_POST['chkneed_agreement'];
                 }
                 else
                 {
                    $lsValues[23]=0;
                     
                 }
                 if(is_array($_POST['ddlrequire_other']))
                 {
                 
                    $lsrequiredanothersubscription=implode(',',$_POST['ddlrequire_other']);   
                 
                 }
                 else
                 {
                    $lsrequiredanothersubscription=$_POST['ddlrequire_other'];
                 } 
                 $lsValues[24]=$lsrequiredanothersubscription;
                  if(is_array($_POST['prevent_if_other']))
                 {
                 
                    $lsdisallowedsubscriptions=implode(',',$_POST['prevent_if_other']);   
                 
                 }
                 else
                 {
                    $lsdisallowedsubscriptions=$_POST['prevent_if_other'];
                 } 
                 $lsValues[25]=$lsdisallowedsubscriptions;
                 $lsValues[26]=$_POST['chkCustomized_Signup'];
                 $lsValues[27]=$_POST['chkexpnotification'];
                 $lsValues[28]=$_POST['ddlrenewalgp'];
                 /*
                 $lsValues[]= ($_POST['chkCustomized_Signup'] == 'CUSTOMIZEDEMAIL') ? $_POST['hdnSignupTemplateID'] : '';
                 $lsValues[]= ($_POST['chkexpnotification'] == 'CUSTOMIZEDEMAIL') ? $_POST['hdnExpireNotifyTemplateID'] : '';
                 */
                 if($_POST['chkCustomized_Signup'] == 'CUSTOMIZEDEMAIL' or $_POST['chkCustomized_Signup'] == 'DONOTSEND')
                 {
                        if($_POST['hdnSignupTemplateID'] != '')
                        {
                            $lsValues[29] = $_POST['hdnSignupTemplateID'];
                        }
                        elseif($_POST['chkCustomized_Signup'] != 'DONOTSEND')
                        {
                            $lsValues[26] = 'DEFAULT';
                            $templateQuery = 'SELECT id FROM '.TABLE_PREFIX.'email_templates WHERE name=\'Product signup completed\' AND productid=0';
                            $lsTemplateID = $loCannedEmail->View($templateQuery);
                            $lsValues[29] = $lsTemplateID[0]['id'];   
                        }
                        else
                        {
                            $lsValues[29] = '';   
                        }
                 }
                 elseif($_POST['chkCustomized_Signup'] == 'DEFAULT')
                 {
                        $templateQuery = 'SELECT id FROM '.TABLE_PREFIX.'email_templates WHERE name=\'Product signup completed\' AND productid=0';
                        $lsTemplateID = $loCannedEmail->View($templateQuery);
                        $lsValues[29] = $lsTemplateID[0]['id'];
                        
                        $templateDelQuery = 'DELETE FROM '.TABLE_PREFIX.'email_templates WHERE name=\'Product signup completed\' AND productid='.$_POST['hdn_product_id'];
                        $DeleteTemplate = $loCannedEmail->Delete($templateDelQuery);
                        
                 }
                 
                 if($_POST['chkexpnotification'] == 'CUSTOMIZEDEMAIL' or $_POST['chkexpnotification'] == 'DONOTSEND')
                 {
                     if($_POST['hdnExpireNotifyTemplateID'] != '')
                     {   
                            $lsValues[30] = $_POST['hdnExpireNotifyTemplateID'];
                     }
                     elseif($_POST['chkexpnotification'] != 'DONOTSEND')
                     {
                            $lsValues[27] = 'DEFAULT';
                            $templateQuery = 'SELECT id FROM '.TABLE_PREFIX.'email_templates WHERE name=\'Subscription expired\' AND productid=0';
                            $lsTemplateID = $loCannedEmail->View($templateQuery);
                            $lsValues[30] = $lsTemplateID[0]['id'];
                     }
                     else
                     {
                            $lsValues[30] = '';   
                     }
                 }
                 elseif($_POST['chkexpnotification'] == 'DEFAULT')
                 {
                       //Subscription expired;
                       $templateQuery = 'SELECT id FROM '.TABLE_PREFIX.'email_templates WHERE name=\'Subscription expired\' AND productid=0';
                       $lsTemplateID = $loCannedEmail->View($templateQuery);
                       $lsValues[30] = $lsTemplateID[0]['id'];
                       
                       $templateDelQuery = 'DELETE FROM '.TABLE_PREFIX.'email_templates WHERE name=\'Subscription expired\' AND productid='.$_POST['hdn_product_id'];
                       $DeleteTemplate = $loCannedEmail->Delete($templateDelQuery);
                 }
                 
                 $lsValues[31]=trim($_POST['txtkeyword']);
                 $lsValues[32]=trim($_POST['isonetimeoffer']);
                 $lsValues[33]=0;
                 $lsValues[34]=$_POST['txtpaypalpagestyle'];  
                 
                 /**** update by nikunj for listmailpro */
                 if($listmailProStatus)
                  {
                     $lsValues[35]=$_POST['listmailpro'];   
                  } 
                 else
                  $lsValues[35]='';    
                
                 /* aweber setting **********/    
                  if($_POST['txtaweber']=="" or $_POST['txtaweber']==null) 
                   $lsValues[36]=''; 
                 else
                   $lsValues[36]=trim($_POST['txtaweber']); 
                  
                /**************************************************************/  
                  
                /* getresponse settings ************************************************/ 
                 if($_POST['txtgetresponse']=="" or $_POST['txtgetresponse']==null) 
                    $lsValues[37]=''; 
                 else
                   $lsValues[37]=trim($_POST['txtgetresponse']); 
                
                /************************************************************************/
                 
                  /* imnicamail setting **********/    
                  if($_POST['txtimnicamail']=="" or $_POST['txtimnicamail']==null) 
                   $lsValues[38]=''; 
                 else
                   $lsValues[38]=trim($_POST['txtimnicamail']); 
                 
                 
                 if(isset($_POST['donotlink'])) 
                   $lsValues[39]=1; 
                 else
                   $lsValues[39]=0;
                
             
                 $formatedPrice=$_POST['txtprice'];
         
               
                if(isset($_POST['linkedinPro']) and $formatedPrice>0)
                {
                  if(is_array($_POST['linkedinPro']))
                  {
                    $strImploded= implode(',',$_POST['linkedinPro']); 
                    $lsValues[]=$strImploded;
                  }
                 else if($formatedPrice>0)
                   $lsValues[]=$_POST['linkedinPro'];  
                }
                else
                  $lsValues[]='';    
                  
                  $formatedPrice=$_POST['txtprice'];
         
               
                if(isset($_POST['linkedinPro']) and $formatedPrice>0)
                {
                  if(is_array($_POST['linkedinPro']))
                  {
                    $strImploded= implode(',',$_POST['linkedinPro']); 
                    $lsValues[40]=$strImploded;
                  }
                 else if($formatedPrice>0)
                   $lsValues[40]=$_POST['linkedinPro'];  
                }
                else
                  $lsValues[40]='';    
                     
  
                   
                  
                /**************************************************************/  
                     
                 if($listmailProStatus) 
                     $lsValues[41]=$_POST['hdn_product_id'];
                 else
                   $lsValues[41]=$_POST['hdn_product_id']; 
                
                   
                /************************************************/      
                 $lirecordcount=$product->Update($query,$lsValues,null);
                 /***************************************************************************************************/
                 /***************************************************************************************************/
                                  
                 if($_FILES['imgfile']['size'] > 0)
                 {
                        $fileName= $_FILES['imgfile']['name']; // image file name
                        $ext= explode('.',$fileName);
                        $fileType=end($ext);
                        $ext=strchr($fileName,'.');
                        $AllowedExtensions = array('.bmp','.gif','.jpeg','.jpg','.png');
                        if(in_array($ext,$AllowedExtensions) and strlen($fileName)>0)
                        {
                            $fileSize= $_FILES['imgfile']['size']; // size of the uploaded file
                                      
                            if($fileSize<99999999)
                            {
                                $tmpName= move_uploaded_file($_FILES['imgfile']['tmp_name'],"image.img"); // name of the temporary stored file name
                                if($tmpName){
                                        
                                        $fp= fopen("image.img", "r"); // open a file handle of the temporary file
                                        $imgContent =addslashes(fread($fp, filesize("image.img"))); // read the temp file
                                        fclose($fp); // close the file handle
                                        
                                         
                                         //echo $lsValues[11];die;
                                        $query123 = "UPDATE ".TABLE_PREFIX."products SET logo='$imgContent' WHERE id=".$_POST['hdn_product_id'];
                                        //echo $query123;die;
                                        $res=mysql_query($query123) or die(mysql_error());                 
                                }
                                else
                                {
                                        $tempMessage = 'Can\'t Read temparary image file';
                                }                
                            }
                            else
                            {
                                $tempMessage = 'Too big size image upload. Please select small size image';   
                            }
                        }
                        else
                        {
                            $tempMessage = '"File is not a image"';
                        }
                }
                else
                {
                    if($_FILES['imgfile']['name'] != '')
                    {    
                        $tempMessage = '"Image is not select"';
                    }
                }
                /******************************************Is Link With Payger(Update payger Product)**********************************************/
                $lbpaygearupdatelink=true;
                $lbunlinkwithpayger=true;
                 if($_POST['linkwithpaygear']==1)
                 { 
                    
                     if($imgContent!=null)
                      {
                                        
                                        $imgContent=getByteArrayformStirng($imgContent);   
                      }  
                       if($_POST['hdn_paygearproduct_id']==0 or $_POST['hdn_paygearproduct_id']==null)
                       {   
                               
                                    $respaygearupdateprod=$PaygearWebserviceClient->AddPaygearProduct($lsValues[1],$lsValues[0],$lsValues[2],$imgContent,$lsValues[31],$lsValues[3],'',
                                                                                     '',$lsValues[4],$lsValues[5],$lsValues[6],$lsValues[7],$lsValues[8],
                                                                                      $lsValues[9],'',$lsValues[11],1,'',$liVendorID,$lsValues[16],$lsValues[13],1,$lsValues[10],$lsValues[34]);
                       }
                       else
                       {
                                  $respaygearupdateprod=$PaygearWebserviceClient->UpdatePaygearProduct((int)$_POST['hdn_paygearproduct_id'],$lsValues[1],$lsValues[0],$lsValues[2],
                                                                                                         $imgContent,$lsValues[31],$lsValues[3],'','',$lsValues[4],$lsValues[5],$lsValues[6],
                                                                                                         $lsValues[7],$lsValues[8],$lsValues[9],'',$lsValues[11],$lsValues[13],
                                                                                                         $liVendorID,$lsValues[16],1,$lsValues[10],$lsValues[34]);
                       }
                     if($respaygearupdateprod!='' && $respaygearupdateprod!="0" &&  $respaygearupdateprod!=null or $respaygearupdateprod!=false)
                       {
                            $lapaygearprodupdate=array();
                            $lapaygearprodupdate[]=$respaygearupdateprod;
                            $lapaygearprodupdate[]=$_POST['hdn_product_id'];
                            $query = "UPDATE ".TABLE_PREFIX."products SET paygear_productid=? WHERE id=?";
                            $lipaygearupdateprod=$product->Update($query,$lapaygearprodupdate,null);
                            $lbpaygearupdatelink=true;
                           
                       } 
                       else
                       {
                            $lbpaygearupdatelink=false; 
                                    
                       }   
                 }
                 else
                 {
                      /* Code For Unlink Product with Paygear*/
                      if($_POST['hdn_paygearproduct_id']!='')
                       {   $lsunlinkwithpaygear=$PaygearWebserviceClient->UpdatePaygearProductStatusIsLinkedWithMemberSite((int)$_POST['hdn_paygearproduct_id'],0);
                           if($lsunlinkwithpaygear=='' &&  $lsunlinkwithpaygear=null or $lsunlinkwithpaygear=false)
                           {
                               $lbunlinkwithpayger=false;
                           }    
                       }    
                 
                 }   
               
               /******************************************Update payger Product **********************************************/  
              
                 /*****End  Add Product in prefix_products***********/ 
                // if($lirecordcount>0)
                 {   
                            $query="update  ".TABLE_PREFIX ."productpaymentoptions set 
                            salespageurl=?,thankyoupageurl=?,price=?,
                            issubscription=?,RecurringChargePeriod=?,RecurringChargePeriodTypeID=?,RecurringTimes=?,
                            RecurringPrice=?,ProductTrialAmount=?,ProductTrialPeriod=?,ProductTrialPeriodTypeID=?,
                            IsTrialSubscription=?,ProductTrialRecurringTimes=?,ProductTrialRecurringPrice=?,IsPaypalAvailable=?,
                            IsAuthorizeAvailable=?,Is2CheckoutAvailable=?,IsGoogleCheckoutAvailable=?,IsActive=?,
                            IsDefault=?,ModifiedBy=?,ModifiedDateTime=?,IpAddress=?,IsLifeTime=?,
                            duration=?,duration_type=?,duration_exactdate=? where productid=?";
                           
                            $lsValues = array();
                          //  $lsValues[]=$laproductid[0]['id'];
                            $lsValues[0]=$_POST['txtsalepageurl'];
                            //$lbonetimeofferprodparent=$product->IsParentofontimeofferproduct($_POST['hdn_product_id']);
                           // if($lbonetimeofferprodparent==true && IS_ENABLE_ONE_TIME_OFFER =='true')
//                            {
//                               $lsValues[1]=$_POST['hdn_thankyoupage_url']; 
//                               $lsonetimeofferavilabel=true;
//                            }
//                            else
//                            {  
                            $lsthankyoupageurl=WEB_URL."/thankyou.php?productid=".trim($_POST['hdn_product_id'])."&thankyoupageurl=".trim($_POST['txtthkpageurl']); 
                           // $lsValues[1]=$_POST['txtthkpageurl'];
                              //  $lsonetimeofferavilabel=false;
                          //  }
                            $lsValues[1]=urlencode($lsthankyoupageurl);    
                            $lsValues[2]=$_POST['txtprice'];
                            if($_POST['chkrecurring']==1)
                            {
                                $lsValues[3]=$_POST['chkrecurring'];
                            }    
                            else
                            {
                               $lsValues[3]=0; 
                            }   
                            $lsValues[4]=$_POST['txtduration'];
                            $lsValues[5]=$_POST['ddlduration'];  
                            $lsValues[6]=$_POST['txtrecuuringtime'];

                            $lsValues[7]=$_POST['txtprice'];/* Recurring Price*/
                            $lsValues[8]=$_POST['txttotprice1'];
                            $lsValues[9]=$_POST['txttotduration1'];
                            $lsValues[10]=$_POST['ddltotduration1'];
                            if($_POST['txttotprice1']!='' && $_POST['ddltotduration1']!='')
                            {
                                $lsValues[11]=1;
                            }
                            else
                            {
                                 $lsValues[11]=0; 
                            } 
                            $lsValues[12]=0; /*ProductTrialRecurringTimes*/
                            $lsValues[13]=0; /*ProductTrialRecurringPrice*/
                            $lsValues[14]= ($_POST['chkIsPaypalAvailable'] != '') ? $_POST['chkIsPaypalAvailable'] : 0; /*IsPaypalAvailable */
                            $lsValues[15]= ($_POST['chkIsAuthorizeAvailable'] != '') ? $_POST['chkIsAuthorizeAvailable'] : 0; /*IsAuthorizeAvailable*/
                            $lsValues[16]= ($_POST['chkIs2CheckoutAvailable'] != '') ? $_POST['chkIs2CheckoutAvailable'] : 0; /*Is2CheckoutAvailable*/
                            $lsValues[17]= ($_POST['chkIsGoogleCheckoutAvailable'] != '') ? $_POST['chkIsGoogleCheckoutAvailable'] : 0; /*IsGoogleCheckoutAvailable*/
                           // if($_POST['isapproved']!='')/*Is Active*/ 
//                             {
//                                    $lsValues[18]=$_POST['isapproved'];
//                             }
//                             else
//                             {
//                                    $lsValues[18]=0;
//                             }    
                            $lsValues[18]=$_POST['hdn_isactive'];
                            // if($_POST['isdefault']!='')/*Is Default*/ 
//                             {
//                                    $lsValues[19]=$_POST['isdefault'];
//                             }
//                             else
//                             {
//                                    $lsValues[19]=0;
//                             } 
                             $lsValues[19]=$_POST['hdn_default_value'];  
                             $lsValues[20]= $_SESSION[SESSION_PREFIX.'Admin_UserID'];   
                             $lsValues[21]=mktime(); 
                             $lsValues[22]=$_SERVER['REMOTE_ADDR'];
                             $lsValues[23]=$_POST['product_lftime'];
                             if($_POST['product_lftime']=="1")
                             {
                                      $lsValues[24]=0;
                                      $lsValues[25]=0;
                                      $lsValues[26]=0;
                                      
                             } 
                             else 
                             {
                                
                                    $lsValues[24]=$_POST['ddlliftimeduration']=='Exact date (mm-dd-yyyy)'?0:trim($_POST['txtlifetimeduration']);
                                    $lsValues[25]=$_POST['ddlliftimeduration'];
                                    $lsValues[26]=$_POST['ddlliftimeduration']=='Exact date (mm-dd-yyyy)'?strtotime(trim(str_replace('-','/',$_POST['txtlifetimeduration']))." ".date('H:i:s')):0; 
                             }    
                             $lsValues[27]=$_POST['hdn_product_id'];     
                             $lirecordcount=$product->Update($query,$lsValues,null); 
                        
                       /******************************************Is Link With Payger(Update Productpaymentoption **********************************************/
                  $lbpaygearproducoptiontlink=true;
                  if($_POST['linkwithpaygear']==1)
                  { 
                       if($_POST['paygear_productpaymentoptionid']==0 or $_POST['paygear_productpaymentoptionid']==null)
                       {   
                              $lsprodpayoptionupdate=$PaygearWebserviceClient->AddPaygearProductPaymentOptions((int)$respaygearupdateprod,(double)$lsValues[2],(int)$lsValues[3],
                                                                               (int)$lsValues[4],(int)$lsValues[5],(int)$lsValues[6],(double)$lsValues[2],(double)$lsValues[8],(int)$lsValues[9],
                                                                               (int)$lsValues[10],(int)$lsValues[11],(int)$lsValues[12],(double)$lsValues[13],1,(int)$lsValues[19],
                                                                               $lsValues[0],$lsValues[1],(int)$lsValues[14],(int)$lsValues[15],(int)$lsValues[16],(int)$lsValues[17],(int)$liVendorID,$lsValues[22]);
                       }
                       else
                       {
                                                                                                                      
                                $lsprodpayoptionupdate=$PaygearWebserviceClient->UpdatePaygearProductPaymentOptions((int)$_POST['paygear_productpaymentoptionid'],(int)$_POST['hdn_paygearproduct_id'],
                                                                                                                        (double)$lsValues[2],(int)$lsValues[3],(int)$lsValues[4],(int)$lsValues[5],(int)$lsValues[6],
                                                                                                                        (double)$lsValues[2],(double)$lsValues[8],(int)$lsValues[9],(int)$lsValues[10],
                                                                                                                        (int)$lsValues[11],(int)$lsValues[12],(double)$lsValues[13],(int)$lsValues[18],(int)$lsValues[19],
                                                                                                                         $lsValues[0],$lsValues[1],(int)$lsValues[14],(int)$lsValues[15],(int)$lsValues[16],(int)$lsValues[17],
                                                                                                                         (int)$liVendorID,$lsValues[22],true);
                                  
                               
                       }
                       if($lsprodpayoptionupdate!='' && $lsprodpayoptionupdate!="0" && $lsprodpayoptionupdate!=null && $lsprodpayoptionupdate!=false)
                       {
                           $lapaygearprodupdate=array();
                           $lapaygearprodupdate[]=$lsprodpayoptionupdate;
                           $lapaygearprodupdate[]=$_POST['hdn_product_id'];
                           $query = "UPDATE ".TABLE_PREFIX."productpaymentoptions SET paygear_productpaymentoptionid=? WHERE productid=?";
                           $liprodpayoptionupdate=$product->Update($query,$lapaygearprodupdate,null);
                           //if($liprodpayoptionupdate>0)
                                $lbpaygearproducoptiontlink=true;
                                
                              /********************Update parentIsonetimeoffer product thk yoy page*************************************/      
                             //$lsvalue=array();
//                             $lsvalue[]=trim($_POST['isonetimeoffer']);
//                             $query="SELECT p.`paygear_productpaymentoptionid`, p.`thankyoupageurl` ,p.`productid`
//                                                        FROM ".TABLE_PREFIX."productpaymentoptions p where p.productid=?";
//                             $laoneofferparent=$product->View($query,$lsvalue,null);
//                             if(is_array($laoneofferparent) && sizeof($laoneofferparent)>0)
//                             {  
//                                                $lionetimeofferpaygearprodpaymentoptionid=$laoneofferparent[0]['paygear_productpaymentoptionid'];
//                                                $lsonetimeofferthkpageurl=$laoneofferparent[0]['thankyoupageurl']; 
//                                                $lionetimeofferproductid=$laoneofferparent[0]['productid'];    
//                                                            
//                             }
//                              if(IS_ENABLE_ONE_TIME_OFFER=="true" && $_POST['isonetimeoffer']!="0")
//                              { 
//                                    $lswebservicethkpageurl=WEB_URL."/user_onetimeoffer_signup.php?productid=".$lionetimeofferproductid;  
//                              }
//                              else
//                              {
//                                  $lswebservicethkpageurl=$lsonetimeofferthkpageurl; 
//                              
//                              }              
//                             
//                             $lbupthkurl=$PaygearWebserviceClient->UpdateOneTimeOfferProductThankPageUrl((int)$lionetimeofferpaygearprodpaymentoptionid,$lswebservicethkpageurl);
                                            /********************End Code*************************************/     
                                      
                       } 
                       else
                       {
                            $lbpaygearproducoptiontlink=false; 
                                    
                       }   
                 }
                  if($lbpaygearupdatelink==false or $lbpaygearproducoptiontlink==false)   
                  {
                                    $lapaygearprodupdate=array();
                                    $lapaygearprodupdate[]=0;
                                    $lapaygearprodupdate[]=$_POST['hdn_product_id']; 
                                    $query = "UPDATE ".TABLE_PREFIX."products SET islinkedwithpaygear=? WHERE id=?"; 
                                    $liuplinkwithpaygear=$product->Update($query,$lapaygearprodupdate,null);
                  }       
               
               /******************************************Update payger Product **********************************************/    
                     if($tempMessage != '')
                     {       
                             if($lbpaygearproducoptiontlink==false or $lbpaygearupdatelink==false)
                                $message->SetMessage('Product is updated successfully but can\'t upload logo because '.$tempMessage.'and not Link with PayGear');
                             else if($lbunlinkwithpayger==false)
                                $message->SetMessage('Product is updated successfully but can\'t upload logo because '.$tempMessage.'and not Unlink with PayGear');    
                             else
                                $message->SetMessage('Product is updated successfully but can\'t upload logo because '.$tempMessage); 
                     }        
                     else
                     {        if($lbpaygearproducoptiontlink==false or $lbpaygearupdatelink==false) 
                                  $message->SetMessage('Product is updated successfully but not Link with PayGear'); 
                              else if($lbunlinkwithpayger==false)
                                $message->SetMessage('Product is updated successfully but not Unlink with PayGear');    
                              else
                                $message->SetMessage('Product is updated successfully ');
                     }
                     
                    if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
                      Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
                    else  
                    Redirect('./admin_product_v.php');  
                 }    
    
                
    break;
    case 'delete': 
            $lbdeleteprd=true;
            $lsValues=array();
            $lsValues[]= $_GET['id']; 
            $lsValues[]= 1; 
            /*Is Link With PayGear*/
           // $query="select islinkedwithpaygear from   ".TABLE_PREFIX ."products set where id=?";
            
            $query="select p.islinkedwithpaygear,p.paygear_productid,po.paygear_productpaymentoptionid from ".TABLE_PREFIX ."products p join
".TABLE_PREFIX ."productpaymentoptions po on  p.id=po.productid where p.id=? and  p.islinkedwithpaygear=?";
            $laislinkinfo=$product->View($query,$lsValues,null);
            if(is_array($laislinkinfo))
            {       
                    $lbdeleteprd=false;
                    if(sizeof($laislinkinfo)>0)
                    { 
                        $lipaygear_productid=(int)$laislinkinfo[0]['paygear_productid']; 
                        $lsproddelete=$PaygearWebserviceClient->DeletePaygearProduct($lipaygear_productid);   
                        if($lsproddelete!='' &&  $lsproddelete!=null && $lsproddelete!=false)
                        {   // $lipaygear_productpaymentoptionid=(int)$laislinkinfo[0]['paygear_productpaymentoptionid']; 
                             //$lsprodpaydelete=$PaygearWebserviceClient->DeletePaygearProductPaymentOptions($lipaygear_productpaymentoptionid);
                             //if($lsprodpaydelete!='' && $lsprodpaydelete!=null && $lsprodpaydelete!=false)
                             {
                                  $lbdeleteprd=true;
                             }    
                        }    
                    }    
                                
            } 
            if($lbdeleteprd==true)                          
            {
                $lsValues=array();
                $lsValues[]= 1;     
                $lsValues[]= $_GET['id']; 
                $query="update ".TABLE_PREFIX ."products set IsDeleted=? where id=?";
                $lsupdatedrows=$product->Update($query,$lsValues,null);;
            }
          /*  if($lipaygear_productpaymentoptionid>0)
            {
               if($lbdeleteprd==true)                          
               {
                    $lsValues=array();
                    $lsValues[]= 0;     
                    $lsValues[]= $_GET['id']; 
                    $query="update ".TABLE_PREFIX ."productpaymentoptions set paygear_productpaymentoptionid=? where productid=?";
                    $lsupdatedrows=$product->Update($query,$lsValues,null);;
               }
            }  */  
           if($lsupdatedrows>0)
           { 
              $message->SetMessage('Product is Successfully Deleted'); 
            $quest="&";
            if(isset($_GET) && !empty($_GET))
             {
                 foreach($_GET as $keyname => $value) {
                      if(strtoupper($keyname)!='ACTION')
                         $quest.=$keyname."=".$value."&";
                    }     
             
             }
             
          if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
                  Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
          else  
            Redirect("./admin_product_v.php?$quest"); 
                    
              
              
           }
         
           
           
    break;
       case 'product_import':
      $vendorid_paygear=0;
      $main_produc_array=array();
      if(isset( $_GET['vendorId']))
          $vendorid_paygear=(int)$_GET['vendorId'];
          $result=$PaygearWebserviceClient->GetPayGearAllProductsForVendor($vendorid_paygear);
          $paygear_comma_sep_ids='';
          if(is_array($result))
           {
             $allProducts_from_membersgear=$product->GetAllProduct_with_paygear_productid();
             $headerCol=explode("!@#\$%^*()",$result[0]);
             $cols=array();
             foreach($headerCol as $col)
             {
              $cols[$col]='';
             }
             for($i=1;$i<count($result);$i++)
             {
                $cols_new=array();
                $trimed=explode("!@#\$%^*()",$result[$i]);
                $j=0;
                 foreach($cols as $key=>$val)
                 {
                   $cols_new[$key]=stripslashes($trimed[$j]);
                   $j++;
                 }
                if(!array_key_exists($cols_new['ID'],$allProducts_from_membersgear)) 
                 {
                    if(strtolower(trim($cols_new['IsProhibited']))!="true" and strtolower(trim($cols_new['IsApproved']))!="false" and strtolower(trim($cols_new['IsDeleted']))!="true")
                    $main_produc_array[]=$cols_new;  
                 }
             }
           
           }
          
          //$main_produc_array=array();
          $smarty->assign('main_products',$main_produc_array); 
          $smarty->display('admin_import_products.tpl');
          
    break;  
    case 'import_posted_product' :
      
       if(isset($_POST['submit']))
        {
        
          if(is_array($_POST['chkBoxProducts']))
           {
             foreach($_POST['chkBoxProducts'] as $val)
              {
              
                    $lapaygeardatinfo=$PaygearWebserviceClient->GetProductWithPaymentOption((int)$val);
                    $plitedArr=array();
                    foreach($lapaygeardatinfo['string'] as $val)
                     {
                        $plit=explode("!@#\$%^*()",$val);
                        $plitedArr[$plit[0]]=$plit[1];
                     }
                   
                    $IsAllAffiliateApprovedByDefault=0;
                    if(strtolower(trim($plitedArr['IsAllAffiliateApprovedByDefault']))=="true")
                      $IsAllAffiliateApprovedByDefault=1;
                    
                    $IsRequiredShippingInformation=0;
                    if(strtolower(trim($plitedArr['IsRequiredShippingInformation']))=="true")
                      $IsRequiredShippingInformation=1;
                    $isrequiredpersonalinformation=0;
                    if(strtolower(trim($plitedArr['IsRequiredPersonalInformation']))=="true")
                      $isrequiredpersonalinformation=1;
                    $plitedArr['IPNUrl']=CONST_IPNURL;  
                    
                    $DisplayLogoOnCheckoutPage=0;
                     if(strtolower(trim($plitedArr['DisplayLogoOnCheckoutPage']))=="true")
                      $DisplayLogoOnCheckoutPage=1;
                    
                    $IsApproved=0; 
                    if(strtolower(trim($plitedArr['IsApproved']))=="true")
                      $IsApproved=1;  
                      
                    $IsDeleted=0;
                    if(strtolower(trim($plitedArr['IsDeleted']))=="true")
                      $IsDeleted=1;  
                    
                    $createdby= $_SESSION[SESSION_PREFIX.'Admin_UserID'];   
                    $createddatetime=mktime(); 
                    $ipaddress=$_SERVER['REMOTE_ADDR'];
                    
                     $templateQuery = 'SELECT id FROM '.TABLE_PREFIX.'email_templates WHERE name=\'Product signup completed\' AND productid=0';
                     $lsTemplateID = $loCannedEmail->View($templateQuery);
                     $templateId = $lsTemplateID[0]['id'];   
                    
                     $templateQuery = 'SELECT id FROM '.TABLE_PREFIX.'email_templates WHERE name=\'Subscription expired\' AND productid=0';
                     $lsTemplateID = $loCannedEmail->View($templateQuery);
                        
                     $expireTempId= $lsTemplateID[0]['id'];
                                
                    $query="insert into ".TABLE_PREFIX ."products 
                     (price,vendorid,name,
                     description,productstatusid,isallaffiliateapprovedbydefault,
                     isrequiredshippingInformation,isrequiredpersonalinformation,
                     ipnurl,ipnsecretcode,categories,displaylogooncheckoutpage,
                     IsApproved,IsDeleted,createdby,
                     createddatetime,ipaddress,islinkedwithpaygear,
                     paygear_productid,protectedurl,scop,
                     sortorder,pricegroup,                                                              
                     displayagreement,
                     singupemail,expirationemail,singupemail_cannedemailid,expirationemail_cannedemailid,keywords,isonetimeoffer,onetimeofferproductid,paypalpagestyle,listmail_groupid)values
                     ($plitedArr[Price],$plitedArr[VendorID],'$plitedArr[Name]','$plitedArr[Description]',$plitedArr[ProductStatusID],
                     $IsAllAffiliateApprovedByDefault,$IsRequiredShippingInformation,$isrequiredpersonalinformation,
                     '$plitedArr[IPNUrl]','$plitedArr[IPNSecretCode]','$plitedArr[Categories]',
                     $DisplayLogoOnCheckoutPage,$IsApproved,$IsDeleted,$createdby,$createddatetime,'$ipaddress',
                     -1,$plitedArr[ID],' ','Visible',999,0,0,'DEFAULT','DEFAULT',$templateId,$expireTempId,'$plitedArr[KeyWords]',0,0,
                     '$plitedArr[PaypalPageStyle]',0)";
                     
                   
                    $lirecordcount=$product->Insert($query,$lsValues,null); 
                 
                    if($lirecordcount>0)
                    {
                        $query="SELECT LAST_INSERT_ID() as id from  ".TABLE_PREFIX ."products"; 
                        $laproductid=$product->View($query);
                        if(is_array($laproductid))
                        {
                            if(sizeof($laproductid)>0)
                            {
                                $lsValuesrenaval = array();
                                $lsValuesrenaval[]=$laproductid[0]['id'];
                                $lsValuesrenaval[]=$laproductid[0]['id']; 
                                $query="update ".TABLE_PREFIX ."products set renewalgroup=? where id=?";
                                $product->Update($query,$lsValuesrenaval,null);
                                
                                    $query="insert into ".TABLE_PREFIX ."productpaymentoptions 
                                (productid,paygear_productpaymentoptionid,salespageurl,thankyoupageurl,price,
                                issubscription,RecurringChargePeriod,RecurringChargePeriodTypeID,RecurringTimes,
                                RecurringPrice,ProductTrialAmount,ProductTrialPeriod,ProductTrialPeriodTypeID,
                                IsTrialSubscription,ProductTrialRecurringTimes,ProductTrialRecurringPrice,IsPaypalAvailable,
                                IsAuthorizeAvailable,Is2CheckoutAvailable,IsGoogleCheckoutAvailable,IsActive,
                                IsDefault,CreatedBy,CreatedDateTime,IpAddress,IsLifeTime,duration,duration_type,duration_exactdate)
                                values
                                (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                                $lsValues = array();
                                $lsValues[0]=$laproductid[0]['id'];
                                $lsValues[1]=$plitedArr['ProductPaymentOptionID'];
                                $lsValues[2]=$plitedArr['SalesPageUrl'];
                                $thankYouPage=urldecode($plitedArr['ThankYouPageUrl']);
                                $position=strpos($thankYouPage,"thankyoupageurl=");
                                if($position!==FALSE)
                                  $thankYouPage=substr($thankYouPage,$position+16);
                                $lsthankyoupageurl=WEB_URL."/thankyou.php?productid=".$laproductid[0]['id']."&thankyoupageurl=".trim($thankYouPage);
                                $lsValues[3]= urlencode($lsthankyoupageurl); 
                                $lsValues[4]=$plitedArr['Price'];
                                if(strtolower(trim($plitedArr['IsSubscription'])) =="true")
                                {
                                    $lsValues[5]=1;
                                }    
                                else
                                {
                                   $lsValues[5]=0; 
                                }   
                                $lsValues[6]=$plitedArr['RecurringChargePeriod'];
                                $lsValues[7]=$plitedArr['RecurringChargePeriodTypeID'];  
                                $lsValues[8]=$plitedArr['RecurringTimes'];
                                $lsValues[9]=$plitedArr['Price'];/* Recurring Price*/
                                $lsValues[10]=$plitedArr['ProductTrialAmount'];
                                $lsValues[11]=$plitedArr['ProductTrialPeriod'];
                                $lsValues[12]=$plitedArr['ProductTrialPeriodTypeID'];
                                
                                if(strtolower(trim($plitedArr['ProductTrialAmount']))!='' && strtolower(trim($plitedArr['ProductTrialPeriodTypeID']))!='')
                                {
                                    $lsValues[13]=1;
                                }
                                else
                                {
                                     $lsValues[13]=0; 
                                } 
                                $lsValues[14]=0; /*ProductTrialRecurringTimes*/
                                $lsValues[15]=0; /*ProductTrialRecurringPrice*/
                                $lsValues[]= ($plitedArr['IsPaypalAvailable'] != '') ? 1 : 0; /*IsPaypalAvailable */
                                $lsValues[]= ($plitedArr['IsAuthorizeAvailable'] != '') ? 1: 0; /*IsAuthorizeAvailable*/
                                $lsValues[]= ($plitedArr['Is2CheckoutAvailable'] != '') ? 1 : 0; /*Is2CheckoutAvailable*/
                                $lsValues[]= ($plitedArr['IsGoogleCheckoutAvailable'] != '') ? 1 : 0; /*IsGoogleCheckoutAvailable*/
                                $lsValues[20]=1;
                                $lsValues[21]=1;/* Is default*/  
                                $lsValues[22]=$_SESSION[SESSION_PREFIX.'Admin_UserID']; 
                                $lsValues[23]=mktime(); 
                                $lsValues[24]=$_SERVER['REMOTE_ADDR']; 
                                $lsValues[25]=1;
                                $lsValues[26]=0;
                                $lsValues[27]=0;
                                $lsValues[28]=0;
                                      
                                $lirecordcount=$product->Insert($query,$lsValues,null); 
                            
                                $message->SetMessage('Selected products imported successfully.');   
 
                                Redirect("./admin_product_v.php"); 

                            }
                        }
                    }                                                                 

              }
           
           }
        
        }
    
    break;          

    case 'edit':
                 /*****************This Is Code Is for Update From PayGear****************/
                 if(trim($_POST['hdn_UpdatefromPaygear'])=="Update from Paygear")
                 {    
                     if(isset($_POST['hdn_product_id']))
                     {
                        // if($_POST['linkwithpaygear']==1)
                         {
                             
                          
                             $lapaygeardatinfo=$PaygearWebserviceClient->GetPaygearProduct((int)$_POST['hdn_paygearproduct_id']);
                             if(is_array($lapaygeardatinfo))
                             {
                                 if(sizeof($lapaygeardatinfo))
                                 {
                                    $lapaygeardatinfo=$product->GetPaygearProductinfo($lapaygeardatinfo);    
                                 }
                                 
                             }
                             $lapaygearprodpayoptiondatainfo=$PaygearWebserviceClient->GetDefaultPaymentOptionsofProduct((int)$_POST['hdn_paygearproduct_id']);
                             if(is_array($lapaygearprodpayoptiondatainfo))
                             {
                                 if(sizeof($lapaygearprodpayoptiondatainfo))
                                 {
                                    $lapaygearprodpayoptiondatainfo=$product->GetPaygearProductPaymentinfo($lapaygearprodpayoptiondatainfo);
                                 }
                             }
                             
                             $laproductdata [] =  array();
                           //  $lbonetimeofferprodparent=$product->IsParentofontimeofferproduct($_POST['hdn_product_id']); 
//                             if($lbonetimeofferprodparent==true && IS_ENABLE_ONE_TIME_OFFER =='true')
//                             {
//                           
//                              $query="select p.onetimeofferproductid,p.isonetimeoffer,p.islinkedwithpaygear, p.paygear_productid, p.protectedurl, p.scop, p.sortorder, p.pricegroup, 
//                                    p.renewalgroup,p.displayagreement,p.requiredanothersubscription,p.disallowedsubscriptions,p.singupemail,
//                                    p.expirationemail,p.singupemail_cannedemailid,p. expirationemail_cannedemailid,po.IsLifeTime,po.duration_exactdate,po.duration,po.duration_type,
//                                    po.thankyoupageurl  from ".TABLE_PREFIX ."products p  left join ".TABLE_PREFIX ."productpaymentoptions po on p.id=po.productid where p.id=".$_POST['hdn_product_id']."";
//                            }
//                            else
                           // {
                                 $query="select  p.onetimeofferproductid,p.isonetimeoffer,p.islinkedwithpaygear, p.paygear_productid, p.protectedurl, p.scop, p.sortorder, p.pricegroup, 
                                    p.renewalgroup,p.displayagreement,p.requiredanothersubscription,p.disallowedsubscriptions,p.singupemail,
                                    p.expirationemail,p.singupemail_cannedemailid,p. expirationemail_cannedemailid,po.IsLifeTime,po.duration_exactdate,po.duration,po.duration_type,aweber_listname,getresponse_listname,imnica_listname,is_donotlink  
                             
                                    from ".TABLE_PREFIX ."products p  left join ".TABLE_PREFIX ."productpaymentoptions po on p.id=po.productid where p.id=".$_POST['hdn_product_id']."";
                                
                                
                          //  } 
                             
                            $laproddata=$product->view($query);
                            $lapaygearbothdatinfo= array_merge($lapaygeardatinfo,$lapaygearprodpayoptiondatainfo,$laproddata[0]);
                            $laproductdata[0]=$lapaygearbothdatinfo ;   
                            $laproductdata[0]['updateproductid']=$_POST['hdn_product_id']; 
                           // $laproductdata[0]['paygear_productpaymentoptionid']=$_POST['paygear_productpaymentoptionid'];
                           /* $prodUrl=$laproductdata[0]['protectedurl'];
                            $substringStartAt=strrpos($prodUrl, "/");
                            $mainUrl=substr($prodUrl,0,$substringStartAt);
                            $filename=substr($prodUrl,$substringStartAt+1);
                            $laproductdata[0]['protectedurl']=$mainUrl;
                            $laproductdata[0]['filename']=$filename;  */
                            
                            $lsipnUrl=$laproductdata[0]['ipnurl'];
                           $lsipnUrlsubstringStartAt=strrpos($lsipnUrl, "/");
                           $ipnurl=substr($lsipnUrl,0,$lsipnUrlsubstringStartAt);
                           $ipnfilename=substr($lsipnUrl,$lsipnUrlsubstringStartAt+1);
                           $laproductdata[0]['ipnurl']=$ipnurl;
                           $laproductdata[0]['ipnurl1']=$ipnfilename;
                            $laproductdata[0]['islinkedwithpaygear']=1;
                            
                            
                            //print_r($laproductdata[0]);
                            //$lsexactdate=$laproductdata[0]['duration_exactdate']!=0?date("Y-m-d",$laproductdata[0]['duration_exactdate']):''; 
                            //$smarty->assign('lsupdateexactdate',$lsexactdate);  
                          
                           $lsprevpageqs=$_POST['hdn_prevpage_qs'];  
                         
                         /** code for link product check */
                           $islinkedProduct='no';
                           $proId_priceChk=(int)$_POST['hdn_product_id'];         
                             
                           $priceZeroChk=$lapaygearprodpayoptiondatainfo['price'];
                           $formatedPrice=number_format($priceZeroChk, 2, '.', ''); 
                                 
                            if($formatedPrice=='0.00'){
                                 
                                    $getAllMainLinkedPro=$product->getAllLinkedProductWithMainProduct();
                                    
                                    if($getAllMainLinkedPro!="" and is_array($getAllMainLinkedPro)){
                                      foreach($getAllMainLinkedPro as $pro){            
                                            
                                          $proArr=explode(",",$pro['linked_products_id']) ;
                                          if(in_array($proId_priceChk,$proArr)){
                                            $islinkedProduct='yes';
                                            break;   
                                          }
                                      
                                       }
                                    
                                    }
                                 }
                         
                            /**********end ***********************************************/
                            
                     
                         }         
                        
                     }
                 }
                  /*****************End Code  for Update From PayGear****************/   
                 else
                 {    
                         $lsValues = array();
                         $lsValues[]=$_GET['id'];   
                         $query="select p.*,p.id as 'Updateproductid',po.* from ".TABLE_PREFIX ."products p left join ".TABLE_PREFIX ."productpaymentoptions po on p.id=po.productid where p.id=?";
                         $laproductdata=$product->View($query,$lsValues,null);
                        /* $prodUrl=$laproductdata[0]['protectedurl'];
                         $substringStartAt=strrpos($prodUrl, "/");
                         $mainUrl=substr($prodUrl,0,$substringStartAt);
                         $filename=substr($prodUrl,$substringStartAt+1);
                         $laproductdata[0]['protectedurl']=$mainUrl;
                         $laproductdata[0]['filename']=$filename;   */
                        
                         $lsipnUrl=$laproductdata[0]['ipnurl'];
                         
                         /** code for link product check */
                         $islinkedProduct='no';
                         $proId_priceChk=(int)$_GET['id'];
                         $priceZeroChk=$laproductdata[0]['price'];
                         $formatedPrice=number_format($priceZeroChk, 2, '.', ''); 
                         
                         if($formatedPrice=='0.00'){
                         
                            $getAllMainLinkedPro=$product->getAllLinkedProductWithMainProduct();
                            
                            if($getAllMainLinkedPro!="" and is_array($getAllMainLinkedPro)){
                              foreach($getAllMainLinkedPro as $pro){            
                                    
                                  $proArr=explode(",",$pro['linked_products_id']) ;
                                  if(in_array($proId_priceChk,$proArr)){
                                    $islinkedProduct='yes';
                                    break;   
                                  }
                              
                               }
                            
                            }
                         }
                         
                         /**********end ***********************************************/
                         $lsipnUrlsubstringStartAt=strrpos($lsipnUrl, "/");
                         $ipnurl=substr($lsipnUrl,0,$lsipnUrlsubstringStartAt);
                         $ipnfilename=substr($lsipnUrl,$lsipnUrlsubstringStartAt+1); 
                         $laproductdata[0]['ipnurl']=$ipnurl;
                         $laproductdata[0]['ipnurl1']=$ipnfilename;
                        // /*For Thankyoupage Url*/
//                         $lsthankyoupageurl=substr($laproductdata[0]['thankyoupageurl'],strpos($laproductdata[0]['thankyoupageurl'],"&thankyoupageurl="));
//                         $lsthankyoupageurl=trim(substr($lsthankyoupageurl,strpos($lsthankyoupageurl,"=")+1));
//                         $laproductdata[0]['thankyoupageurl']=$lsthankyoupageurl;
                         if(isset($_SERVER['HTTP_REFERER']))
                         {
                                 if(strpos($_SERVER['HTTP_REFERER'],'?')>0)
                                 {
                                     $lsprevpageqs=substr($_SERVER['HTTP_REFERER'],strpos($_SERVER['HTTP_REFERER'],'?'));
                                     
                                     
                                 }  
                                 else
                                 {
                                    $lsprevpageqs='';
                                 } 
                         }
                        else
                        {
                           $lsprevpageqs='';  
                        } 
                                     
                                  
                 }
                 /***********update by nikunj for listmailPro */
                 if($listmailProStatus)
                 {  
                     $obj=new product_class();         
                     $prod_id=null;
                      if(isset($_POST['hdn_product_id']))
                        $prod_id=$_POST['hdn_product_id'];
                      else if(isset($_GET['id']))  
                          $prod_id=$_GET['id'];
                          
                     if($prod_id!=null)   
                     {
                        $listmailValue=$obj->getListMailPro_Value_for_product($prod_id);
                        if($listmailValue==null)
                          $listmailValue='null';
                        $smarty->assign('listmailEdit',$listmailValue);          
                     
                     }
                     
                 } 
                 
               /* update by nikunj for aweber  *************************/
               if($aweberStatus)
               {  
                      $smarty->assign('AWEBER','true');    
                   
               }
               /************************************************************/   

           /* update by nikunj for getresponse  *************************/
               if($getresponseStatus)
               {  
                      $smarty->assign('GETRESPONSE','true');    
                   
               }
               /************************************************************/   
               
               /* update by nikunj for imnicamail  *************************/
               if($imnicamailStatus)
               {  
                      $smarty->assign('IMNICAMAIL','true');    
                   
               }
               
              if($laproductdata[0]['is_donotlink']==1)
                    $smarty->assign('donotlink','true');        
              else
                  $smarty->assign('donotlink','false');        
                  
               /************************************************************/      
             
                 /*For Thankyoupage Url*/
                 $lsthankyoupageurl= urldecode($laproductdata[0]['thankyoupageurl']);
                 //print_r($laproductdata[0]);die;
                 if(strpos(" ".urldecode($laproductdata[0]['thankyoupageurl']),"&thankyoupageurl=")>0)
                 {
                    $lsthankyoupageurl=substr(urldecode($laproductdata[0]['thankyoupageurl']),strpos(urldecode($laproductdata[0]['thankyoupageurl']),"&thankyoupageurl="));
                 }
                 if(strpos(" ".$lsthankyoupageurl,"=")>0)
                 {
                    $lsthankyoupageurl=trim(substr($lsthankyoupageurl,strpos($lsthankyoupageurl,"=")+1));
                 }
                 
                 
                 
                 
                 $laproductdata[0]['thankyoupageurl']=$lsthankyoupageurl;
                 $xmlString=$laproductdata[0]['categories'];
                 $catagories=$product->GetProductCategoryIdsFromXML($xmlString);
                 $catagories=implode(',',$catagories); 
                        /* $index=0;
                         $categoriesRooot = $doc->getElementsByTagName( "categories" );
                         foreach( $categoriesRooot as $categorie )
                         {
                             $index++;
                             $category = $categorie->getElementsByTagName( "category" );
                            $categoryVal = $categorie->item(0)->nodeValue;

                         }  */ 
                         
                 $lareqanothersub=explode(',',$laproductdata[0]['requiredanothersubscription']); 
                 $ladisallowsub=explode(',',$laproductdata[0]['disallowedsubscriptions']);
                //$laallProduct=$product->GetAllProduct();
                 if($laproductdata[0]['duration_exactdate']!=0)
                    $lsexactdate=$laproductdata[0]['duration_exactdate']!=0?date("m-d-Y",$laproductdata[0]['duration_exactdate']):''; 
                else
                    $lsexactdate=$laproductdata[0]['duration'];
                $smarty->assign('lsupdateexactdate',$lsexactdate);  
                /*code is Chaged by Asmita for renewalgroup proper product*/
                $laallProduct=$product->GetUserProduct();
                // $laallProduct=$product->GetAllProduct();
              
                foreach($laproductdata[0] as $key=>$value)
                {
                
                    $laproductdata[0][$key]=stripslashes($laproductdata[0][$key]);
                } 
                //print_r($laproductdata);
                
                $isMainUpsellProduct=false;
                $isMainUpsellProduct=$product->isMainUpsellProduct((int)$_GET['id']);
                
                if(!is_array($isMainUpsellProduct) )
                  $smarty->assign('isMainUpsellProduct','false'); 
                else
                  $smarty->assign('isMainUpsellProduct','true');  
                  
                $smarty->assign('lsprevpageqs',$lsprevpageqs);
                $smarty->assign('prodCate',$catagories);
                $smarty->assign(productarry,$laallProduct);      
                $smarty->assign('islinkedProduct',$islinkedProduct);      
                $smarty->assign(productdata,$laproductdata);
                $smarty->assign(reqanothersub,$lareqanothersub);
                $smarty->assign(disallowsub,$ladisallowsub);
                $smarty->assign('IsEdit','yes');
                
                $linkedinedit=explode(',',$laproductdata[0]['linked_products_id']);
                
                
                
                $smarty->assign('linkedinedit',$linkedinedit);
              
                 //$smarty->assign('productid',$_GET['id'])
                 
     default:
    
             
            $ladurationarray=array(1=>"Days",
                                2=>"Months",
                               );
            $latotalduration1array=array(1=>"Days",
                                2=>"Months"
                               );
                                
            $lalifttimeduration=array(1=>"Days",
                                      2=>"Months",
                                      3=>"Years", 
                                      4=>"Exact date (mm-dd-yyyy)");
                                                            
            
    
                                
            /*$lascope=array("Visible"=>"Visible for all",
                         "Disabled"=>"Disabled (hidden both on signup.php and member.php)",
                         "Signup"=>"Only Signup (hide from member.php page)",
                         "Member"=>"Only Members having completed subscriptions (hide from signup page)");*/
            
            $lascope=array("Visible"=>"Visible to all",
                         "Disabled"=>"Disable on both user_signup.php & user_default_page.php",
                         "Signup"=>"Only Signup, disable on user_default.php only",
                         "Member"=>"Only current members, disable on user_signup.php only");           
            $laLinkpaygear=array(1=>"Yes",0=>"No");                               
                         
                      
            $larquire_other_subscription=$product->FillRequireanothersubscription();      
            $laprevent_if_other_subscription=$product->FillDisallowsubscription();


            $laExpire_Notifications=array("DEFAULT"=>"Use MembersGear default settings",
                                          "DONOTSEND"=>"Do not send Email expiration notices for this product despite global settings",
                                           "CUSTOMIZEDEMAIL"=>"Do send Email expiration notices for this product despite global settings");

            $laCustomized_Signup=array("DEFAULT"=>"Use MembersGear default settings",
                                       "DONOTSEND"=>"Do not send Email notices for this product despite global settings",
                                        "CUSTOMIZEDEMAIL"=>"Do send Email notices for this product despite global settings");

             $laisonetimeoffer=array(1=>"Yes",0=>"No"); 
             $smarty->assign('laisonetimeoffer',$laisonetimeoffer);
             if(isset($_GET['id']))
             {
                $laproductforonetimeoffer=$product->GetAllProductForOnetimeoffer(trim($_GET['id']));
             }
             else
             {
                 $laproductforonetimeoffer=$product->GetAllProductForOnetimeoffer(); 
             }    
             
            if(isset($_GET['id']))
             {
               
                $editProId=(int)$_GET['id'];
                $LinkedInProducts=$product->getLinkdInProducts("Visible","0",$editProId);
             }
            else if(isset($_POST['hdn_product_id'])){
                 $editProId=(int)$_POST['hdn_product_id'];
                 $LinkedInProducts=$product->getLinkdInProducts("Visible","0",$editProId);
             }
            else
              $LinkedInProducts=$product->getLinkdInProducts(); 
             
             $smarty->assign('linkedin',$LinkedInProducts);
             $smarty->assign(laproductforonetimeoffer,$laproductforonetimeoffer);
             $smarty->assign(lalifttimeduration,$lalifttimeduration);                         
             $smarty->assign(durationarry,$ladurationarray); 
             $smarty->assign(totalduration1array,$latotalduration1array); 
             $smarty->assign(scope,$lascope);
             $smarty->assign(linkwithpaygear,$laLinkpaygear);
             $smarty->assign(require_other,$larquire_other_subscription);
             $smarty->assign(prevent_if_other,$laprevent_if_other_subscription);
             $smarty->assign(Expire_Notifications,$laExpire_Notifications);
             $smarty->assign(Customized_Signup,$laCustomized_Signup);
             $result=$PaygearWebserviceClient->ViewMasterValue('ProductStatus');
             $ladisplaymarketplace= array();
             if(is_array($result))
             {
                 if(sizeof($result)>0)
                 {
                     foreach($result as $key=>$value)
                     {
                        
                         if($key==3)
                            $ladisplaymarketplace[$key]="Disable this product";
                         elseif($key==2)
                             $ladisplaymarketplace[$key]="Do not show in market place"; 
                          elseif($key==1)
                             $ladisplaymarketplace[$key]="Show in marketplace only after 1 sale has been made";
                         
                     } 
                 }
             }
             else
             {
               
               
               $ladisplaymarketplace[3]="Disable this product";
               $ladisplaymarketplace[2]="Do not show in market place";                         
               $ladisplaymarketplace[1]="Show in marketplace only after 1 sale has been made";
             }   
             
            
            
             $smarty->assign(displaymarketplace,$ladisplaymarketplace);   
             
             $lsWebServiceData = $PaygearWebserviceClient->AvailablePaymentProcessors(decrypt(PAYGEAR_USERNAME));
             
            // print_r($lsWebServiceData);
             if(is_array($lsWebServiceData))
             {  
                $smarty->assign(IsPaypalAvailable,$lsWebServiceData['IsPaypalAvailable']);
                $smarty->assign(IsGoogleCheckoutAvailable,$lsWebServiceData['IsGoogleCheckoutAvailable']);
                $smarty->assign(Is2CheckoutAvailable,$lsWebServiceData['Is2CheckoutAvailable']);
                $smarty->assign(IsAuthorizeDotNetAvailable,$lsWebServiceData['IsAuthorizeDotNetAvailable']);
             }
             
              
           /* update by nikunj for listmail pro *************************/
           if($listmailProStatus)
           {  
            
                $listMailProResult= listmailpro_get_all_list_mailpro_lists();
                $smarty->assign('LIST_MAIL_PRO','true');
                 $smarty->assign('listMailProResult',$listMailProResult);    
               
           }
           /************************************************************/
           
           /* update by nikunj for aweber  *************************/
           if($aweberStatus)
           {  
            
              $smarty->assign('AWEBER','true');    
               
           }
           /************************************************************/      
           
          /* update by nikunj for getresponse  *************************/
               if($getresponseStatus)
               {  
                      $smarty->assign('GETRESPONSE','true');    
                   
               }
           /************************************************************/           
          
             /* update by nikunj for imnicamail  *************************/
               if($imnicamailStatus)
               {  
                      $smarty->assign('IMNICAMAIL','true');    
                   
               }
               /************************************************************/    
               
            $smarty->display('admin_product_m.tpl');
}
?>
Return current item: MembersGear