<?php
/**
* $Id tpl_contest_default.php V1.5 04.01.2009
* Written by SkipWater <skip AT ccssinc DOT net>
*
* @package page template
* @copyright Copyright 2003-2006 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license
http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: Define Generator v0.1 $
*
* osCommerce, Open Source E-Commerce Solutions
*
http://www.oscommerce.com
* Copyright (c) 2007 osCommerce
* Released under the GNU General Public License
* Orginal OSC contributed Written by Carl Skerritt
*/
// testing use only
if ($error == false) {
echo 'ERROR FALSE<br />';
} else {
echo 'ERROR TRUE<br />';
// should not be set to true here reset to false
$error = false;
}
$show_invite = false;
$prossed_complete = 0;
// Check if we should display this page, incase someone accesses it directly.
if (CONTEST_SHOW == 'true') {
$show_invite = true;
// Check if we are a registered customer
if ($_SESSION['customer_id'] && CONTEST_ALLOW_CUSTOMERS == 'false') {
$show_invite = false;
}
// Check if we are a guest
if (!$_SESSION['customer_id'] && CONTEST_ALLOW_GUESTS == 'false') {
$show_invite = false;
}
// Check if within dates of contest
$start_date = strtotime(CONTEST_START_DATE);
$close_date = strtotime(CONTEST_CLOSE_DATE);
$now = strtotime(date("m/d/y"));
if ($now >= $start_date && $now <= $close_date) {
} else {
$show_invite = false;
}
}
if ($show_invite == false) { // Start Contest Closed
// Contest Closed calls define_contestend.php
$file_contestend = substr($define_page, 0, strpos($define_page, '.')); // strip extention
$define_page_contest_end = $file_contestend.'end.php';
require_once($define_page_contest_end);
echo ' <a href="javascript
:history.go(-1)" onMouseOver="self.status=document.referrer;return true">'.zen_image_button(BUTTON_IMAGE_BACK, BUTTON_BACK_ALT).'</a>';
} else { // Contest NOT Closed
// Retrieve Prize details
$sql_query = "select p.products_id, p.products_image, p.products_price, pd.products_name, pd.products_description from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and p.products_id ='" . (int)CONTEST_PRIZE_ID . "' and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' limit 1";
$contest_prize = $db->Execute($sql_query);
if (!$contest_prize->RecordCount() > 0) {
// Data base error display warning
echo '<center><br/><table width="80%" border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFF00" >'.
'<tr> '.
'<td align="center"><strong>ADMIN ERROR:</strong> The selected Prize Could Not Be Found.</td>'.
'</tr>'.
'</table></center>';
}
if (isset($_GET['action']) && ($_GET['action'] == 'process')) {
$error = false;
$entry_email_address = zen_db_prepare_input($_POST['entry_email_address']);
$entry_name = zen_db_prepare_input($_POST['entry_name']);
$entry_valid = zen_db_prepare_input($_POST['entry_qualify_answer']);
echo $entry_email_address.'<br/>'.$entry_name.'<br/>'.$entry_valid;
if (empty($entry_name)) {
$error = true;
$messageStack->add('contest', ERROR_TO_NAME);
}
if (!zen_validate_email($entry_email_address)) {
$error = true;
$messageStack->add('contest', ERROR_TO_ADDRESS);
}
// Check if we have already entered
$check_email_query = "select count(*) as total from " . TABLE_CONTEST . " where contestant_email = '" . $entry_email_address . "' AND contest_code = '" . CONTEST_CODE . "'";
$check_email = $db->Execute($check_email_query);
if ($check_email->fields['total'] > 0) {
$error = true;
$messageStack->add('contest', TEXT_ALREADY_ENTERED);
}
// If this is a members only contest, check that address entered matchs the one held on the account
if (CONTEST_ALLOW_CUSTOMERS == 'true' && CONTEST_ALLOW_GUESTS == 'false') {
// $check_members_email_query = "select count(*) as total from " . TABLE_CUSTOMERS . " where customers_email_address = '" . zen_db_input($entry_email_address) . "' and customers_id = '" . (int)$customer_id . "' AND contest_code = '" . CONTEST_CODE . "'";
$check_members_email_query = "select count(*) as total from " . TABLE_CUSTOMERS . " where customers_email_address = '" . zen_db_input($entry_email_address) . "' and customers_id = '" . (int)$customer_id . "'";
$check_members_email = $db->Execute($check_members_email_query);
if ($check_members_email->fields['total'] = 0) {
$error = true;
$messageStack->add('contest', ERROR_TO_MEMBERS_ADDRESS);
}
}
$validated = "Y";
if (CONTEST_QUALIFY == 'true') {
if (empty($entry_valid)) {
$error = true;
$messageStack->add('contest', ERROR_TO_VALID);
} else {
// Check if question was answered
if (strtoupper($entry_valid{0}) == strtoupper(CONTEST_ANSWER)) {
$validated = "Y";
} else {
$validated = "N";
}
}
}
if ($error == false && $show_invite == true) {
$db->Execute("insert into " . TABLE_CONTEST . " (contestant_name, contestant_email, contestant_ip_address, date_entered, validated, contest_code) values ('" . zen_db_input($entry_name) . "', '" . zen_db_input($entry_email_address) . "', '" . $_SERVER['REMOTE_ADDR'] . "', now(), '" . zen_db_input($validated) . "', '" . zen_db_input(CONTEST_CODE) . "')");
$prossed_complete = 1;
}
} // end of Process
echo zen_draw_form('contest', zen_href_link(FILENAME_CONTEST, 'action=process'));
?>
<!-- bof tpl_contest_default.php -->
<div class='centerColumn' id='contest'>
<h1 id='contest-heading'><?php echo HEADING_TITLE; ?></h1>
<div id='contest-content' class='content'>
<?php
if ($messageStack->size('contest') > 0) {
echo $messageStack->output('contest');
}
if (isset($_GET['action']) && ($_GET['action'] == 'winner')){ // Winners List Start
// Contest Winner Page calls define_contestwinner.php
$file_contestwinner = substr($define_page, 0, strpos($define_page, '.')); // strip extention
$define_page_contest_winner = $file_contestwinner.'winner.php';
require_once($define_page_contest_winner);
echo '<a href="javascript
:history.go(-1)" onMouseOver="self.status=document.referrer;return true">'.zen_image_button(BUTTON_IMAGE_BACK, BUTTON_BACK_ALT).'</a>';
} else { // Winners List
if (isset($_GET['action']) && ($_GET['action'] == 'rules')){ // Rules Start
// Call define contest page (page that user can edit contest rules)
require($define_page);
echo '<a href="javascript
:history.go(-1)" onMouseOver="self.status=document.referrer;return true">'.zen_image_button(BUTTON_IMAGE_BACK, BUTTON_BACK_ALT).'</a>';
} else { // Rules
// User Successful entry
if ($prossed_complete > 0){
echo TEXT_CONTEST_ENTRY_SUCCESSFUL;
echo 'The Winner will be notified by emailed after '.CONTEST_CLOSE_DATE.'<br/>';
echo '<br/><a href="' . zen_href_link(FILENAME_DEFAULT) . '">' . zen_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>';
} else {
?>
<!-- Display Prize -->
<hr>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td class="infoNotice" width=75% align="left" valign="top">
<?php
echo '<strong>Contest Starts: </strong>'.CONTEST_START_DATE.' 12:00am <strong>Ends: </strong>'.CONTEST_CLOSE_DATE.' 11:59pm<br/><br/>';
echo '<hr>';
echo 'The PRIZE is <b>'. $contest_prize->fields['products_name'].'</b><br/>' . $contest_prize->fields['products_description'];
?>
</td>
<td class="main" width=25% align="center" valign="top">
<?php
// Display rules link
echo '<a href="' . zen_href_link('contest&action=rules') . '">Click for Contest Rules</a><br/>';
// Display Winners link
echo '<a href="' . zen_href_link('contest&action=winner') . '">Click for List of Winners</a>';
echo '<hr>';
echo zen_image(DIR_WS_IMAGES . $contest_prize->fields['products_image'], $contest_prize->fields['products_name'], SMALL_IMAGE_WIDTH*2, SMALL_IMAGE_HEIGHT*2);
echo '<br/>MSRP ' . ((zen_has_product_attributes_values((int)$contest_prize->fields['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . zen_get_products_display_price((int)$contest_prize->fields['products_id']);
?>
</td>
</tr>
</table>
<!-- End Prize -->
<fieldset id="contestForm">
<legend><?php echo HEADING_FORM_TITLE; ?></legend>
<div class="alert forward"><?php echo FORM_REQUIRED_INFORMATION; ?></div>
<br class="clearBoth" />
<label class="inputLabel" for="contestname"><?php echo FORM_FIELD_ENTRY_NAME; ?></label>
<?php echo zen_draw_input_field('entry_name', $name, ' size="40" id="contestname"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>
<br class="clearBoth" />
<label class="inputLabel" for="email-address"><?php echo FORM_FIELD_ENTRY_EMAIL; ?></label>
<?php echo zen_draw_input_field('entry_email_address', ($error ? $_POST['entry_email_address'] : $entry_email_address), ' size="40" id="email-address"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>
<br class="clearBoth" />
<?php
if (CONTEST_QUALIFY == "true") {
echo FORM_FIELD_QUALIFING_QUESTION.'<br/>';
// Retrived from Data Base
echo CONTEST_QUESTION;
?>
<label class="inputLabel" for="entry_qualify_answer"><?php echo FORM_FIELD_QUALIFING_ANSWER; ?></label>
<?php echo zen_draw_input_field('entry_qualify_answer', $entry_qualify_answer, ' size="1" id="entry_qualify_answer"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>
<br class="clearBoth" />
<?php
} // End Qualify Question
?>
</fieldset>
<div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_SUBMIT, BUTTON_SUBMIT_ALT); ?>
</div>
</form>
<?php
} // End Success
} // End Rules
} // End Winners List
} // End Contest Closed
echo '</div></div>';
?>