23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
$import->toODS();
exit;
}
$champs = $config->get('champs_membres')->getAll();
$champs->date_inscription = (object) ['title' => 'Date inscription', 'type' => 'date'];
if (f('import'))
{
$form->check('membres_import', [
'upload' => 'file|required',
'type' => 'required|in:galette,garradin',
'galette_translate' => 'array',
]);
if (!$form->hasErrors())
{
try
{
if (f('type') == 'galette')
{
$import->fromGalette($_FILES['upload']['tmp_name'], f('galette_translate'));
}
elseif (f('type') == 'garradin')
{
$import->fromCSV($_FILES['upload']['tmp_name'], $user->id);
}
else
{
throw new UserException('Import inconnu.');
}
Utils::redirect(ADMIN_URL . 'membres/import.php?ok');
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
}
$tpl->assign('ok', null !== qg('ok') ? true : false);
$tpl->assign('garradin_champs', $champs);
$tpl->assign('galette_champs', $import->galette_fields);
$tpl->assign('translate', f('galette_translate'));
$tpl->display('admin/membres/import.tpl');
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
<
|
|
>
|
|
<
<
>
>
>
<
<
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
$import->toODS();
exit;
}
$champs = $config->get('champs_membres')->getAll();
$champs->date_inscription = (object) ['title' => 'Date inscription', 'type' => 'date'];
$csv_file = false;
if (f('csv_encoded'))
{
$form->check('membres_import', [
'csv_encoded' => 'required|json',
'csv_translate' => 'required|array',
'skip_first_line' => 'boolean',
]);
$csv_file = json_decode(f('csv_encoded'), true);
if (!$form->hasErrors())
{
try
{
$import->fromArray($csv_file, f('csv_translate'), f('skip_first_line') ? 1 : 0);
Utils::redirect(ADMIN_URL . 'membres/import.php?ok');
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
}
elseif (f('import'))
{
$form->check('membres_import', [
'upload' => 'file|required',
'type' => 'required|in:csv,garradin',
]);
if (!$form->hasErrors())
{
try
{
if (f('type') == 'garradin')
{
$import->fromGarradinCSV($_FILES['upload']['tmp_name'], $user->id);
Utils::redirect(ADMIN_URL . 'membres/import.php?ok');
}
elseif (f('type') == 'csv')
{
$csv_file = $import->getCSVAsArray($_FILES['upload']['tmp_name']);
}
else
{
throw new UserException('Import inconnu.');
}
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
}
$tpl->assign('ok', null !== qg('ok') ? true : false);
$tpl->assign('csv_file', $csv_file);
$tpl->assign('csv_first_line', $csv_file ? reset($csv_file) : null);
$tpl->assign('garradin_champs', $champs);
$tpl->display('admin/membres/import.tpl');
|