<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* Original Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)   */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2004 by Philippe Brunier   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {include ("mainfile.php");}

function SuserCheck($email) {
    global $stop;
    $stop="";
    if ((!$email) || ($email=="") || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$email))) $stop = translate("ERROR: Invalid email")."<br />";
    if (strrpos($email,' ') > 0) $stop = translate("ERROR: Email addresses do not contain spaces.")."<br />";
    if (mysql_num_rows(mysql_query("select email from users where email='$email'")) > 0) {
       $stop = translate("ERROR: Email address already registered")."<br />";
    }
    if (mysql_num_rows(mysql_query("select email from lnl_outside_users where email='$email'")) > 0) {
       if (mysql_num_rows(mysql_query("select email from lnl_outside_users where email='$email' and status='NOK'")) >0) {
          mysql_query("delete FROM lnl_outside_users WHERE email='$email'");
       } else {
          $stop = translate("ERROR: Email address already registered")."<br />";
       }
    }
    return($stop);
}

function error_handler($ibid) {
   opentable();
   echo translate("Please enter information according to the specifications")."<br /><br />";
   echo "$ibid<br /><a href=\"index.php?\" class=\"NOIR\">".translate("Go Back")."</a>";
   closetable();
}

function subscribe($xemail) {
   include("header.php");
   global $stop;
   if ($xemail!="") {
      SuserCheck($xemail);
      if ($stop=="") {
         $host_name=getip();
         $timeX=strftime("%Y-%m-%d %T",time());
         // Troll Control
         list($troll) = mysql_fetch_row(mysql_query("select count(*) from lnl_outside_users where (host_name='$host_name') and (to_days(now()) - to_days(date) < 3)"));
         if ($troll < 6) {
            mysql_query("insert into lnl_outside_users values ('$xemail', '$host_name', '$timeX', 'OK')");
            // Email validation + url to unsubscribe
            global $sitename, $nuke_url;
            $subject = "".translate("NewsLetter")." / $sitename";
            $message = "".translate("Thank you for taking the time to record you in or DataBase.")."\n\n";
            $message .= "".translate("For Unsubscribe, please goto")." :\n $nuke_url/lnl.php?op=unsubscribe&email=$xemail\n\n";
            include("signat.php");
            send_email($xemail, $subject, $message, "", true, "text");
            OpenTable();
            echo translate("Thank you for taking the time to record you in or DataBase.")."<br /><br />";
            echo "<a href=\"index.php?\" class=\"NOIR\">".translate("Go Back")."</a>";
            CloseTable();
        } else {
            $stop=translate("This account or IP has been temporarily disabled. This means that either this IP, or user account has been moderated down more than x times in the last few hours. If you think this is unfair, you should contact the admin.")."<br />";
            error_handler($stop);
        }
      } else {
         error_handler($stop);
      }
   } else {
     error_handler(translate("Empty data not allowed.")."<br />");
   }
   include("footer.php");
}

function unsubscribe($xemail) {
   if ($xemail!="") {
      if ((!$xemail) || ($xemail=="") || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$xemail))) header("location: index.php");
      if (strrpos($xemail,' ') > 0) header("location: index.php");
      if (mysql_num_rows(mysql_query("select email from lnl_outside_users where email='$xemail'")) > 0) {
         $host_name=getip();
         $timeX=strftime("%Y-%m-%d %T",time());
         // Troll Control
         list($troll) = mysql_fetch_row(mysql_query("select count(*) from lnl_outside_users where (host_name='$host_name') and (to_days(now()) - to_days(date) < 3)"));
         if ($troll < 6) {
            mysql_query("update lnl_outside_users set status='NOK'  where email='$xemail'");
            include("header.php");
            OpenTable();
            echo translate("Thanks!")."<br /><br />";
            echo "<a href=\"index.php?\" class=\"NOIR\">".translate("Go Back")."</a>";
            closeTable();
            include("footer.php");
         } else {
            include("header.php");
            $stop=translate("This account or IP has been temporarily disabled. This means that either this IP, or user account has been moderated down more than x times in the last few hours. If you think this is unfair, you should contact the admin.")."<br />";
            error_handler($stop);
            include("footer.php");
         }
      }
   }
}

switch($op) {
   case "subscribe":
      subscribe($email);
      break;

   case "unsubscribe":
      unsubscribe($email);
      break;
}
?>