1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" href="./css/style.css" type="text/css" />
<title>actualisation des anciens clients</title>
</head>
<body>
<div class="contenu" id="haut">
<a title="retour à l'accueil" href="./index.php"><img src="./jpg/en-tete.jpg" /></a>
<h3 class="titre_rubrique"><font color="#FFFFFF">Actualisation des anciens clients</font></h3>
<!-- Partie formulaire =================================================== -->
<table align="center">
<form method="POST" action="">
<th class="titre_section">SECTION FICHIER</th>
<tr>
<td class="champ_obligatoire">Contenu CSV *</td>
<td><textarea class="contenu_csv" name="contenu_csv"></textarea></td>
</tr>
<tr><!-- séparation de catégorie de formulaire -->
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<th class="titre_section">SECTION VALIDATION</th>
<tr>
<td><input class="bouton" type="submit" value="valider" /></td>
<td><input class="bouton" type="reset" value="réinitialiser" /></td>
</tr>
</table>
</form>
<!-- Partie gestion saisie =============================================== -->
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')//il y a eu validation du formulaire
{
if(!isset($_POST['contenu_csv']) || $_POST['contenu_csv'] == '' || $_POST['contenu_csv'] == ' ')//vérification de la saisie
{
echo '<br/>';
echo '<div class="erreur_id"><h3>La saisie est invalide.</h3></div>';
echo '<br/>';
echo '<div class="navigation"><a title="retour en haut de page" class="a_clair" href="./ajout_reparation_depuis_client_existant.php#haut">haut | </a><a title="retour sur la page d\'accueil" class="a_clair" href="./index.php">accueil </a></div>';
echo '</div>';
exit;
}//fin if saisie invalide
//connexion
include("./connexion_sql.php");
mysqli_query($bdd, "SET foreign_key_checks = 0");//désactivation vérification fk
mysqli_query($bdd, "TRUNCATE tclients_anciens");//vide tclients_anciens
$lignes = explode("\n", $_POST['contenu_csv']);//capture lignes
for ($i = 0; $i < count($lignes); $i++)
{
$champs = explode(";", $lignes[$i]);//capture champs ligne courante
mysqli_query($bdd, "INSERT INTO `tclients_anciens`(`id`, `titre`, `nom`, `prenom`, `complement`, `adresse`, `npa`, `localite`, `telephone1`, `telephone2`, `telephone3`, `fax`, `email`, `web`)
VALUES ('".mysqli_real_escape_string($bdd, $champs[0])."',
'".mysqli_real_escape_string($bdd, $champs[1])."',
'".mysqli_real_escape_string($bdd, $champs[2])."',
'".mysqli_real_escape_string($bdd, $champs[3])."',
'".mysqli_real_escape_string($bdd, $champs[4])."',
'".mysqli_real_escape_string($bdd, $champs[5])."',
'".mysqli_real_escape_string($bdd, $champs[6])."',
'".mysqli_real_escape_string($bdd, $champs[7])."',
'".mysqli_real_escape_string($bdd, $champs[8])."',
'".mysqli_real_escape_string($bdd, $champs[9])."',
'".mysqli_real_escape_string($bdd, $champs[10])."',
'".mysqli_real_escape_string($bdd, $champs[11])."',
'".mysqli_real_escape_string($bdd, $champs[12])."',
'".mysqli_real_escape_string($bdd, $champs[13])."')");
}//fin boucle for
mysqli_query($bdd, "SET foreign_key_checks = 1");//activation vérification fk
//vérification intégrité
$result = mysqli_query($bdd, "SELECT count(*) AS nombre
FROM tclients_anciens");
$data = mysqli_fetch_assoc($result);
if($data['nombre'] == count($lignes))//le nombre d'anciens clients est-il le même que le nombre de lignes capturées dans le csv ?
{echo '<br/><div align="center" class="succes_ajout">L\'actualisation est un succès : <b>'.htmlentities($data['nombre']).'</b> enregistrements insérés sur <b>'.htmlentities(count($lignes)).'</b> fournis.<br/>Vérifier que les données sont intègres.</div>';}
else
{echo '<br/><div align="center" class="erreur_id">Le nombre d\'enregistrements insérés est incorrect. Insérés = '.htmlentities($data['nombre']).' Fournis = '.htmlentities(count($lignes)).'</div>';}
//déconnexion
mysqli_free_result($result);
}//fin if validation formulaire
?>
<!-- Partie navigation =================================================== -->
<br/>
<div class="navigation"><a title="retour en haut de page" class="a_clair" href="./actualisation_anciens_clients.php#haut">haut </a><a title="retour sur la page d'accueil" class="a_clair" href="./index.php">| accueil </a></div>
</div>
</body>
</html> |
Partager