<?php 

/* SAIR */
if(isset($get['admin-logout'])){

$_SESSION['fideliza_logado-admin'] = null;
sleep(1);
header('Location: ' . dominio);
exit;
	
}


function current_data_mysql($date, $hora = false){
			
	//Converter a data MySQL em um objeto DateTime
    $dataHoraMySQL = $date;
	
	if($hora == false){
	return   date("d/m/Y", strtotime($dataHoraMySQL));
	}else{
	return date("d/m/Y H:i:s", strtotime($dataHoraMySQL));	
	}
			
}


//Cadastro ou Update Eventos		
if(isset($post['admin-post-cadastro-evento']) && isset($_SESSION['fideliza_logado-admin'])){
		
        header('Content-Type: application/json');
		
		$nome   = $post['nome']; 
		$grup   = $post['grup'];
		$status = $post['status'];
		$data   = $post['data'];
		$users  = $post['users'];
		$metodo = $post['admin-post-cadastro-evento'];
		
	   $select_db = $parametros_response['select_db'];
	   $select_db->ExeRead(" * ",  'pd_eventos', " WHERE nome = :n AND grup = :g ", "n={$nome}&g={$grup}");
		
		if($metodo != 'insert'){
			
				$prepared_insert_array = [ 
							   'nome'     => $nome,
							   'grup'     => $grup,
							   'status'   => $status,
							   'data'     => $data,
							   'users'    => $users];	
							   
			$updateSiteViews = new Core_update;	
            $updateSiteViews->ExeUpdate('pd_eventos', $prepared_insert_array, "WHERE id = :id ", "id={$metodo}");			
	
			   
	if($updateSiteViews->getResult()){	
	
$resultados = array('result'  => 'success', 
'msg' => 'Evento alterado com sucesso!');
echo json_encode($resultados);
exit;	
	
}else{
	
$resultados = array('result'  => 'error', 
'msg' => 'Erro ao tentar fazer o alteração!');
echo json_encode($resultados);
exit;

}							   
			
			
		}else if (!$select_db->getResult()){
				
			$prepared_insert_array = [ 
							   'nome'     => $nome,
							   'grup'     => $grup,
							   'status'   => $status,
							   'data'     => $data,
							   'users'    => $users];		   
							 				   				
$createSiteViews = new Core_create;	
$createSiteViews->ExeCreate('pd_eventos', $prepared_insert_array);
			
if($createSiteViews->getResult()){
	
$resultados = array('result'  => 'success', 
'msg' => 'Evento cadastrado com sucesso!');
echo json_encode($resultados);
exit;	
	
}else{
	
$resultados = array('result'  => 'error', 
'msg' => 'Erro ao tentar fazer o cadastro!');
echo json_encode($resultados);
exit;

}

			
			}else{
			
$resultados = array('result'  => 'error', 
'msg' => 'Parece que você ja fez esse cadastro!');
echo json_encode($resultados);
exit;			
				
			}
								
		exit;
		
	}

//Cadastro ou Update Participantes		
if(isset($post['admin-post-cadastro-participante']) && isset($_SESSION['fideliza_logado-admin'])){
		
        header('Content-Type: application/json');
		
		
		$nome     = $post['nome']; 
		$senha    = md5($post['senha']);
		$login    = $post['login'];
		$grupo    = $post['grupo'];
		$status   = $post['status'];
		
		$data    = date("d/m/Y");

		$metodo  = $post['admin-post-cadastro-participante'];
		
	   $select_db = $parametros_response['select_db'];
	   $select_db->ExeRead(" * ",  'pd_participante', " WHERE login = :n AND senha = :s ", "n={$login}&s={$senha}");
		
		if($metodo != 'insert'){
			
			if (!$select_db->getResult() && $senha == $select_db->getResult()[0]['senha']){
				
$resultados = array('result'  => 'error', 
'msg' => 'Já existe um mesmo usuario cadastrado!');
echo json_encode($resultados);
exit;
	
				
			}else{
			
				$prepared_insert_array = [ 
							   'nome'     => $nome,
							   'login'    => $login,
							   'senha'    => $senha,
							   'data'     => $data,
							   'grupo'    => $grupo,
							   'status'   => $status];	
							   
			$updateSiteViews = new Core_update;	
            $updateSiteViews->ExeUpdate('pd_participante', $prepared_insert_array, "WHERE id = :id ", "id={$metodo}");

			   
	if($updateSiteViews->getResult()){	
	
$resultados = array('result'  => 'success', 
'msg' => 'Participante alterado com sucesso!');
echo json_encode($resultados);
exit;	
	
}else{
	
$resultados = array('result'  => 'error', 
'msg' => 'Erro ao tentar fazer o alteração!');
echo json_encode($resultados);
exit;

}							   
			

			}			
				
		}else if (!$select_db->getResult()){
				
	$prepared_insert_array = [ 
							   'nome'     => $nome,
							   'login'    => $login,
							   'senha'    => $senha,
							   'data'     => $data,
							   'grupo'    => $grupo,
							   'status'   => $status];		   
							 				   				
$createSiteViews = new Core_create;	
$createSiteViews->ExeCreate('pd_participante', $prepared_insert_array);
			
if($createSiteViews->getResult()){
	
$resultados = array('result'  => 'success', 
'msg' => 'Participante cadastrado com sucesso!');
echo json_encode($resultados);
exit;	
	
}else{
	
$resultados = array('result'  => 'error', 
'msg' => 'Erro ao tentar fazer o cadastro!');
echo json_encode($resultados);
exit;

}

			
			}else{
			
$resultados = array('result'  => 'error', 
'msg' => 'Parece que você ja fez esse cadastro!');
echo json_encode($resultados);
exit;			
				
			}
								
		exit;
		
	}


