Beispiel #1
0
			// fix end

			if (!$ncomps) die("Cannot open this round: no one qualified");
			$qualified = cased_mysql_result($event,0,"r".$round."_groupsize");
			$maxtoproceed = floor($ncomps*.75);
			if (!$maxtoproceed) die("Cannot open this round: not enough competitors");
			if ($maxtoproceed < $qualified)
			{
				$_SESSION["c_error"] = "WARNING!\\n\\nThere were $ncomps competitors in the previous round. $qualified were set to proceed, but according to regulations, only $maxtoproceed at most can proceed. Following rounds could also be affected by this change.";
				$qualified = $maxtoproceed;
			}
			$classification = 0;
			$registered = 0;
			$lasta = "";
			$lastb = "";
			while ($row=cased_mysql_fetch_array($list))
			{
				$registered++;
				if ($row["average"]!=$lasta || ($timetype!=3 && $row["best"]!=$lastb))
				{
					$classification = $registered;
					$lasta = $row["average"];
					$lastb = $row["best"];
				}
				if ($classification<=$qualified)
				{
					strict_query("INSERT INTO $regstable VALUES (?,?," .$row["comp_id"]. ")", array($cat_id,$round));
				} else
				{
					$registered--;
					break;
Beispiel #2
0
function createSheetEvtRnd($sheet,$cat_id,$round,$lround,$timelimit)
{
	global
		$ssC,$ssB,$ssR,$ssTs,$ssTm,$ssBC,$ssBR,$ssBG1,$ssBG2,
		$compstable, $regstable, $timestable,
		$events,$evt, 
		$f_header,$f_headerc,$f_time;
	//
	$category = strict_query("SELECT * FROM categories WHERE id=".$cat_id);
	$timetype = cased_mysql_result($category,0,"timetype");
	$inseconds = cased_mysql_result($category,0,"inseconds");
	$format = strict_query("SELECT * FROM formats WHERE id=".cased_mysql_result($events,$evt,"r".$round."_format"));
	$times = cased_mysql_result($format,0,"times");
	$avgtype = cased_mysql_result($format,0,"avgtype");

	$query =
		"SELECT $regstable.*, $compstable.name, $compstable.WCAid, $timestable.t1, $timestable.t2, $timestable.t3, $timestable.t4, $timestable.t5, $timestable.average, $timestable.best, countries.name AS country FROM $regstable ".
		"JOIN $timestable ON ($regstable.cat_id=$timestable.cat_id AND $regstable.round=$timestable.round AND $regstable.comp_id=$timestable.comp_id) ".
		"JOIN $compstable ON ($regstable.comp_id=$compstable.id) ".
		"JOIN countries ON ($compstable.country_id=countries.id) ".
		"WHERE $regstable.cat_id=" .$cat_id. " AND $regstable.round=" .$round." ORDER BY $timestable.t1 IS NULL, $timestable.average=\"\", $timestable.average, $timestable.best, $regstable.comp_id";
	$result = strict_query($query);
	if (!sql_num_rows($result)) // trick to generate 32 empty lines with formulas
		$result = strict_query("SELECT NULL as name, NULL as country, NULL as WCAid, NULL as t1, NULL as t2, NULL as t3, NULL as t4, NULL as t5 FROM countries LIMIT 32");
	//
	$sheet
		->setTitle(cased_mysql_result($category,0,"abbr")."-".$round);
	$sheet
		//->setCellValue("A1", cased_mysql_result($category,0,"name")." - round $round")
		->setCellValue("A1", cased_mysql_result($category,0,"name")." - ".roundString($round,$lround,$timelimit))
		->setCellValue("A2", "Format: ".cased_mysql_result($format,0,"name"))
		->setCellValue("A3", ($timetype==2?"number of moves":($inseconds?"time in seconds (ss.hh)":"time in minutes (m:ss.hh)")))
		->setCellValue("A4", "Position")
		->setCellValue("B4", "Name")
		->setCellValue("C4", "Country")
		->setCellValue("D4", "WCA id");
	$sheet
		->setSharedStyle($ssB, "A1:A3")
		->setSharedStyle($ssB, "A4:D4");
	if ($timetype!=3)
	{
		if ($times==1)
		{
			$sheet->setCellValue("E4", "Result");
			$letterLT = "E";
			$letterBest = "E";
		}
		else
		{
			for ($x=1;$x<=$times;$x++)
				$sheet->setCellValue(chr(68+$x)."4", $x);
			$letterLT = chr(67+$x);
			$letterBest = chr(68+$x);
		}
		$sheet
			->setSharedStyle($ssBC, "E4:".chr(68+$times)."4")
			->setSharedStyle($ssBR, chr(69+$times)."4:Z4");
		$x = 69+$times;
	}
	else
	{	
		for ($x=1;$x<=$times;$x++)
			$sheet
				->setCellValue(chr(69+($x-1)*4)."4", "tried")
				->setCellValue(chr(69+($x-1)*4+1)."4", "solved")
				->setCellValue(chr(69+($x-1)*4+2)."4", "seconds")
				->setCellValue(chr(69+($x-1)*4+3)."4", "score $x");
		$sheet
			->setSharedStyle($ssBR, "E4:Z4");
		$x = 69+($x-1)*4;
	}
	if ($times>1) $sheet->setCellValue(chr($x++)."4", "Best");
	$sheet->setCellValue(chr($x++)."4", "WR");
	if ($avgtype==0)
	{
		$letterAvg = chr($x+1);
		$sheet
			->setCellValue(chr($x++)."4", "Worst")
			->setCellValue(chr($x++)."4", "Average")
			->setCellValue(chr($x++)."4", "WR");
	}
	elseif ($avgtype==1)
	{
		$letterAvg = chr($x);
		$sheet
			->setCellValue(chr($x++)."4", "Mean")
			->setCellValue(chr($x++)."4", "WR");
	}
	$line = 5;
	$lineb = 4;
	while ($row=cased_mysql_fetch_array($result))
	{
		$sheet
			->setCellValue("B$line", $row["name"])
			->setCellValue("C$line", $row["country"])
			->setCellValue("D$line", $row["WCAid"]);
		if ($timetype!=3)
		{
			for ($x=1;$x<=$times;$x++)
				$sheet->setCellValue(chr(68+$x).$line, formatTime($row["t$x"],$timetype,$inseconds));
			$x = 69+$times;
			if ($times>1) 
				$sheet
					->setCellValue(chr($x++).$line, "=IF(MIN(E$line:$letterLT$line)>0,MIN(E$line:$letterLT$line),IF(COUNTBLANK(E$line:$letterLT$line)=$times,\"\",\"DNF\"))");
			if ($avgtype==0)
			{
				$x++;
				$sheet
					->setCellValue(chr($x++).$line, "=IF(COUNTBLANK(E$line:I$line)>0,\"\",IF(COUNTIF(E$line:I$line,\"DNF\")+COUNTIF(E$line:I$line,\"DNS\")>0,\"DNF\",MAX(E$line:I$line)))")
					->setCellValue(chr($x++).$line, "=IF(COUNTBLANK(E$line:I$line)>0,\"\",IF(COUNTIF(E$line:I$line,\"DNF\")+COUNTIF(E$line:I$line,\"DNS\")>1,\"DNF\",IF(COUNTIF(E$line:I$line,\"DNF\")+COUNTIF(E$line:I$line,\"DNS\")>0,(SUM(E$line:I$line)-J$line)/".($times-2).",(SUM(E$line:I$line)-J$line-L$line)/".($times-2).")))");
			}
			elseif ($avgtype==1)
			{
				$x++;
				$sheet
					->setCellValue(chr($x++).$line, "=IF(COUNTBLANK(E$line:G$line)>0,\"\",IF(COUNTIF(E$line:G$line,\"DNF\")+COUNTIF(E$line:G$line,\"DNS\")>0,\"DNF\",AVERAGE(E$line:G$line)))"); 
			}
			if (isset($letterAvg))
				$sheet
					->setCellValue("A$line", "=IF(AND($letterAvg$lineb=$letterAvg$line,$letterBest$lineb=$letterBest$line),A$lineb,ROW()-4)");
			else
				$sheet
					->setCellValue("A$line", "=IF($letterBest$lineb=$letterBest$line,A$lineb,ROW()-4)");
			if ($timetype==2)
				$sheet->setSharedStyle($ssR, "E$line:Z$line");
			elseif ($inseconds)
				$sheet->setSharedStyle($ssTs, "E$line:Z$line");
			else
				$sheet->setSharedStyle($ssTm, "E$line:Z$line");
		}
		else
		{
			$formula = "";
			$formula_b = "";
			for ($x=1;$x<=$times;$x++)
			{
				if (!$row["t$x"] || $row["t$x"]=="DNF" || $row["t$x"]=="DNS")
					$sheet->setCellValue(chr(69+($x-1)*4).$line, $row["t$x"]);
				else
					$sheet
						->setCellValue(chr(69+($x-1)*4).$line, (int)substr($row["t$x"],2,2))
						->setCellValue(chr(69+($x-1)*4+1).$line, (int)substr($row["t$x"],0,2))
						->setCellValue(chr(69+($x-1)*4+2).$line, round(formatTime(substr($row["t$x"],4,9),1,true))); // Disagree with that "round"
				$lE = chr(69+($x-1)*4);
				$lF = chr(69+($x-1)*4+1);
				$lG = chr(69+($x-1)*4+2);
				$lH = chr(69+($x-1)*4+3);
				$sheet
					->setCellValue(chr(69+($x-1)*4+3).$line, "=IF($lE$line=\"DNS\",-2,IF($lE$line=\"DNF\",-1,(99-$lF$line+$lE$line-$lF$line)*10000000+$lG$line*100+$lE$line-$lF$line))") // Changed formula to suit my records (DNFs were discarded before)
					->setSharedStyle($ssBG1, chr(69+($x-1)*4+3).$line)
					->getColumnDimension(chr(69+($x-1)*4+3))->setWidth(10);
				if ($formula) $formula .= ",";
				$formula .= "IF($lH$line<0,1000000000,$lH$line)";
				if ($formula_b) $formula_b .= ",";
				$formula_b .= "$lH$line<0";
			}
			if ($times==1)
			{
				$sheet
					->setCellValue("A$line", "=IF(H$lineb=H$line,A$lineb,ROW()-4)");
			}
			else
			{
				$letterBest = chr(69+($x-1)*4);
				$sheet
					->setCellValue($letterBest.$line, "=IF(AND($formula_b),-1,MIN($formula))")
					->setCellValue("A$line", "=IF($letterBest$lineb=$letterBest$line,A$lineb,ROW()-4)")
					->setSharedStyle($ssBG2, $letterBest.$line)
					->getColumnDimension(chr(69+($x-1)*4))->setWidth(10);
			}
		}
		$line++;
		$lineb++;
	}
	$sheet->getColumnDimension('B')->setWidth(20);
	$sheet->getColumnDimension('C')->setWidth(10);
	$sheet->getColumnDimension('D')->setWidth(15);
}
Beispiel #3
0
function print_txt_sch($fn)
{
	global $competition, $eventstable;
	//
	$r = strict_query("SELECT name, abbr FROM categories");
	while ($row=cased_mysql_fetch_array($r))
		$categories[$row["abbr"]] = $row["name"]; 
	$r = strict_query("SELECT * FROM $eventstable JOIN categories ON $eventstable.id=categories.id");
	while ($row=cased_mysql_fetch_array($r))
	{
		$events[_RX][$row["abbr"]] = 0;
		$events[_ID][$row["abbr"]] = $row["id"];
		$x = 1;
		while ($x <= 4 && $row["r$x"."_open"]) $x++;
		$events[_RTOP][$row["abbr"]] = $x-1;
	}
	//
	$fh = fopen($fn,'r');
	$ver = trim(fgets($fh));
	if ($ver != "00")
	{
		print_txt01_sch($fh,$categories,$events);
		return;
	}
	//
	echo "<h2>".cased_mysql_result($competition,0,"name")." Schedule</h2><p>";
	$timezone = fgets($fh);
	$line = fgets($fh);
	while ($line)
	{
		echo date("l - F jS, Y",strtotime($line))."<p>";
		echo "<table border=0 cellpadding=0 cellspacing=0 class=SCH><tr><th height=17 width=50>Start</th><th width=200>Event</th><th width=100>Round</th><th width=80>Format</th></tr>";
		$line = fgets($fh);
		while ($line && !strtotime($line))
		{
			$time = fetch($line);
			$abbr = fetch($line);
			echo "<tr".($categories[$abbr]?"":" class=rest").">";
			echo "<td height=17 align=right>$time</td>";
			if ($categories[$abbr])
			{
				echo "<td>".$categories[$abbr]."</td>";
				echo "<td>";
				if (isset($events[_RX][$abbr]))
				{
					$events[_RX][$abbr] = $events[_RX][$abbr] + 1;
					if ($events[_RX][$abbr] <= $events[_RTOP][$abbr])
						echo "<a href='live.php?cid=" .$_GET["cid"]. "&cat=" .$events[_ID][$abbr]. "&rnd=" .$events[_RX][$abbr]. "'>" .fetch($line). "</a>";
					else
						echo fetch($line);
				}
				else
					echo fetch($line);
				echo "</td>";
				echo "<td>".fetch($line)."</td>";
			}
			else
				echo "<td colspan=3 align=center>$abbr</td>";
			echo "<tr>";
			//
			$line = fgets($fh);
		}
		echo "</table><p><br>";
	}
	fclose($fh);
	//
	echo "All times are $timezone";
}
Beispiel #4
0
}
elseif (array_key_exists("aofr",$_GET))
{
	$ts = new TS();
	$ts->AddFont('DejaVu','','DejaVuSans.ttf',true);
	$ofr = strict_query("SELECT $eventstable.id, categories.name, times FROM $eventstable JOIN categories ON (categories.id=$eventstable.id) JOIN formats ON (formats.id=$eventstable.r1_format) WHERE r1_open=1 ORDER BY $eventstable.id");
	while ($rowe=cased_mysql_fetch_array($ofr))
	{
		$query = "SELECT id, name FROM $compstable WHERE cat".$rowe["id"]."=\"X\"";
		if ($_SESSION["c_id"]==$sebastien)
			$query .= " ORDER BY id";
		else
			$query .= " ORDER BY name";
		$comps = strict_query($query);
		$count = 0;
		while ($row=cased_mysql_fetch_array($comps))
		{
			$compname = preg_replace("/\(.*\)/","",$row["name"]);
			$count++;
			$ts->Timesheet($row["id"], $compname, $rowe["name"], 1, $rowe["times"], $count);
		}
	}
	$ts->SetDisplayMode("fullpage","single");
	$ts->Output(preg_replace("/\W/","",$_SESSION["c_name"])." - Scorecards.pdf", "I");
}
else
{
	$ts = new TS();
	for ($x=1;$x<=4;$x++)
		$ts->Timesheet("","","","",5,0);
	$ts->SetDisplayMode("fullpage","single");
Beispiel #5
0
<?
require_once "lib.php";
require_once "lib_ref_admin.php";
require_once "lib_get.php";

$_GETid = _GET_num("id");

if ($_GETid) 
{
	require_once "db.php";
	//
	$result = strict_query("SELECT * FROM $eventstable WHERE id=?", array($_GETid));
	if (sql_num_rows($result)==1)
	{
		$event = cased_mysql_fetch_array($result);
		$round = 0;
		do {	
			$round += 1;
		} while($round < 4 && $event["r".$round]);
		$rnd = "r".$round;
		if (!$event[$rnd])
		{
			$prnd = "r".($round-1);
			if ($event[$prnd."_open"])
				$gs = sql_num_rows(strict_query("SELECT round FROM $regstable WHERE cat_id=? AND round=?", array($_GETid,$round-1)));
			else
				$gs = $event[$prnd."_groupsize"];
			$gs = floor($gs*.75);
			if ($gs >= 2)
			{
				strict_query("UPDATE $eventstable SET ". $rnd."=1, ". $rnd."_format=". $prnd."_format, " .$rnd."_groupsize=". $gs.", " .$rnd."_open=0 WHERE id=?", array($_GETid));
Beispiel #6
0
					if (isset($cats[$col]) && $sheet->getCellByColumnAndRow($col,$row)->getValue().""=="1")
						toggleReg($err,$cats[$col]);		
			}
			else
				$errors .= $err."<br>";
		}
		$row++;
	}
}
ELSE // ---------------------------------------------------------------------------------------------------------------------
{
	fseek($h,0);
	//
	$categories = strict_query("SELECT id, abbr FROM categories");
	$cats = array();
	while ($rcat=cased_mysql_fetch_array($categories))
		$cats[$rcat["abbr"]] = $rcat["id"];
	//
	$ncomp = 0;
	$nimp = 0;
	$errors = "";
	$headersdone = FALSE;
	while (($line = fgets($h))!==FALSE)
	{
		$line = csvstring_to_array(trim($line));
		if (!$headersdone)
		{
			$col = 0;
			foreach ($line as $value)
			{
				$value = strtolower($value);
require_once "lib_get.php";

$_GETid = _GET_num("id");
$_GETfld = _GET_fld("fld");

if ($_GETid && $_GETfld) 
{
	require_once "db.php";
	//
	$result = strict_query("SELECT * FROM $eventstable WHERE id=?", array($_GETid));
	if (sql_num_rows($result)==1)
	{
		$fld = substr($_GETfld,strpos($_GETfld,"_"));
		switch ($fld)
		{
			case "_format":
				$formats = strict_query("SELECT * FROM formats ORDER BY id");
				while($row=cased_mysql_fetch_array($formats)) $fmts[] = $row["name"];
				$category = strict_query("SELECT possible_formats FROM categories WHERE id=".cased_mysql_result($result,0,"id"));
				$possible_formats = cased_mysql_result($category,0,"possible_formats");
				$value = cased_mysql_result($result,0,$_GETfld);
				$newValue = (int)substr ($possible_formats, (strpos($possible_formats,"".$value)+1) % strlen($possible_formats), 1);
				strict_query("UPDATE $eventstable SET $_GETfld=$newValue WHERE id=?", array($_GETid));
				echo $fmts[$newValue-1];
				break;
		}
	}
	sql_close();
}
?>
Beispiel #8
0
function listComps($txt)
{
	global $result, $count, $IE, $live;
	$width = 300;
	$twidth = sql_num_rows($result)*$width;
	echo "<div class=header>";
	if ($IE) 
		echo "<span style='vertical-align:-6px;margin:12px;'>$txt</span></div>";
	else
		echo "<img src='img/header-tip.gif'><span style='vertical-align:8px'>$txt</span></div>";

	echo "<DIV class=list>";
	//echo "<P style='width:".$twidth."px;'>";
	echo "<table cellpadding=0 cellspacing=0 width=".$twidth."><tr valign=top>";
	while ($row=cased_mysql_fetch_array($result))
	{
		$count++;
		//echo "<SPAN style='width:".$width."px;'>";
		echo "<td><div style='width:".$width."px;'>";
		echo "<B class=p>";
		if ($live)
			echo "<a href='live.php?cid=".$row["id"]."'>";
		else
			echo "<a style='cursor:pointer;' onclick='showPWInput(".$row["id"].",$count);'>";
		echo "<img src='img/cube-icon.gif' style='vertical-align:-5px;'> ".$row["name"]."</a></B><br>";
		echo "<span id=div".$count." style='display:none;'></span>";
		echo "<B class=pp>".datesToStr($row["date_b"],$row["date_e"])."</B><br>";
		echo "<B class=pp>".$row["place"]." - ".$row["countryname"]."</B><br>";
		if ($website = $row["website"])
		{
			$pos = strpos($website,"/");
			if (!$pos)
				$website_host = $website;
			else
				$website_host = substr($website,0,$pos);
			if (substr($website,0,7) != "http://") $website = "http://$website";
			echo "<B class=pp><a href='$website' target=_blank>$website_host</a></B><br>";
		}
		//echo "</SPAN>";
		echo "</div></td>";
	}
	echo "</tr></table>";
	//echo "</P>";
	echo "</DIV><p>";
}
Beispiel #9
0
function createEvtRnd($cat_id,$round,$lround,$timelimit)
{
	global
		$compstable, $regstable, $timestable,
		$events, $evt,
		$fname;
	//
	$formats = array(1=>"a",2=>"m",3=>"3",4=>"2",5=>"1");
	//
	$category = strict_mysql_query("SELECT * FROM categories WHERE id=".$cat_id);
	$timetype = cased_mysql_result($category,0,"timetype");
	$inseconds = cased_mysql_result($category,0,"inseconds");
	$format = strict_mysql_query("SELECT * FROM formats WHERE id=".cased_mysql_result($events,$evt,"r".$round."_format"));
	$times = cased_mysql_result($format,0,"times");
	$avgtype = cased_mysql_result($format,0,"avgtype");
	$formatId = $formats[cased_mysql_result($format,0,"id")];

	$query =
		"SELECT $regstable.*, $compstable.name, $compstable.WCAid, $timestable.t1, $timestable.t2, $timestable.t3, $timestable.t4, $timestable.t5, $timestable.average, $timestable.best, countries.name AS country FROM $regstable ".
		// people seem not to like this - "LEFT OUTER ".
		"JOIN $timestable ON ($regstable.cat_id=$timestable.cat_id AND $regstable.round=$timestable.round AND $regstable.comp_id=$timestable.comp_id) ".
		"JOIN $compstable ON ($regstable.comp_id=$compstable.id) ".
		"JOIN countries ON ($compstable.country_id=countries.id) ".
		"WHERE $regstable.cat_id=" .$cat_id. " AND $regstable.round=" .$round." ORDER BY $timestable.t1 IS NULL, $timestable.average=\"\", $timestable.average, $timestable.best, $regstable.comp_id";
	$result = strict_mysql_query($query);
	//

	echo "-- ".cased_mysql_result($category,0,"name")." - ".roundString($round,$lround,$timelimit, $rId)."\r\n";
	$lastA = "***";
	$lastB = "***";
	$count = 0;
	while ($row=cased_mysql_fetch_array($result))
	{
		$count++;
		echo "insert into Results (pos, personName, personId, countryId, competitionId, eventId, roundId, formatId, value1, value2, value3, value4, value5, best, average, regionalSingleRecord, regionalAverageRecord) values (";

		if ($row["average"]!=$lastA || $row["best"]!=$lastB) 
		{
			$position = $count;
			$lastA = $row["average"];
			$lastB = $row["best"];
		}
		echo "$position,";

		echo "\"".$row["name"]."\",";
		echo "\"".$row["WCAid"]."\",";
		echo "\"".$row["country"]."\",";
		echo "\"$fname\",";

		echo "\"".cased_mysql_result($category,0,"abbr")."\",";
		echo "\"$rId\",";
		echo "\"$formatId\",";

		for ($x=1;$x<=5;$x++)
			if ($x<=$times)
				echo formatTime($row["t$x"],$timetype).",";
			else
				echo "0,";

		echo formatTime($row["best"],$timetype).",";
		if ($formatId>"3")
			echo formatTime($row["average"],$timetype).",";
		else
			echo "0,";

		echo "\"\",\"\");\r\n";
	}
	echo "\r\n\n";
}
Beispiel #10
0
	}
}
?>

<tr style="background-color:white;">
<form name=frm onsubmit="return(submitForm());">
<td colspan=2><!--                                       width:118px=86+26+3+3px -->
<input type=text id=WCAid name=WCAid maxlength=10 style="width:118px;text-transform:uppercase;" onblur='validateWCAid(this);'></td>
<td><input type=text id=competitor name=competitor maxlength=50 style="width:200px;"></td>
<td><input type=text id=birth name=birth maxlength=10 onkeypress='birthKeyPress(event);' style="width:72px;" onblur='validateBirth(this)'></td>

<td><select id=country name=country style="width:100px;">
<option value=""></option>
<?
$result = strict_query("SELECT * FROM countries");
while ($row=cased_mysql_fetch_array($result))
{
	echo "<option value=\"" . $row["id"] . "\"";
	if ($row["id"]==$_SESSION["c_country"]) echo " selected";
	echo ">" . $row["name"] . "</option>\r\n";
}
?>
</select></td>

<td><select id=gender name=gender style="width:40px;">
<option value=""></option>
<option value="m">male</option>
<option value="f">female</option>
</select></td>
<?
if (!$ncomps)