Author: cedric.morin@yterium.com
Date: Tue Apr 25 19:08:22 2006
New Revision: 2890
Log:
des petits bugs collateraux du passage en plugin et du fonctionnement sans globales
Il semble rester un probleme a l'import, a l'etude
Modified:
_plugins_/_contenu_editorial_/CSVImport/exec/csvimport_import.php
_plugins_/_contenu_editorial_/CSVImport/inc/csvimport.php
Modified: _plugins_/_contenu_editorial_/CSVImport/exec/csvimport_import.php
--- _plugins_/_contenu_editorial_/CSVImport/exec/csvimport_import.php (original)
+++ _plugins_/_contenu_editorial_/CSVImport/exec/csvimport_import.php Tue Apr 25 19:08:22 2006
@@ -28,18 +28,19 @@
$ajouter = _request('ajouter');
$remplacer = _request('remplacer');
$assoc_field = _request('assoc_field');
+ $apercu = _request('apercu');
if (!$step)
$step = 1;
if (!$retour)
- $retour = 'csvimport_tous.php';
+ $retour = generer_url_ecrire('csvimport_tous');
$titre = _L("Import CSV : ");
$icone = "../"._DIR_PLUGIN_CSVIMPORT."/img_pack/csvimport-24.png";
$operations = array();
- $import_link = generer_url_ecrire("csvimport_import","table=$table&retour=$retour");
- $import_form_link = generer_url_post_ecrire("csvimport_import","table=$table&retour=$retour");
+ $import_link = generer_url_ecrire("csvimport_import","table=$table&retour=".urlencode($retour));
+ $import_form_link = generer_url_post_ecrire("csvimport_import","table=$table&retour".urlencode($retour));
$clean_link = $import_link;
$is_importable = csvimport_table_importable($table,$titre,$operations);
@@ -71,7 +72,7 @@
$step--;
else if (($ajouter)&&(_request('annule_ajoute')))
$step--;
- else if ($apercu)
+ else if ($apercu!=NULL)
$step--;
else if (($remplacer)&&(!isset($csvimport_replace_actif)))
$step--;
@@ -80,7 +81,6 @@
}
if ($step==3){
- global $step;
if ( (!$file_name)||(!$tmp_name)||(!$size)||(!$type) )
$erreur[$step][] = _L("Fichier absent");
@@ -113,7 +113,7 @@
$hidden['type'] = $type;
$hidden['step'] = 3;
foreach($assoc_field as $key=>$value)
- $hidden["assoc_field[$key]"] = $value;
+ $hidden["assoc_field[".htmlentities($key,ENT_QUOTES)."]"] = $value;
$hidden["delim"] = $delim;
$hidden["head"] = $head;
@@ -225,7 +225,6 @@
// --- STEP 2
if ($step==2){
- global $step;
if (!isset($_FILES))
$erreur[$step][] = _L("Problème inextricable...");
if (
@@ -239,7 +238,6 @@
if (isset($erreur[$step])) $step--;
}
if ($step==2){
- global $step;
if (!$head) $head = false;
if (isset($_FILES['csvfile'])){
Modified: _plugins_/_contenu_editorial_/CSVImport/inc/csvimport.php
--- _plugins_/_contenu_editorial_/CSVImport/inc/csvimport.php (original)
+++ _plugins_/_contenu_editorial_/CSVImport/inc/csvimport.php Tue Apr 25 19:08:22 2006
@@ -125,7 +125,7 @@
$s = "";
if ($importable)
$s .= "<a href='$link'>";
- $s .= "<img src='img_pack/$puce' width='7' height='7' border='0'> ";
+ $s .= "<img src='"._DIR_INCLUDE."img_pack/$puce' width='7' height='7' border='0'> ";
$s .= strlen($titre)?typo($titre):$latable;
if ($importable)
$s .= "</a>";
@@ -344,6 +344,7 @@
global $tables_principales;
$csvimport_tables_auth = csvimport_tables_auth();
$assoc=$assoc_field;
+ if (!is_array($assoc)) $assoc = array();
$csvfield=array_keys($data{1});
$csvfield=array_flip($csvfield);
@@ -410,7 +411,7 @@
foreach($csvfield as $csvkey){
$output .= "<tr>";
$output .= "<td>$csvkey</td>";
- $output .= "<td><select name='assoc_field[$csvkey]'>\n";
+ $output .= "<td><select name='assoc_field[".htmlentities($csvkey,ENT_QUOTES)."]'>\n";
$output .= "<option value='-1'>"._L("Ne pas importer")."</option>\n";
foreach($tablefield as $tablekey){
$output .= "<option value='$tablekey'";
@@ -434,18 +435,28 @@
global $tables_principales;
$csvimport_tables_auth = csvimport_tables_auth();
$assoc = array_flip($assoc_field);
+ //$id_primary = mysql_query("INSERT INTO spip_articles (titre) VALUES ('toto')", $GLOBALS['spip_mysql_link']);
+ //$id_primary = mysql_query("INSERT INTO spip_artisans (raison) VALUES ('toto')", $GLOBALS['spip_mysql_link']);
+ $desc = spip_abstract_showtable($table);
+ if (!isset($desc['field']) || count($desc['field'])==0){
+ $erreur[0][] = "Description de la table introuvable";
+ return;
+ }
+ if ($GLOBALS['mysql_rappel_nom_base'] AND $db = $GLOBALS['spip_mysql_db'])
+ $table = '`'.$db.'`.'.$table;
- $tablefield=array_keys($tables_principales[$table]['field']);
+
+ $tablefield=array_keys($desc['field']);
$output = "";
// y a-t-il une cle primaire ?
- if (isset($tables_principales[$table]['key']["PRIMARY KEY"])){
- $primaire = $tables_principales[$table]['key']["PRIMARY KEY"];
+ if (isset($desc['key']["PRIMARY KEY"])){
+ $primaire = $desc['key']["PRIMARY KEY"];
// la cle primaire est-elle importee ?
if (in_array($primaire,$assoc_field))
unset($primaire);
}
// y a-t-il un champ TIMESTAMP ?
- $test=array_flip($tables_principales[$table]['field']);
+ $test=array_flip($desc['field']);
if (isset($test['TIMESTAMP']))
$stamp = $test['TIMESTAMP'];
@@ -472,6 +483,9 @@
if ((strlen($what)>1)&&(strlen($with)>1)) {
$what = substr($what,0,strlen($what)-1) . ")";
$with = substr($with,0,strlen($with)-1) . ")";
+ //$what = "(raison_sociale)";
+ //$with = "('toto')";
+
$id_primary = spip_abstract_insert($table, $what, $with);
if ($id_primary==0)
$erreur[$count_lignes][] = "ajout impossible ::$what::$with::<br />";