1 | <?php |
---|
2 | if (!defined("PHPWG_ROOT_PATH")) |
---|
3 | { |
---|
4 | die ("Hacking attempt!"); |
---|
5 | } |
---|
6 | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | Functions | |
---|
9 | // +-----------------------------------------------------------------------+ |
---|
10 | |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | Check Access and exit when user status is not ok | |
---|
13 | // +-----------------------------------------------------------------------+ |
---|
14 | |
---|
15 | check_status(ACCESS_ADMINISTRATOR); |
---|
16 | |
---|
17 | load_language('plugin.lang', UMR_PATH); |
---|
18 | |
---|
19 | // +-----------------------------------------------------------------------+ |
---|
20 | // | Tabs | |
---|
21 | // +-----------------------------------------------------------------------+ |
---|
22 | |
---|
23 | $page['tab'] = 'home'; |
---|
24 | |
---|
25 | // tabsheet |
---|
26 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
27 | $tabsheet = new tabsheet(); |
---|
28 | $tabsheet->set_id('umr'); |
---|
29 | |
---|
30 | $tabsheet->add('home', l10n('User Mass Register'), UMR_ADMIN . '-home'); |
---|
31 | $tabsheet->select($page['tab']); |
---|
32 | $tabsheet->assign(); |
---|
33 | |
---|
34 | // +-----------------------------------------------------------------------+ |
---|
35 | // | Actions | |
---|
36 | // +-----------------------------------------------------------------------+ |
---|
37 | |
---|
38 | if (isset($_POST['submit'])) |
---|
39 | { |
---|
40 | $lines = explode("\n", $_POST['users']); |
---|
41 | |
---|
42 | $emails_to_create = array(); |
---|
43 | $emails_rejected = array(); |
---|
44 | $emails_already_exist = array(); |
---|
45 | $emails_created = array(); |
---|
46 | $emails_on_error = array(); |
---|
47 | $username_for = array(); |
---|
48 | |
---|
49 | foreach ($lines as $line) |
---|
50 | { |
---|
51 | $fields = explode(';', $line); |
---|
52 | $email = trim($fields[0]); |
---|
53 | |
---|
54 | if (isset($fields[1])) |
---|
55 | { |
---|
56 | $username_for[$email] = trim($fields[1]); |
---|
57 | } |
---|
58 | |
---|
59 | $email = trim($email); |
---|
60 | |
---|
61 | // this test requires PHP 5.2+ |
---|
62 | if (filter_var($email, FILTER_VALIDATE_EMAIL) !== false) |
---|
63 | { |
---|
64 | $emails_to_check[] = $email; |
---|
65 | |
---|
66 | if (!get_userid_by_email($email)) |
---|
67 | { |
---|
68 | $emails_to_create[] = $email; |
---|
69 | } |
---|
70 | else |
---|
71 | { |
---|
72 | $emails_existing[] = $email; |
---|
73 | } |
---|
74 | } |
---|
75 | elseif (!empty($email)) |
---|
76 | { |
---|
77 | $emails_rejected[] = $email; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | foreach ($emails_to_create as $email) |
---|
82 | { |
---|
83 | // find a username |
---|
84 | if (isset($username_for[$email])) |
---|
85 | { |
---|
86 | $username = $username_for[$email]; |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | list($username,) = explode('@', $email); |
---|
91 | } |
---|
92 | |
---|
93 | $base_username = $username; |
---|
94 | $i = 2; |
---|
95 | while (get_userid($username)) |
---|
96 | { |
---|
97 | $username = $base_username.($i++); |
---|
98 | } |
---|
99 | |
---|
100 | // find a password |
---|
101 | $password = generate_key(8); |
---|
102 | |
---|
103 | $user_id = register_user($username, $password, $email, true, $errors, true); |
---|
104 | if (!empty($errors)) |
---|
105 | { |
---|
106 | $emails_on_error[] = $email; |
---|
107 | } |
---|
108 | else |
---|
109 | { |
---|
110 | $emails_created[] = $email; |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | $emails_for_form = array(); |
---|
115 | |
---|
116 | if (!empty($emails_created)) |
---|
117 | { |
---|
118 | array_push( |
---|
119 | $page['infos'], |
---|
120 | sprintf( |
---|
121 | l10n('%d users registered'), |
---|
122 | count($emails_created) |
---|
123 | ) |
---|
124 | ); |
---|
125 | } |
---|
126 | |
---|
127 | if (!empty($emails_on_error)) |
---|
128 | { |
---|
129 | array_push( |
---|
130 | $page['errors'], |
---|
131 | sprintf( |
---|
132 | l10n('%d registrations on error: %s'), |
---|
133 | count($emails_on_error), |
---|
134 | implode(', ', $emails_on_error) |
---|
135 | ) |
---|
136 | ); |
---|
137 | |
---|
138 | $emails_for_form = array_merge($emails_for_form, $emails_on_error); |
---|
139 | } |
---|
140 | |
---|
141 | if (!empty($emails_rejected)) |
---|
142 | { |
---|
143 | array_push( |
---|
144 | $page['errors'], |
---|
145 | sprintf( |
---|
146 | l10n('%d email addresses rejected: %s'), |
---|
147 | count($emails_rejected), |
---|
148 | implode(', ', $emails_rejected) |
---|
149 | ) |
---|
150 | ); |
---|
151 | |
---|
152 | $emails_for_form = array_merge($emails_for_form, $emails_rejected); |
---|
153 | } |
---|
154 | |
---|
155 | if (!empty($emails_existing)) |
---|
156 | { |
---|
157 | array_push( |
---|
158 | $page['warnings'], |
---|
159 | sprintf( |
---|
160 | l10n('%d email addresses already exist: %s'), |
---|
161 | count($emails_existing), |
---|
162 | implode(', ', $emails_existing) |
---|
163 | ) |
---|
164 | ); |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | // +-----------------------------------------------------------------------+ |
---|
169 | // | form | |
---|
170 | // +-----------------------------------------------------------------------+ |
---|
171 | |
---|
172 | // define template file |
---|
173 | $template->set_filename('umr_content', realpath(UMR_PATH . 'admin.tpl')); |
---|
174 | |
---|
175 | // template vars |
---|
176 | $template->assign(array( |
---|
177 | 'UMR_PATH'=> get_root_url() . UMR_PATH, // used for images, scripts, ... access |
---|
178 | 'UMR_ABS_PATH'=> realpath(UMR_PATH), // used for template inclusion (Smarty needs a real path) |
---|
179 | 'UMR_ADMIN' => UMR_ADMIN, |
---|
180 | )); |
---|
181 | |
---|
182 | if (isset($emails_for_form) and !empty($emails_for_form)) |
---|
183 | { |
---|
184 | $template->assign('EMAILS', implode("\n", $emails_for_form)); |
---|
185 | } |
---|
186 | |
---|
187 | // +-----------------------------------------------------------------------+ |
---|
188 | // | sending html code | |
---|
189 | // +-----------------------------------------------------------------------+ |
---|
190 | |
---|
191 | // send page content |
---|
192 | $template->assign_var_from_handle('ADMIN_CONTENT', 'umr_content'); |
---|
193 | |
---|
194 | ?> |
---|