//Deletar Eventos
if(isset($get['deletar-eventos']) &&  isset($_SESSION['fideliza_logado-admin'])){
	
	     header('Content-Type: application/json');
	
	$id = $get['deletar-eventos'];
	
	$Delete = new Core_delete;
    $Delete->ExeDelete('pd_eventos', "WHERE id = :i", "i={$id}");	
		
	if($Delete->getResult()){
		
$resultados = array('result'  => 'success', 
'msg' => 'Evento deletado com sucesso!');
echo json_encode($resultados);
exit;
		
	}else{
		
$resultados = array('result'  => 'error', 
'msg' => 'Erro ao tentar deletar Evento!');
echo json_encode($resultados);
exit;

	}
	
}
		
		
//Deletar Participantes
if(isset($get['deletar-participante']) &&  isset($_SESSION['fideliza_logado-admin'])){
	
	header('Content-Type: application/json');
	
	$id = $get['deletar-participante'];
	
	$Delete = new Core_delete;
    $Delete->ExeDelete('pd_participante', "WHERE id = :i", "i={$id}");	
		
	if($Delete->getResult()){
		
$resultados = array('result'  => 'success', 
'msg' => 'Participante deletado com sucesso!');
echo json_encode($resultados);
exit;
		
	}else{
		
$resultados = array('result'  => 'error', 
'msg' => 'Erro ao tentar deletar o Participante!');
echo json_encode($resultados);
exit;

	}
	
}
		
		

		
		
			
		
