<?php
require_once ("../config.inc.php");
require_once ("../includes/adminlogincheck.inc.php");
require_once ("../includes/mysql.inc.php");
require_once ("../includes/arrays.inc.php");
require_once ("../classes/miscellaneous.class.php");
require_once "../includes/fckeditor/fckeditor.php";

$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
$id			= isset($_REQUEST['id'])	?	trim($_REQUEST['id'])	:	"0";
$message	= "";
if (!$objDB) {
    $message	= "Unable to Locate Database Server.";
} else { 

    $_POST['dDate_Event'] = date("Y-m-d H:i:s", strtotime($_POST['dDate_Event'])); 
    $objMisc		= new miscellaneous($objDB);
    $objMisc->set_single_events($_POST);
    if (isset($_POST['SaveNow'])) {
        $message	= $objMisc->save_single_event($id);
        if ($message == "") {
            header("Location: singleevents.php?page=$page&act=1");
            exit;
        }
    } elseif (isset($_POST['BackNow'])) {
        if ($message == "") {
            header("Location: singleevents.php?page=$page");
            exit;
        }
    } else {
        $array	= $objMisc->get_single_event($id);  //echo '<pre>'; print_r($array); echo '</pre>';
        $objMisc->set_single_events($array);
    }
}

include_once('title.inc.php');
?>
<script type="text/javascript" src="../scripts/calendar.js"></script>
<script type="text/javascript" src="../scripts/calendar-setup.js"></script>
<script type="text/javascript" src="../scripts/calendar-en.js"></script>
<link href="../scripts/calendar.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript">
    function validate()
    {
        var frm	= document.frmUser;

        if (frm.vTitle.value == "") {
            alert("Please enter title of the event.");
            frm.vTitle.focus();
            return false;
        }
        if (frm.vCity.value == "") {
            alert("Please enter city of the event.");
            frm.vCity.focus();
            return false;
        }
        if (frm.vVenue.value == "") {
            alert("Please enter venue of the event.");
            frm.vVenue.focus();
            return false;
        }
        if (frm.dDate_Event.value == "") {
            alert("Please enter date of the event.");
            frm.dDate_Event.focus();
            return false;
        }
        /*if (frm.vDescription.value.length == 0) {
                alert("Please enter description of the event.");
                frm.vDescription.focus();
                return false;
        }*/
        return true;
    }
