<?php
defined("BASEPATH") or exit("No direct access allowed");
if (isset($_POST['ubah'])){
    
    $key = mysqli_real_escape_string($con,$key);
    $pesan1 = mysqli_real_escape_string($con,$pesan1);
    $status1 = mysqli_real_escape_string($con,$status1);
    $namafolder="images/"; 
    If (empty($_FILES["filegbr"]["tmp_name"])){
        
            //simpan
                mysqli_query($con,"update notifwa set key1='$key', pesan1='$pesan1', status1='$status1'  where id=1");
                echo '
                <script>
                	swal("Good Job","Anda sukses menyimpan","success");
                </script>
        		';
    		
    } else {    
        $key = mysqli_real_escape_string($con,$key);
        $pesan1 = mysqli_real_escape_string($con,$pesan1);
        $jenis_gambar=$_FILES['filegbr']['type'];
        if($jenis_gambar=="image/jpeg" || $jenis_gambar=="image/jpg" || $jenis_gambar=="image/gif" || $jenis_gambar=="image/png"){
            
            $logo = $namafolder . basename($_FILES['filegbr']['name']);
            
            if (move_uploaded_file($_FILES['filegbr']['tmp_name'], $logo)) {
            
                //simpan
                mysqli_query($con,"update notifwa set gambar1='$logo', key1='$key', pesan1='$pesan1', status1='$status1'    where id=1");
                echo '
                <script>
                	swal("Good Job","Anda sukses menyimpan","success");
                </script>
        		';
            } else {
                echo '
                <script>
                	swal("Good Error","Gambar gagal diupload","error");
                </script>
        		';
            }
        }else {
            echo '
            <script>
            	swal("Good Error","Jenis gambar yang anda diupload salah. Harus .jpg .png","error");
            </script>
    	  	';
        }
     
    }

        echo '
		<!-- <div class="alert alert-success alert-dismissable" style="margin-top:20px">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
            <h4><i class="icon glyphicon glyphicon-remove"></i> Anda sukses menyimpan setting.</div> -->
		';
        
   
}

if (isset($_POST['ubah2'])){
    
    $appid = mysqli_real_escape_string($con,$appid);
    $csid = mysqli_real_escape_string($con,$csid);
    $pesan2 = mysqli_real_escape_string($con,$pesan2);
    $status2 = mysqli_real_escape_string($con,$status2);
        
            //simpan
                mysqli_query($con,"update notifwa set appid='$appid', csid='$csid', pesan2='$pesan2', status2='$status2'  where id=1");
                echo '
                <script>
                	swal("Good Job","Anda sukses menyimpan","success");
                </script>
        		';
}

$data=mysqli_fetch_row(mysqli_query($con,"select * from notifwa where id=1"));

