<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: friend.php,v 1.12.2.5 2004/04/27 18:19:19 ajvwaay Exp $




/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)            */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* 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(!isset($mainfile)) { include("mainfile.php"); }

require_once('class.phpmailer.php');
$mail = new phpmailer();

/* SET MAIL DELIVERY OPTIONS */
$mail->IsHTML(true);
if ($mailmethod == "0") {
    $mail->IsMail();
} else {
    $mail->IsSMTP();
    $mail->Host = $smtp;
}

function FriendForm($yn, $ye, $style_submit, $style_text) {
echo "
    <TABLE BORDER=0>
    <TR>
      <TD ALIGN=\"RIGHT\">".translate("Your Name: ")."</TD>
      <TD><input class=textbox type=text name=\"yname\" value=\"$yn\" $style_text  SIZE=35></TD>
    </TR>
    <TR>
      <TD ALIGN=\"RIGHT\">".translate("Your Email: ")."</TD>
      <TD><input class=textbox type=text name=\"ymail\" value=\"$ye\" $style_text  SIZE=35></TD>
    </TR>
    <TR>
      <TD ALIGN=\"RIGHT\">".translate("Friend Name: ")."</TD>
      <TD><input class=textbox type=text name=\"fname\" $style_text  SIZE=35></TD>
    </TR>
    <TR>
      <TD ALIGN=\"RIGHT\">".translate("Friend Email: ")."</TD>
      <TD><input class=textbox type=text name=\"fmail\" $style_text  SIZE=35></TD>
    </TR>
</TABLE>";
}


function FriendSend($sid) {
       global $style_text, $style_textarea, $style_submit, $mpnTables;
    if(!isset($sid)) { exit(); }
    include ("header.php");
    $result=mysql_query("select title from ".$mpnTables['stories']." where sid=$sid");
    list($title) = mysql_fetch_row($result);
    OpenTable();
    echo "<CENTER><B>".translate("Send Story to a Friend")."</B></CENTER><br><br>
    ".translate("You will send the story")."<B> $title </B>".translate("to a specified friend:")."<br><br>
    <form action=\"friend.php\" method=post>
    <input type=hidden name=sid value=$sid>";
    global $user, $cookie;

    $yn = $ye = null;

    if ( _MPN_USER ) {
    $result=mysql_query("select uname, email from ".$mpnTables['users']." where uname='$cookie[1]' && uid > 1");
    list($yn, $ye) = mysql_fetch_row($result);
    }
    FriendForm($yn, $ye, $style_submit, $style_text);
    echo "<input type=hidden name=op value=SendStory>
    <input class='button' type=submit $style_submit value=".translate("Send").">
    </form>";
    closetable();
    include ('footer.php');
}

function FriendSectionSend($artid) {
          global $style_text, $style_textarea, $style_submit, $mpnTables;
    if(!isset($artid)) { exit(); }
    include ("header.php");
    $result=mysql_query("select title from ".$mpnTables['seccont']." where artid=$artid");
    list($title) = mysql_fetch_row($result);
    OpenTable();
    echo "<CENTER><B>".translate("Send Story to a Friend")."</B></CENTER><br><br>
    ".translate("You will send the story")." <b>$title</b> ".translate("to a specified friend:")."<br><br>
    <form action=\"friend.php\" method=post>
    <input type=hidden name=artid value=$artid>";
    global $user;

    $yn = $ye = null;

    if ( _MPN_USER ) {
    $cookie = cookiedecode($user);
    $result=mysql_query("select uname, email from ".$mpnTables['users']." where uname='$cookie[1]' && uid > 1");
    list($yn, $ye) = mysql_fetch_row($result);
    }
    FriendForm($yn, $ye, $style_submit, $style_text);
    echo "<input type=hidden name=op value=SendStorySection>
    <input class='button' type=submit $style_submit value=".translate("Send").">
    </form>";
    closetable();
    include ('footer.php');
}

function SendStorySection($artid, $yname, $ymail, $fname, $fmail) {
    global $sitename, $mpnTables, $mail;
    $result2=mysql_query("select title from ".$mpnTables['seccont']." where artid=$artid");
    list($title) = mysql_fetch_row($result2);
    $subject = "".translate("Interesting Article at")." $sitename";
    $message = translate("Hello")." $fname,\n".translate("Your Friend")." $yname ".
               translate("considered the following article interesting and wanted to send it to you.").
               "\n\n$title\n<a href=\"" . _MPN_ROOT_URI . "sections.php?op=viewarticle&artid=$artid\">" . _MPN_ROOT_URI . "sections.php?op=viewarticle&artid=$artid</a>\n\n".
               translate("You can read interesting articles at")." <a href=\""._MPN_ROOT_URI."\">$sitename</a>";
//    mail($fmail, $subject, $message, "From: \"$yname\" <$ymail>\nX-Mailer: PHP/" . phpversion());
    $mail->From = $ymail;
    $mail->FromName = $yname;
    $mail->AddAddress($fmail, $fname);
    $mail->AddReplyTo($ymail);
    $mail->Subject = stripslashes($subject);
    $mail->Body = nl2br( stripslashes($message) );
    $mail->AltBody = strip_tags( stripslashes($message) );
    $mail->Send();
    //$title = urlencode($title);
    //$fname = urlencode($fname);

    StorySent( $title, $fname );
}


