<?php include("../templates/header.php"); ?>
<?php include("check_admin.php"); ?>

<div class="panel panel-primary">
  <div class="panel-heading">
    <h3 class="panel-title">จัดการ Templates</h3>
  </div>
  <div class="panel-body">
  <br>
  <div class="form-group">
  <div class="col-lg-1"></div>
  <div class="col-lg-7">

  <table class="table table-bordered">
  <thead>
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>On / Off</th>
    </tr>
  </thead>
  <tbody>

  <?php
	
	include("../config/mysql_connect.php");

	$strSQL = "SELECT * FROM setting_templates";
	$objQuery = mysqli_query($link,$strSQL);

	while($Result = mysqli_fetch_array($objQuery)){
	$tem_id = $Result['tem_id'];
	$tem_name = $Result['tem_name'];
	$tem_status = $Result['tem_status'];
	$tem_img = $Result['tem_img'];

	$textbox = '';

	if($tem_status == 'on'){
		$textbox = "<a href='#' class='btn btn-success btn-xs'><span class='glyphicon glyphicon-globe'></span> Templates Online</a>";
		$images = $tem_img;
	}
	else{
		$textbox = "<a href='template.php?id=$tem_id' class='btn btn-primary btn-xs'><span class='glyphicon glyphicon-thumbs-up'></span> Open Templates</a>";
	}

	echo "<tr>
      <td>$tem_id</td>
      <td>$tem_name</td>
      <td>$textbox</td>
    </tr>";

	}

	?>

	</tbody>
	</table>

      </div>
      <div class="col-lg-3"><?php echo"<img src='../images/templates/$images' style='width:260px;height:120px';>"; ?></div>
    </div>

  </div>
</div>

 <?php
//Update Banner
 if(isset($_POST["save_img"])){

 	$newname = "../images/banner.jpg";

 	move_uploaded_file($_FILES['fileupload']['tmp_name'],$newname); 

 	echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=setting.php\">";

 }
 ?>

<div class="panel panel-primary">
  <div class="panel-heading">
    <h3 class="panel-title">จัดการ Banner</h3>
  </div>
  <div class="panel-body">

<form class="form-horizontal" method="post" enctype="multipart/form-data" >
<br>
  <fieldset>
    
    <div class="form-group">
      <div class="col-lg-1"></div>
      <div class="col-lg-9">
      	<form method="post" enctype="multipart/form-data">
		    รูป Banner แนะนำขนาดที่เหมาะสม ความยาวของภาพ: 900px ความสูงของภาพ: 200px ไฟล์ภาพต้องเป็น .jpg เท่านั้น<hr>
			<div class="form-group">
		    <div class="col-lg-5"><input type="file" class="btn btn-default" name="fileupload" id="fileupload"></div>
		    <div class="col-lg-3"><input type="submit" class="btn btn-primary" name="save_img" value="อัพโหลดภาพ"></div>
			</div>
		</form>

      </div>
    </div>

  </div>
</div>

 <?php
 // Update Title and Footer
 if(isset($_POST["set_def"])){

	$title = $_POST['title'];
	$footer = $_POST['footer'];

	$sql_update_def = "update setting_default set def_title='$title', def_footer='$footer' where def_id='1'";
	$Query = mysqli_query($link,$sql_update_def);

		if($objQuery){
			echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=setting.php\">";
		}
		else{
			echo "<div class='alert alert-danger'>
			<button type='button' class='close' data-dismiss='alert'>&times;</button>
			<strong>Alerts!</strong> ล้มเหลว </div>";
		}

 }
 ?>

<div class="panel panel-primary">
  <div class="panel-heading">
    <h3 class="panel-title">จัดการ Text Title & Footer</h3>
  </div><br>
  <div class="panel-body">

<form class="form-horizontal" method="post">
<br>
  <fieldset>

  <div class="form-group">
  <div class="col-lg-1"></div>
      <label for="input" class="col-lg-1 control-label">Title</label>
      <div class="col-lg-9">
        <input type="text" class="form-control" name="title" value="<?php echo"$def_title"; ?>">
      </div>
   </div>

   <div class="form-group">
   <div class="col-lg-1"></div>
      <label for="input" class="col-lg-1 control-label">Footer</label>
      <div class="col-lg-9">
      <textarea class="form-control" rows="3" name="footer"><?php echo"$def_footer"; ?></textarea>
      </div>
   </div>

   <!-- <div class="modal-footer"><div class="col-lg-10"><p class="text-muted credit" style="text-align:right">ข้อความใส่ตรงนี้</p></div></div> -->

   <div class="form-group">
      <div class="col-lg-10 col-lg-offset-2">
        <button type="submit" name="set_def" class="btn btn-primary">บันทึก</button>
      </div>

     </fieldset>
</form>

  </div>
</div>

<?php include("../templates/footer.php"); ?>