%PDF- %PDF-
Direktori : /home/jalalj2hb/www/gae/ |
Current File : /home/jalalj2hb/www/gae/importer.php |
<!doctype html> <!--[if lte IE 9]> <html class="lte-ie9" lang="en"> <![endif]--> <!--[if gt IE 9]><!--> <html lang="en"> <!--<![endif]--> <head> <?php session_start(); if(!isset($_SESSION['user'])){ header("location:index.php"); } ?> <meta charset="UTF-8"> <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <style type='text/css'> body { font-family: Arial; font-size: 14px; } a { color: blue; text-decoration: none; font-size: 14px; } a:hover { text-decoration: underline; } .footer{ text-align: center; background: #3498db; color: white; position: fixed; width: 100%; bottom: 0; height: 50px; } .footer a{ color: #ffffff; line-height: 50px; } .container-fluid{ background: #3498db; } .container-fluid{ background: #3498db; } .navbar-default .navbar-nav>li>a { color: #fff; } .navbar-default .navbar-nav>.active>a, .navbar-default .navbar-nav>.active>a:focus, .navbar-default .navbar-nav>.active>a:hover { color: #fff; background-color: #1c6ba0; } .navbar-brand img{ height: 45px; background: white; padding: 3px; margin-top: -12px; } body{ margin-bottom: 80px; } </style> </head> <body > <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="#"><img src="assets/img/logo.png" /></a> </div> <ul class="nav navbar-nav"> <li class="active"><a href="#">Mon compte</a></li> <li><a href="index.php/main/annuaire/">Annuaire</a></li> <li><a href="index.php/main/annuairedouble/">Annuaire ( doublant )</a></li> <li><a href="index.php/main/annuairevide/">Annuaire ( vide )</a></li> <li><a href="index.php/main/types/">Type Annuaire</a></li> <li><a href="importer.php">Importer Annuaire</a></li> <li><form method="POST"><button type='submit' class="btn btn-default" name='Deconnexion' style='margin: 11px;'>Déconnexion</button></form></li> </ul> </div> </nav> </header> <div class="container"> <?php if(isset($_POST['Deconnexion'])){ unset($_SESSION['user']); header("location:index.php"); } include("connexion.php"); $msg_succ=""; $arra_cols_annuaire=array('nom','prenom','entreprise','fonction','tel','mobile','email','adresse','ville','observation'); // Gestion de l'upload de fichier... TEMPORAIRE A MODIFIER // print_r($_POST); if (isset($_POST['import_liste'])) { error_reporting(E_ALL); set_time_limit(0); require("phpexcel180/Classes/PHPExcel.php"); $uploadfile_hist=$_POST['uploadfile_hist']; /** Load $inputFileName to a PHPExcel Object **/ $inputFileType = PHPExcel_IOFactory::identify('uploads/' .$uploadfile_hist); /** Create a new Reader of the type that has been identified **/ $objReader = PHPExcel_IOFactory::createReader($inputFileType); /** Advise the Reader that we only want to load cell data **/ $objReader->setReadDataOnly(true); /** Load $inputFileName to a PHPExcel Object **/ $objPHPExcel = $objReader->load('uploads/' .$uploadfile_hist); // Reading Data $compt=0; // Note: In PHPExcel column index is 0-based while row index is 1-based. That means 'A1' ~ (0,1) $objWorksheet = $objPHPExcel->getActiveSheet(); // Get the highest row and column numbers referenced in the worksheet $highestRow = $objWorksheet->getHighestRow(); // e.g. 10 $highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F' $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5 $i=0; $array_val=array(); $array_cols_annuaire=array(); foreach($_POST['cols_annuaire'] as $cols_a){ if($cols_a!=""){ $array_val[$i]=$i; $array_cols_annuaire[$i]="`".$cols_a."`"; } $i++; } $cols_annuaire=implode(",",$array_cols_annuaire); for ($row = 2; $row <= $highestRow; ++$row) { $gh=$objWorksheet->getCellByColumnAndRow(0, $row)->getValue(); if ($gh<>"") { // Non vide // Exemple de traitement SQL.... $sSql="INSERT INTO annuaire (".$cols_annuaire.") VALUES ("; foreach($array_val as $av){ $sSql.="'".addslashes($objWorksheet->getCellByColumnAndRow($av, $row)->getValue())."',"; } $sSql= substr($sSql,0,-1) . ")"; $q=mysql_query($sSql); } } echo "<br><div class='alert alert-success'><p>Téléchargement complété.<br>Les données ont été intégrées<br><br></p></div>"; } elseif (($_POST['import']=="Traitement en cours...") and ($_FILES['fichier_joint']['name']<>"")) { error_reporting(E_ALL); set_time_limit(0); require("phpexcel180/Classes/PHPExcel.php"); if ($_REQUEST['import']<>"Traitement en cours...") die("acces interdit a cette page"); //print_r($_FILES); if (strstr("excel",$_FILES['fichier_joint']['type'])) die("Erreur: Le fichier téléchargé doit etre au format excel!!"); $uploadfile = date("dmy_h-i").'-'. basename($_FILES['fichier_joint']['name']); //$uploadfile=utf8_decode($uploadfile); $uploadfile = str_replace(" ", "_", $uploadfile); if (! move_uploaded_file($_FILES['fichier_joint']['tmp_name'], 'uploads/' .$uploadfile)) { echo "Attaque potentielle par téléchargement de fichiers.<br> Voici plus d'informations :<br>"; print_r($_FILES); die(); } try { /** Load $inputFileName to a PHPExcel Object **/ $inputFileType = PHPExcel_IOFactory::identify('uploads/' .$uploadfile); /** Create a new Reader of the type that has been identified **/ $objReader = PHPExcel_IOFactory::createReader($inputFileType); /** Advise the Reader that we only want to load cell data **/ $objReader->setReadDataOnly(true); /** Load $inputFileName to a PHPExcel Object **/ $objPHPExcel = $objReader->load('uploads/' .$uploadfile); //var_dump($objPHPExcel); } catch(PHPExcel_Reader_Exception $e) { ?> <div> Téléchargement non complété.<br>Erreur sur le format de fichier ou de traitement<br> <?php echo 'Error loading file: '.$e->getMessage() ; ?> <br> <a href="#">Retour à la page précédente</a> </div> <?php } // Reading Data $compt=0; // Note: In PHPExcel column index is 0-based while row index is 1-based. That means 'A1' ~ (0,1) $objWorksheet = $objPHPExcel->getActiveSheet(); // Get the highest row and column numbers referenced in the worksheet $highestRow = $objWorksheet->getHighestRow(); // e.g. 10 $highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F' $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5 // if ($highestColumnIndex<>6) die("Le nombre de colonnes dans le fichier est incorrect (Colonnes : $highestColumnIndex ($highestColumn) - Lignes : $highestRow)<br><a class='md-btn md-btn-warning md-btn-block md-btn-wave-light' href='outils_admin.php'>Retour à la page précédente</a>"); $msg_err=""; ?> <form method="POST"> <table class="table"> <tbody> <?php for($i=0;$i<=$highestColumnIndex;$i++){ if($objWorksheet->getCellByColumnAndRow($i, 1)->getValue()!=""){ echo "<tr>"; echo "<td>".$objWorksheet->getCellByColumnAndRow($i, 1)->getValue()."</td>"; echo "<td>"; echo "<select class='form-control' name='cols_annuaire[]'>"; echo "<option value=''>ignorer</option>"; foreach($arra_cols_annuaire as $ac){ echo "<option value='".$ac."'>". ucfirst($ac)."</option>"; } echo "</select>"; echo "</td>";; echo "</tr>"; } } ?> </tbody> </table> <br> <input type="hidden" name="uploadfile_hist" class='form-control' value="<?php echo $uploadfile?>"/> <input type="submit" name="import_liste" class="btn btn-success" value="ok"/> </form> <div> - Erreurs ou anomalies constatées : <?php echo (($msg_err<>"") ? "<br>".$msg_err : " Rien à signaler ") ?> </div> <?php } else { ?> <div> L'importation d'un fichier de contact doit respecter les règles suivantes: <ul> <li> <strong>FORMAT de Fichier:</strong> <ul> <li> Le fichier DOIT être au format Excel (xls ou xlsx) OU CSV ET <u>ne pas être protégé par mot de passe</u> </li> <li> La 1ère ligne doit contenir les étiquettes de colonne </li> </ul> </li> </ul> </div> <div> <form name="frm_fichier" id="frm_fichier" class="ewForm" enctype="multipart/form-data" method="post" > <div> <div class="alert alert-info"> <b>Choisir le fichier à télécharger et à integrer puis cliquer sur le bouton "Importer"</b> </div> <input id="form-file" type="file" name="fichier_joint"> </div> <br> <input name="import" class="btn btn-success" type="submit" value="Importer" onclick="this.value='Traitement en cours...'; " > </form> </div> </div> <?php } ?> </body> </html>