<?php  
include 'conector.php';
session_start();

if(isset($_SESSION["user"])&& $_SESSION["tipo"]=='A'){

  $class1="class=\"active\"";
  $class2="";
  $act2="";
  $act1=" active ";

if(isset($_POST['val1'])&&!empty($_POST['val1'])){
 if($_POST['val1']==1){
 
 
 
 $act_curso="update curso 
 			set
 			curso.codigo='".$_POST["codigo_curso1"]."',
 			curso.nombre='".$_POST["nombre_curso1"]."',
			curso.id_docente='".$_POST["docente1"]."',
 			curso.estado='".$_POST["estado1"]."'
 			where 
 			curso.curso_id=".$_POST["ide1"]."	";

	mysql_query($act_curso)or die(mysql_error());
	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Curso Actualizado
			</div>";
 
 }

}



 $select_curso_est="select  	curso_id,
 				codigo,
 				nombre,
 				(select count(*) from estudiante where estudiante.curso_id=curso.curso_id ) ,
 				(select docente.nombre from docente where docente.teacher_id=curso.id_docente),
 				estado,
 				curso.id_docente  
 			from curso 
 			 order by orden";
 $res_select_curso_est=mysql_query($select_curso_est);
				
					$tbody="<tbody>";
					while($r_sce=mysql_fetch_array($res_select_curso_est)){
					$c1='';$c2='';
					if($r_sce[5]=='A'){$est='Activo';$lab='success ';$c1=' selected ';}else{$est='Inactivo';$lab='danger ';$c2=' selected ';}
					$tbody.="<tr role='row'><td>".$r_sce[1]."</td><td>".$r_sce[2]."</td><td>".$r_sce[3]."</td><td>".$r_sce[4]."</td><td><span class='label label-".$lab."'>".$est."</span></td>
					<td>
					<a class='btn btn-info btn-xs'  data-toggle='modal' data-target='#mimodala".$r_sce[0]."' onclick=''>
                			<i class='glyphicon glyphicon-edit icon-white'></i>  
			                Editar               
				            </a>
					</td></tr>
					";
							

		$tbody.="<div name='mimodala".$r_sce[0]."' id='mimodala".$r_sce[0]."' class='modal fade bs-example-modal-sm' tabindex='-1' role='dialog' aria-labelledby='mySmallModalLabel' aria-hidden='true'>
						  <div class='modal-dialog modal-md'>
						    <div class='modal-content'>
						      <div class='modal-header'>
							      <button type='button' class='close' data-dismiss='modal' aria-hidden='true'>x</button>
						      		<h4 class='modal-title' id='myLargeModalLabel'>Consultar Curso</h4>
	      					      </div>
	      					      <div class='modal-body'>";
						$tbody.="
								 
						 <div class='input' style='float:left;width: 120px;padding-top: 5px;padding-left: 10px;text-align: left;height:20px;font-size:12px;' >
						C&oacute;digo &nbsp;  </div>
						<div class='input' ><input    value='".$r_sce[1]."' id='codigo_".$r_sce[0]."' name='codigo_".$r_sce[0]."' type='text' class='form-control2' style='width:50%;margin-bottom: 10px' >
						 </div>
						 <div class='input' style='float:left;width: 120px;padding-top: 5px;padding-left: 10px;text-align: left;height:20px;font-size:12px;' >
						Nombre &nbsp;  </div>
						<div class='input' ><input    value='".$r_sce[2]."' id='nombre_".$r_sce[0]."' name='nombre_".$r_sce[0]."' type='text' class='form-control2' style='width:50%;margin-bottom: 10px' >
						 </div>		 
					 <div class='input' style='float:left;width: 120px;padding-top: 5px;padding-left: 10px;text-align: left;height:20px;font-size:12px;' >
						Docente &nbsp;  </div>
						<div class='input' >
						<select id='docente_".$r_sce[0]."' name='docente_".$r_sce[0]."' class='form-control2' style='width:50%;margin-bottom: 10px'>";
				
			
				
							$select_doc2='select teacher_id,nombre
							from docente where estado="A" order by nombre';
							$res_select_doc2=mysql_query($select_doc2);
							$tbody.="<option value='XX' >Seleccione Docente</option>";
							while($r_sd2=mysql_fetch_array($res_select_doc2)){
							$sel2=' ';
							if($r_sce[6]==$r_sd2[0]){$sel2=' selected ';}
									$tbody.='<option value="'.$r_sd2[0].'"  '.$sel2.'>'.$r_sd2[0].' - '.$r_sd2[1].' </option>';
							}
							
					$tbody.="</select>
						 </div>		 
				 	 <div class='input' style='float:left;width: 120px;padding-top: 5px;padding-left: 10px;text-align: left;height:20px;font-size:12px;' >
								Estado&nbsp;  </div>
					 <div class='input' >
								 <select id='estadoa".$r_sce[0]."' name='estadoa".$r_sce[0]."' class='form-control2' style='width:50%;margin-bottom: 10px'>
								 	<option value='A' $c1 >Activo</option>
								 	<option value='I' $c2 >Inactivo</option>
								 </select>
					 </div>
						 
								 
								 
								 
								 
								 ";

						 $tbody.="<div>
						 <button type=\"button\" class=\"btn btn-primary btn-xs\" onclick='actualizar_curso(".$r_sce[0].")' >Actualizar</button>
							<button type=\"button\" class=\"btn btn-info btn-xs\" data-dismiss='modal' >Cerrar</button>
							</div>";								
								
						$tbody.="
							</div>
						    </div>
						  </div>
						</div>	";	


					}
					$tbody.="</tbody>";

if(isset($_POST['val2'])&&!empty($_POST['val2'])){

 if($_POST['val2']==1){
  $class1="";
  $class2="class=\"active\"";
  $act1="";
  $act2=" active ";


	$insertar_curso='insert into curso (nombre,codigo,id_docente)
	values("'.$_POST['nombre_curso2'].'","'.$_POST['codigo_curso2'].'","'.$_POST['docente2'].'"
	)';
	mysql_query($insertar_curso)or die(mysql_error());
	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Curso: ".$_POST['nombre_curso2']." Insertado
			</div>";

	
	
	

 }
}



echo "
<!DOCTYPE html>
<html lang=\"en\">
  <head>
    <meta charset=\"utf-8\">
    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">
    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
    <meta name=\"description\" content=\"\">
    <meta name=\"author\" content=\"\">
    <link rel=\"shortcut icon\" href=\"assets/ico/favicon.ico\">
    <title>Cursos</title>

    <!-- Bootstrap core CSS -->
    <link href=\"dist/css/bootstrap.min.css\" rel=\"stylesheet\">

    <!-- Custom styles for this template -->
    <link href=\"offcanvas.css\" rel=\"stylesheet\">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src=\"../../assets/js/ie8-responsive-file-warning.js\"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src=\"https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js\"></script>
      <script src=\"https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js\"></script>
    <![endif]-->
    <script>
   
function actualizar_curso(ide){

if(document.getElementById('codigo_'+ide).value==''){alert('Debe digitar el codigo de la Asignatura');return false;}
	else{document.getElementById('codigo_curso1').value=document.getElementById('codigo_'+ide).value}

if(document.getElementById('nombre_'+ide).value==''){alert('Debe digitar el nombre de la Asignatura');return false;}
	else{document.getElementById('nombre_curso1').value=document.getElementById('nombre_'+ide).value}

if(document.getElementById('docente_'+ide).value=='XX'){alert('Debe Seleccionar Docente');return false;}
	else{document.getElementById('docente1').value=document.getElementById('docente_'+ide).value}
document.getElementById('estado1').value=document.getElementById('estadoa'+ide).value;
document.getElementById('ide1').value=ide;


	document.getElementById('val1').value=1;
	document.forms['listar_curso'].submit();				

}

function crea_curso(){

if(document.getElementById('nombre_curso').value==''){alert('Debe digitar el nombre');return false;}
	else{document.getElementById('nombre_curso2').value=document.getElementById('nombre_curso').value}

if(document.getElementById('codigo_curso').value==''){alert('Debe digitar el codigo');return false;}
	else{document.getElementById('codigo_curso2').value=document.getElementById('codigo_curso').value}

if(document.getElementById('docente').value=='XX'){alert('Debe Seleccionar Director de Grupo');return false;}
	else{document.getElementById('docente2').value=document.getElementById('docente').value}


	document.getElementById('val2').value=1;
	document.forms['crear_curso'].submit();			
}


</script>
  
    
    
    
  </head>

  <body>
    <div class=\"navbar navbar-fixed-top navbar-inverse\" role=\"navigation\">
      <div class=\"container\">

        
          <a class=\"\" href=\"general.php\"><img src='img/logo1.png' style='margin-top:5px'></a>

        
        <a href=\"index.php\"><img src='img/salir.png' style='float:right;margin-top:15px'>
       </a><span style='float:right;margin-right:10px; margin-top:15px' class='label label-success'><span class='glyphicon glyphicon-user'></span> ".$_SESSION["user"]."</span>
      </div><!-- /.container -->
    </div><!-- /.navbar -->


    <div class=\"container\">

      <div class=\"row row-offcanvas row-offcanvas-left\">

       <div class=\"col-xs-6 col-sm-3 sidebar-offcanvas\" id=\"sidebar\" role=\"navigation\">
          <div class=\"list-group\">
            <a href=\"general.php\" class=\"list-group-item active\"><span class=\"glyphicon glyphicon-home\"></span> General</a>
            <a href=\"estudiantes.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-th\"></span> Estudiantes</a>
            <a href=\"docentes.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-user\"></span> Docentes</a>
            <a href=\"acudiente.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-user\"></span> Acudientes</a>                      
            <a href=\"asignaturas.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-book\"></span> Asignaturas</a>
            <a href=\"cursos.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-list\"></span> Cursos</a>
            <a href=\"pensum.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-edit\"></span> Pensum</a>    
            <a href=\"logros.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Logros</a>                        
            <a href=\"observaciones.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Indicadores de Comportamiento</a>                                    
            <a href=\"horario.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Horario</a>
<a href=\"horario_atencion.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Horario de Atenci&oacute;n</a>            
<a href=\"planilla_asistencia.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Control de Asistencia</a>            
<a href=\"planilla.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Registro de Calificaciones</a>            
            <a href=\"planilla_obs.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Observador del Estudiante</a>                        
            <a href=\"pagos.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-list\"></span> Pagos</a>                  
            <a href=\"reportes.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Boletines</a>            
<a href=\"eventos.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Anuncios</a>           
            <a href=\"config.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-wrench\"></span> Configuraci&oacute;n</a>
          </div>
        </div><!--/span-->

        <div class=\"col-xs-12 col-sm-9\">
          <p class=\"pull-left visible-xs\">
            <button type=\"button\" class=\"btn btn-primary btn-xs\" data-toggle=\"offcanvas\">menu</button>
          </p>
    
	<div class=\"panel panel-default\">
	<br>";
echo $men;	
echo	      "<!-- Nav tabs -->
	<ul class=\"nav nav-tabs\">
		<li >&nbsp;</li>
	  <li $class1 ><a href=\"#home\" data-toggle=\"tab\">Gesti&oacute;n Cursos</a></li>
	  <li $class2 ><a href=\"#profile\" data-toggle=\"tab\">Crear Cursos</a></li>
	</ul>
	
	<!-- Tab panes -->

	<div class=\"tab-content\">
	<div class=\"tab-pane fade in $act2 \" id=\"profile\">
		<form name='crear_curso' id='crear_curso' method='post' action='cursos.php#profile' target='' enctype='multipart/form-data'>
		<input type='hidden' name='val2' id='val2' value='".$val2."'>	
		<input type='hidden' name='nombre_curso2' id='nombre_curso2' value='".$nombre_curso2."'>	
		<input type='hidden' name='codigo_curso2' id='codigo_curso2' value='".$codigo_curso2."'>	
		<input type='hidden' name='docente2' id='docente2' value='".$docente2."'>			
		
		<div class=\"page\">
			<fieldset>
				<legend>
					<br><span class=\"glyphicon glyphicon-plus\"></span> Crear Nuevo Curso          
				</legend>			
			</fieldset>
		
		
		 <div class='input' style='float:left;width: 140px;padding-top: 5px;text-align: right;' >
			C&oacute;digo&nbsp;
		  </div>
		 <div class='input' >
		    <input id='codigo_curso' name='codigo_curso' type='text' class='form-control' placeholder='ej. 07' style='width:48%;margin-bottom: 10px'>
		 </div>
		<div class='input' style='float:left;width: 140px;padding-top: 5px;text-align: right;' >
			Nombre &nbsp;
		  </div>
		 <div class='input' >
		    <input id='nombre_curso' name='nombre_curso' type='text' class='form-control'  placeholder='ej. s&eacute;ptimo' style='width:48%;margin-bottom: 10px'>
		 </div>
		<div class='input' style='float:left;width: 140px;padding-top: 5px;text-align: right;' >
			Dir. Grupo&nbsp;
		  </div>
		 <div class='input' >
					<select id='docente' name='docente' class='form-control' style='width:48%;margin-bottom: 10px'>";
				
			
				
					$select_doc='select teacher_id,nombre
					from docente order by nombre';
					$res_select_doc=mysql_query($select_doc);
					echo "<option value='XX' >Seleccione Docente</option>";
					while($r_sd=mysql_fetch_array($res_select_doc)){
					$sel1='  ';
					//if($_POST['area']==$r_ar[0]){$sel1=' selected ';}
					//echo "hola";
							echo '<option value="'.$r_sd[0].'"  '.$sel1.'>'.$r_sd[0].' - '.$r_sd[1].' </option>';
					}
					
echo					"</select>
		 </div>



		<fieldset>
		<legend>
					<br>
					
		</legend>	
			<button type='button' class='btn btn-info' onclick='crea_curso()'> Crear Curso</button>     
			<input type='reset' class='btn' value='Borrar'>
						
		</fieldset>
			
			<br>
		</div>
	</form>
</div>

<div class=\"tab-pane fade in $act1 \" id=\"home\">
	<form name='listar_curso' id='listar_curso' method='post' action='cursos.php' target=''>
	<div class=\"page\">
	

	<input type='hidden' name='val1' id='val1' value='".$val1."'>	
	<input type='hidden' name='cur1' id='cur1' value='".$cur1."'>	
		<input type='hidden' name='nombre_curso1' id='nombre_curso1' value='".$nombre_curso1."'>	
		<input type='hidden' name='codigo_curso1' id='codigo_curso1' value='".$codigo_curso1."'>	
		<input type='hidden' name='docente1' id='docente1' value='".$docente1."'>	
		<input type='hidden' name='estado1' id='estado1' value='".$estado1."'>				
		<input type='hidden' name='ide1' id='ide1' value='".$ide1."'>	
		<fieldset>
			<legend><br><span class=\"glyphicon glyphicon-th-list\"></span> 
				Lista de Cursos          
			</legend>			
		</fieldset>
	</div>
	
	<fieldset>
	<div class='table-responsive'>
	<table id='cursos_tabla' class='table table-striped table-bordered '>
		<thead>
			<tr role='row'>
				<th>C&oacute;digo</th>
				<th>Nombre</th>				
				<th>Nro. Alumnos</th>				
				<th>Dir. Grupo</th>				
				<th>Estado</th>
				<th>&nbsp;</th>								
			</tr>
		</thead>";
		
echo $tbody;
echo	"
	</div>
	</table>
	</fieldset>
	
	
	
	</form>

</div>
 
         
        </div><!--/span-->

       
      </div><!--/row-->


        </div><!--/row-->      </div><!--/row-->
      <hr>
      <footer>
        <p>Todos los derechos reservados - Copyright &copy; 2022</p>
      </footer>


    </div><!--/.container-->

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src=\"https://code.jquery.com/jquery-1.10.2.min.js\"></script>
    <script src=\"dist/js/bootstrap.min.js\"></script>
    <script src=\"offcanvas.js\"></script>
<script src='js/tablesort.min.js'></script>
    <script>
      new Tablesort(document.getElementById('cursos_tabla'));
    </script>
  </body>
</html>
";
}else{
echo "<div align='center'>Debe registrase para usar la aplicaci&oacute;n <a href='index.php' > Registrar</a></div>";
}
  ?>