<?
	$savefn="Orders ".$game_checked."-".$pm.".csv";
	$fn=$DOCUMENT_ROOT.$metoobasedir.'turn/orders/'.$savefn;

	if ($orders>0) {
		for ($empo=1; $empo<=$orders; $empo++) {
			for ($emp=1; $emp<=16; $emp++) {
				$moves[$empo][$emp]="";
			}
		}
		$orders=0;
	}

	if (file_exists($fn)) {
		$fp = fopen ($fn, "r");
		if (filesize($fn)>0) { $content = fread($fp, filesize($fn)); }
		fclose($fp);
		$filetime_orders=filemtime($fn);
		
		if ($filetime_orders>$filetime_people[$pm]) {
		
			$piecesorders = explode("§end§", $content);
			$nborders=count($piecesorders)-1;
	
			for ($ip=0; $ip<=$nborders; $ip++) {
				$pieces = explode("/", $piecesorders[$ip]);
				$searchhero=trim($pieces[0]);
				$found=false;
				for ($t=1; $t<=$nbheroes; $t++) {
					if ($hero[$t]->handle==$searchhero) {
						$found=true;
						$tmem=$t;
						$peopleorders=$hero[$t]->people;
					}
				}
				if ($found) {
					$orderfound=substr($pieces[1], 0, 3);
					if (($orderfound=="830") || ($orderfound=="850") || ($orderfound=="860")) {
						$orders++;
						$moves[$orders][1]=$tmem;
						$moves[$orders][2]=1;
#						echo $hero[$tmem]->name." moves from ";
#						echo $hero[$tmem]->hex." to ";
						$jp=0;
						do {
							$jp++;
#							if ($jp!=1) { echo ","; }
#							echo $pieces[$ip+$jp];
							$moves[$orders][$jp+2]=array_search($pieces[$jp+1],$ArmyMoves);
						} while (array_search($pieces[$jp+1], $ArmyMoves));
#						echo "<br>";
					}
					if (($orderfound=="810") || ($orderfound=="870")) {
						$orders++;
						$moves[$orders][1]=$tmem;
						$moves[$orders][2]=2;
#						echo $hero[$tmem]->name." moves from ";
#						echo $hero[$tmem]->hex." to ";
						$moves[$orders][3]=$pieces[2];
#						echo $pieces[$ip+1]."<br>";
					}
					if (($orderfound=="23") || ($orderfound=="25")) {
						$orders++;
						$moves[$orders][1]=$tmem;
						$moves[$orders][2]=3;
					}
				} else {
#					echo $searchhero." not found !<br>";
				}
			}
		}
	}
?>