24 require __DIR__.
"/class_impcard_file_csv_sql.php";
25 require __DIR__.
"/class_impcard_format_sql.php";
46 $this->format->f_name=
'TEMP';
47 $this->format->f_unicode_encoding=
'Y';
48 $this->format->f_card_category=$p_fiche_card;
49 $this->format->f_skiprow=0;
50 $this->format->f_surround=
'"';
51 $this->format->f_delimiter=
";";
52 $this->format->f_saved=0;
53 if ($p_fiche_card == 0 ){
54 $this->format->f_position=
"-1";
56 $a_attribute=$cn->make_list(
57 "select ad_id from jnt_fic_attr join attr_def using(ad_id) where fd_id=$1
59 array($p_fiche_card));
60 $this->format->f_position=$a_attribute;
69 $r = HtmlInput::extension() . Dossier::hidden();
70 $r.= HtmlInput::hidden(
"record", $this->record->id);
71 $r.= HtmlInput::hidden(
"format", $this->format->id);
82 $delimiter =
new IText(
'rdelimiter');
84 $delimiter->value = $this->format->f_delimiter;
85 $fd =
new ISelect(
'rfichedef');
86 $fd->value = $cn->make_array(
'select fd_id,fd_label from fiche_def order by 2');
87 $fd->selected=$this->format->f_card_category;
88 $encodage =
new ICheckBox(
'encodage');
89 $encodage->selected = ($this->format->f_unicode_encoding==
"Y")?TRUE:FALSE;
91 $skip_row->value=$this->format->f_skiprow;
92 $select_template =
new ISelect(
"select_template");
93 $select_template->value=$cn->make_array(
"select id,f_name from importcard.format order by 2");
94 require_once(
'template/input_format.php');
95 $r = ob_get_contents();
107 $hidden = $this->
hidden() . HtmlInput::hidden(
'sa',
'import');
108 $fd =
new ISelect(
'rfichedef');
109 $fd->value = $cn->make_array(
'select fd_id,fd_label from fiche_def order by 2');
110 $file =
new IFile(
'csv_file');
112 require_once(
'template/input_file.php');
113 $r = ob_get_contents();
125 if (trim($_FILES[
'csv_file'][
'name']) ==
'')
127 alert(
'Pas de fichier donné');
130 $this->record->file_name = tempnam($_ENV[
'TMP'],
'upload_');
131 move_uploaded_file($_FILES[
"csv_file"][
"tmp_name"], $this->record->file_name );
132 $this->record->save();
133 $file_def=HtmlInput::default_value_request(
'rfichedef', 0);
135 $this->format->f_card_category=$file_def;
136 $this->format->save();
137 $hidden = $this->
hidden() . HtmlInput::hidden(
'sa',
'record');
147 $this->format->f_card_category= HtmlInput::default_value_request(
'rfichedef',0);
149 $this->format->f_skiprow=HtmlInput::default_value_request(
"skip_row", 0);
150 $this->format->f_delimiter = HtmlInput::default_value_request(
"rdelimiter", $this->format->f_delimiter );
151 $this->format->f_surround = HtmlInput::default_value_request(
"rsurround", $this->format->f_surround);
153 $head_col = HtmlInput::default_value_request(
"head_col", $this->format->f_position);
156 if ( is_array($head_col) ) {
157 $this->format->f_position = join($head_col,
",");
159 $a_attribute=$cn->make_list(
160 "select ad_id from jnt_fic_attr join attr_def using(ad_id) where fd_id=$1
161 order by jnt_order ",
162 array($this->format->f_card_category));
163 $this->format->f_position=$a_attribute;
165 $this->format->f_unicode_encoding= (isset(
$_REQUEST[
'encodage'])) ?
'Y' :
'N';
166 $this->format->save();
177 $filename=$this->record->file_name;
178 $delimiter=$this->format->f_delimiter;
179 $surround=$this->format->f_surround;
181 $fiche_def=$this->format->f_card_category;
183 $a_header=explode(
",", $this->format->f_position);
184 $sql=sprintf(
'select ad_id,ad_text from jnt_fic_attr join attr_def using(ad_id) where fd_id=%d order by ad_text ',$fiche_def);
185 $header=
new ISelect(
'head_col[]');
187 $header->value[]=array(
'value'=>-1,
'label'=>
'-- Non Utilisé --');
191 $a_attribute=$cn->get_array(
192 "select ad_id,ad_text from jnt_fic_attr join attr_def using(ad_id) where fd_id=$1 order by jnt_order ",
195 $t1_valid_header=$cn->make_list(
"select ad_id from jnt_fic_attr join attr_def using(ad_id) where fd_id=$1 ",array($fiche_def));
196 $a_valid_header=explode(
",", $t1_valid_header);
197 require_once(
'template/test_file.php');
228 $fd = fopen($this->record->file_name,
'r');
231 throw new Exception(sprintf(_(
"Ne peut ouvrir le fichier %s"),
232 $this->record->file_name));
241 $valid_accounting = 0;
243 $head_col = explode(
",",$this->format->f_position);
246 for ($i = 0; $i < count($head_col); $i++)
248 if ($head_col[$i] != -1)
250 if ($head_col[$i] == 1)
252 if ($head_col[$i] == ATTR_DEF_QUICKCODE)
254 if ($head_col[$i] == ATTR_DEF_ACCOUNT)
255 $valid_accounting = 1;
256 for ($e = $i + 1; $e < count($head_col); $e++)
257 if ($head_col[$i] == $head_col[$e] && $head_col[$e] != -1)
262 alert(_(
"Aucune colonne n'est définie"));
265 if ($valid_name == 0)
267 alert(_(
"Les fiches doivent avoir au minimum un nom"));
272 alert(_(
'Vous avez défini plusieurs fois la même colonne'));
283 while ((
$row = fgetcsv($fd, 0, $this->format->f_delimiter, $this->format->f_surround)) !==
false)
291 echo
'<tr style="border:solid 1px black">';
293 $count_col = count(
$row);
295 for ($i = 0; $i < $count_col; $i++)
297 if ($head_col[$i] == -1)
299 $header[$col_count] = $head_col[$i];
302 $attr = sprintf(
'av_text%d', $head_col[$i]);
304 if ( $head_col [$i] == ATTR_DEF_QUICKCODE) {
311 if ($valid_qcode == 0)
313 $attr = sprintf(
'av_text%d', ATTR_DEF_QUICKCODE);
320 if ($valid_accounting == 0)
322 $attr = sprintf(
'av_text%d', ATTR_DEF_ACCOUNT);
331 if ($valid_qcode == 0 || trim($qcode) ==
"")
336 $fiche->get_by_qcode($qcode,
false);
340 $msg=(_(
'Mise à jour'));
345 echo td($g_succeed.
" ".
$msg);
350 echo td($e->getMessage());
354 $table_content = ob_get_contents();
358 for ($e = 0; $e < count(
$header); $e++)
360 $name = $cn->get_value(
'select ad_text from attr_def where ad_id=$1', array(
$header[$e]));
366 $name = $cn->get_value(
'select fd_label from fiche_def where fd_id=$1', array($this->format->f_card_category));
367 $cn->get_value(
'select comptaproc.fiche_attribut_synchro($1)', array($this->format->f_card_category));
368 echo
'<span class="notice">';
369 printf (_(
'%d fiches sont insérées dans la catégorie %s') ,
$row_count ,
$name);
375 require_once __DIR__.
"/template/template_save.php";
380 $select_template=
new ISelect(
"template_id");
381 $select_template->value=$cn->make_array(
"select id,f_name from importcard.format where f_saved=1 order by f_name");
382 require_once __DIR__.
"/template/template_show.php";
create_format_temp($p_fiche_card)
fill the CSV format object Importcard_Format_SQL with default values
for($i=0;$i< Database::num_row($ret);$i++) $row
propose_format()
propose different possibilities to use your files
if(isset($_POST['remove'])) $array
test_import()
Test the CSV file, show the choosed delimiter, the CSV parsed, and replace column header by attribute...
__construct($p_file_id=-1, $p_format_id=-1)
hidden()
for the form we have here all the hidden variables
save_file()
Upload the file and record the default format and the file type $cn.
new_import()
show the first screen,
record_import()
record all rows
get_post_format()
fill object Importcard_Format_SQL with the data send by post