<?php

/***************************************************************************

 m_pollform.php
 ---------------
 copyright : (C) 2002-2003 The ezContents Development Team

 ***************************************************************************/

/***************************************************************************
 The ezContents Development Team offers no warranties on this script.
 The owner/licensee of the script is solely responsible for any problems
 caused by installation of the script or use of the script.

 All copyright notices regarding ezContents must remain intact on the
 scripts and in the HTML for the scripts.

 For more info on ezContents,
 visit http://www.ezcontents.org/

/***************************************************************************

/***************************************************************************
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the License which can be found within the
 *	zipped package.
 *
 ***************************************************************************/


$GLOBALS["ModuleName"] = 'poll';
include("moduleref.php");

$GLOBALS["rootdp"] = '../../';
require_once ($GLOBALS["rootdp"]."include/config.php");
require_once ($GLOBALS["rootdp"]."include/db.php");
require_once ($GLOBALS["rootdp"]."include/session.php");

include ($GLOBALS["rootdp"]."include/access.php");

include ($GLOBALS["rootdp"]."include/settings.php");
include ($GLOBALS["rootdp"]."include/functions.php");
include ($GLOBALS["rootdp"].$GLOBALS["admin_home"]."adminfunctions.php");
include ($GLOBALS["rootdp"].$GLOBALS["modules_home"]."modfunctions.php");
include ($GLOBALS["rootdp"].$GLOBALS["language_home"].$GLOBALS["gsLanguage"]."/lang_admin.php");
include ($GLOBALS["rootdp"].$GLOBALS["language_home"].$GLOBALS["gsLanguage"]."/lang_main.php");
include_languagefile ($GLOBALS["modules_home"].$GLOBALS["ModuleRef"].'/',$GLOBALS["gsLanguage"],'lang_poll.php');


// Security vet.
// Start by setting all security access to false.
// Do it in the code to overwrite any spurious values that a hacker may
//	have tried to pass in the url
$GLOBALS["specialedit"] = $GLOBALS["canedit"] = $GLOBALS["canadd"] = $GLOBALS["canview"] = False;
$GLOBALS["fieldstatus"] = '';

// Validate the user's level of access for this form.
$GLOBALS["form"] = 'subcontent';
$GLOBALS["validaccess"] = VerifyAdminLogin();
$GLOBALS["specialedit"] = True;


GetModuleData($GLOBALS["ModuleRef"]);

// If we've been passed the request from the poll options list, then we
//	read the option data from the database for an edit request, or skip
//	if this is an 'add new' request
if ($HTTP_GET_VARS["PollID"] != "") {
	$HTTP_POST_VARS["PollID"] = $HTTP_GET_VARS["PollID"];
}
if ($HTTP_GET_VARS["PollOptionID"] != "") {
	$HTTP_POST_VARS["PollOptionID"] = $HTTP_GET_VARS["PollOptionID"];
	GetGlobalData();
} else {
	GetFormData;
}

if ($HTTP_POST_VARS["submitted"] == "yes") {
	AddPollOption();
	Header("Location: ".BuildLink('m_'.$GLOBALS["ModuleName"].'options.php').'&PollID='.$HTTP_POST_VARS["PollID"]);
}

frmPollOptionForm();


function frmPollOptionForm()
{
	global $HTTP_POST_VARS;

	adminformheader();
	adminformopen('option');
	adminformtitle(2,$GLOBALS["tFormTitle"]);

	?>
	<tr class="tablecontent">
		<?php FieldHeading("Option","option"); ?>
		<td valign="top" class="content">
			<?php EditButtons("Option","option"); ?>
			<textarea rows="2" name="option" cols="66"<?php echo $GLOBALS["fieldstatus"]; ?>><?php echo htmlspecialchars($GLOBALS["gsOption"]); ?></textarea>
		</td>
	</tr>
   </tr>
	<?php
	adminformsavebar(2,'m_polloptions.php');
	if ($GLOBALS["specialedit"] == True)
	{
//		adminhelpmsg(2);
		?><input type="hidden" name="PollOptionID" value="<?php echo $HTTP_POST_VARS["PollOptionID"]; ?>"><?php
		?><input type="hidden" name="PollID" value="<?php echo $HTTP_POST_VARS["PollID"]; ?>"><?php
	}
	adminformclose();
} // function frmPollForm()


function AddPollOption()
{
	global $HTTP_POST_VARS;

	$sOption = dbString($HTTP_POST_VARS["option"]);

	if ($HTTP_POST_VARS["PollOptionID"] != "") {
		$strQuery = "UPDATE ".$GLOBALS["scTable"]."options SET polloption='".$sOption."' WHERE polloptionid='".$HTTP_POST_VARS["PollOptionID"]."'";
	} else {
		$strQuery = "INSERT INTO ".$GLOBALS["scTable"]."options VALUES('', '".$HTTP_POST_VARS["PollID"]."', '".$sOption."', 0)";
	}
	$result = dbExecute($strQuery,true);
	dbCommit();
}


function GetGlobalData()
{
	global $HTTP_GET_VARS;

	$strQuery="SELECT * FROM ".$GLOBALS["scTable"]."options WHERE polloptionid='".$HTTP_GET_VARS["PollOptionID"]."'";
	$result = dbRetrieve($strQuery,true,0,0);
	$rs	= dbFetch($result);

	$GLOBALS["gsOption"]		= $rs["polloption"];
} // function GetGlobalData()


function GetFormData()
{
	global $HTTP_POST_VARS;

	$GLOBALS["gsOption"]	= $HTTP_POST_VARS["option"];
} // function GetFormData()

?>
