name : insert_project.php
<?php session_start(); 
if(isset($_SESSION['status']) != 1  || isset($_SESSION['stauts_login']) != 1 ){
  header("Location:index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>AdminLTE 2 | Dashboard</title>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <link rel="stylesheet" href="dist/css/AdminLTE.css">
  <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
  <link rel="stylesheet" href="bower_components/morris.js/morris.css">
  <link rel="stylesheet" href="bower_components/jvectormap/jquery-jvectormap.css">
  <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
  <link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
  <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<?php include('layout/header.php'); ?>
<?php include('layout/sidebar.php'); ?>
  <div class="content-wrapper">
    <div class="row" style="margin-left:20px;">
      <div class="col-md-12">
      <h2>Insert Project</h2>
              <hr/>
              <form id="add_project" method="post" enctype="multipart/form-data">
                <div id="error_add_project"></div>
                <div class="row">
                  <div class="col-md-6">
                    <div class="form-group">
                      <label>Project Name</label>
                      <input type="text" class="form-control" id="project_name" name="project_name" placeholder="Project Name">
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-6">
                    <div class="form-group">
                      <label>Project Description</label>
                      <textarea rows="5" class="form-control" id="project_desc" name="project_desc"></textarea> 
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-4">
                    <div class="form-group">
                      <label>Project Title :</label><span class="text-danger">|  **image size :  2000 * 948px</span>
                      <div class="radio">
                        <label><input type="radio" name="title_select" id="title_select1" value="1" checked>Title Images</label>
                        <input type="file" name="title_image" id="title_image"  class="form-control" >
                      </div>
                      <div class="radio">
                        <label><input type="radio" name="title_select" id="title_select2" value="2">Title Youtube</label>
                        <input type="text" class="form-control" id="title_youtube" name="title_youtube" placeholder="Title Youtube">
                      </div>
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-6">
                    <div class="form-group">
                      <label>Images Cover</label><span id="text_youtube"></span><span class="text-danger">|  **image size :  1200 * 790px / 850px * 1150px</span>
                      <input type="file" name="im_cover" id="im_cover"  class="form-control" >
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-4">
                    <div class="form-group">
                      <label>Layout Select :</label>
                      <select name="layout" id="layout" class="form-control">
                      <?php 
                        include('../config/config.php');
                        $sql = "SELECT * FROM layouts";
                        $res = $conn->query($sql);
                        $num_rows = $res->num_rows;
                        if($num_rows > 0){
                          while($row = $res->fetch_assoc()){
                        ?>
                          <option value="<?php echo $row['l_id']; ?>"><?php echo $row['l_name']; ?></option>';
                        <?php
                          }
                        }else{
                        ?>
                            <option value="0">No Layout</option>
                        <?php
                        }
                        ?>
                      </select>
                      <span class="help-block"><a href="#" data-toggle="modal" data-target="#myModal"> Example Layout</a></span>
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-3">
                    <div class="form-group">
                      <label>Location :</label>
                      <input type="text" class="form-control" id="location" name="location" placeholder="Location">
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="form-group">
                      <label>Owner :</label>
                      <input type="text" class="form-control" id="owner" name="owner" placeholder="Owner">
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-3">
                    <div class="form-group">
                      <label>Type Project :</label>
                      <select name="types" id="types" class="form-control">
                      <?php 
                        include('../config/config.php');
                        $sql = "SELECT * FROM types";
                        $res = $conn->query($sql);
                        $num_rows = $res->num_rows;
                        if($num_rows > 0){
                          while($row = $res->fetch_assoc()){
                        ?>
                          <option value="<?php echo $row['t_id']; ?>"><?php echo $row['t_name']; ?></option>
                          
                        <?php
                          }
                        }else{
                        ?>
                            <option value="0">No Types</option>
                        <?php
                        }
                        ?>
                      </select>
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="form-group">
                      <label>Category Project :</label>
                      <select name="cats" id="cats" class="form-control">
                      <?php 
                        include('../config/config.php');
                        $sql = "SELECT * FROM categorys WHERE c_id  not  in ('C000')";
                        $res = $conn->query($sql);
                        $num_rows = $res->num_rows;
                        if($num_rows > 0){
                          while($row = $res->fetch_assoc()){
                        ?>
                          <option value="<?php echo $row['c_id']; ?>"><?php echo $row['c_name']; ?></option>';
                        <?php
                          }
                        }else{
                        ?>
                            <option value="0">No Category</option>
                        <?php
                        }
                        ?>
                      </select>
                    </div>
                  </div>
                </div>
                
                <button class="btn btn-primary" type="submit">Save</button>
                <button class="btn btn-danger" type="reset">Cancel</button>
              </form>
      </div>
    </div>
  </section>
</div>

  <?php include('layout/aside.php') ?>
  <div class="control-sidebar-bg"></div>
</div>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog modal-lg">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Layout Select</h4>
      </div>
      <div class="modal-body">
        <div class="col-md-2">
              <label>Layout No. 1</label>
              <img src="../images/ex1.jpg" class="img-responsive" />
        </div>
        <div class="col-md-2">
              <label>Layout No. 2</label>
              <img src="../images/ex2.jpg" class="img-responsive" />
        </div>
        <div class="col-md-3">
              <label>Layout No. 3</label>
              <img src="../images/ex3.jpg" class="img-responsive" />
        </div>
        <div class="col-md-3">
              <label>Layout No. 4</label>
              <img src="../images/ex4.jpg" class="img-responsive" />
        </div>
        <div class="col-md-2">
              <label>Layout No. 5</label>
              <img src="../images/ex5.jpg" class="img-responsive" />
        </div>
      </div>
      <div class="modal-footer">
        
      </div>
    </div>

  </div>
</div>
</body>

<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/jquery-ui/jquery-ui.min.js"></script>
<script>
  $.widget.bridge('uibutton', $.ui.button);
</script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="bower_components/raphael/raphael.min.js"></script>
<script src="bower_components/morris.js/morris.min.js"></script>
<script src="bower_components/jquery-sparkline/dist/jquery.sparkline.min.js"></script>
<script src="plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<script src="bower_components/jquery-knob/dist/jquery.knob.min.js"></script>
<script src="bower_components/moment/min/moment.min.js"></script>
<script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<script src="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<script src="bower_components/fastclick/lib/fastclick.js"></script>
<script src="dist/js/adminlte.min.js"></script>
<script src="dist/js/pages/dashboard.js"></script>
<script src="dist/js/demo.js"></script>
<script src="dist/js/jquery.validate.min.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script> 
<script>
$(document).ready(function(){
    $("#title_image").show();
    $("#title_youtube").hide();
});

$("input[name=title_select").click(function(){
    var value = $(this).val();
   if(value == 1){
      $("#title_image").show();
      $("#title_youtube").hide();
      $("#text_youtube").html("");
   }else{
    $("#title_image").hide();
      $("#title_youtube").show();
      $("#text_youtube").html("<span class='text-danger'>|  **Use Image GIF File </span>");
   }
});

$('#add_project').validate({
      rules: {
        project_name: {
                required: true,
            },
        project_desc: {
            required: true,
        },          
        location: {
            required: true,
        },
        owner: {
            required: true,
        },
        title_image: {
            required: true,
        },
        im_cover: {
            required: true,
        },
      },
      messages: {
          project_name: {
              required: "<p style='color:red'>Please Insert Project Name</p>",
          },
          project_desc: {
              required: "<p style='color:red'>Please Insert Project Description</p>",
          },          
          location: {
              required: "<p style='color:red'>Please Insert Loacation</p>",
          },
          owner: {
              required: "<p style='color:red'>Please Insert Owner</p>",
          },
          title_image: {
              required: "<p style='color:red'>Please Insert Title Images</p>",
          },
          im_cover: {
              required: "<p style='color:red'>Please Insert Images Cover</p>",
          },
      },
      submitHandler: function(form) {
        var file_data = $('#title_image').prop('files')[0];   
        var project_name = $('#project_name').val();
        var project_desc = $('#project_desc').val();
        var layout = $('#layout').val();
        var location = $('#location').val();
        var owner = $('#owner').val();
        var types = $('#types').val();
        var cats = $('#cats').val();
        var title_youtube = $('#title_youtube').val();
        var im_cover = $('#im_cover').prop('files')[0];   
        var form_data = new FormData();          
        form_data.append('file', file_data);
        form_data.append('project_name', project_name);
        form_data.append('project_desc', project_desc);
        form_data.append('layout', layout);
        form_data.append('location', location);
        form_data.append('owner', owner);
        form_data.append('title_youtube', title_youtube);
        form_data.append('types', types);
        form_data.append('cats', cats);
        form_data.append('im_cover', im_cover);                      
       
        $.ajax({
            url: "add_project.php",
            dataType: 'text', 
            cache: false,
            contentType: false,
            processData: false,
            data: form_data,                         
            type: 'post',
        }).done(function(data){
          console.log(data);
          if(data == 1){
            $("#error_add_project").html('<div class="alert alert-success"><strong>Success! </strong>Add Project.</div>').fadeIn(1000).delay(3000).fadeOut(function(){ window.location.href="project_list.php" }); 
            $('#add_project')[0].reset();
          }else if(data == 3){
            $("#error_add_project").html('<div class="alert alert-danger"><strong>Please! </strong> Select Type Images Is GIF.</div>').fadeIn(1000).delay(3000).fadeOut(); 
              $('#im_cover').val("");
              return false;
          }else{
            $("#error_add_project").html('<div class="alert alert-danger"><strong>Warning! </strong> Not Add Project </div>').fadeIn(1000).delay(3000).fadeOut(); 
              return false;
          }
        });
      }
    });

    var _URL = window.URL || window.webkitURL;
    $("#title_image").change(function (e) {
    var file, img;
    if ((file = this.files[0])) {
        img = new Image();
        img.onload = function () {
          var width = this.width;
          var height = this.height;
          if((width != 2000) || (height != 948)){
            $("#error_add_project").html("<p class='alert alert-danger'>Plases Select Images size 2000px * 948px </p> ").fadeIn(1000).delay(3000).fadeOut(1000);
              $("#title_image").val("");
              return false;
            }
        };
        img.src = _URL.createObjectURL(file);
    }
    });

    $("#im_cover").change(function (e) {
    var file, img;
    if ((file = this.files[0])) {
        img = new Image();
        img.onload = function () {
          var width = this.width;
          var height = this.height;
          if(((width == 1200) || (height == 790)) || ((width == 850) || (height == 1150))){
             
            }else{
              $("#error_add_project").html("<p class='alert alert-danger'>Plases Select Images size 1200px * 790px OR 850px * 1150px </p> ").fadeIn(1000).delay(3000).fadeOut(1000);
              $("#im_cover").val("");
              return false;
            }
        };
        img.src = _URL.createObjectURL(file);
    }
    });
    
</script>

</html>

© 2024 UnknownSec