<?php
session_start();
if (!isset($_SESSION['acces'])) {
	header ('Location: acces.php?anh_san=paray_ci');
}
include('connexion.php');
$date_img=date('d_m_Y_H_i_s_');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"><head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="style/style_admin.css" type="text/css">
<link rel="stylesheet" media="screen" type="text/css" title="Design" href="style/style.css">
<link rel="stylesheet" media="screen" type="text/css" title="Design" href="style/bootstrap.css">
<title>AURORE Admin</title>

</head>

<body>
<?php
if (isset($_GET['chaiz']))
{
	$chaiz=addslashes($_GET['chaiz']);
	$dat_mis=date('Y-m-d');

	if ($chaiz!='image')
	{
		$page_prec='ajouter_element.php?chaiz='.$chaiz.'';
		$page_ret='admin_element.php?chaiz='.$chaiz.'';
	}
	else
	{
		$id=addslashes($_GET['id']);
		$page_prec='ajouter_element.php?chaiz='.$chaiz.'&id='.$id.'';
		$page_ret='afficher_element.php?chaiz=dossier&id='.$id.'';
	}
	
	switch ($chaiz)
	{
		case 'produit': $aff='Formulaire d\'Ajout de Produit';
						$final='Produit ajouté';
?>
<div id="toute_off" align="center">
    <div class="page"> <?php echo $aff;?></div>
        
    <div class="cov_off" style="border-radius:15px; margin-bottom:20px;">
    	<form role="form" method="post" action="" enctype="multipart/form-data" name="form2">
        	<table border="0" width="100%">
			
			    <tr>
                <td class="menu_off">Type de produit</td>
                <td><select name="type_proda">
				<option value="Sac &agrave; main">Sac &agrave; main</option>
				<option value="Chaussures">Chaussures</option>
				<option value="Articles Mariamare">Articles Mariamare</option>
				</select></td>
            </tr>
			
            <tr>
                <td class="menu_off" width="25%">Nom</td>
                <td><input type="text" class="form-control" name="nom" value="<?php if (isset($_POST['valider'])){echo $_POST['nom'];} ?>"></td>
            </tr>
			<tr>
                <td class="menu_off" width="25%">Présentation</td>
                <td><textarea class="form-control" name="present" id="textarea_prod"><?php if (isset($_POST['valider'])){echo $_POST['present'];} ?></textarea></td>
            </tr>
            <tr>
                <td class="menu_off" width="35%">Ancien prix ci possible</td>
                <td><input style="float:left; margin:0px 0px 0px 0px;" type="text" class="form-control" name="old" value="<?php if (isset($_POST['valider'])){echo $_POST['old'];} ?>" placeholder="7000" onKeypress="if(event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
     if(event.which < 45 || event.which > 57) return false;"> F cfa</td>
            </tr>
            <tr>
                <td class="menu_off" width="25%">Nouveau Prix (Prix Actuel)</td>
                <td><input style="float:left; margin:0px 0px 0px 0px;" type="text" class="form-control" name="new" value="<?php if (isset($_POST['valider'])){echo $_POST['new'];} ?>" placeholder="10000" onKeypress="if(event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
     if(event.which < 45 || event.which > 57) return false;"> F cfa</td>
            </tr>
            <tr>
                <td class="menu_off">Image</td>
                <td><input type="file" class="form-control" name="tof"></td>
            </tr>
            </table>
            <input type="submit" class="btn btn-default" value="Valider" name="valider"> 
            <a href="<?php echo $page_ret;?>">Retour</a>
        </form>
        
		<?php
		if (isset($_POST['valider']))
		{
			$nom=addslashes(($_POST['nom']));
			$type_proda=addslashes(($_POST['type_proda']));
			$present=addslashes(($_POST['present']));
			$old=addslashes(($_POST['old']));
			$new=addslashes(($_POST['new']));

			$name_img=$_FILES['tof']['name'];
			$type_img=$_FILES['tof']['type'];
			$size_img=$_FILES['tof']['size'];
			$temp_img=$_FILES['tof']['tmp_name'];
			$error_img=$_FILES['tof']['error'];

			if (empty($nom) or empty($new))
			{
				echo '<div style="text-align:center; color:red;"><img src="img/rouge.png" width="20">Veuillez renseigner tous les champs</div>';
			}
			else
			{
				if ($error_img==0 or $error_img==4)
				{
					if (($type_img=="image/png")or ($type_img=="image/gif")or ($type_img=="image/jpeg") or ($type_img=="image/jpg") or ($type_img==""))
					{
						if ($error_img==0)
						{
							if ($type_img!="")
							{
								move_uploaded_file($temp_img, "../../uploads/".$date_img.$name_img);
								$lien_img=$date_img.$name_img;
							}
							$req='INSERT INTO '.$chaiz.' VALUES ("", "'.$nom.'", "'.$present.'", "'.$old.'", "'.$new.'", "'.$lien_img.'", "'.$dat_mis.'", "'.$type_proda.'")';
							$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
							echo '<div style="text-align:center; color:green;"><img src="img/vert.png" width="20"> '.$final.' avec succès';
					?> 
<script type="text/javascript">window.setTimeout("location=('<?php echo $page_prec; ?>');",2200);</script>
					<?php
						}
						elseif ($error_img==4)
						{
							echo '<div style="text-align:center; color:red;"><img src="img/rouge.png" width="20">Pas d\'image !</div>';
						}
					}
					else
					{
						echo '<div style="text-align:center; color:red;"><img src="img/rouge.png" width="20">Format Incorrecte </div>';
					}
				}
				else
				{
					echo '<div style="text-align:center; color:red;"><img src="img/rouge.png" width="20">Erreur de Transmission !</div>';
				}	
			}
		}
		break;

		default: header ('Location: administration.php?anh_san=paray_ci');
	}
		?>
    </div>
</div>

<table border="0" align="center"><tr>
    <td class="bouton_design">
    </td>
    <td class="bouton_design">
    <a href="administration.php?anh_san=paray_ci">Accueil Panneau</a></td>
</tr></table>
<?php 
}
else
{
	header ('Location: administration.php?anh_san=paray_ci');
}
?>
</body>
</html>