<?php
if (!defined('MODULE_FILE')) {
    Header("Location: ../../index.php");
    exit;
}
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
require_once("function/comments.php");

function News($new_topic=0) {
    global $db, $storyhome, $topicname, $topicimage, $topictext, $datetime, $user, $prefix, $multilingual, $currentlang, $sitename, $user_news, $pagenum, $anonymous, $module_name;
    if ($multilingual == 1) {
        $querylang = "AND (alanguage='$currentlang' OR alanguage='')";
    } else {
        $querylang = "";
    }
    include("header.php");
    if (isset($new_topic)) {
        $new_topic = intval($new_topic);
    } else {
        $new_topic == 0;
    }
    $cookie = explode(":", addslashes(base64_decode($user)));
    if (isset($cookie[3]) AND $user_news == 1) {
        $storynum = intval($cookie[3]);
    } else {
        $storynum = $storyhome;
    }
    if ($new_topic == 0) {
        $qdb = "WHERE ihome='0' AND s.time <= NOW()";
        $home_msg = "";
    } else {
        $qdb = "WHERE topic='$new_topic' AND s.time <= NOW()";
        $result_a = $db->sql_query("SELECT topictext FROM ".$prefix."_topics WHERE topicid='$new_topic'");
        $row_a = $db->sql_fetchrow($result_a);
        $numrows_a = $db->sql_numrows($result_a);
        $topic_title = stripslashes(check_html($row_a['topictext'], "nohtml"));
        OpenTable();
        if ($numrows_a == 0) {
            echo "<center><font class=\"title\">$sitename</font><br><br>"._NOINFO4TOPIC."<br><br>[ <a href=\"index.php?name=News\">"._GOTONEWSINDEX."</a> | <a href=\"index.php?name=Topics\">"._SELECTNEWTOPIC."</a> ]</center>";
        } else {
            echo "<center><font class=\"title\">$topic_title</font><br><br>"
            ."<form action=\"index.php?name=Search\" method=\"post\">"
            ."<input type=\"hidden\" name=\"topic\" value=\"$new_topic\">"
            .""._SEARCHONTOPIC.": <input type=\"name\" name=\"query\" size=\"30\">  "
            ."<input type=\"submit\" value=\""._SEARCH."\">"
            ."</form>"
            ."[ <a href=\"index.php\">"._GOTOHOME."</a> | <a href=\"index.php?name=Topics\">"._SELECTNEWTOPIC."</a> ]</center>";
        }
        CloseTable();
    }
    if ($pagenum == "") { $pagenum = 1; }
    $offset = ($pagenum-1) * $storynum;
    $offset = intval($offset);
    $storynum = intval($storynum);
    $sql = "SELECT sid, s.catid, s.aid, s.title, s.time, s.hometext, s.bodytext, s.comments, s.counter, s.topic, s.informant, s.notes, s.acomm, s.score, s.ratings, c.title, t.topicid, t.topicname, t.topicimage, t.topictext FROM ".$prefix."_stories AS s LEFT JOIN ".$prefix."_stories_cat AS c on (s.catid=c.catid) LEFT JOIN ".$prefix."_topics AS t on (s.topic=t.topicid) $qdb $querylang ORDER BY s.time DESC LIMIT $offset, $storynum";
    $result = $db->sql_query($sql);

    $nc = 0; //обнуляем счетчик колонок
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"><tr valign=\"top\">"; //открываем таблицу

    while (list($s_sid , $catid, $aid, $title, $time, $hometext, $bodytext, $comments, $counter, $topic, $informant, $notes, $acomm, $score, $ratings, $ctitle, $topicid, $topicname, $topicimage, $topictext) = $db->sql_fetchrow($result)) {
        if ($catid > 0) {
            $cattitle = $ctitle;
        }
        formatTimestamp($time);
        $c_count = $comments;
        if ($catid != 0) {
            $title_cat = stripslashes(check_html($ctitle, "nohtml"));
            $story_link = "<a href=\"index.php?name=News&file=article&sid=$s_sid\" title=\"$title_cat - $title\">";
            $title = "<a href=\"index.php?name=News&file=categories&op=newindex&catid=$catid\" title=\"$title_cat\"><font class=\"storycat\">$title_cat</a> - </font><a href=\"index.php?name=News&file=article&sid=$s_sid\" title=\"$title\"><font class=\"storytitle\">$title</font></a>";
        } else {
            $story_link = "<a href=\"index.php?name=News&file=article&sid=$s_sid\" title=\"$title\">";
            $title = "<a href=\"index.php?name=News&file=article&sid=$s_sid\" title=\"$title\"><font class=\"storytitle\">$title</font></a>";
        }
        if ($acomm == 0) {
            if ($c_count == 0) {
                $m_com = "| $story_link"._COMMENTS."</a>";
            } elseif ($c_count == 1) {
                $m_com = "| $story_link"._COMMENT.": $c_count</a>";
            } elseif ($c_count > 1) {
                $m_com = "| $story_link"._COMMENTS.": $c_count</a>";
            }
        } else {
            $m_com = "";
        }
        if ($aid == $informant) {
            $posted = "<a href=\"index.php?name=Account&op=userinfo&user_name=$aid\">$aid</a>";
        } elseif ($informant != "" ) {
            $posted = "<a href=\"index.php?name=Account&op=userinfo&user_name=$informant\">$informant</a>";
        } else {
            $posted = "$anonymous";
        }
        $morelink = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"left\">$story_link<b>"._READMORE."</b></a> | "._PDATE.": $datetime | "._POSTEDBY.": $posted | "._READS.": $counter $m_com <td align=\"right\"><a href=\"index.php?name=News&file=print&op=PrintPage&sid=$s_sid\"><img src=\"images/blocks/Print.gif\" border=\"0\" alt=\""._PRINTER."\" title=\""._PRINTER."\" align=\"center\"></a>  <a href=\"index.php?name=News&file=friend&op=FriendSend&sid=$s_sid\"><img src=\"images/blocks/Contact.gif\" border=\"0\" alt=\""._FRIEND."\" title=\""._FRIEND."\" align=\"center\"></a></td></tr></table>";
        if ($score != 0) {
            $rated = substr($score / $ratings, 0, 4);
        } else {
            $rated = 0;
        }
        $morelink = str_replace(" |  | ", " | ", $morelink);

    $nc++; // увеличиваем счетчик на 1
    echo "<td width=\"50%\">"; // открываем ячейку таблицы

        themeindex($aid, $informant, $datetime, $title, $counter, $topic, $hometext, $notes, $morelink, $topicname, $topicimage, $topictext);

    if ($nc == 2){ // если счетчик равен 2
        echo "</td></tr><tr valign=\"top\">"; // закрываем строку таблицы и открываем новую
        $nc = 0;
    } else {
        echo "</td>"; // иначе закрываем только ячейку
    }

    }

    echo "</tr></table>"; // закрываем таблицу

    list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT Count(sid) AS csid FROM ".$prefix."_stories AS s $qdb $querylang"));
    $numpages = ceil($numstories / $storynum);
    if ($numpages > 1) {
        OpenTable();
        echo "<center><b>"._OVERALL." $numstories "._ON." $numpages "._PAGE_S." $storynum "._PERPAGE."</b><br>";
        if ($pagenum > 1) {
            $prevpage = $pagenum - 1;
            if (isset($new_topic)) {
                echo "<a href=\"index.php?name=News&new_topic=$new_topic&pagenum=$prevpage\">[<<] </a>";
            } else {
                echo "<a href=\"index.php?name=News&pagenum=$prevpage\">[<<] </a>";
            }
        }
        echo "[ ";
        for ($i=1; $i < $numpages+1; $i++) {
            if ($i == $pagenum) {
                echo "$i";
            } else {
                if (isset($new_topic)) {
                    echo "<a href=\"index.php?name=News&new_topic=$new_topic&pagenum=$i\"><b>$i</b></a>";
                } else {
                    echo "<a href=\"index.php?name=News&pagenum=$i\"><b>$i</b></a>";
                }
            }
            if ($i < $numpages) { echo " | "; } else { echo " ]"; }
        }
        if ($pagenum < $numpages) {
            $nextpage = $pagenum + 1;
            if (isset($new_topic)) {
                echo "<a href=\"index.php?name=News&new_topic=$new_topic&pagenum=$nextpage\"> [>>]</a>";
            } else {
                echo "<a href=\"index.php?name=News&pagenum=$nextpage\"> [>>]</a>";
            }
        }
        echo "</center>";
        CloseTable();
    }
    include("footer.php");
}