// Editar ou Visualizar - Eventos		
if(isset($get['editar-eventos'])  &&  isset($_SESSION['fideliza_logado-admin'])){
		
$id        = $get['editar-eventos'];

$select_db = $parametros_response['select_db'];
$select_db->ExeRead(" * ",  ' pd_eventos', " WHERE id = :id", "id={$id}");

$nome   = $select_db->getResult()[0]['nome'];
$status = $select_db->getResult()[0]['status'];
$data   = $select_db->getResult()[0]['data'];
$login  = $select_db->getResult()[0]['login'];
$grup   = $select_db->getResult()[0]['grup'];
$users  = explode(',', $select_db->getResult()[0]['users']);

if($status == 0){	   
$update_status_input = '<input type="checkbox" name="status" checked data-toggle="toggle" id="cadastro_status" value="0" data-on="Não" data-off="Sim" data-onstyle="danger" data-offstyle="success">';
}else{
$update_status_input = '<input type="checkbox" name="status" checked data-toggle="toggle" id="cadastro_status" value="1" data-on="Sim" data-off="Não" data-onstyle="success" data-offstyle="danger">';	
}

$select_db = $parametros_response['select_db'];
$select_db->ExeRead(" * ",  'pd_grups', "", "");

    $list_grup = '<option value="'.$grup.'">'.$grup.'</option>';

	for($i=0;$i<count($select_db->getResult());$i++){
		
	$list_grup .= '<option value="'.$select_db->getResult()[$i]['nome'].'">'.$select_db->getResult()[$i]['nome'].'</option>';
	
	}
	
	$select_db = $parametros_response['select_db'];	
	$select_db->ExeRead(" * ",  'pd_participante', "ORDER BY id DESC", "");
    $list_participantes = '';
	$parnome = [];
	
	
for($i=0;$i<count($select_db->getResult());$i++){
	
$parnome[$select_db->getResult()[$i]['id']] = $select_db->getResult()[$i]['nome'];
	
$list_participantes .= '
<tr id="hide_participante'.$select_db->getResult()[$i]['id'].'" >
<td>'.$select_db->getResult()[$i]['nome'].'</td>
<td>'.$select_db->getResult()[$i]['senha'].'</td>
<td><a href="javascript:voip()" onclick="add_user'.$select_db->getResult()[$i]['id'].'()"><i class="pe-7s-plus" style="font-size: 18px;"></i></a></td>
</tr>

<script>

function add_user'.$select_db->getResult()[$i]['id'].'(){
	
	nome = "'.$select_db->getResult()[$i]['nome'].'";
    id   = "'.$select_db->getResult()[$i]['id'].'";
	
	escolhido = jQuery("#evento_escolhidos").html();
	
	links = "<span data-id='.$select_db->getResult()[$i]['id'].' class=selectparticipante>'.$select_db->getResult()[$i]['nome'].'</span>";
	
	jQuery("#evento_escolhidos").html(escolhido + links);
	
	remove_selecionado();
	
	jQuery("#hide_participante'.$select_db->getResult()[$i]['id'].'").hide();
	
}

</script>';

}


	$listagem_escolhidos = '';
	
	for($e=0; $e<count($users);$e++){
		
		if(isset($users[$e]) && isset($parnome[$users[$e]])){
	$listagem_escolhidos .= '<span data-id="'.$users[$e].'" class="selectparticipante">'.$parnome[$users[$e]].' <i class="pe-7s-close-circle"> </i></span>
	<script> window.setTimeout(function(){ jQuery("#hide_participante'.$users[$e].'").hide(); }, 1000); </script>';
		}
	
	}
	
	$listagem_escolhidos .= '<script> window.setTimeout(function(){ remove_selecionado(); }, 1000); </script>';
	
	$a[] = '{cadastro_type}';   $b[]  = '';
	$a[] = '{update_nome}';     $b[]  = $nome;
	$a[] = '{update_login}';    $b[]  = $login;
	$a[] = '{update_data}';     $b[]  = $data;
	$a[] = '{update_status_input}';   $b[] = $update_status_input;
	$a[] = '{label_next}';      $b[]  = 'ALTERAR';
	$a[] = '{update_grup}';     $b[]  = $list_grup;
	$a[] = '{metodo_evento}';   $b[]  = $id; 
	$a[] = '{listagem_escolhidos}'; $b[] = $listagem_escolhidos;
	$a[] = '{admin_select_participantes}'; $b[] = $list_participantes;
	

}else if($parametros_get_page['pag_name'] == 'Admin - Eventos' && isset($_SESSION['fideliza_logado-admin'])){

	   $select_db = $parametros_response['select_db'];
	   $select_db->ExeRead(" * ",  'pd_grups', "", "");

    $list_grup = '';

	for($i=0;$i<count($select_db->getResult());$i++){
		
	$list_grup .= '<option value="'.$select_db->getResult()[$i]['nome'].'">'.$select_db->getResult()[$i]['nome'].'</option>';
	
	}
	
	$select_db = $parametros_response['select_db'];	
	$select_db->ExeRead(" * ",  'pd_eventos', "", "");
    $list_eventos = '';
	  
for($i=0;$i<count($select_db->getResult());$i++){
		
$list_eventos .= '
<tr>
<td>'.$select_db->getResult()[$i]['nome'].'</td>
<td>'.$select_db->getResult()[$i]['grup'].'</td>
<td>'.$select_db->getResult()[$i]['data'].'</td>
<td>'.$select_db->getResult()[$i]['status'].'</td>
<td><div class="d-inline-block dropdown">
<button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn-shadow dropdown-toggle btn btn-info">
<span class="btn-icon-wrapper pr-2 opacity-7">
<i class="nav-link-icon lnr-user"></i>
</span>
Opções
</button>
<div tabindex="-1" role="menu" aria-hidden="true" class="dropdown-menu dropdown-menu-right" style="">
<ul class="nav flex-column">

<li class="nav-item">
<a class="nav-link editar_user"  data-id="'.$select_db->getResult()[$i]['id'].'">
<i class="nav-link-icon lnr-user"></i>
<span> Editar</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link deletar_user" data-id="'.$select_db->getResult()[$i]['id'].'">
<i class="nav-link-icon lnr-trash"></i>
<span> Deletar</span>
</a>
</li>
</ul>
</div>
</div></td>
</tr>';

}


	$select_db = $parametros_response['select_db'];	
	$select_db->ExeRead(" * ",  'pd_participante', "ORDER BY id DESC", "");
    $list_participantes = '';
	  
for($i=0;$i<count($select_db->getResult());$i++){
		
$list_participantes .= '
<tr id="hide_participante'.$select_db->getResult()[$i]['id'].'" >
<td>'.$select_db->getResult()[$i]['nome'].'</td>
<td>'.$select_db->getResult()[$i]['senha'].'</td>
<td><a href="javascript:voip()" onclick="add_user'.$select_db->getResult()[$i]['id'].'()"><i class="pe-7s-plus" style="font-size: 18px;"></i></a></td>
</tr>

<script>

function add_user'.$select_db->getResult()[$i]['id'].'(){
	
	nome = "'.$select_db->getResult()[$i]['nome'].'";
    id   = "'.$select_db->getResult()[$i]['id'].'";
	
	escolhido = jQuery("#evento_escolhidos").html();
	
	links = "<span data-id='.$select_db->getResult()[$i]['id'].' class=selectparticipante>'.$select_db->getResult()[$i]['nome'].'</span>";
	
	jQuery("#evento_escolhidos").html(escolhido + links);
	
	remove_selecionado();
	
	jQuery("#hide_participante'.$select_db->getResult()[$i]['id'].'").hide();
	
}

</script>';

}

	$a[] = '{cadastro_type}';   $b[] = '';
	$a[] = '{update_nome}';     $b[] = '';
	$a[] = '{update_login}';    $b[]  = '';
	$a[] = '{update_status_input}'; $b[] = '<input type="checkbox" name="status" checked data-toggle="toggle" id="cadastro_status" value="1" data-on="Sim" data-off="Não" data-onstyle="success" data-offstyle="danger">';
	$a[] = '{label_next}';      $b[]  = 'CADASTRAR';
	$a[] = '{update_grup}';     $b[]  = $list_grup;
	$a[] = '{metodo_evento}';   $b[]  = 'insert'; 
	$a[] = '{listagem_escolhidos}'; $b[] = '';
	
    $a[] = '{admin_eventos_listar}';       $b[] = $list_eventos;
	$a[] = '{admin_select_participantes}'; $b[] = $list_participantes;
	
}



