commit a7b49c8fba1b5566d116880d3799cde128013f70
Author: Romuald <devnull@localhost>
Date:   Sat May 9 13:34:43 2009 +0200

    Gestion des classements en cas d'égalité (ajustements).

diff --git a/admin/admin.php b/admin/admin.php
index e19944d..8570616 100644
--- a/admin/admin.php
+++ b/admin/admin.php
@@ -43,6 +43,7 @@
 	if ($_POST['validation_championnat'] == "ajouter") $championnat = "validation_ajouter";
 	if ($_POST['validation_championnat'] == "modifier") $championnat = "validation_modifier";
 	if ($_POST['validation_penalites'] == "valider") $championnat = "validation_penalites";
+	if ($_POST['validation_ajustements'] == "valider") $championnat = "validation_ajustements";
 
 	if (isset($_POST['rencontre-ajouter'])) {
 		$rencontre = "ajouter";
@@ -53,6 +54,24 @@
 			$rencontreId = current($vars);
 		}
 	}
+	{
+		$vars = preg_grep("/^adjust-/", array_keys($_POST));
+		if ($vars) {
+			$championnat = "validation_ajustement";
+			switch ($_POST[current($vars)]) {
+				case '&#8593;':
+					$action = "up";
+					break;
+				case '&#8595;':
+					$action = "down";
+					break;
+				default:
+					$action = "unknown";
+					break;
+			}
+			list($prefix, $equipe) = explode("-", current($vars));
+		}
+	}
 	if ($_POST['validation_rencontre'] == "ajouter") $rencontre = "validation_ajouter";
 	if ($_POST['validation_rencontre'] == "modifier") $rencontre = "validation_modifier";
 
@@ -129,7 +148,10 @@
 			case "p�nalit�s":
 				$Pen = getPenalites($path);
 				$equipes = getEquipes($path);
-				$journees = getJournees($path);
+				break;
+			case "ajustements":
+				$Adjust = getAjustements($path);
+				$equipes = getEquipes($path);
 				break;
 			case "modifier":
 				if (file_exists("$path/equipes")) {
@@ -173,6 +195,63 @@
 					$message = "Les p&eacute;nalit&eacute;s ont &eacute;t&eacute; mises � jour.";
 				}
 				break;
