<?php

/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2002 by Francisco Burzi                                */
/* http://phpnuke.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.       */
/*                                                                      */
/************************************************************************/
/* Additional security checking code 2003 by chatserv                   */
/* http://www.nukefixes.com -- http://www.nukeresources.com             */
/************************************************************************/


global $prefix, $db, $admin_file;
if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
    Header("Location: ../../".$admin_file.".php");
    die();
}
$module_name = "ePetitions";
require_once("mainfile.php");
get_lang($module_name);
$aid = substr("$aid", 0,25);
$row = $db->sql_fetchrow($db->sql_query("SELECT `title`, `admins` FROM `".TABLE_MODULES."` WHERE `title`='$module_name'"));
$row2 = $db->sql_fetchrow($db->sql_query("SELECT `name`, `radminsuper` FROM `".TABLE_AUTHORS."` WHERE `aid`='$aid'"));
$admins = explode(",", $row['admins']);
$auth_user = 0;
for ($i=0; $i < sizeof($admins); $i++) { if ($row2['name'] == "$admins[$i]" AND $row['admins'] != "") { $auth_user = 1; } }
if ($row2['radminsuper'] == 1 || $auth_user == 1) {

function NSNePetitionsAdmin() {
	global $admin_file;
    Max_OpenTable();
    echo "<center>\n<table cellpadding=\"3\">\n<tr>\n";
    echo "<td align=\"center\" valign=\"top\" width=\"150\">";
    echo "<a href=\"".$admin_file.".php?op=NSNePetitionsAddOne\">"._NEP_ADD."</a><br />";
    echo "</td>\n";
    echo "<td align=\"center\" valign=\"top\" width=\"150\">";
    echo "</td>\n";
    echo "<td align=\"center\" valign=\"top\" width=\"150\">";
    echo "<a href=\"".$admin_file.".php?op=NSNePetitionsView\">"._NEP_VIEW."</a><br />";
    echo "</td>\n";
    echo "</tr>\n";
    echo "<tr>\n<td colspan=\"3\" align=\"center\"><a href=\"".$admin_file.".php\">"._NEP_MAINADMINMENU."</a></td>\n</tr>\n";
    echo "</table>\n</center>\n";
    Max_CloseTable();
}
function NSNePetitionsPost($gid, $subject, $hometext, $bodytext, $view, $validation, $hidesigner, $enable, $timestart, $timeend, $hideemail,$notestext,$modifynotes,$mailinglist) {
    global $aid, $prefix, $db, $Version_Num;

	$subject = stripslashes(FixQuotes($subject));
    $subject = ereg_replace("\"", "''", $subject);
    $hometext = stripslashes(FixQuotes($hometext));
    $bodytext = stripslashes(FixQuotes($bodytext));
    $notestext = stripslashes(FixQuotes($notestext));

	if($mailinglist==null || $mailinglist=="") $mailinglist=0;

	if($gid==0) $new_sql  = "insert into ".$prefix."_nsngrept_petitions (view,name,hometext,bodytext,validation,hidesigner,enabled,timestart,timeend,aid,createdtime,voters,hideemail,modifynotes,notestext,mailinglist) values ('$view', '$subject', '$hometext', '$bodytext', '$validation','$hidesigner','$enable','$timestart','$timeend','$aid',now(),0,'$hideemail','$modifynotes','$notestext','$mailinglist')";
	else $new_sql = "UPDATE ".$prefix."_nsngrept_petitions set view='$view', name='$subject', hometext='$hometext', bodytext='$bodytext', validation='$validation',hidesigner='$hidesigner',enabled='$enable',timestart='$timestart',timeend='$timeend',hideemail='$hideemail', modifynotes='$modifynotes', notestext='$notestext', mailinglist='$mailinglist' WHERE ePetitionId='$gid'";
    $result = $db->sql_query($new_sql);
}

function NSNePetitionGetCurrentDatetimeStr()
{
	$today = getdate();
    $tday = $today[mday];
    if ($tday < 10){
        $tday = "0$tday";
    }
    $tmonth = $today[mon];
	if($tmonth<10) {
		$tmonth="0$tmonth";
	}
    $tyear = $today[year];
    $thour = $today[hours];
    if ($thour < 10){
        $thour = "0$thour";
    }
    $tmin = $today[minutes];
    if ($tmin < 10){
        $tmin = "0$tmin";
    }
    $tsec = $today[seconds];
    if ($tsec < 10){
        $tsec = "0$tsec";
    }
    $date = "$tyear-$tmonth-$tday $thour:$tmin:$tsec";
	return $date;

}
function NSNePetitionsShowGroupAccess($text, $name, $view)
{
	global $bgcolor2, $db, $prefix;
	if ($view == 0) { $sel1 = "selected"; $sel2 = "";	$sel3 = "";	$sel4 = ""; } 
	elseif ($view == 1) { $sel1 = ""; $sel2 = "selected"; $sel3 = ""; $sel4 = ""; } 
	elseif ($view == 2) { $sel1 = ""; $sel2 = ""; $sel3 = "selected"; $sel4 = ""; } 
	elseif ($view == 3) { $sel1 = ""; $sel2 = ""; $sel3 = ""; $sel4 = "selected"; }

	echo "<tr><td align='right' bgcolor='$bgcolor2'>".$text."</td><td><select name=\"".$name."\">"
		."<option value=\"0\" $sel1>"._MVALL."</option>"
		."<option value=\"1\" $sel2>"._MVUSERS."</option>"
		."<option value=\"2\" $sel3>"._MVADMIN."</option>"
		."<option value=\"3\" $sel4>"._MVANON."</option>";

	if (file_exists("includes/cpg_page.php"))
		$groupsResult = $db->sql_query("select group_id , group_name from ".$prefix."_bbgroups ");
	else $groupsResult = $db->sql_query("select gid, gname from ".TABLE_NSNGR_GROUPS."");

	while(list($gid, $gname) = $db->sql_fetchrow($groupsResult)) {
		$gid = $gid + 3;
		if ($gid == $view) { $selected = " SELECTED"; } else { $selected = ""; }
		echo "<OPTION VALUE=\"$gid\"$selected>$gname";
	}
	echo "</select><br /></td></tr>";

}
function NSNePetitionsShowMailinglist($text, $name, $view)
{
	global $bgcolor2, $db, $prefix;
	if ($view == 0) { $sel1 = "selected"; $sel2 = "";	$sel3 = "";	$sel4 = ""; } 
	elseif ($view == 1) { $sel1 = ""; $sel2 = "selected"; $sel3 = ""; $sel4 = ""; } 
	elseif ($view == 2) { $sel1 = ""; $sel2 = ""; $sel3 = "selected"; $sel4 = ""; } 
	elseif ($view == 3) { $sel1 = ""; $sel2 = ""; $sel3 = ""; $sel4 = "selected"; }

	echo "<tr><td align='right' bgcolor='$bgcolor2'>".$text."</td><td><select name=\"".$name."\">"
		."<option value=\"0\" $sel1>"._MLANYONE."</option>";

	if(file_exists("includes/nsnml_func.php"))
	{
		$groupsResult = $db->sql_query("SELECT lid, title FROM ".$prefix."_nsnml_lists ORDER BY title");

		while(list($gid, $gname) = $db->sql_fetchrow($groupsResult)) {
			if ($gid == $view) { $selected = " SELECTED"; } else { $selected = ""; }
			echo "<OPTION VALUE=\"$gid\"$selected>$gname";
		}
	}
	echo "</select><br /></td></tr>";

}

function NSNePetitionsShowForm($nextop, $buttontext, $gid, $name, $hometext, $bodytext, $view, $enable, $hidesigner, $validation, $timestart, $timeend, $hideemail,$notestext,$modifynotes,$mailinglist)
{
    global $db, $bgcolor2, $prefix, $admin_file;

    if($timestart!="0000-00-00 00:00:00") $bAutomatedStart=1; 
	else 
	{
		$timestart=NSNePetitionGetCurrentDatetimeStr();
		$bAutomatedStart=0;
	}
	if($timeend!="0000-00-00 00:00:00") $bAutomatedEnd=1; 
	else 
	{
		$timeend=NSNePetitionGetCurrentDatetimeStr();
		$bAutomatedEnd=0;
	}

	ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $timestart, $datetimestart);
    ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $timeend, $datetimeend);
    $today = getdate();
    $tday = $today[mday];
    if ($tday < 10){
        $tday = "0$tday";
    }
    $tmonth = $today[month];
    $tyear = $today[year];
    $thour = $today[hours];
    if ($thour < 10){
        $thour = "0$thour";
    }
    $tmin = $today[minutes];
    if ($tmin < 10){
        $tmin = "0$tmin";
    }
    $tsec = $today[seconds];
    if ($tsec < 10){
        $tsec = "0$tsec";
    }
    $date = "$tmonth $tday, $tyear @ $thour:$tmin:$tsec";

	
	echo "<form method=post action=\"".$admin_file.".php?op=$nextop\">\n";
    echo "<input type=\"hidden\" name=\"gid\" value=\"".$gid."\">\n";
    echo "<table border='0' cellpadding='2' cellspacing='2'>\n";

		echo "<tr>\n<td align='right' bgcolor='$bgcolor2'><b>"._NEP_EPETITIONNAME.":</b></td>\n<td><input type=\"text\" name=\"subject\" size=\"80\" maxlength=\"255\" value=\"$name\"></tr>";
	     	
	echo "</table>\n";

	echo "<br /><br /><b>"._STORYTEXT."</b><br />"
		."<textarea wrap=\"virtual\" cols=\"50\" rows=\"12\" name=\"hometext\">$hometext</textarea><br /><br />"
	    ."<b>"._EXTENDEDTEXT."</b><br />"
		."<textarea wrap=\"virtual\" cols=\"50\" rows=\"12\" name=\"bodytext\">$bodytext</textarea><br />"
		."<font class=\"content\">"._ARESUREURL."</font><br /><br />"
        ."<b>"._NOTES."</b><br />"
        ."<textarea wrap=\"virtual\" cols=\"50\" rows=\"4\" name=\"notestext\">$notestext</textarea><br /><br />";

	echo "<table border='0' cellpadding='2' cellspacing='2'>";

		$sel0=""; $sel1=""; if($enable==0) $sel0=" selected"; else $sel1=" selected"; 
		echo "<tr><td align='right' bgcolor='$bgcolor2'>"._ACTIVATE2."</td><td><select name=\"enable\">"
			."<option value=\"0\" $sel0>"._NO."</option>"
			."<option value=\"1\" $sel1>"._YES."</option>"
			."</select><br /></td></tr>";
		$sel0=""; $sel1=""; if($validation==0) $sel0=" selected"; else $sel1=" selected"; 
		echo "<br /><tr><td align='right' bgcolor='$bgcolor2'>"._NEP_REQUESTEMAIL."</td>"
			."<td><select name=\"validation\">"
			."<option value=\"0\" $sel0>"._NO."</option>"
			."<option value=\"1\" $sel1>"._YES."</option>"
			."</select><br /></td></tr>";
		
		NSNePetitionsShowGroupAccess(_VIEWPRIV, "view", $view);
		NSNePetitionsShowGroupAccess(_NEP_HIDESIGNER, "hidesigner", $hidesigner);
		NSNePetitionsShowGroupAccess(_NEP_HIDEEMAIL, "hideemail", $hideemail);
		NSNePetitionsShowGroupAccess(_NEP_MODIFYNOTES, "modifynotes", $modifynotes);
		NSNePetitionsShowMailinglist(_NEP_MAILINGLIST, "mailinglist", $mailinglist);
	echo "</table>\n";

	echo "<table  border='1' cellpadding='0' cellspacing='0'>\n";
		echo "<br />"._NOWIS.": $date<br /><br />";
		echo "<tr  bgcolor='$bgcolor2'><td align='left'>";
			echo ""
				."<b>"._NEP_PROGRAMSTART."</b>&nbsp;&nbsp;"
				."<input type=radio name=automatedstart value=1 ";
			if($bAutomatedStart==1) echo "checked ";
			echo ">"._YES." &nbsp;&nbsp;"
				."<input type=radio name=automatedstart value=0 ";
			if($bAutomatedStart==0) echo "checked ";
			echo ">"._NO."<br /><br />"
				."";
		echo "</td><td align='right'>";
			echo ""
				."<b>"._NEP_PROGRAMEND."</b>&nbsp;&nbsp;"
				."<input type=radio name=automatedend value=1 ";
				if($bAutomatedEnd==1) echo "checked ";
				echo ">"._YES." &nbsp;&nbsp;"
				."<input type=radio name=automatedend value=0 ";
				if($bAutomatedEnd==0) echo "checked ";
				echo ">"._NO."<br /><br />"
				."";
		echo "</td></tr>";

		echo "<tr><td align='left'>";
			$xday = 1;
			echo ""._DAY.": <select name=\"daystart\">";
			while ($xday <= 31) {
				if ($xday == $datetimestart[3]) {
					$sel = "selected";
				} else {
					$sel = "";
				}
				echo "<option name=\"daystart\" $sel>$xday</option>";
				$xday++;
			}
			echo "</select>";
			$xmonth = 1;
			echo ""._UMONTH.": <select name=\"monthstart\">";
			while ($xmonth <= 12) {
				if ($xmonth == $datetimestart[2]) {
					$sel = "selected";
				} else {
					$sel = "";
				}
				echo "<option name=\"monthstart\" $sel>$xmonth</option>";
				$xmonth++;
			}
			echo "</select>";
			echo ""._YEAR.": <input type=\"text\" name=\"yearstart\" value=\"$datetimestart[1]\" size=\"5\" maxlength=\"4\">";
			echo "<br />"._HOUR.": <select name=\"hourstart\">";
			$xhour = 0;
			$cero = "0";
			while ($xhour <= 23) {
				$dummy = $xhour;
				if ($xhour < 10) {
					$xhour = "$cero$xhour";
				}
				if ($xhour == $datetimestart[4]) {
					$sel = "selected";
				} else {
					$sel = "";
				}
				echo "<option name=\"hourstart\" $sel>$xhour</option>";
				$xhour = $dummy;
				$xhour++;
			}
			echo "</select>";
			echo ": <select name=\"minstart\">";
			$xmin = 0;
			while ($xmin <= 59) {
				if (($xmin == 0) OR ($xmin == 5)) {
					$xmin = "0$xmin";
				}
				if ($xmin == (((int)($datetimestart[5]/5)*5))){
					$sel = "selected";
				} else {
					$sel = "";
				}
				echo "<option name=\"minstart\" $sel>$xmin</option>";
				$xmin = $xmin + 5;
			}
			echo "</select>";
			echo ": 00<br /><br />";
		echo "</td><td align='right'>";
			$xday = 1;
			echo ""._DAY.": <select name=\"dayend\">";
			while ($xday <= 31) {
				if ($xday == $datetimeend[3]) {
					$sel = "selected";
				} else {
					$sel = "";
				}
				echo "<option name=\"dayend\" $sel>$xday</option>";
				$xday++;
			}
			echo "</select>";
			$xmonth = 1;
			echo ""._UMONTH.": <select name=\"monthend\">";
			while ($xmonth <= 12) {
				if ($xmonth == $datetimeend[2]) {
					$sel = "selected";
				} else {
					$sel = "";
				}
				echo "<option name=\"monthend\" $sel>$xmonth</option>";
				$xmonth++;
			}
			echo "</select>";
			echo ""._YEAR.": <input type=\"text\" name=\"yearend\" value=\"$datetimeend[1]\" size=\"5\" maxlength=\"4\">";
			echo "<br />"._HOUR.": <select name=\"hourend\">";
			$xhour = 0;
			$cero = "0";
			while ($xhour <= 23) {
				$dummy = $xhour;
				if ($xhour < 10) {
					$xhour = "$cero$xhour";
				}
				if ($xhour == $datetimeend[4]) {
					$sel = "selected";
				} else {
					$sel = "";
				}
				echo "<option name=\"hourend\" $sel>$xhour</option>";
				$xhour = $dummy;
				$xhour++;
			}
			echo "</select>";
			echo ": <select name=\"minend\">";
			$xmin = 0;
			while ($xmin <= 59) {
				if (($xmin == 0) OR ($xmin == 5)) {
					$xmin = "0$xmin";
				}
				if ($xmin == ((round($datetimeend[5]/5)*5))){
					$sel = "selected";
				} else {
					$sel = "";
				}
				echo "<option name=\"minend\" $sel>$xmin</option>";
				$xmin = $xmin + 5;
			}
			echo "</select>";
			echo ": 00<br /><br />";
		echo "</td></tr>";
	echo "</table>\n";

    echo "<INPUT TYPE=SUBMIT VALUE=\"".$buttontext."\"></td>\n";
    echo "</form>\n";

}
/*
*/
if($admintest && $adminsecu)  {
switch($op) {

    case "NSNePetitionEditSigners":
		switch($Action)
		{
			case "Validate":
				$db->sql_query("UPDATE ".$prefix."_nsngrept_signers set validationString='' WHERE ePetitionSignerId='$sid'");
				$db->sql_query("UPDATE ".$prefix."_nsngrept_petitions set voters=voters+1 WHERE ePetitionId='$gid'");
				if($row = $db->sql_fetchrow($db->sql_query("SELECT mailinglist,eMailAddress FROM ".$prefix."_nsngrept_signers WHERE ePetitionSignerId='$sid'")))
				{
					$mailinglist=intval($row['mailinglist']);
					$email=$row['eMailAddress'];

					if(file_exists("includes/nsnml_func.php") && $mailinglist==1)
					{
						if($row = $db->sql_fetchrow($db->sql_query("SELECT mailinglist FROM ".$prefix."_nsngrept_petitions WHERE ePetitionId='$gid'")))
						{
							$mailinglistnumber=intval($row['mailinglist']);
							if($mailinglistnumber>0) NSNePetitionsSuscribeMailingList($email,$mailinglistnumber);
						}
					}
				}
				break;
			case "Delete":
				$db->sql_query("delete from ".$prefix."_nsngrept_signers WHERE ePetitionSignerId='$sid'");
				break;
			case "Resend":
		    	$petition_name="";
				if($query = $db->sql_query("SELECT name FROM ".$prefix."_nsngrept_petitions WHERE ePetitionId='$gid'"))
    			list($petition_name) = $db->sql_fetchrow($query);

				$query = $db->sql_query("select validationString,eMailAddress FROM ".$prefix."_nsngrept_signers WHERE ePetitionSignerId='$sid'");
				if($query)
				{
					while(list($check_num, $user_email) = $db->sql_fetchrow($query)) 
					{
						NSNePetitionsSendMail("ePetitions",$check_num,$user_email,$petition_name);
					}
				}

				break;
			default:
				break;
		}
		$pagetitle = _NEP_ADMIN.": "._NEP_MANAGESIGNERS;
		incoh();
		title("$pagetitle");
		NSNePetitionsAdmin();
        br('1');
        Max_OpenTable();
			echo "<center><table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" bgcolor=\"$bgcolor2\">\n";
				echo "<tr bgcolor=\"$bgcolor1\">\n";
					echo "<td align=\"center\" class=\"content\">"._NEP_UNCONFIRMED."</td>\n";
					echo "<td align=\"center\" class=\"content\"><a href=\"".$admin_file.".php?op=NSNePetitionValidateUnconfirmedSigners&amp;gid=$gid\"><img src=\"images/epetitions/yes.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\""._NEP_VALIDATEALL."\" title=\""._NEP_VALIDATEALL."\"></a></td>\n";
					echo "<td align=\"center\" class=\"content\"><a href=\"".$admin_file.".php?op=NSNePetitionDeleteUnconfirmedSigners&amp;gid=$gid\"><img src=\"images/epetitions/delete.png\" height=\"16\" width=\"16\" border=\"0\" alt=\""._NEP_DELETEALL."\" title=\""._NEP_DELETEALL."\"></a></td>\n";
					echo "<td align=\"center\" class=\"content\"><a href=\"".$admin_file.".php?op=NSNePetitionResendUnconfirmedSigners&amp;gid=$gid\"><img src=\"images/friend.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\""._NEP_RESENDTOALL."\" title=\""._NEP_RESENDTOALL."\"></a></td>\n";
				echo "</tr>";
			echo "</table></center>\n";
        Max_Max_CloseTable();
        br('1');
        Max_OpenTable();
			NSNePetitionsShowSigners($gid, "NSNePetitionEditSigners","AND validationString<>''",1);
        Max_CloseTable();
		incof();
	    break;
	case "NSNOneePetitionView":
		$pagetitle = _NEP_ADMIN.": "._NEP_VIEWSIGNERS;
		incoh();
		
		title("$pagetitle");
		NSNePetitionsAdmin();
        br('1');
        Max_OpenTable();

		NSNePetitionsView($gid,0);
		echo "<hr>";
		NSNePetitionsShowSigners($gid,"","AND validationString=''",1);

        Max_CloseTable();
		incof();
	    break;

	case "NSNePetitionsEditOne":
    case "NSNePetitionsAddOne":
	    if($op=="NSNePetitionsAddOne") {
			$pagetitle = _NEP_ADMIN.": "._NEP_ADD;
			$mailinglist=0; $modifynotes=0; $hideemail=0; $notestext=""; $gname="";$hometext="";$bodytext="";$view=0;$enable=1;$validation=0;$hidesigner=0; $nextop="NSNePetitionsPutOne"; $buttontext=_NEP_ADDEPETITION;
			$timestart=$timeend="0000-00-00 00:00:00";
		}
		else if($op=="NSNePetitionsEditOne")
		{
			$pagetitle = _NEP_ADMIN.": "._NEP_MODIFY;
			$nextop="NSNePetitionsEditOneConf";$buttontext=_NEP_MODIFYEPETITION;
	        list($gname,$hometext,$bodytext,$view,$enable,$hidesigner,$validation,$timestart,$timeend,$hideemail,$notestext,$modifynotes,$mailinglist) = $db->sql_fetchrow($db->sql_query("SELECT name,hometext,bodytext,view,enabled,hidesigner,validation,timestart,timeend,hideemail,notestext,modifynotes,mailinglist FROM ".$prefix."_nsngrept_petitions WHERE ePetitionId='$gid'"));
		}
		incoh();
		
        title("$pagetitle");
		NSNePetitionsAdmin();
        br('1');
        Max_OpenTable();
			NSNePetitionsShowForm($nextop, $buttontext, $gid, $gname, $hometext, $bodytext, $view, $enable, $hidesigner, $validation, $timestart, $timeend,$hideemail,$notestext,$modifynotes,$mailinglist);
        Max_CloseTable();
        incof();
	    break;
    case "NSNePetitionDelete":
	case "NSNePetitionsEmptyOne":
        if($op=="NSNePetitionDelete")$pagetitle = _NEP_ADMIN.": "._NEP_EPETITIONDELETE;
		else $pagetitle = _NEP_ADMIN.": "._NEP_EPETITIONEMPTY;
        incoh();
        title("$pagetitle");
		NSNePetitionsAdmin();
        br('1');
        Max_OpenTable();
			list($gname) = $db->sql_fetchrow($db->sql_query("SELECT name FROM ".$prefix."_nsngrept_petitions WHERE ePetitionId='$gid'"));
			echo "<center><table><tr>\n";
			echo "<form action=\"".$admin_file.".php\" method=\"post\">\n";
			echo "<input type=\"hidden\" name=\"op\" value=\"".$op."Conf\">\n";
			echo "<input type=\"hidden\" name=\"gid\" value=\"$gid\">\n";
			echo "<td align=\"center\">";
			if($op=="NSNePetitionDelete") echo _NEP_DELEPETITION; else echo _NEP_DELETESIGNERS;
			echo " #$gid ($gname)?</td>\n";
			echo "</tr><tr><td align=\"center\"><input type=\"submit\" value=\"";
			if($op=="NSNePetitionDelete") echo _NEP_DELETE;	else echo _NEP_EMPTY;
			echo "&quot;$gname&quot;\"></td></form>\n";
			echo "</tr></table></center>\n";
			echo "<center>"._GOBACK."</center>\n";
        Max_CloseTable();
        incof();
    break;
	case "NSNePetitionsPutOne":
	case "NSNePetitionsEditOneConf":
	    $sec = "00";
	    if ($daystart < 10) $daystart = "0$daystart";
		if ($monthstart < 10) $monthstart = "0$monthstart";
	    if ($dayend < 10) $dayend = "0$dayend";
		if ($monthend < 10) $monthend = "0$monthend";
    
	    $timestart = "$yearstart-$monthstart-$daystart $hourstart:$minstart:$sec";
	    $timeend = "$yearend-$monthend-$dayend $hourend:$minend:$sec";

		if($automatedstart==0) $timestart="0000-00-00 00:00:00";
		if($automatedend==0) $timeend="0000-00-00 00:00:00";

		NSNePetitionsPost($gid,$subject,$hometext,$bodytext,$view,$validation, $hidesigner, $enable, $timestart, $timeend,$hideemail,$notestext,$modifynotes,$mailinglist);
		break;

	case "NSNePetitionsEmptyOneConf":
    case "NSNePetitionDeleteConf":
		$db->sql_query("delete from ".$prefix."_nsngrept_signers WHERE ePetitionId = '$gid'");
		if($op=="NSNePetitionDeleteConf")$db->sql_query("delete from ".$prefix."_nsngrept_petitions WHERE ePetitionId = '$gid'");
		else $db->sql_query("UPDATE ".$prefix."_nsngrept_petitions set voters=0 WHERE ePetitionId='$gid'"); 
		break;

	case "NSNePetitionsEnableOne":
		// if asking to enable or disable a ePetition in display mode
		if($enable!="") {
			if(!is_numeric($enable) || ($enable!=0 && $enable!=1)) $enable=0;
			$db->sql_query("UPDATE  ".$prefix."_nsngrept_petitions SET enabled='".$enable."' WHERE ePetitionId='".$gid."'");
		}
		break;
    case "NSNePetitionDeleteUnconfirmedSigners":
		$db->sql_query("delete from ".$prefix."_nsngrept_signers WHERE validationString<>''");
		break;
	case "NSNePetitionValidateUnconfirmedSigners":
		$mailinglistnumber=0;
		if($result = $db->sql_fetchrow($db->sql_query("SELECT mailinglist FROM ".$prefix."_nsngrept_petitions WHERE ePetitionId='$gid'")))
			$mailinglistnumber=intval($result['mailinglist']);

    	$result = $db->sql_query("SELECT mailinglist,eMailAddress FROM ".$prefix."_nsngrept_signers WHERE (ePetitionId='$gid' AND validationString<>'')");
		$nbValidatedUsers = $db->sql_numrows($result);

		if($nbValidatedUsers!=0)
		{
			$db->sql_query("UPDATE ".$prefix."_nsngrept_signers set validationString='' WHERE (ePetitionId='$gid' AND validationString<>'')");
			$db->sql_query("UPDATE ".$prefix."_nsngrept_petitions set voters=voters+$nbValidatedUsers WHERE ePetitionId='$gid'");

			if(file_exists("includes/nsnml_func.php") && $mailinglistnumber>0) // NSN Mailing list installed & petition automatic suscribtion to mailing list set
			{
				while(list($mailinglist, $email) = $db->sql_fetchrow($result)) 
				{
					$mailinglist=intval($mailinglist);
					if($mailinglist==1) NSNePetitionsSuscribeMailingList($email,$mailinglistnumber);
				}
			}
		}
		break;

    case "NSNePetitionResendUnconfirmedSigners":
    	$petition_name="";
		if($query = $db->sql_query("SELECT name FROM ".$prefix."_nsngrept_petitions WHERE ePetitionId='$gid'"))
    		list($petition_name) = $db->sql_fetchrow($query);

		$query = $db->sql_query("select validationString,eMailAddress FROM ".$prefix."_nsngrept_signers WHERE (ePetitionId='$gid' AND validationString<>'')");
		if($query)
		{
			while(list($check_num, $user_email) = $db->sql_fetchrow($query)) {
				NSNePetitionsSendMail("ePetitions",$check_num,$user_email,$petition_name);
			}
		}
		break;

    case "NSNePetitionsView":
	    $pagetitle = _NEP_ADMIN.": "._NEP_EPETITIONSVIEW;

		incoh();
	
        title("$pagetitle");
		NSNePetitionsAdmin();
        br('1');
        Max_OpenTable();
        echo "<center><table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" bgcolor=\"$bgcolor2\">\n";
        echo "<tr>\n";
        echo "<td align=\"center\" class=\"option\" width=\"200\">"._NEP_EPETITIONNAME."</td>\n";
        echo "<td align=\"center\" class=\"option\" width=\"100\">"._NEP_EPETITIONSIGNED."</td>\n";
        echo "<td align=\"center\" class=\"option\" width=\"100\">"._NEP_EPETITIONUNVALIDATEDSIGNED."</td>\n";
        echo "<td align=\"center\" class=\"option\" width=\"100\">"._STATUS."</td>\n";
	    echo "<td align=\"center\" class=\"option\" width=\"100\">"._VIEW."</td>";
        echo "<td align=\"center\" class=\"option\" width=\"100\">"._NEP_FUNCTIONS."</td>\n";
        echo "</tr>\n";
        $result = $db->sql_query("SELECT ePetitionId, name, enabled, view FROM ".$prefix."_nsngrept_petitions ORDER BY enabled DESC,name");
        while(list($gid, $gname,$enabled,$view) = $db->sql_fetchrow($result)) {
            echo "<tr bgcolor=\"$bgcolor1\">\n";
            echo "<td align=\"center\" class=\"content\">$gname ($gid)</td>\n";
            $numusers = $db->sql_numrows($db->sql_query("SELECT ePetitionSignerId FROM ".$prefix."_nsngrept_signers WHERE ePetitionId ='$gid'"));
			echo "<td align=\"center\" class=\"content\">$numusers</td>\n";
            $numusers = $db->sql_numrows($db->sql_query("SELECT ePetitionSignerId FROM ".$prefix."_nsngrept_signers WHERE ePetitionId ='$gid' AND validationString!=''"));
			echo "<td align=\"center\" class=\"content\">$numusers</td>\n";
            echo "<td align=\"center\" class=\"content\">\n";
			if($enabled==1) echo "<a href=\"".$admin_file.".php?op=NSNePetitionsEnableOne&amp;gid=$gid&amp;enable=0\"><img src=\"images/epetitions/green_dot.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\""._DEACTIVATE."\" title=\""._DEACTIVATE."\"></a>\n";
			else echo "<a href=\"".$admin_file.".php?op=NSNePetitionsEnableOne&amp;gid=$gid&amp;enable=1\"><img src=\"images/epetitions/red_dot.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\""._ACTIVATE."\" title=\""._ACTIVATE."\"></a>\n";
            echo "</td>\n";
			if ($view == 0) {
				$who_view = _MVALL;
			} elseif ($view == 1) {
				$who_view = _MVUSERS;
			} elseif ($view == 2) {
				$who_view = _MVADMIN;
			} elseif ($view == 3) {
				$who_view = _MVANON;
				// Begin NSN Mod
			} elseif ($view >3) {
				$newView = $view - 3;
				list($who_view) = $db->sql_fetchrow($db->sql_query("select gname from ".TABLE_NSNGR_GROUPS." where gid=$newView"));
				// End NSN Mod
			}
			echo "<td align=\"center\" class=\"content\">$who_view</td>";

            echo "<td align=\"center\" class=\"content\">\n";
            echo "<a href=\"".$admin_file.".php?op=NSNOneePetitionView&amp;gid=$gid\"><img src=\"images/epetitions/view.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\""._NEP_VIEWSIGNERS."\" title=\""._NEP_VIEWSIGNERS."\"></a>\n";
            echo "<a href=\"".$admin_file.".php?op=NSNePetitionEditSigners&amp;gid=$gid\"><img src=\"images/epetitions/pencil.png\" height=\"16\" width=\"16\" border=\"0\" alt=\""._NEP_MANAGESIGNERS."\" title=\""._NEP_MANAGESIGNERS."\"></a>\n";
            echo "<a href=\"".$admin_file.".php?op=NSNePetitionsEditOne&amp;gid=$gid\"><img src=\"images/epetitions/edit.png\" height=\"16\" width=\"16\" border=\"0\" alt=\""._NEP_EDIT."\" title=\""._NEP_EDIT."\"></a>\n";
            echo "<a href=\"".$admin_file.".php?op=NSNePetitionDelete&amp;gid=$gid\"><img src=\"images/epetitions/delete.png\" height=\"16\" width=\"16\" border=\"0\" alt=\""._NEP_DELETE."\" title=\""._NEP_DELETE."\"></a>\n";
            echo "<a href=\"".$admin_file.".php?op=NSNePetitionsEmptyOne&amp;gid=$gid\"><img src=\"images/epetitions/empty.png\" height=\"16\" width=\"16\" border=\"0\" alt=\""._NEP_EMPTY."\" title=\""._NEP_EMPTY."\"></a>\n";
            echo "</td>\n";
            echo "</tr>\n";
        }
        echo "</table></center>\n";
        Max_CloseTable();
        incof();
	    break;
}}

} else {
    echo "Access Denied";
}