<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

$action = $_GET['action'];

function RandPass($length) {

    $pass = "";
    for ($i = 0; $i < $length; $i++) {
        $rand = rand(1,3);
        switch($rand) {
            case 1: $pass .= chr(rand(48,57)); break;
            case 2: $pass .= chr(rand(65,90)); break;
            case 3: $pass .= chr(rand(97,122)); break;
        }
    }
    return $pass;
}

if($action=="save") {

  $email = $_POST['email'];

	$sem = '^[a-z0-9_\.-]+@[a-z0-9_-]+\.[a-z0-9_\.-]+$';
	if(!(eregi($sem, $email))) redirect('index.php?site=newsletter', 'Your e-mail is not valid!');
	else {

		$ergebnis = safe_query("SELECT * FROM ".PREFIX."newsletter WHERE email='".$email."'");
  	if(!mysql_num_rows($ergebnis)) {

   		$pass = RandPass(7);

   		safe_query("INSERT INTO ".PREFIX."newsletter ( email, pass) values ('$email', '".$pass."') ");

	   	$header="From:".PAGETITLE."<$admin_email>\n";
   		$header .= "Reply-To: $admin_email\n";
   		$header .= "X-Mailer: PHP/" . phpversion(). "\n";
   		$header .= "X-Sender-IP: $REMOTE_ADDR\n";
   		$header .= "Content-Type: text/html";
   		mail($email,PAGETITLE.": Newsletter registration","<b>Thank you for your registration!</b><br><br>To remove your mail adress from the maillist click <a href='http://".$_SERVER[HTTP_HOST].$_SERVER[PHP_SELF]."?site=newsletter&mail=".$email."&pass=".$pass."'>here</a><br>Your password to delete yourself: ".$pass."<br><br>See you at ".$hp_url,$header);

 			redirect('index.php?site=newsletter', 'thank you for your registration.');
 		} else redirect('index.php?site=newsletter', 'You are already registered.');
 	} 	
}
elseif($action=="delete") {
 		$ergebnis = safe_query("SELECT pass FROM ".PREFIX."newsletter WHERE email='".$_POST['email']."'");
    $dn=mysql_fetch_array($ergebnis);

    if($_POST['password'] == $dn[pass]) {
		 safe_query("DELETE FROM ".PREFIX."newsletter WHERE email='".$_POST['email']."'");
		 redirect('index.php?site=newsletter', 'Your mail adress has been deleted.');
	  }else redirect('index.php?site=newsletter', 'The mail/password didnt match.');
}
elseif($action=="forgot") {
 		$ergebnis = safe_query("SELECT pass FROM ".PREFIX."newsletter WHERE email='".$_POST['email']."'");
    $dn=mysql_fetch_array($ergebnis);

    if($dn[pass] != "") {

     $email = $_POST['email'];
     $pass = $dn[pass];

     $header="From:".PAGETITLE."<$admin_email>\n";
     $header .= "Reply-To: $admin_email\n";
     $header .= "X-Mailer: PHP/" . phpversion(). "\n";
     $header .= "X-Sender-IP: $REMOTE_ADDR\n";
     $header .= "Content-Type: text/html";
     mail($email,PAGETITLE.": Deletion key","<b>You required your deletion key!</b><br><br>To remove your mail adress from the maillist click <a href='http://".$_SERVER[HTTP_HOST].$_SERVER[PHP_SELF]."?site=newsletter&mail=".$email."&pass=".$pass."'>here</a><br>Your password to delete yourself: <b>".$pass."</b><br><br>See you at ".$hp_url,$header);

		 redirect('index.php?site=newsletter', 'The password had been send.');
	  }else redirect('index.php?site=newsletter', 'There is no such mail adress.');
}
else {

			$bg1=BG_1;
			$bg2=BG_2;
			$bg3=BG_3;
			$bg4=BG_4;
			
      $usermail = getemail($userID);
      $get_mail = $_GET['mail'];
      if($get_mail == "") $get_mail = 'mail adress';
      $get_pw = $_GET['pass'];
      if($get_pw == "") $get_pw = 'del-key';

			eval ("\$newsletter_title = \"".gettemplate("title_newsletter")."\";");
	        echo $newsletter_title;

			eval ("\$newsletter = \"".gettemplate("newsletter")."\";");
	        echo $newsletter;

}
?>
			

			
