<?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");

$module_name = "Reviews";
get_lang($module_name);

function alpha() {
	global $module_name;
	$alphabet = array ("A","B","C","D","E","F","G","H","I","J","K","L","M",
	"N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0");
	$num = count($alphabet) - 1;
	echo "<center>[ ";
	$counter = 0;
	while (list(, $ltr) = each($alphabet)) {
		echo "<a href=\"modules.php?name=$module_name&amp;rop=$ltr\">$ltr</a>";
		if ( $counter == round($num/2) ) {
			echo " ]\n<br />\n[ ";
		} elseif ( $counter != $num ) {
			echo "&nbsp;|&nbsp;\n";
		}
		$counter++;
	}
	echo " ]</center><br /><br />\n\n\n";
	echo "<center>[ <a href=\"modules.php?name=$module_name&amp;rop=write_review\">"._WRITEREVIEW."</a> ]</center>\n\n";
	br('1');
}

function display_score($score) {
	$image = "<img src='images/blue.gif' alt='' />";
	$halfimage = "<img src='images/bluehalf.gif' alt='' />";
	$full = "<img src='images/star.gif' alt='' />";

	if ($score == 10) {
		for ($i=0; $i < 5; $i++)
		echo "$full";
	} else if ($score % 2) {
		$score -= 1;
		$score /= 2;
		for ($i=0; $i < $score; $i++)
		echo "$image";
		echo "$halfimage";
	} else {
		$score /= 2;
		for ($i=0; $i < $score; $i++)
		echo "$image";
	}
}


function r_comments($id, $title) {
	global $module_name, $anonymous;
	$id = $GLOBALS['db']->XMFnum($id);
	$result = $GLOBALS['db']->sql_query("SELECT `cid`, `userid`, `date`, `comments`, `score` FROM `".TABLE_REVIEWS_COMMENTS."` WHERE `rid`='$id' ORDER BY `date` DESC");
	while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
		$cid      = $GLOBALS['db']->XMFnum($row['cid']);
		$uname    = stripslashes($row['userid']);
		$date     = stripslashes($row['date']);
		$comments = stripslashes($row['comments']);
		$score    = $GLOBALS['db']->XMFnum($row['score']);
		Max_OpenTable();
		$title = htmlspecialchars(urldecode(check_html($title, "nohtml")));
		echo "<b>$title</b><br />";
		if ($uname == $anonymous) {
			echo ""._POSTEDBY." $uname "._ON." $date<br />";
		} else {
			echo ""._POSTEDBY." <a href=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$uname\">$uname</a> "._ON." $date<br />";
		}
		echo ""._MYSCORE." ";
		display_score($score);
		if (defined('ADMIN_ALLOW')) {
			echo "<br /><b>"._ADMIN."</b> [ <a href=\"modules.php?name=$module_name&amp;rop=del_comment&amp;cid=$cid&amp;id=$id\">"._DELETE."</a> ]</font><hr noshade size='1' /><br /><br />";
		} else {
			echo "</font><hr noshade size='1' /><br /><br />";
		}
		$comments = FixQuotes(filter_text($comments));
		echo "$comments";
		Max_CloseTable();
		br('1');
	}
$GLOBALS['db']->sql_freeresult($result);
}

function del_review($id_del) {
	global $module_name;
	$id_del = $GLOBALS['db']->XMFnum($id_del);
	if (defined('ADMIN_ALLOW')) {
		$GLOBALS['db']->sql_query("DELETE FROM `".TABLE_REVIEWS."` WHERE `id`='$id_del'");
		$GLOBALS['db']->sql_query("DELETE FROM `".TABLE_REVIEWS_COMMENTS."` WHERE `rid`='$id_del'");
		redirect_url("modules.php?name=$module_name");
	} else {
		echo "ACCESS DENIED";
	}
}

function del_comment($cid, $id) {
	global $module_name;
	$cid = $GLOBALS['db']->XMFnum($cid);
	if (defined('ADMIN_ALLOW')) {
		$GLOBALS['db']->sql_query("DELETE FROM `".TABLE_REVIEWS_COMMENTS."` WHERE `cid`='$cid'");
		redirect_url("modules.php?name=$module_name&rop=showcontent&id=$id");
	} else {
		echo 'ACCESS DENIED';
	}
}

if (strlen($rop) == 1 AND ctype_alnum($rop)) {
include_once('modules/Reviews/includes/reviews.php');
} else { 
switch($rop) {

	case 'showcontent':include_once('modules/Reviews/includes/showcontent.php');break;
	case 'write_review':include_once('modules/Reviews/includes/write_review.php');break;
	case 'preview_review':include_once('modules/Reviews/includes/preview_review.php');break;
	case ""._YES."":include_once('modules/Reviews/includes/send_review.php');break;
	case 'del_review':del_review($id_del);break;
	case 'mod_review':include_once('modules/Reviews/includes/mod_review.php');break;
	case 'postcomment':include_once('modules/Reviews/includes/postcomment.php');break;
	case 'savecomment':include_once('modules/Reviews/includes/savecomment.php');break;
	case 'del_comment':del_comment($cid, $id);break;
	default:include_once('modules/Reviews/includes/reviews_index.php');break;
}
}