<?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-2005 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 FriendSend($sid) {
    if (!isset($sid)) { exit(); }
    $result=mysql_query("select title, aid  from stories where sid='$sid'");
    list($title, $aid) = mysql_fetch_row($result);
    if (!$aid) {
       header ("Location: index.php");
    }
    include ("header.php");
    OpenTable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo translate("Send Story to a Friend");
    echo "</td></tr></table>\n";
    echo "<br />";
    echo translate("You will send the story")." <b>".aff_langue($title)."</b> ".translate("to a specified friend:")."<br /><br />
    <form action=\"friend.php\" method=\"post\"><input type=\"hidden\" name=\"sid\" value=\"$sid\">";
    global $user;
    if ($user) {
       global $cookie;
       $result=mysql_query("select name, email from users where uname='$cookie[1]'");
       list($yn, $ye) = mysql_fetch_row($result);
    }
    echo "
    ".translate("Your Name: ")."<br /><input class=\"TEXTBOX\" type=\"text\" name=\"yname\" value=\"$yn\" size=\"30\" max=\"100\"><br />
    ".translate("Your Email: ")."<br /><input class=\"TEXTBOX\" type=\"text\" name=\"ymail\" value=\"$ye\" size=\"30\" max=\"100\"><br /><br />
    ".translate("Friend Name: ")."<br /><input class=\"TEXTBOX\" type=\"text\" name=\"fname\" size=\"25\" max=\"100\"><br />
    ".translate("Friend Email: ")."<br /><input class=\"TEXTBOX\" type=\"text\" name=\"fmail\" size=\"25\" max=\"100\"><br /><br />
    <input type=\"hidden\" name=\"op\" value=\"SendStory\">
    <input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".translate("Send")."\">
    </form>";
    closetable();
    include ('footer.php');
}

function SendStory($sid, $yname, $ymail, $fname, $fmail) {
    global $sitename, $nuke_url;
    $result2=mysql_query("select title, time, topic from stories where sid='$sid'");
    list($title, $time, $topic) = mysql_fetch_row($result2);
    $result3=mysql_query("select topictext from topics where topicid='$topic'");
    list($topictext) = mysql_fetch_row($result3);
    $subject = translate("Interesting Article at")." $sitename";
    $fname=removeHack($fname);
    $message = "".translate("Hello")." $fname :\n\n".translate("Your Friend")." $yname ".translate("considered the following article interesting and wanted to send it to you.")."\n\n".aff_langue($title)."\n".translate("Date:")." $time\n".translate("Topic:")." ".aff_langue($topictext)."\n\n".translate("The Article")." : $nuke_url/article.php?sid=$sid\n\n";
    include("signat.php");
    $fmail=removeHack($fmail);
    $subject=removeHack($subject);
    $message=removeHack($message);
    $yname=removeHack($yname);
    $ymail=removeHack($ymail);
    $stop=false;
    if ((!$fmail) || ($fmail=="") || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$fmail))) $stop = true;
    if ((!$ymail) || ($ymail=="") || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$ymail))) $stop = true;
    if (!$stop) {
       send_email($fmail, $subject, $message, "\"$yname\" <$ymail>", false,"text");
    } else {
      $title="";
      $fname="";
    }
    $title = urlencode(aff_langue($title));
    $fname = urlencode($fname);
    Header("Location: friend.php?op=StorySent&title=$title&fname=$fname");
}

function StorySent($title, $fname) {
    include ("header.php");
    opentable();
    $title = urldecode($title);
    $fname = urldecode($fname);
    echo "<p align=\"center\">";
    if ($fname=="") {
       echo translate("ERROR: Invalid email");
    } else {
       echo translate("Story")." <b>".stripslashes($title)."</b> ".translate("has been sent to")." $fname... ".translate("Thanks!");
    }
    echo "</p>";
    closetable();
    include ("footer.php");
}

function RecommendSite() {
    include ("header.php");
    OpenTable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo translate("Recommend this Site to a Friend");
    echo "</td></tr></table>\n";
    echo "<br />";
    echo "<form action=\"friend.php\" method=\"post\"><input type=\"hidden\" name=\"op\" value=\"SendSite\">";
    global $user;
    if ($user) {
       global $cookie;
       $result=mysql_query("select name, email from users where uname='$cookie[1]'");
       list($yn, $ye) = mysql_fetch_row($result);
    }
    echo "
    ".translate("Your Name: ")."<br /><input class=\"TEXTBOX\" type=\"text\" name=\"yname\" value=\"$yn\" size=\"30\" max=\"100\"><br />
    ".translate("Your Email: ")."<br /><input class=\"TEXTBOX\" type=\"text\" name=\"ymail\" value=\"$ye\" size=\"30\" max=\"100\"><br /><br />
    ".translate("Friend Name: ")."<br /><input class=\"TEXTBOX\" type=\"text\" name=\"fname\" size=\"25\" max=\"100\"><br />
    ".translate("Friend Email: ")."<br /><input class=\"TEXTBOX\" type=\"text\" name=\"fmail\" size=\"25\" max=\"100\"><br /><br />
    <input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".translate("Send")."\">
    </form>";
    closetable();
    include ('footer.php');
}

function SendSite($yname, $ymail, $fname, $fmail) {
    global $sitename, $nuke_url;
    $subject = "".translate("Interesting Site:")." $sitename";
    $fname=removeHack($fname);
    $message = "".translate("Hello")." $fname :\n\n".translate("Your Friend")." $yname ".translate("considered our site")." $sitename ".translate("interesting and wanted to send it to you.")."\n\n$sitename : $nuke_url\n\n";
    include("signat.php");
    $fmail=removeHack($fmail);
    $subject=removeHack($subject);
    $message=removeHack($message);
    $yname=removeHack($yname);
    $ymail=removeHack($ymail);
    $stop=false;
    if ((!$fmail) || ($fmail=="") || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$fmail))) $stop = true;
    if ((!$ymail) || ($ymail=="") || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$ymail))) $stop = true;
    if (!$stop) {
       send_email($fmail, $subject, $message, "\"$yname\" <$ymail>", false,"text");
    } else {
      $fname="";
    }
    Header("Location: friend.php?op=SiteSent&fname=$fname");
}

function SiteSent($fname) {
    include ('header.php');
    opentable();
    echo "<p align=\"center\">";
    if ($fname=="") {
       echo translate("ERROR: Invalid email");
    } else {
       echo translate("The reference to our site has been sent to")." $fname...";
       echo "<br /><br />".translate("Thanks for recommend us!");
    }
    echo "</p>";
    closetable();
    include ('footer.php');
}

switch($op) {
    case "SendStory":
        SendStory($sid, $yname, $ymail, $fname, $fmail);
        break;

    case "StorySent":
        StorySent($title, $fname);
        break;

    case "SendSite":
        SendSite($yname, $ymail, $fname, $fmail);
        break;

    case "SiteSent":
        SiteSent($fname);
        break;

    case "FriendSend":
        FriendSend($sid);
        break;

    default:
        RecommendSite();
        break;
}
?>