<%if save%>
  <%Links::Payment::save_config%>
  <%if payment_config_invalid_fee%>
    <%set message = "<br><font color=red>You entered an invalid signup
      charge!</font>"%>
  <%endif%>
  <%if payment_config_invalid_discount%>
  <%set message .= "<br><font color=red>You entered an invalid discount!</font>"%>
  <%endif%>
  <%if payment_config_invalid_term%>
  <%set message .= "<br><font color=red>You entered an invalid signup
    term!</font>"%>
  <%endif%>
  <%if renewal_warning_invalid%>
  <%set message .= "<br><font color=red>You did not enter a valid renewal
    warning!</font>"%>
  <%endif%>
  <%if config_saved_done%>
  <%set message = "<font color=green>Your payment configuration has been saved
    successfully</font>"%>
  <%endif%>
<%endif%>
<html>
<head>
  <title>Gossamer Links - Payments - Payment Setup</title>
</head>

<body bgcolor="white">
<%set header_title = "Payment Setup"%>
<%set header_description = "This page allows you to enable and configure the Gossamer Links payment system."%>

<%include payment_header.html%>
<br>
<%set font_tag = '<font face="Tahoma,Arial,Helvetica" size="2">'%>
<%Links::Payment::load_config%>

<form method="post" action="admin.cgi">
<input type="hidden" name="do" value="page">
<input type="hidden" name="page" value="payment_setup.html">
<input type="hidden" name="save" value="1">

