<?php
require './../inc/init.php';

$sites = $core->load_system('sites');
$this_module = $sites->load_module('item');
/**
* 内容查看次数
**/

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$id or exit('');

$data = $DB_slave->fetch_one("SELECT views, comments, model FROM $this_module->main_table WHERE id = '$id'");
$data or exit('');


if(
	$DB_master->update(
		$this_module->main_table,
		array('views' => 'views +1'),
		"id = '$id'",
		false
	)
){
	
	$this_module->set_model($data['model']);
	
	$DB_master->update(
		$this_module->table,
		array('views' => 'views +1'),
		"id = '$id'",
		false
	);
}
if(REQUEST_METHOD == 'GET'){
	exit('
	$(function(){
		$(\'.item_views\').html('. $data['views'] .');
		$(\'.item_comments\').html('. $data['comments'] .');
	});
	');
}else{
	echo p8_json(array(
		'views' => $data['views'],
		'comments' => $data['comments']
	));
	exit();
}
