
<?php

	include('public/functions.php');

  $qry = "SELECT * FROM tbl_onesignal WHERE id = '1'";
  $result = mysqli_query($connect, $qry);
  $result_row = mysqli_fetch_assoc($result);
  
	if(isset($_POST['submit'])) {

        $data = array(
          'onesinal_app_id' => $_POST['onesinal_app_id'],
          'rest_api_key' => $_POST['rest_api_key']
        );
        
        $result_id = Update('tbl_onesignal', $data, "WHERE id = '1'");
  		
  		if ($result_id > 0) {
  			$_SESSION['msg'] = "Key/ID alterados com êxito!";
              header( "Location:onesignal.php");
              exit;
  		}		
 	}

?>

<!-- START CONTENT -->
<section id="content">

      <!--breadcrumbs start-->
      <div id="breadcrumbs-wrapper" class="grey lighten-3">
          <div class="container">
            <div class="row">
                <div class="col s12 m12 l12">
                  <h5 class="breadcrumbs-title">Configuracões One Signal</h5>
                  <ol class="breadcrumb">
                    <li><a href="dashboard.php">Principal</a>
                    </li>
                    <li><a class="active">One Signal Key & ID</a>
                    </li>
                  </ol>
                </div>
            </div>
          </div>
      </div>
      <!--breadcrumbs end-->

     <!--start container-->
      <div class="container">
          <div class="section">
              <div class="row">
                  <div class="col s12 m12 l12">  

                          <div class="col s12 m12 l6">
                              <?php if(isset($_SESSION['msg'])) { ?>
                          <div class='card-panel teal' id="aviso">
                              <span class='white-text text-darken-2'><?php echo $_SESSION['msg'] ?></span>
                          </div>

                          <?php unset($_SESSION['msg']); }?>
                            <div class="card-panel">
		                	<div class="row">
		                 		<form method="post" class="col s12">
		                  			<div class="row">
		                    			<div class="input-field col s12">
											<div class="row">
						                      <div class="input-field col s12">
						                      	<label for="onesinal_app_id">One Signal ID</label>
						                        <input type="text" name="onesinal_app_id" placeholder="8250eaf6-1a58-489e-b136-7c74a864b434" id="onesinal_app_id" value="<?php echo $result_row['onesinal_app_id']; ?>" />
						                      </div>
						                    </div>

											<div class="row">
						                      <div class="input-field col s12">
						                      	<label for="rest_api_key">Rest Api Key</label>
												<input type="text" name="rest_api_key" placeholder="NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj" id="rest_api_key" value="<?php echo $result_row['rest_api_key']; ?>" />
						                      </div>
                                            </div>
                                
											<button class="btn cyan waves-effect waves-light right" type="submit" name="submit" style="border-radius:7px;">Atualizar
						                        <i class="mdi-content-save left"></i>
						                    </button>

						                </div>
						            </div>
						        </form>
						    </div>
						</div>
                              
                          </div>
                      </div>

                  </div>

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

</section>
<script>
  $().ready(function() {
  setTimeout(function () {
  $('#aviso').hide(); // "aviso" é o id do elemento que seja manipular.
  }, 5500); // O valor é representado em milisegundos.
  });
</script>