<html>


<?php
include("header.php");
$db = db_init ();

	 
	if($ask) 
	{
		$i = 0;
		while( $selection[$i] )
		{
			echo "$selection[$i]<br>:";
			$result = db_query("SELECT * FROM files WHERE pofile=\"$selection[i]\"",$db);  
			$myrow = db_fetch_row($result);
			$sqlstring = sprintf("REPLACE selection[$i] VALUES %s,%s,%s,%s",$selection[i],$myrow[1],$myrow[2],$newtr);
			echo "mysqlstring: $sqlstring";
			$i++;
		}
	}
	else
	{
		if($pofile) 
		{
			// echo $pofile;
			// CREATE TABLE files ( pofile varchar(100) NOT NULL, package varchar(20), status 
			// varchar(15), idTranslator tinyint(4), PRIMARY KEY (pofile) );
			$result = db_query("SELECT * FROM files WHERE pofile=\"$pofile\"",$db);    
			$status = db_result(($result,0,"status");
			$pack = db_result(($result,0,"package");
			$name = db_result(($result,0,"pofile");
			$cvsline =  sprintf("<A HREF=%s>%s</A>", db_result(($result,0,"cvsurl"), db_result(($result,0,"cvsreference"));
			$idtr = db_result(($result,0,"idTranslator");    
			$result1 = db_query("SELECT * FROM translators WHERE id=$idtr",$db);       
			$fullname = sprintf("%s %s",db_result(($result1,0,"first"),db_result(($result1,0,"last"));
			$email = db_result(($result1,0,"email");
			$result2 = db_query("SELECT * FROM packages WHERE package=\"$pack\"",$db); 
			$idresp = db_result(($result2,0,"idTranslator");
			$result3 = db_query("SELECT * FROM translators WHERE id=$idresp",$db);     
			$fullname3 = sprintf("%s %s",db_result(($result3,0,"first"),db_result(($result3,0,"last"));
			$email3 = db_result(($result3,0,"email");
			printf(gettext("File")." :<b> %s </b> <i> ".gettext("from package %s")."</i> (".gettext("state").": %s)<p>",$name,$pack,$status);
			printf(gettext("File Maintainer").": <b><a href=\"mailto:nospam-%s.nospam\">%s</a></b>. <br>",$email,$fullname);
			printf(gettext("Package Maintainer").": <b><a href=\"mailto:nospam-%s.nospam\">%s</a></b>.<br>",$email3,$fullname3);
			printf("Send translated files to %s<br>",$cvsline);
		}
		else
		{
			if($package) 
			{
				echo $package; 
				// CREATE TABLE files ( pofile varchar(100) NOT NULL, package varchar(20), 
				// status varchar(15), idTranslator tinyint(4), PRIMARY KEY (pofile) );
				$result = db_query("SELECT * FROM files WHERE package=\"$package\"",$db);
				echo "<form action=requests.php method=\"POST\">";
				echo "<table border=1>\n";
				echo "<tr><td>".gettext("File")."</td><td>".gettext("Maintainer")."</td><td>";
				echo gettext("State")."</td><td>".gettext("Select")."</td></tr>\n";
					while ($myrow = db_fetch_row($result)) 
					{
						$result1 = db_query("SELECT * FROM translators WHERE id=$myrow[3]",$db);
						printf("<tr><td><a href=%s?pofile=%s>%s</a> </td><td><a href=\"mailto:nospam-%s.nospam\">%s %s </a></td><td>%s</td>", $PHP_SELF,$myrow[0],$myrow[0],db_result(($result1,0,"email"), db_result(($result1,0,"first"),db_result(($result1,0,"last"),$myrow[2]);
						if($myrow[2]!="requested" && $myrow[2]!="locked")
						{
							printf("<td><input type=checkbox value=\"%s\" name=\"selection[]\"></td></tr>\n",$myrow[0]);
						}
						else
						{
							printf("</tr>\n",$myrow[0]);
						}
					}
				echo "</table><br>";
				echo "<input type=\"submit\" value=\"".gettext("Ask for allocation of the selected packages")."\" name=\"ask\" ><br>";
				echo "<input type=\"submit\" value=\"".gettext("Set status")."\" name=\"stato\" > : <input name=\"newstatus\" value=\"done\"> (done,locked,new,unassigned,in progress,...)<br>";
				echo "</form>\n"; 
			}
			else
			{
				// CREATE TABLE packages (package varchar(20) NOT NULL, idTranslator tinyint(4), 
				// PRIMARY KEY (package));
				$result = db_query("SELECT * FROM packages ORDER BY package",$db);
				echo "<table border=1>\n";
				echo "<tr><td>".gettext("Package")."</td><td>".gettext("Maintainer")."</tr>\n";
				while ($myrow = db_fetch_row($result)) 
				{
					$result1 = db_query("SELECT * FROM translators WHERE id=$myrow[1]",$db);
					printf("<tr><td><a href=%s?package=%s>%s</a> </td><td><a href=\"mailto:nospam-%s.nospam\">%s %s </a></td></tr>\n", $PHP_SELF,$myrow[0],$myrow[0],db_result(($result1,0,"email"), 
					db_result(($result1,0,"first"),db_result(($result1,0,"last"));
				}
				echo "</table>\n";
			}
		}
	}
include("footer.php");
?>
</body>
</html>