function Cat($catid) {
    global $storyhome, $topicname, $topicimage, $topictext, $datetime, $user, $prefix, $multilingual, $currentlang, $db, $module_name, $pagenum;
    if ($multilingual == 1) {
        $querylang = "AND (alanguage='$currentlang' OR alanguage='')";
    } else {
        $querylang = "";
    }
    include("header.php");
    $cookie = explode(":", addslashes(base64_decode($user)));
    if (isset($cookie[3])) {
        $storynum = intval($cookie[3]);
    } else {
        $storynum = $storyhome;
    }
    $catid = intval($catid);
    $pagenum = (!$pagenum) ? 1 : $pagenum;
    $offset = ($pagenum-1) * $storynum;
    $offset = intval($offset);
    $storynum = intval($storynum);
    $sql = "SELECT sid, s.catid, s.aid, s.title, s.time, s.hometext, s.bodytext, s.comments, s.counter, s.topic, s.informant, s.notes, s.acomm, s.score, s.ratings, c.title, t.topicid, t.topicname, t.topicimage, t.topictext FROM ".$prefix."_stories AS s LEFT JOIN ".$prefix."_stories_cat AS c on (s.catid=c.catid) LEFT JOIN ".$prefix."_topics AS t on (s.topic=t.topicid) WHERE s.catid='$catid' AND s.time <= NOW() $querylang ORDER BY s.time DESC LIMIT $offset, $storynum";
    $result = $db->sql_query($sql);
    while (list($s_sid , $catid, $aid, $title, $time, $hometext, $bodytext, $comments, $counter, $topic, $informant, $notes, $acomm, $score, $ratings, $ctitle, $topicid, $topicname, $topicimage, $topictext) = $db->sql_fetchrow($result)) {
        $n_catid = intval($catid);
        if ($catid > 0) $cattitle = $ctitle;
        formatTimestamp($time);
        $c_count = $comments;
        $title_cat = text_filter($ctitle);
        $story_link = "<a href=\"index.php?name=News&op=Article&sid=$s_sid\" title=\"$title_cat - $title\">";
        $story_link_c = "<a href=\"index.php?name=News&op=Article&sid=$s_sid#$s_sid\" title=\"$title_cat - $title\">";
        $title = "<a href=\"index.php?name=News&op=Cat&catid=$catid\" title=\"$title_cat\"><font class=\"storycat\">$title_cat</a> - </font><a href=\"index.php?name=News&op=Article&sid=$s_sid\" title=\"$title\"><font class=\"storytitle\">$title</font></a>";
        if ($acomm == 0) {
            if ($c_count == 0) {
                $m_com = "| $story_link_c"._COMMENTS."</a>";
            } elseif ($c_count == 1) {
                $m_com = "| $story_link_c"._COMMENT.": $c_count</a>";
            } elseif ($c_count > 1) {
                $m_com = "| $story_link_c"._COMMENTS.": $c_count</a>";
            }
        } else {
            $m_com = "";
        }
        if ($aid == $informant) {
            $posted = "<a href=\"index.php?name=Account&op=userinfo&user_name=$aid\">$aid</a>";
        } elseif ($informant != "" ) {
            $posted = "<a href=\"index.php?name=Account&op=userinfo&user_name=$informant\">$informant</a>";
        } else {
            $posted = "$anonymous";
        }
        $morelink = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"left\">$story_link<b>"._READMORE."</b></a> | "._PDATE.": $datetime | "._POSTEDBY.": $posted | "._READS.": $counter $m_com <td align=\"right\"><a href=\"index.php?name=News&op=PrintPage&sid=$s_sid\"><img src=\"images/blocks/Print.gif\" border=\"0\" alt=\""._PRINTER."\" title=\""._PRINTER."\" align=\"center\"></a>&nbsp;&nbsp;<a href=\"index.php?name=News&op=FriendSend&sid=$s_sid\"><img src=\"images/blocks/Contact.gif\" border=\"0\" alt=\""._FRIEND."\" title=\""._FRIEND."\" align=\"center\"></a></td></tr></table>";
        if ($score != 0) {
            $rated = substr($score / $ratings, 0, 4);
        } else {
            $rated = 0;
        }
        $morelink = str_replace(" |  | ", " | ", $morelink);
        themeindex($aid, $informant, $time, $title, $counter, $topic, bb_decode($hometext), $notes, $morelink, $topicname, $topicimage, $topictext);
    }
    list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT Count(catid) AS csid FROM ".$prefix."_stories AS s WHERE s.catid='$n_catid' AND s.time <= NOW() $querylang"));
    $numpages = ceil($numstories / $storynum);
    num_page($module_name, $numstories, $numpages, $storynum, "op=Cat&catid=".$n_catid."&");
    include("footer.php");
}

