
<?php
/*-------------------------------------------------------+
| Ajax Comments mSF For PHP-Fusion 7.xx v.1.0
| Copyright © 2008-2009 Powered by .:MeF:.
| URL: http://x-iweb.ru/
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../../maincore.php";
require_once INCLUDES."comments/show_comments.php";  

    $cid = stripinput($_POST['id']);
    $ctype = stripinput($_POST['ctype']);
    $cdb = stripinput($_POST['cdb']);
    $ccol = stripinput($_POST['ccol']);
    $clink = stripinput($_POST['clink']);

        if (!iMEMBER) {
    $name = urldecode($_POST['name']);
    if ($locale['charset'] != 'UTF-8') { $name = iconv('UTF-8', $locale['charset'], $name); }
    $name = mysql_real_escape_string($name);	
        }

        if ($_GET['delete_comment'] == '0') {
    $comment = urldecode($_POST['comment']);
    $comment = iconv('UTF-8', $locale['charset'], $comment);
    $comment = mysql_real_escape_string($comment);
        } else { $comment = ""; }

    if ((iMEMBER || $settings['guestposts'] == "1") && isset($comment)) {

		if (iMEMBER) {
			$comment_name = $userdata['user_id'];
		} elseif ($settings['guestposts'] == "1") {
			$comment_name = trim(stripinput($name));
			$comment_name = preg_replace("(^[0-9]*)", "", $comment_name);
			if (isnum($comment_name)) { $comment_name = ""; }
			include_once INCLUDES."securimage/securimage.php";
			$securimage = new Securimage();
			if (!isset($_POST['com_captcha_code']) || $securimage->check($_POST['com_captcha_code']) == false) {
			show_comments($ctype, $cdb, $ccol, $cid, $clink); 
			echo "<div class='admin-message'>Neteisingai ivestas saugos kodas.</div>";
			die; }
		}

		$comment_message = trim(stripinput(censorwords($comment)));
		
	    if ($_GET['delete_comment'] == '1') {
	        if ((iADMIN && checkrights("C")) || (iMEMBER && dbcount("(comment_id)", DB_COMMENTS, "comment_id='".$_POST['comment_id']."' AND comment_name='".$userdata['user_id']."'"))) {
		    $result = dbquery("DELETE FROM ".DB_COMMENTS." WHERE comment_id='".$_POST['comment_id']."' AND comment_type = '".$ctype."'");
	        }
		
	    } else {

			if (!dbcount("(".$ccol.")", $cdb, $ccol."='".$cid."'")) { redirect(BASEDIR."index.php"); }
			if ($comment_name && $comment_message) {
				require_once INCLUDES."flood_include.php";
				if (!flood_control("comment_datestamp", DB_COMMENTS, "comment_ip='".USER_IP."'")) {
					$result = dbquery("INSERT INTO ".DB_COMMENTS." (comment_item_id, comment_type, comment_name, comment_message, comment_datestamp, comment_ip) VALUES ('$cid', '$ctype', '$comment_name', '$comment_message', '".time()."', '".USER_IP."')");
				}
			}
		}
	
	$c_start = (ceil(dbcount("(comment_id)", DB_COMMENTS, "comment_item_id='".$cid."' AND comment_type='".$ctype."'") / 10) - 1) * 10;
	}

	show_comments($ctype, $cdb, $ccol, $cid, $clink);
	
?>

