<?php
require_once "peardb_class.php";
require_once INCLUDE_DIR."/master_class.php";
class product_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 FillRequireanothersubscription()
{
/* Updated By Asmita For Proper Prodct selection*/
//$query= "SELECT id,name FROM ".TABLE_PREFIX."products where IsApproved=1 and IsDeleted=0 order by name";
$query= "SELECT id,name FROM ".TABLE_PREFIX."products p WHERE p.`IsApproved`=1
and (p.`IsDeleted`=0 or p.`IsDeleted` is null)
and (p.`isprohibited`=0 or p.`isprohibited` is null)
and p.`islinkedwithpaygear`=1
and (p.`paygear_productid` is not null and p.`paygear_productid`>0) order by name";
$result = $this->View($query);
if(is_array($result))
{
$lareqsubscription=array();
if(sizeof($result))
{
foreach($result as $key=>$value)
{
$lareqsubscription["ACTIVE-".$value['id']]="Require ACTIVE subscription for ".$value['name'];
$lareqsubscription["EXPIRED-".$value['id']]="Require EXPIRED subscription for ".$value['name'];
}
}
else
{
$lareqsubscription=null;
}
}
else
{
$lareqsubscription=null;
}
return $lareqsubscription;
}
function FillDisallowsubscription()
{
/* Updated By Asmita For Proper Prodct selection*/
//$query= "SELECT id,name FROM ".TABLE_PREFIX."products where IsApproved=1 and IsDeleted=0 order by name";
$query= "SELECT id,name FROM ".TABLE_PREFIX."products p WHERE p.`IsApproved`=1
and (p.`IsDeleted`=0 or p.`IsDeleted` is null)
and (p.`isprohibited`=0 or p.`isprohibited` is null)
and p.`islinkedwithpaygear`=1
and (p.`paygear_productid` is not null and p.`paygear_productid`>0) order by name";
$result = $this->View($query);
if(is_array($result))
{
$ladissubscription=array();
if(sizeof($result))
{
foreach($result as $key=>$value)
{
$ladissubscription["ACTIVE-".$value['id']]="Member has ACTIVE subscription for ".$value['name'];
$ladissubscription["EXPIRED-".$value['id']]="Member has EXPIRED subscription for ".$value['name'];
}
}
else
{
$ladissubscription=null;
}
}
else
{
$ladissubscription=null;
}
return $ladissubscription;
}
function GetAllProduct()
{
$query= "SELECT id,name FROM ".TABLE_PREFIX."products order by name";
$result = $this->View($query);
if(is_array($result))
{
if(sizeof($result))
{
$laallProduct=array();
foreach($result as $key=>$value)
{
$laallProduct[$value['id']]=$value['name'];
}
}
else
{
$laallProduct=null;
}
}
else
{
$laallProduct=null;
}
return $laallProduct;
}
function GetAllProduct_with_paygear_productid()
{
$query= "SELECT id,name,paygear_productid FROM ".TABLE_PREFIX."products order by name";
$result = $this->View($query);
if(is_array($result))
{
if(sizeof($result))
{
$laallProduct=array();
foreach($result as $key=>$value)
{
$laallProduct[$value['paygear_productid']]=$value['name'];
}
}
else
{
$laallProduct=null;
}
}
else
{
$laallProduct=null;
}
return $laallProduct;
}
function GetUserProduct()
{
$query= "SELECT id,name FROM ".TABLE_PREFIX."products p WHERE p.`IsApproved`=1
and (p.`IsDeleted`=0 or p.`IsDeleted` is null)
and (p.`isprohibited`=0 or p.`isprohibited` is null)
and p.`islinkedwithpaygear`=1
and (p.`paygear_productid` is not null and p.`paygear_productid`>0) order by name";
$result = $this->View($query);
if(is_array($result))
{
if(sizeof($result))
{
$laallProduct=array();
foreach($result as $key=>$value)
{
$laallProduct[$value['id']]=$value['name'];
}
}
else
{
$laallProduct=null;
}
}
else
{
$laallProduct=null;
}
return $laallProduct;
}
function GetSpecificProduct($pid)
{
$query= "SELECT * FROM ".TABLE_PREFIX."products where IsApproved=1 and IsDeleted=0 and id=$pid order by name";
$result = $this->View($query);
return $result;
}
function getAllLinkedProductWithMainProduct()
{
$query= "SELECT * FROM ".TABLE_PREFIX."products where linked_products_id IS NOT NULL order by name";
$result = $this->View($query);
return $result;
}
function GetSpecificProductphpBB($pid)
{
$query= "SELECT * FROM ".TABLE_PREFIX."products where IsDeleted=0 and id=$pid order by name";
$result = $this->View($query);
return $result;
}
function GetSpecificProductphpBBByProductUrl()
{
$query= "SELECT * FROM ".TABLE_PREFIX."products where IsDeleted=0 and UPPER(TRIM(protectedurl))=UPPER(TRIM('/forum/')) order by name";
$result = $this->View($query);
return $result;
}
function GetSpecificProductPaymentOptions($pid)
{
$query= "SELECT * FROM ".TABLE_PREFIX."productpaymentoptions where productid=$pid";
$result = $this->View($query);
return $result;
}
function GetProductCategoryIdsFromXML($pXml)
{
$result=array();
$arrXml = explode('"',$pXml);
foreach($arrXml as $key=>$value)
{
if(is_numeric($value))
$result[] = $value;
}
return $result;
}
function GetPaygearProductinfo($plapaygeardatinfo)
{
// $lapaygeardatinfo=$PaygearWebserviceClient->GetPaygearProduct(164);
$lapaygearupdateinfo=array();
$sp="!@#$%^*()";
foreach($plapaygeardatinfo as $key=>$value)
{
$value1=str_replace($sp,'|',$value);
$value2=strtolower(substr($value1,0,strpos($value1,'|')));
if($value2=="id")
{
$value2='paygear_productid';
}
$arrayvaue=substr($value1,strpos($value1,'|')+1);
if($arrayvaue=="True")
{
$arrayvaue=1;
}
if($arrayvaue=="False")
{
$arrayvaue=0;
}
$lapaygearupdateinfo[$value2]=$arrayvaue;
}
return $lapaygearupdateinfo;
}
function GetPaygearProductPaymentinfo($plapaygeardatinfo)
{
// $lapaygeardatinfo=$PaygearWebserviceClient->GetPaygearProduct(164);
$lapaygearupdateinfo=array();
$sp="!@#$%^*()";
foreach($plapaygeardatinfo as $key=>$value)
{
$value1=str_replace($sp,'|',$value);
$value2=strtolower(substr($value1,0,strpos($value1,'|')));
if($value2=="id")
{
$value2='paygear_productpaymentoptionid';
}
$arrayvaue=substr($value1,strpos($value1,'|')+1);
if($arrayvaue=="True")
{
$arrayvaue=1;
}
if($arrayvaue=="False")
{
$arrayvaue=0;
}
$lapaygearupdateinfo[$value2]=$arrayvaue;
}
return $lapaygearupdateinfo;
}
function getUserPaymentHistory($pUserId)
{
$query= "SELECT productid,ps.name,amount,islifetime,fromdate,uptodate,paygear_paymentgetway FROM ".TABLE_PREFIX."product_users p
join ".TABLE_PREFIX."products ps on ps.id=p.productid where p.userid=$pUserId and p.paygear_epaymentstatus=1 order by p.paygear_paidon DESC ";
$result = $this->View($query);
return $result;
}
function deleteDuplicateTransaction($pUserId,$pProductid)
{
$query="delete from ".TABLE_PREFIX."product_users where userid=$pUserId and productid=$pProductid and paygear_epaymentstatus is null";
$res=$this->delete($query);
}
function checkForSameActiveSubscription($pUserId,$pProductid)
{
$query="select productid from ".TABLE_PREFIX."product_users where userid=$pUserId and productid=$pProductid and paygear_epaymentstatus=1
and productmembershipstatusid=(select mv.id from ".TABLE_PREFIX."master_values mv left join ".TABLE_PREFIX."master m on m.id=mv.masterid where masterid=4 and value='Active')";
$res=$this->View($query);
$id=$res[0]['productid'];
return $id;
}
function getAllLinkedProductsForSpecificProduct($proId)
{
$query="select linked_products_id from ".TABLE_PREFIX."products where id=$proId and price>0";
$res=$this->View($query);
$ids=$res[0]['linked_products_id'];
return $ids;
}
function checkForActiveSubscription($pUserId,$pProductid)
{
$query="select productid from ".TABLE_PREFIX."product_users where userid=$pUserId and productid=$pProductid and paygear_epaymentstatus=1
and productmembershipstatusid=(select mv.id from ".TABLE_PREFIX."master_values mv left join ".TABLE_PREFIX."master m on m.id=mv.masterid where masterid=4 and value='Active')";
$res=$this->View($query);
$id=$res[0]['productid'];
return $id;
}
function checkForSubscription($pUserId,$pProductid)
{
$query="select productid from ".TABLE_PREFIX."product_users where userid=$pUserId and productid=$pProductid";
$res=$this->View($query);
$id=$res[0]['productid'];
return $id;
}
function isValidProduct($pProductId)
{
$queryProductCheck ="SELECT p.`id` FROM ".TABLE_PREFIX."products p
WHERE p.`IsApproved`=1
and (p.`IsDeleted`=0 or p.`IsDeleted` is null)
and (p.`isprohibited`=0 or p.`isprohibited` is null)
and p.`islinkedwithpaygear`=1
and (p.`paygear_productid` is not null and p.`paygear_productid`>0) and p.`id`=$pProductId" ;
$res=$this->View($queryProductCheck);
$prodid=$res[0]['id'];
return $prodid;
}
function getLinkdInProducts($pScope='Visible', $pGroup='0',$editId='0')
{
$pgroups=explode(',',$pGroup);
if($pGroup=='0')
{
$query = "SELECT p.id,p.price,p.name FROM ".TABLE_PREFIX."products p
WHERE p.`IsApproved`=1 and p.`isonetimeoffer`!=1 and p.`productstatusid`!=3
and (p.`IsDeleted`=0 or p.`IsDeleted` is null)
and (p.`isprohibited`=0 or p.`isprohibited` is null)
and p.`islinkedwithpaygear`=1
and (p.`paygear_productid` is not null and p.`paygear_productid`>0)
and (p.`price`=0)
and IFNULL(`requiredanothersubscription`,'') = '' and IFNULL(`disallowedsubscriptions`,'') = ''
and p.pricegroup >=0";
if($editId>0)
{
$query.=" and p.id<>$editId ";
}
$query.=" order by sortorder ASC, name ASC ";
}
else
{
$query = "SELECT * FROM ".TABLE_PREFIX."products p
WHERE p.`IsApproved`=1 and p.`isonetimeoffer`!=1 and p.`productstatusid`!=3
and (p.`IsDeleted`=0 or p.`IsDeleted` is null)
and (p.`isprohibited`=0 or p.`isprohibited` is null)
and p.`islinkedwithpaygear`=1
and (p.`paygear_productid` is not null and p.`paygear_productid`>0)
and IFNULL(`requiredanothersubscription`,'') = '' and IFNULL(`disallowedsubscriptions`,'') = ''";
if($editId>0)
{
$query.=" and p.id<>$editId ";
}
$query.=" order by sortorder ASC, name ASC ";
}
$productResults = users_signup_class::View($query);
$pgroups=explode(',',$pGroup);
/* update for 1,-2,-4 values in user signup */
$productArrayGroup="";
if($pGroup!='0')
{
$flag=true;
for($count=0;$count<=sizeof($pgroups)-1;$count++)
{
if(!is_numeric($pgroups[$count]) and !ord($pgroups[$count])==0)
{
$flag=false;
break;
}
}
if($flag==true)
{
if(is_array($productResults))
{
for($i=0;$i<=sizeof($productResults)-1;$i++)
{
$groupvaue=$productResults[$i]['pricegroup'];
$len=sizeof($pgroups);
$splitedGroupValue=explode(',',$groupvaue);
for($j=0;$j<=$len-1;$j++)
{
//if($pgroups[$j]<0)
//{
if(in_array($pgroups[$j],$splitedGroupValue))
{
$productArrayGroup[]=$productResults[$i];
break;
}
//}
}
}
}
}
}
if($pGroup!='0')
$productResults= $productArrayGroup;
$productResultModifiedArray="";
if(is_array($productResults))
{
for($i=0;$i<=sizeof($productResults)-1;$i++)
{
$productid=$productResults[$i]['id'];
$queryExpireddate="select * from ".TABLE_PREFIX."productpaymentoptions where productid=".$productid;
$resultOfExpiredProducts=users_signup_class::View($queryExpireddate);
if($resultOfExpiredProducts[0]['duration_type']=='Exact date (mm-dd-yyyy)')
{
$curentTimeStamp= strtotime(date("m/d/YH:i:s"));
if($resultOfExpiredProducts[0]['duration_exactdate']<$curentTimeStamp)
{
//unset($productResults[$i]);
}
else
{
$productResultModifiedArray[]=$productResults[$i];
}
}
else
{
$productResultModifiedArray[]=$productResults[$i];
}
}
}
$resetedArray=array();
$prod_clss_obj=new product_class();
$upsellProducts=$prod_clss_obj->getAllUpsellSubProducts();
if($productResultModifiedArray!=false)
{
if( sizeof($upsellProducts) > 0)
{
$upsellProducts=$upsellProducts[0]['products'];
$len=sizeof($productResultModifiedArray)-1;
$prductArr=explode(",",$upsellProducts);
for($i=0;$i<=$len;$i++)
{
if(in_array($productResultModifiedArray[$i]['id'],$prductArr))
{
unset($productResultModifiedArray[$i]);
}
}
}
foreach($productResultModifiedArray as $arr)
{
$proObj=new product_protection_class();
$result=$proObj->ifIsDripCreated($arr['id']);
if($result==false and $arr['is_donotlink']==1)
{}
else
$resetedArray[]=$arr;
}
}
return $resetedArray;
}
function GetAllProductForOnetimeoffer($pProductid='')
{
if($pProductid=='')
{
/* $query= "SELECT id,name FROM ".TABLE_PREFIX."products p WHERE p.`IsApproved`=1
and (p.`IsDeleted`=0 or p.`IsDeleted` is null)
and (p.`isprohibited`=0 or p.`isprohibited` is null)
and p.`islinkedwithpaygear`=1
and (p.`paygear_productid` is not null and p.`paygear_productid`>0) order by name"; */
$query=" SELECT id,name FROM ".TABLE_PREFIX."products p
where isonetimeoffer != 1 and productstatusid!=3
and isprohibited != 1
and isDeleted != 1
and IsApproved = 1
and islinkedwithpaygear = 1
and (`paygear_productid` is not null and `paygear_productid`>0)
and (`scop` = 'Visible' or p.`scop`='Member')
and ifnull(onetimeofferproductid,0) = 0 order by name";
}
else
{
/* $query= "SELECT id,name FROM ".TABLE_PREFIX."products p WHERE p.id!=$pProductid p.`IsApproved`=1
and (p.`IsDeleted`=0 or p.`IsDeleted` is null)
and (p.`isprohibited`=0 or p.`isprohibited` is null)
and p.`islinkedwithpaygear`=1
and (p.`paygear_productid` is not null and p.`paygear_productid`>0) order by name"; */
$query=" SELECT id,name FROM ".TABLE_PREFIX."products p
where id!=$pProductid and isonetimeoffer != 1 and productstatusid!=3
and isprohibited != 1
and isDeleted != 1
and IsApproved = 1
and islinkedwithpaygear = 1
and (`paygear_productid` is not null and `paygear_productid`>0)
and (`scop` = 'Visible' or p.`scop`='Member')
and ifnull(onetimeofferproductid,0) = 0 order by name";
}
$result = $this->View($query);
if(is_array($result))
{
if(sizeof($result))
{
$laallProduct=array();
foreach($result as $key=>$value)
{
$laallProduct[$value['id']]=$value['name'];
}
}
else
{
$laallProduct=null;
}
}
else
{
$laallProduct=null;
}
return $laallProduct;
}
function IsParentofontimeofferproduct($pProductid)
{
$result=false;
$lsvalues=array();
$lsvalues[]=$pProductid;
$query=" SELECT id FROM ".TABLE_PREFIX."products p where onetimeofferproductid=?";
$result = $this->View($query,$lsvalues,null);
if(is_array($result))
{
if(sizeof($result))
{
$result=true;
}
}
else
{
$result=false;
}
return $result;
}
function getRenwalProductRecord($pProd,$pProduser)
{
$prodid=null;
$masterclassObj=new master_class();
$masterId=$masterclassObj->getMasterId("productmembershipstatus");
$masterValuesId=$masterclassObj->getMasterValuesId("Expire",$masterId);
$getRenwalProductQuery ="SELECT p.`productid` FROM ".TABLE_PREFIX."product_users p
WHERE p.`paygear_epaymentstatus`=1
and (p.`productid`=$pProd )
and (p.`userid`=$pProduser ) and (p.`productmembershipstatusid`=$masterValuesId)";
$res=$this->View($getRenwalProductQuery);
$prodid=$res[0]['productid'];
return $prodid;
}
function getRenwalProductGroup($pProd)
{
$getRenwalProductQuery ="SELECT p.`renewalgroup` FROM ".TABLE_PREFIX."products p
WHERE p.`id`=$pProd ";
$res=$this->View($getRenwalProductQuery);
$prodid=$res[0]['renewalgroup'];
return $prodid;
}
function get_all_list_mailpro_lists()
{
$listMailPro_Host=LISTMAIL_HOST;
$listMailPro_user=LISTMAIL_USERNAME;
$listMailPro_Password=LISTMAIL_PASSWORD;
$listMailPro_Db=LISTMAIL_DB;
$listMailPro_Table_Prefix=LISTMAIL_TABLE_PREFIX;
$listMailProResult=array();
if($db = @mysql_connect($listMailPro_Host, $listMailPro_user, $listMailPro_Password))
{
$linkid =@mysql_connect($listMailPro_Host,$listMailPro_user,$listMailPro_Password);
if(@mysql_select_db($listMailPro_Db, $linkid))
{
if($listMailPro_Table_Prefix!="" or $listMailPro_Table_Prefix!=NULL)
$ListMailProQuery="SELECT id, listnum,title FROM ".$listMailPro_Table_Prefix."lm_lists";
else
$ListMailProQuery="SELECT id, listnum,title FROM lm_lists";
$ListResult=mysql_query($ListMailProQuery,$linkid);
if($ListResult!=false)
{
if(mysql_num_rows($ListResult)>0)
{
while($row= mysql_fetch_assoc($ListResult))
{
$listMailProResult[]=$row;
}
}
else
return 'false';
}
else
return 'false';
}
else
return 'false';
}
else
return 'false';
return $listMailProResult;
}
function get_list_mailpro_user($pemail,$pListNum)
{
$listMailPro_Host=LISTMAIL_HOST;
$listMailPro_user=LISTMAIL_USERNAME;
$listMailPro_Password=LISTMAIL_PASSWORD;
$listMailPro_Db=LISTMAIL_DB;
$listMailPro_Table_Prefix=LISTMAIL_TABLE_PREFIX;
$listMailProResult=array();
if($db = @mysql_connect($listMailPro_Host, $listMailPro_user, $listMailPro_Password))
{
$linkid =@mysql_connect($listMailPro_Host,$listMailPro_user,$listMailPro_Password);
if(@mysql_select_db($listMailPro_Db, $linkid))
{
if($listMailPro_Table_Prefix!="" or $listMailPro_Table_Prefix!=NULL)
$ListMailProUserQuery="SELECT * FROM ".$listMailPro_Table_Prefix."lm_users where email=\"$pemail\" and list=$pListNum";
else
$ListMailProUserQuery="SELECT * FROM lm_users email=\"$pemail\"";
$ListUserResult=mysql_query($ListMailProUserQuery,$linkid);
if($ListUserResult!=false)
{
if(mysql_num_rows($ListUserResult)>0)
{
while($row= mysql_fetch_assoc($ListUserResult))
{
$listMailProUserResult[]=$row;
}
}
else
return 'false';
}
else
return 'false';
}
else
return 'false';
}
else
return 'false';
return $listMailProUserResult[0];
}
function getListMailPro_Value_for_product($pProd)
{
$getListMailProdId ="SELECT p.`listmail_groupid` FROM ".TABLE_PREFIX."products p WHERE p.`id`=$pProd ";
$res=$this->View($getListMailProdId);
$listmailVal=$res[0]['listmail_groupid'];
return $listmailVal;
}
function isMainUpsellProduct($productID)
{
$query="select * from ".TABLE_PREFIX."productupsells where mainproductid=$productID";
$res=$this->View($query);
return $res;
}
function getimnicamail_Value_for_product($pProd)
{
$getImnicallistId ="SELECT p.`imnica_listname` FROM ".TABLE_PREFIX."products p WHERE p.`id`=$pProd ";
$res=$this->View($getImnicallistId);
$imnicaVal=$res[0]['imnica_listname'];
return $imnicaVal;
}
function getAweber_Value_for_product($pProd)
{
$getAweberlist ="SELECT p.`aweber_listname` FROM ".TABLE_PREFIX."products p WHERE p.`id`=$pProd ";
$res=$this->View($getAweberlist);
$aweberVal=$res[0]['aweber_listname'];
return $aweberVal;
}
function getGetResponse_Value_for_product($pProd)
{
$getgetResponselist ="SELECT p.`getresponse_listname` FROM ".TABLE_PREFIX."products p WHERE p.`id`=$pProd ";
$res=$this->View($getgetResponselist);
$getResponseVal=$res[0]['getresponse_listname'];
return $getResponseVal;
}
function GetPaygearProductPaymentCommisioninfo($plapaygeardatinfo)
{
// $lapaygeardatinfo=$PaygearWebserviceClient->GetPaygearProduct(164);
$lapaygearupdateinfo=array();
$sp="!@#$%^*()";
foreach($plapaygeardatinfo as $key=>$value)
{
$value1=str_replace($sp,'|',$value);
$value2=strtolower(substr($value1,0,strpos($value1,'|')));
if($value2=="CommissionID")
{
$value2='paygear_CommissionID';
}
$arrayvaue=substr($value1,strpos($value1,'|')+1);
if($arrayvaue=="True")
{
$arrayvaue=1;
}
if($arrayvaue=="False")
{
$arrayvaue=0;
}
$lapaygearupdateinfo[$value2]=$arrayvaue;
}
return $lapaygearupdateinfo;
}
function getAllUpsellSubProducts()
{
$query= "SELECT GROUP_CONCAT(yesbuttonupsellproductid) as products FROM ".TABLE_PREFIX."productupsells";
$result = $this->View($query);
return $result;
}
}
?>