<?php
session_name("AUTHENUSER");
session_start();
$USERNAME = $_SESSION['SES_USERNAME'];
if(!session_name("AUTHENUSER"))
	{
?>
						<script language="javascript">
						 alert("Waktu Login telah habis.Silahkan Login Kembali");
						document.location="index.php";
						</script>
<?php
	}
if(!$USERNAME)
	{
?>
						<script language="javascript">
						 alert("Harap Login Dahulu.");
						document.location="index.php";
						</script>
<?php
	}
	?>
	<?php 
	include "common/config.php";
	include "include/head.php";

	$act  = $_REQUEST['act'];
	$kode = mysql_fetch_array(mysql_query("select max(id_shape) as maxid from tbl_shape"));
	$maxid = $kode['maxid'];
	if($maxid == "")
	{
		$kode1 = "SHAPE1";
	
	}
	else
	{
		$total = $maxid+1;
		$kode1 = "SHAPE".$total;
	}
	if($act == 1)
	{
		list($d, $e, $f)=split ("[-]", $_REQUEST['inputDate']);
		$startdate=$f."-".$e."-".$d;
		list($d, $e, $f)=split ("[-]", $_REQUEST['inputDate2']);
		$enddate=$f."-".$e."-".$d;
		$description = $_REQUEST['description'];
		if($description ==  "")
		{
		?>
				<script language="javascript">
                alert("Input Description");
                document.location="add_calender.php";
                </script>
		<?php	
		}
		elseif(strtotime($startdate) > strtotime($enddate))
						{
						?>
						<script language="javascript">
										 alert("Start Date < End Date");
										document.location="add_calender.php";
										</script>
						<?php
						}
						
		else
		{
			
			$insert = mysql_query("insert into calender (startdate,enddate,description,user_update) values ('$startdate','$enddate','$description','$USERNAME')");
			if($insert)
			{
				?>
				<script language="javascript">
                alert("Add Calender Success");
                document.location="add_calender.php";
                </script>
				<?php
			}
			else
			{
				?>
				<script language="javascript">
                alert("Add Calender Failed");
                document.location="add_calender.php";
                </script>
				<?php	
			}
		}
	}
	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-th"></i> Add Calender</h1>
</div>

<!--<ol class="breadcrumb">
  <li><a href="#">Home</a></li>
  <li><a href="#">Bread</a></li>
  <li><a href="#">Crumbs</a></li>
  <li class="active">Example</li>
</ol>-->
          <div class="main-content">
            <div class="row">
                <div class="widget">
                  <div class="widget-content-white glossed">
                    <div class="padded">
                      <form method="post" action="add_calender.php?act=1" role="form" class="form-horizontal">
                        <div class="form-group">
                          <label class="col-md-4 control-label">Start Date</label>
                          <div class="col-md-8">
                             <input type="text" class="inputDate" name="inputDate" id="inputDate" value="<?php echo date('d-m-Y'); ?>">
                          </div>
                        </div>
                         <div class="form-group">
                          <label class="col-md-4 control-label">End Date</label>
                          <div class="col-md-8">
                             <input type="text" class="inputDate2" name="inputDate2" id="inputDate2" value="<?php echo date('d-m-Y'); ?>">
                          </div>
                        </div>
                    <div class="form-group">
                          <label class="col-md-4 control-label">Description</label>
                          <div class="col-md-8"><textarea cols="80" rows="5" name="description" id="description" class="form-control" ></textarea>
                          </div>
                        </div>    
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="submit" class="btn btn-default">Submit</button>
                            <button type="reset" class="btn btn-default">Reset</button>
                          </div>
                        </div>
                      </form>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                   

<?php include "include/foot.php"; ?>
<script src='assets/js/for_pages/dashboard.js'></script>
</body>

</html>