| 1 |
<?php |
<?php |
| 2 |
|
// $Id$ |
|
// $Id: advuser.module,v 1.12.4.2 2007/06/02 22:45:47 earnie Exp $ |
|
|
define('ADVUSER_MODULE_VERSION', '$Id: advuser.module,v 1.12.4.2 2007/06/02 22:45:47 earnie Exp $' ); |
|
| 3 |
|
|
| 4 |
define('ADVUSER_DEFAULT_NEW_MAIL', "User email: %user_email\n\nIf you want to check and edit the account go to %uri.\n\nInvestigate User:\nYahoo search %user_email: %yahoo_user \nGoogle search %user_email: %google_user\n\n--\n%site"); |
define('ADVUSER_DEFAULT_NEW_MAIL', "User email: %user_email\n\nIf you want to check and edit the account go to %uri.\n\nInvestigate User:\nYahoo search %user_email: %yahoo_user \nGoogle search %user_email: %google_user\n\n--\n%site"); |
| 5 |
define('ADVUSER_DEFAULT_MODIFY_MAIL', ADVUSER_DEFAULT_NEW_MAIL); // "User email: %user_email\n\nIf you want to check and edit the account go to %uri.\n\nYahoo search %user_email: %yahoo_user \nGoogle search %user_email: %google_user\n\n--\n%site"); |
define('ADVUSER_DEFAULT_MODIFY_MAIL', ADVUSER_DEFAULT_NEW_MAIL); // "User email: %user_email\n\nIf you want to check and edit the account go to %uri.\n\nYahoo search %user_email: %yahoo_user \nGoogle search %user_email: %google_user\n\n--\n%site"); |
| 11 |
define('ADVUSER_DEFAULT_LISTNO', 200); |
define('ADVUSER_DEFAULT_LISTNO', 200); |
| 12 |
define('ADVUSER_DEFAULT_PROFILE_FIELDS', NULL); |
define('ADVUSER_DEFAULT_PROFILE_FIELDS', NULL); |
| 13 |
|
|
|
//define('ADVUSER_MAIL_MESSAGE_TEMPLATE', "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"); |
|
|
|
|
| 14 |
/** |
/** |
| 15 |
* hook_perm() implementation |
* Implementation of hook_perm(). |
|
* |
|
|
* @return array of permissions |
|
| 16 |
*/ |
*/ |
| 17 |
|
function advuser_perm() { |
| 18 |
|
return array('administer advuser', 'access advuser', 'email users advuser'); |
| 19 |
|
} |
| 20 |
|
|
| 21 |
/** |
/** |
| 22 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 23 |
*/ |
*/ |
| 24 |
function advuser_menu($may_cache) { |
function advuser_menu($may_cache) { |
| 25 |
// code which should run exactly once per page view |
// Include filters |
| 26 |
if (!$may_cache) { |
include_once(drupal_get_path('module','advuser').'/advuser_filters.inc'); |
| 27 |
drupal_add_css(drupal_get_path('module', 'advuser') .'/advuser.css'); |
|
| 28 |
} |
$admin_access = user_access('administer advuser'); |
| 29 |
$items = array(); |
$access_access = user_access('access advuser'); |
| 30 |
|
|
| 31 |
if ($may_cache) { |
if ($may_cache) { |
| 32 |
$items[] = array( |
$items[] = array( |
| 33 |
'path' => 'admin/settings/advuser', |
'path' => 'admin/settings/advuser', |
| 35 |
'description' => t('Advanced User Settings'), |
'description' => t('Advanced User Settings'), |
| 36 |
'callback' => 'drupal_get_form', |
'callback' => 'drupal_get_form', |
| 37 |
'callback arguments' => array('advuser_settings'), |
'callback arguments' => array('advuser_settings'), |
| 38 |
'access' => user_access('administer site configuration'), |
'access' => $admin_access, |
| 39 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM); |
|
); |
|
| 40 |
|
|
| 41 |
$items[] = array( |
$items[] = array('path' => 'admin/user/advuser', 'title' => t('Advanced management'), |
| 42 |
'path' => 'admin/user/advuser', |
'description' => t('List, add, edit and email users.'), |
| 43 |
'title' => t('Advanced managment'), |
'callback' => 'advuser_admin', 'callback arguments' => array('list'), 'access' => $access_access); |
|
'callback' => 'advuser_admin_users', |
|
|
'type' => MENU_NORMAL_ITEM, |
|
|
// 'weight' => 7, |
|
|
'access' => user_access('administer users'), |
|
|
); |
|
| 44 |
} |
} |
|
|
|
| 45 |
return $items; |
return $items; |
| 46 |
} |
} |
| 47 |
|
|
| 48 |
/** |
function advuser_admin($callback_arg = '') { |
| 49 |
* hook_help implementation |
$op = isset($_POST['op']) ? $_POST['op'] : $callback_arg; |
|
*/ |
|
|
function advuser_help($section) { |
|
|
|
|
|
switch ($section) { |
|
|
case 'admin/modules#description': |
|
|
return t('Advanced user management module. Filter users and mass actions based on their filters.'); |
|
|
} |
|
|
} |
|
|
|
|
|
/* |
|
|
** Filters |
|
|
*/ |
|
|
function advuser_admin_filters() { |
|
|
|
|
|
$filters = array(); |
|
|
|
|
|
// Regular filters |
|
|
$filters['email'] = array( |
|
|
'title' => t('E-mail'), |
|
|
'where' => "u.mail = '%s'", |
|
|
); |
|
|
|
|
|
$filters['uid'] = array( |
|
|
'title' => t('User Id'), |
|
|
'where' => "u.uid = '%s'", |
|
|
); |
|
|
|
|
|
$filters['access'] = array( |
|
|
'title' => t('Last Access'), |
|
|
'where' => "u.access = '%s'", |
|
|
); |
|
|
$filters['status'] = array( |
|
|
'title' => t('Status'), |
|
|
'type' => t('selection'), |
|
|
'options' => array(0 => t('Blocked'), 1 => ('Active')), |
|
|
'where' => 'u.status = %s', |
|
|
); |
|
|
|
|
|
$fields = variable_get('advuser_profile_fields', ADVUSER_DEFAULT_PROFILE_FIELDS); |
|
|
if ( is_array($fields) ) { |
|
|
foreach ( $fields as $fid => $value) { |
|
|
if ( $value ) { |
|
|
$field = db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid)); |
|
|
$options = array(); |
|
|
if ( $field->type == 'selection' ) { |
|
|
$result_v = db_query('SELECT DISTINCT * FROM {profile_values} WHERE fid = %d', $field->fid); |
|
|
while ( $value = db_fetch_object($result_v)) { |
|
|
$options[$value->value] = $value->value; |
|
|
} |
|
|
} |
|
|
|
|
|
// Regular filters |
|
|
$filters[$field->fid] = array( |
|
|
'title' => $field->title, |
|
|
'type' => $field->type, |
|
|
'options' => $options, |
|
|
'field_where' => 'pf.fid = '. $field->fid .' AND pv.value = '."'%s'", |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
advuser_module_invoke('filter', $filters); |
|
|
return $filters; |
|
|
} |
|
|
|
|
|
function advuser_admin_filter_form_validate($form_id, $form) { |
|
|
$op = $form_values['op']; |
|
|
if ( $op == 'Filter' || $op == 'Refine' ) { |
|
|
if ( ! isset($form[$form['filter']]) || $form[$form['filter']] == '' ) { |
|
|
form_set_error($form['filter'], t('Please fill some value to correctely set up the filter')); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
| 50 |
|
|
|
function advuser_admin_filter_form_submit() { |
|
|
global $form_values; |
|
|
$op = $form_values['op']; |
|
|
$filters = advuser_admin_filters(); |
|
| 51 |
switch ($op) { |
switch ($op) { |
| 52 |
case t('Filter'): case t('Refine'): |
default: |
| 53 |
if (isset($form_values['filter'])) { |
if ($_POST['accounts'] && $_POST['operation'] == 'delete') { |
| 54 |
$filter = $form_values['filter']; |
$output = drupal_get_form('advuser_multiple_delete_confirm'); |
| 55 |
if ( $filters[$filter]['type'] == 'selection' ) { |
} else if ($_POST['accounts'] && $_POST['operation'] == 'email') { |
| 56 |
if (isset($filters[$filter]['options'][$form_values[$filter]])) { |
$output = drupal_get_form('advuser_multiple_email_confirm'); |
| 57 |
$_SESSION['advuser_user_filter'][] = array($filter, $form_values[$filter]); |
} else { |
| 58 |
} |
$output = drupal_get_form('advuser_filter_form'); |
| 59 |
} |
$output .= drupal_get_form('advuser_admin_account'); |
|
else { |
|
|
$_SESSION['advuser_user_filter'][] = array($filter, $form_values[$filter]); |
|
|
} |
|
| 60 |
} |
} |
|
break; |
|
|
case t('Undo'): |
|
|
array_pop($_SESSION['advuser_user_filter']); |
|
|
break; |
|
|
case t('Reset'): |
|
|
$_SESSION['advuser_user_filter'] = array(); |
|
|
break; |
|
|
case t('Update'): |
|
|
return; |
|
|
} |
|
|
if ($op != '') { |
|
|
drupal_goto('admin/user/advuser'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function advuser_admin_filter_form() { |
|
|
//print_r($_SESSION['advuser_user_filter']); |
|
|
|
|
|
$sess = &$_SESSION['advuser_user_filter']; |
|
|
$sess = is_array($sess) ? $sess : array(); |
|
|
$session = $sess; |
|
|
asort($session); |
|
|
$filters = advuser_admin_filters(); |
|
|
|
|
|
$i = 0; |
|
|
$form['filters'] = array('#type' => 'fieldset', '#title' => t('Show only items where'), '#theme' => 'advuser_filters'); |
|
|
|
|
|
$types_used = array(); |
|
|
foreach ($session as $filter) { |
|
|
list($type, $value) = $filter; |
|
|
$original = $filters[$type]; |
|
|
$em = 'and'; |
|
|
if ( array_search($type, $types_used) !== FALSE ) { |
|
|
$em = 'or'; |
|
|
} |
|
|
$string = ($i++ ? '<em>'. $em .'</em> where <strong>%a</strong> is <strong>%b</strong>' : '<strong>%a</strong> is <strong>%b</strong>'); |
|
|
$txt_value = $value; |
|
|
if ($original['type'] == 'selection') { |
|
|
$txt_value = $original['options'][$value]; |
|
|
} |
|
|
$form['filters']['current'][] = array('#value' => t($string, array('%a' => $filters[$type]['title'] , '%b' => $txt_value))); |
|
|
$types_used[] = $type; |
|
|
} |
|
|
|
|
|
foreach ($filters as $key => $filter) { |
|
|
$names[$key] = $filter['title']; |
|
|
if ( $filter['type'] == 'selection' ) { |
|
|
$form['filters']['status'][$key] = array('#type' => 'select', '#options' => $filter['options']); |
|
|
} |
|
|
else { |
|
|
$form['filters']['status'][$key] = array('#type' => 'textfield'); |
|
|
} |
|
|
} |
|
|
|
|
|
$names_keys = array_keys($names); |
|
|
$form['filters']['filter'] = array('#type' => 'radios', '#options' => $names , '#default_value' => $names_keys[0] ); |
|
|
$form['filters']['buttons']['submit'] = array('#type' => 'submit', '#value' => (count($session) ? t('Refine') : t('Filter'))); |
|
|
if (count($session)) { |
|
|
$form['filters']['buttons']['undo'] = array('#type' => 'submit', '#value' => t('Undo')); |
|
|
$form['filters']['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset')); |
|
| 61 |
} |
} |
| 62 |
|
return $output; |
|
// return drupal_get_form('advuser_admin_filter_form', $form); |
|
|
return $form; |
|
| 63 |
} |
} |
| 64 |
|
|
| 65 |
|
function advuser_admin_account() { |
| 66 |
/* |
$filter = advuser_build_filter_query(); |
| 67 |
** AdvUser operations |
$header = array( |
| 68 |
*/ |
array(), |
| 69 |
function advuser_admin_users_operations() { |
array('data' => t('Username'), 'field' => 'u.name'), |
| 70 |
$external = array(); |
array('data' => t('Status'), 'field' => 'u.status'), |
| 71 |
$operations = array( |
t('Roles'), |
| 72 |
'email' => array(t('Email users'), 'advuser_multiple_email_confirm_page', 'confirm'), |
array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'), |
| 73 |
'delete' => array(t('Delete users'), 'advuser_multiple_delete_confirm' , 'confirm') |
array('data' => t('Last access'), 'field' => 'u.access'), |
| 74 |
|
t('Operations') |
| 75 |
); |
); |
|
|
|
|
advuser_module_invoke('actions', $external); |
|
|
|
|
|
foreach ($external as $k => $v ) { |
|
|
$operations['external_'. $k] = $v; |
|
|
} |
|
|
|
|
|
return $operations; |
|
|
} |
|
|
|
|
|
function advuser_admin_user_build_filter_query() { |
|
|
$filters = advuser_admin_filters(); |
|
| 76 |
|
|
| 77 |
// Build query |
$query = ''; |
| 78 |
$field_where = $where = $where_args = $having_args = array(); |
if (module_exists('profile')) { |
| 79 |
$join = ''; |
$fields = variable_get('advuser_profile_fields', ADVUSER_DEFAULT_PROFILE_FIELDS); |
| 80 |
|
if (is_array($fields)) { |
| 81 |
$cnt = 0; |
foreach ( $fields as $fid => $value) { |
| 82 |
$session = $_SESSION['advuser_user_filter']; |
if ( $value ) { |
| 83 |
asort($session); |
$field = db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid)); |
| 84 |
foreach ($session as $filter) { |
$ff[] = array('data' => t($field->title), 'field' => $field->name.value); |
| 85 |
list($key, $value) = $filter; |
#$pquery .= ', '.$field->name.'.value as '.$field->name; |
|
|
|
|
// Check if process the filter an how |
|
|
$where_key = TRUE ; |
|
|
$where_keys = array_keys($where, $filters[$key]['where']); |
|
|
if ( count((array) $where_keys) > 0 ) { |
|
|
// check for same value to on arg array, should have the same key |
|
|
foreach ( $where_keys as $k => $v ) { |
|
|
if ( $where_args[$v] == $value ) { |
|
|
$where_key = FALSE; |
|
| 86 |
} |
} |
|
}//foreach; |
|
|
} |
|
|
|
|
|
if ( isset($filters[$key]['where']) && $where_key ) { |
|
|
$where[] = $filters[$key]['where']; |
|
|
$where_args[] = $value; |
|
|
} |
|
|
|
|
|
// Check if process the filter an how |
|
|
$field_where_key = TRUE; |
|
|
$field_where_keys = array_keys($field_where, $filters[$key]['field_where']); |
|
|
if ( count((array) $field_where_keys) > 0 ) { |
|
|
// check for same value to on arg array, should have the same key |
|
|
foreach ( $field_where_keys as $k => $v ) { |
|
|
if ( $having_args[$v] == $value ) { |
|
|
$field_where_key = FALSE; |
|
|
} |
|
|
}//foreach; |
|
|
} |
|
|
else { |
|
|
if ( isset($filters[$key]['field_where']) ) { |
|
|
$cnt++; |
|
| 87 |
} |
} |
| 88 |
} |
} |
| 89 |
|
$header = array_merge($header, $ff); |
|
if ( isset($filters[$key]['field_where']) && $field_where_key ) { |
|
|
$field_where[] = $filters[$key]['field_where']; |
|
|
$having_args[] = $value; |
|
|
} |
|
|
|
|
|
// Proces join just once |
|
|
if ( ! strstr($join, $filters[$key]['join'] .' ') ) { |
|
|
$join .= $filters[$key]['join'] .' '; |
|
|
} |
|
|
} |
|
|
|
|
|
//print_r($field_where); |
|
|
|
|
|
// build query smartly |
|
|
$where_sql = 'WHERE u.uid > 1 AND '; |
|
|
foreach ( (array) $where as $w ) { |
|
|
if ( $lastwhere ) { |
|
|
if ( $lastwhere == $w ) { |
|
|
$where_sql .= ' OR '. $w ; |
|
|
} |
|
|
else { |
|
|
$where_sql .= ') AND ('. $w ; |
|
|
} |
|
|
} |
|
|
else { |
|
|
$where_sql .= '('. $w ; |
|
|
} |
|
|
$lastwhere = $w; |
|
|
} |
|
|
if ( $lastwhere ) { |
|
|
$where_sql .= ') AND '; |
|
|
} |
|
|
$where_sql .= '1'; |
|
|
|
|
|
$where = count($where) ? 'WHERE u.uid > 1 AND '. implode(' AND ', $where) : ''; |
|
|
$field_where_cnt = count($field_where); |
|
|
$field_where = $field_where_cnt ? implode(' OR ', $field_where) : '0'; |
|
|
$having[] = 'SUM(IF('. $field_where .',1,0)) = '. $cnt; |
|
|
$having = count($having) ? 'HAVING '. implode(' AND ', $having) : ''; |
|
|
|
|
|
$args = array_merge($where_args, $having_args); |
|
|
|
|
|
return array( 'where' => $where_sql, 'join' => $join, 'args' => $args, 'having' => $having); |
|
|
} |
|
|
|
|
|
function advuser_multiple_email_confirm_page($all, $form) { |
|
|
return drupal_get_form('advuser_multiple_email_confirm', $all, $form); |
|
|
} |
|
|
|
|
|
function advuser_multiple_email_confirm($all, $form) { |
|
|
$form['mailsubject'] = array( |
|
|
'#type' => 'textfield', |
|
|
'#title' => t('Subject'), |
|
|
'#required' => TRUE, |
|
|
); |
|
|
$form['mailbody'] = array( |
|
|
'#type' => 'textarea', |
|
|
'#title' => t('Mail body'), |
|
|
'#required' => TRUE, |
|
|
); |
|
|
|
|
|
return confirm_form($form, |
|
|
t('Are you sure you want to mail these users?'), |
|
|
'admin/user/advuser', t('This action cannot be undone.'), |
|
|
t('Mail all'), t('Cancel')); |
|
|
} |
|
|
|
|
|
|
|
|
function advuser_multiple_email_confirm_submit($form_id, $edit) { |
|
|
if ($edit['confirm']) { |
|
|
foreach ($edit['users'] as $uid => $value) { |
|
|
$account = user_load(array('uid' => $uid)); |
|
|
if ( module_exists('lightcrm') ) { |
|
|
_lightcrm_comment_add($uid, $edit['mailsubject'], $edit['mailbody']); |
|
|
} |
|
|
else { |
|
|
$from = variable_get("site_mail", ini_get("sendmail_from")); // http://drupal.org/node/77689 |
|
|
drupal_mail('advance-user-mail', $account->mail, $edit['mailsubject'], $edit['mailbody'], $from); |
|
|
} |
|
|
} |
|
|
drupal_set_message(t('The users have been mailed.')); |
|
|
} |
|
|
drupal_goto('admin/user/advuser'); |
|
|
} |
|
|
|
|
|
function advuser_multiple_delete_confirm_submit($form_id, $edit) { |
|
|
if ($edit['confirm']) { |
|
|
foreach ($edit['users'] as $uid => $value) { |
|
|
$account = user_load(array('uid' => $uid)); |
|
|
db_query('DELETE FROM {users} WHERE uid = %d', $account->uid); |
|
|
db_query('DELETE FROM {sessions} WHERE uid = %d', $account->uid); |
|
|
db_query('DELETE FROM {users_roles} WHERE uid = %d', $account->uid); |
|
|
db_query('DELETE FROM {authmap} WHERE uid = %d', $account->uid); |
|
|
watchdog('user', t('Deleted user: %name %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', '<'. $account->mail .'>'))), WATCHDOG_NOTICE); |
|
|
drupal_set_message(t('The account has been deleted.')); |
|
|
module_invoke_all('user', 'delete', $edit, $account); |
|
|
} |
|
|
drupal_set_message(t('The items have been deleted.')); |
|
|
} |
|
|
drupal_goto('admin/user/advuser'); |
|
|
} |
|
|
|
|
|
function advuser_multiple_confirm($all, $action, $user_func) { |
|
|
$edit = $_POST['edit']; |
|
|
|
|
|
$form = array(); |
|
|
$form['users'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE); |
|
|
// array filter returns only elements with true values |
|
|
if ( $all ) { |
|
|
$filter = advuser_admin_user_build_filter_query(); |
|
|
$result = db_query('SELECT u.* FROM {users} u '. $filter['join'] .' LEFT JOIN {profile_values} pv ON u.uid = pv.uid LEFT JOIN {profile_fields} pf on pv.fid = pf.fid '. $filter['where'] .' GROUP BY u.uid '. $filter['having'] .' ORDER BY u.login DESC', $filter['args']); |
|
|
while ( $usr = db_fetch_object($result)) { |
|
|
$user_array[$usr->uid] = ''; |
|
|
} |
|
|
} |
|
|
else { |
|
|
$user_array = array_filter($edit['users']); |
|
|
} |
|
|
|
|
|
foreach ($user_array as $uid => $value) { |
|
|
$name = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid)); |
|
|
$form['users'][$uid] = array('#type' => 'hidden', '#value' => $uid, '#prefix' => '<li>', '#suffix' => check_plain($name) ."</li>\n"); |
|
|
} |
|
|
$form['operation'] = array('#type' => 'hidden', '#value' => $action); |
|
|
|
|
|
if ( function_exists($user_func) ) { |
|
|
$user_func($all, $form); |
|
| 90 |
} |
} |
| 91 |
|
|
| 92 |
$operations = advuser_admin_users_operations(); |
$sql = 'SELECT DISTINCT u.uid, u.name, u.status, u.created, u.access '.$pquery.' FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid '. $filter['join'] .' WHERE u.uid != 0 '. $filter['where']; |
|
return confirm_form($user_func, $form, |
|
|
t('Are you sure you want to update these items?'), |
|
|
'admin/user/advuser', t('This action cannot be undone.'), |
|
|
$operations[$action][0], t('Cancel')); |
|
|
} |
|
| 93 |
|
|
| 94 |
function advuser_admin_users() { |
$sql .= tablesort_sql($header); |
| 95 |
$output = drupal_get_form('advuser_admin_filter_form'); |
$query_count = 'SELECT COUNT(DISTINCT u.uid) FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid '. $filter['join'] .' WHERE u.uid != 0 '. $filter['where']; |
| 96 |
|
$result = pager_query($sql, 50, 0, $query_count, $filter['args']); |
| 97 |
|
|
| 98 |
// Call the form first, to allow for the form_values array to be populated. |
$form['options'] = array( |
| 99 |
// $output .= drupal_get_form('user_admin_account'); |
'#type' => 'fieldset', |
| 100 |
$output .= drupal_get_form('advuser_admin_users_form'); |
'#title' => t('Update options'), |
| 101 |
|
'#prefix' => '<div class="container-inline">', |
| 102 |
return $output; |
'#suffix' => '</div>', |
|
} |
|
|
|
|
|
function advuser_admin_users_form() { |
|
|
global $form_values; |
|
|
|
|
|
$op = $form_values['op']; |
|
|
if ( $op == 'Update all' ) { |
|
|
$all = TRUE; |
|
|
} |
|
|
|
|
|
foreach (advuser_admin_users_operations() as $key => $value) { |
|
|
if ( $value[2] == 'confirm' ) { |
|
|
if ( |
|
|
$_POST['edit']['options_all']['operation'] == $key && $all || |
|
|
( $_POST['edit']['options_sel']['operation'] == $key && (count($_POST['edit']['users']) > 0) ) || |
|
|
$_POST['edit']['operation'] == $key |
|
|
) { |
|
|
|
|
|
return advuser_multiple_confirm($all, $key, $value[1]); |
|
|
//return call_user_func($value[1], $all); |
|
|
//return advuser_multiple_delete_confirm($all); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
$filter = advuser_admin_user_build_filter_query(); |
|
|
$listno = variable_get('advuser_listno', ADVUSER_DEFAULT_LISTNO); |
|
|
$result = pager_query('SELECT u.* FROM {users} u '. $filter['join'] .' LEFT JOIN {profile_values} pv ON u.uid = pv.uid LEFT JOIN {profile_fields} pf on pv.fid = pf.fid '. $filter['where'] .' GROUP BY u.uid '. $filter['having'] .' ORDER BY u.login DESC', $listno, 0, NULL, $filter['args']); |
|
|
//$result = 'SELECT u.* FROM {users} u '. $filter['join'] .' LEFT JOIN {profile_values} pv ON u.uid = pv.uid LEFT JOIN {profile_fields} pf on pv.fid = pf.fid '. $filter['where'] .' GROUP BY u.uid ' . $filter['having'] . ' ORDER BY u.login DESC', $listno, 0, $filter['args']; |
|
|
//$result .= tablesort_sql($header); |
|
|
|
|
|
$form['options_all'] = array( |
|
|
'#type' => 'fieldset', '#title' => t('Mass update on every record'), |
|
|
'#prefix' => "<div class=\"container-inline\">" , '#suffix' => "</div>", |
|
|
'#tree' => TRUE, |
|
| 103 |
); |
); |
| 104 |
$options = array(); |
$options = array(); |
| 105 |
foreach (advuser_admin_users_operations() as $key => $value) { |
|
| 106 |
$options[$key] = $value[0]; |
$operations = module_invoke_all('user_operations'); |
| 107 |
|
$operations = array_merge($operations,module_invoke_all('advuser_operations')); |
| 108 |
|
foreach ($operations as $operation => $array) { |
| 109 |
|
$options[$operation] = $array['label']; |
| 110 |
} |
} |
| 111 |
$form['options_all']['operation'] = array( |
$form['options']['operation'] = array( |
| 112 |
'#type' => 'select', |
'#type' => 'select', |
| 113 |
'#options' => $options, |
'#options' => $options, |
| 114 |
|
'#default_value' => 'unblock', |
| 115 |
); |
); |
| 116 |
$form['options_all']['submit'] = array( |
$form['options']['submit'] = array( |
| 117 |
'#type' => 'submit', |
'#type' => 'submit', |
| 118 |
'#value' => t('Update all') |
'#value' => t('Update'), |
|
); |
|
|
|
|
|
$form['options_sel'] = array( |
|
|
'#type' => 'fieldset', '#title' => t('Update on selected records only'), |
|
|
'#prefix' => "<div class=\"container-inline\">" , '#suffix' => "</div>", |
|
|
'#tree' => TRUE, |
|
| 119 |
); |
); |
|
$options = array(); |
|
|
foreach (advuser_admin_users_operations() as $key => $value) { |
|
|
$options[$key] = $value[0]; |
|
|
} |
|
|
$form['options_sel']['operation'] = array( |
|
|
'#type' => 'select', |
|
|
'#options' => $options, |
|
|
); |
|
|
$form['options_sel']['submit'] = array( |
|
|
'#type' => 'submit', |
|
|
'#value' => t('Update') |
|
|
); |
|
|
|
|
|
$destination = drupal_get_destination(); |
|
| 120 |
|
|
| 121 |
$status = array(t('blocked'), t('active')); |
$destination = drupal_get_destination(); |
| 122 |
|
|
| 123 |
while ($usr = db_fetch_object($result)) { |
$status = array(t('blocked'), t('active')); |
| 124 |
$users[$usr->uid] = ''; |
$roles = user_roles(1); |
|
$form['name'][$usr->uid] = array('#value' => theme('username', $usr)); |
|
| 125 |
|
|
| 126 |
|
while ($account = db_fetch_object($result)) { |
| 127 |
|
$accounts[$account->uid] = ''; |
| 128 |
|
$form['name'][$account->uid] = array('#value' => theme('username', $account)); |
| 129 |
$form['status'][$account->uid] = array('#value' => $status[$account->status]); |
$form['status'][$account->uid] = array('#value' => $status[$account->status]); |
| 130 |
$form['access'][$usr->uid] = array('#value' => $usr->access ? t('%time ago', array('%time' => format_interval(time() - $usr->access))) : t('never')); |
$users_roles = array(); |
| 131 |
//$form['access'][$usr->access] = array('#value' => ($usr->access ? format_interval(time() - $usr->access))); |
$roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = %d', $account->uid); |
| 132 |
$form['operations'][$usr->uid] = array('#value' => l(t('edit'), 'user/'. $usr->uid .'/edit', array(), $destination)); |
while ($user_role = db_fetch_object($roles_result)) { |
| 133 |
$form['refcode'][$usr->uid] = array('#value' => $usr->uid); |
$users_roles[] = $roles[$user_role->rid]; |
| 134 |
|
} |
| 135 |
|
asort($users_roles); |
| 136 |
|
$form['roles'][$account->uid][0] = array('#value' => theme('item_list', $users_roles)); |
| 137 |
|
$form['member_for'][$account->uid] = array('#value' => format_interval(time() - $account->created)); |
| 138 |
|
$form['last_access'][$account->uid] = array('#value' => $account->access ? t('@time ago', array('@time' => format_interval(time() - $account->access))) : t('never')); |
| 139 |
|
$form['operations'][$account->uid] = array('#value' => l(t('edit'), "user/$account->uid/edit", array(), $destination)); |
| 140 |
|
#$form['profile_ln'][$account->uid] = array('#value' => $account->profile_ln); |
| 141 |
} |
} |
| 142 |
|
$form['accounts'] = array( |
|
$form['users'] = array( |
|
| 143 |
'#type' => 'checkboxes', |
'#type' => 'checkboxes', |
| 144 |
'#options' => $users |
'#options' => $accounts |
| 145 |
); |
); |
|
|
|
| 146 |
$form['pager'] = array('#value' => theme('pager', NULL, 50, 0)); |
$form['pager'] = array('#value' => theme('pager', NULL, 50, 0)); |
| 147 |
|
|
|
$form['#method'] = 'post'; |
|
|
$form['#action'] = url('admin/user/advuser/action'); |
|
|
|
|
| 148 |
return $form; |
return $form; |
| 149 |
} |
} |
| 150 |
|
|
| 151 |
|
/** |
| 152 |
function theme_advuser_admin_users_form($form) { |
* Theme user administration overview. |
| 153 |
|
*/ |
| 154 |
|
function theme_advuser_admin_account($form) { |
| 155 |
// Overview table: |
// Overview table: |
| 156 |
$header = array( |
$header = array( |
| 157 |
theme('table_select_header_cell'), |
theme('table_select_header_cell'), |
| 158 |
array('data' => t('Username'), 'field' => 'u.name'), |
array('data' => t('Username'), 'field' => 'u.name'), |
| 159 |
array('data' => t('Status'), 'field' => 'u.status'), |
array('data' => t('Status'), 'field' => 'u.status'), |
| 160 |
|
t('Roles'), |
| 161 |
|
array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'), |
| 162 |
array('data' => t('Last access'), 'field' => 'u.access'), |
array('data' => t('Last access'), 'field' => 'u.access'), |
|
array('data' => t('User ID'), 'field' => 'u.uid'), |
|
| 163 |
t('Operations') |
t('Operations') |
| 164 |
); |
); |
| 165 |
|
|
| 166 |
|
if (module_exists('profile')) { |
| 167 |
|
$fields = variable_get('advuser_profile_fields', ADVUSER_DEFAULT_PROFILE_FIELDS); |
| 168 |
|
if (is_array($fields)) { |
| 169 |
|
foreach ( $fields as $fid => $value) { |
| 170 |
|
if ( $value ) { |
| 171 |
|
$field = db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid)); |
| 172 |
|
$ff[] = array('data' => t($field->title), 'field' => $field->name); |
| 173 |
|
} |
| 174 |
|
} |
| 175 |
|
} |
| 176 |
|
$header = array_merge($header, $ff); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
$output .= drupal_render($form['options_all']); |
$output = drupal_render($form['options']); |
|
$output .= drupal_render($form['options_sel']); |
|
| 180 |
if (isset($form['name']) && is_array($form['name'])) { |
if (isset($form['name']) && is_array($form['name'])) { |
| 181 |
foreach (element_children($form['name']) as $key) { |
foreach (element_children($form['name']) as $key) { |
| 182 |
$rows[] = array( |
$row = array( |
| 183 |
drupal_render($form['users'][$key]), |
drupal_render($form['accounts'][$key]), |
| 184 |
drupal_render($form['name'][$key]), |
drupal_render($form['name'][$key]), |
| 185 |
drupal_render($form['status'][$key]), |
drupal_render($form['status'][$key]), |
| 186 |
drupal_render($form['access'][$key]), |
drupal_render($form['roles'][$key]), |
| 187 |
drupal_render($form['refcode'][$key]), |
drupal_render($form['member_for'][$key]), |
| 188 |
drupal_render($form['operations'][$key]), |
drupal_render($form['last_access'][$key]), |
| 189 |
|
drupal_render($form['operations'][$key]), |
| 190 |
); |
); |
|
} |
|
| 191 |
|
|
| 192 |
|
if (module_exists('profile')) { |
| 193 |
|
$fields = variable_get('advuser_profile_fields', ADVUSER_DEFAULT_PROFILE_FIELDS); |
| 194 |
|
if (is_array($fields)) { |
| 195 |
|
foreach ( $fields as $fid => $value) { |
| 196 |
|
if ( $value ) { |
| 197 |
|
$field = db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid)); |
| 198 |
|
$row[] = drupal_render($form[$field->name][$key]); |
| 199 |
|
} |
| 200 |
|
} |
| 201 |
|
} |
| 202 |
|
} |
| 203 |
|
$rows[] = $row; |
| 204 |
|
} |
| 205 |
} |
} |
| 206 |
else { |
else { |
| 207 |
$rows[] = array(array('data' => t('No posts available.'), 'colspan' => '4')); |
$rows[] = array(array('data' => t('No users available.'), 'colspan' => '7')); |
| 208 |
} |
} |
| 209 |
|
|
| 210 |
$output .= theme('table', $header, $rows); |
$output .= theme('table', $header, $rows); |
| 213 |
} |
} |
| 214 |
|
|
| 215 |
$output .= drupal_render($form); |
$output .= drupal_render($form); |
|
$output .= theme('pager', NULL, 50, 0); |
|
|
return $output; |
|
|
} |
|
| 216 |
|
|
|
function theme_advuser_admin_filter_form(&$form) { |
|
|
$output .= '<div id="advuser-admin-filter">'; |
|
|
$output .= drupal_render($form['filters']); |
|
|
$output .= '</div>'; |
|
|
$output .= drupal_render($form); |
|
| 217 |
return $output; |
return $output; |
| 218 |
} |
} |
| 219 |
|
|
|
function advuser_admin_users_validate($form_id, $edit) { |
|
|
$op = $form_values['op']; |
|
|
if ( $op == 'Update' ) { |
|
|
$edit['users'] = array_diff($edit['users'], array(0)); |
|
|
if (count($edit['users']) == 0) { |
|
|
form_set_error('', t('Please select some items to perform the update on.')); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
| 220 |
/** |
/** |
| 221 |
* Perform actions on users |
* Submit the user administration update form. |
| 222 |
*/ |
*/ |
| 223 |
function advuser_admin_users_submit($form_id, $edit) { |
function advuser_admin_account_submit($form_id, $form_values) { |
| 224 |
$operations = advuser_admin_users_operations(); |
$operations = module_invoke_all('user_operations'); |
| 225 |
if ($operations[$edit['operation']][1]) { |
$operations = array_merge($operations,module_invoke_all('advuser_operations')); |
| 226 |
// Execute sql |
$operation = $operations[$form_values['operation']]; |
| 227 |
$operation = $operations[$edit['operation']][1]; |
// Filter out unchecked accounts. |
| 228 |
foreach ($edit['users'] as $uid => $value) { |
$accounts = array_filter($form_values['accounts']); |
| 229 |
if ($value) { |
if ($function = $operation['callback']) { |
| 230 |
db_query($operation, $uid); |
// Add in callback arguments if present. |
| 231 |
} |
if (isset($operation['callback arguments'])) { |
| 232 |
|
$args = array_merge(array($accounts), $operation['callback arguments']); |
| 233 |
} |
} |
| 234 |
|
else { |
| 235 |
|
$args = array($accounts); |
| 236 |
|
} |
| 237 |
|
call_user_func_array($function, $args); |
| 238 |
|
|
| 239 |
|
cache_clear_all('*', 'cache_menu', TRUE); |
| 240 |
drupal_set_message(t('The update has been performed.')); |
drupal_set_message(t('The update has been performed.')); |
|
drupal_goto('admin/user/advuser'); |
|
| 241 |
} |
} |
| 242 |
} |
} |
| 243 |
|
|
| 244 |
/** |
function advuser_admin_account_validate($form_id, $form_values) { |
| 245 |
* Invokes hook_advuser() in every module. |
$form_values['accounts'] = array_filter($form_values['accounts']); |
| 246 |
* |
if (count($form_values['accounts']) == 0) { |
| 247 |
* We cannot use module_invoke() for this, because the arguments need to |
form_set_error('', t('No users selected.')); |
|
* be passed by reference. |
|
|
*/ |
|
|
function advuser_module_invoke($type, &$array) { |
|
|
foreach (module_list() as $module) { |
|
|
$function = $module .'_advuser'; |
|
|
if (function_exists($function)) { |
|
|
$function($type, $array); |
|
|
} |
|
| 248 |
} |
} |
| 249 |
} |
} |
| 250 |
|
|
| 251 |
function theme_advuser_filters(&$form) { |
function advuser_multiple_delete_confirm() { |
| 252 |
$output .= '<ul>'; |
$edit = $_POST; |
|
if (sizeof($form['current'])) { |
|
|
foreach (element_children($form['current']) as $key) { |
|
|
$output .= '<li>'. drupal_render($form['current'][$key]) .'</li>'; |
|
|
} |
|
|
} |
|
| 253 |
|
|
| 254 |
$output .= '<li><dl class="multiselect">'. (sizeof($form['current']) ? '<dt><em>'. t('and/or') .'</em> '. t('where') .'</dt>' : '') .'<dd class="a">'; |
$form['accounts'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE); |
| 255 |
foreach (element_children($form['filter']) as $key) { |
// array_filter returns only elements with TRUE values |
| 256 |
$output .= drupal_render($form['filter'][$key]); |
foreach (array_filter($edit['accounts']) as $uid => $value) { |
| 257 |
|
$user = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid)); |
| 258 |
|
$form['accounts'][$uid] = array('#type' => 'hidden', '#value' => $uid, '#prefix' => '<li>', '#suffix' => check_plain($user) ."</li>\n"); |
| 259 |
} |
} |
| 260 |
$output .= '</dd>'; |
$form['operation'] = array('#type' => 'hidden', '#value' => 'delete'); |
| 261 |
|
|
| 262 |
$output .= '<dt>'. t('is') .'</dt><dd class="b">'; |
return confirm_form($form, |
| 263 |
|
t('Are you sure you want to delete these users?'), |
| 264 |
|
'admin/user/advuser', t('This action cannot be undone.'), |
| 265 |
|
t('Delete all'), t('Cancel')); |
| 266 |
|
} |
| 267 |
|
|
| 268 |
foreach (element_children($form['status']) as $key) { |
function advuser_multiple_delete_confirm_submit($form_id, $form_values) { |
| 269 |
$output .= drupal_render($form['status'][$key]); |
if ($form_values['confirm']) { |
| 270 |
|
foreach ($form_values['accounts'] as $uid => $value) { |
| 271 |
|
user_delete($form_values, $uid); |
| 272 |
|
} |
| 273 |
|
drupal_set_message(t('The users have been deleted.')); |
| 274 |
} |
} |
| 275 |
$output .= '</dd>'; |
return 'admin/user/advuser'; |
| 276 |
|
} |
|
$output .= '</dl>'; |
|
|
$output .= '<div class="container-inline" id="advuser-admin-buttons">'. drupal_render($form['buttons']) .'</div>'; |
|
|
$output .= '</li></ul><br class="clear" />'; |
|
| 277 |
|
|
| 278 |
return $output; |
/** |
| 279 |
|
* Email functionality |
| 280 |
|
*/ |
| 281 |
|
function advuser_advuser_operations() { |
| 282 |
|
$operations = array( |
| 283 |
|
'email' => array( |
| 284 |
|
'label' => t('Email selected users') |
| 285 |
|
) |
| 286 |
|
); |
| 287 |
|
return $operations; |
| 288 |
} |
} |
| 289 |
|
|
| 290 |
function advuser_settings() { |
function advuser_multiple_email_confirm() { |
| 291 |
$form['module_banner'] = array( |
$edit = $_POST; |
| 292 |
|
|
| 293 |
|
$form['accounts'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE); |
| 294 |
|
// array_filter returns only elements with TRUE values |
| 295 |
|
foreach (array_filter($edit['accounts']) as $uid => $value) { |
| 296 |
|
$user = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid)); |
| 297 |
|
$form['accounts'][$uid] = array('#type' => 'hidden', '#value' => $uid, '#prefix' => '<li>', '#suffix' => check_plain($user) ."</li>\n"); |
| 298 |
|
} |
| 299 |
|
$form['operation'] = array('#type' => 'hidden', '#value' => 'email'); |
| 300 |
|
|
| 301 |
|
$form['variables'] = array( |
| 302 |
'#type' => 'markup', |
'#type' => 'markup', |
| 303 |
'#value' => '<div style="border: solid 1px #eee; margin: .5em; padding: .5em;" <strong>Module maintenance and development sponsored by <a href="http://exodusdev.com">Exodus Development</a></strong><br/>' |
'#value' => '<div class="advuser-inset-panel"><strong>Substitution variables</strong> available in subject and email body<br/><em> %username, %site, %uri, %user_email, %google_user (search google for user email), %yahoo_user (search yahoo for user email)</em></div>' |
| 304 |
); |
); |
| 305 |
|
|
| 306 |
$form['module_id'] = array( |
$form['mailsubject'] = array( |
| 307 |
'#type' => 'markup', |
'#type' => 'textfield', |
| 308 |
'#value' => ADVUSER_MODULE_VERSION .'<br/></div>' |
'#title' => t('Subject'), |
| 309 |
|
'#required' => TRUE, |
| 310 |
); |
); |
| 311 |
|
$form['mailbody'] = array( |
| 312 |
|
'#type' => 'textarea', |
| 313 |
|
'#title' => t('Mail body'), |
| 314 |
|
'#required' => TRUE, |
| 315 |
|
); |
| 316 |
|
|
| 317 |
|
return confirm_form($form, |
| 318 |
|
t('Are you sure you want to email these users?'), |
| 319 |
|
'admin/user/advuser', t('This action cannot be undone.'), |
| 320 |
|
t('Email'), t('Cancel')); |
| 321 |
|
} |
| 322 |
|
|
| 323 |
|
function advuser_multiple_email_confirm_submit($form_id, $form_values) { |
| 324 |
|
if ($form_values['confirm']) { |
| 325 |
|
foreach ($form_values['accounts'] as $uid => $value) { |
| 326 |
|
$account = user_load(array('uid' => $uid)); |
| 327 |
|
if ( module_exists('lightcrm') ) { |
| 328 |
|
_lightcrm_comment_add($uid, $edit['mailsubject'], $edit['mailbody']); |
| 329 |
|
} else { |
| 330 |
|
$from = variable_get("site_mail", ini_get("sendmail_from")); // http://drupal.org/node/77689 |
| 331 |
|
// these are invariant for all sent emails |
| 332 |
|
$variables = _advuser_get_variables($account); |
| 333 |
|
$form_values['mailsubject'] = strtr($form_values['mailsubject'], $variables); |
| 334 |
|
$form_values['mailbody'] = strtr($form_values['mailbody'], $variables); |
| 335 |
|
drupal_mail('advance-user-mail', $account->mail, $form_values['mailsubject'], $form_values['mailbody'], $from); |
| 336 |
|
} |
| 337 |
|
} |
| 338 |
|
drupal_set_message(t('The users have been mailed.')); |
| 339 |
|
} |
| 340 |
|
return 'admin/user/advuser'; |
| 341 |
|
} |
| 342 |
|
|
| 343 |
|
/** |
| 344 |
|
* advuser settings page |
| 345 |
|
*/ |
| 346 |
|
function advuser_settings() { |
| 347 |
|
|
| 348 |
$form['advuser_mail'] = array( |
$form['advuser_mail'] = array( |
| 349 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 396 |
'#description' => t('The mail that is going to be sent to the selected roles when a user modifies their account. You may insert substitution variables within this item.'), |
'#description' => t('The mail that is going to be sent to the selected roles when a user modifies their account. You may insert substitution variables within this item.'), |
| 397 |
'#default_value' => variable_get('advuser_modify_mail', ADVUSER_DEFAULT_MODIFY_MAIL), |
'#default_value' => variable_get('advuser_modify_mail', ADVUSER_DEFAULT_MODIFY_MAIL), |
| 398 |
); |
); |
| 399 |
|
|
| 400 |
//Maximum rows in dataset to display |
//Maximum rows in dataset to display |
| 401 |
$form['advuser_mail']['advuser_listno'] = array( |
$form['advuser_mail']['advuser_listno'] = array( |
| 402 |
'#type' => 'select', |
'#type' => 'select', |
| 434 |
= array('#type' => 'markup', |
= array('#type' => 'markup', |
| 435 |
'#value' => '<div class="advuser-settings-warning"><strong>WARNING: No roles selected!</strong> - no email notifications will be sent.</div>'); |
'#value' => '<div class="advuser-settings-warning"><strong>WARNING: No roles selected!</strong> - no email notifications will be sent.</div>'); |
| 436 |
} |
} |
| 437 |
|
|
| 438 |
if ( module_exists('profile') ) { |
if ( module_exists('profile') ) { |
| 439 |
$form['advuser_profile'] = array( |
$form['advuser_profile'] = array( |
| 440 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 444 |
); |
); |
| 445 |
|
|
| 446 |
$fields = array(); |
$fields = array(); |
| 447 |
$result = db_query('SELECT * FROM {profile_fields} WHERE visibility != %d ORDER BY category, weight', PROFILE_HIDDEN); |
$result = db_query('SELECT * FROM {profile_fields} ORDER BY category, weight'); |
| 448 |
while ( $row = db_fetch_object($result)) { |
while ( $row = db_fetch_object($result)) { |
| 449 |
$fields[$row->fid] = $row->title; |
$fields[$row->fid] = $row->title; |
| 450 |
} |
} |
| 584 |
case 'update': |
case 'update': |
| 585 |
return advuser_user_update($edit, $user, $category); |
return advuser_user_update($edit, $user, $category); |
| 586 |
} |
} |
|
|
|
|
//print $type; |
|
| 587 |
} |
} |
|
|
|
|
// vim:ft=php:et:sw=2:ts=2:sts=2:ai:sta |
|