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

 require_once "peardb_class.php";
  require_once INCLUDE_DIR."/master_class.php";
 class product_protection_class extends peardb_class
 {  
 
      function View($pQuery, $pValues=false, $types=true, $pStart=0, $pEnd=0)
    {
        /*
        global $mdb2;    
        $result;  
 
        $query      = 'SELECT * FROM tbluser1 t limit 10;';
        $resultset  = $mdb2->query($query);
        
        if(PEAR::isError($resultset)) 
        {
            die("Failed to issue query, error message : " . $resultset->getMessage());
        }
        
        while($row = $resultset->fetchRow(MDB2_FETCHMODE_ASSOC))
        {
            $result[] = $row;
        }
                                                                                                                 
        return  $result;   
        */
        //print_r($pParameters);
        
        return $this->BaseView($pQuery,$pValues,$types,$pStart,$pEnd);
        
    }
    
    function Update($pQuery, $pValues=false, $types=true)
    { 
       
        return $this->BaseUpdate($pQuery, $pValues, $types);
    
    }

    
    function Insert($pQuery, $pValues=false, $types=true)
    { 
    
        return $this->BaseInsert($pQuery, $pValues, $types);
    
    }
    
     function delete($pQuery, $pValues=false, $types=true)
    {
        
      return $this->BaseDelete($pQuery, $pValues,null);
        
    } 

     function getProducts($pScope)
    {
         $query="select * from ".TABLE_PREFIX."products where isApproved=1 and IsDeleted=0 and (scop='Visible' or scop='$pScope') and pricegroup=0 order by sortorder";          
         $productResults = users_signup_class::View($query);
         return $productResults;            
     
    }  
    
      function getSpecificProductInfo($pid)
       {
         $query="select * from ".TABLE_PREFIX."product_protect where id=$pid";          
         $productResults = $this->View($query);
          return $productResults;            
     
       } 
       
       
        function getSpecificDripInfo($pid)
       {
         $query="select * from ".TABLE_PREFIX."drips where id=$pid";          
         $productResults = $this->View($query);
          return $productResults;            
     
       } 
        
    
      function getProductsOnEdit($pid)
    {
    
         $query="select allowed_productid from ".TABLE_PREFIX."product_protect where folder = (select folder from ".TABLE_PREFIX."product_protect where id=$pid)";
         $selectedProductResults = $this->View($query);  $laallProduct=array();
         $i=0;
         foreach($selectedProductResults as $key=>$value)
         {
             $laallProduct[$i]=$value['allowed_productid'];
             $i++;
         }   
         return  $laallProduct;
    
    }
    
    function getDripOnEdit($pid)
    {
    
         $query="select product_id from ".TABLE_PREFIX."drips where filename = (select filename from ".TABLE_PREFIX."drips where id=$pid)";
         $selectedProductResults = $this->View($query);  $laallProduct=array();
         $i=0;
         foreach($selectedProductResults as $key=>$value)
         {
             $laallProduct[$i]=$value['product_id'];
             $i++;
         }   
         return  $laallProduct;
    
    }
    
    
    function getDripInfo($pProdId,$filepath)
    {
    
         $query="select * from ".TABLE_PREFIX."drips where product_id = $pProdId and locate(fileurl, '$filepath')>0  ";
         $selectedProductResults = $this->View($query); 
         return $selectedProductResults;
      
    }
    
    
    
     
    function getAllProtectedProducts()
    {
         $query="select allowed_productid,protection_method,folder from ".TABLE_PREFIX."product_protect";
         $ProductResults = $this->View($query); 
         return $ProductResults; 
         
    } 
    function isAlreadyProtected($folderPath)
     {
       $query="select * from ".TABLE_PREFIX."product_protect where folder='$folderPath'";
       $arrAlreadyProtected = $this->View($query);
       if($arrAlreadyProtected!=FALSE)
        {
          $url=$arrAlreadyProtected[0]['folder'];
          if($url!=null or $url!="")
            return true;
          else
            return false;  
        }
     }
     
     function isAlreadyProtectedFile($filePath)
     {
       $query="select * from ".TABLE_PREFIX."drips where fileurl='$filePath'";
       $arrAlreadyProtected = $this->View($query);
       if($arrAlreadyProtected!=FALSE)
        {
          $url=$arrAlreadyProtected[0]['fileurl'];
          if($url!=null or $url!="")
            return true;
          else
            return false;  
        }
     }
     
     
     
     function getProductUserPaidOnDate($productid,$pUserid)
      {
          $masterclassObj=new master_class();
          $maxProdIdQuery ="SELECT  max(id) as `maxid` FROM ".TABLE_PREFIX."product_users WHERE userid=$pUserid and productid=$productid ";
          $res=$this->View($maxProdIdQuery);
          $maxId=$res[0]['maxid'];
                                 
           $payGearstatusValue="Active";
           
           $masterId=$masterclassObj->getMasterId("productmembershipstatus");
           $masterValuesId=$masterclassObj->getMasterValuesId($payGearstatusValue,$masterId);
           
           if($maxId!=null and $maxId!="")
           {
               $userSubscribedProductsQuery="select * from ".TABLE_PREFIX."product_users pu
                                                join ".TABLE_PREFIX."products p on p.`id` = pu.`productid`
                                            where pu.`userid`=$pUserid and (pu.`productmembershipstatusid`=$masterValuesId)
                                            and productid=$productid and pu.id=$maxId
                                             and ifnull(p.`IsApproved`,1)=1
                                             and ifnull(p.`IsDeleted`,0) != 1
                                             and ifnull(p.`isProhibited`,0) != 1; ";
           }
           else
            {
                       $userSubscribedProductsQuery="select * from ".TABLE_PREFIX."product_users pu
                                                join ".TABLE_PREFIX."products p on p.`id` = pu.`productid`
                                            where pu.`userid`=$pUserid and (pu.`productmembershipstatusid`=$masterValuesId)
                                            and productid=$productid 
                                             and ifnull(p.`IsApproved`,1)=1
                                             and ifnull(p.`IsDeleted`,0) != 1
                                             and ifnull(p.`isProhibited`,0) != 1; ";
            
            }                            
          
           $arrUserSubscr=$this->View($userSubscribedProductsQuery);   
           
           return $arrUserSubscr;
          
      }
     
     function getProductUserId($productid,$pUserid)
      {
           $payGearstatusValue="Active";
           $masterclassObj=new master_class();
           $masterId=$masterclassObj->getMasterId("productmembershipstatus");
           $masterValuesId=$masterclassObj->getMasterValuesId($payGearstatusValue,$masterId);
           
           $userSubscribedProductsQuery="select pu.id from ".TABLE_PREFIX."product_users pu
                                            join ".TABLE_PREFIX."products p on p.`id` = pu.`productid`
                                        where pu.`userid`=$pUserid and (pu.`productmembershipstatusid`=$masterValuesId)
                                        and productid=$productid
                                         and ifnull(p.`IsApproved`,1)=1
                                         and ifnull(p.`IsDeleted`,0) != 1
                                         and ifnull(p.`isProhibited`,0) != 1; ";
          
           $arrUserSubscr=$this->View($userSubscribedProductsQuery);   
           
           return $arrUserSubscr;
          
      } 
    function isValidProductRequest($pImploString,$puserId)
    {
         $explodeArr=explode(",",$pImploString);
         $curentTimeStamp= strtotime(date("Y/m/dH:i:s"));
      
           $payGearstatusValue="Active";
           $masterclassObj=new master_class();
           $masterId=$masterclassObj->getMasterId("productmembershipstatus");
           $masterValuesId=$masterclassObj->getMasterValuesId($payGearstatusValue,$masterId);
           
           $userSubscribedProductsQuery="select `productid` from ".TABLE_PREFIX."product_users pu
                                            join ".TABLE_PREFIX."products p on p.`id` = pu.`productid`
                                        where pu.`userid`=$puserId and (pu.`productmembershipstatusid`=$masterValuesId)
                                         and ifnull(p.`IsApproved`,1)=1
                                         and ifnull(p.`IsDeleted`,0) != 1
                                         and ifnull(p.`isProhibited`,0) != 1; ";
                                        
           $arrUserSubscr=$this->View($userSubscribedProductsQuery);
           $result = false;
         
         $len=sizeof($arrUserSubscr);
         if($len>0)
         {
                 foreach($arrUserSubscr as $key=>$value)
                  {
                      $prdoId=$value['productid'];
                      if(in_array($prdoId,$explodeArr))
                       {
                         $result=true;
                        
                       } 
                      
                  }
         }        
         
         return $result; 
        
    } 
     
  
    function getuser_clicks_for_drips($pProduct_user_id,$pDripId)
    {
        $query="select clicks from ".TABLE_PREFIX."drips_clicks where product_users_id=$pProduct_user_id and drips_id=$pDripId";
        $arrUserSubscrClick=$this->View($query);    
        return $arrUserSubscrClick;
        
    }
    
     function ifIsDripCreated($proId)
     {
        $query="select * from ".TABLE_PREFIX."drips where product_id=$proId and status=1";
        $arr=$this->View($query); 
        if($arr!=false and sizeof($arr)>0)
          return true;
        else
          return false;  
     
     }
     
    function update_Drip_Clicks($pProDUserId,$clicks,$dripId)
     {
        $query="select id from ".TABLE_PREFIX."drips_clicks where product_users_id=$pProDUserId and drips_id=$dripId";
        $arrUserSubscrClick=$this->View($query); 
        $len=sizeof($arrUserSubscrClick);    
        $id=$arrUserSubscrClick[0]['id'];
        if($arrUserSubscrClick!=false  and $len>0)
         {
            $updateDrips="update ".TABLE_PREFIX."drips_clicks set clicks=$clicks where id=$id";
            $this->View($updateDrips); 
         }
        else
         {
             $query="insert into ".TABLE_PREFIX."drips_clicks(product_users_id,clicks,drips_id) values($pProDUserId,$clicks,$dripId)";
             $this->View($query);       
             
         }    
         
     }
     
     
     function getDripsProductsUrls($commSepProdId)
     {
          $query="select * from ".TABLE_PREFIX."drips pd left join ".TABLE_PREFIX."products p on p.id=pd.product_id   where pd.product_id in ($commSepProdId) order by IFNULL(pd.sortorder,10000),pd.filename ASC";
          $arrUserSubscrClick=$this->View($query); 
          return $arrUserSubscrClick;
         
     }
    function getUsersValidSubscription($pImploString,$puserId)
    {
         $explodeArr=explode(",",$pImploString);
         $curentTimeStamp= strtotime(date("Y/m/dH:i:s"));
      
           $payGearstatusValue="Active";
           $masterclassObj=new master_class();
           $masterId=$masterclassObj->getMasterId("productmembershipstatus");
           $masterValuesId=$masterclassObj->getMasterValuesId($payGearstatusValue,$masterId);
           
           $userSubscribedProductsQuery="select pu.id,`productid` from ".TABLE_PREFIX."product_users pu
                                            join ".TABLE_PREFIX."products p on p.`id` = pu.`productid`
                                        where pu.`userid`=$puserId and (pu.`productmembershipstatusid`=$masterValuesId)
                                         and ifnull(p.`IsApproved`,1)=1
                                         and ifnull(p.`IsDeleted`,0) != 1
                                         and ifnull(p.`isProhibited`,0) != 1; ";
                                        
           $arrUserSubscr=$this->View($userSubscribedProductsQuery);
           $result = false;
         
         $arrValidSubscription=array();
         $len=sizeof($arrUserSubscr);
         if($len>0)
         {
                 foreach($arrUserSubscr as $key=>$value)
                  {
                      $prdoId=$value['productid'];
                      $id=$value['id'];
                      if(in_array($prdoId,$explodeArr))
                       {
                        $arrValidSubscription[]=array('id'=>$id,'productid'=>$prdoId);
                        
                       } 
                      
                  }
         }        
         
         return $arrValidSubscription; 
        
    } 

 }

?>
Return current item: MembersGear