<?php

	include('public/functions.php');

  $qry = "SELECT * FROM menuapp_config WHERE id = '1' ";
  $result = mysqli_query($connect, $qry);
  $row_result = mysqli_fetch_assoc($result);

  switch ($_GET['local']) {
    case 'tv':
      $link = "tv_link";
      $status = "tv_status";
    break;
	case 'radio':
      $link = "radio_link";
      $status = "radio_status";
    break;
	case 'programacao':
      $link = "programacao_link";
      $status = "programacao_status";
    break;
	case 'noticias':
      $link = "noticias_link";
      $status = "noticias_status";
    break;
    	case 'equipe':
      $link = "equipe_link";
      $status = "equipe_status";
    break;
	case 'promocoes':
      $link = "promocao_link";
      $status = "promocao_status";
    break;
	case 'recados':
      $link = "recados_link";
      $status = "recados_status";
    break;	
	case 'whatsapp':
      $link = "whatsapp_link";
      $status = "whatsapp_status";
    break;
    case 'site':
      $link = "site_link";
      $status = "site_status";
    break;
    case 'facebook':
      $link = "facebook_link";
      $status = "facebook_status";
    break;
    case 'twitter':
      $link = "twitter_link";
      $status = "twitter_status";
    break;
    case 'instagram':
      $link = "instagram_link";
      $status = "instagram_status";
    break;
     case 'youtube':
      $link = "youtube_link";
      $status = "youtube_status";
    break;
    
    default:
      # code...
      break;
  }

	if(isset($_POST['submit'])) {

  		$data = array(
          $link => $_POST['link'],
          $status => $_POST['status']
  		);

  		$result = Update('menuapp_config', $data, " WHERE id = '1' ");
  		
			$_SESSION['msg'] = "Dados alterados com êxito!.";
      header( "Location:menuapp.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">Menu app</h5>
                  <ol class="breadcrumb">
                    <li><a href="dashboard.php">Dashboard</a>
                    </li>
                    <li><a class="active">Configuração do app</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="card-panel">
                        <h5>Local: <?php echo $_GET['local']; ?></h5>
                          <form method="post" enctype="multipart/form-data">
                              <div class="row">

                                  <?php if(isset($_SESSION['msg'])) { ?>
                                  <div class='card-panel teal lighten-2'>
                                      <span class='white-text text-darken-2'><?php echo $_SESSION['msg'] ?></span>
                                  </div>

                                  <?php unset($_SESSION['msg']); }?>
                                  
                                  <div class="col s12 m12 l12">
                                      <div class="input-field col s12 l6">
                                          <label>Link :</label>
                                          <br>
                                          <input type="text" name="link" value="<?php echo $row_result[$link] ?>" placeholder="Link" />
                                      </div>
                                  </div>

                                  <div class="col s12 m12 l12">
                                      <div class="input-field col s12 l6">
                                          <label>Status :</label>
                                          <br><br>
                                          <select name="status">
                                            <option <?php echo ($row_result[$status]=="desativado")?"selected":""; ?> value="desativado">Desativar</option>
                                            <option <?php echo ($row_result[$status]=="ativado")?"selected":""; ?> value="ativado">Ativar</option>
                                          </select>
                                      </div>
                                  </div>

                                  <div class="input-field col s12"><br>
                                      <button type="submit" name="submit" class="btn cyan waves-effect waves-light">Alterar</button>
                                  </div>

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

                  </div>

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

</section>
