<?php
include("include/config.php");
include("include/db.class.php");
include("include/functions.php");
include_once("adminmotormarket/include/jdf.php");
$db=new DB($globalConfig['dbase'], $globalConfig['dbhost'],$globalConfig['dbuser'], $globalConfig['dbpass']);
 session_start();

 function checkAccess($file_name, $group_id){
        $db = con();
        $sql = $db->query("SELECT * FROM u_admin_file_to_groups WHERE groupID ='" . $group_id .
            "' AND  fileName  ='" . $file_name . "'");
        $num = mysql_num_rows($sql);
        if ($num > 0) {
            return 'checked="checked"';
        }
        return '';
    }
    function checkAccess2($file_name, $group_id){
        $db = con();
        $sql = $db->query("SELECT * FROM  u_file_to_groups WHERE groupID ='" . $group_id .
            "' AND  fileName  ='" . $file_name . "'");
        $num = mysql_num_rows($sql);
        if ($num > 0) {
            return 'checked="checked"';
        }
        return '';
    }

 if(isset($_GET['act'])) $action = $_GET['act'];
  switch($action){

//--------------------------------------------------------

case 'commentlike':
	
$queryln=$db->query("select * from comments where id = ".$_POST['id']." ");
$resln=$db->fetchNextArray($queryln);


	if($_POST['act']=='like'){
		$ip = $_SERVER['REMOTE_ADDR'];
		$queryc=$db->query("select * from comment_like where comment = ".$_POST['id']." && ip = '".$ip."' ");
		$count = mysql_num_rows($queryc);
			if($count<=0){
				$newlike = $resln['likes']+1;
				$db->execute("insert into comment_like set
											ip= '".$ip."',
											comment ='".$_POST['id']."'");
				 $db->execute("update comments set
						 likes = ".$newlike."
						 where id=".$_POST['id']."");

				}
	
		}elseif($_POST['act']=='unlike'){
		$ip = $_SERVER['REMOTE_ADDR'];
		$queryc=$db->query("select * from comment_like where comment = ".$_POST['id']." && ip = '".$ip."' ");
		$count = mysql_num_rows($queryc);
			if($count<=0){
				$newlike = $resln['unlikes']+1;
				$db->execute("insert into comment_like set
											ip= '".$ip."',
											comment ='".$_POST['id']."'");
				 $db->execute("update comments set
						 unlikes = ".$newlike."
						 where id=".$_POST['id']."");
				}
			}
$queryc=$db->query("select * from comments where id = ".$_POST['id']." ");
$resc=$db->fetchNextArray($queryc);	
?>
<div class="answer" id="answer<?php echo $resc['id']?>">
                	<div class="like"><img src="images/icon/like.png"  /><span><?php echo $resc['likes']?></span></div>
                    <div class="unlike"><img src="images/icon/dislike.png" /><span><?php echo $resc['unlikes']?></span></div>
                    <div class="unlike"><a href="javascript:void(0)" onclick="replayshow(<?php echo $resc['id']?>);">پاسخ</a></div>
              </div>
<?php	
break;
case 'contactform':
if(isset($_POST)){
$db->execute("insert contact set
		name='".$db->safe_string($_POST['name'])."',
		mail = '".$db->safe_string($_POST['email'])."',
		description = '".$db->safe_string($_POST['message'])."',
		phone = '".$db->safe_string($_POST['phone'])."',
		date = NOW()
		 ");

?>
  <div class="theme-success success">پیامتان را دریافت کردیم. با شما تماس میگیریم. از اینکه وقت گذاشتید تشکر میکنیم</div>

<?php }
break;
} 

?>
 