+			case "validation_ajustements":
+				$vars = preg_grep("/^adjust_/", array_keys($_POST));
+				if ($vars) {
+					$ajustements = "";
+					foreach ($vars as $var) {
+						if ($_POST[$var] != 0) {
+							if (abs($_POST[$var]) <= 9) {
+								list($prefix, $equipe) = explode("_", $var);
+								$ajustements .= $equipe.":".$_POST[$var]."\n";
+							} else {
+								$message = "Ajustement trop important (".$_POST[$var].").";
+								break 2;
+							}
+						}
+					}
+					$file = "$path/ajustements";
+					if ($ajustements) {
+						my_file_put_contents($file, $ajustements);
+					} else {
+						if (file_exists($file)) unlink($file);
+					}
+					$message = "Les ajustements ont &eacute;t&eacute; mis � jour.";
+				}
+				break;
+			case "validation_ajustement":
+				$Adjust = getAjustements($path);
+				$equipes = getEquipes($path);
+				switch ($action) {
+					case "up":
+						$Adjust[$equipe]++;
+						$message = "L'&eacute;quipe ".$equipes[$equipe]." a &eacute;t&eacute; remont&eacute;e d'une position.";
+						break;
+					case "down":
+						$Adjust[$equipe] = $Adjust[$equipe] - 1; /* $var-- don't works with empty value */
+						$message = "L'&eacute;quipe ".$equipes[$equipe]." a &eacute;t&eacute; redescendue d'une position.";
+						break;
+					default:
+						break 2;
+				}
+				$ajustements = "";
+				foreach ($Adjust as $n => $val) {
+					if ($val != 0) {
+						if (abs($val) <= 9) {
+							$ajustements .= "$n:$val\n";
+						} else {
+							$message = "Ajustement trop important ($val).";
+							break 2;
+						}
+					}
+				}
+				$file = "$path/ajustements";
+				if ($ajustements) {
+					my_file_put_contents($file, $ajustements);
+				} else {
+					if (file_exists($file)) unlink($file);
+				}
+				break;
 			case "supprimer":
 				// Suppression de tous les fichiers du r�pertoire
 				if ($dir = opendir($path)) {
@@ -372,6 +451,20 @@
 		<input type="submit" name="validation_penalites" value="valider" />
 	</form>
 <?php retour("annuler"); ?>
+<?php } else if ($championnat == "ajustements") { ?>
+	<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
+		<table>
+<?php foreach ($equipes as $n => $e) { ?>
+			<tr>
+				<td><?=$e?></td>
+				<td>:<input type="text" name="adjust_<?=$n?>" size="3" value="<?=($Adjust[$n] ? $Adjust[$n] : "0")?>" /></td>
+			</tr>
+<?php	} ?>
+		</table>
+<?php hiddenVars() ?>
+		<input type="submit" name="validation_ajustements" value="valider" />
+	</form>
+<?php retour("annuler"); ?>
 <?php } else if ($rencontre == "ajouter" || $rencontre == "modifier") { ?>
 	<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
 		<table border="0">
diff --git a/functions.php b/functions.php
index 04eb864..d4839a5 100644
--- a/functions.php
+++ b/functions.php
@@ -108,6 +108,18 @@ function getPenalites($path) {
 	return $Pen;
 }
 
+function getAjustements($path) {
+	$Adjust = array();
+	$file = "$path/ajustements";
+	if (file_exists($file) && $ajustements = file($file)) {
+		foreach ($ajustements as $a) {
+			list($equipe, $ajustement) = explode(":", rtrim($a));
+			$Adjust[$equipe] = $ajustement;
+		}
+	}
+	return $Adjust;
+}
+
 function backup(&$zip, $dir, $zipdir) {
 	if ($dh = opendir($dir)) {
 		while (($file = readdir($dh)) !== false) {
diff --git a/index.php b/index.php
index 1b56746..931cce0 100644
--- a/index.php
+++ b/index.php
@@ -113,6 +113,9 @@
 
 	// R�cup�ration des p�nalit�s
 	$Pen = getPenalites($path);
+
+	// R�cup�ration des ajustements
+	$Adjust = getAjustements($path);
 ?>
 <html>
 <head>
@@ -242,6 +245,7 @@
 ?>
 			<input type="submit" name="championnat" value="supprimer" onClick='return confirm("Voulez-vous vraiment effacer <?=$compet?> ?")' />
 			<input type="submit" name="championnat" value="p&eacute;nalit&eacute;s" />
+			<input type="submit" name="championnat" value="ajustements" />
 		</div>
 <?php 	} ?>
 <?php }
@@ -281,14 +285,18 @@
 	if ($equipes) foreach ($equipes as $n => $e) {
 		$Pts[$n] -= $Pen[$n];
 		$Diff[$n] = $PG[$n] - $PP[$n];
-		$Rang[$n] = $Pts[$n] + $Diff[$n]/1000;
+		$Rang[$n] = $Pts[$n] + $Adjust[$n]/100 + $Diff[$n]/100000;
 	}
 	arsort($Rang);
+	$sortKeys = array_keys($Rang);
 ?>
 	<div id="tabClassement">
 		<table>
 			<tr>
 				<th class="colClt">Clt</th>
+<?php if (IamAdmin()) { ?>
+				<th class="colAdjust">Ajustement</th>
+<?php } ?>
 				<th class="colEquipe">Equipe</th>
 				<th class="colPts">Pts</th>
 				<th class="colJoue">Jou&eacute;</th>
@@ -302,12 +310,22 @@
 				<th class="colDiff">Diff</th>
 			</tr>
 <?php
-	$i = 0;
-	if ($equipes) foreach ($Rang as $equipe => $r) {
-		$i++;
+	if ($equipes) foreach ($sortKeys as $i => $equipe) {
+		$prev = ($i > 0) ? $sortKeys[$i-1] : -1;
+		$next = ($i < count($sortKeys)-1) ? $sortKeys[$i+1] : -1;
 ?>
 			<tr>
-				<td class="colClt"><?=(isset($last) && $last == $Pts[$equipe]) ? "-" : $i?></td>
+				<td class="colClt"><?=($prev != -1 && $Pts[$prev] == $Pts[$equipe]) ? "-" : $i+1?></td>
+<?php if (IamAdmin()) { ?>
+				<td class="colAdjust">
+<?php if ($prev != -1 && $Pts[$prev] == $Pts[$equipe]) { ?>
+					<input class="adjustBtn" type="submit" name="adjust-<?=$equipe?>" value="&uarr;" />
+<?php } ?>
+<?php if ($next != -1 && $Pts[$next] == $Pts[$equipe]) { ?>
+					<input class="adjustBtn" type="submit" name="adjust-<?=$equipe?>" value="&darr;" />
+<?php } ?>
+				</td>
+<?php } ?>
 				<td class="colEquipe"><?=$equipes[$equipe]?></td>
 				<td class="colPts"><?=$Pts[$equipe]?></td>
 				<td class="colJoue"><?=$Joue[$equipe]?></td>
@@ -320,15 +338,11 @@
 				<td class="colPP"><?=($PP[$equipe]) ? $PP[$equipe] : "0"?></td>
 				<td class="colDiff"><?=($Diff[$equipe]) ? $Diff[$equipe] : "0"?></td>
 			</tr>
-<?php
-		$last = $Pts[$equipe];
-	}
-?>
+<?php } ?>
 		</table>
 	</div>
 	<br />
 <?php
-	$j = 0;
 	foreach ($rencontres as $j => $rencontre) {
 ?>
 	<div class="tabJournee">
diff --git a/style/fftt.css b/style/fftt.css
index e0e0153..c7949a3 100644
--- a/style/fftt.css
+++ b/style/fftt.css
@@ -29,7 +29,7 @@ th {
 	margin: auto;
 }
 
-th.smallCol, th.colClt, th.colPts, th.colJoue,
+th.colClt, th.colAdjust, th.colPts, th.colJoue,
 th.colVic, th.colNul, th.colDef, th.colFft, th.colPen,
 th.colPG, th.colPP, th.colDiff {
 	width: 30px;
