<?php
require_once('../includes/inc_general.php');
header('Content-Type:text/html;charset=' . SYS_CHARSET);
$uid = 0;

function getWebSnapshot($url) {
    $rtn = '';
    $isUrlOpen = @ini_get("allow_url_fopen");
    if ($isUrlOpen) {
        $data = null;
        $data = @file_get_contents($url);
        if ($data) {
            $rtn = $data;
        } 
    } 

    return $rtn;
} 

function addRecords() {
    global $db, $lang;

    global $uid, $tag, $article_id, $ratevalue, $is_show, $is_getsnapshot ;

    $rtn = false;

    $flag = 0;
    $relation_type = 0;
    $relation_info = $article_id;
    $addtime = time();
    $edittime = 0;
    $ip = getIP();
    if (!isset($ratevalue)) $ratevalue = 0;

    $content = '';
    if ($is_getsnapshot == 1) $content = addslashes(getWebSnapshot(SYS_WEBURL . DIR_INSTALL . "article.php?id=$article_id"));
    $status = 1;
    if ($is_show == 0) $status = 0;
    if ($ratevalue == '') $ratevalue = 0;

    $sql = "insert into " . TB_USER_REPOSITORY . " (tag, relation_type, relation_info, ratevalue, content, uid, addtime, edittime, ip, status, flag) values('$tag', '$relation_type', '$relation_info', '$ratevalue', '$content', '$uid', '$addtime', '$edittime', '$ip', '$status', '$flag')";
    $rs = $db -> Execute($sql);
    if ($rs) {
        $rtn = true;
    } else {
    } 
    $rs -> Close();
    return $rtn;
} 

function showResult($result = '') {
    $str = '';
    $str .= $result; 
    // $str .= "showResult('$result');";
    echo $str;
} 
// start---
if (getCookie(COOKIE_UID) != '') {
    $uid = getCookie(COOKIE_UID);
} 

if ($uid == 0) {
    showResult($lang['isLogin']);
} else {
    if (dbGetRecordCount(TB_USER_REPOSITORY, "uid='$uid' and relation_type='0' and relation_info='$article_id'") > 0) {
        showResult($lang['fovarite_exist']);
    } else {
        if (addRecords()) showResult($lang['successful']);
        else showResult($lang['failed']);
    } 
} 

?>