function Article($sid) {
    global $db, $storyhome, $topicname, $topicimage, $topictext, $datetime, $user, $prefix, $multilingual, $currentlang, $sitename, $user_news, $pagenum, $anonymous, $module_name, $pagetitle, $defis, $admin_file, $hometext, $bodytext;
    $sid = intval($sid);
    $result = $db->sql_query("SELECT s.catid, s.aid, s.time, s.title, s.hometext, s.bodytext, s.topic, s.informant, s.notes, s.acomm, s.haspoll, s.pollID, s.score, s.ratings, s.associated, c.title, t.topicid, t.topicname, t.topicimage, t.topictext FROM ".$prefix."_stories AS s LEFT JOIN ".$prefix."_stories_cat AS c on (s.catid=c.catid) LEFT JOIN ".$prefix."_topics AS t on (s.topic=t.topicid) WHERE sid='$sid' AND s.time <= NOW()");
    if ($numrows = $db->sql_numrows($result) == 1) {
        list($catid, $aid, $time, $title, $hometext, $bodytext, $topic, $informant, $notes, $acomm, $haspoll, $pollID, $score, $ratings, $associated, $ctitle, $topicid, $topicname, $topicimage, $topictext) = $db->sql_fetchrow($result);
        $db->sql_query("UPDATE ".$prefix."_stories SET counter=counter+1 where sid='$sid'");
        if ($catid != 0) {
            $pagetitle = "$defis "._NEWS." $defis $ctitle $defis $title";
        } else {
            $pagetitle = "$defis "._NEWS." $defis $title";
        }
        include("header.php");
        formatTimestamp($time);
        if ($notes != "") {
            $notes = "<br><br><b>"._NOTES."</b><br><br>$notes";
        } else {
            $notes = "";
        }
        if ($bodytext == "") {
            $bodytext = "".$hometext."".$notes."";
        } else {
            $bodytext = "".$hometext."<br><br>".$bodytext."".$notes."";
        }
        if ($catid != 0) {
            $title = "<a href=\"index.php?name=$module_name&op=Cat&catid=$catid\"><font class=\"storycat\">$ctitle</a> - </font><font class=\"storytitle\">$title</font>";
        } else {
            $title = "<font class=\"storytitle\">$title</font>";
        }
        themearticle($aid, $informant, $datetime, $title, bb_decode($bodytext), $topic, $topicname, $topicimage, $topictext);
        OpenTable();
        echo "<center>[ <a href=\"index.php?name=$module_name&op=PrintPage&sid=$sid\" title=\""._PRINTER."\">"._PRINTER."</a> | <a href=\"index.php?name=$module_name&op=FriendSend&sid=$sid\" title=\""._FRIEND."\">"._FRIEND."</a>";
        if (is_admin($admin)) {
            echo " | <a href=\"".$admin_file.".php?op=adminStory\">"._ADD."</a> | <a href=\"".$admin_file.".php?op=EditStory&sid=$sid\">"._EDIT."</a> | <a href=\"".$admin_file.".php?op=RemoveStory&sid=$sid\">"._DELETE."</a> ]</center>";
        } else {
            echo " ]</center>";
        }
        CloseTable();
        if ($multilingual == 1) {
            $querylang = "AND (blanguage='$currentlang' OR blanguage='')";
        } else {
            $querylang = "";
        }
        OpenTable();
        echo "<center><font class=\"option\">"._RATEARTICLE."</center></font></center><br>"
        ."<table align=\"center\"><tr><td>"._AVERAGESCORE.": </td><td>".vote_graphic($ratings, $score)."</td><td>"._VOTES.":</td><td>$ratings</td></tr></table>"
        ."<hr><table width=\"100%\" align=\"center\" border=\"0\"><tr><td><form action=\"index.php?name=$module_name\" method=\"post\">"
        ."<input type=\"hidden\" name=\"sid\" value=\"$sid\">"
        ."<input type=\"hidden\" name=\"op\" value=\"RateArticle\">"
        ."<input type=\"radio\" name=\"score\" value=\"5\"> <img src=\"images/articles/stars-5.gif\" border=\"0\" alt=\""._EXCELLENT."\" title=\""._EXCELLENT."\"></td>"
        ."<td><input type=\"radio\" name=\"score\" value=\"4\"> <img src=\"images/articles/stars-4.gif\" border=\"0\" alt=\""._VERYGOOD."\" title=\""._VERYGOOD."\"></td>"
        ."<td><input type=\"radio\" name=\"score\" value=\"3\"> <img src=\"images/articles/stars-3.gif\" border=\"0\" alt=\""._GOOD."\" title=\""._GOOD."\"></td>"
        ."<td><input type=\"radio\" name=\"score\" value=\"2\"> <img src=\"images/articles/stars-2.gif\" border=\"0\" alt=\""._REGULAR."\" title=\""._REGULAR."\"></td>"
        ."<td><input type=\"radio\" name=\"score\" value=\"1\"> <img src=\"images/articles/stars-1.gif\" border=\"0\" alt=\""._BAD."\" title=\""._BAD."\"></td>"
        ."<td align=\"right\"><input type=\"submit\" value=\""._CASTMYVOTE."\"></td></tr></form></table>";
        CloseTable();
        if ($associated != "") {
            OpenTable();
            echo "<center><font class=\"option\">"._ASTOPIC."</font></center><br>";
            $asso_t = explode("-", $associated);
            for ($i = 0; $i<sizeof($asso_t); $i++) {
                if ($asso_t[$i] != "") {
                    $t = intval($asso_t[$i]);
                    $result = $db->sql_query("SELECT sid, title, time FROM ".$prefix."_stories WHERE topic='$t' AND sid!='$sid' ORDER BY time DESC LIMIT 0, 10");
                    while(list($s_sid, $title, $time)= $db->sql_fetchrow($result)) {
                        echo "<table><tr><td><img src=\"images/blocks/News.gif\" border=\"0\" title=\"$title\"></td><td>$time - <a href=\"index.php?name=News&op=Article&sid=$s_sid\" title=\"$title\">$title</a></td></tr></table>";
                    }
                }
            }
            CloseTable();
        }
        if ($acomm == 0) {
            echo "<a name=\"$sid\"></a>";
            ShowComments($sid);
        }
        include("footer.php");
    } else {
        Header("Location: index.php");
        exit;
    }
}

