
<?php
 
    $jsonAdmin = json_decode($_SESSION['fideliza_logado-admin']);
    
    $id        = $jsonAdmin->ad_id;
    
 
	$select_db->ExeRead("*",  'fd_moderadores', " WHERE ad_ref = $id  ORDER BY ad_id DESC", "");

?>

<div class="col-md-12">
<div class="row" style="background-color: #e8e8e8; margin-bottom: 15px">
            <div class="col-md-9">
                <h1 style="margin: 0">
                    <i class="fa fa-gift color1"></i>
                    Prêmios Disponíveis
                </h1>
            </div>
            	<div class="col-md-3" style="margin-top:10px">
			<button type="button" class="simple-btn" onclick="TerminalAdmin.dashboard();">Voltar</button>
		</div>
     </div>
</div>

        <table class="table table-striped">
        <thead>
            <tr>
                <th style="width: 150px">Nome</th>
                <th>Login</th>
                <th>Permissão</th>
                <th>Opções</th>
            </tr>
        </thead>
        <tbody id="listar_terminal">
      
      <?php
	  		
		$array_perm = array(
        '1' => 'Pontos',
        '2' => 'Prémios',
        '3' => 'Clientes',
        '4' => 'Resgate',
		'5' => 'Parametrização');
		$perm = '';
			
	  for($i=0;$i<count($select_db->getResult());$i++){
		  
	
		  $permissao = explode(',', $select_db->getResult()[$i]['permissao']);
		  
		  for($e=1;$e<count($permissao)+1;$e++){

		    $perm .= $array_perm[$permissao[$e-1]] . ', ';
			    
		  }
			 
		  echo '<tr class="pre_'.$select_db->getResult()[$i]['ad_id'].'"><td>'.$select_db->getResult()[$i]['ad_name'].'</td><td>'.$select_db->getResult()[$i]['ad_login'].'</td><td>'. $perm .'</td><td><a href="javascript:void(0);" onclick="editar_moderador('.$select_db->getResult()[$i]['ad_id'].')" class="btn btn-warning">Editar</a> <a href="javascript:void(0)" onclick="excluir_moderador('.$select_db->getResult()[$i]['ad_id'].')" class="btn btn-danger">Excluir</a></td></tr>';
		  
	  }
	  
	  ?>
      
      <script type="text/javascript">
	
		  function editar_moderador(id){
			  		
	      $('#load-ajax').load(BASE_URL + '?terminal-admin-ajax=moderador-editar&id='+id);  
			  
		  }
		  
		  
		  function excluir_moderador(id){
			  
			  c = confirm('Tem certeza que deseja deletar esse Moderador?');
			  
			  if(c){
				  
				  tr = '.pre_' + id;
				  
		$.ajax({
            type:   'GET',
             url:    BASE_URL,
             data:   'moderador-deletar=' + id,
             success: function(d){
				   alert(d);
                   $(tr).hide(500);
            }
        }); 
				  
				    
			  }
			  
		  }
		
	</script>
      
        </tbody>
  <table>



