<?php
	session_start();

			include 'SQL/conexion.php';

			$lvl=$_GET["lvl"];
			$sql = "SELECT CV_CCT as Clave, ".($lvl=="Superior"?"MUNICIPIO":$lvl=="Media"?"MUNICIPIO":"C_NOM_MUN")." as Municipio, NOMBRECT as Institucion, COUNT(respuesta.id_respuesta) AS Respuestas FROM ".$lvl." LEFT JOIN respuesta ON CV_CCT = respuesta.clave_escuela GROUP BY CV_CCT, NOMBRECT;";
//			$result = $conn->query($sql)

	
	if (isset($_SESSION["userType"]) && $_SESSION["userType"] == 965){

?>
					<!-- Page Heading -->
					<div class="d-sm-flex align-items-center justify-content-between mb-4">
						<h1 class="h3 mb-0 text-gray-800"><i class="fas fa-fw fa-tools"></i> Proyect Config</h1>
						<a target="_blanl" href="#ov" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm" onclick="UpdatePage('overview.php', true);">
							<i class="fas fa-sync-alt fa-sm text-white-50"></i> 
							Update CSV
						</a>
					</div>

					<!-- Content Row -->
					<div class="row">

						<!-- ID Card -->
						<div class="col-xl-3 col-md-6 mb-4">
							<div class="card border-left-danger shadow h-100 py-2">
								<div class="card-body">
									<div class="row no-gutters align-items-center">
										<div class="col mr-2">
											<div class="text-xs font-weight-bold text-danger text-uppercase mb-1">Loged as Root</div>
										</div>
										<div class="col-auto">
											<i class="fas fa-user-lock fa-2x text-gray-300"></i>
										</div>
									</div>
								</div>
							</div>
						</div>
						
					</div>
					
					
					<div class="row">

						<!-- Salida del sistema -->
						<div class="col-xl-9 col-lg-9">
							<div class="card shadow mb-4">
								<!-- Card Header - Dropdown -->
								<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
									<h6 class="m-0 font-weight-bold text-primary">System output</h6>
								</div>
								<!-- Card Body -->
								<div id="outputDIV" class="card-body">								
								</div>
							</div>
						</div>

						<!-- Opciones del sistema -->
						<div class="col-xl-3 col-lg-3">
							<div class="card shadow mb-4">
								<!-- Card Header - Dropdown -->
								<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
									<h6 class="m-0 font-weight-bold text-primary">System Tasks</h6>									
								</div>
								<!-- Card Body -->
								<div class="card-body">

									<div class="container">
									  <ul class="ks-cboxtags">
										<li><input type="checkbox" id="cbCDUP" value="" checked onchange="$(this).prop('disabled', true); getConfig('executeCfg.php?act=CDUP');"><label for="cbCDUP">Count duplicates</label></li>
										<li><input type="checkbox" id="cbDDUP" value="" checked onchange="$(this).prop('disabled', true); getConfig('executeCfg.php?act=DDUP');"><label for="cbDDUP">Delete duplicates</label></li>
										<li><input type="checkbox" id="cbCEMP" value="" checked onchange="$(this).prop('disabled', true); getConfig('executeCfg.php?act=CEMP');"><label for="cbCEMP">Count empty</label></li>
										<li><input type="checkbox" id="cbDEMO" value="" checked onchange="$(this).prop('disabled', true); getConfig('executeCfg.php?act=DEMP');"><label for="cbDEMO">Delete empty</label></li>
										<li><input type="checkbox" id="cbLIST" value="" checked onchange="$(this).prop('disabled', true); getConfig('executeCfg.php?act=LIST');"><label for="cbLIST">Update R's CSV</label></li>
										<li><input type="checkbox" id="cbRWC" value="" checked onchange="$(this).prop('disabled', true); getConfig('executeCfg.php?act=RWC');"><label for="cbRWC">Update Wordcloud</label></li>
										<li><input type="checkbox" id="cbMBAK" value="" checked onchange="$(this).prop('disabled', true); getConfig('executeCfg.php?act=MBAK');"><label for="cbMBAK">Backup Database</label></li>
										<li><input type="checkbox" id="cbANAME" value="" checked onchange="$(this).prop('checked', true); getConfig('executeCfg.php?act=ANAME');"><label for="cbANAME">Annotate Names</label></li>
									  </ul>
									</div>
									
								</div>
							</div>
							
						</div>
					</div>

	<script>

		// Obtenemos el control del DIV principal...
		var DivOutput = document.getElementById("outputDIV");
		
		// Request de actualización dinámica (main)...
		var configClient = new XMLHttpRequest();
		
		// Actualiza div contenedor (main)...
		getConfig = function (wPage){
			// Create a FormData instance...
			var upData = new FormData();
			// Set POST data...
			configClient.open("post", wPage, true);
			// Send to server...
			configClient.send(upData);
			// User message...
			DivOutput.innerHTML = "Executing task...";
			// Terminamos...
			return true;
		}
					
		// Respuesta del cliente main...
		configClient.onreadystatechange = function(){
			// Status OK...
			if (configClient.readyState == 4 && configClient.status == 200){
				// Check for errors on response...
				if (configClient.responseText.indexOf('Error!') != -1) {
					// Present data to user...
					DivOutput.innerHTML = configClient.responseText;
				}else{
					// Present data to user...
					DivOutput.innerHTML = configClient.responseText;
					// Clear response...
					configClient.responseText = "";
				}
			}else{
				DivOutput.innerHTML = "Error!";
			}
			
		}
	</script>					
					
					
<?php

	}else{
		echo "<script> UpdatePage('loginCfg.php') </script>";
	}
	
?>
