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
|
if (isset($_SESSION['user'])) {
$compt = $_SESSION['user'];
$idUsersconnectes = $compt['idUsers'];
$cpt = "SELECT idUsers, nomUsers, prenomUsers, login, idGroupe FROM VUTILISATEUR WHERE supUsers='1' AND idUsers='$idUsersconnectes'";
$results = $idcom->query($cpt);
$row = $results->fetch(PDO::FETCH_ASSOC);
$idUsers = $row['idUsers'];
$nomUsers = strtoupper($row['nomUsers']);
$prenomUsers = $row['prenomUsers'];
$login = $row['login'];
$user = $nomUsers . " " . $prenomUsers;
setlocale(LC_TIME, 'fra_fra');
$dateSaving = utf8_decode(utf8_encode(gmstrftime('%A %d %B %Y, %H:%M')));
$target_galerie = "../ressources/upload/";
$target_file = $target_galerie . basename($_FILES["fichier"]["name"]);
if (!move_uploaded_file($_FILES["fichier"]["tmp_name"], $target_file)) {
header("location: ../views/accueil.php?");
}
if ($target_file) {
$fichiers = $_FILES["fichier"]["name"];
if (file_exists($target_file)) {
if ($_FILES["fichier"]["size"] > 0) {
include("../ressources/PHPExcel/Classes/PHPExcel/IOFactory.php");
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($target_file);
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow(); // e.g. 10
for ($row = 5; $row <= $highestRow; $row++) {
$name0 = $objWorksheet->getCellByColumnAndRow(0, $row)->getValue();
$name1 = utf8_decode($objWorksheet->getCellByColumnAndRow(1, $row)->getValue());
$name2 = utf8_decode(PHPExcel_Style_NumberFormat::toFormattedString($objWorksheet->getCellByColumnAndRow(2, $row)->getValue(), 'YYYY-MM-DD'));
$name3 = utf8_decode($objWorksheet->getCellByColumnAndRow(3, $row)->getValue());
$name4 = utf8_decode($objWorksheet->getCellByColumnAndRow(4, $row)->getValue());
$name5 = utf8_decode($objWorksheet->getCellByColumnAndRow(5, $row)->getValue());
$name6 = utf8_decode($objWorksheet->getCellByColumnAndRow(6, $row)->getValue());
$name7 = utf8_decode($objWorksheet->getCellByColumnAndRow(7, $row)->getValue());
$name8 = utf8_decode($objWorksheet->getCellByColumnAndRow(8, $row)->getValue());
$name9 = utf8_decode(PHPExcel_Style_NumberFormat::toFormattedString($objWorksheet->getCellByColumnAndRow(9, $row)->getValue(), 'YYYY-MM-DD'));
$name10 = utf8_decode($objWorksheet->getCellByColumnAndRow(10, $row)->getValue());
$name11 = utf8_decode($objWorksheet->getCellByColumnAndRow(11, $row)->getValue());
$name12 = utf8_decode($objWorksheet->getCellByColumnAndRow(12, $row)->getValue());
$name13 = utf8_decode($objWorksheet->getCellByColumnAndRow(13, $row)->getValue());
$name14 = utf8_decode($objWorksheet->getCellByColumnAndRow(14, $row)->getValue());
$name15 = utf8_decode($objWorksheet->getCellByColumnAndRow(15, $row)->getValue());
$name16 = utf8_decode(PHPExcel_Style_NumberFormat::toFormattedString($objWorksheet->getCellByColumnAndRow(16, $row)->getValue(), 'YYYY-MM-DD'));
$name17 = utf8_decode(PHPExcel_Style_NumberFormat::toFormattedString($objWorksheet->getCellByColumnAndRow(17, $row)->getValue(), 'YYYY-MM-DD'));
$name18 = utf8_decode(PHPExcel_Style_NumberFormat::toFormattedString($objWorksheet->getCellByColumnAndRow(18, $row)->getValue(), 'YYYY-MM-DD'));
$name19 = utf8_decode(PHPExcel_Style_NumberFormat::toFormattedString($objWorksheet->getCellByColumnAndRow(19, $row)->getValue(), 'YYYY-MM-DD'));
$name20 = utf8_decode(strtoupper($objWorksheet->getCellByColumnAndRow(20, $row)->getValue()));
if ($name20 == "DEPOT1") {
$name21 = 2440003;
} elseif ($name20 == "DEPOT2") {
$name21 = 2440005;
} elseif ($name20 == "DEPOT3") {
$name21 = 2440008;
} elseif ($name20 == "DEPOT4") {
$name21 = 2440001;
}
$query = "INSERT INTO test (id, name1, name2, name3, name4, name5, name6, name7,
name8, name9, name10, name11, name12,name14, name15, name16, name17, name18, name19,
name20, name21, volumeDeposeAuCompteur, idRespEnreg, dateRespEnreg, idRespDernierEnreg,
dateRespDernierEnreg, sup)
VALUES(NULL, '$name1', '$name2', '$name3', '$name4', '$name5', '$name6', '$name7', '$name8', '$name9', '$name10',
'$name11', '$name12','$name14','$name15','$name16','$name17','$name18','$name19','$name20','$name21','NULL','$idUsers',
'$dateSaving',NULL,NULL,'1')";
$result = $idcom->exec($query);
}
if ($result != 0) {
// Tout se passe bien,
header("location: ../views/test.php?op=2");
} else {
header("location: ../views/test.php?err=2");
}
} else {
header("location: ../views/test.php?err=1");
}
} else {
// le fichier n'existe pas
header("location: ../views/test.php?err=3");
}
}
} |
Partager