function RateArticle($sid, $score) {
    global $prefix, $db, $ratecookie;
    $score = intval($score);
    $sid = intval($sid);
    if ($score) {
        if ($score > 5) $score = 5;
        if ($score < 1) $score = 1;
        if ($score != 1 AND $score != 2 AND $score != 3 AND $score != 4 AND $score != 5) {
            Header("Location: index.php");
            die();
        }
        if (isset($ratecookie)) $r_cookie = explode(":", addslashes(base64_decode($ratecookie)));
        for ($i = 0; $i < sizeof($r_cookie); $i++) {
            if ($r_cookie[$i] == $sid) $a = 1;
        }
        if ($a == 1) {
            Header("Location: index.php?name=News&op=RateComplete&sid=$sid&rated=1");
        } else {
            $result = $db->sql_query("UPDATE ".$prefix."_stories SET score=score+$score, ratings=ratings+1 WHERE sid='$sid'");
            $info = base64_encode("$rcookie$sid:");
            setcookie("ratecookie","$info",time()+3600);
            update_points(7);
            Header("Location: index.php?name=News&op=RateComplete&sid=$sid");
        }
    } else {
        include("header.php");
        title(""._ARTICLERATING."");
        OpenTable();
        echo "<center>"._DIDNTRATE."<br><br>"._GOBACK."</center>";
        CloseTable();
        include("footer.php");
    }
}

