<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
include_once("admin_header.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsform/formdhtmltextarea.php");
function Choice() {
global $xoopsModule;
xoops_cp_header();
OpenTable();
echo "<a href='index.php?op=Config'>"._XTG_GUESTBOOK_CONFIG."</a><br />";
echo "<a href='index.php?op=modlogo'>"._XTG_IMGCHANGE."</a><br />";
echo "<a href='index.php?op=Messageshow'>"._XTG_GUESTBOOK_EDIT."</a><br />";
CloseTable();
xoops_cp_footer();
}
function Config() {
xoops_cp_header();
OpenTable();
global $myts;
include_once("../cache/config.php");
echo _XTG_INTROTEXT;
echo "<form name='frmmessage' action='index.php?op=SaveConfig' method='post'>";
$disclaimer = join('', file("../cache/disclaimer.txt"));
$disclaimer = $myts->makeTboxData4PreviewInForm($disclaimer);
$desc       = new XoopsFormDhtmlTextArea('', 'disclaimer', $disclaimer, 10, 50);
echo $desc->render();
echo "<P>";
echo _XTG_NBMSGBYPAGE." : <input type='text' class='text' value='$nbmsgbypage' name='nbmessage' /><br />";
if ($allowbbcode==1) $allowbbcode1="selected='selected'";
else $allowbbcode0="selected='selected'";
if($allowhtml==1) $allowhtml1="selected='selected'";
else $allowhtml0="selected='selected'";
if($allowsmileys==1) $allowsmileys1="selected='selected'";
else $allowsmileys0="selected='selected'";
if($sendmail2webmaster==1) $sendmail2webmaster1="selected='selected'";
else $sendmail2webmaster0="selected='selected'";
if($moderate==1) $moderate1="selected='selected'";
else $moderate0="selected='selected'";
if($showdisclaimer==1) $showdisclaimer1="selected='selected'";
else $showdisclaimer0="selected='selected'";
if($showlogo==1) $showlogo1="selected='selected'";
else $showlogo0="selected='selected'";
echo _XTG_ALLOWBBCODE." : <select class='select' name='allowbbcode'><option value='1' ".$allowbbcode1.">"._YES."</option><option value='0' ".$allowbbcode0.">"._NO."</option></select><br />";
echo _XTG_ALLOWHTML." : <select class='select' name='allowhtml'><option value='1' ".$allowhtml1.">"._YES."</option><option value='0' ".$allowhtml0.">"._NO."</option></select><br />";
echo _XTG_ALLOWSMILEYS." : <select class='select' name='allowsmileys'><option value='1' ".$allowsmileys1.">"._YES."</option><option value='0' ".$allowsmileys0.">"._NO."</option></select><br />";
echo _XTG_SENDMAIL2WEBMASTER." : <select class='select' name='sendmail2webmaster'><option value='1' ".$sendmail2webmaster1.">"._YES."</option><option value='0' ".$sendmail2webmaster0.">"._NO."</option></select><br />";
echo _XTG_MODERATE." : <select class='select' name='moderate'><option value='1' ".$moderate1.">"._YES."</option><option value='0' ".$moderate0.">"._NO."</option></select><br />";
echo _XTG_DISCLAIMER." : <select class='select' name='showdisclaimer'><option value='1' ".$showdisclaimer1.">"._YES."</option><option value='0' ".$showdisclaimer0.">"._NO."</option></select><br />";
echo _XTG_LOGO." : <select class='select' name='showlogo'><option value='1' ".$showlogo1.">"._YES."</option><option value='0' ".$showlogo0.">"._NO."</option></select><br />";
echo "<input type='submit' class='button' name='submit' value='Ok' /></form";
CloseTable();
xoops_cp_footer();
}
function SaveConfig($nbmessage,$allowbbcode,$allowhtml,$allowsmileys,$sendmail2webmaster,$moderate,$showdisclaimer,$showlogo) {
global $db, $myts, $_POST;
$fp=fopen("../cache/config.php","w");
fwrite($fp,'<?php
$allowbbcode='.$allowbbcode.';
$allowhtml='.$allowhtml.';
$allowsmileys='.$allowsmileys.';
$nbmsgbypage='.$nbmessage.';
$sendmail2webmaster='.$sendmail2webmaster.';
$moderate='.$moderate.';
$showdisclaimer='.$showdisclaimer.';
$showlogo='.$showlogo.';
?>');
fclose($fp);
$filename = XOOPS_ROOT_PATH."/modules/xtremguestbook/cache/disclaimer.txt";
if ( $file = fopen($filename, "wb") ) {
	$disclaimer = $myts->oopsStripSlashesGPC($_POST['disclaimer']);
	fwrite($file, $disclaimer);
	fclose($file);
	} else {
		redirect_header("index.php", 1, XTG_NOTUPDATED);
		exit();
	}
	
		redirect_header("index.php", 1, _UPDATED);
	exit();
}
function Messagedel($idmsg,$uid) {
xoops_cp_header();
OpenTable();
echo "<div align='center'>"._DELETE."<br /><br />
<input type='button' class='button' onclick=\"document.location='index.php?op=Messagedel1&idmsg=".$idmsg."&uid=$uid'\" value='"._YES."'>
<input type='button' class='button' onclick=\"document.location='index.php'\" value='"._NO."'></div>";
CloseTable();
xoops_cp_footer();
}
function Messagedel1($idmsg,$uid) {
global $db;
if ($uid != 0) {
	$sql = "UPDATE ".$db->prefix("users")." SET posts=posts-1 WHERE uid=".$uid."";
		   $db->query($sql);
		}
$result=$db->query("DELETE FROM ".$db->prefix("xtremguestbook")." WHERE xtremguestbook_id=$idmsg");
redirect_header("index.php",1,_XTG_MSGDEL);
exit();
}
function Messageapprove($idmsg) {
global $db;
$result=$db->query("update ".$db->prefix("xtremguestbook")." SET moderate=0 WHERE xtremguestbook_id=$idmsg");
redirect_header("index.php",1,_XTG_MSGAPPROVE);
exit();
}
function Messagesave($idmsg,$uname,$url,$email,$title,$message,$note) {
global $db, $myts;
$uname   = $myts->makeTareaData4Save($uname);
$email   = $myts->makeTareaData4Save($email);
$url     = $myts->makeTareaData4Save($url);
$title   = $myts->makeTareaData4Save($title);
$message = $myts->makeTareaData4Save($message);
$note    = $myts->makeTareaData4Save($note);
$db->query("UPDATE ".$db->prefix("xtremguestbook")." set uname='$uname', url='$url', email='$email', title='$title', message='$message', note='$note' WHERE xtremguestbook_id=$idmsg");
redirect_header("index.php",1,_XTG_MSGMOD);
exit();
}
function Messageedit($idmsg) {
global $db, $xoopsModule, $myts;
xoops_cp_header();
$result=$db->query("SELECT user_id,uname,url,email,title,message,note FROM ".$db->prefix("xtremguestbook")." WHERE xtremguestbook_id=$idmsg");
list($user_id,$uname,$url,$email,$title,$message,$note) = $db->fetchRow($result);
$uname   = $myts->makeTareaData4Edit($uname);
$email   = $myts->makeTareaData4Edit($email);
$url     = $myts->makeTareaData4Edit($url);
$title   = $myts->makeTareaData4Edit($title);
$message = $myts->makeTareaData4Edit($message);
OpenTable();
if($user_id!=0) {
	$disabled="readonly='readonly'";
	}
echo "
<form name='guestbook' action='index.php?op=Messagesave' method='post'>
<table width='95%' border='0'>
<tr><td>
"._XTG_NAME."
</td><td>
<input name='uname' type='text' class='text' ".$disabled." value='".$uname."' />
</td></tr>
<tr><td>
"._EMAIL."
</td><td>
<input name='email' type='text' class='text' ".$disabled." value='".$email."' />
</td></tr>
<tr><td>
"._XTG_URL."
</td><td>
<input name='url' type='text' class='text' ".$disabled." value='".$url."' />
</td></tr>
<tr><td>
"._XTG_TITLE."
</td><td>
<input name='title' id='title' class='text' value='".$title."' type='text'  />
</td></tr>
<tr><td>
"._XTG_MESSAGE."
</td><td>
<textarea name='message' id='message' class='text' cols='50' rows='5'>$message</textarea>
</td></tr>
<tr><td>
"._XTG_NOTE."
</td><td>
<textarea name='note' id='note' class='textarea' cols='50' rows='5'>$note</textarea>
</td></tr>
<tr><td>
&nbsp;
</td><td>
<input type='hidden' name='idmsg' value='$idmsg' />
<input type='submit' class='button' value='"._XTG_SEND."' />
</td></tr>
</table>
</form>";
CloseTable();
xoops_cp_footer();
}
function Messageshow() {
global $db, $myts;
xoops_cp_header();
OpenTable();
echo "
<table border='1' width='90%'>
<tr><td><b>"._XTG_NUM."</b></td><td><b>"._XTG_NAME."</b></td><td><b>"._XTG_TITLE."</b></td><td><b>"._XTG_MESSAGE."</b></td><td><b>"._XTG_ACTION."</b></td></tr>";
$result=$db->query("SELECT xtremguestbook_id,title,message,uname,user_id,moderate FROM ".$db->prefix("xtremguestbook")." order by post_time desc");
$nbmessage=$db->getRowsNum($result);
while (list($idmsg,$title,$message,$uname,$uid,$moderate) = $db->fetchRow($result)) {
	$message = $myts->sanitizeForDisplay($message, 0, 1, 1);
	$title   = $myts->sanitizeForDisplay($title, 0, 0, 0);
	if($moderate) $approve="<a href='index.php?op=Messageapprove&idmsg=$idmsg'>"._XTG_APPROVE."</a> | ";
	else $approve="";
	echo "<tr>
	<td>$nbmessage )</td>
	<td>";
	if ($uid!=0) echo "<a href='../../../userinfo.php?uid=$uid'>$uname</a>";
	else echo $uname;
	echo "</td>
	<td>$title&nbsp;</td>
	<td>$message&nbsp;</td>
	<td>".$approve."<a href='index.php?op=Messageedit&idmsg=$idmsg'>"._XTG_EDIT."</a> | <a href='index.php?op=Messagedel&idmsg=$idmsg&uid=$uid'>"._DELETE."</a></td>
	</tr>";
	$nbmessage--;
	}
echo "</table>";
CloseTable();
xoops_cp_footer();
}


switch($op) {
case "Messagesave":
	Messagesave($idmsg,$_POST["uname"],$_POST["url"],$_POST["email"],$_POST["title"],$_POST["message"],$_POST["note"]);
	break;
case "Messageedit":
	Messageedit($_GET["idmsg"]);
	break;
case "Messageapprove":
	Messageapprove($_GET["idmsg"]);
	break;
case "Messagedel":
	Messagedel($_GET["idmsg"],$_GET["uid"]);
	break;
case "Messagedel1":
	Messagedel1($_GET["idmsg"],$_GET["uid"]);
	break;
case "Messageshow":
	Messageshow();
	break;
case "Config":
	Config();
	break;
case "SaveConfig":
	SaveConfig($nbmessage,$_POST["allowbbcode"],$_POST["allowhtml"],$_POST["allowsmileys"],$_POST["sendmail2webmaster"],$_POST["moderate"],$_POST["showdisclaimer"],$_POST["showlogo"]);
	break;
 
default:
	Choice();
	break;
}
?>
