<?php
require_once "../config/config.php";
require_once INCLUDE_DIR."/users_class.php";
require_once INCLUDE_DIR."/master_class.php";
require_once INCLUDE_DIR."/folderProtection.php";
require_once INCLUDE_DIR."/product_class.php";
require_once INCLUDE_DIR."/passgen.php";
require_once INCLUDE_DIR."/product_protection_class.php";
$users = new users_class();
if($_SERVER['REQUEST_METHOD']=="GET")
$_SESSION[SESSION_PREFIX.'page_referrer']=$_SERVER['HTTP_REFERER'];
if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can view protect folders')==false)
{
Redirect('admin_nopermission.php',true);
}
if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can manage protect folders')==false)
{
Redirect('admin_nopermission.php',true);
}
switch($_action)
{
case 'insert':
$lsFolder_path=trim($_POST['txtprodurl']);
$lsreletiveUrl=WEB_URL.$lsFolder_path;
$objProductProtection=new product_protection_class();
$lsAradyProtected=$objProductProtection->isAlreadyProtectedFile($lsFolder_path);
$dripname=trim($_POST['filename']);
$lsSubscription=$_POST['products'];
$status=trim($_POST['ddlstatus']);
$showHome=trim($_POST['showHome']);
$isfree=trim($_POST['isfree']);
$trackType=trim($_POST['trackType']);
$sortorder=trim($_POST['txtsortorder']);
$fromdays='';
$uptodays='';
$clicks='';
$fromfixeddate='';
$uptofixeddate='';
if($trackType==1)
{
$fromdays=trim($_POST['startday']);
$uptodays=trim($_POST['endday']);
}
else if($trackType==2)
$clicks=trim($_POST['numberOfClicks']);
else if($trackType==3)
{
$fromfixeddate=strtotime(trim($_POST['startdate'])) ;
$uptofixeddate=strtotime(trim($_POST['enddate']));
}
$lsUrl=trim(dirname(PHYSICAL_DIR.$lsFolder_path));
if(!$lsAradyProtected)
{
if(file_exists($lsUrl))
{
if(is__writable($lsUrl."/"))
{
$objProtecfolderProtection_Class=new ProtecfolderProtection_Class();
$filecreationHtaccess=$objProtecfolderProtection_Class->createModRewriteHtaccess($lsUrl."/");
if($filecreationHtaccess )
{
$objProductProtection=new product_protection_class();
$length=sizeof($lsSubscription);
for($i=0;$i<$length;$i++)
{
$arrLsValue=array();
$arrLsValue[] = $lsSubscription[$i];
$arrLsValue[] = $dripname;
$arrLsValue[] = $lsFolder_path;
$arrLsValue[] = $status;
$arrLsValue[] = $showHome;
$arrLsValue[] = $isfree;
$arrLsValue[] = $trackType;
$arrLsValue[] = $fromdays;
$arrLsValue[] = $uptodays;
$arrLsValue[] = $clicks;
$arrLsValue[] = $fromfixeddate;
$arrLsValue[] = $uptofixeddate;
if($sortorder!='')
$arrLsValue[] = $sortorder;
else
$arrLsValue[] = 0;
$query="insert into ".TABLE_PREFIX."drips(product_id,filename,fileurl,status,showondefaultpage,isfilefree,trackingtype,
fromdays,uptodays,clicks,fromfixeddate,uptofixeddate,sortorder)
values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
$objProductProtection->Insert($query,$arrLsValue,null);
}
$message->SetMessage('drip system apply to file successfully.');
}
else
{
if($filecreationHtaccess!=true)
$msg="Please change ".dirname($lsFolder_path)."/.htaccess"." file permission to Read and Write.";
$products = new product_class();
$result = $products->GetUserProduct();
$smarty->assign('err','true');
$smarty->assign('msg',$msg);
$smarty->assign('products',$result);
$smarty->assign('editProducts',$_POST['products']);
$smarty->assign('filename',$dripname);
$smarty->assign('file',$_POST['txtprodurl']);
$smarty->assign('status',$status);
$smarty->assign('show_home',$showHome);
$smarty->assign('isfree',$isfree);
$smarty->assign('trackType',$trackType);
$smarty->assign('startday',$fromdays);
$smarty->assign('endday',$uptodays);
$smarty->assign('noclicks',$clicks);
$smarty->assign('startdate',$_POST['startdate']);
$smarty->assign('enddate',$_POST['enddate']);
$smarty->assign('sortorder',$_POST['txtsortorder']);
$smarty->assign('postback','true');
$smarty->assign('protection',$protection);
$smarty->assign('browsPath',$lsFolder_path);
$smarty->display('admin_drip_system_m.tpl');
break;
}
}
else
{
$msg="Please change ".dirname($lsFolder_path)." folder permission to Read and Write.";
$products = new product_class();
$result = $products->GetUserProduct();
$smarty->assign('err','true');
$smarty->assign('msg',$msg);
$smarty->assign('products',$result);
$smarty->assign('editProducts',$_POST['products']);
$smarty->assign('filename',$dripname);
$smarty->assign('file',$_POST['txtprodurl']);
$smarty->assign('status',$status);
$smarty->assign('show_home',$showHome);
$smarty->assign('isfree',$isfree);
$smarty->assign('trackType',$trackType);
$smarty->assign('startday',$fromdays);
$smarty->assign('endday',$uptodays);
$smarty->assign('noclicks',$clicks);
$smarty->assign('startdate',$_POST['startdate']);
$smarty->assign('enddate',$_POST['enddate']);
$smarty->assign('sortorder',$_POST['txtsortorder']);
$smarty->assign('postback','true');
$smarty->assign('protection',$protection);
$smarty->assign('browsPath',$lsFolder_path);
$smarty->display('admin_drip_system_m.tpl');
break;
}
}
else
$message->SetMessage('No such folder exist');
if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
else
Redirect('admin_drip_v.php');
}
else
{
$msg="This file is already in drip system.";
$products = new product_class();
$result = $products->GetUserProduct();
$smarty->assign('err','true');
$smarty->assign('msg',$msg);
$smarty->assign('products',$result);
$smarty->assign('editProducts',$_POST['products']);
$smarty->assign('filename',$dripname);
$smarty->assign('file',$_POST['txtprodurl']);
$smarty->assign('status',$status);
$smarty->assign('show_home',$showHome);
$smarty->assign('isfree',$isfree);
$smarty->assign('trackType',$trackType);
$smarty->assign('startday',$fromdays);
$smarty->assign('endday',$uptodays);
$smarty->assign('noclicks',$clicks);
$smarty->assign('startdate',$_POST['startdate']);
$smarty->assign('enddate',$_POST['enddate']);
$smarty->assign('sortorder',$_POST['txtsortorder']);
$smarty->assign('postback','true');
$smarty->assign('protection',$protection);
$smarty->assign('browsPath',$lsFolder_path);
$smarty->display('admin_drip_system_m.tpl');
break;
}
break;
case 'update':
$id=$_POST['editId'];
$lsFolder_path=trim($_POST['txtprodurl']);
$lsreletiveUrl=WEB_URL.$lsFolder_path;
$lsSubscription=$_POST['products'];
$productIds=(implode(',',$lsSubscription));
$lsUrl=trim(dirname(PHYSICAL_DIR.$lsFolder_path));
if(file_exists($lsUrl))
{
if(is__writable($lsUrl."/"))
{
$objProtecfolderProtection_Class=new ProtecfolderProtection_Class();
$filecreationHtaccess=$objProtecfolderProtection_Class->createModRewriteHtaccess($lsUrl."/");
if($filecreationHtaccess )
{
$objProductProtection=new product_protection_class();
$folderSelectionQuery="select fileurl from ".TABLE_PREFIX."drips where id=$id";
$resfolderSelectionQuery=$objProductProtection->view($folderSelectionQuery);
$folder= $resfolderSelectionQuery[0]['fileurl'];
$delSelectQuery="select id from ".TABLE_PREFIX."drips
where fileurl = (select fileurl from ".TABLE_PREFIX."drips where id =$id ) and product_id not in($productIds)";
$resDelSelectQuery=$objProductProtection->view($delSelectQuery);
if($resDelSelectQuery!=false)
{
if(sizeof($resDelSelectQuery)>0)
{
$i=0;
foreach($resDelSelectQuery as $key=>$value)
{
$lProduct[$i]=$value['id'];
$i++;
}
$impoledValue=(implode(',',$lProduct));
$query="delete from ".TABLE_PREFIX."drips where id in($impoledValue)";
$resDelete=$objProductProtection->delete($query);
}
}
$dripname=trim($_POST['filename']);
$lsSubscription=$_POST['products'];
$status=trim($_POST['ddlstatus']);
$showHome=trim($_POST['showHome']);
$isfree=trim($_POST['isfree']);
$trackType=trim($_POST['trackType']);
$sortorder=trim($_POST['txtsortorder']);
$fromdays='';
$uptodays='';
$clicks='';
$fromfixeddate='';
$uptofixeddate='';
if($trackType==1)
{
$fromdays=trim($_POST['startday']);
$uptodays=trim($_POST['endday']);
}
else if($trackType==2)
$clicks=trim($_POST['numberOfClicks']);
else if($trackType==3)
{
$fromfixeddate=strtotime((trim($_POST['startdate'])));
$uptofixeddate=strtotime((trim($_POST['enddate'])));
}
$objProductProtection=new product_protection_class();
$length=sizeof($lsSubscription);
for($i=0;$i<$length;$i++)
{
$query2="select * from ".TABLE_PREFIX."drips where
product_id=$lsSubscription[$i]
and fileurl='$folder'";
$result2=$objProductProtection->View($query2);
if(isset($result2[0]['id']))
{
$arrLsValue=array();
$arrLsValue[]=$dripname;
$arrLsValue[]=$status;
$arrLsValue[]=$showHome;
$arrLsValue[]=$isfree;
$arrLsValue[]=$trackType;
$arrLsValue[]=$fromdays;
$arrLsValue[]=$uptodays;
$arrLsValue[]=$clicks;
$arrLsValue[]=$fromfixeddate;
$arrLsValue[]=$uptofixeddate;
if($sortorder!='')
$arrLsValue[]=$sortorder;
else
$arrLsValue[]=0;
$updateId=$result2[0]['id'];
$updateQuery="update ".TABLE_PREFIX."drips set filename=?,
status=?,showondefaultpage=?,
isfilefree=?,trackingtype=?,fromdays=?,uptodays=?,
clicks=?,fromfixeddate=?,uptofixeddate=?,sortorder=?
where id=".$result2[0]['id'];
$objProductProtection->Update($updateQuery,$arrLsValue,null);
}
else
{
$objProductProtection=new product_protection_class();
$arrLsValue=array();
$arrLsValue[]=$lsSubscription[$i];
$arrLsValue[]=$dripname;
$arrLsValue[]=trim($_POST['txtprodurl']);
$arrLsValue[]=$status;
$arrLsValue[]=$showHome;
$arrLsValue[]=$isfree;
$arrLsValue[]=$trackType;
$arrLsValue[]=$fromdays;
$arrLsValue[]=$uptodays;
$arrLsValue[]=$clicks;
$arrLsValue[]=$fromfixeddate;
$arrLsValue[]=$uptofixeddate;
if($sortorder!='')
$arrLsValue[]=$sortorder;
else
$arrLsValue[]=0;
$query="insert into ".TABLE_PREFIX."drips(product_id,filename,fileurl,status,showondefaultpage,isfilefree,trackingtype,
fromdays,uptodays,clicks,fromfixeddate,uptofixeddate,sortorder)
values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
$objProductProtection->Insert($query,$arrLsValue,null);
}
}
$msg="Drip system apply to file successfully.";
}
else
{
if($filecreationHtaccess!=true)
$msg="Please change ".dirname($lsFolder_path)."/.htaccess"." file permission to Read and Write.";
$lsProduct_protection=new product_protection_class();
$lsId=$_POST['editId'];
$lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
$products = new product_class();
$result = $products->GetUserProduct();
$product_result=$lsProduct_protection->getSpecificDripInfo($lsId);
$selectedProduct=$lsProduct_protection->getDripOnEdit($lsId);
$smarty->assign('products',$result);
$smarty->assign('editProducts',$selectedProduct);
$smarty->assign('filename',$product_result[0]['filename']);
$smarty->assign('file',$product_result[0]['fileurl']);
$smarty->assign('status',$product_result[0]['status']);
$smarty->assign('show_home',$product_result[0]['showondefaultpage']);
$smarty->assign('isfree',$product_result[0]['isfilefree']);
$smarty->assign('trackType', $product_result[0]['trackingtype'] );
$smarty->assign('startday', $product_result[0]['fromdays'] );
$smarty->assign('endday',$product_result[0]['uptodays'] );
$smarty->assign('noclicks',$product_result[0]['clicks']);
$stdate='';
if($product_result[0]['fromfixeddate']!="")
$stdate=date("m/d/Y",$product_result[0]['fromfixeddate']);
$edate='';
if($product_result[0]['uptofixeddate']!="")
$edate=date("m/d/Y",$product_result[0]['uptofixeddate']);
$smarty->assign('startdate',$stdate);
$smarty->assign('enddate',$edate);
$smarty->assign('sortorder',$product_result[0]['sortorder']);
$smarty->assign('browsPath',$product_result[0]['fileurl']);
$smarty->assign('IsEdit','yes');
$smarty->assign('editId',$lsId);
$smarty->assign('msg',$msg);
$smarty->display('admin_drip_system_m.tpl');
exit;
}
}
else
{
$msg="Please change ".dirname($lsFolder_path)."/.htaccess"." file permission to Read and Write.";
$lsProduct_protection=new product_protection_class();
$lsId=$_POST['editId'];
$lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
$products = new product_class();
$result = $products->GetUserProduct();
$product_result=$lsProduct_protection->getSpecificDripInfo($lsId);
$selectedProduct=$lsProduct_protection->getDripOnEdit($lsId);
$smarty->assign('products',$result);
$smarty->assign('editProducts',$selectedProduct);
$smarty->assign('filename',$product_result[0]['filename']);
$smarty->assign('file',$product_result[0]['fileurl']);
$smarty->assign('status',$product_result[0]['status']);
$smarty->assign('show_home',$product_result[0]['showondefaultpage']);
$smarty->assign('isfree',$product_result[0]['isfilefree']);
$smarty->assign('trackType', $product_result[0]['trackingtype'] );
$smarty->assign('startday', $product_result[0]['fromdays'] );
$smarty->assign('endday',$product_result[0]['uptodays'] );
$smarty->assign('noclicks',$product_result[0]['clicks']);
$stdate='';
if($product_result[0]['fromfixeddate']!="")
$stdate=date("m/d/Y",$product_result[0]['fromfixeddate']);
$edate='';
if($product_result[0]['uptofixeddate']!="")
$edate=date("m/d/Y",$product_result[0]['uptofixeddate']);
$smarty->assign('startdate',$stdate);
$smarty->assign('enddate',$edate);
$smarty->assign('sortorder',$product_result[0]['sortorder']);
$smarty->assign('browsPath',$product_result[0]['fileurl']);
$smarty->assign('IsEdit','yes');
$smarty->assign('editId',$lsId);
$smarty->assign('msg',$msg);
$smarty->display('admin_drip_system_m.tpl');
exit;
}
}
else
{
$msg='No such folder/file exist';
Redirect("admin_drip_v.php");
exit;
}
$message->SetMessage($msg);
if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
else
Redirect('admin_drip_v.php');
break;
case 'delete':
$lsId=$_GET['id'];
$objProductProtection=new product_protection_class();
$folderSelectionQuery="select fileurl from ".TABLE_PREFIX."drips where id=$lsId";
$resfolderSelectionQuery=$objProductProtection->view($folderSelectionQuery);
$folder= $resfolderSelectionQuery[0]['fileurl'];
$lsDelFolderPth=trim(PHYSICAL_DIR).trim($folder);
$lsDelFolderPth=dirname($lsDelFolderPth);
if(file_exists($lsDelFolderPth."/.htaccess"))
{
if(is__writable($lsDelFolderPth."/"))
{
if(is_writable($lsDelFolderPth."/.htaccess"))
unlink($lsDelFolderPth."/.htaccess");
else
{
$msg="Please change ".$folder."/.htaccess"." file permission to Read and Write.";
$message->SetMessage($msg);
Redirect('admin_drip_v.php?err=true');
exit();
}
}
else
{
$msg="Please change ".$lsDelFolderPth." folder permission to Read and Write.";
$message->SetMessage($msg);
Redirect('admin_drip_v.php?err=true');
exit();
}
}
$deleteFolderQuery="delete from ".TABLE_PREFIX."drips where locate(fileurl,'$folder')>0";
$resDelete=$objProductProtection->delete($deleteFolderQuery);
$message->SetMessage('file protection removed successfully.');
$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_drip_v.php?$quest");
break;
case 'edit':
$lsProduct_protection=new product_protection_class();
$lsId=$_GET['id'];
$lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
$products = new product_class();
$result = $products->GetUserProduct();
$product_result=$lsProduct_protection->getSpecificDripInfo($lsId);
$selectedProduct=$lsProduct_protection->getDripOnEdit($lsId);
$smarty->assign('products',$result);
$smarty->assign('editProducts',$selectedProduct);
$smarty->assign('filename',$product_result[0]['filename']);
$smarty->assign('file',$product_result[0]['fileurl']);
$smarty->assign('status',$product_result[0]['status']);
$smarty->assign('show_home',$product_result[0]['showondefaultpage']);
$smarty->assign('isfree',$product_result[0]['isfilefree']);
$smarty->assign('trackType', $product_result[0]['trackingtype'] );
$smarty->assign('startday', $product_result[0]['fromdays'] );
$smarty->assign('endday',$product_result[0]['uptodays'] );
$smarty->assign('noclicks',$product_result[0]['clicks']);
$smarty->assign('sortorder',$product_result[0]['sortorder']);
$stdate='';
if($product_result[0]['fromfixeddate']!="")
$stdate=date("m/d/Y",$product_result[0]['fromfixeddate']);
$edate='';
if($product_result[0]['uptofixeddate']!="")
$edate=date("m/d/Y",$product_result[0]['uptofixeddate']);
$smarty->assign('startdate',$stdate);
$smarty->assign('enddate',$edate);
$smarty->assign('browsPath',$product_result[0]['fileurl']);
$smarty->assign('IsEdit','yes');
$smarty->assign('editId',$lsId);
$smarty->display('admin_drip_system_m.tpl');
break;
default:
$lsProtection_technique=new master_class();
$lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
$products = new product_class();
$result = $products->GetUserProduct();
$protection=$lsProtection_technique->View('protectionmethod');
$prodarrLen=sizeof($result);
$smarty->assign('products',$result);
$smarty->assign('productslen',$prodarrLen);
$smarty->assign('protection',$protection);
$smarty->assign('browsPath',$lsPathOfBroseDir);
$smarty->display('admin_drip_system_m.tpl');
}
?>