<?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['submitimage'])) {
				$name = $_POST['title'];
				$directory = $_POST['directory'];
				$frontend = $_POST['frontend'];
				$backend = $_POST['backend'];
				$shortend = $_POST['shortend'];
				$panelend = $_POST['panelend'];
				$supportend = $_POST['supportend'];
				$paymentsend = $_POST['paymentsend'];
				$widgetend = $_POST['widgetend'];
				$premiumlogin = $_POST['premiumlogin'];
				$emailend = $_POST['emailend'];
				$sqledit = mysql_query("INSERT INTO Web_Themes_All VALUES('','$name','$directory','$frontend','$backend','$shortend','$panelend','$supportend','$paymentsend','$widgetend','$premiumlogin','$emailend')");
						
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Template created
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
			if(isset($_POST['editimage'])) {
				$imageid = $_POST['imageid'];
				$name = $_POST['title'];
				$directory = $_POST['directory'];
				$frontend = $_POST['frontend'];
				$backend = $_POST['backend'];
				$shortend = $_POST['shortend'];
				$panelend = $_POST['panelend'];
				$supportend = $_POST['supportend'];
				$paymentsend = $_POST['paymentsend'];
				$widgetend = $_POST['widgetend'];
				$premiumlogin = $_POST['premiumlogin'];
				$emailend = $_POST['emailend'];
				$sqledit = mysql_query("UPDATE Web_Themes_All SET name='$name',directory='$directory',frontend='$frontend',backend='$backend',shortend='$shortend',panelend='$panelend',supportend='$supportend',paymentsend='$paymentsend',widgetend='$widgetend',premiumlogin='$premiumlogin',emailend='$emailend' WHERE id='$imageid'");
						
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Template edited
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
if(isset($_POST['deleterequest'])) {
	$imageid = $_POST['imageid'];
	$delete = mysql_query("DELETE FROM Web_Images WHERE id='$imageid'");
	?>
	<div style="margin-top: -80px;" class="alert alert-success" role="alert">
		<strong>Well done!</strong> Template 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'])) {
 	 		$imageid = $_POST['imageid'];
 	 		$pgs = mysql_query("SELECT * FROM Web_Themes_All WHERE id='$imageid'");
			$pgsr = mysql_fetch_array($pgs);
			
			$name = $pgsr['name'];
			$directory = $pgsr['directory'];
	?>
		<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='imageid' value='<?php echo $imageid; ?>'>
							<input class="form-control" value='<?php echo $name; ?>' placeholder="Template Name" name="title" type="text">
							<input class="form-control" value='<?php echo $directory; ?>' placeholder="Template directory" name="directory" type="text">
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">FrontEnd</span>
               						<input id="f1" class="toggle toggle-left" name="frontend" value="1" type="radio" <?php if($pgsr['frontend'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="f1" class="btn">Activated</label>
											<input id="f2" class="toggle toggle-right" name="frontend" value="0" type="radio" <?php if($pgsr['frontend'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="f2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Admin Panel</span>
               						<input id="a1" class="toggle toggle-left" name="backend" value="1" type="radio" <?php if($pgsr['backend'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="a1" class="btn">Activated</label>
											<input id="a2" class="toggle toggle-right" name="backend" value="0" type="radio" <?php if($pgsr['backend'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="a2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Ad Loader</span>
               						<input id="lo1" class="toggle toggle-left" name="shortend" value="1" type="radio" <?php if($pgsr['shortend'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="lo1" class="btn">Activated</label>
											<input id="lo2" class="toggle toggle-right" name="shortend" value="0" type="radio" <?php if($pgsr['shortend'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="lo2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">User Panel</span>
               						<input id="us1" class="toggle toggle-left" name="panelend" value="1" type="radio" <?php if($pgsr['panelend'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="us1" class="btn">Activated</label>
											<input id="us2" class="toggle toggle-right" name="panelend" value="0" type="radio" <?php if($pgsr['panelend'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="us2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Support Panel</span>
               						<input id="s1" class="toggle toggle-left" name="supportend" value="1" type="radio" <?php if($pgsr['supportend'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="s1" class="btn">Activated</label>
											<input id="s2" class="toggle toggle-right" name="supportend" value="0" type="radio" <?php if($pgsr['supportend'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="s2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Payments Panel</span>
               						<input id="pay1" class="toggle toggle-left" name="paymentsend" value="1" type="radio" <?php if($pgsr['paymentsend'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="pay1" class="btn">Activated</label>
											<input id="pay2" class="toggle toggle-right" name="paymentsend" value="0" type="radio" <?php if($pgsr['paymentsend'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="pay2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Widget</span>
               						<input id="w1" class="toggle toggle-left" name="widgetend" value="1" type="radio" <?php if($pgsr['widgetend'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="w1" class="btn">Activated</label>
											<input id="w2" class="toggle toggle-right" name="widgetend" value="0" type="radio" <?php if($pgsr['widgetend'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="w2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Premium Login</span>
               						<input id="log1" class="toggle toggle-left" name="premiumlogin" value="1" type="radio" <?php if($pgsr['premiumlogin'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="log1" class="btn">Activated</label>
											<input id="log2" class="toggle toggle-right" name="premiumlogin" value="0" type="radio" <?php if($pgsr['premiumlogin'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="log2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Email Panel</span>
               						<input id="e1" class="toggle toggle-left" name="emailend" value="1" type="radio" <?php if($pgsr['emailend'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="e1" class="btn">Activated</label>
											<input id="e2" class="toggle toggle-right" name="emailend" value="0" type="radio" <?php if($pgsr['emailend'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="e2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<span class="input-group-btn">
								<input value="Edit template" class="btn btn-default" style="width: 150px;" name="editimage" type="submit">
							</span>
					</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="Template Name" name="title" type="text">
							<input class="form-control" placeholder="Template directory" name="directory" type="text">
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">FrontEnd</span>
               						<input id="f1" class="toggle toggle-left" name="frontend" value="1" type="radio" <?php if($link2['active'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="f1" class="btn">Activated</label>
											<input id="f2" class="toggle toggle-right" name="frontend" value="0" type="radio" <?php if($link2['active'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="f2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Admin Panel</span>
               						<input id="a1" class="toggle toggle-left" name="backend" value="1" type="radio" <?php if($link2['active'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="a1" class="btn">Activated</label>
											<input id="a2" class="toggle toggle-right" name="backend" value="0" type="radio" <?php if($link2['active'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="a2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Ad Loader</span>
               						<input id="lo1" class="toggle toggle-left" name="shortend" value="1" type="radio" <?php if($link2['active'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="lo1" class="btn">Activated</label>
											<input id="lo2" class="toggle toggle-right" name="shortend" value="0" type="radio" <?php if($link2['active'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="lo2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">User Panel</span>
               						<input id="us1" class="toggle toggle-left" name="panelend" value="1" type="radio" <?php if($link2['active'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="us1" class="btn">Activated</label>
											<input id="us2" class="toggle toggle-right" name="panelend" value="0" type="radio" <?php if($link2['active'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="us2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Support Panel</span>
               						<input id="s1" class="toggle toggle-left" name="supportend" value="1" type="radio" <?php if($link2['active'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="s1" class="btn">Activated</label>
											<input id="s2" class="toggle toggle-right" name="supportend" value="0" type="radio" <?php if($link2['active'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="s2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Payments Panel</span>
               						<input id="pay1" class="toggle toggle-left" name="paymentsend" value="1" type="radio" <?php if($link2['active'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="pay1" class="btn">Activated</label>
											<input id="pay2" class="toggle toggle-right" name="paymentsend" value="0" type="radio" <?php if($link2['active'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="pay2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Widget</span>
               						<input id="w1" class="toggle toggle-left" name="widgetend" value="1" type="radio" <?php if($link2['active'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="w1" class="btn">Activated</label>
											<input id="w2" class="toggle toggle-right" name="widgetend" value="0" type="radio" <?php if($link2['active'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="w2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Premium Login</span>
               						<input id="log1" class="toggle toggle-left" name="premiumlogin" value="1" type="radio" <?php if($link2['active'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="log1" class="btn">Activated</label>
											<input id="log2" class="toggle toggle-right" name="premiumlogin" value="0" type="radio" <?php if($link2['active'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="log2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
								<center>
									<div class="form-group has-success">
										<div class="input-group">
               						<span class="input-group-addon">Email Panel</span>
               						<input id="e1" class="toggle toggle-left" name="emailend" value="1" type="radio" <?php if($link2['active'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="e1" class="btn">Activated</label>
											<input id="e2" class="toggle toggle-right" name="emailend" value="0" type="radio" <?php if($link2['active'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="e2" class="btn">Deactivated</label>
           							</div>
									</div>
									</center>					
							</div>
							<span class="input-group-btn">
								<input value="Create Template" class="btn btn-default" style="width: 150px;" name="submitimage" type="submit">
							</span>
					</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>Templates</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;'>Directory</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_Themes_All 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 Templates</td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
   ";
   }else{
	$numberoflink = 0;
     while($row = mysql_fetch_array($result))
				{
						$numberoflink = $numberoflink + 1;
						?>
										<tr>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $numberoflink; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['name']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['directory']; ?></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='imageid' value='<?php echo $row['id'];?>'>
													<input style='float:right' name='deleterequest' value='Delete' class='btn btn-default' type='submit'>
													<input style='float:right' name='editrequest' value='Edit' class='btn btn-default' type='submit'>
												</td>
											</form>
										</tr>
						<?php 
				}

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

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