<?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['submitblock'])) {
				$titlea = $_POST['title'];
				$blockcontent = $_POST['content'];
				$ordernum = $_POST['ordernum'];
				$sqledit = mysql_query("INSERT INTO Web_Home_Blocks VALUES('','$titlea','$ordernum','$blockcontent')");
						
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Home block created
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
			if(isset($_POST['editpage'])) {
				$ordernum = $_POST['ordernum'];
				$newordernum = $_POST['newordernum'];
				$titlea = $_POST['title'];
				$blockcontent = $_POST['content'];
				$sqledit = mysql_query("UPDATE Web_Home_Blocks SET name='$titlea',ordernum='$newordernum',html='$blockcontent' WHERE ordernum='$ordernum'");
						
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Home block edited
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
if(isset($_POST['deleterequest'])) {
	$ordernum = $_POST['block'];
	$delete = mysql_query("DELETE FROM Web_Home_Blocks WHERE ordernum='$ordernum'");
	?>
	<div style="margin-top: -80px;" class="alert alert-success" role="alert">
		<strong>Well done!</strong> Home block 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'])) {
 	 		$ordernum = $_POST['block'];
 	 		$pgs = mysql_query("SELECT * FROM Web_Home_Blocks WHERE ordernum='$ordernum'");
			$pgsr = mysql_fetch_array($pgs);
			
			$titlea = $pgsr['name'];
			$dbordernum = $pgsr['ordernum'];
			$html = $pgsr['html'];
	?>
		<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='ordernum' value='<?php echo $dbordernum;?>'>
							<input class="form-control" value="<?php echo $titlea;?>" placeholder="Title" name="title" type="text">
							<input class="form-control" value="<?php echo $dbordernum;?>" placeholder="Order [1,2,3]" name="newordernum" 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="content" rows="18"><?php echo $html;?></textarea>
							</center>					
					</div>
					<input type="hidden" name="csrf_token" value="<?php echo $token; ?>">
				</form>
				</br>
				</center>
			</div>
        </div>
      </div>
    </div>
	<?php
	}
	if(isset($_POST['createrequest'])) {
		$ordernum = $_POST['block'];
 	 ?>
	<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='ordernum' value='<?php echo $ordernum; ?>'>
							<input class="form-control" placeholder="Block title" name="title" type="text">
							<span class="input-group-btn">
								<input value="Create" class="btn btn-default" style="width: 150px;" name="submitblock" 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="content" rows="18">Block 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>Home Blocks</small></h1>
 	</div>
		<div class="col-sm-12">
		<center>
         <?php
			$query = "SELECT * FROM Web_Home_Blocks WHERE ordernum='1' ORDER BY ordernum ASC LIMIT 1";
			$result = mysql_query($query) or die('Error, query failed');

			// print the random numbers
			
			if(mysql_num_rows($result)<1){
   		?>
   			<div class="col-sm-4">
   				<div class="well">
   				<form method="POST">
   					<input type='hidden' name='block' value="1">
   					<input name='createrequest' value='+' class='btn btn-default' type='submit'>
   				</form>
   				</div>
   			</div>
   		<?php
   		}else{
     		while($row = mysql_fetch_array($result))
				{
					?>
   				<div class="col-sm-4">
   					<div class="well">
   					<form method="POST">
   						<input type='hidden' name='block' value="<?php echo $row['ordernum'];?>">
   						<p><?php echo $row['name'];?></p>
   						<input name='editrequest' value='Edit' class='btn btn-default' type='submit'>
   						<input name='deleterequest' value='Delete' class='btn btn-danger' type='submit'>
   					</form>
   					</div>
   				</div>
   				<?php
				}
       	}
			?>
			<?php
			$query = "SELECT * FROM Web_Home_Blocks WHERE ordernum='2' ORDER BY ordernum ASC LIMIT 1";
			$result = mysql_query($query) or die('Error, query failed');

			// print the random numbers
			
			if(mysql_num_rows($result)<1){
   		?>
   			<div class="col-sm-4">
   				<div class="well">
   				<form method="POST">
   					<input type='hidden' name='block' value="2">
   					<input name='createrequest' value='+' class='btn btn-default' type='submit'>
   				</form>
   				</div>
   			</div>
   		<?php
   		}else{
     		while($row = mysql_fetch_array($result))
				{
					?>
   				<div class="col-sm-4">
   					<div class="well">
   					<form method="POST">
   						<input type='hidden' name='block' value="<?php echo $row['ordernum'];?>">
   						<p><?php echo $row['name'];?></p>
   						<input name='editrequest' value='Edit' class='btn btn-default' type='submit'>
   						<input name='deleterequest' value='Delete' class='btn btn-danger' type='submit'>
   					</form>
   					</div>
   				</div>
   				<?php
				}
       	}
			?>
			<?php
			$query = "SELECT * FROM Web_Home_Blocks WHERE ordernum='3' ORDER BY ordernum ASC LIMIT 1";
			$result = mysql_query($query) or die('Error, query failed');

			// print the random numbers
			
			if(mysql_num_rows($result)<1){
   		?>
   			<div class="col-sm-4">
   				<div class="well">
   				<form method="POST">
   					<input type='hidden' name='block' value="3">
   					<input name='createrequest' value='+' class='btn btn-default' type='submit'>
   				</form>
   				</div>
   			</div>
   		<?php
   		}else{
     		while($row = mysql_fetch_array($result))
				{
					?>
   				<div class="col-sm-4">
   					<div class="well">
   					<form method="POST">
   						<input type='hidden' name='block' value="<?php echo $row['ordernum'];?>">
   						<p><?php echo $row['name'];?></p>
   						<input name='editrequest' value='Edit' class='btn btn-default' type='submit'>
   						<input name='deleterequest' value='Delete' class='btn btn-danger' type='submit'>
   					</form>
   					</div>
   				</div>
   				<?php
				}
       	}
			?>
        </center>
        </div>
</div>

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