// Editar ou Visualizar - Participantes		
if(isset($get['editar-participante'])  &&  isset($_SESSION['fideliza_logado-admin'])){
		
$id        = $get['editar-participante'];
$select_db = $parametros_response['select_db'];
$select_db->ExeRead(" * ",  ' pd_participante', " WHERE id = :id", "id={$id}");

$nome   = $select_db->getResult()[0]['nome'];
$senha  = $select_db->getResult()[0]['senha'];
$login  = $select_db->getResult()[0]['login'];
$grup   = $select_db->getResult()[0]['grupo'];

	$select_db = $parametros_response['select_db'];	

if($select_db->getResult()[0]['status'] == 0){	   
$update_status_input = '<input type="checkbox" name="status" checked data-toggle="toggle" id="cadastro_status" value="0" data-on="Não" data-off="Sim" data-onstyle="danger" data-offstyle="success">';
}else{
$update_status_input = '<input type="checkbox" name="status" checked data-toggle="toggle" id="cadastro_status" value="1" data-on="Sim" data-off="Não" data-onstyle="success" data-offstyle="danger">';	
}

	$select_db = $parametros_response['select_db'];
    $select_db->ExeRead(" * ",  'pd_grups', "", "");

    $list_grup = '<option value="'.$grup.'">'.$grup.'</option>';

	for($i=0;$i<count($select_db->getResult());$i++){
		
	$list_grup .= '<option value="'.$select_db->getResult()[$i]['nome'].'">'.$select_db->getResult()[$i]['nome'].'</option>';
	
	}

	$a[] = '{cadastro_type}';   $b[]  = '';
	$a[] = '{update_nome}';     $b[]  = $nome;
	$a[] = '{update_login}';    $b[]  = $login;
	$a[] = '{update_senha}';    $b[]  = $senha;
	$a[] = '{label_next}';      $b[]  = 'ALTERAR';
	$a[] = '{metodo_participante}';   $b[]  = $id; 
    $a[] = '{update_status_input}';   $b[] = $update_status_input;
    $a[] = '{update_grup}';           $b[]  = $list_grup;
    	
}else if($parametros_get_page['pag_name'] == 'Admin - Participantes' && isset($_SESSION['fideliza_logado-admin'])){

	$select_db = $parametros_response['select_db'];	
	$select_db->ExeRead(" * ",  'pd_participante', "ORDER BY id DESC", "");
	
	
	$select_db = $parametros_response['select_db'];
    $select_db->ExeRead(" * ",  'pd_grups', "", "");
    $list_grup = '';
   
	for($i=0;$i<count($select_db->getResult());$i++){
		
	$list_grup .= '<option value="'.$select_db->getResult()[$i]['nome'].'">'.$select_db->getResult()[$i]['nome'].'</option>';
	
	}
	

	$a[] = '{cadastro_type}';         $b[]  = '';
	$a[] = '{update_nome}';           $b[] = '';
    $a[] = '{update_login}';          $b[] = '';
	$a[] = '{update_senha}';          $b[] = '';
	$a[] = '{label_next}';            $b[]  = 'CADASTRAR';
	$a[] = '{metodo_participante}';   $b[]  = 'insert';
	
	$a[] = '{update_status_input}'; $b[] = '<input type="checkbox" name="status" checked data-toggle="toggle" id="cadastro_status" value="1" data-on="Sim" data-off="Não" data-onstyle="success" data-offstyle="danger">';
    $a[] = '{update_grup}';     $b[]  = $list_grup;

}



