<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
defined('MAXIMUS') or Header("Location: index.php");

        incoh();
        $score = $db->XMFnum($score);
        if ($score) {
            if ($score > 5) { $score = 5; }
            if ($score < 1) { $score = 1; }
            if ($score != 1 AND $score != 2 AND $score != 3 AND $score != 4 AND $score != 5) {
                redirect_url(" index.php");
                die();
            }
            if (isset($ratecookie)) {
                $rcookie = base64_decode($ratecookie);
                $r_cookie = explode(":", $rcookie);
            }
            for ($i=0; $i < sizeof($r_cookie); $i++) { if ($r_cookie[$i] == $sid) { $a = 1; } }
            if ($a == 1) {
                redirect_url("modules.php?name=$module_name&op=rate_complete&sid=$sid&rated=1");
            } else {
                $sql = "update ".TABLE_STORIES." set score=score+$score, ratings=ratings+1 where sid='$sid'";
		if ( !($result = $db->sql_query($sql)) )
{ query_die(MODULE_ERROR, 'Could not update stories WebSite', '', __LINE__, __FILE__, $sql);}
                $info = base64_encode("$rcookie$sid:");
                setcookie("ratecookie","$info",time()+3600);
               // update_points(7);
                redirect_url("modules.php?name=$module_name&op=rate_complete&sid=$sid$r_options");
            }
        } else {
            incoh();
            title("$sitename: "._ARTICLERATING."");
            Max_OpenTable();
            echo "<center>"._DIDNTRATE."\n";
	    br('2');
            echo ""._GOBACK."</center>\n";
            Max_CloseTable();
            incof();
        }
        incof();