Пример #1
0
function printEvent($event, &$coltimewidth, $print_headers=true,$_cat_id=NULL,$_round=NULL,$comp_id=NULL)
{
	global 
		$cid, $showmode,
		$regstable, $compstable, $timestable, $eventstable;
	//
	if ($event)
		global $cat_id, $round;
	else
	{
		$cat_id = $_cat_id;
		$round = $_round;
		$event = cased_mysql_fetch_array(strict_query("SELECT * FROM $eventstable WHERE id=?",array($cat_id)));
	}
	//
	$category = strict_query("SELECT * FROM categories WHERE id=?",array($cat_id));
	$timetype = cased_mysql_result($category,0,"timetype");
	if ($timetype==1)
		$coltimewidth = 60;
	elseif ($timetype==2)
		$coltimewidth = 30;
	else
		$coltimewidth = 100;
	//
	$format = strict_query("SELECT * FROM formats WHERE id=".$event["r".$round."_format"]);
	$times = cased_mysql_result($format,0,"times");
	$avgtype = cased_mysql_result($format,0,"avgtype");
	if (cased_mysql_result($category,0,"canhavetimelimit") && $round==1)
	{
		$timelimit = $event["timelimit"];
		if($timelimit) $timelimit = substr("000:00.00",0,9-strlen($timelimit)).$timelimit;
		if (!timelimitNum($timelimit)) $timelimit = "";
	}
	else
		$timelimit = "";
	//
	$nrounds = 4;
	while ($nrounds>1 && !$event["r$nrounds"]) $nrounds--;
	//
	// Do we know who proceeded?
	if ($round < $nrounds && $event["r".($round+1)."_open"])
	{
		$resultac = strict_query("SELECT comp_id FROM $regstable WHERE cat_id=? AND round=?", array($cat_id,$round+1));
		$actuallyClassified = array();
		while ($rowac=cased_mysql_fetch_array($resultac))
			$actuallyClassified[$rowac["comp_id"]] = true;
		$rowac = null;
		$resultac = null;
	}
	else
		$actuallyClassified = null;
	//
	// $cat_st = cased_mysql_result($category,0,"name")." - round ".$round;
	$cat_st = cased_mysql_result($category,0,"name")." - ".roundString($round,$nrounds,(cased_mysql_result($category,0,"canhavetimelimit") && $round==1 && $timelimit));
	if ($timelimit) $cat_st .= " - cutoff ".formatTime($timelimit,1);
	if (!$comp_id && !$showmode)
		echo "<div style='margin:0 0 6px 0;'>$cat_st</div>";

	// scores table - begin
	if ($print_headers)
	{
		if ($comp_id) echo "<br>";
		echo "<table class=TH cellspacing=0 border=0>";
		echo "<tr><th class=col_cl>#</th>";
		if (!$comp_id)
			echo "<th style='width:200px;text-align:left;'>name</th><th style='width:101px;text-align:left;'>country</th>";
		else
			echo "<th style='width:301px;text-align:left;'>event / round</th>";
		for ($x=1;$x<=$times;$x++)
			echo "<th style='width:".($coltimewidth+1)."px;'>t$x</td>";
		switch($avgtype)
		{
		case 0:
			echo "<th style='width:".($coltimewidth)."px;'>average</th>";
			break;
		case 1:
			echo "<th style='width:".($coltimewidth)."px;'>mean</th>";
			break;
		}
		echo "<th style='width:".($coltimewidth)."px;'>best</th>";
		echo "</tr></table>";
		//
		echo "<table class=TD cellspacing=0 border=0>";
	}
	//
	$query =
		"SELECT $regstable.*, $compstable.name, $timestable.t1, $timestable.t2, $timestable.t3, $timestable.t4, $timestable.t5, $timestable.average, $timestable.best, countries.name AS cname FROM $regstable ".
		"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 (countries.id=$compstable.country_id) ".
		"WHERE $regstable.cat_id=? AND $regstable.round=? ORDER BY $timestable.t1 IS NULL, $timestable.average='', $timestable.average, $timestable.best, $compstable.name";
	$list = strict_query($query,array($cat_id,$round));
	if (!$actuallyClassified)
		$qualified = (
			$round<4 && $event["r".($round+1)] ?
			$event["r".($round+1)."_groupsize"] :
			3
			);
	$classification = 0;
	$count = 0;
	$lasta = "";
	$lastb = "";
	while ($row=cased_mysql_fetch_array($list))
	{
		$count++;
		if (!$row["t1"])
			$classification = "";
		elseif ($row["average"]!=$lasta || ($timetype!=3 && $row["best"]!=$lastb))
		{
			$classification = $count;
			$lasta = $row["average"];
			$lastb = $row["best"];
		}
		if (!$actuallyClassified)
			if ($qualified > 0) // Elegible to proceed?
			{
				if ($row["best"] > "A") $qualified = -1;
			}

		if (!$comp_id || $row["comp_id"]==$comp_id)
		{
			echo ($comp_id || $count % 2)?"<tr class=row_even>":"<tr class=row_odd>";
			echo "<td class=col_cl";
			if ($actuallyClassified)
			{
				if (array_key_exists($row["comp_id"],$actuallyClassified)) echo " style='background-color:#CCFF00;'";
			}
			else
			{
				if ($classification && $classification<=$qualified) echo " style='background-color:#CCFF00;'";
			}
			echo "><b>$classification</b></td>";
			if (!$comp_id)
				echo "<td><div class=col_nm><a href='live.php?cid=$cid&compid=".$row["comp_id"]."'>" .$row["name"]. "</a></div></td><td><div class=col_ct>" .$row["cname"]. "</div></td>";
			else
				echo "<td><div class=col_ct style='width:300px'><a href='live.php?cid=$cid&cat=$cat_id&rnd=$round'>$cat_st</a></div></td>";
			for ($x=1;$x<=$times;$x++)
				if (!$comp_id)
					echo "<td class=col_tm>".formatTime($row["t$x"],$timetype)."</td>";
				else
					echo "<td class=col_tm style='width:".$coltimewidth."px;'>".formatTime($row["t$x"],$timetype)."</td>";
			if ($avgtype!=2) echo "<td style='width:".$coltimewidth."px;'><b>".formatTime($row["average"],$timetype)."</b></td>";
			echo "<td style='width:".$coltimewidth."px;'>".($avgtype==2?"<b>":"") .formatTime($row["best"],$timetype). ($avgtype==2?"</b>":"")."</td>";
			echo "</tr>";
		}
	}
	if (!$comp_id) echo "</table><br>";
	// score table -end
}
Пример #2
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";
}
Пример #3
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);
}
Пример #4
0
	$nevents++;
	//
	$nrounds = 4;
	while ($nrounds>1 && !$event["r$nrounds"]) $nrounds--;
	//
	echo "<td>";
	echo "<table cellspacing=0 border=0 class=nested><tr valign=top><td style='width:58px;'><img border=0 src='img/corner".$event["abbr"].".jpg'>";
	if (!$event["r1_open"]) echo "<br>&nbsp;&nbsp;<a style='cursor:pointer;' title='remove event' onclick='if (confirm(\"Are you sure you want to remove the event?\")) callPage(\"delevent.php?id=". $event["id"] ."\");'><img border=0 src='img/del.gif'></a>";
	echo "</td><td style='width:100%;'><div class=header>".$event["name"]."</div>";
	echo "<DIV style='margin-left:10px;'>";
	$round = 1;
	$rnd = "r1";
	while($round <= 4 && $event[$rnd])
	{	
		$nextrnd = "r".($round+1);
		echo "<b>".roundString($round,$nrounds,($event["canhavetimelimit"] && $round==1 && $event["timelimit"]))."</b> ";
		// combined
		if ($event["canhavetimelimit"] && $round==1)
		{
			$st = (timelimitNum($event["timelimit"])?"cutoff ".formatTimelimit($event["timelimit"]):"no cutoff");
			if ($round <= $last_rwt)
				echo "-<span onclick='alert(\"Change not allowed: this round already has results\");'> $st </span>";
			else
			{
				echo "-<span id=" . $rnd."_".$event["id"] . "_1 style='cursor:pointer;' onclick='setTimeLimit(\"" . $rnd."_".$event["id"] . "_1\",\"" . $event["id"] . "\", \"";
				if (isset($events)) echo substr($events["timelimit"],1);
				echo "\");' title='click to change'> $st </span>";
			}
		}
		// format
		if ($round <= $last_rwt)