// LISTAR EVENTOS
if($parametros_get_page['pag_name'] == 'Admin - Eventos Listar' && isset($_SESSION['fideliza_logado-admin'])){
		
	$select_db = $parametros_response['select_db'];	
	$select_db->ExeRead(" * ",  'pd_eventos', " ORDER BY id DESC", "");
    $eventos_list = '';
	  

	  
for($i=0;$i<count($select_db->getResult());$i++){
		
$eventos_list .= '
<tr>
<td>'.$select_db->getResult()[$i]['nome'].'</td>
<td>'.$select_db->getResult()[$i]['grup'].'</td>
<td>'.$select_db->getResult()[$i]['data'].'</td>
<td>'.$select_db->getResult()[$i]['status'].'</td>
<td><div class="d-inline-block dropdown">
<button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn-shadow dropdown-toggle btn btn-info">
<span class="btn-icon-wrapper pr-2 opacity-7">
<i class="nav-link-icon lnr-user"></i>
</span>
Opções
</button>
<div tabindex="-1" role="menu" aria-hidden="true" class="dropdown-menu dropdown-menu-right" style="">
<ul class="nav flex-column">

<li class="nav-item">
<a class="nav-link editar_user"  data-id="'.$select_db->getResult()[$i]['id'].'">
<i class="nav-link-icon lnr-user"></i>
<span> Editar</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link deletar_user" data-id="'.$select_db->getResult()[$i]['id'].'">
<i class="nav-link-icon lnr-trash"></i>
<span> Deletar</span>
</a>
</li>
</ul>
</div>
</div></td>
</tr>';

}


$eventos_list .= "<script>

function deletar_evento(id){
	
	data_inputs = 'deletar-eventos=' + id;

		$.ajax({
            type:   'GET',
             url:    BASE_URL,
             data:   data_inputs,
			 dataType: 'json',
             success: function(data){
				 alert(data.msg);  
			 }
			 
			 
		});
		
}


window.setTimeout(function(){
	
	jQuery('.editar_user').click(function(){
		
		id = jQuery(this).attr('data-id');
		window.location = 'admin-eventos?editar-eventos=' + id;
			
	});
	
	jQuery('.deletar_user').click(function(){
		
		id = jQuery(this).attr('data-id');
	    deletar_evento(id);
			
	});

	jQuery('#cliente_status .btn-success').click(function(){

	jQuery('#cadastro_status').val('0')
		
	});
	
	jQuery('#cliente_status .btn-danger').click(function(){

	jQuery('#cadastro_status').val('1')
		
	});
	

},1000);

</script>";



$a[] = '{admin_eventos}'; $b[] =  $eventos_list;
	
	
}

 
if(isset($post['bro_update']) && isset($_SESSION['fideliza_logado-admin'])){
    
$bro_link   = $post['bro_link'] ? $post['bro_link'] : 'http://';
$bro_format = $post['bro_format'];
$volume_maximo = $post['bro_volume_maximo'];
$permission  = $post['bro_permission'];

$id         = $post['bro_update'];

    $prepared_insert_array = [ 'link'       =>  $bro_link,
							   'type_format' =>  $bro_format,
							   'volume_maximo' => $volume_maximo,
							   'permission'   => $permission];
						   
$updateSiteViews = new Core_update;	
$updateSiteViews->ExeUpdate('pd_broadcastv_vd', $prepared_insert_array,  "WHERE id = :d ", "d={$id}");
   
   
   	
	if($updateSiteViews->getResult()){
		
	echo 'Video alterado com sucesso!';
	exit;
		
	}else{
		
	echo 'Falha no cadastro!';
	exit;
		
	}
    
}
 		
		
 
 //BROADCAST CUSTUMIZE
if($parametros_get_page['pag_name'] == 'Admin - Broadcast' && isset($_SESSION['fideliza_logado-admin'])){
		
	$select_db = $parametros_response['select_db'];	
	//ORDER BY id DESC
	$select_db->ExeRead(" * ",  'pd_broadcastv_vd', "", "");
    $participantes = '';
	  
for($i=0;$i<count($select_db->getResult());$i++){
	
		
$participantes .= '
<tr>
<td><img src="'.$select_db->getResult()[$i]['level_thumb'].'" width="200" height="auto" /></td>
<td>'.$select_db->getResult()[$i]['type_format'].'</td>
<td>'.$select_db->getResult()[$i]['link'].'</td>
<td><div class="d-inline-block dropdown">
<button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn-shadow dropdown-toggle btn btn-info">
<span class="btn-icon-wrapper pr-2 opacity-7">
<i class="metismenu-icon pe-7s-film"></i>
</span>
Opções
</button>
<div tabindex="-1" role="menu" aria-hidden="true" class="dropdown-menu dropdown-menu-right" style="">
<ul class="nav flex-column">

<li class="nav-item">
<a class="nav-link editar_user"  data-id="'.$select_db->getResult()[$i]['id'].'">
<i class="fa fa-fw" aria-hidden="true" title="Copy to use edit"></i>&nbsp&nbsp
<span> Editar</span>
</a>
</li>
</ul>
</div>
</div></td>
</tr>';

}


$participantes .= "<script>



window.setTimeout(function(){
	
	jQuery('.editar_user').click(function(){
		
		id = jQuery(this).attr('data-id');
	
			jQuery('#alertmodal').click();
			
			url = BASE_URL + 'admin-dashboard/?ajax-update-level-broadcast-update='+	id;
		
			jQuery('#ajax_content').load(url);
			
				
	//	jQuery('#swal2-title').html('PARABÉNS!')
	//	jQuery('#swal2-content').html('Seus saldo foi alterado..')
	//	jQuery('.swal2-confirm').html('Fazer Aposta');
	
			
	});
	
	jQuery('.deletar_user').click(function(){
		
		id = jQuery(this).attr('data-id');
	    deletar_participante(id);
			
	});


},1000);

</script>";

$a[] = '{admin_broadcast}'; $b[] = $participantes; 
	
}

 
 //PARTICIPANTES LISTAR
