<?php

function submitstuff_user_handle_unsubscribe( $contest_name, $contest_func, $display_image_link,
                                              $display_image, $display_image_width, $display_image_height )
{
  $email_subject = "$contest_name Submission";
  $thankyou_title = "$contest_name";

  $display_image_anchor_begin = "";
  $display_image_anchor_end = "";

  if ( !empty( $display_image_link ) )
  {
    $display_image_anchor_begin = "<a href=\"$display_image_link\">";
    $display_image_anchor_end = "</a>";
  }

  global $page_title;
  $page_title = $thankyou_title;

  list( $_submit_check,
        $emailaddress ) = pnVarCleanFromInput( '_submit_check',
                                               'emailaddress' );

  // Create output object - this object will store all of our output so that
  // we can return it easily when required
  $output = new pnHTML();
  $output->SetInputMode(_PNH_VERBATIMINPUT);

  if ( $_submit_check == '1' )
  {
    $subject = $email_subject;

    $submitdate = date("F j, Y, g:i a");
    $submitip = getenv("REMOTE_ADDR");

    $message = "";
    $message .= $submitdate . "\n";
    $message .= $submitip . "\n";
    $message .= "\n\n";

    $message .= "emailaddress: " . $emailaddress  . "\n\n";

    // To send HTML mail, you can set the Content-type header.
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
    $headers .= "From: Contest Submit <unsubscribe@kidspages.org>\r\n";

    // and now mail it
    @mail('unsubscribe@kidspages.org', $subject, $message, $headers);
    @mail('contest@kidspages.org', $subject, $message, $headers);

    // begin database

    // insert into database
    $strsql = "INSERT INTO `kp_ebook_unsubscribe` (";
    $strsql .= "submitdate" . ", ";
    $strsql .= "ipaddress"  . ", ";
    $strsql .= "email";

    $strsql .= ") VALUES (";

    $strsql .= "'" . addslashes( $submitdate     ) . "', ";
    $strsql .= "'" . addslashes( $submitip       ) . "', ";
    $strsql .= "'" . addslashes( $emailaddress   ) . "'";
    $strsql .= ")";

//    echo '<b style="font-size:30px;">' . $strsql . '</b><hr>'; // debug

    list($dbconn) = pnDBGetConn();
    $dbconn->Execute( $strsql );
    // end database

    $output->Text( '<font class="header">' . $thankyou_title . '</font><br /><br />' );
    $output->Text( '<span style="font-size:18px">Your email address has been taken off the eBook list.</span><br /><br />' );

    $output->Text( '<a href="/oldkpindex.php">Back to the home page</a>' );
    return $output->GetOutput();
  }

  $emailaddress   = htmlentities( $emailaddress );

$output->Text(
<<<EOT
<style>
div.class-container {
  border: 2px dashed #fff;
  background-color: #fff;
  padding-left:15px;
  padding-right:15px;
  padding-top:15px;
  padding-bottom:0px;
  font-family: geneva, verdana, trebuchet MS, trebuchet, verdana, arial, sans-serif;
  font-size: 15px;
  font-weight:bold;
  }

div.class-container table {
  font-size: 15px
}
</style>

<div style="width:785px;">
  <div style="float: right;text-align:left;font-size:18px;font-weight:900;color:#264ba0;width:300px;">
    $display_image_anchor_begin<img src="/images/contests/$display_image" width="$display_image_width" height="$display_image_height" border="0" style="padding-top:5px;">$display_image_anchor_end
  </div>

  <div class="class-container">
    We're sorry to see you go.<br />
    Enter your e-mail address and click unsubscribe.<br />

    <br />
    <form action="/oldkpindex.php" method="post">
      <input type="hidden" name="module" value="SubmitStuff">
      <input type="hidden" name="func" value="$contest_func">
      <input type="hidden" name="_submit_check" value="1"/>
      <table border="0">
        <tr><td>E-Mail:</td><td><input name="emailaddress" size="50" maxlength="50" value="$emailaddress"></td></tr>

        <tr><td colspan="2">&nbsp;</td></tr>
        <tr><td colspan="2"><input type="submit" name="Unsubscribe" value="Unsubscribe"></td></tr>
      </table>
    </form>
  </div>
</div>

EOT
);

  global $pnuser_googleAd;
  $output->Text( $pnuser_googleAd );

  return $output->GetOutput();
}

function submitstuff_user_unsubscribe()
{
  $contest_name = "eBook Unsubscribe";
  $contest_func = "unsubscribe";

  //                1234567890123456789012345678901
  $display_image = "eBookSignup-display.gif";
  $display_image_width = "300";
  $display_image_height = "450";

  $display_image_link = "http://kidspages.local/oldkpindex.php?module=SubmitStuff&func=viewebooksignup";

  return submitstuff_user_handle_unsubscribe( $contest_name, $contest_func, $display_image_link,
                                              $display_image, $display_image_width, $display_image_height );
}