function SendStory($sid, $yname, $ymail, $fname, $fmail) {
    global $sitename, $mpnTables, $mail;
    $result2=mysql_query("select title, time, topic from ".$mpnTables['stories']." where sid=$sid");
    list($title, $time, $topic) = mysql_fetch_row($result2);
    $result3=mysql_query("select topictext from ".$mpnTables['topics']." where topicid=$topic");
    $time = strftime(translate("forumdatestring2"),strtotime($time));
    list($topictext) = mysql_fetch_row($result3);
    $subject = "".translate("Interesting Article at")." $sitename";
    //<br>
    $message = translate("Hello")." $fname,\n".translate("Your Friend")." $yname ".
               translate("considered the following article interesting and wanted to send it to you.").
               "\n\n$title\n(".translate("Date:")." $time)\n".
               translate("Topic:")." $topictext\n\n".
               translate("URL").": <a href=\"" . _MPN_ROOT_URI . "article.php?sid=$sid\">" . _MPN_ROOT_URI . "article.php?sid=$sid</a>\n\n".
               translate("You can read interesting articles at")." <a href = \"". _MPN_ROOT_URI ."\">$sitename</a>";
//    mail($fmail, $subject, $message, "From: \"$yname\" <$ymail>\nX-Mailer: PHP/" . phpversion());
    $mail->From = $ymail;
    $mail->FromName = $yname;
    $mail->AddAddress($fmail, $fname);
    $mail->AddReplyTo($ymail);
    $mail->Subject = stripslashes($subject);
    $mail->Body = nl2br( stripslashes($message) );
    $mail->AltBody = strip_tags( stripslashes($message) );
    $mail->Send();
    //$title = urlencode($title);
    //$fname = urlencode($fname);

    StorySent( $title, $fname );
}

function StorySent($title, $fname) {

   // $title = urldecode($title);
    //$title = stripslashes($title);
    //$fname = urldecode($fname);

    $home = translate( 'Back To Home Page' );

    include_once("header.php");

    opentable();
    echo "<center>\n";

    echo "".translate("Story")." <b>$title</b> ".translate("has been sent to")." $fname... ".translate("Thanks!")."";

    echo "<br /><br />\n";

    echo "<a href='./' title='$home'>$home</a>\n";

    echo "</center>\n";

    closetable();
    include_once("footer.php");
}

function RecommendSite() {
    global $style_text, $style_textarea, $style_submit, $mpnTables;
    include ("header.php");
    OpenTable();
    echo "<CENTER><B>".translate("Recommend this Site to a Friend")."</B></CENTER><br><br>
    <form action=\"friend.php\" method=post>
    <input type=hidden name=op value=SendSite>";
    global $user, $cookie;

    $yn = $ye = null;

    if ($user) {
    $result=mysql_query("select uname, email from ".$mpnTables['users']." where uname='$cookie[1]'");
    list($yn, $ye) = mysql_fetch_row($result);
    }
    FriendForm($yn, $ye, $style_submit, $style_text);
    echo "<input class='button' type=submit $style_submit value=".translate("Send").">
    </form>";
    closetable();
    include ('footer.php');
}

function SendSite($yname, $ymail, $fname, $fmail) {
    global $sitename, $slogan, $mail;
    $subject = "".translate("Interesting Site: ")." $sitename";

    $message = translate("Hello")." $fname,\n".
               translate("Your Friend")." $yname ".translate("considered our site")." $sitename ".
               translate("interesting and wanted to send it to you.")."\n\n".
               translate("Site Name:")." $sitename\n$slogan\n\n".
               translate("Site URL:")." <a href=\"" . _MPN_ROOT_URI . "\">" . _MPN_ROOT_URI . "</a>";
//    mail($fmail, $subject, $message, "From: \"$yname\" <$ymail>\nX-Mailer: PHP/" . phpversion());
    $mail->From = $ymail;
    $mail->FromName = $yname;
    $mail->AddAddress($fmail, $fname);
    $mail->AddReplyTo($ymail);
    $mail->Subject = stripslashes($subject);
    $mail->Body = nl2br( stripslashes($message) );
    $mail->AltBody = strip_tags( stripslashes($message) );
    $mail->Send();

    StorySent( $sitename, $fname );
}

function SiteSent($fname) {
    include ('header.php');
    opentable();
        echo "    <center>".translate("The reference to our site has been sent to")." $fname...<br><br>".translate("Thanks for recommending us!")."</center>";
    closetable();
    include ('footer.php');
}

if (!isset( $op ))
{
    $op = null;
}

switch($op) {

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

    case "SendStorySection":
    SendStorySection($artid, $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;

    case "FriendSendSection":
    FriendSectionSend($artid);
    break;

    default:
    RecommendSite();
    break;

}
?>
