<?php

if(file_exists('../../../wp-load.php')) { include_once('../../../wp-load.php');} 
else { echo "wp-config.php not found"; exit(); } 

list($filename,$level) = explode("|",base64_decode($_GET[f]));

$mbr_level = 'read_level'.$level;   //echo "$filename | $level | $mbr_level<hr>";

// Get protected download dir from the options table //
$subm_dwnld = get_option('subm_members_dwnld'); //echo "$subm_dwnld[dwndir]<hr>";
  
//  $wpdir = WP_CONTENT_DIR; 
//  $dwnld_dir = str_replace("wp-content", "$subm_dwnld[dwndir]", $wpdir); // To chk if file exist
  
  $actual_url = site_url() . '/'. $subm_dwnld[dwndir] . "/$filename"; 

  // Admin User - Over-ride all settings //
  // ------------------------------------//
  if( current_user_can("delete_users") ) {  header("Location: $actual_url");  }

  // ------------------------------------//
  // display Premium Content for Members //
  // ------------------------------------//
  if(current_user_can($mbr_level)) {
      //echo "You may download ==> $filename"; 
      header("Location: $actual_url");
  } else {
      get_header(); $siteurl = site_url();     $err_msg = $subm_dwnld[err_txt];
      if($err_msg == '') {
        $err_msg = "Oops ... insufficient permission to download file!";
      }
      echo "
      <P>&nbsp;</p><center><h2>$err_msg</h2><P>&nbsp;</p>
      Click here to go back to: <a href=$siteurl>$siteurl</a>
      
      </center>";
      get_footer(); exit();
  }  
?>