<?php

$id = $_GET['id'];
$jsonAdmin = json_decode($_SESSION['fideliza_logado-admin']);
$level     = $jsonAdmin->ad_level;
$ref        = $jsonAdmin->ad_id;

    /* Editar Premio */
	$select_db->ExeRead("*",  'fd_moderadores', " WHERE ( ad_id = :i AND ad_ref = :r)", "i={$id}&r={$ref}");

?>
   
<div class="col-md-12">
<div style="margin-top:40%;" >	
   
        <div class="login-box box-cadastro"  style=" background:#fff">

            <form action="" method="post"  id="form2">
                <input type="text" name="usu_nome" id="usu_nome" placeholder="Nome" value="<?php echo $select_db->getResult()[0]['ad_name']; ?>" />
                <input type="text" name="usu_login" id="usu_login" placeholder="Login" value="<?php echo $select_db->getResult()[0]['ad_login']; ?>" />
                <input type="password" name="usu_senha" id="usu_senha" placeholder="Senha" value="<?php echo $select_db->getResult()[0]['ad_senha']; ?>"/>
                               
                 <label>Defina permissões ao Moderador</label>
                              
                              <?php
				
				$permissoes = explode(',', $select_db->getResult()[0]['permissao']);
				
				echo '<script> 
				
				window.setTimeout(function(){ ';
		
				for($i=0;$i<count($permissoes);$i++){
					

					echo ' 
					
					jQuery(".activeBox'.$permissoes[$i].'").attr("checked","checked");
					
					';
					
				}
					
				echo '}, 600); </script>'
				
				?>
                               
                               <span><input type="checkbox" class="checkboxClass activeBox1" value="1">Pontos</span>&nbsp;&nbsp;
                                 <span><input type="checkbox" class="checkboxClass activeBox2" value="2">Prémios</span>
                                  <span><input type="checkbox" class="checkboxClass activeBox4" value="4">Resgate</span><br>
<span><input class="checkboxClass activeBox3" type="checkbox" value="3">Clientes</span>&nbsp;&nbsp;<span><input class="checkboxClass activeBox5" type="checkbox" value="5">Parametrização</span>
                                <br>
                                
                                <input type="hidden" name="permissao-select" id="permissao-select" value="<?php echo $select_db->getResult()[0]['permissao']; ?>" />
                                
<br>

                <input type="hidden" name="editar-db-moderador" value="<?php echo $select_db->getResult()[0]['ad_id']; ?>" />
                <button
                    type="button"
                    style="width: 100%; height: 50px"
                    onclick="LoginCadastroModerador.cadastro()">Alterar</button>
            </form>
 
        </div>
	
     </div>
</div>
    
<script type="text/javascript">
 

$(".checkboxClass").click(function(){
  var selectedCountry = new Array();
  $(".checkboxClass:checked").each(function(){
    selectedCountry.push($(this).val());
  });
  $("#permissao-select").val(selectedCountry.join(','));
});	
		
LoginCadastroModerador = {
	
	cadastro : function(){
	
usu_nome  = jQuery('#usu_nome').val();
usu_login = jQuery('#usu_login').val();
usu_senha = jQuery('#usu_senha').val();
		
		if(usu_nome == ''){
			
			alert('Nome Obrigatório!');
			
		}else if(usu_login == ''){
			
			alert('Login Obrigatório!');
			
	    }else if(usu_senha == ''){
			
			alert('Senha Obrigatório!');
					
		}else{
			

		$.ajax({
            type:   'POST',
             url:    BASE_URL,
             data:   $('#form2').serialize(),
             success: function(d){

                if (d == 'Cadadstro alterado com sucesso!') {
					alert(d);
                  TerminalAdmin.ListarModerador()
                } else {
					alert(d);
				}

            }
        });
		

			
		}
		
	}

}

</script>
  
