<?php
session_start();
include ("../BD/conexion_bd.php");
if(!$conexion)
{
	die("error al intentar conectar: " .mysql_error());
}
mysql_query("SET NAMES 'utf8'");// para configurar acentos y eñes

if(isset($_SESSION['ID_tarea']))//ya hay sesion abierta
{
	$consulta=mysql_query("SELECT id, Nombre_Tarea, Descripcion_Detallada, Fecha_Inicio, Fecha_Termino, Prioridad FROM Tareas WHERE id=".$_SESSION['ID_tarea'],$conexion);
	while($rowEmp=mysql_fetch_assoc($consulta))
	{
		$nombre_tarea=$rowEmp['Nombre_Tarea'];
		$descripcion_tarea=$rowEmp['Descripcion_Detallada'];
		$fecha_inicio_tarea=$rowEmp['Fecha_Inicio'];
		$fecha_termino_tarea=$rowEmp['Fecha_Termino'];
		$prioridad_tarea=$rowEmp['Prioridad'];
	}
} 
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Asignaci&oacute;m de Actividades</title>
<link rel="stylesheet" href="buttons.css" type="text/css" media="screen">
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>
<script type="text/javascript" src="campos.js"></script>
<script type="text/javascript">
	function funcion(variable){
		new JsDatePick({
			useMode:2,
			target:variable.id,
			dateFormat:"%d-%M-%Y"
			/*selectedDate:{				This is an example of what the full configuration offers.
				day:5,						For full documentation about these settings please see the full version of the code.
				month:9,
				year:2006
			},
			yearsRange:[1978,2020],
			limitToToday:false,
			cellColorScheme:"beige",
			dateFormat:"%m-%d-%Y",
			imgPath:"img/",
			weekStartDay:1*/
		});
	};
	
</script>


<link href="asignacion_actividades_formulario.css" rel="stylesheet" type="text/css" />
</head>
<body>

<div id="div_title">
Asignaci&oacute;n de Actividades
</div>
<form id="formulario_tarea" method="post" onsubmit="return submitform(this)" action="actions_php/action_tarea.php">
<div id="div_tarea">
<fieldset class="fielset"><legend>TAREA</legend>

<div class="content">NOMBRE</div>
<div class="content_input"><input <?php if(isset($_SESSION['ID_tarea'])) echo "value='$nombre_tarea' disabled='disabled'";   ?>  name="nombre_tarea" size="50" type="text" /></div>

<div class="content">DESCRIPCI&Oacute;N</div>
<div class="content_input">
  <label for="textarea"></label>
  <textarea name="descripcion" id="textarea"  cols="50" rows="5"<?php if(isset($_SESSION['ID_tarea'])) echo "disabled='disabled'";  ?>><?php if(isset($_SESSION['ID_tarea'])) echo "$descripcion_tarea";  ?></textarea>
</div>



<div id="fechas"><fieldset style="font-size:55%; " id="checboxes">
  <legend>FECHA</legend>
 <div style="width:45%; float:left;">
  <div class="content2" >Inicio</div>
	<div class="content_input">
    <input class="calendario" <?php if(isset($_SESSION['ID_tarea'])) echo "value='$fecha_inicio_tarea' disabled='disabled'" ;  ?>  name="fecha_inicio" size="15" id="inicio1" onfocus="javascript: funcion(this)" type="text"  />
    
    </div>
 </div>
 <div style="width:45%; float:left;">
 <div class="content2" >T&eacute;rmino</div>
	<div class="content_input">
    <input class="calendario"<?php if(isset($_SESSION['ID_tarea']))
										{
											if(substr($fecha_termino_tarea,0,4)=="0000")
												echo "value='No Def.'";
											else 
												echo "value='$fecha_termino_tarea'";
											echo "disabled='disabled'";
										}?> 
                                    name="fecha_termino" size="15" id="termino1" onfocus="javascript: funcion(this)" type="text" />
    </div>
 </div>
</fieldset></div>



