Overview
SHA1:06f494acb38a2d537293b0d2ac47a1ca00e4df04
Date: 2017-09-21 01:55:51
User: bohwaz
Comment:Correction import CSV: ignorer le BOM UTF-8 au début du CSV (signalé par @Jean-jaques et @Nicolas)
Timelines: family | ancestors | descendants | both | dev
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2017-09-21
07:08
[d3c235bbd3] Créer une sauvegarde avant mise à jour (user: bohwaz, tags: dev)
01:55
[06f494acb3] Correction import CSV: ignorer le BOM UTF-8 au début du CSV (signalé par @Jean-jaques et @Nicolas) (user: bohwaz, tags: dev)
2017-09-20
06:33
[b4e9e4804f] @count n'est plus une syntaxe valide (user: bohwaz, tags: dev)
Changes

Modified src/include/lib/Garradin/Compta/Import.php from [60189afd5d] to [5efe3ab736].

102
103
104
105
106
107
108

109
110
111
112
113
114
115
...
281
282
283
284
285
286
287

288
289
290
291
292
293
294
...
300
301
302
303
304
305
306

307
308

309
310
311

312
313
314
315
316
317
318
319
320
321
322
				return null;

			return $row[$columns[$column]];
		};

		$line = 0;
		$delim = Utils::find_csv_delim($fp);


		while (!feof($fp))
		{
			$row = fgetcsv($fp, 4096, $delim);
			$line++;

			if (empty($row))
................................................................................
				return null;

			return $row[$columns[$column]];
		};

		$line = 0;
		$delim = Utils::find_csv_delim($fp);


		while (!feof($fp))
		{
			$row = fgetcsv($fp, 4096, $delim);
			$line++;

			if (empty($row))
................................................................................
			{
				$columns = $row;
				$columns = array_flip($columns);
				continue;
			}

			$date = $col('Date');


			if (!preg_match('!^\d{2}/\d{2}/\d{4}$!', $date))

			{
				$db->rollback();
				throw new UserException('Erreur sur la ligne ' . $line . ' : la date n\'est pas au format jj/mm/aaaa.');

			}

			$date = explode('/', $date);
			$date = $date[2] . '-' . $date[1] . '-' . $date[0];

			if ($db->test('compta_exercices', '(? < debut OR ? > fin) AND cloture = 0', $date, $date))
			{
				continue;
			}

			$debit = $get_compte($col('Compte débité - Numéro'), $col('Compte débité - Intitulé'));







>







 







>







 







>

<
>


<
>


<
|







102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
...
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
...
302
303
304
305
306
307
308
309
310

311
312
313

314
315
316

317
318
319
320
321
322
323
324
				return null;

			return $row[$columns[$column]];
		};

		$line = 0;
		$delim = Utils::find_csv_delim($fp);
		Utils::skip_bom($fp);

		while (!feof($fp))
		{
			$row = fgetcsv($fp, 4096, $delim);
			$line++;

			if (empty($row))
................................................................................
				return null;

			return $row[$columns[$column]];
		};

		$line = 0;
		$delim = Utils::find_csv_delim($fp);
		Utils::skip_bom($fp);

		while (!feof($fp))
		{
			$row = fgetcsv($fp, 4096, $delim);
			$line++;

			if (empty($row))
................................................................................
			{
				$columns = $row;
				$columns = array_flip($columns);
				continue;
			}

			$date = $col('Date');
			$date = \DateTime::createFromFormat('d/m/Y', $date);


			if (!$date)
			{
				$db->rollback();

				throw new UserException(sprintf('Erreur sur la ligne %d : la date "%s" n\'est pas au format jj/mm/aaaa.', $line, $col('Date')));
			}


			$date = $date->format('Y-m-d');

			if ($db->test('compta_exercices', '(? < debut OR ? > fin) AND cloture = 0', $date, $date))
			{
				continue;
			}

			$debit = $get_compte($col('Compte débité - Numéro'), $col('Compte débité - Intitulé'));

Modified src/include/lib/Garradin/Membres/Import.php from [c8e1a71b74] to [eefd4b70a3].

91
92
93
94
95
96
97

98
99
100
101
102
103
104
...
172
173
174
175
176
177
178

179
180
181
182
183
184
185
				return null;

			return $row[$columns[$column]];
		};

		$line = 0;
		$delim = Utils::find_csv_delim($fp);


		while (!feof($fp))
		{
			$row = fgetcsv($fp, 4096, $delim);
			$line++;

			if (empty($row))
................................................................................
		$champs[] = 'date_inscription';
		//$champs[] = 'date_connexion';
		//$champs[] = 'id';
		//$champs[] = 'id_categorie';

		$line = 0;
		$delim = Utils::find_csv_delim($fp);


		while (!feof($fp))
		{
			$row = fgetcsv($fp, 4096, $delim);

			$line++;








>







 







>







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
				return null;

			return $row[$columns[$column]];
		};

		$line = 0;
		$delim = Utils::find_csv_delim($fp);
		Utils::skip_bom($fp);

		while (!feof($fp))
		{
			$row = fgetcsv($fp, 4096, $delim);
			$line++;

			if (empty($row))
................................................................................
		$champs[] = 'date_inscription';
		//$champs[] = 'date_connexion';
		//$champs[] = 'id';
		//$champs[] = 'id_categorie';

		$line = 0;
		$delim = Utils::find_csv_delim($fp);
		Utils::skip_bom($fp);

		while (!feof($fp))
		{
			$row = fgetcsv($fp, 4096, $delim);

			$line++;

Modified src/include/lib/Garradin/Utils.php from [06255be23d] to [2bf872f126].

646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
...
668
669
670
671
672
673
674

675
676









677
678
679
680
681
682
683
684
685
686
687
688
            if (!(is_numeric($params['query']) && (int)$params['query'] === 1) && $params['query'] !== true)
                $url .= $params['query'];
        }

        return $url;
    }

    static public function find_csv_delim($fp)
    {
        $line = '';

        while ($line === '' && !feof($fp))
        {
            $line = trim(fgets($fp, 4096));
        }
................................................................................
            "\t"=> substr_count($line, "\t")
        ];

        arsort($delims);
        reset($delims);

        rewind($fp);

        return key($delims);
    }










    static public function row_to_csv($row)
    {
        $row = (array) $row;

        array_walk($row, function ($field) {
            return str_replace('"', '""', $field);
        });

        return '"' . implode('", "', $row) . '"';
    }
}







