<?php
if(basename($_SERVER['PHP_SELF']) == 'npost.php') 
  $cm=" class='current'";
include'header.php';
include'connection.php';

if(isset($_POST['submit_post']))
		{
			$postna=$_POST['postna'];
			$postown=$_POST['postown'];
			$month=$_POST['month'];
			$year=$_POST['year'];
			$contract=$_POST['contract'];
			$starting="$month/$year";

	$temp1 = explode(".", $_FILES["file1"]["name"]);
$newfilename1 = round(microtime(true)) . '.' . end($temp1);
move_uploaded_file($_FILES["file1"]["tmp_name"], "contact/" . $newfilename1);
	if(!end($temp1))
	$newfilename1='';

$so=mysqli_query($conn, "INSERT INTO `position` (`Postname`, `Starting`, `Done`, `Date`) VALUES ('$postna', '$starting', '$loge', '$Date')");

$pto=10;
		}

		if(isset($_POST['edit_id']))
		{
			$rowid=$_POST['rowid'];
			$do=mysqli_query($conn, "SELECT *FROM `position` WHERE `Postid`='$rowid' LIMIT 1");
				$ro=mysqli_fetch_assoc($do);
					$code=$ro['Postid'];
					$pna=$ro['Postname'];
					$starting=$ro['Starting'];

					/*
					$contra=$ro['Contract'];
					$file1=$ro['File1'];
					if($file1)
	$dfile="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='down_contra.php?link=$file1'>Download File</a>";
else
	$dfile="";
	*/
					$coupe = explode("/", $starting);
							$month=$coupe[0]; 
							$year=$coupe[1];
				$namb="update_post";
				$valub="Update";
		}
		else{
			$code='';
			$pna='';
			$month='';
			$year='';
			$namb="submit_post";
			$valub="Submit";
			$dfile='';
		}

		if(isset($_POST['update_post']))
		{
			$rowid=$_POST['rowid'];
			$postna=$_POST['postna'];
			$month=$_POST['month'];
			$year=$_POST['year'];
			$starting="$month/$year";

/*
	$temp1 = explode(".", $_FILES["file1"]["name"]);
$newfilename1 = round(microtime(true)) . '.' . end($temp1);
move_uploaded_file($_FILES["file1"]["tmp_name"], "contract/" . $newfilename1);
	if(!end($temp1)){
	$newfilename1='';
	$upda="";
	}
	else{
	$upda=", `File1`='$newfilename1'";
	}
*/
$so=mysqli_query($conn, "UPDATE `position` SET `Postname`='$postna', `Starting`='$starting', `Done`='$loge' WHERE `Postid`='$rowid' LIMIT 1");
//$fo=mysqli_num_rows($so);
$fo=1;

$do=mysqli_query($conn, "SELECT *FROM `position` WHERE `Postid`='$rowid'");
				$ro=mysqli_fetch_assoc($do);
					$code=$ro['Postid'];
					$pna=$ro['Postname'];
					$starting=$ro['Starting'];
					$coupe = explode("/", $starting);
							$month=$coupe[0]; 
							$year=$coupe[1];
				$namb="update_post";
				$valub="Update";
if($fo)
	$pto=20;
else
	$pto=30;
		}


//$do=mysqli_query($conn, "SELECT *FROM `position`");
//$fo=mysqli_num_rows($do);
?>
<div class="container-fluid main-content">
<div class="page-title">
        <h1 style='margin-top:-20px; margin-bottom: 5px;'>Positions</h1>
  
    </div>
<div class="row">
<div class="col-md-2">
 
  <ul class="list-group">
   
      <li class="list-group-item">
	  <a href="postm.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Positions' List
                </p>
              </a></li>   
           <li class="list-group-item active">
           <a href="npost.php">
           <p>
           <i class="lnr lnr-plus-circle"></i>&nbsp;Create New Post
           </p></a>
           </li>
          
        </div>
 <div class="col-md-10">
 <div class="widget-container fluid-height clearfix">
 <div class="widget-content padded">
 <form method="post" class="form-horizontal" action="npost.php" enctype="multipart/form-data">
 <input name="app_file_size" id="app_file_size" type="hidden">
 <br>
 <?php 
if($pto==10)
echo"<center><div class='alert alert-danger' style='width:48%;text-align:center;float:center;background-color: #60c560;color: #ffffff;border-radius:5px;'>
		<i class='lnr lnr-checkmark-circle'></i> &nbsp;&nbsp; <button class='close' data-dismiss='alert' type='button'>×</button>New Post Has Been Created.
		</div></center>";
