Advertisement
wahyu_f14

input-berita

Aug 28th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.30 KB | None | 0 0
  1. <?php
  2. include "koneksi/koneksi.php";
  3. session_name('profil');
  4. session_start();
  5. if (isset($_SESSION['profil-username'])) {
  6.   ?>
  7.  
  8.   <!DOCTYPE html>
  9.   <html>
  10.   <head>
  11.     <meta charset="UTF-8">
  12.     <title>Input Penelitian | Sistem Informasi Perikanan Palabuhanratu</title>
  13.     <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
  14.     <!-- bootstrap 3.0.2 -->
  15.     <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
  16.     <!-- font Awesome -->
  17.     <link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" />
  18.     <!-- Ionicons -->
  19.     <link href="css/ionicons.min.css" rel="stylesheet" type="text/css" />
  20.     <!-- Theme style -->
  21.     <link href="css/AdminLTE.css" rel="stylesheet" type="text/css" />
  22.     <!-- Favicon -->
  23.     <link rel="shortcut icon" href="img/favicon.ico" />
  24.     <!-- bootstrap wysihtml5 - text editor -->
  25.     <link href="css/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css" rel="stylesheet" type="text/css" />
  26.     <style>
  27.       .callout {
  28.         margin-bottom: 0;
  29.       }
  30.       .row {
  31.         margin-bottom: 15px;
  32.       }
  33.       .wysiwyg {
  34.         width: 100%;
  35.         height: 200px;
  36.         font-size: 14px;
  37.         line-height: 18px;
  38.         border: 1px solid #dddddd;
  39.         padding: 10px;
  40.       }
  41.       .wysiwyg:focus{
  42.         border-color: #3c8dbc !important;
  43.         box-shadow: none;
  44.         outline: 0;
  45.       }
  46.     #txt-file {
  47.       padding: 5px 5px;
  48.     }
  49.   </style>
  50. </head>
  51. <body class="skin-blue">
  52.  
  53.   <?php include 'includes/header.php'; ?>
  54.  
  55.   <div class="wrapper row-offcanvas row-offcanvas-left">
  56.     <!-- Left side column. contains the logo and sidebar -->
  57.     <?php include 'includes/menu.php'; ?>
  58.  
  59.     <!-- Right side column. Contains the navbar and content of the page -->
  60.     <aside class="right-side">
  61.       <!-- Content Header (Page header) -->
  62.       <section class="content-header">
  63.         <h1>
  64.           Berita
  65.           <small><i class="fa fa-angle-right"></i>&nbsp; Input Berita</small>
  66.         </h1>
  67.       </section>
  68.  
  69.       <!-- Main content -->
  70.       <section class="content">
  71.  
  72.         <!-- top row -->
  73.         <div class="row">
  74.           <div class="col-md-10">
  75.             <!-- general form elements -->
  76.             <div class="box box-info">
  77.               <div class="box-header">
  78.                 <h3 class="box-title"><i class="fa fa-edit"></i>&nbsp; FORM INPUT BERITA</h3>
  79.               </div><!-- /.box-header -->
  80.  
  81.               <?php
  82.               // -------------------- SIMPAN BERITA --------------------
  83.               if (isset($_POST['simpan-berita'])) {
  84.                 $id_pengguna = $_SESSION['profil-id'];
  85.                 $judul       = $_POST['judul'];
  86.                 $isi         = $_POST['isi'];
  87.                 $label       = $_POST['label'];
  88.  
  89.                 $cek_judul = mysqli_query($db, "SELECT id FROM berita WHERE judul='$judul'");
  90.                 if (mysqli_num_rows($cek_judul) > 0) {
  91.                   echo "<script>alert('Judul sudah ada !')</script>";
  92.                 } else {
  93.                   if ($_FILES['gambar']['tmp_name'] != '') {
  94.                     $gambar         = $_FILES['gambar']['tmp_name'];
  95.                     $gambar_name    = $_FILES['gambar']['name'];
  96.                     $gambar_size    = $_FILES['gambar']['size'];
  97.                     if ($gambar_size > 1000000) {
  98.                       echo "<script>alert('Ukuran gambar terlalu besar !')</script>";
  99.                     } else {
  100.                       move_uploaded_file($gambar, 'gambar/'.$gambar_name); // simpan gambar
  101.                       $simpan_berita = mysqli_query($db, "INSERT INTO berita(id_pengguna, judul, isi, tgl, label, gambar, status) VALUES('$id_pengguna', '$judul', '$isi', NOW(), '$label', '$gambar_name', 'publish')");
  102.                     }
  103.                   } else {
  104.                     $simpan_berita = mysqli_query($db, "INSERT INTO berita(id_pengguna, judul, isi, tgl, label, gambar, status) VALUES('$id_pengguna', '$judul', '$isi', NOW(), '$label', '', 'publish')");
  105.                   }
  106.  
  107.                   if ($simpan_berita == true) {
  108.                     echo "<script>alert('Berita telah disimpan')</script>";
  109.                   } else {
  110.                     echo "<script>alert('Gagal menyimpan data. ".mysqli_error($db)."')</script>";
  111.                   }
  112.                 }
  113.               }
  114.               ?>
  115.  
  116.               <!-- form start -->
  117.               <form role="form" enctype="multipart/form-data" method="POST">
  118.                 <div class="box-body">
  119.                   <div class="form-group">
  120.                       <label for="txt-judul">Judul Berita</label>
  121.                       <input type="text" class="form-control" name="judul" required autofocus />
  122.                   </div>
  123.                   <div class="form-group">
  124.                     <textarea class="wysiwyg" name="isi" placeholder="Isikan konten berita di sini ..." required></textarea>
  125.                   </div>
  126.                   <div class="row">
  127.                     <div class="col-xs-5">
  128.                       <label>Gambar</label>
  129.                       <input type="file" accept=".jpg" name="gambar" class="form-control" />
  130.                       <span class="help-block">Gunakan gambar dengan ekstensi *.JPG</span>
  131.                     </div>
  132.                     <div class="col-xs-7">
  133.                       <label>Label</label>
  134.                       <input type="text" name="label" class="form-control" required />
  135.                     </div>
  136.                   </div>
  137.                 </div><!-- /.box-body -->
  138.                 <div class="box-footer">
  139.                   <button type="submit" name="simpan-berita" class="btn btn-info"><i class="fa fa-check"></i> &nbsp; Simpan</button>
  140.                   <button type="reset" class="btn btn-default"><i class="fa fa-repeat"></i> &nbsp; Ulangi</button>
  141.                 </div>
  142.               </form>
  143.  
  144.             </div><!-- /.box -->
  145.           </div><!-- /.col -->
  146.         </div>
  147.         <!-- /.row -->
  148.  
  149.       </section><!-- /.content -->
  150.     </aside><!-- /.right-side -->
  151.   </div><!-- ./wrapper -->
  152.  
  153.   <!-- add new calendar event modal -->
  154.  
  155.   <!-- jQuery 2.0.2 -->
  156.   <script src="js/jquery.min.js"></script>
  157.   <!-- jQuery UI 1.10.3 -->
  158.   <script src="js/jquery-ui-1.10.3.min.js" type="text/javascript"></script>
  159.   <!-- Bootstrap -->
  160.   <script src="js/bootstrap.min.js" type="text/javascript"></script>
  161.   <!-- AdminLTE App -->
  162.   <script src="js/AdminLTE/app.js" type="text/javascript"></script>
  163.  
  164.   <!-- InputMask -->
  165.   <script src="js/plugins/input-mask/jquery.inputmask.js" type="text/javascript"></script>
  166.   <script src="js/plugins/input-mask/jquery.inputmask.date.extensions.js" type="text/javascript"></script>
  167.   <script src="js/plugins/input-mask/jquery.inputmask.extensions.js" type="text/javascript"></script>
  168.   <!-- Bootstrap WYSIHTML5 -->
  169.   <script src="js/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js" type="text/javascript"></script>
  170.  
  171.   <!-- Inline Scripts -->
  172.   <script type="text/javascript">
  173.     /* wysiwyg */
  174.     $(".wysiwyg").wysihtml5({
  175.       "font-styles": true,
  176.       "emphasis": true,
  177.       "lists": true,
  178.       "html": false,
  179.       "link": false,
  180.       "image": false,
  181.       "color": true
  182.     });
  183.   </script>
  184. </body>
  185. </html>
  186.  
  187. <?php
  188. } else {
  189.   header('location:login.php');
  190. }
  191. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement