<?php
// INCLUDE HEADER IN PAGE
include('other_header.php');
// GET CURRENT DATE AND TIME
$date = date('Y-m-d H:i:s');
if(isset($_POST['success'])) {
	if($_POST['success'] == 'loggedin') {
	?>
	<div style="margin-top: -80px;" class="alert alert-success" role="alert">
		<strong>Well done!</strong> Successfully logged in.
	</div>
	<?php
	}
}

///////////////////////////////////////////////////////////////////
			if(isset($_POST['submitpage'])) {
				$titlea = $_POST['title'];
				$message = $_POST['newcontent'];
				$sqledit = mysql_query("INSERT INTO Web_News VALUES('','$date','$titlea','$message')");
						
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> News successfully created.
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
			if(isset($_POST['editpage'])) {
				$newid = $_POST['newid'];
				$titlea = $_POST['title'];
				$message = $_POST['newcontent'];
				$sqledit = mysql_query("UPDATE Web_News SET title='$titlea',message='$message' WHERE id='$newid'");
						
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> News successfully edited.
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
if(isset($_POST['deleterequest'])) {
	$newid = $_POST['newid'];
	$delete = mysql_query("DELETE FROM Web_News WHERE id='$newid'");
	?>
	<div style="margin-top: -80px;" class="alert alert-success" role="alert">
		<strong>Well done!</strong> News successfully deleted
	</div>
	<?php
}
?>
  <div class="container">
    <div class="text-center">
      <h1><?php echo $title; ?>
      	<small>/Active is: Admin Account
			</small>
		</h1>
 	 </div>
 	 </br>
 	 <?php
 	 	if(isset($_POST['editrequest'])) {
 	 		$newid = $_POST['newid'];
 	 		$pgs = mysql_query("SELECT * FROM Web_News WHERE id='$newid'");
			$pgsr = mysql_fetch_array($pgs);
			
			$titlea = $pgsr['title'];
			$message = $pgsr['message'];
	?>
		<div class="row">
      <div class="col-md-10 col-md-offset-1">
		<div class="well">
			<div class="row">
				<center>
				<form name="csrf_form" id="campaignform" action="" method="POST">
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<input type='hidden' name='newid' value='<?php echo $newid; ?>'>
							<input class="form-control" value="<?php echo $titlea;?>" placeholder="Title" name="title" type="text">
							<span class="input-group-btn">
								<input value="Edit" class="btn btn-default" style="width: 150px;" name="editpage" type="submit">
							</span>
					</div>
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<textarea class="input-block-level" id="summernote" name="newcontent" rows="18"><?php echo $message;?></textarea>
							</center>					
					</div>
					<input type="hidden" name="csrf_token" value="<?php echo $token; ?>">
				</form>
				</br>
				</center>
			</div>
        </div>
      </div>
    </div>
	<?php
	}
	if(!isset($_POST['editrequest'])) {
 	 ?>
	<div class="row">
      <div class="col-md-10 col-md-offset-1">
		<div class="well">
			<div class="row">
				<center>
				<form name="csrf_form" id="campaignform" action="" method="POST">
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<input class="form-control" placeholder="Title" name="title" type="text">
							<span class="input-group-btn">
								<input value="Create" class="btn btn-default" style="width: 150px;" name="submitpage" type="submit">
							</span>
					</div>
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<textarea class="input-block-level" id="summernote" name="newcontent" rows="18">New content</textarea>
							</center>					
					</div>
					<input type="hidden" name="csrf_token" value="<?php echo $token; ?>">
				</form>
				</br>
				</center>
			</div>
        </div>
      </div>
    </div>
    	<?php
 		}
	 	?>
	
   <div class="text-center">
      <h1><small>News</small></h1>
 	</div>
		<div class="col-sm-12">
          <table class="table table-bordered" style="width:100%;max-width:100%"  data-effect="fade">
										<thead>
											<tr>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>#</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Title</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Date of creation</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'><?php echo $a061; ?></th>
											</tr>
										</thead>
											<?php
			$query = "SELECT * FROM Web_News ORDER BY id DESC";
			$result = mysql_query($query) or die('Error, query failed');

			// print the random numbers
			
			if(mysql_num_rows($result)<1){
   echo "
						<tr>
							<td>No News</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
   ";
   }else{
	$numberoflink = 0;
     while($row = mysql_fetch_array($result))
				{
					$link = $row['name'];
					if(empty($link)) {
						
					}
					echo "
										<tr>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5>{$row['id']}</h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5>{$row['title']}</h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5>{$row['date']}</h5>
											</td>
											<form name='actions' action='' method='POST'>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<input type='hidden' name='newid' value='".$row['id']."'>
												<input style='float:right' name='deleterequest' value='Delete' class='btn btn-default' type='button'>
												<input style='float:right' name='editrequest' value='Edit' class='btn btn-default' type='submit'>
											</td>
											</form>
										</tr>";

				}

       }
	?>
									</table>
        </div>
</div>

<?php
include('other_footer.php');
?>
