<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */

require "LogIndExtract.php";
require "SecPeriod.php";
require "auth/confcol.php";

# Displays logros e indicadores possibly with a message, and allow to edit some
# @author Vladimir Támara
# Public domain. 2004. No warranties. http://structio.sourceforge.net/sigue
function showLogInd($dircol,$nomasig,$nomgrado,$nomprof,$my_sec,$my_cla,
	$year,$siguientes,$msg) {

	$title=$GLOBALS['t_logros']. " y ".$GLOBALS['t_indicador']." de ".$nomprof."<br> Año: ".$year.
		" Asignatura:".$nomasig." en ".$nomgrado;
	require "header.php";

	$tli=new LogIndExtract($dircol, $year, $my_cla);
	$indicadores=$tli->indicadores();
	$logros=$tli->logros();
	$recuperables=$tli->recuperables();
	$tpi=new SecPeriod($dircol."/planest/".$year."/".$my_sec, 
		$my_cla);
	$perind=$tpi->logindper();
	if ($msg!="") {
		echo "<div align=\"center\"><font color=\"#FF0000\">$msg</font></div><p/>";
	}
	echo "<form action=\"actlogind.php\" method=\"post\" enctype\"multipart/form-data\">";  # enctype to allow entire ISO10646 character set (ref HTML 4.0 spec)
	echo "<table border=\"1\" >";
	echo "<tr><th>Id. ".$GLOBALS['t_logro']."</th><th>Texto del ".$GLOBALS['t_logro']."</th></tr>";
	foreach ($logros as $il => $logro) {
		echo "<tr><td>$il<br>";
		$pelim=true;
		if (isset($indicadores[$il])) {
			foreach ($indicadores[$il] as $ii => $ind) {
				if (isset($perind[$il][$ii])) {
					$pelim=false;
				}
			}
		}
		if ($pelim) {
			echo "<button type=\"submit\" name=\"submit\" value=\"eliml_$il\"><font size=\"-1\">Eliminar ".$GLOBALS['t_logro']."</font></button>";
		}
		echo "</td>";
		echo "<td>".stripslashes($logro)." <br>
<table border=\"1\">
<tr><th>Id. ".$GLOBALS['t_indicador']."</th><th>Texto del ".$GLOBALS['t_indicador']."</th><th>Tipo</th><th>Períodos</th></tr>";
		if (isset($indicadores[$il])) {
			foreach ($indicadores[$il] as $ii => $ind) {
				echo "<tr><td width=\"20%\">$ii<br>";
				$pelim=true;
				if (!isset($perind[$il][$ii])) {
					echo "<button type=\"submit\" name=\"submit\" value=\"elimi_$il.$ii\"><font size=\"-1\">Eliminar ".$GLOBALS['t_indicador']."</font></button><br>";
				}
				echo "</td>";
				echo "<td width=\"40%\">".stripslashes($ind)."</td>";
				echo "<td width=\"10%\">";
				if ($recuperables[$il][$ii]) {
					echo "Recuperable";
				}
				else {
					echo "No Rec.";
				}
				echo "</td>";
				echo "<td width=\"30%\">";
				$se=$siguientes;
				$numref=0;
				if (isset($perind[$il][$ii])) {
					foreach ($perind[$il][$ii] as $kp => $per) {
						echo "<table><tr><td>$per</td><td>";
						if (in_array($per,$siguientes) 
					&& (!$GLOBALS['VALORAR'] 
					|| $per!=$_SESSION['periodo'])) {
							echo "<button type=\"submit\" name=\"submit\" value=\"elimr_$per.$il.$ii\"><font size=\"-1\">Eliminiar referencia</font></button><br>";
							unset($se[array_search($per,$se)]);
						}
						echo "</td></tr></table>";
						$numref++;
					}
       	 			}
				if ($GLOBALS['VALORAR'] &&
					in_array($_SESSION['periodo'],$se)) {
					unset($se[array_search($_SESSION['periodo'],$se)]);
				}
				if (isset($se) && sizeof($se)>0
					&& (!isset($recuperables[$il][$ii])
					|| !$recuperables[$il][$ii]
					|| ($recuperables[$il][$ii]
					&& $numref==0)))  {
					echo "<table><tr><td>";
					$ref=isset($_POST["ref_$il*$ii"])?
						$_POST["ref_$il*$ii"]:'';
					showselect($se,"ref_$il*$ii",$ref); # Toco poner * en lugar de . porque el . era convertido a _
					echo "</td><td><button type=\"submit\" class=\"alerta\" name=\"submit\" value=\"añadirr_$il.$ii\"><font size=\"-1\">Añadir ref.</font></button></td></tr></table>";
				}
				echo "</td></tr>\n";
			}
		}
		$idind=isset($_POST["idind_$il"])?$_POST["idind_$il"]:'';
		echo "<tr><td><input type=\"text\" name=\"idind_$il\" value=\"".
			$idind.	
			"\"></input></td>";
		$textoind=isset($_POST["textoind_$il"]) ? 
			$_POST["textoind_$il"] : '';
		echo "<td><input type=\"text\" name=\"textoind_$il\" value=\"".
			$textoind.	
			"\"></input></td>";
		$s1=$s2="";
		if ($_POST["rec_$il"]="si") { 
			$s1="selected";
		}
		else if ($_POST["rec_$il"]="no") {
			$s2="selected";
		}
		echo "<td><select name=\"rec_$il\"><option value=\"si\" $s1>Recuperable</option><option value=\"no\" $s2>No Rec.</option></select></td>";
		echo "<td><button type=\"submit\" name=\"submit\" value=\"añadiri_$il\"><font size=\"-1\">Añadir ".$GLOBALS['t_indicador']."</font></button></td></tr>";
        	echo "</table></td></tr>"; 
	}
	$idlog=isset($_POST['idlog'])?$_POST['idlog']:'';
	echo "<tr><td><input type=\"text\" name=\"idlog\" value=\"".
		$idlog.
		"\"></input><br>";
	echo "<button type=\"submit\" name=\"submit\" value=\"añadirl\"><font size=\"-1\">Añadir ".$GLOBALS['t_logro']."</font></button></td>";

	$textolog=isset($_POST["textolog"])?$_POST["textolog"]:'';
	echo "<td><input type=\"text\" name=\"textolog\" value=\"".
		"\"></input></td></tr>";
	echo "</table>
	</form>";

	require "footer.php";
}

?>

