Location: PHPKode > projects > MembersGear > membersgear/admin/admin_protected_folder.php
<?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['folder']); 
            $lsreletiveUrl=WEB_URL.$lsFolder_path;
            $objProductProtection=new product_protection_class();
            $lsAradyProtected=$objProductProtection->isAlreadyProtected($lsFolder_path);
            if(!$lsAradyProtected)
              {
            
                    $lsProtection_Method=$_POST['protection_method'];
                    $lsSubscription=$_POST['products'];
                    $lsInvalidAccessMessageShowHide=$_POST['show_iam'];
                    if($lsInvalidAccessMessageShowHide==1)
                     {
                       $lsInvalidAccessMessage=$_POST['invalid_access_message'];
                     }
                    else
                       $lsInvalidAccessMessage=NULL;
                     
                    
                    
                    $masterclassObj                =new master_class();
                    $mastervalue                   =$masterclassObj->getValueFromID($lsProtection_Method);
                 
                 
                     if($mastervalue==".htaccess")
                      {
                         $lsUrl=trim(PHYSICAL_DIR.$lsFolder_path."/");
                         if(file_exists($lsUrl))
                           {  
                                
                                  if(is__writable($lsUrl))
                                       {      
                                              $objProtecfolderProtection_Class=new ProtecfolderProtection_Class();
                                              
                                              $filecreationHtaccess=$objProtecfolderProtection_Class->createHtaccess($lsUrl);
                                              
                                                          if($filecreationHtaccess)
                                                           {
                                                          
                                                                  $filecreationHtpass=$objProtecfolderProtection_Class->createPasswdfile($lsUrl,$lsSubscription);  
                                                                  
                                                                  if($filecreationHtpass)
                                                                    {
                                                                          $objProductProtection=new product_protection_class();
                                                                          $length=sizeof($lsSubscription);
                                                                        
                                                                        
                                                                            for($i=0;$i<$length;$i++)
                                                                              {
                                                                                  $arrLsValue=array();
                                                                                  $arrLsValue[] = $lsFolder_path;
                                                                                  $arrLsValue[] = $lsProtection_Method;
                                                                                  $arrLsValue[] = $lsSubscription[$i];
                                                                                  $arrLsValue[] = $lsInvalidAccessMessageShowHide;
                                                                                  $arrLsValue[] = $lsInvalidAccessMessage;
                                                                                  $arrLsValue[] = mktime();
                                                                                  $arrLsValue[] = $_SESSION[SESSION_PREFIX.'Admin_UserID'];
                                                                                  $arrLsValue[] = $_SERVER['REMOTE_ADDR'];
                                                                                  $query="insert into ".TABLE_PREFIX."product_protect(folder,protection_method,allowed_productid,is_invalid_access_message,invalid_access_message,createdon,createdby,createdipaddress)
                                                                                          values(?,?,?,?,?,?,?,?)";
                                                                                  $objProductProtection->Insert($query,$arrLsValue,null);         
                                                                                  
                                                                              }
                                                                           
                                                                            $message->SetMessage('Folder protected successfully by HTACCESS method');
                                                                     } 
                                                                    else
                                                                     {
                                                                            $msg="Please change ".$lsFolder_path."/.htpasswd"."<br>file permission to Read and Write"; 
                                                                            $smarty->assign('err','true');
                                                                            $smarty->assign('msg',$msg);
                                                                            $products = new product_class();
                                                                            $result = $products->GetUserProduct();
                                                                            $smarty->assign('msg',$msg);
                                                                            $smarty->assign('products',$result);
                                                                            $smarty->assign('editProducts',$_POST['products']);
                                                                            $smarty->assign('folder',$_POST['folder']);
                                                                            $smarty->assign('protection_method',$_POST['protection_method']);
                                                                            $smarty->assign('invalid_access',$_POST['show_iam']);
                                                                            $smarty->assign('invalid_access_message',$_POST['invalid_access_message']);
                                                                            $lsProtection_technique=new master_class(); 
                                                                            $protection=$lsProtection_technique->View('protectionmethod');
                                                                            $smarty->assign('protection',$protection);
                                                                            $smarty->assign('postback','true');
                                                                          
                                                                            $smarty->assign('protection',$protection);
                                                                            $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                                            $smarty->display('admin_protected_folder.tpl'); 
                                                                            break;
                                                                         
                                                                     }  
                                                           } 
                                                          else
                                                           {
                                                                $msg="Please change ".$lsFolder_path."/.htaccess"."<br>file permission to Read and Write"; 
                                                                $smarty->assign('msg',$msg);
                                                                $smarty->assign('err','true');
                                                                $products = new product_class();
                                                                $result = $products->GetUserProduct();
                                                                $smarty->assign('msg',$msg);   
                                                                $smarty->assign('products',$result);
                                                                $smarty->assign('editProducts',$_POST['products']);
                                                                $smarty->assign('folder',$_POST['folder']);
                                                                $smarty->assign('protection_method',$_POST['protection_method']);
                                                                $smarty->assign('invalid_access',$_POST['show_iam']);
                                                                $smarty->assign('invalid_access_message',$_POST['invalid_access_message']);
                                                                $lsProtection_technique=new master_class(); 
                                                                $protection=$lsProtection_technique->View('protectionmethod');
                                                                $smarty->assign('protection',$protection);
                                                                $smarty->assign('postback','true');
                                                              
                                                                $smarty->assign('protection',$protection);
                                                                $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                                $smarty->display('admin_protected_folder.tpl'); 
                                                                break;
                                                      
                                                           }           
                                                         
                                            }
                                          else      
                                           {
                                               $msg="Please change ".$_POST['folder']."<br>folder permission to Read and Write"; 
                                               $smarty->assign('err','true');
                                               $smarty->assign('msg',$msg);
                                               $products = new product_class();
                                               $result = $products->GetUserProduct();
                                               $smarty->assign('msg',$msg);   
                                               $smarty->assign('products',$result);
                                               $smarty->assign('editProducts',$_POST['products']);
                                               $smarty->assign('folder',$_POST['folder']);
                                               $smarty->assign('protection_method',$_POST['protection_method']);
                                               $smarty->assign('invalid_access',$_POST['show_iam']);
                                               $smarty->assign('invalid_access_message',$_POST['invalid_access_message']);
                                                $lsProtection_technique=new master_class(); 
                                                $protection=$lsProtection_technique->View('protectionmethod');
                                                $smarty->assign('protection',$protection);
                                                $smarty->assign('postback','true');
                                              
                                                $smarty->assign('protection',$protection);
                                                $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                $smarty->display('admin_protected_folder.tpl'); 
                                                break;
                                           }    
                                            
                              }
                              else
                                $message->SetMessage('No such folder exist');           
                         }
                         elseif($mastervalue=="new_rewrite")
                         {
                                
                                 $lsUrl=trim(PHYSICAL_DIR.$lsFolder_path."/");
                                 
                                 if(file_exists($lsUrl))
                                  {  
                                          if(is__writable($lsUrl))
                                           {      
                                                 $objProtecfolderProtection_Class=new ProtecfolderProtection_Class();
                                                 $filecreationHtaccess=$objProtecfolderProtection_Class->createModRewriteHtaccess($lsUrl);
                                                 $filecreationPage_not_found=$objProtecfolderProtection_Class->create_page_not_found_php($lsUrl);
                                           
                                                      if($filecreationHtaccess && $filecreationPage_not_found)
                                                       {
                                                                  $objProductProtection=new product_protection_class();
                                                                  $length=sizeof($lsSubscription);
                                                            
                                    
                                                                    for($i=0;$i<$length;$i++)
                                                                      {
                                                                          $arrLsValue=array();
                                                                          $arrLsValue[] = $lsFolder_path;
                                                                          $arrLsValue[] = $lsProtection_Method;
                                                                          $arrLsValue[] = $lsSubscription[$i];
                                                                          $arrLsValue[] = $lsInvalidAccessMessageShowHide;
                                                                          $arrLsValue[] = $lsInvalidAccessMessage;
                                                                          $arrLsValue[] = mktime();
                                                                          $arrLsValue[] = $_SESSION[SESSION_PREFIX.'Admin_UserID'];
                                                                          $arrLsValue[] = $_SERVER['REMOTE_ADDR'];
                                                                          $query="insert into ".TABLE_PREFIX."product_protect(folder,protection_method,allowed_productid,is_invalid_access_message,invalid_access_message,createdon,createdby,createdipaddress)
                                                                                  values(?,?,?,?,?,?,?,?)";
                                                                          $objProductProtection->Insert($query,$arrLsValue,null);
                                                                      }
                                                                     $message->SetMessage('Folder protected successfully by NEW_REWRITE method');
                                                         }
                                                       else
                                                        {
                                                             if($filecreationHtaccess!=true)
                                                                 $msg="Please change ".$lsFolder_path."/.htaccess"."<br>file permission to Read and Write";           
                                                             else if($filecreationPage_not_found!=true)
                                                                 $msg="Please change ".$lsFolder_path."/page_not_found.php"."<br>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('folder',$_POST['folder']);
                                                               $smarty->assign('protection_method',$_POST['protection_method']);
                                                               $smarty->assign('invalid_access',$_POST['show_iam']);
                                                               $smarty->assign('invalid_access_message',$_POST['invalid_access_message']);
                                                               $lsProtection_technique=new master_class(); 
                                                               $protection=$lsProtection_technique->View('protectionmethod');
                                                               $smarty->assign('protection',$protection);
                                                               $smarty->assign('postback','true');
                                                              
                                                               $smarty->assign('protection',$protection);
                                                               $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                               $smarty->display('admin_protected_folder.tpl'); 
                                                               break;
                                                        
                                                        
                                                        
                                                        }               
                                                          
                                           }
                                          else      
                                           {
                                               $msg="Please change ".$_POST['folder']."<br>folder permission to Read and Write";           
                                               $products = new product_class();
                                               $smarty->assign('err','true');
                                               $result = $products->GetUserProduct();
                                               $smarty->assign('msg',$msg);   
                                               $smarty->assign('products',$result);
                                               $smarty->assign('editProducts',$_POST['products']);
                                               $smarty->assign('folder',$_POST['folder']);
                                               $smarty->assign('protection_method',$_POST['protection_method']);
                                               $smarty->assign('invalid_access',$_POST['show_iam']);
                                               $smarty->assign('invalid_access_message',$_POST['invalid_access_message']);
                                               $lsProtection_technique=new master_class(); 
                                               $protection=$lsProtection_technique->View('protectionmethod');
                                               $smarty->assign('protection',$protection);
                                               $smarty->assign('postback','true');
                                              
                                               $smarty->assign('protection',$protection);
                                               $smarty->assign('browsPath',$lsPathOfBroseDir);
                                               $smarty->display('admin_protected_folder.tpl'); 
                                               break;
                                           }    
                                     }
                                     else
                                      $message->SetMessage('No such folder exist');                                             
                        
                           } 
                         elseif($mastervalue=="php_include")
                            {
                                 $lsUrl=trim(PHYSICAL_DIR.$lsFolder_path."/");
                                 if(file_exists($lsUrl))
                                  {  
                                          if(is__writable($lsUrl))
                                           {      
                                                   $objProtecfolderProtection_Class=new ProtecfolderProtection_Class();
                                                   $filecreationHtaccess=$objProtecfolderProtection_Class->createPhpIncludeHtaccess($lsUrl);
                                                   $filecreationPage_not_found=$objProtecfolderProtection_Class->create_page_not_found_php($lsUrl);
                                                   $length=sizeof($lsSubscription);
                                            
                                                    if($filecreationHtaccess && $filecreationPage_not_found)
                                                     {
                                                            for($i=0;$i<$length;$i++)
                                                              {
                                                                  $arrLsValue=array();
                                                                  $arrLsValue[] = $lsFolder_path;
                                                                  $arrLsValue[] = $lsProtection_Method;
                                                                  $arrLsValue[] = $lsSubscription[$i];
                                                                  $arrLsValue[] = $lsInvalidAccessMessageShowHide;
                                                                  $arrLsValue[] = $lsInvalidAccessMessage;
                                                                  $arrLsValue[] = mktime();
                                                                  $arrLsValue[] = $_SESSION[SESSION_PREFIX.'Admin_UserID'];
                                                                  $arrLsValue[] = $_SERVER['REMOTE_ADDR'];
                                                                  $query="insert into ".TABLE_PREFIX."product_protect(folder,protection_method,allowed_productid,is_invalid_access_message,invalid_access_message,createdon,createdby,createdipaddress)
                                                                          values(?,?,?,?,?,?,?,?)";
                                                                  $objProductProtection->Insert($query,$arrLsValue,null);         
                                                                  
                                                              }
                                          
                                                                 $message->SetMessage('Folder protected successfully by PHP_INCLUDE method');
                                                     }
                                                   else
                                                     {
                                                           if($filecreationHtaccess!=true)
                                                             $msg="Please change ".$lsFolder_path."/.htaccess"."<br>file permission to Read and Write"; 
                                                           else if($filecreationPage_not_found!=true)
                                                             $msg="Please change ".$lsFolder_path."/page_not_found.php"."<br>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('folder',$_POST['folder']);
                                                           $smarty->assign('protection_method',$_POST['protection_method']);
                                                           $smarty->assign('invalid_access',$_POST['show_iam']);
                                                           $smarty->assign('invalid_access_message',$_POST['invalid_access_message']);
                                                           $lsProtection_technique=new master_class(); 
                                                           $protection=$lsProtection_technique->View('protectionmethod');
                                                           $smarty->assign('protection',$protection);
                                                           $smarty->assign('postback','true');
                                                          
                                                           $smarty->assign('protection',$protection);
                                                           $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                           $smarty->display('admin_protected_folder.tpl'); 
                                                            break;
                                                     
                                                     }            
                                           }
                                          else      
                                           {
                                                   $msg="Please change ".$_POST['folder']."<br>folder permission to Read and Write";     
                                                   $products = new product_class();
                                                   $result = $products->GetUserProduct();
                                                   $smarty->assign('products',$result);
                                                   $smarty->assign('err','true'); 
                                                   $smarty->assign('msg',$msg);   
                                                   $smarty->assign('editProducts',$_POST['products']);
                                                   $smarty->assign('folder',$_POST['folder']);
                                                   $smarty->assign('protection_method',$_POST['protection_method']);
                                                   $smarty->assign('invalid_access',$_POST['show_iam']);
                                                   $smarty->assign('invalid_access_message',$_POST['invalid_access_message']);
                                                   $lsProtection_technique=new master_class(); 
                                                   $protection=$lsProtection_technique->View('protectionmethod');
                                                   $smarty->assign('protection',$protection);
                                                   $smarty->assign('postback','true');
                                                  
                                                   $smarty->assign('protection',$protection);
                                                   $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                   $smarty->display('admin_protected_folder.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_protected_folder_v.php'); 
                          
            }
           else
            {
                  
                  $lsProtection_technique=new master_class();
                  $lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
                  $products = new product_class();
                  $result = $products->GetUserProduct();
                  $protection=$lsProtection_technique->View('protectionmethod');
                  $smarty->assign('products',$result);
                  $smarty->assign('protection',$protection);
                  $smarty->assign('browsPath',$lsPathOfBroseDir);
                  $smarty->assign('err','true');
                  $smarty->assign('msg','This Folder is already protected');
                  $smarty->display('admin_protected_folder.tpl');
            }    
                            
            break;
          case 'update':
                 $id=$_POST['editId'];
                 $lsFolder_path=trim($_POST['folder']); 
                 $lsreletiveUrl=WEB_URL.$lsFolder_path;
                 $objProductProtection=new product_protection_class();
                 $lsProtection_Method=$_POST['protection_method'];
                 $lsSubscription=$_POST['products'];
                 $lsInvalidAccessMessageShowHide=$_POST['show_iam'];
                        if($lsInvalidAccessMessageShowHide==1)
                         {
                           $lsInvalidAccessMessage=$_POST['invalid_access_message'];
                         }
                        else
                           $lsInvalidAccessMessage=NULL;
                 $productIds=(implode(',',$lsSubscription));
                                      
                    $masterclassObj                =new master_class();
                    $mastervalue                   =$masterclassObj->getValueFromID($lsProtection_Method);
                      if($mastervalue==".htaccess")
                      {
                         $lsUrl=trim(PHYSICAL_DIR.$lsFolder_path."/");
                         
                            if(file_exists($lsUrl))
                               {  
                                          
                                        if(is__writable($lsUrl))
                                         {    
                                              $objProtecfolderProtection_Class=new ProtecfolderProtection_Class();
                                              $filecreationHtaccess=$objProtecfolderProtection_Class->createHtaccess($lsUrl); 
                                              if($filecreationHtaccess)
                                               {
                                                    $filecreationPasss=$objProtecfolderProtection_Class->createPasswdfile($lsUrl,$lsSubscription);
                                                     if($filecreationPasss)
                                                     {
                                                       $mes='Folder protection updated successfully';
                                                     }
                                                     else
                                                      {
                                                      
                                                           $msg="Please change ".$lsFolder_path."/.htpassword"."<br>file permission to Read and Write"; 
                                                           $lsId=$_POST['editId'];
                                                          $lsProtection_technique=new master_class();
                                                          $lsProduct_protection=new product_protection_class();
                                                          $lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
                                                          $products = new product_class();
                                                          $result = $products->GetUserProduct();
                                                          $product_result=$lsProduct_protection->getSpecificProductInfo($lsId);
                                                          $protection=$lsProtection_technique->View('protectionmethod');
                                                          $selectedProduct=$lsProduct_protection->getProductsOnEdit($lsId);
                                                          $smarty->assign('products',$result);
                                                          $smarty->assign('err','true');
                                                          $smarty->assign('msg',$msg); 
                                                          $smarty->assign('editProducts',$selectedProduct);
                                                          $smarty->assign('folder',trim($product_result[0]['folder']));
                                                          $smarty->assign('protection_method',$product_result[0]['protection_method']);
                                                          $smarty->assign('invalid_access',$product_result[0]['is_invalid_access_message']);
                                                          $smarty->assign('invalid_access_message',trim($product_result[0]['invalid_access_message']));
                                                          
                                                          $smarty->assign('protection',$protection);
                                                          $smarty->assign('IsEdit','yes');
                                                          $smarty->assign('editId',$lsId);
                                                          
                                                          $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                          $smarty->display('admin_protected_folder.tpl');
                                                          break;
                                                      }     
                                               }
                                              else
                                               {
                                               
                                                      $msg="Please change ".$lsFolder_path."/.htaccess"."<br>file permission to Read and Write"; 
                                                        $lsId=$_POST['editId'];
                                                      $lsProtection_technique=new master_class();
                                                      $lsProduct_protection=new product_protection_class();
                                                      $lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
                                                      $products = new product_class();
                                                      $result = $products->GetUserProduct();
                                                      $product_result=$lsProduct_protection->getSpecificProductInfo($lsId);
                                                      $protection=$lsProtection_technique->View('protectionmethod');
                                                      $selectedProduct=$lsProduct_protection->getProductsOnEdit($lsId);
                                                      $smarty->assign('products',$result);
                                                      $smarty->assign('err','true');
                                                      $smarty->assign('msg',$msg); 
                                                      $smarty->assign('editProducts',$selectedProduct);
                                                      $smarty->assign('folder',trim($product_result[0]['folder']));
                                                      $smarty->assign('protection_method',$product_result[0]['protection_method']);
                                                      $smarty->assign('invalid_access',$product_result[0]['is_invalid_access_message']);
                                                      $smarty->assign('invalid_access_message',trim($product_result[0]['invalid_access_message']));
                                                      
                                                      $smarty->assign('protection',$protection);
                                                      $smarty->assign('IsEdit','yes');
                                                      $smarty->assign('editId',$lsId);
                                                      
                                                      $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                      $smarty->display('admin_protected_folder.tpl');
                                                      break;
                                               
                                               
                                               
                                               } 
                                              
                                         }
                                         else      
                                           {
                                                   $msg="Please change ".$_POST['folder']."<br>folder permission to Read and Write";  
                                                    $lsId=$_POST['editId'];
                                                      $lsProtection_technique=new master_class();
                                                      $lsProduct_protection=new product_protection_class();
                                                      $lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
                                                      $products = new product_class();
                                                      $result = $products->GetUserProduct();
                                                      $product_result=$lsProduct_protection->getSpecificProductInfo($lsId);
                                                      $protection=$lsProtection_technique->View('protectionmethod');
                                                      $selectedProduct=$lsProduct_protection->getProductsOnEdit($lsId);
                                                      $smarty->assign('products',$result);
                                                      $smarty->assign('err','true');
                                                      $smarty->assign('msg',$msg); 
                                                      $smarty->assign('editProducts',$selectedProduct);
                                                      $smarty->assign('folder',trim($product_result[0]['folder']));
                                                      $smarty->assign('protection_method',$product_result[0]['protection_method']);
                                                      $smarty->assign('invalid_access',$product_result[0]['is_invalid_access_message']);
                                                      $smarty->assign('invalid_access_message',trim($product_result[0]['invalid_access_message']));
                                                      
                                                      $smarty->assign('protection',$protection);
                                                      $smarty->assign('IsEdit','yes');
                                                      $smarty->assign('editId',$lsId);
                                                      
                                                      $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                      $smarty->display('admin_protected_folder.tpl');
                                                      break;
                                           }
                               }
                               else
                                  $mes='No such folder exist';
                                          
                                  
                      }
                       elseif($mastervalue=="new_rewrite")
                         {
                          
                              $lsUrl=trim(PHYSICAL_DIR.$lsFolder_path."/");
                                if(file_exists($lsUrl))
                               {  
                                           
                                           
                                           if(is__writable($lsUrl))
                                            { 
                              
                                              $objProtecfolderProtection_Class=new ProtecfolderProtection_Class();
                                              $filecreationHtaccess=$objProtecfolderProtection_Class->createModRewriteHtaccess($lsUrl);
                                               $filecreationPage_not_found=$objProtecfolderProtection_Class->create_page_not_found_php($lsUrl);
                                                                                           
                                              if($filecreationHtaccess && $filecreationPage_not_found)
                                               {
                                                 $mes='Folder protection updated successfully';
                                               }
                                              else
                                               {
                                                   if($filecreationHtaccess!=true) 
                                                      $msg="Please change ".$lsFolder_path."/.htaccess"."<br>file permission to Read and Write";
                                                    else if($filecreationPage_not_found!=true)
                                                      $msg="Please change ".$lsFolder_path."/page_not_found.php"."<br>file permission to Read and Write";
                                                        
                                                       $lsId=$_POST['editId'];
                                                      $lsProtection_technique=new master_class();
                                                      $lsProduct_protection=new product_protection_class();
                                                      $lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
                                                      $products = new product_class();
                                                      $result = $products->GetUserProduct();
                                                      $product_result=$lsProduct_protection->getSpecificProductInfo($lsId);
                                                      $protection=$lsProtection_technique->View('protectionmethod');
                                                      $selectedProduct=$lsProduct_protection->getProductsOnEdit($lsId);
                                                      $smarty->assign('products',$result);
                                                      $smarty->assign('err','true');
                                                      $smarty->assign('msg',$msg); 
                                                      $smarty->assign('editProducts',$selectedProduct);
                                                      $smarty->assign('folder',trim($product_result[0]['folder']));
                                                      $smarty->assign('protection_method',$product_result[0]['protection_method']);
                                                      $smarty->assign('invalid_access',$product_result[0]['is_invalid_access_message']);
                                                      $smarty->assign('invalid_access_message',trim($product_result[0]['invalid_access_message']));
                                                      
                                                      $smarty->assign('protection',$protection);
                                                      $smarty->assign('IsEdit','yes');
                                                      $smarty->assign('editId',$lsId);
                                                      
                                                      $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                      $smarty->display('admin_protected_folder.tpl');
                                                      break;
                                               
                                               
                                               }   
                                            }
                                           else      
                                            {
                                                     $msg="Please change ".$_POST['folder']."<br>folder permission to Read and Write";
                                                     $lsId=$_POST['editId'];
                                                      $lsProtection_technique=new master_class();
                                                      $lsProduct_protection=new product_protection_class();
                                                      $lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
                                                      $products = new product_class();
                                                      $result = $products->GetUserProduct();
                                                      $product_result=$lsProduct_protection->getSpecificProductInfo($lsId);
                                                      $protection=$lsProtection_technique->View('protectionmethod');
                                                      $selectedProduct=$lsProduct_protection->getProductsOnEdit($lsId);
                                                      $smarty->assign('products',$result);
                                                      $smarty->assign('err','true');
                                                      $smarty->assign('msg',$msg); 
                                                      $smarty->assign('editProducts',$selectedProduct);
                                                      $smarty->assign('folder',trim($product_result[0]['folder']));
                                                      $smarty->assign('protection_method',$product_result[0]['protection_method']);
                                                      $smarty->assign('invalid_access',$product_result[0]['is_invalid_access_message']);
                                                      $smarty->assign('invalid_access_message',trim($product_result[0]['invalid_access_message']));
                                                      
                                                      $smarty->assign('protection',$protection);
                                                      $smarty->assign('IsEdit','yes');
                                                      $smarty->assign('editId',$lsId);
                                                      
                                                      $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                      $smarty->display('admin_protected_folder.tpl');
                                                      break;
                                           }
                               }
                               else
                                  $mes='No such folder exist';               
                         }
                       elseif($mastervalue=="php_include")
                            {
                                  $lsUrl=trim(PHYSICAL_DIR.$lsFolder_path."/");
                                  if(file_exists($lsUrl))
                                  {  
                                           
                                       if(is__writable($lsUrl))
                                        {
                                          
                                              $objProtecfolderProtection_Class=new ProtecfolderProtection_Class();
                                              $filecreationHtaccess= $objProtecfolderProtection_Class->createPhpIncludeHtaccess($lsUrl);
                                              $filecreationPage_not_found=$objProtecfolderProtection_Class->create_page_not_found_php($lsUrl);
                                              
                                              if($filecreationHtaccess && $filecreationPage_not_found)
                                              {
                                                 $mes='Folder protection updated successfully';
                                              }
                                             else
                                              {    
                                                     if($filecreationHtaccess!=true)
                                                            $msg="Please change ".$lsFolder_path."/.htaccess"."<br>file permission to Read and Write";  
                                                     else if($filecreationPage_not_found!=true)
                                                           $msg="Please change ".$lsFolder_path."/.page_not_found"."<br>file permission to Read and Write";  
                                                           
                                                        $lsId=$_POST['editId'];
                                                      $lsProtection_technique=new master_class();
                                                      $lsProduct_protection=new product_protection_class();
                                                      $lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
                                                      $products = new product_class();
                                                      $result = $products->GetUserProduct();
                                                      $product_result=$lsProduct_protection->getSpecificProductInfo($lsId);
                                                      $protection=$lsProtection_technique->View('protectionmethod');
                                                      $selectedProduct=$lsProduct_protection->getProductsOnEdit($lsId);
                                                      $smarty->assign('products',$result);
                                                      $smarty->assign('err','true');
                                                      $smarty->assign('msg',$msg); 
                                                      $smarty->assign('editProducts',$selectedProduct);
                                                      $smarty->assign('folder',trim($product_result[0]['folder']));
                                                      $smarty->assign('protection_method',$product_result[0]['protection_method']);
                                                      $smarty->assign('invalid_access',$product_result[0]['is_invalid_access_message']);
                                                      $smarty->assign('invalid_access_message',trim($product_result[0]['invalid_access_message']));
                                                      
                                                      $smarty->assign('protection',$protection);
                                                      $smarty->assign('IsEdit','yes');
                                                      $smarty->assign('editId',$lsId);
                                                      
                                                      $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                      $smarty->display('admin_protected_folder.tpl');
                                                      break;
                                              
                                              
                                              } 
                                            
                                        }
                                     else      
                                           {
                                                     $msg="Please change ".$_POST['folder']."<br>folder permission to Read and Write";
                                                      $lsId=$_POST['editId'];
                                                      $lsProtection_technique=new master_class();
                                                      $lsProduct_protection=new product_protection_class();
                                                      $lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
                                                      $products = new product_class();
                                                      $result = $products->GetUserProduct();
                                                      $product_result=$lsProduct_protection->getSpecificProductInfo($lsId);
                                                      $protection=$lsProtection_technique->View('protectionmethod');
                                                      $selectedProduct=$lsProduct_protection->getProductsOnEdit($lsId);
                                                      $smarty->assign('products',$result);
                                                      $smarty->assign('err','true');
                                                      $smarty->assign('msg',$msg); 
                                                      $smarty->assign('editProducts',$selectedProduct);
                                                      $smarty->assign('folder',trim($product_result[0]['folder']));
                                                      $smarty->assign('protection_method',$product_result[0]['protection_method']);
                                                      $smarty->assign('invalid_access',$product_result[0]['is_invalid_access_message']);
                                                      $smarty->assign('invalid_access_message',trim($product_result[0]['invalid_access_message']));
                                                      
                                                      $smarty->assign('protection',$protection);
                                                      $smarty->assign('IsEdit','yes');
                                                      $smarty->assign('editId',$lsId);
                                                      
                                                      $smarty->assign('browsPath',$lsPathOfBroseDir);
                                                      $smarty->display('admin_protected_folder.tpl');
                                                      break;
                                           }
                                          
                                  } 
                                  else
                                     $mes='No such folder exist';                 
                            
                       }
                       
                 $objProductProtection=new product_protection_class();  
                 
                 $folderSelectionQuery="select folder from ".TABLE_PREFIX."product_protect where id=$id";
                 $resfolderSelectionQuery=$objProductProtection->view($folderSelectionQuery);
                 $folder= $resfolderSelectionQuery[0]['folder'];
            
                 $delSelectQuery="select id from ".TABLE_PREFIX."product_protect
                                 where folder = (select folder from ".TABLE_PREFIX."product_protect where id =$id ) and allowed_productid 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."product_protect where id in($impoledValue)";
                              $resDelete=$objProductProtection->delete($query);
                         } 
                  }           
                   $length=sizeof($lsSubscription);     
                   for($i=0;$i<$length;$i++)
                     {
                            $arrLsValue=array();
                            $arrLsValue[] = $lsProtection_Method;
                            $arrLsValue[] = $lsSubscription[$i];
                            $arrLsValue[] = $lsInvalidAccessMessageShowHide;
                            $arrLsValue[] = $lsInvalidAccessMessage;
                            $arrLsValue[] = mktime();
                            $arrLsValue[] = $_SESSION[SESSION_PREFIX.'Admin_UserID'];
                            $arrLsValue[] = $_SERVER['REMOTE_ADDR'];
                           
                                  
                           $query2="select * from ".TABLE_PREFIX."product_protect where allowed_productid=$lsSubscription[$i] 
                                and folder='$folder'";
                           $result2=$objProductProtection->View($query2);
                           if(isset($result2[0]['id']))
                            {
                                $updateId=$result2[0]['id'];
                                $updateQuery="update ".TABLE_PREFIX."product_protect set protection_method=?,allowed_productid=?,is_invalid_access_message=?,invalid_access_message=?,modifiedon=?,modifiedby=?,modifiedipaddress=?
                                                 where allowed_productid=$lsSubscription[$i] and id=$updateId"; 
          
                                      $objProductProtection->Update($updateQuery,$arrLsValue,null);         
                            }
                          else
                           {
                              $arrLsValue[] = $lsFolder_path;
                              $query="insert into ".TABLE_PREFIX."product_protect(protection_method,allowed_productid,is_invalid_access_message,invalid_access_message,createdon,createdby,createdipaddress,folder)
                                              values(?,?,?,?,?,?,?,?)";
                                      $objProductProtection->Insert($query,$arrLsValue,null);         
                                     
                           }       
                     } 
      
                 $message->SetMessage($mes);
                 if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
                      Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
                 else  
                   Redirect('admin_protected_folder_v.php'); 
                                                       

            break;
         case 'delete':
              $lsId=$_GET['id'];
              $objProductProtection=new product_protection_class();
               $folderSelectionQuery="select folder from ".TABLE_PREFIX."product_protect where id=$lsId";
              $resfolderSelectionQuery=$objProductProtection->view($folderSelectionQuery);
              $folder= $resfolderSelectionQuery[0]['folder'];
              
              $lsDelFolderPth=trim(PHYSICAL_DIR).trim($folder);
               if(file_exists($lsDelFolderPth."/.htaccess"))
                {
                     if(is__writable($lsDelFolderPth."/"))
                       {
                           if(is_writable($lsDelFolderPth."/.htaccess"))
                              unlink($lsDelFolderPth."/.htaccess");
                           else
                            {
                               $msg="Please change ".$folder."/.htaccess"."<br>file permission to Read and Write";  
                               $message->SetMessage($msg);     
                                Redirect('admin_protected_folder_v.php?err=true');  
                               exit();                   
                            }
                       }  
                      else
                       {
                           $msg="Please change ".$folder."<br>folder permission to Read and Write";
                            $message->SetMessage($msg);
                            Redirect('admin_protected_folder_v.php?err=true');  
                               exit();                   
                       }   
               
                }
                if(file_exists($lsDelFolderPth."/.htpasswd"))
                 {
                  
                      
                      if(is__writable($lsDelFolderPth."/"))  
                        {    
                           if(is_writable($lsDelFolderPth."/.htpasswd")) 
                             unlink($lsDelFolderPth."/.htpasswd");
                           else
                            {
                                $msg="Please change ".$folder."/.htpasswd"."<br>file permission to Read and Write"; 
                                $message->SetMessage($msg);
                                Redirect('admin_protected_folder_v.php?err=true');  
                                exit(); 
                            }  
                        } 
                      else
                       {
                          $msg="Please change ".$folder."<br>folder permission to Read and Write";
                           $message->SetMessage($msg);
                           Redirect('admin_protected_folder_v.php?err=true');  
                           exit();
                       
                       }  
                 }
                if(file_exists($lsDelFolderPth."/page_not_found.php"))
                 {
                  
                      
                      if(is__writable($lsDelFolderPth."/"))  
                        {    
                           if(is_writable($lsDelFolderPth."/page_not_found.php")) 
                             unlink($lsDelFolderPth."/page_not_found.php");
                           else
                            {
                                $msg="Please change ".$folder."/page_not_found"."<br>file permission to Read and Write"; 
                                $message->SetMessage($msg);
                                Redirect('admin_protected_folder_v.php?err=true');  
                                exit(); 
                            }  
                        } 
                      else
                       {
                          $msg="Please change ".$folder."<br>folder permission to Read and Write";
                           $message->SetMessage($msg);
                           Redirect('admin_protected_folder_v.php?err=true');  
                           exit();
                       
                       }  
                 } 
                 
                 
                  $deleteFolderQuery="delete from ".TABLE_PREFIX."product_protect where locate(folder,'$folder')>0";
                  $resDelete=$objProductProtection->delete($deleteFolderQuery);
              
                  $message->SetMessage('Folder 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_protected_folder_v.php?$quest");   
                          
                           
            break;
         case 'edit':
                  $lsId=$_GET['id'];
                  $lsProtection_technique=new master_class();
                  $lsProduct_protection=new product_protection_class();
                  $lsLogedinUser=$_SESSION[SESSION_PREFIX.'UserID'];
                  $products = new product_class();
                  $result = $products->GetUserProduct();
                  $product_result=$lsProduct_protection->getSpecificProductInfo($lsId);
                  $protection=$lsProtection_technique->View('protectionmethod');
                  $selectedProduct=$lsProduct_protection->getProductsOnEdit($lsId);
                  $smarty->assign('products',$result);
                  $smarty->assign('editProducts',$selectedProduct);
                  $smarty->assign('folder',trim($product_result[0]['folder']));
                  $smarty->assign('protection_method',$product_result[0]['protection_method']);
                  $smarty->assign('invalid_access',$product_result[0]['is_invalid_access_message']);
                  $smarty->assign('invalid_access_message',trim($product_result[0]['invalid_access_message']));
                  
                  $smarty->assign('protection',$protection);
                  $smarty->assign('IsEdit','yes');
                  $smarty->assign('editId',$lsId);
                  
                  $smarty->assign('browsPath',$lsPathOfBroseDir);
                  $smarty->display('admin_protected_folder.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_protected_folder.tpl');
    }        
    
?>
Return current item: MembersGear