* @version $Revision: 1.4 $ $Date: 2004/10/21 12:18:15 $
*
*/
include_once('config.php');
include_once('class.Validator.php');
$check = new Validator ();
$Metas = array('\"','/','+','*','?','[','^',']','(','$',')',';',':','<','>');
$errors=array();
$thnxmsg=NULL;
$template = new template();
$template->title = 'motherboards.org Weekly Newsletter Signup';
$template->section = 'home';
$template->description = $template->title;
$template->open_page();
$g_conn = new db_mysql();
$g_conn->select_db('mbhw');
if(isset($_POST['frontsub']))
{
if($check->is_email($_POST['frontsub']))
{
if(!newsletter_exists($_POST['frontsub']))
{
$addmail = $_POST['frontsub'];
newsletter_add($addmail);
}
}
header('location:http://www.motherboards.org');
}
else
{
if(isset($_POST['hit']))
{
if(!$check->custom_has($Metas,$_POST['hit']))
{
array_push($errors,"Bad data Recieved");
}
else
{
if($_POST['hit']=="in")
{
$opto='in';
}
else
{
$opto='out';
}
}
switch($opto)
{
case 'in':
$sel=array("in"=>"checked", "out"=>NULL);
break;
case 'out':
$sel=array("in"=>NULL, "out"=>"checked");
break;
default:
$sel=array("in"=>"checked", "out"=>NULL);
break;
}
if(isset($_POST['theemail']))
{
if($_POST['theemail']!="")
{ if(!$check->is_email($_POST['theemail']))
{
array_push($errors,$check->ERROR);$inemail=NULL;
}
else
{
$inemail = $_POST['theemail'];
$exemail = newsletter_exists($inemail);
if($exemail)
{
switch($opto)
{
case 'in':
array_push($errors,"You have already subscribed.");
break;
case 'out':
newsletter_remove($exemail);
$thnxmsg="Your email has been removed";
break;
default:
array_push($errors,"No selection made.");
break;
}
}
else
{
switch($opto)
{
case 'in':
if(newsletter_in_exclude_list($inemail))
{
mysql_query("delete from thenewsletter_exclude where email = \"$inemail\"");
if(!newsletter_add($inemail))
{
array_push($errors,"Error adding email to database.");
}
else
{
$thnxmsg="Your email has been received";
}
}
else
{
if(!newsletter_add($inemail))
{
array_push($errors,"Error adding email to database.");
}
else
{
$thnxmsg="Your email has been received";
}
}
break;
case 'out':
if(newsletter_in_exclude_list($exemail))
{
array_push($errors,"You have already been removed.");
}
else
{
array_push($errors,"No record found.");
}
break;
default:
array_push($errors,"No selection made.");
break;
}
}
}
}
else
{
array_push($errors,"Email is required");
$inemail=NULL;
}
}
else
{
$inemail=NULL;
}
}
else
{
$sel=array("in"=>"checked", "out"=>NULL);
}
if(count($errors)<1)
{
$errtab=NULL;
}
else
{
$errtab="
Errors: |
";
foreach($errors as $errnum => $err)
{
$pre=$errnum+1;
$errtab.="".$pre.") | ".$err." |
";
}
$errtab.="
";
}
$form = "
";
$thanks = "";
$stage=array(NULL, $form, $thanks);
if(!$errtab && $hit)
{
$out=$stage[2];
}
else
{
$out=$stage[1];
}
}
function newsletter_add($inemail)
{
global $g_conn;
$qt="insert into thenewsletter values (null, \"$inemail\", ".time().", \"".$_SERVER['REMOTE_ADDR']."\")";
if($checkq = mysql_query($qt))
{
return true;
}
else
{
return false;
}
}
function newsletter_remove($inemail)
{
global $g_conn;
$errors=array();
$qt="delete from thenewsletter where email = \"$inemail\"";
if(!$checkq = mysql_query($qt))
{
array_push($errors,"No Data");
}
$qt="insert into thenewsletter_exclude values (null, \"$inemail\", ".time().", \"".$_SERVER['REMOTE_ADDR']."\")";
if(!$checkq = mysql_query($qt))
{
array_push($errors,"No Data");
}
if(count($errors)<1)
{
return true;
}
else
{
return false;
}
}
function newsletter_in_exclude_list($inemail)
{
global $g_conn;
$theq = mysql_query("select email from thenewsletter_exclude where email = \"$inemail\"");
if(mysql_num_rows($theq)>0)
{
return true;
}
else
{
return false;
}
}
function newsletter_exists($inemail)
{
global $g_conn;
$theq = mysql_query("select email from thenewsletter where email = '$inemail'");
$emailar = mysql_fetch_row($theq);
$exemail=$emailar[0];
if($exemail)
{
return $exemail;
}
else
{
return false;
}
}
?>
Newsletter :: Subscribe / Unsubscribe :: Motherboards.org
close_page();
?>