if(isset($get['ajax-update-level-broadcast-update']) && isset($_SESSION['fideliza_logado-admin'])){
    
    $id = $get['ajax-update-level-broadcast-update'];

	$select_db = $parametros_response['select_db'];	
	$select_db->ExeRead(" * ",  'pd_broadcastv_vd', "WHERE id = :d ", "d={$id}");

    $content = '<form name="form1" id="form1" action="" method="post">
    
<div class="form-row">

<div class="col-md-12">
<div class="position-relative form-group">
    <img src="'.$select_db->getResult()[0]['level_thumb'].'" width="100%" height="auto" />
</div>
</div>

<div class="col-md-12">
<div class="position-relative form-group">
<label for="exampleEmail2">FORMATO <span style="color:#F00">*</span></label>
<select class="form-control" name="bro_format" id="cadastro_grup">
<option value="'.$select_db->getResult()[0]['type_format'].'">'.$select_db->getResult()[0]['type_format'].'</option>
<option value="DESATIVAR">DESATIVAR</option>
<option value="MP4">MP4</option>
<option value="YOUTUBE">YOUTUBE</option>
<option value="LIVE">LIVE</option>
<option value="BROADCAST">BROADCAST</option>
</select>
</div>
</div>

<div class="col-md-12">
<div class="position-relative form-group">
<label for="exampleEmail2">URL VIDEO STREAM<span style="color:#F00">*</span></label>
<input name="bro_link"  placeholder="Link: " type="text" class="form-control" value="'.$select_db->getResult()[0]['link'].'">
</div>
</div>


<div class="col-md-6">
<div class="position-relative form-group">
<label for="exampleEmail2">VOLUME MAXIMO<span style="color:#F00">*</span></label>
<input name="bro_volume_maximo"  placeholder="Link: " type="number" class="form-control" value="'.$select_db->getResult()[0]['volume_maximo'].'">
</div>
</div>


<div class="col-md-6">
<div class="position-relative form-group">
<label for="exampleEmail2">CONTROLES<span style="color:#F00">*</span></label>
<select class="form-control" name="bro_permission" id="cadastro_grup">
<option value="'.$select_db->getResult()[0]['permission'].'">'.$select_db->getResult()[0]['permission'].'</option>
<option value="ADMINISTRADOR">ADMINISTRADOR</option>
<option value="ANFITRIÃO">ANFITRIÃO</option>
<option value="CONVIDADOS">CONVIDADOS</option>
</select>
</div>
</div>


<div class="col-md-12">
<div class="position-relative form-group">
<button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn-shadow btn btn-info"  style="float:right" onclick="update_broadcast()">
<span class="btn-icon-wrapper pr-2 opacity-7">
<i class="metismenu-icon pe-7s-film"></i>
</span>
SALVAR
</button>
</div>
</div>
<input name="bro_update"  type="hidden" class="form-control" value="'.$select_db->getResult()[0]['id'].'">
</form>


<script>

function update_broadcast(){
    

		$.ajax({
            type:   "POST",
             url:    BASE_URL + "/admin-broadcast",
             data:    $("#form1").serialize(),
             success: function(d){

if(d == "Video alterado com sucesso!"){
        alert(d);
        window.location = window.location;
}else{
    alert(d)
}
			 }
			 
		});

}

</script>


';

echo $content;
exit;

}


 
//PARTICIPANTES LISTAR
if($parametros_get_page['pag_name'] == 'Admin - Participantes Listar' && isset($_SESSION['fideliza_logado-admin'])){
		
	$select_db = $parametros_response['select_db'];	
	$select_db->ExeRead(" * ",  'pd_participante', "ORDER BY id DESC", "");
    $participantes = '';
	  
for($i=0;$i<count($select_db->getResult());$i++){
		
$participantes .= '
<tr>
<td>'.$select_db->getResult()[$i]['nome'].'</td>
<td>'.$select_db->getResult()[$i]['senha'].'</td>
<td>'.$select_db->getResult()[$i]['data'].'</td>
<td><div class="d-inline-block dropdown">
<button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn-shadow dropdown-toggle btn btn-info">
<span class="btn-icon-wrapper pr-2 opacity-7">
<i class="nav-link-icon lnr-user"></i>
</span>
Opções
</button>
<div tabindex="-1" role="menu" aria-hidden="true" class="dropdown-menu dropdown-menu-right" style="">
<ul class="nav flex-column">

<li class="nav-item">
<a class="nav-link editar_user"  data-id="'.$select_db->getResult()[$i]['id'].'">
<i class="nav-link-icon lnr-user"></i>
<span> Editar</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link deletar_user" data-id="'.$select_db->getResult()[$i]['id'].'">
<i class="nav-link-icon lnr-trash"></i>
<span> Deletar</span>
</a>
</li>
</ul>
</div>
</div></td>
</tr>';

}


$participantes .= "<script>

function deletar_participante(id){
	
	data_inputs = 'deletar-participante=' + id;

		$.ajax({
            type:   'GET',
             url:    BASE_URL + '/admin-participante',
             data:   data_inputs,
			 dataType: 'json',
             success: function(data){ 
				alert(data.msg);  
			 }
			 
			 
		});
		
}

window.setTimeout(function(){
	
	jQuery('.editar_user').click(function(){
		
		id = jQuery(this).attr('data-id');
		window.location = 'admin-participante?editar-participante=' + id;
			
	});
	
	jQuery('.deletar_user').click(function(){
		
		id = jQuery(this).attr('data-id');
	    deletar_participante(id);
			
	});


},1000);

</script>";

$a[] = '{admin_participantes}'; $b[] = $participantes; 
	
}


