<?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 die ('Access denied block epetition MAXIMUS directly...');

global $prefix, $cookie, $user, $admin, $language, $blockfiletitle, $side;
if (is_file('includes/ePetitions.php')) {
include_once('includes/ePetitions.php');}

$block_name = "ePetitions";
get_blang("$block_name");

$cmdline=$blockfiletitle;
$content=_NEP_NOPETITION;

$sql = "SELECT `ePetitionId`, `name`, `view`, `voters` FROM `".$prefix."_nsngrept_petitions` WHERE (`enabled`='1' AND `timestart`<=now() AND (`timeend`='0000-00-00 00:00:00' || `timeend`>=now())) ORDER BY `ePetitionId` DESC, `timestart` DESC";
if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(CORE_ERROR, 'Could not obtain _nsngrept_petitions', '', __LINE__, __FILE__, $sql);}
while($row = $GLOBALS['db']->sql_fetchrow($result))
{
	$ePetitionId  = $GLOBALS['db']->XMFnum($row['ePetitionId']);
	$petitionName = stripslashes($row['name']);
	$view         = $GLOBALS['db']->XMFnum($row['view']);
	$voters       = $GLOBALS['db']->XMFnum($row['voters']);
	if(is_visible_for_user($view,$user,$admin)==1)
	{
		$content=NSNePetitionsSign($ePetitionId,$petitionName, $voters, $side,1, 0);
		break;
	}
}

$blockfiletitle=_NEP_SIGNPETITION;
$GLOBALS['db']->sql_freeresult($result);