Import focntionnel avec vérification

This commit is contained in:
Prof Langues 2020-10-06 08:29:14 +02:00
parent 03568f6641
commit 5291f058a7
2 changed files with 38 additions and 39 deletions

View File

@ -555,7 +555,7 @@ class user extends common {
if($this->isPost()) {
// Lecture du CSV et construction du tableau
$file = $this->getInput('userImportCSVFile',helper::FILTER_STRING_SHORT, true);
$filePath = helper::baseUrl(false) . self::FILE_DIR . 'source/' . $file;
$filePath = self::FILE_DIR . 'source/' . $file;
if (file_exists ($filePath)) {
$rows = array_map(function($row) { return str_getcsv($row, $this->getInput('userImportSeparator') ); }, file($filePath));
$header = array_shift($rows);
@ -566,11 +566,11 @@ class user extends common {
// Stockage des données
foreach($csv as $item ) {
// Nettoyage de l'identifiant
$userId = helper::filter($item['id'] , self::FILTER_ID);
$userId = helper::filter($item['id'] , helper::FILTER_ID);
// N'insére que les utilisateurs dont l'id n'existe pas
if( !$this->getData(['user', $userId]) ) {
// Vérifier la présence des champs
if ( $item['prenom']
if( !$this->getData(['user', $userId])
AND $item['prenom']
AND $item['nom']
AND $item['groupe']
AND $item['email']
@ -589,6 +589,10 @@ class user extends common {
'signature' => 1, // Pseudo
'password' => uniqid() // A modifier à la première connexion
]]);
$item['notification'] = 'Ok';
} else {
$item['notification'] = 'Pb';
}
// Création du tableau de confirmation
self::$users[] = [
@ -597,14 +601,9 @@ class user extends common {
$item['prenom'],
self::$groups[$item['groupe']],
$item['prenom'],
$item['email']
$item['email'],
$item['notification']
];
$notification = 'Import efectué';
$success = true;
} else {
$success = 3;
}
}
}
} else {
$notification = 'Erreur de lecture : ' . $file;

View File

@ -38,5 +38,5 @@
</div>
<?php echo template::formClose(); ?>
<?php if ($module::$users): ?>
<?php echo template::table([1, 3, 3, 1, 1,3], $module::$users, ['Identifiant', 'Nom', 'Prénom','Groupe', 'Pseudo', 'eMail']); ?>
<?php echo template::table([1, 3, 3, 1, 1, 2, 1, 1 ], $module::$users, ['Identifiant', 'Nom', 'Prénom','Groupe', 'Pseudo', 'eMail', 'Statut']); ?>
<?php endif;?>