<?
/*---------------------------------------------------+
| PHP-Fusion 6 Content Management System
+----------------------------------------------------+
| Copyright © 2002 - 2006 Nick Jones
| http://www.php-fusion.co.uk/
+----------------------------------------------------+
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
+----------------------------------------------------+
| Modified by PHP-Fusion SF Group
| Copyright © 2007 by SF
| http://www.rus-phpfusion.com/
+----------------------------------------------------*/
require_once "maincore.php";
require_once "subheader.php";
require_once "side_left.php";

if (file_exists("locale/".$settings['locale']."/guestbook.php")) {
        include "locale/".$settings['locale']."/guestbook.php";
} else {
        include "locale/Russian/guestbook.php";
}
@$name=$userdata['user_name'];
@$email=$userdata['user_email'];
$weburl='';
$webtitle='';
$message='';

$result = dbquery("SELECT * FROM ".$db_prefix."settings");
$gb_set = dbarray($result);

$time=time()-$gb_set['gb_tm']*60;
$result = dbquery("SELECT * FROM ".$db_prefix."gbook WHERE (guestbook_datestamp>'".$time."' && guestbook_ip='".USER_IP."')");
$num = dbrows($result);
if (isset($_POST['gb_submit'])) {
if ($num == 0){

        $error = false;
        if ($settings['display_validation'] == "1") {
	if (!check_captcha($_POST['captcha_encode'], $_POST['captcha_code'])) {
		$error .= $locale['410']."<br />\n";
	}
}
       if (!$error && $_POST['gb_name'] != "" && $_POST['gb_message'] != "") {
                $guest_name = trim(stripinput($_POST['gb_name']));
                $guest_email = trim(stripinput($_POST['gb_email']));
                $guest_weburl = trim(stripinput($_POST['gb_weburl']));
                $guest_webtitle = trim(stripinput($_POST['gb_webtitle']));
                $guest_message = trim(stripinput($_POST['gb_message']));
                if ($guest_name != "" && $guest_message != "") {
                                $result = dbquery("INSERT INTO ".$db_prefix."gbook (guestbook_name, guestbook_email, guestbook_weburl, guestbook_webtitle, guestbook_message, guestbook_datestamp, guestbook_ip) VALUES('$guest_name', '$guest_email', '$guest_weburl', '$guest_webtitle', '$guest_message', '".time()."', '".USER_IP."')");
                }
                redirect(FUSION_SELF);
        } else {
                $name = trim(stripinput($_POST['gb_name']));
                $email = trim(stripinput($_POST['gb_email']));
                $weburl = trim(stripinput($_POST['gb_weburl']));
                $webtitle = trim(stripinput($_POST['gb_webtitle']));
                $message = trim(stripinput($_POST['gb_message']));
                opentable($locale['gb407']);
                echo "<div align='center'><b>".$locale['gb430']."</b><br>\n<span class='small'>";
                if ($error) { echo $locale['gb431']."<br>\n"; }        echo $locale['gb432']."</span></div>\n";
                closetable();
                tablebreak();
        }
}else{
     $name = trim(stripinput($_POST['gb_name']));
     $email = trim(stripinput($_POST['gb_email']));
     $weburl = trim(stripinput($_POST['gb_weburl']));
     $webtitle = trim(stripinput($_POST['gb_webtitle']));
     $message = trim(stripinput($_POST['gb_message']));
     opentable($locale['gb434']);
     echo "<div align='center'><b>".$locale['gb430']."</b><br>\n<span class='small'>";
     echo $locale['gb433']."</span></div>\n";
     closetable();
     tablebreak();
}
}
opentable($locale['gb400']);
        echo "<form name='inputform' method='post' action=''>