|







 







>


>
>
>
>
>
>
>
>
>












646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
...
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
            if (!(is_numeric($params['query']) && (int)$params['query'] === 1) && $params['query'] !== true)
                $url .= $params['query'];
        }

        return $url;
    }

    static public function find_csv_delim(&$fp)
    {
        $line = '';

        while ($line === '' && !feof($fp))
        {
            $line = trim(fgets($fp, 4096));
        }
................................................................................
            "\t"=> substr_count($line, "\t")
        ];

        arsort($delims);
        reset($delims);

        rewind($fp);

        return key($delims);
    }

    static public function skip_bom(&$fp)
    {
        // Skip BOM
        if (fgets($fp, 4) !== chr(0xEF) . chr(0xBB) . chr(0xBF))
        {
            fseek($fp, 0);
        }
    }

    static public function row_to_csv($row)
    {
        $row = (array) $row;

        array_walk($row, function ($field) {
            return str_replace('"', '""', $field);
        });

        return '"' . implode('", "', $row) . '"';
    }
}

Modified src/www/admin/compta/import.php from [8dcdde991d] to [9b4e3790c6].

45
46
47
48
49
50
51
52
53
54
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }
}

$tpl->assign('ok', qg('ok'));

$tpl->display('admin/compta/import.tpl');







|


45
46
47
48
49
50
51
52
53
54
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }
}

$tpl->assign('ok', qg('ok') !== null);

$tpl->display('admin/compta/import.tpl');