<?php
/*---------------------------------------------------+
| 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 BASEDIR."subheader.php";
require_once ADMIN."navigation.php";

if (!checkrights("GB") || !defined("iAUTH") || $aid != iAUTH) fallback("../index.php");
if (file_exists("../locale/".$settings['locale']."/guestbook.php")) {
        include "../locale/".$settings['locale']."/guestbook.php";
} else {
        include "../locale/Russian/guestbook.php";
}
$data = dbarray($result);
$name = '';
$email = '';
$weburl = '';
$webtitle = '';
$message = '';
$otvet = '';
$formaction = FUSION_SELF.$aidlink;

if (isset($_GET['action']) && $_GET['action']=='edit'){
   $result = dbquery("SELECT * FROM ".$db_prefix."gbook WHERE guestbook_id='".intval($_GET['id'])."'");
    if (dbrows($result)) {
                $data = dbarray($result);
                $name = $data['guestbook_name'];
                $email = $data['guestbook_email'];
                $weburl = $data['guestbook_weburl'];
                $webtitle = $data['guestbook_webtitle'];
                $message = $data['guestbook_message'];
                $otvet = $data['guestbook_otvet'];
                $formaction = FUSION_SELF.$aidlink."&action=save&amp;id=".intval($_GET['id'])."";
    }
}
if (isset($_GET['action']) && $_GET['action']=='save') {
   $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']));
   $guest_otvet = trim(stripinput($_POST['gb_otvet']));
   dbquery("UPDATE ".$db_prefix."gbook SET guestbook_name='$guest_name', guestbook_email='$guest_email', guestbook_weburl='$guest_weburl', guestbook_webtitle='$guest_webtitle', guestbook_message='$guest_message', guestbook_otvet='$guest_otvet' WHERE guestbook_id='".intval($_GET['id'])."'");
}
if (isset($_GET['action']) && $_GET['action']=='delete') {
   $result = dbquery("DELETE FROM ".$db_prefix."gbook WHERE guestbook_id='".intval($_GET['id'])."'");
}
if (isset($_GET['action']) && $_GET['action']=='ud'){
   $dell=$_POST['dell'];
   for ($i=0; $i<count($dell); $i++){
       $result = dbquery("DELETE FROM ".$db_prefix."gbook WHERE guestbook_id='".$dell[$i]."'");
       redirect(FUSION_SELF);
   }
}

opentable($locale['gb437']);
        echo "<form name='inputform' method='post' action=$formaction>
<table align='center' cellpadding='0' cellspacing='0'>
<tr>
<td align='right' class='tbl'>".$locale['gb401']."</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>
<tr>
<td align='right' valign='top' class='tbl'>".$locale['gb405']."</td>
<td class='tbl'><textarea name='gb_message' rows='5' class='textbox' style='width:250px'>$message</textarea><br><br>
".displaysmileys("gb_message")."<br><br>
</td>
</tr>
<tr>
<td align='right' valign='top' class='tbl'>".$locale['gb438']."</td>
<td class='tbl'><textarea name='gb_otvet' rows='5' class='textbox' style='width:250px'>$otvet</textarea><br><br>
".displaysmileys("gb_otvet")."<br><br>
</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,10");
        $numrows = dbrows($result);
         echo "<form name='d' method='POST' action='".FUSION_SELF.$aidlink."&action=ud'>";
        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 "<td align='right' nowrap style='padding-left: 5px; padding-right: 5px'><b>ip:</b> ".$data['guestbook_ip']."</td>
</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 "
<td align='right' class='small'><a href='".FUSION_SELF.$aidlink."&action=edit&amp;id=".$data['guestbook_id']."'>".$locale['gb421']."</a> |
<a href='".FUSION_SELF.$aidlink."&action=delete&amp;id=".$data['guestbook_id']."' onClick='return DeleteMessage();'>".$locale['gb422']."</a>
<input type='checkbox' name='dell[]' value='".$data['guestbook_id']."'></td>
</tr>
</table>
</td>
</tr>
</table>
\n";
                if ($i != $numrows) echo "<br>\n";
                $i++;
        }
echo '<center>
<table border="0" cellspacing="0" cellpadding="0" width="80%">
     <tr>
        <td width="100%">&nbsp;</td>
        <td align="right" width="0"><input class="button" onClick="Dell();" type="button" value="'.$locale['gb422'].'"></td>
        <td align="right" width="0"><input class="button" onClick="SelAll();" type="button" value="'.$locale['gb439'].'"></td>
        <td align="right" width="0"><input class="button" onClick="RemAll();" type="button" value="'.$locale['gb440'].'"></td>
     </tr>
</table>
</center>
</form>';
} 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,10,$rows,3,FUSION_SELF."?")."\n</div>\n";

echo "<script>
function DeleteMessage() {
        return confirm(\"".$locale['gb424']."\");
}
function SelAll() {
numCheckbox = document.forms.d.length - 3;
for (i=0; i<numCheckbox; i++) document.forms.d.elements[i].checked=1;
}
function RemAll() {
numCheckbox = document.forms.d.length - 3;
for (i=0; i<numCheckbox; i++) document.forms.d.elements[i].checked=0;
}
function Dell() {
numCheckbox = document.forms.d.length - 3;
kl=0;
for (i=0; i<numCheckbox; i++) if (document.forms.d.elements[i].checked==1) kl++;
if (kl!=0) {if (confirm(\"".$locale['gb441']."\")) document.forms.d.submit();}
else {alert('".$locale['gb442']."');}
}
</script>\n";

require_once BASEDIR."footer.php";
?>