| Commit | Line | Data |
|---|---|---|
| 088bea1c TW |
1 | <?php |
| 2 | // $Id$ | |
| 3 | ||
| 73fe857f TW |
4 | require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc'); |
| 5 | ||
| 088bea1c TW |
6 | /** |
| 7 | * gallery.module : gallery_user_admin.inc | |
| 8 | * Gallery User Administration | |
| 9 | */ | |
| 10 | ||
| 588dcdb8 | 11 | define(G2BATCH_INTERVAL, 50); |
| 088bea1c | 12 | |
| 088bea1c | 13 | /** |
| 73fe857f TW |
14 | * Function _gallery_user_users(). |
| 15 | * (gallery users page - view list of users) | |
| 088bea1c TW |
16 | */ |
| 17 | function _gallery_user_users($args) { | |
| 588dcdb8 | 18 | // Sync the selected user |
| 088bea1c TW |
19 | if ($args && is_numeric($args)) { |
| 20 | _gallery_user_sync($args); | |
| 21 | drupal_goto('admin/user/gallery/users'); | |
| 22 | } | |
| 72b86752 | 23 | |
| 588dcdb8 | 24 | // Generate user status overview |
| 088bea1c TW |
25 | $header = array( |
| 26 | array('data' => t('ID'), 'field' => 'u.uid', 'sort' => 'asc'), | |
| 27 | array('data' => t('G2ID')), | |
| 28 | array('data' => t('Username'), 'field' => 'u.name'), | |
| 29 | array('data' => t('Status'), 'field' => 'u.status'), | |
| 30 | array('data' => t('Sync Status')), | |
| 31 | t('Operations') | |
| 32 | ); | |
| dc6f674c | 33 | $query = 'SELECT u.uid, u.name, u.status FROM {users} u WHERE uid != 0'; |
| 088bea1c TW |
34 | |
| 35 | $status = array(t('blocked'), t('active')); | |
| 36 | $destination = drupal_get_destination(); | |
| 72b86752 | 37 | $filter = $_SESSION['gallery_user_filter']; |
| 088bea1c TW |
38 | |
| 39 | if (!_gallery_init(TRUE)) { | |
| 40 | return ''; | |
| 41 | } | |
| 190c63c0 | 42 | list($ret, $g2_admin) = GalleryCoreApi::isUserInSiteAdminGroup(); |
| 87b542e2 TW |
43 | if ($ret) { |
| 44 | gallery_error(t('Error calling \'GalleryCoreApi::isUserInSiteAdminGroup\'.'), $ret); | |
| 45 | } | |
| 72b86752 | 46 | |
| 47 | if (isset($filter)) { | |
| 48 | $result = db_query($query); | |
| 49 | } | |
| 50 | else { | |
| 51 | $query .= tablesort_sql($header); | |
| 52 | $result = pager_query($query, 50); | |
| 53 | } | |
| 54 | ||
| 088bea1c | 55 | while ($user = db_fetch_object($result)) { |
| dc6f674c | 56 | $g2_userinfo = gallery_user_map_info(user_load(array('uid' => $user->uid)), FALSE); |
| 190c63c0 | 57 | |
| 088bea1c TW |
58 | $g2_id = ($g2_userinfo['g2_id'] >= 0) ? $g2_userinfo['g2_id'] : t('N/A'); |
| 59 | ||
| 60 | $operations = array(l(t('edit'), "user/$user->uid/edit", array(), $destination)); | |
| 61 | ||
| 190c63c0 | 62 | if ($g2_admin && ($g2_userinfo['g2_id'] > 0)) { |
| 088bea1c TW |
63 | $link_url = gallery_generate_url(array('view' => 'core.SiteAdmin', |
| 64 | 'subView' => 'core.AdminEditUser', | |
| 65 | 'userId' => $g2_userinfo['g2_id']), FALSE); | |
| 66 | $operations[] = l(t('edit G2'), $link_url); | |
| 67 | } | |
| 68 | ||
| 190c63c0 | 69 | if (count($g2_userinfo['status'])) { |
| 6eba0a2f | 70 | $operations[] = l(t('sync'), 'admin/user/gallery/users/sync/'. $user->uid, array(), drupal_get_destination()); |
| 088bea1c | 71 | } |
| 190c63c0 | 72 | |
| 72b86752 | 73 | if (isset($filter)) { |
| 7ddd9a6d TW |
74 | if ($filter == G2USERINFO_ERROR) { |
| 75 | if (!count($g2_userinfo['status'])) { | |
| 76 | continue; | |
| 77 | } | |
| 78 | } | |
| 79 | elseif (!in_array($filter, $g2_userinfo['status'])) { | |
| 80 | continue; | |
| 81 | } | |
| 72b86752 | 82 | } |
| 088bea1c TW |
83 | |
| 84 | $rows[] = array($user->uid, | |
| 85 | $g2_id, | |
| 86 | theme_username($user), | |
| 87 | $status[$user->status], | |
| 190c63c0 | 88 | implode(',<br />', gallery_user_map_info_status($g2_userinfo['status'])), |
| 088bea1c TW |
89 | implode(' | ', $operations)); |
| 90 | } | |
| 87b542e2 | 91 | |
| 72b86752 | 92 | if ($filter && !count($rows)) { |
| 93 | $rows[] = array(array('data' => t('There are no users with the selected status.'), 'colspan' => '6', 'align' => 'center', 'class' => 'message')); | |
| 94 | } | |
| 95 | ||
| 96 | $output = drupal_get_form('_gallery_user_filter_form', $filter); | |
| 190c63c0 TW |
97 | $output .= theme('table', $header, $rows); |
| 98 | $output .= theme('pager', array(), 50); | |
| 088bea1c TW |
99 | |
| 100 | GalleryEmbed::done(); | |
| 101 | return $output; | |
| 102 | } | |
| 103 | ||
| 104 | /** | |
| 73fe857f TW |
105 | * Function _gallery_user_filter_form(). |
| 106 | * (filter form for user status) | |
| 72b86752 | 107 | */ |
| 108 | function _gallery_user_filter_form($filter) { | |
| 109 | $form['filter'] = array( | |
| 110 | '#type' => 'fieldset', | |
| 111 | '#title' => t('Filter by status'), | |
| 112 | '#collapsible' => TRUE, | |
| 113 | '#collapsed' => !$filter, | |
| 114 | ); | |
| 190c63c0 TW |
115 | $filter_options = gallery_user_map_info_status(array(), FALSE); |
| 116 | unset($filter_options[G2USERINFO_NOERROR]); | |
| 72b86752 | 117 | $form['filter']['filter_status'] = array( |
| 118 | '#type' => 'select', | |
| 119 | '#title' => t('Show only users with status'), | |
| 190c63c0 | 120 | '#options' => $filter_options, |
| 72b86752 | 121 | '#default_value' => $filter, |
| 122 | ); | |
| 123 | $form['filter']['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Filter')); | |
| 124 | if ($filter) { | |
| 125 | $form['filter']['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset')); | |
| 126 | } | |
| 127 | $form['#submit']['_gallery_user_filter_submit'] = array(); | |
| 128 | ||
| 129 | return $form; | |
| 130 | } | |
| 131 | ||
| 132 | /** | |
| 73fe857f TW |
133 | * Function _gallery_user_filter_submit(). |
| 134 | * (submit handler of the filter form) | |
| 72b86752 | 135 | */ |
| 136 | function _gallery_user_filter_submit($form_id, $form_values) { | |
| 137 | unset($_SESSION['gallery_user_filter']); | |
| 138 | if ($form_values['op'] == t('Filter')) { | |
| 139 | $_SESSION['gallery_user_filter'] = $form_values['filter_status']; | |
| 140 | } | |
| 141 | } | |
| 142 | ||
| 143 | /** | |
| 73fe857f TW |
144 | * Function _gallery_user_advanced(). |
| 145 | * (advanced user administration) | |
| 088bea1c TW |
146 | */ |
| 147 | function _gallery_user_advanced() { | |
| 148 | $form['advanced'] = array( | |
| 149 | '#type' => 'fieldset', | |
| 3c1f5fa5 | 150 | '#title' => t('Advanced Sync (Batch operations)'), |
| 088bea1c | 151 | '#collapsible' => FALSE, |
| 588dcdb8 | 152 | '#collapsed' => FALSE, |
| 088bea1c TW |
153 | ); |
| 154 | $form['advanced']['gallery_user_advanced_import'] = array( | |
| 155 | '#type' => 'checkbox', | |
| 156 | '#title' => t('Import users from Gallery2'), | |
| 157 | '#return_value' => 1, | |
| 158 | '#default_value' => FALSE, | |
| 588dcdb8 | 159 | '#description' => t('Use this option to import users from an existing Gallery2 install into Drupal.'), |
| 088bea1c TW |
160 | ); |
| 161 | $form['advanced']['gallery_user_advanced_sync'] = array( | |
| 162 | '#type' => 'checkbox', | |
| 163 | '#title' => t('Synchronize (export) all existing users'), | |
| 164 | '#return_value' => 1, | |
| 165 | '#default_value' => FALSE, | |
| 588dcdb8 | 166 | '#description' => t('Use this option to sync all users between Drupal and Gallery2.'), |
| 088bea1c TW |
167 | ); |
| 168 | ||
| 169 | $form['advanced']['gallery_user_advanced_offline'] = array( | |
| 170 | '#type' => 'checkbox', | |
| 171 | '#title' => t('Switch Drupal to \'offline mode\' for operation'), | |
| 172 | '#return_value' => 1, | |
| 173 | '#default_value' => FALSE, | |
| 174 | '#disabled' => (user_access('administer site configuration') && !variable_get('site_offline', 0)) ? FALSE : TRUE, | |
| 588dcdb8 | 175 | '#prefix' => '<br />', |
| 088bea1c TW |
176 | ); |
| 177 | ||
| 178 | $form['buttons']['start'] = array('#type' => 'submit', '#value' => t('Start')); | |
| 179 | $form['#base'] = '_gallery_user_advanced'; | |
| 180 | return $form; | |
| 181 | } | |
| 182 | ||
| 183 | /** | |
| 588dcdb8 | 184 | * Function _gallery_user_advanced_validate(). |
| 088bea1c | 185 | */ |
| 588dcdb8 TW |
186 | function _gallery_user_advanced_validate($form_id, $form_values) { |
| 187 | if (($form_values['gallery_user_advanced_import'] + $form_values['gallery_user_advanced_sync']) < 1) { | |
| 088bea1c TW |
188 | form_set_error('', t('No option selected.')); |
| 189 | } | |
| 190 | } | |
| 191 | ||
| 192 | /** | |
| 588dcdb8 | 193 | * Function _gallery_user_advanced_submit(). |
| 088bea1c | 194 | */ |
| 588dcdb8 TW |
195 | function _gallery_user_advanced_submit($form_id, $form_values) { |
| 196 | if ($form_values['op'] == t('Start')) { | |
| 197 | if ($form_values['gallery_user_progress_offline']) { | |
| 088bea1c TW |
198 | variable_set('site_offline', 1); |
| 199 | $_SESSION['gallery_user_progress_offline'] = TRUE; | |
| 200 | } | |
| 201 | ||
| 588dcdb8 TW |
202 | $tasks = array(); |
| 203 | if ($form_values['gallery_user_advanced_import']) { | |
| 204 | $tasks[] = 'import'; | |
| 088bea1c | 205 | } |
| 588dcdb8 TW |
206 | if ($form_values['gallery_user_advanced_sync']) { |
| 207 | $tasks[] = 'sync'; | |
| 088bea1c | 208 | } |
| 588dcdb8 | 209 | _gallery_user_advanced_start($tasks); |
| 088bea1c TW |
210 | } |
| 211 | } | |
| 212 | ||
| 213 | /** | |
| 588dcdb8 | 214 | * Function _gallery_user_advanced_import(). |
| 088bea1c TW |
215 | */ |
| 216 | function _gallery_user_advanced_import(&$position) { | |
| 588dcdb8 | 217 | // Get number of G2 users |
| 6758036d | 218 | list($ret, $total) = GalleryCoreApi::fetchUserCount(); |
| 088bea1c TW |
219 | if ($ret || !$total) { |
| 220 | gallery_error(t('Error getting number of G2 users'), $ret); | |
| 221 | return 100; | |
| 222 | } | |
| 588dcdb8 | 223 | // First pass |
| 088bea1c | 224 | if (!$position) { |
| b304c130 TW |
225 | // Flush entity cache |
| 226 | gallery_flush_entity_cache(); | |
| 588dcdb8 | 227 | // Import Gallery2 groups |
| 088bea1c | 228 | if (variable_get('gallery_user_import_groups', 1)) { |
| d582342e | 229 | _gallery_groups_import(); |
| 088bea1c TW |
230 | } |
| 231 | } | |
| d582342e | 232 | // Fetch a list of G2 users |
| 6758036d | 233 | list($ret, $g2_users) = GalleryCoreApi::fetchUsernames(G2BATCH_INTERVAL, $position); |
| 088bea1c TW |
234 | if ($ret) { |
| 235 | gallery_error(t('Error fetching G2 usernames'), $ret); | |
| 236 | return 0; | |
| 237 | } | |
| 238 | else { | |
| 588dcdb8 TW |
239 | if (!_gallery_user_import($g2_users)) { |
| 240 | return 0; | |
| 241 | } | |
| 088bea1c TW |
242 | } |
| 243 | $position += G2BATCH_INTERVAL; | |
| 647a600b | 244 | |
| 088bea1c TW |
245 | return ( 100 * $position ) / $total; |
| 246 | } | |
| 247 | ||
| 248 | /** | |
| 588dcdb8 | 249 | * Function _gallery_user_advanced_sync(). |
| 088bea1c TW |
250 | */ |
| 251 | function _gallery_user_advanced_sync(&$position) { | |
| 252 | $total = db_fetch_object(db_query("SELECT COUNT(*) AS users FROM {users} WHERE uid > 0")); | |
| 253 | if (!$total->users) { | |
| 254 | return 100; | |
| 255 | } | |
| 588dcdb8 | 256 | // Empty externalIdMap in first pass |
| 088bea1c TW |
257 | if (!$position && variable_get('gallery_user_sync_remap', 0)) { |
| 258 | $ret = GalleryCoreApi::removeAllMapEntries('ExternalIdMap'); | |
| 259 | if ($ret) { | |
| 260 | gallery_error(t('Error emptying \'ExternalIdMap\''), $ret); | |
| 261 | return 0; | |
| 262 | } | |
| 263 | } | |
| 588dcdb8 | 264 | // Sync users |
| 088bea1c TW |
265 | $result = db_query_range("SELECT uid FROM {users} WHERE uid > 0", $position, G2BATCH_INTERVAL); |
| 266 | while ($user = db_fetch_object($result)) { | |
| 267 | if ($account = user_load(array('uid' => $user->uid))) { | |
| 588dcdb8 TW |
268 | if (!gallery_user_modify($account, 'update', !$position)) { |
| 269 | return 0; | |
| 270 | } | |
| 088bea1c TW |
271 | } |
| 272 | } | |
| 273 | $position += G2BATCH_INTERVAL; | |
| 274 | ||
| 275 | return ( 100 * $position ) / $total->users; | |
| 276 | } | |
| 277 | ||
| 278 | /** | |
| 588dcdb8 | 279 | * Function _gallery_user_advanced_start(). |
| 088bea1c | 280 | */ |
| 588dcdb8 | 281 | function _gallery_user_advanced_start($mode, $redirect = NULL) { |
| 088bea1c TW |
282 | $_SESSION['gallery_user_progress_mode'] = $mode; |
| 283 | $_SESSION['gallery_user_progress_position'] = 0; | |
| 049f9e86 | 284 | $_SESSION['gallery_user_progress_messages'] = array(); |
| 588dcdb8 | 285 | $_SESSION['gallery_user_progress_redirect'] = $redirect; |
| 088bea1c TW |
286 | drupal_goto('admin/user/gallery/advanced_progress'); |
| 287 | } | |
| 288 | ||
| 289 | /** | |
| 588dcdb8 | 290 | * Function _gallery_user_advanced_progress(). |
| 088bea1c TW |
291 | */ |
| 292 | function _gallery_user_advanced_progress() { | |
| 293 | $mode = $_SESSION['gallery_user_progress_mode']; | |
| 294 | $position = $_SESSION['gallery_user_progress_position']; | |
| 049f9e86 | 295 | $messages = $_SESSION['gallery_user_progress_messages']; |
| 588dcdb8 | 296 | $redirect = $_SESSION['gallery_user_progress_redirect']; |
| 088bea1c | 297 | if ($_SERVER['REQUEST_METHOD'] == 'GET') { |
| 588dcdb8 | 298 | if (!_gallery_init(TRUE, NULL, FALSE)) { |
| 647a600b | 299 | $percent = 0; |
| 588dcdb8 | 300 | drupal_set_message(t('Unable to initialize embedded Gallery.'), 'error'); |
| 647a600b TW |
301 | } |
| 302 | else { | |
| 588dcdb8 | 303 | switch (reset($mode)) { |
| 647a600b | 304 | case 'import': |
| 049f9e86 | 305 | $status = t('Importing Gallery2 users into Drupal ...'); |
| 647a600b TW |
306 | $percent = _gallery_user_advanced_import($position); |
| 307 | break; | |
| 308 | case 'sync': | |
| 049f9e86 | 309 | $status = t('Synchronizing Drupal and Gallery2 users ...'); |
| 647a600b TW |
310 | $percent = _gallery_user_advanced_sync($position); |
| 311 | break; | |
| 312 | default: | |
| 049f9e86 | 313 | $status = t('Performing batch operation ...'); |
| 647a600b TW |
314 | $percent = $position++; |
| 315 | } | |
| 316 | GalleryEmbed::done(); | |
| 088bea1c | 317 | } |
| 588dcdb8 | 318 | // Operation finished or error occured |
| 088bea1c | 319 | if ($percent >= 100 || !$percent) { |
| 588dcdb8 TW |
320 | array_shift($mode); |
| 321 | if (count($mode) && $percent) { | |
| 322 | _gallery_user_advanced_start($mode, $redirect); | |
| 323 | } | |
| 088bea1c TW |
324 | if ($_SESSION['gallery_user_progress_offline']) { |
| 325 | variable_set('site_offline', 0); | |
| 326 | unset($_SESSION['gallery_user_progress_offline']); | |
| 327 | } | |
| 049f9e86 | 328 | if (count($_SESSION['gallery_user_progress_messages'])) { |
| 73fe857f | 329 | drupal_set_message(theme('item_list', $_SESSION['gallery_user_progress_messages'], t('The following messages occured:')), 'notice'); |
| b304c130 | 330 | drupal_set_message(t('Invalid user items were skipped.'), 'error'); |
| 73fe857f | 331 | watchdog('gallery', theme('item_list', $_SESSION['gallery_user_progress_messages'], t('The following messages occured:')), WATCHDOG_NOTICE); |
| 049f9e86 | 332 | } |
| 088bea1c TW |
333 | unset($_SESSION['gallery_user_progress_mode']); |
| 334 | unset($_SESSION['gallery_user_progress_position']); | |
| 049f9e86 | 335 | unset($_SESSION['gallery_user_progress_messages']); |
| 088bea1c | 336 | if ($percent) { |
| 588dcdb8 | 337 | drupal_set_message(t('User synchronization successfully completed.')); |
| 088bea1c TW |
338 | } |
| 339 | else { | |
| 73fe857f | 340 | drupal_set_message(t('User synchronization (partially) failed.'), 'error'); |
| 588dcdb8 TW |
341 | } |
| 342 | if ($redirect) { | |
| 343 | unset($_SESSION['gallery_user_progress_redirect']); | |
| 344 | drupal_goto($redirect); | |
| 088bea1c TW |
345 | } |
| 346 | drupal_goto('admin/user/gallery/advanced'); | |
| 088bea1c TW |
347 | } |
| 348 | $_SESSION['gallery_user_progress_position'] = $position; | |
| 349 | } | |
| 350 | ||
| 351 | drupal_set_title('Drupal <> Gallery2'); | |
| 6758036d | 352 | drupal_set_html_head('<meta http-equiv="Refresh" content="0; URL='. base_path() .'index.php?q=admin/user/gallery/advanced_progress">'); |
| 049f9e86 | 353 | print theme('gallery_user_progress_page', theme('progress_bar', round($percent, 1), $status), FALSE); |
| 088bea1c TW |
354 | exit(); |
| 355 | } | |
| 356 | ||
| 73fe857f TW |
357 | /** |
| 358 | * Theme function : theme_gallery_user_progress_page(). | |
| 359 | */ | |
| 088bea1c TW |
360 | function theme_gallery_user_progress_page($content, $messages = TRUE, $partial = FALSE) { |
| 361 | drupal_set_header('Content-Type: text/html; charset=utf-8'); | |
| 362 | drupal_set_html_head('<link rel="shortcut icon" href="'. base_path() .'misc/favicon.ico" type="image/x-icon" />'); | |
| 363 | ||
| 364 | $css = array('all' => array('module' => array('misc/maintenance.css' => FALSE, 'modules/system/system.css' => FALSE))); | |
| 365 | ||
| 366 | $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | |
| 367 | $output .= '<html xmlns="http://www.w3.org/1999/xhtml">'; | |
| 368 | $output .= '<head>'; | |
| 369 | $output .= ' <title>'. strip_tags(drupal_get_title()) .'</title>'; | |
| 370 | $output .= drupal_get_html_head(); | |
| 371 | $output .= drupal_get_css($css); | |
| 372 | $output .= drupal_get_js(); | |
| 373 | $output .= '</head>'; | |
| 374 | $output .= '<body>'; | |
| 6758036d | 375 | $output .= '<h2>'. drupal_get_title() .'</h2>'; |
| 088bea1c TW |
376 | |
| 377 | $output .= "\n<!-- begin content -->\n"; | |
| 378 | $output .= $content; | |
| 379 | $output .= "\n<!-- end content -->\n"; | |
| 380 | ||
| 381 | $output .= '</body></html>'; | |
| 382 | ||
| 383 | return $output; | |
| 384 | } | |
| 385 | ||
| 73fe857f TW |
386 | /** |
| 387 | * Function _gallery_user_settings(). | |
| 388 | */ | |
| 088bea1c TW |
389 | function _gallery_user_settings() { |
| 390 | $form['user'] = array( | |
| 391 | '#type' => 'fieldset', | |
| 392 | '#title' => t('Settings'), | |
| 393 | '#collapsible' => FALSE, | |
| 394 | '#collapsed' => FALSE | |
| 395 | ); | |
| 588dcdb8 | 396 | |
| 73fe857f | 397 | // General (not sync related) settings |
| 588dcdb8 TW |
398 | $form['user']['gallery_user_hide_profile'] = array( |
| 399 | '#type' => 'checkbox', | |
| 400 | '#title' => t('Hide Gallery2 section in profiles'), | |
| 401 | '#default_value' => variable_get('gallery_user_hide_profile', 0), | |
| 402 | '#description' => t('Hide the Gallery2 section (i.e. Gallery2-Drupal Sync Status) on the user profile pages.'), | |
| 403 | ); | |
| 404 | ||
| 405 | // Sync settings | |
| 406 | $form['user']['sync'] = array( | |
| 407 | '#type' => 'fieldset', | |
| 408 | '#title' => t('User Synchronization'), | |
| 409 | '#collapsible' => TRUE, | |
| 410 | '#collapsed' => FALSE | |
| 411 | ); | |
| 412 | ||
| 088bea1c TW |
413 | $roles = array(0 => t('none')); |
| 414 | $roles += user_roles(TRUE); | |
| 647a600b | 415 | unset($roles[DRUPAL_AUTHENTICATED_RID]); |
| 588dcdb8 | 416 | $form['user']['sync']['gallery_user_admin_role'] = array( |
| 088bea1c TW |
417 | '#type' => 'select', |
| 418 | '#title' => t('Drupal \'admin\' role'), | |
| 419 | '#default_value' => variable_get('gallery_user_admin_role', 0), | |
| 420 | '#options' => $roles, | |
| 049f9e86 TW |
421 | '#description' => t('Select the Drupal role equivalent to Gallery2\'s \'Site Admin\' group (or \'none\' to disable this |
| 422 | feature). The roles \'anonymous\' and \'authenticated\' are not available for selection.'), | |
| 088bea1c TW |
423 | ); |
| 424 | ||
| dc6f674c TW |
425 | $form['user']['sync']['gallery_user_locked'] = array( |
| 426 | '#type' => 'checkbox', | |
| 427 | '#title' => t('Lock G2 accounts'), | |
| 428 | '#default_value' => variable_get('gallery_user_locked', 0), | |
| 429 | '#description' => t('Locking G2 account prevents users from changing their details (password, email, ...) in G2.'), | |
| 430 | ); | |
| 431 | ||
| 588dcdb8 TW |
432 | // Fullname settings |
| 433 | $profile_status = module_exists('profile'); | |
| 434 | $profile_status_str = theme('gallery_module_status_message', $profile_status); | |
| 435 | $desc = t('Full names in Gallery2 can be supported by using the profile module | |
| 436 | (!profile_status) with a \'Full Name\' profile field as defined below.', | |
| 437 | array('!profile_status' => $profile_status_str) | |
| 922fd0d1 | 438 | ); |
| 588dcdb8 TW |
439 | if (!$profile_status) { |
| 440 | $desc .= t(' However the profile module is disabled, so this functionality is | |
| 441 | not available and the options are disabled.'); | |
| 442 | } | |
| 588dcdb8 | 443 | $form['user']['sync']['fullname'] = array( |
| 088bea1c | 444 | '#type' => 'fieldset', |
| 588dcdb8 | 445 | '#title' => t('Full Name settings'), |
| 088bea1c | 446 | '#collapsible' => TRUE, |
| 588dcdb8 TW |
447 | '#collapsed' => !$profile_status, |
| 448 | '#description' => $desc, | |
| 088bea1c | 449 | ); |
| 8ab23cba TW |
450 | if ($profile_status) { |
| 451 | $form['user']['sync']['fullname']['gallery_use_fullname'] = array( | |
| 452 | '#type' => 'checkbox', | |
| 453 | '#title' => t('Enable Full Name support'), | |
| 454 | '#return_value' => 1, | |
| 455 | '#default_value' => variable_get('gallery_use_fullname', 0), | |
| 456 | '#disabled' => !$profile_status, | |
| 457 | '#description' => t('Use full name from profile module in Gallery2 user data. Note that | |
| 458 | enabling/disabling this only updates Gallery2 user data when the | |
| 459 | Drupal user is updated or if a user sync is performed.'), | |
| 460 | ); | |
| 461 | ||
| 462 | $categories = array(); | |
| 463 | $result = db_query("SELECT DISTINCT(category) FROM {profile_fields}"); | |
| 464 | while ($category = db_fetch_object($result)) { | |
| 465 | $categories[$category->category] = $category->category; | |
| 466 | } | |
| 467 | $default_category = variable_get('gallery_profile_fullname_category', 'Personal Information'); | |
| 468 | $form['user']['sync']['fullname']['gallery_profile_fullname_category'] = array( | |
| 469 | '#type' => 'select', | |
| 470 | '#title' => t('Full name profile category'), | |
| 471 | '#default_value' => $default_category, | |
| 472 | '#options' => $categories, | |
| 473 | '#description' => t('Name of the category containing the \'Full Name\' field in profile module.'), | |
| 474 | ); | |
| 475 | $fields = array(); | |
| 476 | $result = _profile_get_fields($default_category); | |
| 477 | while ($field = db_fetch_object($result)) { | |
| 478 | $fields[$field->name] = $field->title; | |
| 479 | } | |
| 480 | $form['user']['sync']['fullname']['gallery_profile_fullname_field'] = array( | |
| 481 | '#type' => 'select', | |
| 482 | '#title' => t('Full name profile field'), | |
| 483 | '#default_value' => variable_get('gallery_profile_fullname_field', 'profile_fullname'), | |
| 484 | '#options' => $fields, | |
| 485 | '#description' => t('Name of \'Full Name\' field in profile module.'), | |
| 486 | ); | |
| 487 | } | |
| 588dcdb8 TW |
488 | |
| 489 | // Import behaviour | |
| 088bea1c TW |
490 | $form['user']['sync']['import'] = array( |
| 491 | '#type' => 'fieldset', | |
| 3c1f5fa5 | 492 | '#title' => t('Advanced Sync - Import'), |
| 588dcdb8 TW |
493 | '#collapsible' => TRUE, |
| 494 | '#collapsed' => TRUE, | |
| 088bea1c | 495 | ); |
| 588dcdb8 | 496 | |
| 088bea1c TW |
497 | $form['user']['sync']['import']['gallery_user_import_groups'] = array( |
| 498 | '#type' => 'checkbox', | |
| 499 | '#title' => t('Import Gallery2 groups'), | |
| 500 | '#default_value' => variable_get('gallery_user_import_groups', 1), | |
| 647a600b | 501 | '#description' => t('Import Gallery2 groups into Drupal roles (in addition to users).'), |
| 088bea1c | 502 | ); |
| 588dcdb8 | 503 | |
| 088bea1c TW |
504 | $form['user']['sync']['import']['gallery_user_import_override'] = array( |
| 505 | '#type' => 'checkbox', | |
| 506 | '#title' => t('Override existing Drupal users'), | |
| 588dcdb8 | 507 | '#default_value' => variable_get('gallery_user_import_override', 0), |
| b304c130 TW |
508 | '#description' => t('Replaces user details (password, email, groups, ...) of existing Drupal users with Gallery2 imported values.'), |
| 509 | ); | |
| 510 | ||
| 511 | $form['user']['sync']['import']['gallery_user_import_conflict'] = array( | |
| 512 | '#type' => 'checkboxes', | |
| 513 | '#title' => t('Auto-resolve email address conflicts'), | |
| 514 | '#default_value' => variable_get('gallery_user_import_conflict', array()), | |
| 515 | '#options' => array( | |
| 516 | G2IMPORT_CONFLICT_DUPLICATE => t('Duplicate e-mail addresses'), | |
| 517 | G2IMPORT_CONFLICT_INVALID => t('Invalide e-mail addresses') | |
| 518 | ), | |
| 519 | '#description' => t('Renames duplicate/invalid e-mail addresses to username@drupaldomain. | |
| 520 | If this option is disabled you get a list of users to handle conflicts yourself.') | |
| 088bea1c | 521 | ); |
| 588dcdb8 TW |
522 | |
| 523 | // Export behaviour | |
| 088bea1c TW |
524 | $form['user']['sync']['export'] = array( |
| 525 | '#type' => 'fieldset', | |
| 588dcdb8 TW |
526 | '#title' => t('Advanced Sync - Export (Synchronize)'), |
| 527 | '#collapsible' => TRUE, | |
| 528 | '#collapsed' => TRUE, | |
| 088bea1c | 529 | ); |
| 588dcdb8 | 530 | |
| 088bea1c TW |
531 | $form['user']['sync']['export']['gallery_user_sync_remap'] = array( |
| 532 | '#type' => 'checkbox', | |
| 533 | '#title' => t('Remap all users'), | |
| 534 | '#default_value' => variable_get('gallery_user_sync_remap', 0), | |
| 049f9e86 TW |
535 | '#description' => t('Remaps all users instead of missing or mismatching ones only. |
| 536 | This will completely flush Gallery2\'s \'externalIdMap\'.'), | |
| 088bea1c TW |
537 | ); |
| 538 | ||
| 588dcdb8 TW |
539 | $form['#submit']['_gallery_user_settings_submit'] = array(); |
| 540 | $form['#submit']['system_settings_form_submit'] = array(); | |
| 088bea1c TW |
541 | return system_settings_form($form); |
| 542 | } | |
| 543 | ||
| 73fe857f TW |
544 | /** |
| 545 | * Function _gallery_user_settings_submit(). | |
| 546 | */ | |
| 588dcdb8 TW |
547 | function _gallery_user_settings_submit($form_id, $form_values) { |
| 548 | if ($form_values['op'] == t('Reset to defaults')) { | |
| 8ab23cba | 549 | $fullname_changed = variable_get('gallery_use_fullname', 0); |
| 588dcdb8 TW |
550 | } |
| 551 | else { | |
| 8ab23cba | 552 | $fullname_changed = ($form_values['gallery_use_fullname'] != variable_get('gallery_use_fullname', 0)); |
| 588dcdb8 TW |
553 | } |
| 554 | if ($fullname_changed) { | |
| 555 | drupal_set_message(t('Full Name settings have changed. You should now synchronize | |
| 556 | your users on the <a href="@user-admin">Gallery users</a> page.', | |
| 557 | array('@user-admin' => url('admin/user/gallery')))); | |
| 558 | } | |
| 559 | } |