Plugins  LAST
 All Data Structures Files Functions Variables Pages
test_file.php
Go to the documentation of this file.
1 <?php
2 //This file is part of NOALYSS and is under GPL
3 //see licence.txt
4 ?>
5 
6 <h2>
7 <?php
8 echo _('Importation de données');
9 ?>
10 </h2>
11 
12 <p>
13  <?php echo _("Pour importer des données, c'est-à-dire transformer des fichiers CSV (Valeur séparé par des virgules) en des fiches. Vous devez choisir, un fichier et donner une catégorie de fiche existante. Ensuite, il suffit d'indiquer quelles colonnes correspondent à quelle attribut. ");?>
14 </p>
15 
16 <form method="POST" >
17 <?php echo $hidden?>
18 <table>
19 <tr>
20 <td>Délimiteur </td>
21 <td> <?php echo $_POST['rdelimiter']?></td>
22 </tr>
23 <tr>
24 <td><?php echo _("Fichier à charger");?></td><td> <?php echo $_FILES['csv_file']['name']?></td>
25 </tr>
26 <tr>
27 <td><?php echo _("Catégorie de fiche");?></td><td> <?php echo $file_cat;?></td>
28 </tr>
29 <tr>
30 <td><?php echo _("Encodage");?> </td><td> <?php echo $encoding?></td>
31 </tr>
32 <tr>
33 <td><?php echo _("Texte entouré par");?></td><td> <?php echo $_POST['rsurround'];?></td>
34 </tr>
35 </table>
36 <?php
37 foreach (array('rfichedef','rdelimiter','encodage') as $e)
38 {
39  if ( isset($_POST[$e])) echo HtmlInput::hidden($e,$_POST[$e]);
40 }
41 echo HtmlInput::hidden('filename',$filename);
42 
43  echo HtmlInput::submit('record_import','Valider');
44 ?>
45 <input type="hidden" name="rsurround" value='<?php echo $_POST['rsurround']?>'>
46 
47 
48 
49 <?php
50  global $cn;
51  ob_start();
52  /**
53  * Open the file and parse it
54  */
55 $fcard=fopen($filename,'r');
56 $row_count=0;
57 $max=0;
58 while (($row=fgetcsv($fcard,0,$_POST['rdelimiter'],$_POST['rsurround'])) !== false)
59  {
60  $row_count++;
61  echo '<tr style="border:solid 1px black">';
62  echo td($row_count);
63  $count_col=count($row);
64  $max=($count_col>$max)?$count_col:$max;
65  for ($i=0;$i<$count_col;$i++)
66  {
67  echo td($row[$i],'style="border:solid 1px black"');
68  }
69  echo '</tr>';
70  }
71 $table=ob_get_contents();
72 ob_end_clean();
73 
74 
75 echo '<table style="border:solid 1px black;width:100%">
76 <tr>';
77 
78 /**
79  *create widget column header
80  */
81 $header=new ISelect('head_col[]');
82 $fiche_def=HtmlInput::default_value_post('rfichedef', -1);
83 if ( $fiche_def == -1 ||isNumber($fiche_def)==0) {
84  throw new Exception(_('Catégorie invalide'));
85 }
86 $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 ', sql_string($fiche_def));
87 $a_attribute=$cn->get_array($sql);
88 $header->value=$cn->make_array($sql);
89 $header->value[]=array('value'=>-1,'label'=>'-- Non Utilisé --');
90 $header->selected=-1;
91 echo th(_('Numéro de ligne'));
92 for ($i=0;$i<$max;$i++)
93  {
94  // Select the default column
95  $header->selected=$a_attribute[$i]['ad_id'];
96  echo '<th>'.$header->input().'</th>';
97  }
98 echo '</tr>';
99 echo $table;
100 echo '</table>';
101 echo '</form>';
102 ?>
$max
Definition: test_file.php:33
if($fcard==FALSE) $row_count
Definition: test_file.php:32
for($i=0;$i< Database::num_row($ret);$i++) $row
$header
$p_year value
$categorie_appel table
global $cn
Definition: test_file.php:20
$categorie_appel name
while(($row=fgetcsv($fcard, 0, $delimiter, $surround))!==false) $table
Definition: test_file.php:48
$sql
$fcard
Open the file and parse it.
Definition: test_file.php:26