/* GRUPO */
if($parametros_get_page['pag_name'] == 'Admin - Grupos' && isset($_SESSION['fideliza_logado-admin'])){
	
	$select_db = $parametros_response['select_db'];	
	$select_db->ExeRead(" * ",  'pd_grups', "", "");
	$tr = '';
	
	for($i=0;$i<count($select_db->getResult());$i++){
		
	$tr .= '<tr>
    <td>'.$select_db->getResult()[$i]['nome'].'</td>
    </tr>';

	}

$a[] = '{admin_grupos}'; $b[] = $tr;
	
}



/* QUIZ */
if($parametros_get_page['pag_name'] == 'Admin - Quiz' && isset($_SESSION['fideliza_logado-admin'])){
	
	$select_db = $parametros_response['select_db'];	
	$select_db->ExeRead(" pd_participante.nome as username, evento, quiz, tempo, pontos  ",  'pd_quiz, pd_participante', " WHERE pd_quiz.user=pd_participante.id ", "");
	$tr = '';
	
	for($i=0;$i<count($select_db->getResult());$i++){
		
	$tr .= '<tr>
	<td>'.$select_db->getResult()[$i]['username'].'</td>
    <td>'.$select_db->getResult()[$i]['tempo'].'</td>
	<td>'.$select_db->getResult()[$i]['quiz'].'</td>
	<td>'.$select_db->getResult()[$i]['pontos'].'</td>
	<td>'.$select_db->getResult()[$i]['evento'].'</td>
    </tr>';

	}

$a[] = '{admin_quiz}'; $b[] = $tr;
	
}




/* Dashboard */
if($parametros_get_page['pag_name'] == 'Admin Dashboard' && isset($_SESSION['fideliza_logado-admin'])){

   $jsonAdmin = json_decode($_SESSION['fideliza_logado-admin']);
   $r         = $jsonAdmin->ad_id;    
   $select_db = $parametros_response['select_db'];
   
   $date = date('/m/');
   
	$as = array('R$', ' ', ',', '.');
	$bs = array('', '', '', '');
	

    $status = 1;
	$data = date('-m-');

	$select_db->ExeRead(" data ",  'pd_participante', "WHERE data  LIKE '%' :d '%'", "d={$date}");
    $total_recentes = count($select_db->getResult());
	
	$select_db->ExeRead(" data ",  'pd_eventos', "WHERE data  LIKE '%' :d '%' AND status=1", "d={$data}");
    $total_eventos = count($select_db->getResult());
			

	$a[] = '{logo_admin}'; $b[] = $jsonAdmin->logo;
	$a[] = '{user_admin}'; $b[] = $jsonAdmin->ad_login;
	$a[] = '{admin_name}'; $b[] = $jsonAdmin->ad_name;
	$a[] = '{dashboard_titulo}'; $b[] = 'Dashboard';
	$a[] = '{admin_banca_new_users}'; $b[] = $total_recentes;
    $a[] = '{admin_eventos}'; $b[] = $total_eventos;
	
}


if(isset($_GET['terminal-admin-ajax'])){
	
$template = $_GET['terminal-admin-ajax'];

switch ($template) {

	case 'cadastro-cliente';
    include('ajax-admin/cadastro-cliente.php');
	exit;	
	break;		
										
}
	
}