////////////////////////////////////////////////


function submitstuff_user_handle_nlunsubscribe( $contest_name, $contest_func, $display_image_link,
                                                $display_image, $display_image_width, $display_image_height )
{
  $email_subject = "$contest_name Submission";
  $thankyou_title = "$contest_name";

  $display_image_anchor_begin = "";
  $display_image_anchor_end = "";

  if ( !empty( $display_image_link ) )
  {
    $display_image_anchor_begin = "<a href=\"$display_image_link\">";
    $display_image_anchor_end = "</a>";
  }

  global $page_title;
  $page_title = $thankyou_title;

  list( $_submit_check,
        $emailaddress ) = pnVarCleanFromInput( '_submit_check',
                                               'emailaddress' );

  // Create output object - this object will store all of our output so that
  // we can return it easily when required
  $output = new pnHTML();
  $output->SetInputMode(_PNH_VERBATIMINPUT);

  if ( $_submit_check == '1' )
  {
    $subject = $email_subject;

    $submitdate = date("F j, Y, g:i a");
    $submitip = getenv("REMOTE_ADDR");

    $message = "";
    $message .= $submitdate . "\n";
    $message .= $submitip . "\n";
    $message .= "\n\n";

    $message .= "emailaddress: " . $emailaddress  . "\n\n";

    // To send HTML mail, you can set the Content-type header.
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
    $headers .= "From: Contest Submit <nlunsubscribe@kidspages.org>\r\n";

    // and now mail it
    @mail('nlunsubscribe@kidspages.org', $subject, $message, $headers);
    @mail('contest@kidspages.org', $subject, $message, $headers);

    // begin database

    // insert into database
    $strsql = "INSERT INTO `kp_emails_block` (";
    $strsql .= "submitdate" . ", ";
    $strsql .= "ipaddress"  . ", ";
    $strsql .= "email_address";

    $strsql .= ") VALUES (";

    $strsql .= "'" . addslashes( $submitdate     ) . "', ";
    $strsql .= "'" . addslashes( $submitip       ) . "', ";
    $strsql .= "'" . addslashes( $emailaddress   ) . "'";
    $strsql .= ")";

//    echo '<b style="font-size:30px;">' . $strsql . '</b><hr>'; // debug

    list($dbconn) = pnDBGetConn();
    $dbconn->Execute( $strsql );
    // end database

    $output->Text( '<font class="header">' . $thankyou_title . '</font><br /><br />' );
    $output->Text( '<span style="font-size:18px">Your email address has been taken off the Kids\' Pages Newsletter list.</span><br /><br />' );

    $output->Text( '<a href="/oldkpindex.php">Back to the home page</a>' );
    return $output->GetOutput();
  }

  $emailaddress   = htmlentities( $emailaddress );

$output->Text(
<<<EOT
<style>
div.class-container {
  border: 2px dashed #fff;
  background-color: #fff;
  padding-left:15px;
  padding-right:15px;
  padding-top:15px;
  padding-bottom:0px;
  font-family: geneva, verdana, trebuchet MS, trebuchet, verdana, arial, sans-serif;
  font-size: 15px;
  font-weight:bold;
  }

div.class-container table {
  font-size: 15px
}
</style>

<div style="width:785px;">
  <div style="float: right;text-align:left;font-size:18px;font-weight:900;color:#264ba0;width:300px;">
    $display_image_anchor_begin<img src="/images/contests/$display_image" width="$display_image_width" height="$display_image_height" border="0" style="padding-top:5px;">$display_image_anchor_end
  </div>

  <div class="class-container">
    We're sorry to see you go.<br />
    Enter your e-mail address and click unsubscribe.<br />

    <br />
    <form action="/oldkpindex.php" method="post">
      <input type="hidden" name="module" value="SubmitStuff">
      <input type="hidden" name="func" value="$contest_func">
      <input type="hidden" name="_submit_check" value="1"/>
      <table border="0">
        <tr><td>E-Mail:</td><td><input name="emailaddress" size="50" maxlength="50" value="$emailaddress"></td></tr>

        <tr><td colspan="2">&nbsp;</td></tr>
        <tr><td colspan="2"><input type="submit" name="Unsubscribe" value="Unsubscribe"></td></tr>
      </table>
    </form>
  </div>
</div>

EOT
);

  global $pnuser_googleAd;
  $output->Text( $pnuser_googleAd );

  return $output->GetOutput();
}

function submitstuff_user_nlunsubscribe()
{
  $contest_name = "Newsletter Unsubscribe";
  $contest_func = "nlunsubscribe";

  //                1234567890123456789012345678901
  $display_image = "pix.gif";
  $display_image_width = "300";
  $display_image_height = "450";

  $display_image_link = "";

  return submitstuff_user_handle_nlunsubscribe( $contest_name, $contest_func, $display_image_link,
                                                $display_image, $display_image_width, $display_image_height );
}



?>
