if (isset($_COOKIE[session_name()])) {
        setcookie(session_name(), '', time() - 42000, '/');
    }
    session_destroy();
    $logout = "You have been Successfully Logged Out!";
}
if (isset($_POST['addevent'])) {
    $event_name = addslashes(htmlentities($_POST['eventname']));
    $event_category_id = $_POST['eventcat'];
    $added_by = $_SESSION['admin'];
    addEvent($event_name, $event_category_id, $added_by);
    $addscs = "Event has been successfully added to the database !";
}
if (isset($_POST['selectevent'])) {
    $evntid = $_POST['eventname'];
    $edtevnt = getEventbyid($evntid);
}
if (isset($_POST['editevent'])) {
    $modified_by = $_SESSION['admin'];
    $eventname = htmlentities($_POST['eventname']);
    $event_category_id = htmlentities($_POST['eventcat']);
    $about = $san->cleanHTML($_POST['about']);
    $rules = $san->cleanHTML($_POST['rules']);
    $contacts = $san->cleanHTML($_POST['contacts']);
    $evntid = $san->cleanHTML($_POST['evntid']);
    $clink = $san->cleanHTML($_POST['clink']);
    $strtdate = date('Y-m-d H:i:s', strtotime(addslashes(htmlentities($_POST['strtdate'])) . ' ' . addslashes(htmlentities($_POST['strttime']))));
    $enddate = date('Y-m-d H:i:s', strtotime($_POST['enddate'] . ' ' . $_POST['endtime']));
    editEvent($evntid, $eventname, $event_category_id, $about, $rules, $contacts, $clink, $strtdate, $enddate, $modified_by);
    $editscs = "Event has been successfully updated in the database !";
}
        $stuff = "<div class='box'>\n\t\t\t\t\t<div class='box-head'>\n\t\t\t\t\t\t<h2 class='left'> " . $eventdetails[0]['event_name'] . ": </h2>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div style='padding: 10px 10px 10px 20px;'><br>\n\t\t\t\t\t\t<h3><b><u>About: </u></b></h3><br>\n\t\t\t\t\t\t<p style='padding-bottom: 5px; font-size:14px; line-height:18px;'>" . stripslashes($eventdetails[0]['about']) . "</p><br>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div style='padding: 10px 10px 10px 20px;'>\n\t\t\t\t\t\t<h3><b><u>Rules:</u> </b></h3><br>\n\t\t\t\t\t\t<p style='padding-bottom: 5px;font-size:14px; line-height:18px;'>" . stripslashes($eventdetails[0]['rules']) . "</p><br>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div style='padding: 10px 10px 10px 20px;'>\n\t\t\t\t\t\t<h3><b><u>Contest Link:</u></b> </h3><br>\n\t\t\t\t\t\t<p style='padding-bottom: 5px;font-size:14px; line-height:18px;'><a href='" . stripslashes($eventdetails[0]['clink']) . "' target='new'>" . stripslashes($eventdetails[0]['clink']) . "</a></p><br>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div style='padding: 10px 10px 10px 20px;'>\n\t\t\t\t\t\t<h3><b><u>Contact Details:</u> </b></h3><br>\n\t\t\t\t\t\t<p style='padding-bottom: 5px; font-size:14px; line-height:18px;'>" . stripslashes($eventdetails[0]['contacts']) . "</p><br>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t";
    }
}
if (isset($_POST['register'])) {
    $regval = addslashes(htmlentities($_POST['regval']));
    if (!alreadyRegistered($userid, $regval)) {
        if (isProfileComplete($user)) {
            registerEvent($regval, $userid, $user);
            $registerscs = "<p style='color:#74a446; font-size:15px;' > You have successfully registered to the Event! </p>";
        } else {
            $registerscs = "<p style='color:red; font-size:15px;' > First you need to complete your profile information to apply for Events.<p>";
        }
    } else {
        $registerscs = "<p style='color:#74a446; font-size:15px;' > You are already registered to the Event! </p>";
    }
    $eventdetails = getEventbyid($regval);
    $stuff = "<div class='box'>\n\t\t\t\t<div class='box-head'>\n                                                <h2 class='left'> " . $eventdetails[0]['event_name'] . ": </h2>\n                                        </div>\n                                        <div style='padding: 10px 10px 10px 20px;'><br>\n                                                <h3><b><u>About: </u></b></h3><br>\n                                                <p style='padding-bottom: 5px; font-size:14px; line-height:18px;'>" . stripslashes($eventdetails[0]['about']) . "</p><br>\n                                        </div>\n                                        <div style='padding: 10px 10px 10px 20px;'>\n                                                <h3><b><u>Rules:</u> </b></h3><br>\n                                                <p style='padding-bottom: 5px;font-size:14px; line-height:18px;'>" . stripslashes($eventdetails[0]['rules']) . "</p><br>\n                                        </div>\n                                        <div style='padding: 10px 10px 10px 20px;'>\n                                                <h3><b><u>Contest Link:</u></b> </h3><br>\n\t\t\t\t\t\t<p style='padding-bottom: 5px;font-size:14px; line-height:18px;'><a href='" . stripslashes($eventdetails[0]['clink']) . "' target='new'>" . stripslashes($eventdetails[0]['clink']) . "</a></p><br>\n                                        </div>  \n                                        <div style='padding: 10px 10px 10px 20px;'>\n                                                <h3><b><u>Contact Details:</u> </b></h3><br>\n                                                <p style='padding-bottom: 5px; font-size:14px; line-height:18px;'>" . stripslashes($eventdetails[0]['contacts']) . "</p><br>\n                                        </div>  \n\t\n\t\t\t</div>\n\t\t\t\t";
}
?>

<!-- Container -->

    
    <div id="main" style="width:940px; margin:20px auto;">
      <div class="cl">&nbsp;</div>
      <?php 
echo "<span style='margin-left:20px;margin-top:5px;'>{$registerscs} </span>";
?>
      <div id="content" >
		<?php 
echo $stuff;
$username = $_SESSION['user'];
$userid = getAccountid($username);
$eventlist = "";
$eventname = "";
$upcoming = "";
$ongoing = "";
$registered = "";
$events = array();
$categories = array();
$news = array();
$timezone = "Asia/Calcutta";
date_default_timezone_set($timezone);
$eventlist = getRegisteredEvents($userid);
for ($i = 0; $i < count($eventlist); $i++) {
    $eventname = getEventbyid($eventlist[$i]['event_id']);
    $registered .= "<tr>\n\t\t\t   <td><p style='padding:3px; line-height:20px;'>{$eventname[0]['event_name']}</p></td>\n\t\t\t   <td><p style='padding:3px; line-height:20px;'>" . format_date($eventname[0]['start']) . "</p></td>\n\t\t\t   <td><p style='padding:3px; line-height:20px;'>" . format_date($eventname[0]['end']) . "</p></td>\n\t\t   </tr>\n\t   ";
}
$categories = getEventCategories();
$events = getAllEvents();
for ($i = 0; $i < count($categories); $i++) {
    $eventcat = $categories[$i]['id'];
    for ($j = 0; $j < count($events); $j++) {
        if ($eventcat == $events[$j]['event_category_id']) {
            if (strtotime($events[$j]['start']) <= time() && time() < strtotime($events[$j]['end'])) {
                $ongoing .= "<tr><td>{$events[$j]['event_name']}</td><td>" . ucFirst($categories[$i]['name']) . "</td><td>" . format_date($events[$j]['end']) . "</td></tr>";
            }
        }
    }
}
$count = 0;