<table border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td>
      <table bgcolor="white" border="0" cellpadding="3" cellspacing="3" width="500" valign="top">
        <tr>
          <td width="20%" rowspan="2" valign="top"><%font_tag%><b>Payments Enabled:<br></b></font></td>
          <td width="80%"><%font_tag%>
            <select name="payment_enabled">
              <option value="1"<%if payment_config_enabled%> selected<%endif%>>Yes</option>
              <option value="0"<%ifnot payment_config_enabled%> selected<%endif%>>No</option>
            </select>
          </font></td>
        </tr>
        <tr>
          <td>
            <%font_tag%>If enabled, you will be able to receive payment from users for adding new links.<br><br>
            <%if payment_config_enabled and not payment_enabled%><font color="red">No payment methods have been configured; payments will not be enabled until a method is configured.</font><%endif%>
            </font>
          </td>
        </tr>
        <tr>
          <td width="20%" rowspan="2" valign="top"><%font_tag%><b>Expiry Notify:<br></b></font></td>
          <td width="80%"><%font_tag%><input name="payment_expiry_notify" value="<%if payment_expiry_notify%><%payment_expiry_notify%><%endif%>" size="5" maxlength="3"> days</font></td>
        </tr>
        <tr>
          <td><%font_tag%>A cron job will send a notification email to users X days before their links expire.<br><br></font></td>
        </tr>
        <tr>
          <td width="20%" rowspan="2" valign="top"><%font_tag%><b>Payment global option:<br></b></font></td>
          <td width="80%"><%font_tag%>
            <select name="payment_mode">
              <option value="3"<%if payment_mode == 3%> selected<%endif%>>Required</option>
              <option value="2"<%if payment_mode == 2%> selected<%endif%>>Optional</option>
              <option value="1"<%if payment_mode == 1%> selected<%endif%>>Not accepted</option>
            </select>
          </font></td>
        </tr>
        <tr>
          <td><%font_tag%>
            This option controls the default payment status of your directory.
            Note that individual categories have the same option that will
            override this global setting.  If this option is set to "required",
            then users must pay to add their links.  If set to "optional"
            payment categories will allow them to choose whether or not to pay
            to add their links.  If they pay, their links show up at the top of
            the page with any other "paid" links, otherwise it shows at the
            bottom below any paid links, mixed in with the unpaid links.  If
            set to "Not accepted", no payments will be allowed.
            <br><br></font></td>
        </tr>
        <tr>
          <td width="20%" valign="top"><%font_tag%><b>Link payment auto-validation:<br></b></font></td>
          <td width="80%"><%font_tag%>
            <input type="radio" name="payment_auto_validate" value="0"<%if payment_auto_validate == 0%> CHECKED<%endif%>> Admin/Editors approves all links.<br>
            <input type="radio" name="payment_auto_validate" value="1"<%if payment_auto_validate == 1%> CHECKED<%endif%>> All paid links are automatically validated.
          </font></td>
        </tr>
        <tr>
          <td width="20%" valign="top">&nbsp;</td>
          <td width="80%"><%font_tag%><i>Note that manual payments are automatically validated on payment approval.</i></font><br><br></td>
        </tr>

        <tr>
          <td width="20%" valign="top"><%font_tag%><b>Change expired links to free:<br></b></font></td>
          <td width="80%"><%font_tag%>
            <input type="radio" name="payment_expired_is_free" value="1"<%if payment_expired_is_free%> CHECKED<%endif%>> Changed expired links to free links.<br>
            <input type="radio" name="payment_expired_is_free" value="0"<%ifnot payment_expired_is_free%> CHECKED<%endif%>> Do not update expired links.
          </font></td>
        </tr>
        <tr>
          <td width="20%" valign="top">&nbsp;</td>
          <td width="80%"><%font_tag%>
            This option allows you to define how Gossamer Links treats expired links in optional
            categories - the links can either automatically become free links, in which case they
            will still show up in the free listing of optional-payment categories, or they can be
            left as expired and consequently will not show up in optional payment categories.
            <br>
            <b>Note: After changing this option, you must run the Repair Tables code (located
              in the Database admin menu)</b>
          </font><br><br></td>
        </tr>

        <tr>
          <td width="20%" valign="top"><%font_tag%><b>Payment description:<br></b></font></td>
          <td width="80%">
            <%font_tag%><textarea name="payment_description" cols="40" rows="6"><%if payment_description%><%payment_description%><%endif%></textarea><br>
          </font></td>
        </tr>

      <%if num_signup or num_renewal%>
        <tr>
          <td valign="top" style="padding-top: 6px"><%font_tag%><b>
              <%if num_renewal and renewal_differs%>Initial Terms:
              <%else%>Payment Terms:
              <%endif%>
          </b></td>
          <td valign="top" style="padding-top: 0px">
            <table border="0" cellpadding="0" cellspacing="6">
              <tr>
                <td><%font_tag%><u>Delete</u></font></td>
                <td><%font_tag%><u>Cost</u></font></td>
                <td><%font_tag%><u>Term</u></font></td>
              </tr>
              <%loop signup%>
              <tr>
                <td><%font_tag%><input type="checkbox" name="delete_signup" value="<%term%>"></font></td>
              <td><%font_tag%><%Links::Payment::currency($cost)%></font></td>
                <td><%font_tag%><%ifnot term_unit%>Lifetime<%else%><%term_num%> <%term_unit%><%endif%></font></td>
              </tr>
              <%endloop%>
            </table>
          </td>
        </tr>
        <tr>
          <td valign="top"><%font_tag%><b>Renewal Terms:</b></td>
          <%if num_renewal and renewal_differs%>
          <td valign="top" style="padding-top: 0px">
            <table border="0" cellpadding="0" cellspacing="6">
              <tr>
                <td><%font_tag%><u>Delete</u></font></td>
                <td><%font_tag%><u>Cost</u></font></td>
                <td><%font_tag%><u>Term</u></font></td>
              </tr>
              <%loop renewal%>
              <tr>
                <td><%font_tag%><input type="checkbox" name="delete_renewal" value="<%term%>"></font></td>
                <td><%font_tag%><%Links::Payment::currency($cost)%></font></td>
                <td><%font_tag%><%ifnot term_unit%>Lifetime<%else%><%term_num%> <%term_unit%><%endif%></font></td>
              </tr>
              <%endloop%>
            </table>
          </td>
          <%else%>
          <td valign="top">
            <%font_tag%>Same as payment terms above.</font>
          </td>
          <%endif%>
        </tr>
      <%endif%>
      <%if num_recurring%>
        <tr>
          <td valign="top"><%font_tag%><b>Recurring Terms:</b></td>
          <td valign="top" style="padding-top: 0px">
            <table border="0" cellpadding="0" cellspacing="6">
              <tr>
                <td><%font_tag%><u>Delete</u></font></td>
                <td><%font_tag%><u>Cost</u></font></td>
                <td><%font_tag%><u>Term</u></font></td>
              </tr>
              <%loop recurring%>
              <tr>
                <td><%font_tag%><input type="checkbox" name="delete_recurring" value="<%term%>"></font></td>
                <td><%font_tag%><%Links::Payment::currency($cost)%></font></td>
                <td><%font_tag%><%term_num%> <%term_unit%></font></td>
              </tr>
              <%endloop%>
            </table>
            <%unless Links::Payment::recurring_enabled()%>
            <%font_tag%><font color="red">Note that recurring payments require
              a supporting payment method.  No appropriate payment method is
              currently enabled.</font></font>
            <%endunless%>
          </td>
        </tr>
      <%endif%>
        <tr>
          <td valign="top"><%font_tag%><b>New Term:</b></td>
          <td valign="top" style="padding-top: 0px">
            <table border="0" cellpadding="0" cellspacing="6">
              <tr>
                <td><%font_tag%>
                  <%Links::Payment::currency('<input type="text" name="signup_cost" size="6">')%>
                  <input type="radio" name="add_type" value="signup"<%if not add_type or add_type eq 'signup'%> checked="checked"<%endif%>> Single
                  <input type="radio" name="add_type" value="renewal"<%if add_type eq 'renewal'%> checked="checked"<%endif%>> Renewal
                  <input type="radio" name="add_type" value="recurring"<%if add_type eq 'recurring'%> checked="checked"<%endif%>> Recurring<br>
                  <input type="text" name="term_length" size="2">
                  <select name="term_unit">
                    <option value="d">days</option>
                    <option value="w">weeks</option>
                    <option value="m">months</option>
                    <option value="y">years</option>
                    <option value="unlimited">lifetime</option>
                  </select>
                </font></td>
              </tr>
            </table>
          </td>
        </tr>

        <%if payment_discounts%>
        <tr>
          <td valign="top" style="padding-top: 6px"><%font_tag%><b>Payment
              Discounts:</b></td>
          <td valign="top" style="padding-top: 0px">
            <table border="0" cellpadding="0" cellspacing="6">
              <tr>
                <td><%font_tag%><u>Delete</u></font></td>
                <td><%font_tag%><u>Num</u></font></td>
                <td><%font_tag%><u>Discount</u></font></td>
                <td><%font_tag%><u>Description</u></font></td>
              </tr>
              <%loop payment_discounts%>
              <tr>
                <td><%font_tag%><input type="checkbox" name="delete_discount"
                  value="<%num%>"></font></td>
                <td><%font_tag%>&nbsp;<%num%></font></td>
                <td><%font_tag%>&nbsp;<%percent%>%</font></td>
                <td><%font_tag%>&nbsp;<%description%></font></td>
              </tr>
              <%endloop%>
            </table>
          </td>
        </tr>
        <%endif%>
        <tr>
          <td valign="top"><%font_tag%><b>New Payment Discount:</b></td>
          <td valign="top" style="padding-top: 0px">
            <table border="0" cellpadding="0" cellspacing="6">
              <tr>
                <td><%font_tag%>Num of links:</font></td>
                <td><%font_tag%><input type="text" name="discount_num_links" value="<%if
                discount_num_links%><%discount_num_links%><%endif%>" size="1"><br></font></td>
                <td><%font_tag%>Discount percentage:</font></td>
                <td><%font_tag%><input type="text" name="discount_percent" value="<%if
                  discount_percent%><%discount_percent%><%endif%>"
                  size="1">&nbsp;%<br></font></td>
              </tr>
              <tr>
                <td><%font_tag%>Discount description:</font></td>
              <td colspan="3"><%font_tag%><textarea
                  name="discount_description" cols="38"
                  rows="6"><%if discount_description%><%discount_description%><%endif%></textarea><br></font></td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td colspan="3" align="center"><%font_tag%><input type="submit" value="Save Changes"></font></td>
        </tr>
      </table>
    </td>
  </tr>
</table>

</form>
</body>
</html>