<div style="width:340px;"><fieldset id="checboxes"><legend style="font-size:55%">ASIGNAR EMPLEADOS</legend>
    <div style="padding-left:5px;" class="example">
      
      <?php
      	$consulta=mysql_query("SELECT user, Nombre, ApellidoP FROM Empleado ORDER BY Nombre",$conexion);
		$total_registros=mysql_num_rows($consulta);
		if($total_registros<1)
		{
			echo "
					<label ><span></span><label style=' font-size:14px;font-style:italic;'>No se encontraron empleados registrados...</label></label>
				 ";
		}
		else
		{
			while($rowEmp=mysql_fetch_assoc($consulta))
			{
				$usuario=$rowEmp['user'];
				$nombre=$rowEmp['Nombre'];
				$apellidop=$rowEmp['ApellidoP'];
				$espacio=' ';
				if(!isset($_SESSION['ID_tarea']))//no hay sesion
				{
					echo "
							<div>
								<input id='checkbox1' style='font-size:80%;' type='checkbox' name='names[]' value='$usuario' />
								<label ><span></span><label style='font-size:14px;'>$nombre $espacio $apellidop</label></label>
							</div>
						 ";
				}
				if(isset($_SESSION['ID_tarea']))// hay sesion
				{
					$count=mysql_query("SELECT Empleado_user FROM Tareas_has_Empleado where Tareas_has_Empleado.Tareas_id=".$_SESSION['ID_tarea']." AND Tareas_has_Empleado.Empleado_user='$usuario'",$conexion);
					$total_count=mysql_num_rows($count);
					if($total_count==0)// no tiene asociada la tarea
					{
						echo "
							<div>
								<input id='checkbox1' disabled='disabled' style='font-size:80%;' type='checkbox' name='names[]' value='$usuario' />
								<label ><span></span><label style='font-size:16px;'>$nombre $espacio $apellidop</label></label>
							</div>
						 ";
					}
					if($total_count==1)
					{
						echo "
							<div>
								<input id='checkbox1' disabled='disabled' style='font-size:80%;' checked='checked' type='checkbox' name='names[]' value='$usuario' />
								<label ><span></span><label style='font-size:16px;'>$nombre $espacio $apellidop</label></label>
							</div>
						 ";
					}
				}
			}
		}
		mysql_close($conexion);
	  ?>
      
      
      <!--<div >
        <input id="checkbox2" style="font-size:80%;" type="checkbox" name="checkbox2" />
        <label ><span></span><label style="font-size:16px;">Nayivi Lopez</label></label>
      </div>
      <div >
        <input id="checkbox1" style="font-size:80%;" type="checkbox" name="checkbox" ><label ><span></span><label style="font-size:16px;">Lady Jimenez</label></label>
      </div>
      <div >
        <input id="checkbox1" style="font-size:80%;" type="checkbox" name="checkbox" ><label ><span></span><label style="font-size:16px;">Omar Zavala</label></label>
      </div>
      <div >
        <input id="checkbox1" style="font-size:80%;" type="checkbox" name="checkbox" ><label ><span></span><label style="font-size:16px;">Luis Fernando Hernandez</label></label>
      </div>
      <div >
        <input id="checkbox1" style="font-size:80%;" type="checkbox" name="checkbox" ><label ><span></span><label style="font-size:16px;">Karla Alvarez</label></label>
      </div>-->
    </div>
    
</fieldset></div>

<div style="width:340px;; margin-left:00px;"><fieldset id="checboxes"><legend style="font-size:55%">PRIORIDAD</legend>
    <div >
        <input id="checkbox1" style="margin-left:20px;" type="radio" value="Baja" name="prioridad_tarea" <?php if(isset($_SESSION['ID_tarea']))
																													{ 
																											   		if($prioridad_tarea=="Baja")
																														echo "checked='checked'";
																													echo "disabled='disabled'";
																													}?> 
        ><label ><span></span><label style="font-size:16px;">Baja</label></label>
      
        <input id="checkbox1" value="Media" style="font-size:80%; margin-left:20px;" type="radio" <?php if(!isset($_SESSION['ID_tarea'])) 
																								    		echo "checked='checked'";  
																										if(isset($_SESSION['ID_tarea']))
																										{
																											if($prioridad_tarea=="Media")
																												echo "checked='checked'";
																											echo "disabled='disabled'";
																										}
																											?> 
                                                                                                        
        name="prioridad_tarea" ><label ><span></span><label style="font-size:16px;">Media</label></label>
      
        <input id="checkbox1" value="Alta" style="font-size:80%; margin-left:20px;" type="radio" <?php if(isset($_SESSION['ID_tarea'])) 
																													{
																											   		if($prioridad_tarea=="Alta")
																														echo "checked='checked'";
																													echo "disabled='disabled'";
																													}?>
        name="prioridad_tarea" ><label ><span></span><label style="font-size:16px;">Alta</label></label>
      </div>
    <div id="boton_aceptar"><button
    	<?php 
	    if(isset($_SESSION['ID_tarea']))//ya hay sesion abierta
	   {echo "disabled='disabled'";} ?>
     class="cupid-blue">ACEPTAR</button></div>
