Plugins  LAST
 All Data Structures Files Functions Variables Pages
import_plan.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This file is part of NOALYSS.
4  *
5  * NOALYSS is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * NOALYSS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with NOALYSS; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 /* $Revision$ */
20 
21 // Copyright (c) 2002 Author Dany De Bontridder dany@alchimerys.be
22 
23 /**\file
24  * \brief import Accountancy plan
25  */
26 echo '<div style="width:80%;margin-left:10%;border-collapse: separate;border-spacing: 5px;">';
27 if (!isset($_POST['imp']) && !isset($_GET['confirm']))
28 {
29  ?>
30 
31 
32  <h2> Importer le plan comptable</h2>
33  Comment votre fichier doit être ?
34  <ul>
35  <li>Il faut 4 champs</li>
36  <li>Les champs sont séparés par des points virgules</li>
37  </ul>
38  Les champs sont
39  <ol>
40  <li>Le poste comptable</li>
41  <li>Le libellé du poste</li>
42  <li>Le poste parent</li>
43  <li>Le type de poste : PAS pour passif, ACT pour actif, PRO pour produit, CHA pour charge, CON suivant contexte, pour les comptes inversés ajouter INV à la fin, exemple PROINV (produit compte inversé)</li>
44  </ol>
45  <?php
46  echo ' <form method="post" enctype="multipart/form-data" >';
47  echo HtmlInput::hidden('sa', $_GET ['sa']);
48  echo HtmlInput::extension();
49  echo dossier::hidden();
50  $file = new IFile('plan');
51 
52  echo '<p>';
53  echo $file->input();
54  echo '</p>';
55 
56  $latin = new ICheckBox('latin');
57  $overwrite = new ICheckBox('over');
58  echo "Le fichier n'est pas en unicode mais en latin1" . $latin->input() . '<br>';
59  echo "Supprimer le plan comptable uniquement si vous n'avez entré aucune opération" . $overwrite->input() . "</br>";
60 
61  echo HtmlInput::submit('imp', 'Importation');
62  ?>
63 
64 
65  </form>
66  <?php
67 }
68 
69 // Import the file and ask to confirm
70 if (isset($_POST['imp']))
71 {
72 
73  if (trim($_FILES['plan']['name']) == '')
74  {
75  alert('Pas de fichier donné');
76  return -1;
77  }
78 
79  $filename = tempnam($_ENV['TMP'], 'upload_');
80  move_uploaded_file($_FILES["plan"]["tmp_name"], $filename);
81  $fplan = fopen($filename, 'r');
82  echo '<table>';
83  $row_count = 0;
84  while (($row = fgetcsv($fplan, 0, ';')) !== false)
85  {
86  $row_count++;
87  echo '<tr style="border:solid 1px black">';
88  $count_col = count($row);
89  if ($count_col == 4)
90  {
91  echo td($row_count);
92  echo td($count_col);
93  for ($i = 0; $i < 4; $i++)
94  {
95  echo td($row[$i], 'style="border:solid 1px black"');
96  }
97  }
98  echo '</tr>';
99  }
100  echo '</table>';
101  echo '<form method="get">';
102  echo HtmlInput::hidden('file', $filename);
103  echo dossier::hidden();
104  echo HtmlInput::hidden('sa', $_REQUEST['sa']);
105  echo HtmlInput::extension();
106  if (isset($_POST['latin']))
107  echo HtmlInput::hidden('latin', $_POST['latin']);
108  if (isset($_POST['over']))
109  echo HtmlInput::hidden('over', $_POST['over']);
110  echo HtmlInput::hidden('ac', $_REQUEST['ac']);
111  echo HtmlInput::submit('confirm', 'Confirmez');
112  echo '</form>';
113 }
114 /*
115  * delete and insert into tmp_pcmn
116  */
117 if (isset($_GET['confirm']))
118 {
119  $cn->start();
120  global $g_failed, $g_succeed;
121  if (isset($_GET ['over']))
122  {
123  $cn->exec_sql('delete from tmp_pcmn');
124  }
125  $fplan = fopen($_GET['file'], 'r');
126  echo '<table>';
127  $row_count = 0;
128  while (($row = fgetcsv($fplan, 0, ';')) !== false)
129  {
130 
131  $count_col = count($row);
132  if ($count_col == 4)
133  {
134  $dup = $cn->get_value('select * from tmp_pcmn where pcm_val=$1', array($row[0]));
135  // check duplicate
136  if ($dup == 0)
137  {
138  // insert
139  if (isset($_GET['latin']))
140  {
141  $cn->exec_sql("insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent,pcm_type) values ($1,$2,$3,$4)", array(
142  $row[0],
143  utf8_encode($row[1]),
144  $row[2],
145  $row[3])
146  );
147  }
148  else
149  {
150  $cn->exec_sql("insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent,pcm_type) values ($1,$2,$3,$4)", array(
151  $row[0],
152  $row[1],
153  $row[2],
154  $row[3]
155  )
156  );
157  }
158  $ok = 1;
159  }
160  else
161  $ok = 0;
162  echo '<tr style="border:solid 1px black">';
163  $row_count++;
164 
165  echo td($row_count);
166  for ($i = 0; $i < 4; $i++)
167  {
168  echo td($row[$i], 'style="border:solid 1px black"');
169  }
170  if ($ok == 1)
171  echo '<td>' . $g_succeed . '</td>';
172  else
173  echo '<td>' . $g_failed . '</td>';
174  }
175  echo '</tr>';
176  }
177  echo '</table>';
178  echo "Nombre de postes insérés " . $row_count;
179  $cn->commit();
180 }
181 echo '</div>';
182 
global $g_failed
for($i=0;$i< Database::num_row($ret);$i++) $row
global $g_succeed
$_REQUEST['sb']
Definition: am_print.php:39
$file
Definition: import_bank.php:60
$row_count
global $cn