if(isset($_POST['cadastro-db-moderador'])){
		
$usu_nome  = $_POST['usu_nome'];
$usu_login = $_POST['usu_login'];
$usu_senha = md5($_POST['usu_senha']);
$permissao = $_POST['permissao-select'];
$jsonAdmin = json_decode($_SESSION['fideliza_logado-admin']);
$r        = $jsonAdmin->ad_id;

	$select_db = $parametros_response['select_db'];
	$select_db->ExeRead("*",  'fd_moderadores', "WHERE ( ad_login = :l AND ad_ref = :r)", "l={$usu_login}&r={$r}");

    if ($select_db->getResult() && $select_db->getResult()[0]['ad_login'] != $usu_login){
        
    	echo 'Este LOGIN já esta sendo usado!';
		exit;
		    
    }

	
	$prepared_insert_array = [ 'ad_login' => $usu_login,
							   'ad_senha' => $usu_senha,
							   'ad_name'  => $usu_nome,
							   'ad_level' => 0,
							   'logo'     => '',
							   'permissao' =>  $permissao,
							   'ad_ref'    =>  $jsonAdmin->ad_id];
						   
$createSiteViews = new Core_create;	
$createSiteViews->ExeCreate('fd_moderadores', $prepared_insert_array);		   
	
	if($createSiteViews->getResult()){
		
	echo 'Cadadstro realizado com sucesso!';
		exit;
		
	}else{
		
	echo 'Falha no cadastro!';
		exit;
		
	}
	
	
	
}


if(isset($_POST['editar-db-moderador'])){
		
$id        = $_POST['editar-db-moderador'];
$usu_nome  = $_POST['usu_nome'];
$usu_login = $_POST['usu_login'];
$jsonAdmin = json_decode($_SESSION['fideliza_logado-admin']);

$level     = $jsonAdmin->ad_level;
$r        = $jsonAdmin->ad_id;
	
$select_db = $parametros_response['select_db'];
$select_db->ExeRead("*",  'fd_moderadores', "WHERE ( ad_login = :l AND ad_level = :ll AND ad_ref = :r)", "l={$usu_login}&ll={$level}&r={$r}");


    if ($select_db->getResult() && $select_db->getResult()[0]['ad_login'] != $usu_login){
        
    	echo 'Este LOGIN já esta sendo usado! ' . $jsonAdmin->ad_login;
		exit;
		    
    }	

	
if(strlen($_POST['usu_senha']) < 30){
$usu_senha = md5($_POST['usu_senha']);
}else{
$usu_senha = $_POST['usu_senha'];				
}
	
$permissao = $_POST['permissao-select'];
	
$prepared_insert_array = [ 'ad_login' => $usu_login,
							   'ad_senha' => $usu_senha,
							   'ad_name'  => $usu_nome,
							   'ad_level' => 0,
							   'logo'     => '',
							   'permissao' =>  $permissao];
						   
$updateSiteViews = new Core_update;	
$updateSiteViews->ExeUpdate('fd_moderadores', $prepared_insert_array, "WHERE ( ad_id = :i AND ad_ref = :id )", "i={$id}&id={$r}");	
	
	if($updateSiteViews->getResult()){
		
	echo 'Cadadstro alterado com sucesso!';
	exit;
		
	}else{
		
	echo 'Falha no cadastro!';
	exit;
		
	}
	
}



if(isset($_GET['import'])){
	
// Caminho para o arquivo de texto
$nome        = 'txt/nome.txt';
$grup        = 'txt/grups.txt';
$senha       = 'txt/senha.txt';

$select_db = $parametros_response['select_db'];
$select_db_grup = $parametros_response['select_db'];
	
if (file_exists($nome)) {
    // Lê o conteúdo do arquivo e o divide em linhas
    $linhas_nome        = file($nome, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
	$linhas_grup        = file($grup, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
	$linhas_senha       = file($senha, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
	
	$i = 0;
	
    // Verifica se há linhas no arquivo
    if ($linhas_nome !== false) {
        // Itera sobre cada linha usando um loop foreach
        foreach ($linhas_nome as $nomes) {

$senha = $linhas_senha[$i];
$grupo = $linhas_grup[$i];

	$select_db->ExeRead("nome,senha,grupo",  'pd_participante', "WHERE nome = :n AND senha = :s AND grupo = :g", "n={$nomes}&s={$senha}&g={$grupo}");
	
	echo '<pre>Nome: ' . $nomes . ' Senha: ' . $senha . ' Grupo: ' . $grupo. '</pre><br>';
	
		
$prepared_insert_array = [ 
'nome'             => $nomes,
'senha'            => $senha,
'grupo'            => $grupo];		   
							 				   				
$createSiteViews = new Core_create;	
$createSiteViews->ExeCreate('pd_participante', $prepared_insert_array);


	
	
$i++;

		}

	}		
	
	exit;
	
	
}



}



?>