<table align='center' cellpadding='0' cellspacing='0'>
<tr>
<td align='right' class='tbl'>".@$locale['gb401']."<span style='color:#ff0000'>*</span></td>
<td class='tbl'><input type='text' name='gb_name' value='$name' class='textbox' style='width:200px'></td>
</tr>
<tr>
<td align='right' class='tbl'>".$locale['gb402']."</td>
<td class='tbl'><input type='text' name='gb_email' value='$email' class='textbox' style='width:200px'></td>
</tr>
<tr>
<td align='right' class='tbl'>".$locale['gb403']."</td>
<td class='tbl'><input type='text' name='gb_weburl' value='$weburl' class='textbox' style='width:200px'></td>
</tr>
<tr>
<td align='right' class='tbl'>".$locale['gb404']."</td>
<td class='tbl'><input type='text' name='gb_webtitle' value='$webtitle' class='textbox' style='width:200px'></td>
</tr>\n";
echo "<tr>\n<td class='tbl'>".$locale['gb407']."<span style='color:#ff0000'>*</span></td>\n<td class='tbl'>";
echo make_captcha();
echo "</td>
</tr>
<tr>
<td class='tbl'>".$locale['gb408']."<span style='color:#ff0000'>*</span></td>
<td class='tbl'><input type='text' name='captcha_code' class='textbox' style='width:100px'></td>
</tr>\n";       
echo "<tr>
<td align='right' valign='top' class='tbl'>".$locale['gb405']."<span style='color:#ff0000'>*</span></td>
<td class='tbl'><textarea name='gb_message' rows='5' class='textbox' style='width:250px'>$message</textarea><br><br>
".displaysmileys("gb_message")."
</td>
</tr>
<tr>
<td class='tbl'></td>
<td class='tbl'><input type='submit' name='gb_submit' value='".$locale['gb406']."' class='button'></td>
</tr>
</table>
</form>\n";
        closetable();
        tablebreak();

opentable($locale['gb420']);
$result = dbquery("SELECT * FROM ".$db_prefix."gbook");
$rows = dbrows($result);
if (!isset($rowstart) || !isNum($rowstart)) $rowstart = 0;
if ($rows != 0) {
        tablebreak();
        $i = 1;
        $result = dbquery("SELECT * FROM ".$db_prefix."gbook ORDER BY guestbook_datestamp DESC LIMIT $rowstart,".$gb_set['gb_kl']."");
        $numrows = dbrows($result);
        while ($data = dbarray($result)) {
                if ($data['guestbook_weburl']) {
                        $weburl = str_replace("http://", "", $data['guestbook_weburl']);
                        if ($data['guestbook_webtitle']) {
                                $alt= $data['guestbook_webtitle'];
                        } else {
                                $alt= $weburl;
                        }
                        $web = "<td width='0' align='right' style='padding-left: 5px; padding-right: 5px'><a href='http://$weburl' target='_blank'><img border='0' alt='$alt' src='images/home.gif' width='16' height='16' ></a></td>";
                } else {
                        $web = "";
                }
                if ($data['guestbook_email']) {
                        $email = '<td align="right" width="0" style="padding-left: 5px; padding-right: 5px"><a href="mailto:'.$data['guestbook_email'].'"><img alt="'.$data['guestbook_email'].'" border="0" src="images/mail.gif" width="16" height="16"></a></td>';
                } else {
                        $email = "";
                }
                echo "<table align='center' cellpadding='0' cellspacing='1' width='80%' class='tbl-border'>
<tr>
<td class='tbl2'>
<table cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td class='small'  width='100%'><b>".$data['guestbook_name']."</b></td>\n";
echo $email.$web;
                echo "</tr>
</table>
</td>
</tr>
<tr>
<td class='tbl1'>".nl2br(parsesmileys(parseubb($data['guestbook_message'])))."</td>
</tr>";
if ($data['guestbook_otvet']!=''){
echo "<tr>
<td class='tbl1'><i>".nl2br(parsesmileys(parseubb($data['guestbook_otvet'])))."<i></td>
</tr>";
}
echo "<tr>
<td class='tbl2'>
<table cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td class='small'>
".showdate("shortdate", $data['guestbook_datestamp'])."</td>\n";
echo "</tr>
</table>
</td>
</tr>
</table>\n";
                if ($i != $numrows) echo "<br>\n";
                $i++;
        }
} else {
        echo "<center><br>\n".$locale['gb423']."<br><br>\n</center>\n";
}
closetable();

if ($rows != 0) echo "<div align='center' style='margin-top:5px;'>\n".makePageNav($rowstart,$gb_set['gb_kl'],$rows,3,FUSION_SELF."?")."\n</div>\n";


require_once "side_right.php";
require_once "footer.php";
?>