$cachetimeout=-1;
// include the DB abstraction layer
ini_set('include_path', '.:/opt/php/lib/php');
require_once("DB.php");
$db = "contests";
require_once("/websites/PHP_COMMON/russ_pear.php");
/*********************************************************************\
MAIN SCRIPT
\*********************************************************************/
print_header();
main();
print_footer();
exit();
/*********************************************************************\
FUNCTIONS
\*********************************************************************/
/*********************************************************************\
email_validate($emailAddress)
Returns true or false.
Copied from warnerreprise.com/lyris/join_list.php - 5/24/2004
\*********************************************************************/
function email_validate($emailAddress)
{
$arr= explode('@',$emailAddress);
if (count ($arr) != 2)
return false; # "bogus..only one @ allowed";
if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $emailAddress))
||
(preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',
$emailAddress))
)
{
return true;
} else {
return false;
}
}
/*********************************************************************\
is_duplicate($emailAddress)
Returns true or false.
\*********************************************************************/
function is_duplicate($emailAddress, $fieldName = 'email')
{
global $dbh;
$sql = sprintf("select count(*) as count from %s where %s='%s'", 'oc_ipod', $fieldName, $emailAddress);
if (DB::isError($result = $dbh->query($sql))) {
die($result->getUserInfo());
}
$record = $result->fetchRow(DB_FETCHMODE_ASSOC);
return ($record['count'] > 0);
}
/*********************************************************************\
main()
\*********************************************************************/
function main ()
{
global $dbh;
$fields = array(
"age" => "",
"name" => "",
"email" => "",
"address" => "",
"city" => "",
"state" => "",
"zip" => "",
"phone" => "",
);
// define mail list info for update checkboxes
$join_lists = array(
"join_artist" => "musicfromtheoc"
);
// define db column info for update checkboxes
$db_fields = array(
"join_artist" => "join_artist"
);
$submitted_form = false;
$missing_fields = false;
$duplicate_user = false;
// verify that all requried form information is present
foreach(array_keys($fields) as $field_name)
{
if (isset($_POST[$field_name]))
{
$submitted_form = true;
if ($_POST[$field_name] == "")
{
$missing_fields = true;
}
else
{
$fields[$field_name] = trim(strip_tags($_POST[$field_name]));
}
}
}
// validate email
if (isset($_POST['email']) && !email_validate($fields['email']))
{
$missing_fields = true;
$fields['email'] = "";
}
// check for duplicate email address
$duplicate_user = is_duplicate($fields['email']);
// check submission, if any, and generate output
if ($submitted_form && !$missing_fields && !$duplicate_user) // do the dirty data processing work
{
// build db insert query
$columns = array();
$values = array();
foreach($fields as $field_name => $field_value)
{
array_push($columns, $field_name);
array_push($values, addslashes($field_value));
}
array_push($columns, $db_fields['join_artist']);
array_push($values, ($_POST['join_artist']) ? 1 : 0);
// enter into contest database
$sql = sprintf("insert into %s (%s) values ('%s')", 'oc_ipod', join(",", $columns), join("','",$values));
//printf("\n\n\n\n\n", $sql);
if (DB::isError($result = $dbh->query($sql))) {
die($result->getUserInfo());
}
// submit to lyris join form
if($_POST['join_artist']) { join_mail_list($fields['email'], $join_lists['join_artist']); }
//readfile("thanks.html");
print_thanks($fields);
}
else // print the contest submission form
{
// store answers for any selected lists
foreach(array_keys($join_lists) as $list_code)
{
if (isset($_POST[$list_code]))
{
$fields[$list_code] = $_POST[$list_code];
}
}
print_form($fields, $missing_fields, $duplicate_user);
}
}
/*********************************************************************\
join_mail_list($email_address, $list_name)
'GET's a virtual form (poor mans' RPC) to lyris join script
\*********************************************************************/
function join_mail_list($email_address, $list_name)
{
$lyris_url = "http://www.warnerreprise.com/lyris/join_list.php";
$lyris_args = array(
"email" => urlencode($email_address),
"list" => urlencode($list_name),
"good" => "default",
"error" => "default"
);
$qparams = array();
foreach($lyris_args as $qkey => $qval )
$qparams[] = $qkey."=".$qval;
$get_url = $lyris_url.'?'.join('&',$qparams);
//printf("
joining list '%s' with '%s' at '%s'
\n", $list_name, $email_address, $get_url);
$lyris_results = file_get_contents($get_url);
//echo "".$lyris_results."\n\n\n\n\n\n\n";
}
/*********************************************************************\
print_header()
\*********************************************************************/
function print_header()
{
?>
MUSIC FROM THE OC, MIX 4 POD CONTEST
The 4th installment of Music From The OC is coming on April 5, 2005, and to celebrate, we're giving away an 20GB iPod engraved with "Music from the OC" and pre-loaded with the new Mix 4 and Mixes 1, 2 and 3, plus a pair of tickets to see The Futureheads (featured on Mix 4) on tour in April at a city nearest you! Two runners-up will receive a pair of tickets each in their closest city.
Enter now and you might be able to mix up the mixes on a new iPod!
Good luck!
}
/*********************************************************************\
print_thanks()
\*********************************************************************/
function print_thanks($f)
{
?>
Thanks!
}
/*********************************************************************\
print_footer()
\*********************************************************************/
function print_footer()
{
?>