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 <h2>
6 <?php
7 echo _('Importation de données');
8 ?>
9 </h2>
10 
11 <p>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.
12 </p>
13 
14 <form method="POST" >
15 <?php echo $hidden?>
16 <table>
17 <tr>
18 <td>Délimiteur </td>
19 <td> <?php echo $_POST['rdelimiter']?></td>
20 </tr>
21 <tr>
22 <td>Fichier à charger</td><td> <?php echo $_FILES['csv_file']['name']?></td>
23 </tr>
24 <tr>
25 <td>Catégorie de fiche</td><td> <?php echo $file_cat;?></td>
26 </tr>
27 <tr>
28 <td>Encodage </td><td> <?php echo $encoding?></td>
29 </tr>
30 <tr>
31 <td>Texte entouré par</td><td> <?php echo $_POST['rsurround'];?></td>
32 </tr>
33 </table>
34 <?php
35 foreach (array('rfichedef','rdelimiter','encodage') as $e)
36 {
37  if ( isset($_POST[$e])) echo HtmlInput::hidden($e,$_POST[$e]);
38 }
39 echo HtmlInput::hidden('filename',$filename);
40 
41  echo HtmlInput::submit('record_import','Valider');
42 ?>
43 <input type="hidden" name="rsurround" value='<?php echo $_POST['rsurround']?>'>
44 
45 
46 
47 <?php
48  global $cn;
49  ob_start();
50  /**
51  * Open the file and parse it
52  */
53 $fcard=fopen($filename,'r');
54 $row_count=0;
55 $max=0;
56 while (($row=fgetcsv($fcard,0,$_POST['rdelimiter'],$_POST['rsurround'])) !== false)
57  {
58  $row_count++;
59  echo '<tr style="border:solid 1px black">';
60  echo td($row_count);
61  $count_col=count($row);
62  $max=($count_col>$max)?$count_col:$max;
63  for ($i=0;$i<$count_col;$i++)
64  {
65  echo td($row[$i],'style="border:solid 1px black"');
66  }
67  echo '</tr>';
68  }
69 $table=ob_get_contents();
70 ob_end_clean();
71 
72 
73 echo '<table style="border:solid 1px black;width:100%">
74 <tr>';
75 
76 /**
77  *create widget column header
78  */
79 $header=new ISelect('head_col[]');
80 
81 $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 ',$_POST['rfichedef']);
82 $header->value=$cn->make_array($sql);
83 $header->value[]=array('value'=>-1,'label'=>'-- Non Utilisé --');
84 $header->selected=-1;
85 echo th('Numéro de ligne');
86 for ($i=0;$i<$max;$i++)
87  {
88  echo '<th>'.$header->input().'</th>';
89  }
90 echo '</tr>';
91 echo $table;
92 echo '</table>';
93 echo '</form>';
94 ?>
$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