<?php
//  ----------------------------------// 
//  Download Protection Options Page  //
//  ----------------------------------// 
function subm_options_protect() {
$dfolder = preg_replace('/http:\/\//','',site_url());
$dfolder2 = preg_replace('/www\./','',$dfolder);
list($dfolder, $download_folder) = explode("/", $dfolder2);
?>
<script language="javascript">
function popWin(var1) {
  window.open("http://easybiztools.com/subm/viewimage.php?id="+var1,"Details","menubar=no,height=517,width=747,scrollbars=yes,resizable=yes");
}
</script>

  <div class='wrap'>
  <h2>SubscriptionMate Download Protection</h2>
  <table class='form-table'>
  <tr><td>1. Upload all the files you want to protect to the 'Protected Directory'.  Create
      this folder in the <?php echo "<font color=red><b>\"$download_folder\"</b></font>"; ?> 
      directory (same directory where Wordpress is installed. <BR /></td></tr>
  <tr><td>2. To insert the download links for your members, you may use the following shortcodes:<BR />
      <font color=blue><b>[dprotect file='filename.zip' level='X']</b><font color=red>
      custom download text</font> <b>[/dprotect]</b>
      </font> <BR /> OR <BR />
      <font color=blue><b>[dprotect file='filename.zip' level='X']</b></font> <BR />
      where:  "X" = 1,2,3,4 or 5 (corresponds with the 5 levels of membership)  <BR />
      and 'filename.zip' is the filename of the protected file that only your members can access.
      </td></tr>
  <tr><td>3. Click <a href="javascript:popWin('1')"><b> here for a screenshot</b></a> to see how it is done</td></tr>    
  </table>    
  <form method="post" action="options.php">
  <?php
    settings_fields('subm_members_dwnld');
    $subm_dwnld = get_option('subm_members_dwnld'); $mesg_type = "DOWNLOAD PROTECTION";
    include_once("subm_text.php"); // display text instructions on the options page.
  ?>
  <table class='form-table'>
  <tr><td width=50% valign=top><font size=+1>Protected Directory:</font><BR />Create this folder 
      under the <?php echo "<font color=red><b>\"$download_folder\"</b></font>"; ?> directory
       on your server. Upload all the files that you want to protect to this folder.</td>
      <td valign=top>
      <input type='text' name='subm_members_dwnld[dwndir]' value='<?php echo "$subm_dwnld[dwndir]";?>'>
      </td></tr>
  <tr><td width=50% valign=top><font size=+1>Default Download Anchor Text:</font><BR />
      (eg. Download Now, Click Here to Download, etc)</td>
      <td valign=top>
      <input type='text' name='subm_members_dwnld[dwnld_txt]' value='<?php echo "$subm_dwnld[dwnld_txt]";?>'>
      </td></tr>
      
  <tr><td valign=top><font size=+1>Default Error Text:</font><BR />This text will be displayed 
      when an un-authorized person tries to download the protected files</td><td valign=top>
      <textarea cols=40 rows=5 name='subm_members_dwnld[err_txt]'><?php echo "$subm_dwnld[err_txt]";?></textarea>
      <br />
      <?php 
      $wpcontent = WP_CONTENT_DIR; $dwnld_dir = str_replace("wp-content", "$subm_dwnld[dwndir]", $wpcontent);
      // "$dwnld_dir";
      ?>
      </td></tr>

  <tr><td>&nbsp;</td><td>
  <p class='submit'><input type="submit" class="button-primary" value="Save Changes" /></p>
  </td></tr>
  </table>
  </form>
  </div>

<?php
}


//  ---------------------------------------// 
//  The Actual Options Page the Admin sees //
//  ---------------------------------------// 
function subm_options_page() {
?>
<script language="javascript">
function popWin(var1) {
  window.open("http://easybiztools.com/subm/viewimage.php?id="+var1,"Details","menubar=no,height=517,width=747,scrollbars=yes,resizable=yes");
}
</script>

  <div class='wrap'>
  <h2>SubscriptionMate Membership Settings</h2>
  <form method="post" action="options.php">
  <?php
    settings_fields('subm_members_group');
    $subm_mbrs = get_option('subm_members_option');
    $mesg_type = "SETTINGS";
    include_once("subm_text.php"); // display text instructions on the options page.
    
    $ipnurl = plugins_url() ."/subscriptionmate/subm_ipn.php";
    $thankyou_url = site_url() . "/subm_thanks.php";

  ?>
  <table class='form-table'>
  <tr><td colspan=2><font size=+1 color=blue><b>Payment Processor:</b></font> 
  <!--
      <input type='text' size=2 name='subm_members_option[processor_type]' 
             value='<?php echo "$subm_mbrs[processor_type]";?>' />
             1 = ClickBank | 2 = Paypal | 3 = DigiResult | 4 = JVZoo 
       <option value="4" <?php selected($subm_mbrs[processor_type],4); ?>>JVZoo</option>      
  -->
      <select name='subm_members_option[processor_type]'>
        <option value="1" <?php selected($subm_mbrs[processor_type],1); ?>>ClickBank</option>
        <option value="2" <?php selected($subm_mbrs[processor_type],2); ?>>Paypal</option>
        <option value="3" <?php selected($subm_mbrs[processor_type],3); ?>>DigiResult</option>
      </select>
      </td></tr>
  <tr><td colspan=2><h2>ClickBank:</h2>
      Please log into your ClickBank account and change the following: <BR />
      1.  IPN URL:  <input type=text size='100' value='<?php echo "$ipnurl";?>'> <BR />
      2.  Thankyou URL: <input type=text size='90' value='<?php echo "$thankyou_url";?>'></td></tr>
      
  <tr><td><b>ClickBank Vendor ID:</b></td><td>
      <input type='text' name='subm_members_option[nick]' value='<?php echo "$subm_mbrs[nick]";?>'>
      </td></tr>
  <tr><td><b>ClickBank Secret Key:</b></td><td>
      <input type='text' name='subm_members_option[skey]' value='<?php echo "$subm_mbrs[skey]";?>'>
      </td></tr>
  <tr><td colspan=2><hr></td></tr>

  <tr><td colspan=2><h2>Paypal:</h2>
      Please log into your Paypal account and change the following: <BR />
      1.  PDT URL:  <input type=text size='100' value='<?php echo "$thankyou_url";?>'> <BR /></td></tr>
  <tr><td><b>Paypal Business Email:</b></td><td>
      <input type='text' name='subm_members_option[paypal_vendor]' size='60' value='<?php echo "$subm_mbrs[paypal_vendor]";?>'>
      </td></tr>
  <tr><td><b>Paypal PDT Identity Token:</b></td><td>
      <input type='text' name='subm_members_option[paypal_pdt_token]' size='60' value='<?php echo "$subm_mbrs[paypal_pdt_token]";?>'>
      </td></tr>
  <tr><td colspan=2><hr></td></tr>

  <tr><td colspan=2><h2>DigiResult:</h2>

  <tr><td><b>Direct Receipt Secret Code:</b></td><td>
      <input type='text' name='subm_members_option[drkey]' value='<?php echo "$subm_mbrs[drkey]";?>'>
      </td></tr>
  <tr><td colspan=2><hr></td></tr>
  
  <tr><td><b>Autoresponder Type:</b> </td><td>
      <input type='text' size=3 name='subm_members_option[artype]' value='<?php echo "$subm_mbrs[artype]";?>'>
      1 = aweber | 2 = getresponse | 4 = others | 5 = mailchimp | 8 = customAPI
      </td></tr>
      
  <tr><td>Autoresponder API Key (if any):</td><td>
      <input type='text' size='60' name='subm_members_option[api_key]' value='<?php echo "$subm_mbrs[api_key]";?>'>
      </td></tr>      
      
  <tr><td valign=top><b>Membership Level 5: </b>(Platinum)</td>
      <td>ClickBank/Paypal Item #: 
      <input type='text' size='5' name='subm_members_option[level5]' value='<?php echo "$subm_mbrs[level5]";?>'>
      <BR /> Autoresponder Listname:
      <input type='text' size='35' name='subm_members_option[listname5]' value='<?php echo "$subm_mbrs[listname5]";?>'>
      <BR /> Welcome Page: 
      <input type='text' name='subm_members_option[welcome5]' size='75' value='<?php echo "$subm_mbrs[welcome5]"; ?>' />
      </td></tr>
  
  <tr><td valign=top><b>Membership Level 4: </b>(Gold)</td>
      <td>ClickBank/Paypal Item #: 
      <input type='text' size='5' name='subm_members_option[level4]' value='<?php echo "$subm_mbrs[level4]";?>'>
      <BR /> Autoresponder Listname:
      <input type='text' size='35' name='subm_members_option[listname4]' value='<?php echo "$subm_mbrs[listname4]";?>'>
      <BR /> Welcome Page:
      <input type='text' name='subm_members_option[welcome4]' size='75' value='<?php echo "$subm_mbrs[welcome4]"; ?>' />
      </td></tr>
      
  <tr><td valign=top><b>Membership Level 3: </b>(Silver)</td>
      <td>ClickBank/Paypal Item #: 
      <input type='text' size='5' name='subm_members_option[level3]' value='<?php echo "$subm_mbrs[level3]";?>'>
      <BR /> Autoresponder Listname:
      <input type='text' size='35' name='subm_members_option[listname3]' value='<?php echo "$subm_mbrs[listname3]";?>'>
      <BR /> Welcome Page:
      <input type='text' name='subm_members_option[welcome3]' size='75' value='<?php echo "$subm_mbrs[welcome3]"; ?>' />
      </td></tr>
      
  <tr><td valign=top><b>Membership Level 2:</b> (Bronze)</td>
      <td>ClickBank/Paypal Item #: 
      <input type='text' size='5' name='subm_members_option[level2]' value='<?php echo "$subm_mbrs[level2]";?>'>
      <BR /> Autoresponder Listname:
      <input type='text' size='35' name='subm_members_option[listname2]' value='<?php echo "$subm_mbrs[listname2]";?>'>
      <BR /> Welcome Page:
      <input type='text' name='subm_members_option[welcome2]' size='75' value='<?php echo "$subm_mbrs[welcome2]"; ?>' />
      </td></tr>
      
  <tr><td valign=top><b>Membership Level 1:</b> (Basic) </td>
      <td>ClickBank/Paypal Item# <b>OR</b> Free Membership Level : 
      <input type='text' size='5' name='subm_members_option[level1]' value='<?php echo "$subm_mbrs[level1]";?>'>
      <BR /> Autoresponder Listname:
      <input type='text' size='35' name='subm_members_option[listname1]' value='<?php echo "$subm_mbrs[listname1]";?>'>
      <BR /> Welcome Page:
      <input type='text' name='subm_members_option[welcome1]' size='75' value='<?php echo "$subm_mbrs[welcome1]"; ?>' />
      </td></tr>
      
  <tr><td valign=top><b>Insufficient Privileges (Error) Mesg:</b> This message will be displayed
      when non-members try to access members content, or if a lower-level member (Level 2) tries
      to access a post that is designated for Level 3.</td><td valign=top>
      <textarea cols='50' rows='10' name='subm_members_option[upgrademsg]'><?php echo "$subm_mbrs[upgrademsg]";?></textarea>
      </td></tr>
  <tr><td>&nbsp;</td>
      <td><input type="submit" name="Save" class="button-primary" value="Save Changes" /></td></tr>
  </table>
  </form>
  </div>
  <?php 
}
?>