Location: PHPKode > projects > MembersGear > membersgear/includes/import_class.php
<?php
 //echo date("Y-m-d",1243728000)  ;echo strtotime("2009-05-26"); die;   
 require_once "peardb_class.php"; 
 require_once INCLUDE_DIR."/location_class.php";
 require_once INCLUDE_DIR."/product_class.php";
 require_once INCLUDE_DIR."/master_class.php"; 
  
 class import_class extends peardb_class
 {   
          function CSVImport($csv_path,$pUserTableFields,$pUserFieldsIndex,$pTempProductFields,$pTempProductFieldsIndex,$pFieldSeparator) 
          {          
                    $loLocationClass = new location_class(); 
                    
                    $filename = $csv_path;
                    $handle = fopen($filename, "r");
                    $contents = fread($handle, filesize($filename));
                    fclose($handle);

                    $larrContents  =  explode("\n",$contents);
                    
                    $lsSeparatorInCsvFile = $pFieldSeparator;

                    //pass database field for update or insert of user table                                
                    $lsPrefix_Database_Fields = $pUserTableFields;//array('username','password','email','city');

                    //specify the fields index of csv file to read
                    $larrReadColumns = $pUserFieldsIndex;//array(1,2,1,2);
                    
                    $larrFileLine = '';
                    
                    $totalCsvColumns = 0;
                    
                    foreach($larrContents as $key=>$rowValue)
                    {
                        if($key != 0)   
                        {
                            $rowValue = str_replace("\"","",$rowValue);
                            $larrRow = explode($lsSeparatorInCsvFile, $rowValue);
                            if($larrRow[0] != '')
                            {
                                    
                                    
                                        //$lsInsertQuery = 'insert into '.TABLE_PREFIX.'users('; 
                                        $lsInsertQuery = ''; 
                                        
                                       // loop for insert field
                                        //foreach($larrReadColumns as $columnKey =>$columnValue)
                                        //{
                                            //$lsInsertQuery .= '`'.$lsPrefix_Database_Fields[$columnKey].'`,';
                                            
                                            if($totalCsvColumns == 0) {
                                                
                                                $totalCsvColumns = count($larrRow);
                                                
                                            }else{
                                                if($totalCsvColumns != count($larrRow)) {
                                                    $arrFalseResult = array(false,false);
                                                    return $arrFalseResult;
                                                }else{
                                                    //echo "\$totalCsvColumns=>$totalCsvColumns,count(\$larrRow)=".count($larrRow)."<br />";
                                                    
                                                }
                                                
                                            }
                                            
                                        //}

                                        //$lsInsertQuery = substr($lsInsertQuery,0,strlen($lsInsertQuery)-1).") values (";
                                        
                                       // loop for insert value
                                        foreach($larrReadColumns as $readcolKey=>$readcolValue)
                                        {
                                            
                                            if(is_int($rowValue))
                                            {
                                                        $lsInsertQuery .= ($larrRow[$readcolValue-1] != '') ? $larrRow[$readcolValue-1] : 0;
                                                        $lsInsertQuery .= ",";
                                            }
                                            else
                                            {
                                                   if(strlen($readcolValue) > 2)
                                                   //if($readcolValue > 0)
                                                   {
                                                            //$lsInsertQuery .= "'"; 
                                                            $lsInsertQuery .= ($readcolValue != '') ? $readcolValue  : ' '; 
                                                            $lsInsertQuery .= ",";
                                                   }
                                                   else     
                                                   {     
                                                            if($readcolKey == "createdon" or $readcolKey == "modifiedon")
                                                            {
                                                                   $larrRow[$readcolValue-1] = strtotime($larrRow[$readcolValue-1]);
                                                            }
                                                            
                                                           if(is_int($rowValue))
                                                           {
                                                                $lsInsertQuery .= ($larrRow[$readcolValue-1] != '') ? $larrRow[$readcolValue-1] : 0;
                                                                $lsInsertQuery .= ",";
                                                           }
                                                            else
                                                            {
                                                                /*
                                                                if($readcolKey == "isapproved" or $readcolKey == "islockedout" or $readcolKey == "isunsubscribedfromemails")
                                                                {
                                                                    $quote = "";   
                                                                }
                                                                else
                                                                {
                                                                    $quote = "'";   
                                                                }
                                                                $lsInsertQuery .= $quote; 
                                                                //*/
                                                                if($readcolKey == "country" or $readcolKey == "state" or $readcolKey == "billing_country" or $readcolKey == "billing_state")
                                                                {
                                                                    if($readcolKey == 'state' or $readcolKey == 'billing_state')
                                                                    {
                                                                            $larrRow[$readcolValue-1] = $loLocationClass->getCountryStateIDByName($larrRow[$readcolValue-1],$countryCode);                                             
                                                                            $countryCode = 0;                                                                                                               
                                                                    }
                                                                    else
                                                                    {
                                                                            $larrRow[$readcolValue-1] = $loLocationClass->getCountryStateIDByName($larrRow[$readcolValue-1]);
                                                                            $countryCode = $larrRow[$readcolValue-1];
                                                                    }     
                                                                    
                                                                }
                                                                $lsInsertQuery .= ($larrRow[$readcolValue-1] != '') ? $larrRow[$readcolValue-1]  : (($readcolKey == "isapproved" or $readcolKey == "islockedout" or $readcolKey == "isunsubscribedfromemails" or $readcolKey == "country" or $readcolKey == "state" or $readcolKey == "billing_country" or $readcolKey == "billing_state") ? 0 : ' ');
                                                                $lsInsertQuery .= ",";
                                                                //$lsInsertQuery .= $quote.",";    
                                                            }    
                                                   }     
                                            }
                                        }            
                                        //$lsInsertQuery = substr($lsInsertQuery,0,strlen($lsInsertQuery)-1).");";
                                        $lsInsertQuery = substr($lsInsertQuery,0,strlen($lsInsertQuery)-1);
                                        if($lsInsertQuery != '')
                                        {
                                            $lsUserTableQuery[] .= $lsInsertQuery."|";
                                        }
                                        //write mysql code to execute this query
                                    
                            }
                        }
                    }    
                   // print_r($lsUserTableQuery); die;
                    //echo "<br/>".$lsUserTableQuery; 
                    /***************************************************************************************/
                    
                    //pass database field for update or insert of user table                                
                    $lsPrefix_Database_Fields = $pTempProductFields;//array('username','password','email','city');

                    //specify the fields index of csv file to read
                    $larrReadColumns = $pTempProductFieldsIndex;//array(1,2,1,2);

                    $lsProductTempTableQuery = '';
                   
                   /******************************* for temp_product_user table ***********************************/
                    
                    foreach($larrContents as $key=>$rowValue)
                    {
                        if($key != 0)   
                        {
                            $rowValue = str_replace("\"","",$rowValue);
                            $larrRow = explode($lsSeparatorInCsvFile, $rowValue);
                            
                            if($larrRow[0] != '')
                            {
                                    
                                       //$lsInsertQuery = 'insert into '.TABLE_PREFIX.'product_users('; 
                                        $lsInsertQuery = ''; 
                                        
                                        //loop for insert field
                                        foreach($larrReadColumns as $columnKey =>$columnValue)
                                        {
                                            //$lsInsertQuery .= '`'.$lsPrefix_Database_Fields[$columnKey].'`,';
                                        }

                                        //$lsInsertQuery = substr($lsInsertQuery,0,strlen($lsInsertQuery)-1).") values (";
                                        
                                        //loop for insert value
                                        foreach($larrReadColumns as $readcolKey=>$readcolValue)
                                        {
                                                if(strlen($readcolValue) > 2)
                                                //if($readcolValue > 0)
                                                   {
                                                            if($readcolKey == "fromdate" or $readcolKey == "uptodate")
                                                            {
                                                                 //  $readcolValue = strtotime($readcolValue);
                                                                   
                                                                   $sadatetime='';
                                                                   $sadatetime = strtotime($readcolValue);  
                                                                   if($readcolKey == "uptodate")
                                                                   {
                                                                      if(!$sadatetime)
                                                                      {
                                                                      
                                                                         $readcolValue= strtotime("2037-12-31");
                                                                      }
                                                                      else
                                                                      {
                                                                         $readcolValue = strtotime($readcolValue); 
                                                                      }
                                                                       
                                                                   }
                                                                   else
                                                                   {
                                                                       if(!$sadatetime)
                                                                        {
                                                                            if($readcolValue==null)
                                                                                $readcolValue =mktime(); 
                                                                            else
                                                                                $readcolValue = "0";   
                                                                        }
                                                                        else
                                                                        {
                                                                              $readcolValue = strtotime($readcolValue); 
                                                                            
                                                                        }
                                                                       
                                                                   }
                                                                   
                                                                   
                                                                   
                                                                   
                                                                   
                                                            }
                                                            
                                                            if($readcolKey == "fromdate" or $readcolKey == "uptodate" or $readcolKey == "amount")
                                                            {
                                                                $quote = "";
                                                            }
                                                            else
                                                            {
                                                                $quote = "'";   
                                                            }
                                                            
                                                            if($readcolKey == "amount")
                                                            {
                                                                   $readcolValue = $readcolValue+0.00;
                                                            }
                                                            
                                                            //$lsInsertQuery .= $quote; 
                                                            $lsInsertQuery .= ($readcolValue != '') ? $readcolValue  : ' ';
                                                            $lsInsertQuery .= ","; 
                                                            //$lsInsertQuery .= $quote.',';
                                                            /*$lsInsertQuery .= "'"; 
                                                            $lsInsertQuery .= ($larrRow[$readcolValue-1] != '') ? $larrRow[$readcolValue-1]  : ' '; 
                                                            $lsInsertQuery .= "',";*/
                                                   }
                                                   else     
                                                   {     
                                                       /*$lsInsertQuery .= "'"; 
                                                            $lsInsertQuery .= ($readcolValue != '') ? $readcolValue  : ' '; 
                                                            $lsInsertQuery .= "',";*/
                                                            if($readcolKey == "fromdate" or $readcolKey == "uptodate")
                                                            {
                                                                  // $larrRow[$readcolValue-1] = strtotime($larrRow[$readcolValue-1]);
                                                                   $sadatetime='';
                                                                   $sadatetime = strtotime($larrRow[$readcolValue-1]);  
                                                                   if($readcolKey == "uptodate")
                                                                   {
                                                                      if(!$sadatetime)
                                                                      {
                                                                      
                                                                         $larrRow[$readcolValue-1]= strtotime("2037-12-31");
                                                                      }
                                                                      else
                                                                      {
                                                                          $larrRow[$readcolValue-1] = strtotime($larrRow[$readcolValue-1]);
                                                                      }
                                                                       
                                                                   }
                                                                   else
                                                                   {
                                                                       if(!$sadatetime)
                                                                        {
                                                                            if($larrRow[$readcolValue-1]==null)
                                                                            {
                                                                               $larrRow[$readcolValue-1]=mktime();
                                                                            }
                                                                            else
                                                                            {
                                                                               $larrRow[$readcolValue-1] = "0";
                                                                                
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                              $larrRow[$readcolValue-1] = strtotime($larrRow[$readcolValue-1]);
                                                                            
                                                                        }
                                                                       
                                                                   }
                                                                   
                                                                   
                                                            }
                                                            if(is_int($rowValue))
                                                            {
                                                                $lsInsertQuery .= $larrRow[$readcolValue-1];
                                                                $lsInsertQuery .= ",";
                                                            }
                                                            else
                                                            {
                                                                //$lsInsertQuery .= "'".$larrRow[$readcolValue-1]."',"; 
                                                                if($readcolKey == "fromdate" or $readcolKey == "uptodate" or $readcolKey == "amount")
                                                                {
                                                                    $quote = "";
                                                                    
                                                                }
                                                                else
                                                                {
                                                                    $quote = "'";   
                                                                }
                                                                
                                                                //$lsInsertQuery .= $quote; 
                                                                $lsInsertQuery .= ($larrRow[$readcolValue-1] != '') ? $larrRow[$readcolValue-1]  : (($readcolKey == "fromdate" or $readcolKey == "uptodate" or $readcolKey == "amount") ? 0 : ' ');
                                                                $lsInsertQuery .= ","; 
                                                                //$lsInsertQuery .= $quote.",";    
                                                            }
                                                   } 
                                        }            
                                        
                                        $lsInsertQuery = substr($lsInsertQuery,0,strlen($lsInsertQuery)-1);
                                        
                                        //$lsProductTempTableQuery .= "\r\n".$lsInsertQuery;
                                        if($lsInsertQuery != '')
                                        {
                                            $lsProductTempTableQuery[] .= $lsInsertQuery."|";    
                                        }
                                        
                            }
                        }
                    } 
                    //echo "<br/>".$lsProductTempTableQuery;
                    /***************************************************************************************/ 
//              echo $lsProductTempTableQuery;die;
                //print_r($lsProductTempTableQuery); die;
              $laInsertQuery = array();
              
              
              $laInsertQuery[0] = $lsUserTableQuery;
              $laInsertQuery[1] = $lsProductTempTableQuery;
              
              return $laInsertQuery;  
          }
          
          function ShowCSVData($csv_path,$pUserTableFields,$pUserFieldsIndex,$pTempProductFields,$pTempProductFieldsIndex,$pFieldSeparator) 
          {
                     
                    $filename = $csv_path;
                    $handle = fopen($filename, "r");
                    $contents = fread($handle, filesize($filename));
                    fclose($handle);

                    $larrContents  =  explode("\n",$contents);
                    
                    $lsSeparatorInCsvFile = $pFieldSeparator;

                    //pass database field for update or insert of user table                                
                    $lsPrefix_Database_Fields = array_merge($pUserTableFields,$pTempProductFields);//array('username','password','email','city');

                    //specify the fields index of csv file to read
                    $larrReadColumns = array_merge($pUserFieldsIndex,$pTempProductFieldsIndex);//array(1,2,1,2);
                    
                    $larrFileLine = '';

                    $laDemoData = array();
                    /*******************************for user table ***********************************/
                    
                    foreach($larrContents as $key=>$rowValue)
                    {
                        if($key != 0)   
                        {
                            $larrRow = explode($lsSeparatorInCsvFile, $rowValue);
                            if($larrRow[0] != '')
                            {
                                       $lsInsertQuery .= '<tr>'; 
                                        
                                       foreach($larrReadColumns as $readcolKey=>$readcolValue)
                                        {
                                            $lsInsertQuery .= "<td class=\"\" stlye=\"width:30px;\">"; 
                                            
                                              if(strlen($readcolValue) > 2)
                                                   //if($readcolValue > 0)
                                               {
                                                        $lsInsertQuery .= ($readcolValue != '') ? $readcolValue  : ' ';
                                                        $laDemoData[$readcolValue][$readcolKey] = ($readcolValue != '') ? $readcolValue  : ' '; 
                                               }
                                               else
                                               {
                                                        $lsInsertQuery .= ($larrRow[$readcolValue-1] != '') ? $larrRow[$readcolValue-1]  : "&nbsp;";
                                                         $laDemoData[$readcolValue][$readcolKey] = ($larrRow[$readcolValue-1] != '') ? $larrRow[$readcolValue-1]  : "&nbsp;";  
                                               }
                                            
                                            $lsInsertQuery .= "</td>";    
                                        }            
                                        
                                        $lsInsertQuery .= "</tr>";
                            }
                        }
                        if($key >= 20)
                            break;
                    }
                    
              //echo $laDemoData;die;
              $t = $laDemoData;
              return $lsInsertQuery;  
          }
          
        function Insert($pQuery, $pValues=false, $types=true)
        { 
            return $this->BaseInsert($pQuery, $pValues, $types);
        }
        
        function GetUserTableQuery($UserTableValues)
        {
            /*encrypt password*/
                $lstokenKey=createToken();
                $lspassword=encrypt($UserTableValues[1],$lstokenKey);
            /******************/
             
            $UserTableValues[0] = ($UserTableValues[0] != '') ? addslashes($UserTableValues[0]) : ' ';
            $UserTableValues[1] = ($UserTableValues[1] != '') ? addslashes($UserTableValues[1]) : ' ';
            $UserTableValues[2] = ($UserTableValues[2] != '') ? addslashes($UserTableValues[2]) : ' ';
            $UserTableValues[3] = ($UserTableValues[3] != '') ? addslashes($UserTableValues[3]) : ' ';
            $UserTableValues[4] = ($UserTableValues[4] != '') ? addslashes($UserTableValues[4]) : ' ';
            $UserTableValues[5] = ($UserTableValues[5] != '') ? addslashes($UserTableValues[5]) : ' ';
            $UserTableValues[6] = ($UserTableValues[6] != '') ? addslashes($UserTableValues[6]) : ' ';
            $UserTableValues[7] = ($UserTableValues[7] != '') ? addslashes($UserTableValues[7]) : ' ';
            $UserTableValues[8] = ($UserTableValues[8] != '') ? addslashes($UserTableValues[8]) : ' ';
            $UserTableValues[9] = ($UserTableValues[9] != '') ? addslashes($UserTableValues[9]) : ' ';
           // $UserTableValues[10] = ($UserTableValues[10] != '' and (int)$UserTableValues[10]) ? (int)$UserTableValues[10] : 0;
            $UserTableValues[10] = ($UserTableValues[10] != '' and (int)$UserTableValues[10]) ? (int)$UserTableValues[10] : 1;
            $UserTableValues[11] = ($UserTableValues[11] != '' and (int)$UserTableValues[11]) ? (int)$UserTableValues[11] : 0;
            $UserTableValues[12] = ($UserTableValues[12] != '') ? addslashes($UserTableValues[12]) : ' ';
            $UserTableValues[13] = ($UserTableValues[13] != '') ? addslashes($UserTableValues[13]) : ' ';
            $UserTableValues[14] = ($UserTableValues[14] != '') ? addslashes($UserTableValues[14]) : ' ';
            $UserTableValues[15] = ($UserTableValues[15] != '') ? addslashes($UserTableValues[15]) : ' ';
            $UserTableValues[16] = ($UserTableValues[16] != '') ? addslashes($UserTableValues[16]) : ' ';
            $UserTableValues[17] = ($UserTableValues[17] != '') ? addslashes($UserTableValues[17]) : ' ';
            $UserTableValues[18] = ($UserTableValues[18] != '') ? addslashes($UserTableValues[18]) : ' ';
            $UserTableValues[19] = ($UserTableValues[19] != '' and (int)$UserTableValues[19]) ? (int)$UserTableValues[19] : 0;
            
            
            foreach($UserTableValues as $UTVKey => $UTVValue){
                $UserTableValues[$UTVKey] = str_replace("\\'","\'",$UTVValue);
            }
            
            
            /******** current timestamp ********/
                $lsCreatedOn = mktime();
            /**********************************/
            $query = "insert into ".TABLE_PREFIX."users";
            $query .= "(`username`,`password`,`secretsalt`,`firstname`,`lastname`,`Email`,`country`,`state`,`city`,`address1`,`address2`,`zipcode`,`isapproved`,`islockedout`,`phone_main`,`phone_home`,`phone_office`,`phone_mobile`,`createdon`,`createdby`,`createdipaddress`,`modifiedon`,`modifiedby`,`modifiedipaddress`,`billing_country`,`billing_state`,`billing_city`,`billing_address`,`billing_name`,`billing_phone`,`billing_zip`,`isunsubscribedfromemails`)";
            $query .= " values (";
            $query .= "'$UserTableValues[0]','$lspassword','$lstokenKey','$UserTableValues[3]','$UserTableValues[4]','$UserTableValues[2]',$UserTableValues[5],$UserTableValues[6],'$UserTableValues[7]','$UserTableValues[8]',' ','$UserTableValues[9]',$UserTableValues[10],$UserTableValues[11],'$UserTableValues[12]',' ',' ',' ',$lsCreatedOn,0,' ',0,0,' ',$UserTableValues[13],$UserTableValues[14],'$UserTableValues[15]','$UserTableValues[16]',' ','$UserTableValues[17]','$UserTableValues[18]',$UserTableValues[19]";
            $query .= ');';
        
            return $query;
        }
        
        
         function GetUserTableUpdateQuery($UserTableValues,$userid)
        {
            /*encrypt password*/
                $lstokenKey=createToken();
                $lspassword=encrypt($UserTableValues[1],$lstokenKey);
            /******************/
             
            $UserTableValues[0] = ($UserTableValues[0] != '') ? addslashes($UserTableValues[0]) : ' ';
            $UserTableValues[1] = ($UserTableValues[1] != '') ? addslashes($UserTableValues[1]) : ' ';
            $UserTableValues[2] = ($UserTableValues[2] != '') ? addslashes($UserTableValues[2]) : ' ';
            $UserTableValues[3] = ($UserTableValues[3] != '') ? addslashes($UserTableValues[3]) : ' ';
            $UserTableValues[4] = ($UserTableValues[4] != '') ? addslashes($UserTableValues[4]) : ' ';
            $UserTableValues[5] = ($UserTableValues[5] != '') ? addslashes($UserTableValues[5]) : ' ';
            $UserTableValues[6] = ($UserTableValues[6] != '') ? addslashes($UserTableValues[6]) : ' ';
            $UserTableValues[7] = ($UserTableValues[7] != '') ? addslashes($UserTableValues[7]) : ' ';
            $UserTableValues[8] = ($UserTableValues[8] != '') ? addslashes($UserTableValues[8]) : ' ';
            $UserTableValues[9] = ($UserTableValues[9] != '') ? addslashes($UserTableValues[9]) : ' ';
            //$UserTableValues[10] = ($UserTableValues[10] != '' and (int)$UserTableValues[10]) ? (int)$UserTableValues[10] : 0;
            $UserTableValues[10] = ($UserTableValues[10] != '' and (int)$UserTableValues[10]) ? (int)$UserTableValues[10] : 1;
            $UserTableValues[11] = ($UserTableValues[11] != '' and (int)$UserTableValues[11]) ? (int)$UserTableValues[11] : 0;
            $UserTableValues[12] = ($UserTableValues[12] != '') ? addslashes($UserTableValues[12]) : ' ';
            $UserTableValues[13] = ($UserTableValues[13] != '') ? addslashes($UserTableValues[13]) : ' ';
            $UserTableValues[14] = ($UserTableValues[14] != '') ? addslashes($UserTableValues[14]) : ' ';
            $UserTableValues[15] = ($UserTableValues[15] != '') ? addslashes($UserTableValues[15]) : ' ';
            $UserTableValues[16] = ($UserTableValues[16] != '') ? addslashes($UserTableValues[16]) : ' ';
            $UserTableValues[17] = ($UserTableValues[17] != '') ? addslashes($UserTableValues[17]) : ' ';
            $UserTableValues[18] = ($UserTableValues[18] != '') ? addslashes($UserTableValues[18]) : ' ';
            $UserTableValues[19] = ($UserTableValues[19] != '' and (int)$UserTableValues[19]) ? (int)$UserTableValues[19] : 0;
          
            foreach($UserTableValues as $UTVKey => $UTVValue){
                $UserTableValues[$UTVKey] = str_replace("\\'","\'",$UTVValue);
            }
            
            /******** current timestamp ********/
                $lsCreatedOn = mktime();
            /**********************************/
            $query = "update ".TABLE_PREFIX."users";
            $query .= " set `password`='$lspassword',`secretsalt`='$lstokenKey',`firstname`='$UserTableValues[3]',`lastname`='$UserTableValues[4]',`Email`='$UserTableValues[2]',`country`=$UserTableValues[5],`state`=$UserTableValues[6],`city`='$UserTableValues[7]',`address1`='$UserTableValues[8]',`address2`=' ',`zipcode`='$UserTableValues[9]',`isapproved`=$UserTableValues[10],`islockedout`=$UserTableValues[11],`phone_main`='$UserTableValues[12]',`modifiedon`=$lsCreatedOn,`billing_country`=$UserTableValues[13],`billing_state`=$UserTableValues[14],`billing_city`='$UserTableValues[15]',`billing_address`='$UserTableValues[16]',`billing_phone`='$UserTableValues[17]',`billing_zip`='$UserTableValues[18]',`isunsubscribedfromemails`=$UserTableValues[19] where id=$userid ";
            
            return $query;
        }
        function GetProductTempTableQuery($laTableValue) 
        {
          
          if(trim($laTableValue[1])!=""){
          
            $proclass=new product_class();
             $proData=$proclass->GetSpecificProductPaymentOptions($laTableValue[1]);
            
            $islifetime=0;
            if($proData!=false and $proData!=null)
               $islifetime=$proData[0]['islifetime'];
            
           
              if($islifetime!=1){
                
                $lsdurationCheckQuery       ="select duration_type from ".TABLE_PREFIX."productpaymentoptions where productid=$laTableValue[1]";
                $result                     =$this->BaseView($lsdurationCheckQuery);
                $lsDurationType             =$result[0]['duration_type'];
                
                if(isset($lsDurationType) and $lsDurationType=="Months")
                 {
                         $igetMonthQuery         ="select duration from ".TABLE_PREFIX."productpaymentoptions where productid=$laTableValue[1]";
                         $resultMonthQuery       = $this->BaseView($igetMonthQuery); 
                         $lsDurationValue        =$resultMonthQuery[0]['duration'];       
                     
                         if($lsDurationValue>0)
                          {
                              $liFromDate                     = $laTableValue[2];
                              $liUptoDate                     = strtotime("+$lsDurationValue month",$laTableValue[2]);
                          }
                      
                 }
                 
                else if(isset($lsDurationType) and $lsDurationType=="Days")
                 {
                         $igetDayQuery           ="select duration from ".TABLE_PREFIX."productpaymentoptions where productid=$laTableValue[1]";
                         $resultDayQuery         = $this->BaseView($igetDayQuery); 
                         $lsDurationValue        =$resultDayQuery[0]['duration'];       
                     
                         if($lsDurationValue>0)
                          {
                              $liFromDate                     = $laTableValue[2];
                              $liUptoDate                     = strtotime("+$lsDurationValue day",$laTableValue[2]);
                          }
                      
                 }
                  else if(isset($lsDurationType) and $lsDurationType=="Years")
                 {
                         $igetYearQuery           ="select duration from ".TABLE_PREFIX."productpaymentoptions where productid=$laTableValue[1]";
                         $resultYearQuery         = $this->BaseView($igetYearQuery); 
                         $lsDurationValue         =$resultYearQuery[0]['duration'];       
                     
                         if($lsDurationValue>0)
                          {
                              $liFromDate                     = $laTableValue[2];
                              $liUptoDate=strtotime("+$lsDurationValue year",$laTableValue[2]); 
                              
                              
                          }
                      
                 }
                else if(isset($lsDurationType) and $lsDurationType=="Exact date (mm-dd-yyyy)")
                 {
                
                     $liFromDate             = strtotime(date("m/d/YH:i:s")); 
                     $igetexactdate          ="select duration_exactdate from ".TABLE_PREFIX."productpaymentoptions where productid=$laTableValue[1]";
                     $resultexactdateQuery   = $this->BaseView($igetexactdate); 
                     $lsDurationValue        =$resultexactdateQuery[0]['duration_exactdate'];
                     $liUptoDate             =$lsDurationValue;  
                 
                 }
                 
                 
                        
                   
                   $todayTimeStemp=strtotime(date("m/d/YH:i:s"));
                   
                   if($todayTimeStemp >=  $liFromDate  and  $todayTimeStemp<= $liUptoDate){
                       
                        $payGearstatusValue="Active";
                        $masterclassObj=new master_class();
                        $masterId=$masterclassObj->getMasterId("productmembershipstatus");
                        $masterValuesId=$masterclassObj->getMasterValuesId($payGearstatusValue,$masterId);  
              
                   
                   }
                  else{
                        
                        $payGearstatusValue="Expire";
                        $masterclassObj=new master_class();
                        $masterId=$masterclassObj->getMasterId("productmembershipstatus");
                        $masterValuesId=$masterclassObj->getMasterValuesId($payGearstatusValue,$masterId);  
                    
                  } 
                        
             }
            else{
            
                 $payGearstatusValue="Active";
                 $masterclassObj=new master_class();
                 $masterId=$masterclassObj->getMasterId("productmembershipstatus");
                 $masterValuesId=$masterclassObj->getMasterValuesId($payGearstatusValue,$masterId);  
                 
                 $liFromDate=$laTableValue[2];
                 $liUptoDate=$laTableValue[3];
                 
                   
            }  
            
            if($laTableValue[2]=="0")
            {
               //$laTableValue[2] = mktime(); 
                
            }
            $query = "insert into ".TABLE_PREFIX."product_users";
            $query .= "(`productid`,`userid`,`amount`,`fromdate`,`uptodate`,`islifetime`,`paygear_paidon`,`paygear_epaymentstatus`,`productmembershipstatusid`)";
            $query .= " values(";
            $query .= "$laTableValue[1],$laTableValue[0],$laTableValue[4],$liFromDate,$liUptoDate,$islifetime,$laTableValue[2],1,$masterValuesId";
            $query .= ")";
          //  echo $query;
            return $query;
            
          } 
        }
        
        function View($pQuery, $pValues=false, $types=true, $pStart=0, $pEnd=0)
        {
           
            return $this->BaseView($pQuery,$pValues,$types,$pStart,$pEnd);
            
        }

 }   
?>
Return current item: MembersGear