1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
| <?php
define('IN_PHPBB', 1);
//
// Let's set the root dir for phpBB
//
$phpbb_root_path = "./../";
require($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'includes/functions_selects.'.$phpEx);
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
define('IN_ADMIN', true);
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
$debut = microtime(true);
if (empty($no_page_header))
{
include('./page_header_admin.'.$phpEx);
}
$template->set_filenames(array(
'body' => 'admin/action_creer_utilisateurs.tpl')
);
//
// Récupération de la liste
//
$email_liste = array();
$email_bdd = array();
if( isset($_POST['upload']) ) // si formulaire soumis
{
$content_dir = './'; // dossier où sera déplacé le fichier
$tmp_file = $_FILES['fichier']['tmp_name'];
if( !is_uploaded_file($tmp_file) )
{
message_die(GENERAL_ERROR, "Le fichier est introuvable");
}
// on vérifie maintenant l'extension
$extension = strrchr($_FILES['fichier']['name'], '.');
//Ensuite on teste
if(trim($extension) != '.csv')
{
message_die(GENERAL_MESSAGE, 'no_csv');
}
// on copie le fichier dans le dossier de destination
$name_file = $_FILES['fichier']['name'];
if( !move_uploaded_file($tmp_file, $content_dir . $name_file) )
{
message_die(GENERAL_ERROR, "Impossible de copier le fichier dans $content_dir");
}
$template->assign_vars(array(
'CREER_OFFRE_SUBMIT' => "ajouter",
'TITRE_PAGE' => $lang['maj_bdd'],
'PSEUDO' => $lang['pseudo'],
'EMAIL' => $lang['email'],
'MOT_DE_PASSE' => $lang['mot_de_passe'],
'SUPPRIMER' => $lang['Delete'],
'CREER_OFFRE' => $lang['Creer_offre'],
'EDITER' => $lang['Edit'])
);
$row = 1;
$handle = fopen($name_file, "r");
if ($handle == 0)
{
message_die(GENERAL_MESSAGE, 'Fichier impossible à ouvrir');
}
$nb_cree = 0;
while (($data = fgetcsv($handle, 1000, "\r")) !== FALSE)
{
$num = count($data);
$row++;
for ($c=0; $c < $num-1; $c++) // Pour chaque utilisateur
{
$email = "";
for ($a = 0; $a <= 4; $a++)
{
$chaine = strval($data[$c]);
$Ligne = explode(";",$chaine);
$donnée = $Ligne[$a];
if ($a == 0)
{
$nom = $donnée;
}
else if ($a == 1)
{
$email = trim($donnée);
$email = strtolower($email);
}
}
$email_liste[] = array($email, $nom);
}
}
fclose($handle);
}
else
{
message_die(GENERAL_MESSAGE, "Pas de forumulaire");
}
// On récupère le nombre total d'inscrits avant la création
$nb_dans_bdd = 0;
$sql = "SELECT user_email
FROM phpbb_users
WHERE user_id <> -1";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Impossible d\'obtenir la liste des inscrits', '', __LINE__, __FILE__, $sql);
}
while( $row = $db->sql_fetchrow($result) )
{
$email_bdd[] = strtolower(trim($row['user_email']));
}
$nb_cree = 0;
//--------------------------------------------------------------------//
// Vérification : est-ce que les mail dans la liste sont dans la bdd //
//-------------------------------------------------------------------//
for ($i = 0; $i <= count($email_liste)-1; $i++)
{
if ( !(in_array($email_liste[$i][0],$email_bdd)))
{
$nb_cree++;
$nom_text = '\'' . $nom . '\'';
$email_text = '\'' . $email_liste[$i][0] . '\'';
$date_inscription = time();
// ajout de l'utilisateur à la base de donnée
$insert = "INSERT INTO phpbb_users(user_id, username, user_regdate, user_email)
VALUES(" . $user_id . ", " . $nom_text . "," . $date_inscription .", " . $email_text . ")";
if( !($result = $db->sql_query($insert)) )
{
message_die(GENERAL_ERROR, 'Impossible d\'ajouter un membre', '', __LINE__, __FILE__, $insert);
}
$email_bdd[] = $email_liste[$i][0];
}
}
$template->assign_vars(array(
'PRESENTATION_PAGE' => $lang['presentation_traitement'],
'NOMBRE_DANS_BDD' => count($email_bdd),
'NOMBRE_LISTE' => count($email_liste),
'NOMBRE_CREE' => $nb_cree,
)
);
$template->pparse("body");
?> |
Partager