function RateComplete($sid, $rated=0) {
    include("header.php");
    title(""._ARTICLERATING."");
    OpenTable();
    if ($rated == 0) {
        echo "<center>"._THANKSVOTEARTICLE."<br><br>"
        ."[ <a href=\"index.php?name=News&op=Article&sid=$sid\">"._BACKTOARTICLEPAGE."</a> ]</center>";
    } elseif ($rated == 1) {
        echo "<center>"._ALREADYVOTEDARTICLE."<br><br>"
        ."[ <a href=\"index.php?name=News&op=Article&sid=$sid\">"._BACKTOARTICLEPAGE."</a> ]</center>";
    }
    CloseTable();
    include("footer.php");
}

function PrintPage($sid) {
    global $site_logo, $homeurl, $sitename, $datetime, $prefix, $db, $module_name, $defis, $ThemeSel;
    $defis = urldecode($defis);
    $sid = intval($sid);
    $result = $db->sql_query("SELECT title, time, hometext, bodytext, topic, notes FROM ".$prefix."_stories WHERE sid='$sid' AND time <= NOW()");
    if ($numrows = $db->sql_numrows($result) == 1) {
        list($title, $time, $hometext, $bodytext, $topic, $notes) = $db->sql_fetchrow($result);
        list($topictext) = $db->sql_fetchrow($db->sql_query("SELECT topictext FROM ".$prefix."_topics WHERE topicid='$topic'"));
        formatTimestamp($time);
        echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
        ."<html>\n"
        ."<head>\n"
        ."<meta http-equiv=\"content-type\" content=\"text/html; charset="._CHARSET."\">\n"
        ."<link rel=\"stylesheet\" href=\"templates/$ThemeSel/style.css\" type=\"text/css\">\n"
        ."<title>$sitename $defis "._NEWS." $defis $title</title></head><body><table border=\"0\" align=\"center\"><tr><td><table border=\"0\" width=\"640\" cellpadding=\"0\" cellspacing=\"0\"><tr><td><table border=\"0\" width=\"640\" cellpadding=\"20\" cellspacing=\"1\" class=\"bodyline\"><tr><td><center><a href=\"$homeurl\"><img src=\"images/$site_logo\" border=\"0\" alt=\"$sitename\"></a><br><br><font class=\"content\"><b>$title</b></font><br><font class=tiny><b>"._PDATE.":</b> $datetime<br><b>"._PTOPIC.":</b> $topictext</font><br><br></center><font class=\"content\">".bb_decode($hometext)."<br><br>".bb_decode($bodytext)."<br><br></font></td></tr></table></td></tr></table><p><center><font class=\"content\">"._COMESFROM.": <a href=\"$homeurl\">$homeurl</a><br>"._THEURL.": <a href=\"$homeurl/index.php?name=$module_name&op=Article&sid=$sid\">$homeurl/index.php?name=$module_name&op=Article&sid=$sid</a></font></td></tr></table></body></html>";
    } else {
        Header("Location: index.php");
        exit;
    }
}