</script>
<?php include_once('tophtml.php');?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td valign="top" class="white"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="72%" valign="top">
                        <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                                        <tr>
                                            <td width="41%" class="headings1" colspan="2">Manage Event</td>
                                        </tr>
                                    </table>
                                    <div class="bordernew padding2">
                                        <form name="frmUser" method="post" action="" >
                                            <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                                                <tr>
                                                    <td><table class="tblestyle_admin2" width="100%"  border="0" cellspacing="0" cellpadding="0">
                                                            <?php if ($objDB) {
                                                                ?>
                                                                <?php 	if(isset($message) && $message!='') {
                                                                    ?>
                                                            <tr align="left">
                                                                <td align="center" class="maintext2">&nbsp;</td>
                                                                <td colspan="2" class="maintext2 warning"><?php echo $message;?></td>
                                                            </tr>
                                                                    <?php  	}//end if?>
                                                            <tr align="left">
                                                                <td width="3%" class="maintext2">&nbsp;</td>
                                                                <td width="27%" class="maintext2">Event Type</td>
                                                                <td width="70%" class="maintext2"><select name="vType" class="textbox select-big">
                                                                        <option value="SE" <?php echo $objMisc->vType=="SE"?"selected":""?>>Single Event</option>
                                                                        <option value="MC" <?php echo $objMisc->vType=="MC"?"selected":""?>>Monthly Contest</option>
                                                                    </select></td>
                                                            </tr>
                                                            <tr align="left">
                                                                <td class="maintext2">&nbsp;</td>
                                                                <td class="maintext2">Event Title<span><font color="red"> * </font> </span>
                                                                </td>
                                                                <td class="maintext2"><input name="vTitle" type="text" value="<?php echo htmlspecialchars($objMisc->vTitle)?>" size="35" maxlength="200" class="textbox"></td>
                                                            </tr>
                                                            <tr align="left">
                                                                <td class="maintext2">&nbsp;</td>
                                                                <td class="maintext2">Event City<span><font color="red"> * </font> </span></td>
                                                                <td class="maintext2"><input name="vCity" type="text" value="<?php echo htmlspecialchars($objMisc->vCity)?>" size="35" maxlength="200" class="textbox"></td>
                                                            </tr>
                                                            <tr align="left">
                                                                <td class="maintext2">&nbsp;</td>
                                                                <td class="maintext2">Event Venue<span><font color="red"> * </font> </span></td>
                                                                <td class="maintext2"><input name="vVenue" type="text" value="<?php echo htmlspecialchars($objMisc->vVenue)?>" size="35" maxlength="200" class="textbox"></td>
                                                            </tr>
                                                            <tr align="left">
                                                                <td class="maintext2">&nbsp;</td>
                                                                <td class="maintext2">Event Date<span><font color="red"> * </font> </span></td>
                                                                <td class="maintext2"><input id='dDate_Event' name="dDate_Event" type="text" value="<?php echo date("m/d/Y H:i:s",strtotime($objMisc->dDate_Event))?>" size="25" maxlength="200" readonly class="textbox">
                                                                    <input type="button" value="V" id="button1" name="button1"  class="button_stylenew_new" style=" width:30px;">
                                                                    <script type="text/javascript" language="javascript">
                                                                        Calendar.setup({
                                                                            inputField    : "dDate_Event",
                                                                            button        : "button1",
                                                                            //ifFormat      : "%Y-%m-%d %H:%M:%S",       // format of the input field
                                                                            ifFormat      : "%m/%d/%Y %H:%M:%S",       // format of the input field
                                                                            showsTime     : true,
                                                                            timeFormat    : "24"
                                                                        });
                                                                    </script></td>
                                                            </tr>
                                                            <tr align="left">
                                                                <td class="maintext2">&nbsp;</td>
                                                                <td width="27%" valign="top" class="maintext2">Event Description<span><font color="red"> * </font> </span></td>
                                                                <td width="70%" valign="top" class="maintext2"><?php
                                                                        $sBasePath                      = "fckeditor/";
                                                                        $sBasePath                      = dirname(dirname($_SERVER['PHP_SELF'])) == "/" ? "/includes/fckeditor/" : dirname(dirname($_SERVER['PHP_SELF'])) ."/includes/fckeditor/";
                                                                        $oFCKeditor 					= new FCKeditor('vDescription') ;
                                                                        $oFCKeditor->BasePath			= $sBasePath ;
                                                                        $oFCKeditor->Value				= $objMisc->vDescription;
                                                                        $oFCKeditor->Config['SkinPath'] = $sBasePath . 'editor/skins/silver/' ;
                                                                        $oFCKeditor->Width  = '90%' ;
                                                                        $oFCKeditor->Height = '300' ;
                                                                        $oFCKeditor->Create() ;
                                                                        ?></td>
                                                            </tr>
                                                                <?php
                                                            }//end first if
                                                            ?>
                                                        </table>
                                                        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td align="right"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                                                                        <tr>
                                                                            <td>&nbsp;</td>
                                                                        </tr>
                                                                    </table>
                                                                    <?php if ($objDB) {
                                                                        ?>
                                                                    <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                                                                        <tr>
                                                                            <td align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                                                                                    <tr>
                                                                                        <td width="30%">&nbsp;</td>
                                                                                        <td width="7%">
                                                                                            <input name="BackNow" type="submit" class="back-btn" value="Back"></td>
                                                                                            <?php //if ($id > 0) { ?>
                                                                                        <td><input name="SaveNow" type="submit" class="loginbutton" value="Save" onclick="return validate();"><input type="hidden" name="id" value="<?php echo $id?>">
                                                                                            <input type="hidden" name="page" value="<?php echo $page?>"></td>
                                                                                        <td width="50%">&nbsp;</td>
                                                                                            <?php //}//end if?>
                                                                                    </tr>
                                                                                </table></td>
                                                                        </tr>
                                                                    </table>
                                                                        <?php
                                                                    }//end first if
                                                                    ?></td>
                                                            </tr>
                                                        </table></td>
                                                </tr>
                                            </table></form>
                                    </div>
                                </td>
                            </tr>
                        </table>

                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<?php include_once('bottomhtml.php');?>