<?php

function submitstuff_user_handle_ebooksignup( $contestid, $contest_name, $contest_func, $display_image_link,
                                              $display_image, $display_image_width, $display_image_height,
                                              $the_big_print, $the_small_print )
{
  $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\" target=\"_blank\">";
    $display_image_anchor_end = "</a>";
  }

  global $page_title;
  $page_title = $thankyou_title;

  list( $_submit_check,
        $entryname,
        $entryemail,
        $entryzip,
        $entryregion ) = pnVarCleanFromInput( '_submit_check',
                                              'entryname',
                                              'entryemail',
                                              'entryzip',
                                              'entryregion'
                                            );

  // 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 .= "entryname: "    . $entryname   . "\n\n";
    $message .= "entryemail: "   . $entryemail  . "\n\n";
    $message .= "entryzip: "     . $entryzip    . "\n\n";
    $message .= "entryregion: "  . $entryregion . "\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 <contest@kidspages.org>\r\n";

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

    // begin database
    $entryquestion  = '';  // no question

    // insert into database
    $strsql = "INSERT INTO `kp_contest` (";
    $strsql .= "contestid"  . ", ";
    $strsql .= "submitdate" . ", ";
    $strsql .= "ipaddress"  . ", ";
    $strsql .= "name"       . ", ";
    $strsql .= "email"      . ", ";
    $strsql .= "zip"        . ", ";
    $strsql .= "school";

    $strsql .= ") VALUES (";

    $strsql .= "$contestid, ";
    $strsql .= "'" . addslashes( $submitdate     ) . "', ";
    $strsql .= "'" . addslashes( $submitip       ) . "', ";
    $strsql .= "'" . addslashes( $entryname      ) . "', ";
    $strsql .= "'" . addslashes( $entryemail     ) . "', ";
    $strsql .= "'" . addslashes( $entryzip       ) . "', ";
    $strsql .= "'" . addslashes( $entryregion    ) . "'";
    $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">Thank you for your submission!</span><br /><br />' );


//    $output->Text( '<span style="font-size:18px">Your information has been received. Welcome to Kids\' Pages!<br /></span>' );

    $output->Text( '<span style="font-size:18px">Welcome to Kids\' Pages and thank you for subscribing to our eBook!<br /></span>' );
    $output->Text( '<span style="font-size:18px">You are automatically entered to Win a Nintendo Wii!<br /></span>' );


    $output->Text( '<div style="font-size:15px;width:575px;">' );
    $output->Text( '  <br />' );
    $output->Text( '  Please take a minute to make sure that e-mail messages from Kids\' Pages are not being blocked by any spam filters or firewalls. Messages from KidsPages.org addresses should be allowed to arrive in your inbox.<br />' );
    $output->Text( '  <br />' );
    $output->Text( '  Thank you,<br />' );
    $output->Text( '  Kids\' Pages Family Media' );
    $output->Text( '  <br />' );
    $output->Text( '</div>' );
    $output->Text( '  <br />' );

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

  $entryname    = htmlentities( $entryname );
  $entryemail   = htmlentities( $entryemail );
  $entryzip     = htmlentities( $entryzip );

$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 style="text-align:center;font-size:18px;font-weight:900;font-style:italic;width:480px;">
    $the_big_print
  </div>

  <div class="class-container">
    Please fill out form completely.

    <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>Name:</td><td><input name="entryname" size="50" maxlength="50" value="$entryname"></td></tr>
        <tr><td>E-Mail:</td><td><input name="entryemail" size="50" maxlength="50" value="$entryemail"></td></tr>
        <tr><td>Zip:</td><td><input name="entryzip" size="10" maxlength="10" value="$entryzip"></td></tr>

        <tr>
          <td>Region:</td>
          <td>
            <select name="entryregion">
              <option value="Denver Metro" selected>Denver Metro</option>
              <option value="Northern Colorado">Northern Colorado</option>
            </select>
          </td>
        </tr>

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

    <div>
      <img src="/images/contests/WinAWii.gif" width="450" height="217">
    </div>
  </div>
</div>

EOT
);

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

  return $output->GetOutput();
}


function submitstuff_user_viewebooksignup()
{
  $contestid = 50002;
  $contest_name = "eBook Signup";
  $contest_func = "viewebooksignup";

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

  $display_image_link = "";

//           1         2         3         4
//  1234 67890 234 67890 234 67890 234 67890
  $the_big_print = <<<EOT
    Fill out this form to receive<br />
    Kids' Pages eBook every month<br />
    and you will be automatically<br />
    entered to win a Nintendo WII!
EOT;

  $the_small_print = <<<EOT
EOT;

  return submitstuff_user_handle_ebooksignup( $contestid, $contest_name, $contest_func, $display_image_link,
                                              $display_image, $display_image_width, $display_image_height,
                                              $the_big_print, $the_small_print );
}

// ======================================================================================================================
// ======================================================================================================================

?>