function FriendSend($sid) {
    global $user, $userinfo, $prefix, $db, $user_prefix, $module_name, $pagetitle, $defis, $stop;
    $sid = intval($sid);
    $result = $db->sql_query("SELECT title FROM ".$prefix."_stories WHERE sid='$sid' AND time <= NOW()");
    if ($numrows = $db->sql_numrows($result) == 1) {
        list($title) = $db->sql_fetchrow($result);
        $title = stripslashes($title);
        $pagetitle = "$defis "._NEWS." $defis $title $defis "._FRIEND."";
        include ("header.php");
        title(""._FRIEND."");
        if ($stop) warning($stop, "", "", 1);
        OpenTable();
        echo "<center><font class=\"content\"><b>"._YOUSENDSTORY." \"$title\" "._TOAFRIEND."</b></center><br>"
        ."<form action=\"index.php?name=$module_name\" method=\"post\">"
        ."<input type=\"hidden\" name=\"sid\" value=\"$sid\">";
        if (is_user($user)) {
            getusrinfo($user);
            $yn = $userinfo['user_name'];
            $ye = $userinfo['user_email'];
        }
        echo "<table align=\"center\"><tr><td>"._YOURNAME.":</td><td><input type=\"text\" name=\"yname\" value=\"$yn\" size=\"30\"></td></tr>"
        ."<tr><td>"._YOUREMAIL.":</td><td><input type=\"text\" name=\"ymail\" value=\"$ye\" size=\"30\"></td></tr>"
        ."<tr><td>"._FFRIENDNAME.":</td><td><input type=\"text\" name=\"fname\" size=\"30\"></td></tr>"
        ."<tr><td>"._FFRIENDEMAIL.":</td><td><input type=\"text\" name=\"fmail\" size=\"30\"></td></tr></table><br>"
        ."<center><input type=\"hidden\" name=\"op\" value=\"SendStory\">\n"
        ."<input type=\"submit\" value="._SEND.">\n"
        ."</form></center>\n";
        CloseTable();
    } else {
        Header("Location: index.php");
        exit;
    }
    include ('footer.php');
}

