<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8"/>
		<title>Gestion des Points</title>
		<link rel="shortcut icon" type="image/x-icon" href="../mmd/favicon.ico"/>
		<link rel="stylesheet" href="../createPoints/styles/sky.css"/>
		<link rel="stylesheet" href="../style.css"/>
		<link rel="stylesheet" href="style.css"/>
		<script type="text/javascript" src="jquery.js"></script>
	</head>

		<?php
			$id = $_GET["id"];
		?>
		<a href="<?php echo "afficheInfos.php?id=".$id ?>"><div class="back_arrow"></div></a>
		<style type="text/css">
		.back_arrow {
			background: url('../mmd/return.svg') no-repeat center;
			cursor: pointer;
			position: absolute;
			top: 50px;
			left: 50px;
			width: 50px;
			height: 50px;
			opacity: 1;
		}

		.back_arrow:hover {
			opacity: 0.5;
		}
		</style>

<?php

function afficheInfos($key, $value)
{
	if ($key != "id" ) {
		echo "<p class='{utf8_encode($key)}'><b>".utf8_encode($key)."</b></p>";
		echo "<p>".utf8_encode($value)."</p>";
	}
}

$db = mysql_connect('localhost', 'root', 'm148r43a9Y@%Z')  or die ('Erreur de connexion '.mysql_error());

mysql_select_db('smartpassTest2',$db) or die ('Erreur de selection '.mysql_error());

$sql = "SHOW TABLES FROM smartpassTest2";
$tables = mysql_query($sql);

echo "<h1>Modification du point</h1>";

echo "<form action='update.php?id={$id}' method='post' id='sky-form' class='sky-form' style='width:45%;margin:auto;margin-bottom:50px;'>";
echo "<fieldset id='dynamic_fieldset'>";

while ($row = mysql_fetch_row($tables)) {
	if($row[0]!="Parcours" and $row[0]!="photos" and $row[0]!="ips"){

		$sql = "SELECT * FROM {$row[0]} WHERE id = {$id}";
		$data = mysql_fetch_array(mysql_query($sql));

		foreach ($data as $key => $value) {
			if (!is_null($value) and !is_integer($key)) {
				if($key != "id"){

					$tableName = strval($row[0]);
					$columnName = strval($key);

					$champs = mysql_fetch_array(mysql_query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$tableName}' and COLUMN_NAME = '{$columnName}' GROUP BY DATA_TYPE"));

					echo "<section>";
					echo "<label class='label'>{$key}</label>";

					foreach ($champs as $nom => $size) {

						$dataChamps = explode(")",$champs[0]);
						$dataChamps = explode ( "(" , $dataChamps[0]);

						if ($columnName != "DescriptionLongue") {

							if ($dataChamps[0] == "int" and $dataChamps[1] == 1){
								if ($value == 1){
									echo "<div class='inline-group'>";
									echo "<label class='radio'><input name='{$tableName}_{$columnName}' type='radio' value='1'checked><i></i>Oui</label>";
									echo "<label class='radio'><input name='{$tableName}_{$columnName}' type='radio' value='0'><i></i>Non</label>";
									echo "</div>";
								}
								else{
									echo "<div class='inline-group'>";
									echo "<label class='radio'><input name='{$tableName}_{$columnName}' type='radio' value='1'><i></i>Oui</label>";
									echo "<label class='radio'><input name='{$tableName}_{$columnName}' type='radio' value='0'checked><i></i>Non</label>";
									echo "</div>";
								}
							}
							else{
								echo "<label class='input'><input name='{$tableName}_{$columnName}' value='".htmlspecialchars(($value),ENT_QUOTES)."' type='text'/></label>";
							}
						}
						else{
							echo "<label class='textarea'><textarea name='{$tableName}_{$columnName}' cols='60' rows='10'>".htmlspecialchars(($value),ENT_QUOTES)."</textarea></label>";
						}
						echo "</br>";
						break;
					}

					echo "</section>";
				}
			}
		}
	}
}

echo "<input type='submit' class='myButton' value ='Modifier' id='submit'>";

echo '</fieldset>';
echo "</form>";

?>