</fieldset>
</div>

</fieldset>
</div>
</form>

<form id="formulario_subtarea" onsubmit="return submitform_sub(this)" method="post" action="actions_php/action_subtarea.php">
<div id="div_subtarea">
<fieldset class="fielset"><legend>SUBTAREA(S)</legend>
<div class="content">NOMBRE</div>
<div class="content_input"><input name="nombre_subtarea" <?php if(!isset($_SESSION['ID_tarea'])) 
													echo "disabled='disabled'" ;  ?> size="50" type="text" /></div>
<div class="content">DESCRIPCI&Oacute;N</div>
<div class="content_input">
  <label for="textarea"></label>
  <textarea name="descripcion" id="textarea" <?php if(!isset($_SESSION['ID_tarea'])) echo "disabled='disabled'" ;  ?>  cols="50" rows="5"></textarea>
</div>


<div id="fechas"><fieldset style="font-size:55%; " id="checboxes">
  <legend>FECHA</legend>
 <div style="width:45%; float:left;">
  <div class="content2" >Inicio</div>
	<div class="content_input">
    <input class="calendario" name="fecha_inicio_subtarea" <?php if(!isset($_SESSION['ID_tarea'])) 
												echo "disabled='disabled'" ;
											else
											{
												switch(substr($fecha_inicio_tarea,5,2))
												{
													case '01': $mes="ENE";
														break;
													case '02': $mes="FEB";
														break;
													case '03': $mes="MAR";
														break;
													case '04': $mes="ABR";
														break;
													case '05': $mes="MAY";
														break;
													case '06': $mes="JUN";
														break;
													case '07': $mes="JUL";
														break;
													case '08': $mes="AGO";
														break;
													case '09': $mes="SEP";
														break;
													case '10': $mes="OCT";
														break;
													case '11': $mes="NOV";
														break;
													case '12': $mes="DIC";
														break;
													default:
												}
												$format_date=substr($fecha_inicio_tarea,-2,2)."-".$mes."-".substr($fecha_inicio_tarea,0,4);
												echo "value='$format_date'"; 
											} ?> size="15" id="inicio2" onfocus="javascript: funcion(this)" type="text"  />
                                            
    
    </div>
 </div>
 <div style="width:45%; float:left;">
 <div class="content2" >T&eacute;rmino</div>
	<div class="content_input">
    <input class="calendario" name="fecha_termino_subtarea" size="15" <?php if(!isset($_SESSION['ID_tarea'])) echo "disabled='disabled'" ;  ?> id="termino2" onfocus="javascript: funcion(this)" type="text" />
    </div>
 </div>
</fieldset></div>

<div style="width:340px;; margin-left:00px;"><fieldset id="checboxes"><legend style="font-size:55%">PRIORIDAD</legend>
    <div >
        <input id="checkbox1" <?php if(!isset($_SESSION['ID_tarea'])) echo "disabled='disabled'" ;  ?> style="margin-left:20px;" type="radio" value="Baja" name="prioridad_subtarea" ><label ><span></span><label style="font-size:16px;">Baja</label></label>
      
        <input value="Media" id="checkbox1" <?php if(!isset($_SESSION['ID_tarea'])) echo "disabled='disabled'" ;  ?> style="font-size:80%; margin-left:20px;" type="radio" checked="checked"name="prioridad_subtarea" ><label ><span></span><label style="font-size:16px;">Media</label></label>
      
        <input value="Alta" id="checkbox1" <?php if(!isset($_SESSION['ID_tarea'])) echo "disabled='disabled'" ;  ?> style="font-size:80%; margin-left:20px;" type="radio" name="prioridad_subtarea" ><label ><span></span><label style="font-size:16px;">Alta</label></label>
      </div><div id="boton_aceptar"><button
	  <?php 
	  if(!isset($_SESSION['ID_tarea']))//no hay sesion abierta
	  {echo "disabled='disabled'";} ?> 
class="cupid-blue">+ AGREGAR SUBTAREA</button></div>
</fieldset></div>




</fieldset>
</div>
</form>
<form method="post" action="actions_php/terminar_sesion_id.php">
<div id="div_terminar"><button
	  <?php 
	  if(!isset($_SESSION['ID_tarea']))//no hay sesion abierta
	  {echo "disabled='disabled'";} ?>
  class="clean-gray">TERMINAR</button>
</div>
</form>

</body>
</html>