function SendStory($sid, $yname, $ymail, $fname, $fmail) {
    global $sitename, $homeurl, $prefix, $db, $module_name, $stop;
    checkemail($ymail);
    checkemail($fmail);
    if (!$stop) {
        $sid = intval($sid);
        list($title, $time, $topic) = $db->sql_fetchrow($db->sql_query("SELECT title, time, topic FROM ".$prefix."_stories WHERE sid='$sid'"));
        $title = stripslashes($title);
        $time = stripslashes($time);
        $topic = intval($topic);
        list($topictext) = $db->sql_fetchrow($db->sql_query("SELECT topictext FROM ".$prefix."_topics WHERE topicid='$topic'"));
        $topictext = stripslashes($topictext);
        $subject = "$sitename - "._INTERESTING."";
        $message = ""._HELLO." $fname!<br />"._YOURFRIEND." $yname "._CONSIDERED."<br /><br />"._FSTORY.": $title<br />"._PDATE.": ".formatTimestamp($time)."<br />"._PTOPIC.": $topictext<br /><br />"._THEURL.": <a href=\"$homeurl/index.php?name=$module_name&op=Article&sid=$sid\" target=\"_blank\">$homeurl/index.php?name=$module_name&op=Article&sid=$sid</a><br /><br />"._YOUCANREAD.": <a href=\"$homeurl\" target=\"_blank\">$sitename</a><br />"._FSITEURL.": <a href=\"$homeurl\" target=\"_blank\">$homeurl</a>";
        mail_send($fmail, $ymail, $subject, $message, 0, 3);
        update_points(6);
        include("header.php");
        title(""._FRIEND."");
        warning(""._FSTORY." \"$title\" "._HASSENT." $fname", "?name=$module_name&op=Article&sid=$sid", 5, 2);
        include("footer.php");
    } else {
        FriendSend($sid);
    }
}

switch ($op) {
    default:
    News($new_topic);
    break;

    case "Cat":
    Cat($catid);
    break;
    
    case "Article":
    Article($sid);
    break;
    
    case "RateArticle":
    RateArticle($sid, $score);
    break;

    case "RateComplete":
    RateComplete($sid, $rated);
    break;

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

    case "FriendSend":
    FriendSend($sid);
    break;
}
?>
