0byt3m1n1
Path:
/
home
/
k
/
a
/
s
/
kassiope
/
www
/
administrer
/
[
Home
]
File: mysql2csv.php
<? include("../configuration.inc.php"); necessite_identification(); necessite_priv("admin"); $DOC_TITLE = "[Exportation CSV - GAIABOUTIK.FR]"; include("modeles/haut.php"); echo '<table border=0 cellpadding="0" cellspacing="0" width="100%" class="tablespace"> <tr ><th class="entete" colspan="3">EXPORTER UN FICHIER</th></tr> <tr><td colspan="3" class="normal">'; $table = "gaia_produits"; $csv_file = $table.".csv"; switch(vb($_REQUEST['mode'])) { case "lire" : db2csv($table,$csv_file); echo "<li type=\"square\"><a href=$table.csv class=\"normal\">Lire le fichier csv</a></li>"; form2csv(); break; default : form2csv(); break; } echo '</td></tr></table>'; include("modeles/bas.php"); /* FONCTIONS */ function db2csv($table,$csv_file) { global $wwwroot; $min = intval($_GET['min']); $max = intval($_GET['max']); $langue = htmlspecialchars($_GET['langue']); $create_csv = fopen($csv_file,"w"); fwrite($create_csv,"#country=fr\r\n#type=basic\r\n#currency=EUR\r\n"); $select = "select p.id, p.nom_".$_SESSION['langue'].", p.descriptif_".$_SESSION['langue'].", p.image1, p.prix, p.promotion, c.nom_".$_SESSION['langue']." AS categorie from gaia_produits p, gaia_categories c, gaia_produits_categories pc WHERE pc.produit_id = p.id AND c.id = pc.categorie_id LIMIT ".$min.", ".$max.""; echo "<span class=\"normal\">Requête utilisée pour la génération du fichier csv : $select</span>"; $req = mysql_query_override($select); while($prod = mysql_fetch_array_override($req)) { $text = TrimExt(strip_tags($prod['descriptif_'.$_SESSION['langue'].''])); $prix = $prod['prix'] * (1-$prod["promotion"]/100); fwrite($create_csv,""); fwrite($create_csv,stripslashes("$wwwroot/achat/produit_details.php?id=".$prod['id']." ").";"); fwrite($create_csv,stripslashes($prod['nom_'.$_SESSION['langue'].'']).";".$text.";".$prix.";".$prod['id'].";"); if (!empty($prod['image1'])) {$image = "$wwwroot/administrer/images/".$prod['image1']."";} else { $image = "";} fwrite($create_csv,htmlspecialchars($image).";".stripslashes($prod['categorie'])."\r\n"); } fclose($create_csv); mysql_free_result($req); } function form2csv() { global $table; echo "<form method=\"GET\" name=\"prod2csv\" action=\"".$_SERVER['PHP_SELF']."\">"; echo "<div class=\"normal\">Exporter au format CSV les produits "; echo "<input type=\"hidden\" name=\"mode\" value=\"lire\">"; echo "<br \><br /><input type=\"submit\" class=\"bouton\" value=\"lire le fichier csv \">"; echo "</span></div></form>"; } Function TrimExt( $Src ) { $Src = ereg_replace( "(\r\n){0,15}$", "", $Src ); $Src = ereg_replace( "^(\r\n){0,15}", "", $Src ); $Src = ereg_replace( "(\n){0,15}$", "", $Src ); $Src = ereg_replace( "^(\n){0,15}", "", $Src ); $Src = trim( $Src ); return $Src; } ?>