if($pto==20)
echo"<center><div class='alert alert-danger' style='width:48%;text-align:center;float:center;background-color: #60c560;color: #ffffff;border-radius:5px;'>
		<i class='lnr lnr-checkmark-circle'></i> &nbsp;&nbsp; <button class='close' data-dismiss='alert' type='button'>×</button>Current Post Has Been Updated.
		</div></center>";
if($pto==30)
echo"<center><div class='alert alert-danger' style='width:48%;text-align:center;float:center;border-radius:5px;'>
		<i class='lnr lnr-checkmark-circle'></i> &nbsp;&nbsp; <button class='close' data-dismiss='alert' type='button'>×</button>Nothing Has Been Changed.
		</div></center>";
	
			echo"<input value='$code' name='rowid' type='hidden'>";
			?>
  <div class="form-group">
            <label class="control-label col-md-3">Post Name</label>
            <div class="col-md-6">
              <input name="postna" class="form-control" type="text" value="<?php echo $pna ?>" OnKeyup='return cUpper(this);' required>
            </div>
			  <span style="color:#d43f3a">
                         mandatory
                      </span>  
 </div>
 <div class="form-group">
   <label class="control-label col-md-3">Post Owner</label>
                  <div class="col-md-6">
              <input class="form-control" name="postown" type="text" value="<?php echo $pna ?>">
            </div> 
			  <span style="color:#d43f3a">
                         mandatory
                      </span>  
			</div>



  <div class="form-group">
 <label class="control-label col-md-3">Starting Date</label>
            <div class="col-sm-2" style='margin-right:132px;'>
 <select class="form-control" name="month" style='width:200px;'>
	<option value="" selected="selected"> </option>
              <?php
    for ($i = 0; $i < 12;   $i++) {
    $date_str = date('F', strtotime("+ $i months"));
	if($date_str==$month)
		$st='selected';
	else
		$st='';
    echo "<option value='$date_str' $st>".$date_str ."</option>";
    } 
	?>
              </select>  
	 </div>
            <div class="col-sm-2">
	<select class="form-control" name="year" style='width:200px;'>
		<option value="" selected="selected"> </option>
                 <?php
				 $l=date("Y")+2;
				 $e=$l-11;
    for ($i = $l; $i > $e;   $i--) {
		if($i==$year)
			$si='selected';
		else
			$si='';
    echo "<option value='$i' $si>".$i."</option>";
    } 
	?>
              </select> 
	</div></div>

  <div class="form-group">
            <label class="control-label col-md-3">Done&nbsp;by</label>
            <div class="col-md-6">
              <input name="contract" class="form-control" value="<?php echo $loge ?>" type="text">
            </div> 
 </div>

 <div class="form-group">
    <label class="control-label col-md-3">Document File</label>
                     <div class="col-md-6">
              <div class="fileupload fileupload-new" data-provides="fileupload"><input value="" name="" type="hidden">
                <span class="btn btn-default btn-file"><span class="fileupload-new">Select</span><span class="fileupload-exists">Change</span><input name="file1" id="app_file" type="file" readonly='readonly'></span><span class="fileupload-preview"></span><button class="close fileupload-exists" data-dismiss="fileupload" style="float:none" type="button">×</button>

				
                     
              </div>     <small>Zip, txt, jpeg, png, pdf, doc (Max : 2M)</small>
            </div>
            </div>

  <div class="form-group">
  <div class="col-md-12">
  <div class="col-md-3"></div>
   <div class="col-sm-2" align='center' style='border:0px solid black; width:255px;'>                 
    <button class="btn btn-lg btn-block btn-success" type="submit" name="<?php echo $namb ?>" style='width:210px;'>
	<i class="lnr lnr-checkmark-circle"></i> <?php echo $valub ?></button>   
	  
		</div>
		
		 <div class="col-sm-2" align='center' style='border:0px solid black; width:255px;'>
		 <button class="btn btn-lg btn-block btn-danger" type="reset" style='width:210px;'><i class="lnr lnr-undo"></i> Reset</button>  
   </div> 
  <div class="col-md-3"></div>      
 </div></div>
 
 </form>
 </div>
 </div>
 </div>

<?php
include'footer.php';
?>