<?php   include 'conector.php';session_start();include 'menu_header.php';
$men="";$val1="";$val2="";$val3="";$val4="";$cur1="";$cur2="";$cur3="";$cur4="";
$class1="";$class2="";$class3="";$class4="";$act1="";$act2="";$act3="";$act4="";$tbody="";
$nombre_asignatura1="";$codigo_asignatura1="";$sigla_asignatura1="";$estado_1="";$ide1="";
$nombre_asignatura2="";$codigo_asignatura2="";$sigla_asignatura2="";

if(isset($_GET['eliminar']) && !empty($_GET['eliminar'])){
	$subject_id = intval($_GET['eliminar']);
	$eliminar_asignatura="delete from asignatura where subject_id=".$subject_id;
	if(mysql_query($eliminar_asignatura)){
		$men="<div class=\"alert alert-success\">
                     <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                     Asignatura Eliminada               
 			</div>";
	}
}

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_asignatura="update asignatura 
 			set
 			asignatura.codigo='".$_POST["codigo_asignatura1"]."',
 			asignatura.nombre='".$_POST["nombre_asignatura1"]."',
 			asignatura.sigla='".$_POST["sigla_asignatura1"]."',
 			asignatura.estado='".$_POST["estado_1"]."'
 			where 
 			asignatura.subject_id=".$_POST["ide1"]."
 				";
 
	mysql_query($act_asignatura)or die(mysql_error());
	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Asignatura Actualizada 
			</div>";


 }
}


 $select_asignatura="select codigo,nombre,sigla,estado,subject_id
 from asignatura where asignatura.estado in ('A','I') order by nombre";
 $res_select_asignatura=mysql_query($select_asignatura);
				
					$tbody="<tbody>";
					
					
					
					
					while($r_sag=mysql_fetch_array($res_select_asignatura)){
					if($r_sag[3]=='A'){$est='Activo';$lab='success ';}else{$est='Inactivo';$lab='danger ';}
					$tbody.="<tr role='row'><td>".$r_sag[0]."</td><td>".$r_sag[1]."</td><td>".$r_sag[2]."</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_sag[4]."' onclick=''>
                			<i class='glyphicon glyphicon-edit icon-white'></i> Editar               
				            </a>
					<input type='button' value='Eliminar' class='btn btn-danger btn-xs' onclick=\"if(confirm('¿Eliminar asignatura?')){location.href='asignaturas.php?eliminar=".$r_sag[4]."'}\">
					</td>
					</tr>
					";
					$c1='';$c2='';
		if($r_sag[3]=='A'){$c1=' selected ';}
		if($r_sag[3]=='I'){$c2=' selected ';}	
						$tbody.="<div name='mimodala".$r_sag[4]."' id='mimodala".$r_sag[4]."' 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 Asignatura</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_sag[0]."' id='codigo_".$r_sag[4]."' name='codigo_".$r_sag[4]."' 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_sag[1]."' id='nombre_".$r_sag[4]."' name='nombre_".$r_sag[4]."' 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;' >
						Sigla &nbsp;  </div>
						<div class='input' ><input    value='".$r_sag[2]."' id='sigla_".$r_sag[4]."' name='sigla_".$r_sag[4]."' 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;' >
								Estado&nbsp;  </div>
					 <div class='input' >
								 <select id='estadoa".$r_sag[4]."' name='estadoa".$r_sag[4]."' 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_asignatura(".$r_sag[4].")' >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_asignatura='insert into asignatura (codigo,nombre,sigla)
	values("'.$_POST['codigo_asignatura2'].'","'.$_POST['nombre_asignatura2'].'","'.$_POST['sigla_asignatura2'].'"
	)';
	mysql_query($insertar_asignatura)or die(mysql_error());
	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Asignatura: ".$_POST['nombre_asignatura2']." Insertada
			</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\">
	<style>
	</style>
    <title>Asignaturas</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_asignatura(ide){
if(document.getElementById('codigo_'+ide).value==''){alert('Debe digitar el codigo de la Asignatura');return false;}
	else{document.getElementById('codigo_asignatura1').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_asignatura1').value=document.getElementById('nombre_'+ide).value}

if(document.getElementById('sigla_'+ide).value==''){alert('Debe digitar la sigla de la Asignatura');return false;}
	else{document.getElementById('sigla_asignatura1').value=document.getElementById('sigla_'+ide).value}

document.getElementById('estado_1').value=document.getElementById('estadoa'+ide).value;
document.getElementById('ide1').value=ide;

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

}
function crea_asignatura(){

if(document.getElementById('nombre_asignatura').value==''){alert('Debe digitar el nombre de la Asignatura');return false;}
	else{document.getElementById('nombre_asignatura2').value=document.getElementById('nombre_asignatura').value}
if(document.getElementById('codigo_asignatura').value==''){alert('Debe digitar el Codigo de la Asignatura');return false;}
	else{document.getElementById('codigo_asignatura2').value=document.getElementById('codigo_asignatura').value}
if(document.getElementById('sigla_asignatura').value==''){alert('Debe digitar Sigla de la Asignatura');return false;}
	else{document.getElementById('sigla_asignatura2').value=document.getElementById('sigla_asignatura').value}
	

	document.getElementById('val2').value=1;
	document.forms['crear_asignatura'].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\"><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 active\"><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\">Gestion Asignaturas</a></li>
	  <li $class2 ><a href=\"#profile\" data-toggle=\"tab\">Crear Asignatura</a></li>
	</ul>
	
	<!-- Tab panes -->

	<div class=\"tab-content\">
	<div class=\"tab-pane fade in $act2 \" id=\"profile\">
		<form name='crear_asignatura' id='crear_asignatura' method='post' action='asignaturas.php#profile' target='' >
		<input type='hidden' name='val2' id='val2' value='".$val2."'>	
		<input type='hidden' name='nombre_asignatura2' id='nombre_asignatura2' value='".$nombre_asignatura2."'>	
		<input type='hidden' name='codigo_asignatura2' id='codigo_asignatura2' value='".$codigo_asignatura2."'>	
		<input type='hidden' name='sigla_asignatura2' id='sigla_asignatura2' value='".$sigla_asignatura2."'>					

		
		<div class=\"page\">
			<fieldset>
				<legend>
					<br><span class=\"glyphicon glyphicon-plus\"></span> Crear Nueva Asignatura          
				</legend>			
			</fieldset>
		
		
		 <div class='input' style='float:left;width: 140px;padding-top: 5px;text-align: right;' >
			Nombre&nbsp;
		  </div>
		 <div class='input' >
		    <input id='nombre_asignatura' name='nombre_asignatura' type='text' class='form-control' placeholder='ej. matematicas' style='width:48%;margin-bottom: 10px'>
		 </div>

		<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_asignatura' name='codigo_asignatura' type='text' class='form-control' placeholder='ej. 01' style='width:48%;margin-bottom: 10px'>
		  </div>
		<div class='input' style='float:left;width: 140px;padding-top: 5px;text-align: right;' >
			Sigla&nbsp;
		  </div>
		 <div class='input' >
		    <input id='sigla_asignatura' name='sigla_asignatura' type='text' class='form-control' placeholder='ej. MATEM' style='width:48%;margin-bottom: 10px'>
		     </div>
		
		
		<fieldset>
		<legend>
					<br>
					
		</legend>	
			<button type='button' class='btn btn-info' onclick='crea_asignatura()'> Crear Asignatura</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_asignatura' id='listar_asignatura' method='post' action='asignaturas.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_asignatura1' id='nombre_asignatura1' value='".$nombre_asignatura1."'>	
	<input type='hidden' name='codigo_asignatura1' id='codigo_asignatura1' value='".$codigo_asignatura1."'>	
	<input type='hidden' name='sigla_asignatura1' id='sigla_asignatura1' value='".$sigla_asignatura1."'>	
	<input type='hidden' name='estado_1' id='estado_1' value='".$estado_1."'>		
	<input type='hidden' name='ide1' id='ide1' value='".$ide1."'>	
		<fieldset>
			<legend><br><span class=\"glyphicon glyphicon-th-list\"></span> 
				Lista de Asignaturas          
			</legend>			
		</fieldset>
	</div>
	
	<fieldset>
	<div class='table-responsive'>
	<table id='asignaturas_tabla' class='table table-striped table-bordered '>
		<thead>
			<tr role='row'>
				<th>C&oacute;digo</th>
				<th>Nombre</th>
				<th>Sigla</th>				
				<th>Estado</th>				
				<th></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; CDLE</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('asignaturas_tabla'));
    </script>
  </body>
</html>
";
}else{
echo "<div align='center'>Debe registrase para usar la aplicaci&oacute;n <a href='index.php' > Registrar</a></div>";
}
  ?>