<?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'];
				$urlname = $_POST['urlname'];
				$pagecontent = $_POST['pagecontent'];
				$sqledit = mysql_query("INSERT INTO Web_Pages VALUES('','$titlea','','$urlname','$pagecontent','1')");
						
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Page successfully added
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
			if(isset($_POST['editpage'])) {
				$pageid = $_POST['pageid'];
				$titlea = $_POST['title'];
				$urlname = $_POST['urlname'];
				$pagecontent = $_POST['pagecontent'];
				$sqledit = mysql_query("UPDATE Web_Pages SET name='$titlea',filename='$urlname',html='$pagecontent' WHERE id='$pageid'");
						
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Page successfully added
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
if(isset($_POST['deleterequest'])) {
	$pageid = $_POST['pageid'];
	$delete = mysql_query("DELETE FROM Web_Pages WHERE id='$pageid'");
	?>
	<div style="margin-top: -80px;" class="alert alert-success" role="alert">
		<strong>Well done!</strong> Campaign 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'])) {
 	 		$pageid = $_POST['pageid'];
 	 		$pgs = mysql_query("SELECT * FROM Web_Pages WHERE id='$pageid'");
			$pgsr = mysql_fetch_array($pgs);
			
			$titlea = $pgsr['name'];
			$url = $pgsr['filename'];
			$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='pageid' value='<?php echo $pageid; ?>'>
							<input class="form-control" value="<?php echo $titlea;?>" placeholder="Page title" name="title" type="text">
							<input class="form-control" value="<?php echo $url;?>" placeholder="URL Page name (ex. about)" name="urlname" type="text">
							<span class="input-group-btn">
								<input value="Edit page" 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="pagecontent" 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['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="Page title" name="title" type="text">
							<input class="form-control" placeholder="URL Page name (ex. about)" name="urlname" type="text">
							<span class="input-group-btn">
								<input value="Create page" 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="pagecontent" rows="18">Page 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>Pages</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;'>Name</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>URL name</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Link</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_Pages WHERE custom='1' ORDER BY id ASC";
			$result = mysql_query($query) or die('Error, query failed');

			// print the random numbers
			
			if(mysql_num_rows($result)<1){
   echo "
						<tr>
							<td>No Pages</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['name']}</h5>
											</td>";
											?>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $link; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<input value='Open' onclick="window.open('<?php echo $mainurl;?>f.<?php echo $row['filename']; ?>')" class='btn btn-default' type='button'>
											</td>
											<?php 
					echo "				<form name='actions' action='' method='POST'>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<input type='hidden' name='pageid' 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');
?>