?>
    <style>
        #image-holder {
            margin-top: 8px;
        }
        
        #image-holder img {
            border: 8px solid #DDD;
            max-width:100%;
        }
    </style>
    
   <div class="card-header">
          
          <nav aria-label="breadcrumb">
                      <ol class="breadcrumb bg-warning text-white-all">
                        <li class="breadcrumb-item"><a href="#"><i class="fas fa-tachometer-alt"></i> Home</a></li>
                        <li class="breadcrumb-item"><a href="#"><i class="far fa-file"></i> Notif</a></li>
                        <li class="breadcrumb-item active" aria-current="page"><i class="fas fa-list"></i>WA</li>
                      </ol>
                    </nav>
          </div>

            
              <a class="nav-link dropdown-toggle" href="#" id="pagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <img src="images/warotator.png">
                <span>Notifikasi WA</span>
              </a>
              <div class="dropdown-menu" aria-labelledby="pagesDropdown">
                <h6 class="dropdown-header">Sub Menu:</h6>
                <a class="dropdown-item" href="index.php?page=notif&set=woowaserver"><img src="images/api.png"> Woowa Server</a>
                <a class="dropdown-item" href="index.php?page=notif&set=woowaandroid"><img src="images/WA.jpg" width="16"> Woowa Android</a>
              </div>
            
         
            
            <?php
            IF($_GET['set']=='woowaserver'){
            ?>
                <div class="card-body">
                       
                       <div class="alert alert-primary alert-has-icon p-4">
                <div class="alert-icon"><i class="far fa-lightbulb"></i></div>
                <div class="alert-body">
                <div class="alert-title">Petunjuk:</div>
                1. Daftar dan login di layanan <a href="https://woo-wa.com/" target="_blank"><b>Woowa Server</b></a>.<br>
                2. Input Key.<br>
                3. Upload gambar anda.
                </div>
                </div>
                
                 
                    <form action="" method="POST" enctype="multipart/form-data"> 
    
                            <div class="form-group">
                                
                                <?php  
                                    
                                         if($data[4]==0) {
                                              $ktw = 'Tidak Aktif';
                                         }else{
                                              $ktw = 'Aktif';
                                         }     
                                         echo "
                                         <label for='tiga' class='col-sm-2 control-label'>Status</label>
                                         <select name='status1' class='form-control'>
                                         <option value=$data[4]>$ktw</option>
                                         <option value='0'>Tidak Aktif</option>
                                         <option value='1'>Aktif</option>
                                            </select> 
                                         ";
    
                                        ?>
                                        
                                <label for="tiga" class="col-sm-2 control-label">Key</label>
                                <input type="text" class="form-control" name="key"  value="<?php echo $data[1]; ?>" required>
                                <label for="tiga" class="col-sm-2 control-label">Gambar</label>
                                <div class="col-sm-10">
                                    <img class="img-rounded" src="<?php echo $data[3]; ?>" width="250"><br>
                                    <input type='file' name='filegbr' id='Filegambar'>
                                </div>
                                <label for='tiga' class='col-sm-6 control-label'>Pesan pertama yang diterima Subsriber</label>
                                    <div class='col-sm-10'>
                                        <textarea name="pesan1" cols="20" class='ckeditor' required>
                                            <?php echo $data[2]; ?> 
                                           </textarea>
                                    </div>
                            </div>
                        
                            <div class="form-group">
                              <div class  ="col-sm-4">
                                <button type="submit" class="btn btn-primary" name="ubah"><span class="glyphicon glyphicon-pencil"></span> Simpan</button>
                              </div>
                            </div>
    
                    </form>
                </div>
            <?php } ?>
            <?php
            IF($_GET['set']=='woowaandroid'){
            ?>
                <div class="card-body">
                       
                       <div class="alert alert-primary alert-has-icon p-4">
                <div class="alert-icon"><i class="far fa-lightbulb"></i></div>
                <div class="alert-body">
                <div class="alert-title">Petunjuk:</div>
                1. Buka dan Jalankan Apliksi Woowaandroid anda. <br>
                2. Cek App Id dalam akun Woowa anda kemudian input atau masukkan App ID <b>429d3472-da0f-4b2b-a63e-4644050caf8f</b><br>
                3. Cek CS Id anda pada aplikasi Woowaandroid, seperti <a href="https://i.ibb.co/8z4mgd6/get-cs-id-player-id.jpg" target="_blank"><b>Gambar ini</b></a>.
                </div>
                </div>
                
                 
                    <form action="" method="POST" enctype="multipart/form-data"> 
    
                            <div class="form-group">
                                
                                <?php  
                                    
                                         if($data[8]==0) {
                                              $ktw = 'Tidak Aktif';
                                         }else{
                                              $ktw = 'Aktif';
                                         }     
                                         echo "
                                         <label for='tiga' class='col-sm-2 control-label'>Status</label>
                                         <select name='status2' class='form-control'>
                                         <option value=$data[8]>$ktw</option>
                                         <option value='0'>Tidak Aktif</option>
                                         <option value='1'>Aktif</option>
                                            </select> 
                                         ";
    
                                        ?>
                                        
                                <label for="tiga" class="col-sm-6 control-label">App ID</label>
                                <input type="text" class="form-control" name="appid"  value="<?php echo $data[5]; ?>" required>
                                <label for="tiga" class="col-sm-6 control-label">CS ID</label>
                                <input type="text" class="form-control" name="csid"  value="<?php echo $data[6]; ?>" required>
                                <label for='tiga' class='col-sm-6 control-label'>Pesan Demo Test Ngirim WA<br>
                                <i>Bisa Tambahkan tag: [nama],dan [hp]</i></label>
                        		<p><textarea class="form-control" name="pesan2" rows="2" cols="50"><?php echo $data[7]; ?> </textarea></p>
                                   
                            </div>
                        
                            <div class="form-group">
                              <div class  ="col-sm-4">
                                <button type="submit" class="btn btn-primary" name="ubah2"><span class="glyphicon glyphicon-pencil"></span> Simpan</button>
                              </div>
                            </div>
    
                    </form>
                </div>
            <?php } ?>
      
    