<?php
$lcheck = "b";
$z = "b";
global $setting;

//To view the comments
function view_comments($id) {
global $pre;
global $setting;

include ("forum_functions.php");
echo "</br><table cellspacing=\"0\" cellpadding=\"1\" border=\"1\" width=\"600\">";

$sql = mysql_query("SELECT * FROM ".$pre."comments WHERE aid = '".$id."' AND type = 'content' ORDER BY `id` DESC");
while($r = mysql_fetch_array($sql)) {

$sql2 = mysql_query("SELECT id FROM ".$pre."profile WHERE username = '".$r[name]."'");
$mr = mysql_num_rows($sql2);
$ma = mysql_fetch_row($sql2);

	if ($mr > "0") {
		$user = "<a href='index.php?load=elite&user=".$ma[0]."'>".$r[name]."</a>";
	} else {
		$user = "Guest";
	}
	echo "<tr><td><center><b>Profile</b></center></td><td><b>".$r[subject]."</b> posted by ".$user." at <i>".date($setting[dformat], $r['date'])."</i></td></tr><tr><td>".comments($r[name])."</td><td><p>".bbcode(stripslashes($r[comment]))."</p>".comments3($r[name])."</td></tr>";
}
echo "</table>";
}

//To Post them
function comment($id,$url) {


global $setting;
global $useridn;
global $email;

if($useridn == "" && $setting[guest_comments] == "No") {
echo "Sorry, but you have to be logged in to comment on ".$setting[sitename].". Please <a href='login.html'><b>Login</b></a> or <a href='register.html'><b>Register</b></a>";
} else {

//If you want to enable the WYSIWYG editor for comments, simply uncoment the below line
//echo wysiwyg();
echo "<SCRIPT LANGUAGE='JavaScript'>
  function smiles(which) {
  document.form1.text1.value = document.form1.text1.value + which;
  }
</SCRIPT>
<script language='javascript'>
function awindow(towhere, newwinname, properties) {
window.open(towhere,newwinname,properties);
}
</script>
<form name='form1' method='post' action='comments.php?view=add'>
<input type='hidden' name='aid' value='".$_GET['id']."'>
<input type='hidden' name='name' value='".$_COOKIE[$pre."username"]."'>
<table cellspacing=\"0\" cellpadding=\"1\" border=\"0\" align=\"center\">";
if ($useridn == "") {
echo "<tr><td><b>Name</b></td><td><input type='text' name='name' width='18'></td></tr><tr><td><b>Email</b></td><td><input type='text' name='email' width='18'></td></tr>";
} else{
echo "<tr><td><b>Name</b></td><td>".$_COOKIE[$pre."username"]."</td></tr><tr><td><b>E-mail</b></td><td>".$email."</td></tr>";
} 
echo "<tr><td><b>Subject</b></td><td><input type='text' name='title' width='18'></td></tr>
<tr><td><b>Comments</b></td><td><textarea name=\"text1\" cols='18' rows='7'></textarea></td><td width='65'><b>Smilies</b>";

echo "<br><br><a href='javascript:awindow(\"comments.php?view=smilies\", \"\", \"width=300,height=200,scroll=yes\")'>View All</a><br></br>";

if ($setting[captcha] == Yes) {
$ts = time();
?>
<script language="JavaScript"><!--
ts = <?= $ts ?>;
--></script>
<?php

echo "<tr><td><img id='captcha' src='includes/captcha.php?img=".$ts."'></td></tr><tr><td>* Displayed Code?</td><td><input type='text' name='captcha'><a href=\"no_matter\" onclick=\"document.getElementById('captcha').src = 'includes/captcha.php?img=' + ++ts; return false\"> New CAPTCHA</a></td></tr>";
}
echo "</td></tr><tr><td><input type='submit' value='Submit Comment'></td><td><input type='reset' name='reset' value='Reset'></td></tr></table></form>";

}
}

if ($_GET['view'] == "add") {
include("config.php");

if ($setting[captcha] == Yes) {
session_start();
$salted = $_POST['captcha'];
global $captcha_salt;
if (md5($captcha_salt.$salted) != $_SESSION['captcha']) {
eval (" ?>" . headera() . " <?php ");
echo "Wrong code entered, go back and try again";
echo $captcha_salt;
eval (" ?>" . footera() . " <?php ");
die;
}
}

if ($_POST["name"] == "") {
$name = "Guest";
} else {
$name = $_COOKIE[$pre."username"];
}

$comment = mysql_query("INSERT INTO ".$pre."comments VALUES ('null', '".$name."', '".$_POST["title"]."', '".addslashes($_POST["text1"])."', '".$_POST["aid"]."', '".$email."', '".time()."', '".$_SERVER[REMOTE_ADDR]."', 'content')") or die(mysql_error());

if ($comment == TRUE) {
eval (" ?>" . headera() . " <?php ");
echo "<h1>Comment Posted</h1>";
echo "Your comment has been submitted.  You will now be redirected back to the last page you visited.  Thanks!";
echo re_direct("2000", $siteurl);
eval (" ?>" . footera() . " <?php ");
}
//}
}

if ($_GET['view'] == "smilies") {
echo "<SCRIPT LANGUAGE='JavaScript'>
function smiles2(text) {
	text = '' + text + '';
	opener.document.form1.text1.value  += text;
	opener.document.form1.text1.focus();
  }
</SCRIPT><title>".$sitename." - Smilies :: View All</title>";
echo "<table cellpadding='1' cellspacing='0' border='0' width='198' height='100%'><tr><td width='198' align='left' valign='top'>";
if ($handle = opendir("includes/smilies")) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$file2 = explode(".", $file);
echo "<a href=\"javascript:smiles2(' :".strtolower($file2[0]).": ')\"><img src='includes/smilies/".$file."' border='0'></a>&nbsp;";
}
}
}
}
?>