/[drupal]/contributions/modules/advuser/advuser.module
ViewVC logotype

Diff of /contributions/modules/advuser/advuser.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.12 by inactivist, Sat Jan 20 21:05:26 2007 UTC revision 1.13 by earnie, Sun Sep 30 07:34:57 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3    // $Id: advuser.module,v 1.11 2007/01/20 20:58:53 inactivist Exp $    // $Id: advuser.module,v 1.12.4.2 2007/06/02 22:45:47 earnie Exp $
4  define('ADVUSER_MODULE_VERSION', '$Id: advuser.module,v 1.11 2007/01/20 20:58:53 inactivist Exp $' );  define('ADVUSER_MODULE_VERSION', '$Id: advuser.module,v 1.12.4.2 2007/06/02 22:45:47 earnie Exp $' );
5    
6  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");
7  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");
# Line 26  define('ADVUSER_DEFAULT_PROFILE_FIELDS', Line 26  define('ADVUSER_DEFAULT_PROFILE_FIELDS',
26  function advuser_menu($may_cache) {  function advuser_menu($may_cache) {
27    // code which should run exactly once per page view    // code which should run exactly once per page view
28    if (!$may_cache) {    if (!$may_cache) {
29      theme_add_style(drupal_get_path('module', 'advuser') .'/advuser.css');      drupal_add_css(drupal_get_path('module', 'advuser') .'/advuser.css');
30    }    }
31    $items = array();    $items = array();
32    if ($may_cache) {    if ($may_cache) {
33      $items[] =      $items[] = array(
34        array('path' => 'admin/user/advuser',        'path' => 'admin/settings/advuser',
35              'title' => t('advanced managment'),        'title' => t('Advanced User'),
36          'description' => t('Advanced User Settings'),
37          'callback' => 'drupal_get_form',
38          'callback arguments' => array('advuser_settings'),
39          'access' => user_access('administer site configuration'),
40          'type' => MENU_NORMAL_ITEM,
41        );
42    
43        $items[] = array(
44                'path' => 'admin/user/advuser',
45                'title' => t('Advanced managment'),
46              'callback' => 'advuser_admin_users',              'callback' => 'advuser_admin_users',
47              'type' => MENU_LOCAL_TASK,              'type' => MENU_NORMAL_ITEM,
48              'weight' => 7,  //            'weight' => 7,
49              'access' => user_access('administer users'),              'access' => user_access('administer users'),
50              );              );
51    }    }
# Line 63  function advuser_admin_filters() { Line 73  function advuser_admin_filters() {
73    
74    // Regular filters    // Regular filters
75    $filters['email'] = array(    $filters['email'] = array(
76        'title' =>t('E-mail'),        'title' => t('E-mail'),
77        'where' => "u.mail = '%s'",        'where' => "u.mail = '%s'",
78      );      );
79    
80                    $filters['uid'] = array(     $filters['uid'] = array(
81        'title' =>t('User Id'),        'title' => t('User Id'),
82        'where' => "u.uid = '%s'",        'where' => "u.uid = '%s'",
83      );      );
84    
85                    $filters['access'] = array(      $filters['access'] = array(
86        'title' =>t('Last Access'),        'title' => t('Last Access'),
87        'where' => "u.access = '%s'",        'where' => "u.access = '%s'",
88      );      );
89                                  $filters['status'] = array(      $filters['status'] = array(
90        'title' =>t('Status'),        'title' => t('Status'),
91        'type'  =>t('selection'),        'type'  => t('selection'),
92        'options' => array(0 => t('Blocked'), 1 => ('Active')),        'options' => array(0 => t('Blocked'), 1 => ('Active')),
93        'where' => 'u.status = %s',        'where' => 'u.status = %s',
94      );      );
# Line 98  function advuser_admin_filters() { Line 108  function advuser_admin_filters() {
108    
109          // Regular filters          // Regular filters
110          $filters[$field->fid] = array(          $filters[$field->fid] = array(
111              'title' =>$field->title,              'title' => $field->title,
112              'type' => $field->type,              'type' => $field->type,
113              'options' => $options,              'options' => $options,
114              'field_where' => 'pf.fid = ' . $field->fid .' AND pv.value = ' . "'%s'",              'field_where' => 'pf.fid = '. $field->fid .' AND pv.value = '."'%s'",
115            );            );
116        }        }
   
117      }      }
118    }    }
119    
   
120    advuser_module_invoke('filter', $filters);    advuser_module_invoke('filter', $filters);
121    return $filters;    return $filters;
122  }  }
123    
124  function advuser_admin_filter_form_validate($form_id, $form) {  function advuser_admin_filter_form_validate($form_id, $form) {
125    $op = $_POST['op'];    $op = $form_values['op'];
126    if(  $op == 'Filter' || $op == 'Refine' ) {    if ( $op == 'Filter' || $op == 'Refine' ) {
127      if ( ! isset($form[$form['filter']]) || $form[$form['filter']] == '' ) {      if ( ! isset($form[$form['filter']]) || $form[$form['filter']] == '' ) {
128        form_set_error($form['filter'], t('Please fill some value to correctely set up the filter'));        form_set_error($form['filter'], t('Please fill some value to correctely set up the filter'));
129      }      }
# Line 125  function advuser_admin_filter_form_valid Line 133  function advuser_admin_filter_form_valid
133    
134  function advuser_admin_filter_form_submit() {  function advuser_admin_filter_form_submit() {
135    global $form_values;    global $form_values;
136    $op = $_POST['op'];    $op = $form_values['op'];
137    $filters = advuser_admin_filters();    $filters = advuser_admin_filters();
138    switch ($op) {    switch ($op) {
139      case t('Filter'): case t('Refine'):      case t('Filter'): case t('Refine'):
# Line 135  function advuser_admin_filter_form_submi Line 143  function advuser_admin_filter_form_submi
143            if (isset($filters[$filter]['options'][$form_values[$filter]])) {            if (isset($filters[$filter]['options'][$form_values[$filter]])) {
144              $_SESSION['advuser_user_filter'][] = array($filter, $form_values[$filter]);              $_SESSION['advuser_user_filter'][] = array($filter, $form_values[$filter]);
145            }            }
146          } else {          }
147             else {
148            $_SESSION['advuser_user_filter'][] = array($filter, $form_values[$filter]);            $_SESSION['advuser_user_filter'][] = array($filter, $form_values[$filter]);
149          }          }
150        }        }
# Line 175  function advuser_admin_filter_form() { Line 184  function advuser_admin_filter_form() {
184      if ( array_search($type, $types_used) !== FALSE ) {      if ( array_search($type, $types_used) !== FALSE ) {
185        $em = 'or';        $em = 'or';
186      }      }
187      $string = ($i++ ? '<em>'.$em.'</em> where <strong>%a</strong> is <strong>%b</strong>' : '<strong>%a</strong> is <strong>%b</strong>');      $string = ($i++ ? '<em>'. $em .'</em> where <strong>%a</strong> is <strong>%b</strong>' : '<strong>%a</strong> is <strong>%b</strong>');
188      $txt_value = $value;      $txt_value = $value;
189      if ($original['type'] == 'selection') {      if ($original['type'] == 'selection') {
190        $txt_value = $original['options'][$value];        $txt_value = $original['options'][$value];
# Line 188  function advuser_admin_filter_form() { Line 197  function advuser_admin_filter_form() {
197      $names[$key] = $filter['title'];      $names[$key] = $filter['title'];
198      if ( $filter['type'] == 'selection' ) {      if ( $filter['type'] == 'selection' ) {
199        $form['filters']['status'][$key] = array('#type' => 'select', '#options' => $filter['options']);        $form['filters']['status'][$key] = array('#type' => 'select', '#options' => $filter['options']);
200      } else {      }
201         else {
202        $form['filters']['status'][$key] = array('#type' => 'textfield');        $form['filters']['status'][$key] = array('#type' => 'textfield');
203      }      }
204    }    }
# Line 201  function advuser_admin_filter_form() { Line 211  function advuser_admin_filter_form() {
211      $form['filters']['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset'));      $form['filters']['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset'));
212    }    }
213    
214    return drupal_get_form('advuser_admin_filter_form', $form);  //  return drupal_get_form('advuser_admin_filter_form', $form);
215      return $form;
216  }  }
217    
218    
219  /*  /*
220  ** Node operations  ** AdvUser operations
221  */  */
222  function advuser_admin_users_operations() {  function advuser_admin_users_operations() {
223    $external = array();    $external = array();
224    $operations = array(    $operations = array(
225      'email' => array(t('Email users'), 'advuser_multiple_email_confirm', 'confirm'),      'email' => array(t('Email users'), 'advuser_multiple_email_confirm_page', 'confirm'),
226      'delete' =>    array(t('Delete users'), 'advuser_multiple_delete_confirm' , 'confirm')      'delete' =>    array(t('Delete users'), 'advuser_multiple_delete_confirm' , 'confirm')
227    );    );
228    
229    advuser_module_invoke('actions', $external);    advuser_module_invoke('actions', $external);
230    
231    foreach ($external as $k => $v ) {    foreach ($external as $k => $v ) {
232      $operations['external_'.$k] = $v;      $operations['external_'. $k] = $v;
233    }    }
234    
235    return $operations;    return $operations;
# Line 242  function advuser_admin_user_build_filter Line 254  function advuser_admin_user_build_filter
254      if ( count((array) $where_keys) > 0 ) {      if ( count((array) $where_keys) > 0 ) {
255        // check for same value to on arg array, should have the same key        // check for same value to on arg array, should have the same key
256        foreach ( $where_keys as $k => $v ) {        foreach ( $where_keys as $k => $v ) {
257          if ( $where_args[$v] == $value ) {          if ( $where_args[$v] == $value ) {
258             $where_key = FALSE;            $where_key = FALSE;
259          }          }
260        }//foreach;        }//foreach;
   
261      }      }
262    
263      if ( isset($filters[$key]['where']) && $where_key )  {      if ( isset($filters[$key]['where']) && $where_key )  {
# Line 260  function advuser_admin_user_build_filter Line 271  function advuser_admin_user_build_filter
271      if ( count((array) $field_where_keys) > 0 ) {      if ( count((array) $field_where_keys) > 0 ) {
272        // check for same value to on arg array, should have the same key        // check for same value to on arg array, should have the same key
273        foreach ( $field_where_keys as $k => $v ) {        foreach ( $field_where_keys as $k => $v ) {
274          if ( $having_args[$v] == $value ) {          if ( $having_args[$v] == $value ) {
275             $field_where_key = FALSE;            $field_where_key = FALSE;
276          }          }
277        }//foreach;        }//foreach;
278        }
279      } else {       else {
280        if (  isset($filters[$key]['field_where']) ) {        if (  isset($filters[$key]['field_where']) ) {
281          $cnt++;          $cnt++;
282        }        }
# Line 277  function advuser_admin_user_build_filter Line 288  function advuser_admin_user_build_filter
288      }      }
289    
290      // Proces join just once      // Proces join just once
291      if ( ! strstr($join, $filters[$key]['join'] . ' ') ) {      if ( ! strstr($join, $filters[$key]['join'] .' ') ) {
292        $join .= $filters[$key]['join'] . ' ';        $join .= $filters[$key]['join'] .' ';
293      }      }
294    }    }
295    
# Line 289  function advuser_admin_user_build_filter Line 300  function advuser_admin_user_build_filter
300    foreach ( (array) $where as $w ) {    foreach ( (array) $where as $w ) {
301      if ( $lastwhere ) {      if ( $lastwhere ) {
302        if ( $lastwhere == $w ) {        if ( $lastwhere == $w ) {
303          $where_sql .= ' OR ' . $w ;          $where_sql .= ' OR '. $w ;
304        } else {        }
305          $where_sql .= ') AND (' . $w ;         else {
306            $where_sql .= ') AND ('. $w ;
307        }        }
308      } else {      }
309        $where_sql .= '(' . $w ;       else {
310          $where_sql .= '('. $w ;
311      }      }
312      $lastwhere = $w;      $lastwhere = $w;
313    }    }
# Line 306  function advuser_admin_user_build_filter Line 319  function advuser_admin_user_build_filter
319    $where = count($where) ? 'WHERE u.uid > 1 AND '. implode(' AND ', $where) : '';    $where = count($where) ? 'WHERE u.uid > 1 AND '. implode(' AND ', $where) : '';
320    $field_where_cnt = count($field_where);    $field_where_cnt = count($field_where);
321    $field_where = $field_where_cnt ? implode(' OR ', $field_where) : '0';    $field_where = $field_where_cnt ? implode(' OR ', $field_where) : '0';
322    $having[] = 'SUM(IF(' . $field_where . ',1,0)) = ' . $cnt;    $having[] = 'SUM(IF('. $field_where .',1,0)) = '. $cnt;
323    $having = count($having) ? 'HAVING '. implode(' AND ', $having) : '';    $having = count($having) ? 'HAVING '. implode(' AND ', $having) : '';
324    
325    $args = array_merge($where_args, $having_args);    $args = array_merge($where_args, $having_args);
326    
327    return array( 'where' => $where_sql, 'join' => $join, 'args' => $args, 'having'=> $having);    return array( 'where' => $where_sql, 'join' => $join, 'args' => $args, 'having' => $having);
328  }  }
329    
330  function advuser_multiple_email_confirm($all, &$form) {  function advuser_multiple_email_confirm_page($all, $form) {
331      return drupal_get_form('advuser_multiple_email_confirm', $all, $form);
332    }
333    
334    function advuser_multiple_email_confirm($all, $form) {
335    $form['mailsubject'] = array(    $form['mailsubject'] = array(
336        '#type' => 'textfield',        '#type' => 'textfield',
337        '#title' => t('Subject'),        '#title' => t('Subject'),
# Line 325  function advuser_multiple_email_confirm( Line 342  function advuser_multiple_email_confirm(
342        '#title' => t('Mail body'),        '#title' => t('Mail body'),
343        '#required' => TRUE,        '#required' => TRUE,
344      );      );
345    
346      return confirm_form($form,
347                          t('Are you sure you want to mail these users?'),
348                          'admin/user/advuser', t('This action cannot be undone.'),
349                          t('Mail all'), t('Cancel'));
350  }  }
351    
352    
353  function advuser_multiple_email_confirm_submit($form_id, $edit) {  function advuser_multiple_email_confirm_submit($form_id, $edit) {
354    if ($edit['confirm']) {    if ($edit['confirm']) {
355      foreach ($edit['users'] as $uid => $value) {      foreach ($edit['users'] as $uid => $value) {
356        $account = user_load(array('uid'=>$uid));        $account = user_load(array('uid' => $uid));
357        if ( module_exist('lightcrm') ) {        if ( module_exists('lightcrm') ) {
358          _lightcrm_comment_add($uid, $edit['mailsubject'], $edit['mailbody']);          _lightcrm_comment_add($uid, $edit['mailsubject'], $edit['mailbody']);
359        } else {        }
360           else {
361          $from = variable_get("site_mail", ini_get("sendmail_from")); // http://drupal.org/node/77689          $from = variable_get("site_mail", ini_get("sendmail_from")); // http://drupal.org/node/77689
362          user_mail($account->mail, $edit['mailsubject'], $edit['mailbody'], "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");          drupal_mail('advance-user-mail', $account->mail, $edit['mailsubject'], $edit['mailbody'], $from);
         //user_mail($account->mail, $edit['mailsubject'], $edit['mailbody'], "Reply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");  
363        }        }
364      }      }
365      drupal_set_message(t('The users have been mailed.'));      drupal_set_message(t('The users have been mailed.'));
# Line 348  function advuser_multiple_email_confirm_ Line 370  function advuser_multiple_email_confirm_
370  function advuser_multiple_delete_confirm_submit($form_id, $edit) {  function advuser_multiple_delete_confirm_submit($form_id, $edit) {
371    if ($edit['confirm']) {    if ($edit['confirm']) {
372      foreach ($edit['users'] as $uid => $value) {      foreach ($edit['users'] as $uid => $value) {
373        $account = user_load(array('uid'=>$uid));        $account = user_load(array('uid' => $uid));
374        db_query('DELETE FROM {users} WHERE uid = %d', $account->uid);        db_query('DELETE FROM {users} WHERE uid = %d', $account->uid);
375        db_query('DELETE FROM {sessions} WHERE uid = %d', $account->uid);        db_query('DELETE FROM {sessions} WHERE uid = %d', $account->uid);
376        db_query('DELETE FROM {users_roles} WHERE uid = %d', $account->uid);        db_query('DELETE FROM {users_roles} WHERE uid = %d', $account->uid);
# Line 370  function advuser_multiple_confirm($all, Line 392  function advuser_multiple_confirm($all,
392    // array filter returns only elements with true values    // array filter returns only elements with true values
393    if ( $all ) {    if ( $all ) {
394      $filter = advuser_admin_user_build_filter_query();      $filter = advuser_admin_user_build_filter_query();
395      $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']);      $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']);
396      while ( $usr = db_fetch_object($result)) {      while ( $usr = db_fetch_object($result)) {
397        $user_array[$usr->uid] = '';        $user_array[$usr->uid] = '';
398      }      }
399    } else {    }
400       else {
401      $user_array = array_filter($edit['users']);      $user_array = array_filter($edit['users']);
402    }    }
403    
# Line 396  function advuser_multiple_confirm($all, Line 419  function advuser_multiple_confirm($all,
419  }  }
420    
421  function advuser_admin_users() {  function advuser_admin_users() {
422      $output = drupal_get_form('advuser_admin_filter_form');
423    
424      // Call the form first, to allow for the form_values array to be populated.
425    //  $output .= drupal_get_form('user_admin_account');
426      $output .= drupal_get_form('advuser_admin_users_form');
427    
428      return $output;
429    }
430    
431    function advuser_admin_users_form() {
432    global $form_values;    global $form_values;
   $output = advuser_admin_filter_form();  
433    
434    $op = $_POST['op'];    $op = $form_values['op'];
435    if ( $op == 'Update all' ) {    if ( $op == 'Update all' ) {
436      $all = TRUE;      $all = TRUE;
437    }    }
# Line 421  function advuser_admin_users() { Line 453  function advuser_admin_users() {
453    
454    $filter = advuser_admin_user_build_filter_query();    $filter = advuser_admin_user_build_filter_query();
455    $listno = variable_get('advuser_listno', ADVUSER_DEFAULT_LISTNO);    $listno = variable_get('advuser_listno', ADVUSER_DEFAULT_LISTNO);
456    $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 = 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']);
457    //$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 = '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'];
458    //$result .= tablesort_sql($header);    //$result .= tablesort_sql($header);
459    
# Line 434  function advuser_admin_users() { Line 466  function advuser_admin_users() {
466    foreach (advuser_admin_users_operations() as $key => $value) {    foreach (advuser_admin_users_operations() as $key => $value) {
467      $options[$key] = $value[0];      $options[$key] = $value[0];
468    }    }
469    $form['options_all']['operation'] = array('#type' => 'select', '#options' => $options);    $form['options_all']['operation'] = array(
470    $form['options_all']['submit'] = array('#type' => 'submit', '#value' => t('Update all'));      '#type' => 'select',
471        '#options' => $options,
472      );
473      $form['options_all']['submit'] = array(
474        '#type' => 'submit',
475        '#value' => t('Update all')
476      );
477    
478    $form['options_sel'] = array(    $form['options_sel'] = array(
479      '#type' => 'fieldset', '#title' => t('Update on selected records only'),      '#type' => 'fieldset', '#title' => t('Update on selected records only'),
# Line 446  function advuser_admin_users() { Line 484  function advuser_admin_users() {
484    foreach (advuser_admin_users_operations() as $key => $value) {    foreach (advuser_admin_users_operations() as $key => $value) {
485      $options[$key] = $value[0];      $options[$key] = $value[0];
486    }    }
487    $form['options_sel']['operation'] = array('#type' => 'select', '#options' => $options);    $form['options_sel']['operation'] = array(
488    $form['options_sel']['submit'] = array('#type' => 'submit', '#value' => t('Update'));      '#type' => 'select',
489        '#options' => $options,
490       );
491      $form['options_sel']['submit'] = array(
492        '#type' => 'submit',
493        '#value' => t('Update')
494       );
495    
496        $destination = drupal_get_destination();
497    
498        $status = array(t('blocked'), t('active'));
499    
   $destination = drupal_get_destination();  
500    while ($usr = db_fetch_object($result)) {    while ($usr = db_fetch_object($result)) {
501      $users[$usr->uid] = '';      $users[$usr->uid] = '';
502      $form['name'][$usr->uid] = array('#value' => l($usr->name, 'user/'. $usr->uid));      $form['name'][$usr->uid] = array('#value' => theme('username', $usr));
503      $form['status'][$usr->uid] =  array('#value' =>  ($usr->status ? t('active') : t('blocked')));  
504          $form['access'][$usr->uid] = array('#value' => $usr->access ? t('%time ago', array('%time' => format_interval(time() - $usr->access))) : t('never'));      $form['status'][$account->uid] =  array('#value' => $status[$account->status]);
505          //$form['access'][$usr->access] = array('#value' => ($usr->access ? format_interval(time() - $usr->access)));      $form['access'][$usr->uid] = array('#value' => $usr->access ? t('%time ago', array('%time' => format_interval(time() - $usr->access))) : t('never'));
506          $form['operations'][$usr->uid] = array('#value' => l(t('edit'), 'user/'. $usr->uid .'/edit', array(), $destination));      //$form['access'][$usr->access] = array('#value' => ($usr->access ? format_interval(time() - $usr->access)));
507        $form['operations'][$usr->uid] = array('#value' => l(t('edit'), 'user/'. $usr->uid .'/edit', array(), $destination));
508      $form['refcode'][$usr->uid] = array('#value' => $usr->uid);      $form['refcode'][$usr->uid] = array('#value' => $usr->uid);
509    }    }
510    $form['users'] = array('#type' => 'checkboxes', '#options' => $users);  
511      $form['users'] = array(
512        '#type' => 'checkboxes',
513        '#options' => $users
514       );
515    
516    $form['pager'] = array('#value' => theme('pager', NULL, 50, 0));    $form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
517    
518    $form['#method'] = 'post';    $form['#method'] = 'post';
519    $form['#action'] =  url('admin/user/advuser/action');    $form['#action'] =  url('admin/user/advuser/action');
520    
521    // Call the form first, to allow for the form_values array to be populated.    return $form;
   $output .= drupal_get_form('advuser_admin_users', $form);  
   
   return $output;  
522  }  }
523    
524    
525  function theme_advuser_admin_users($form) {  function theme_advuser_admin_users_form($form) {
526    // Overview table:    // Overview table:
527    $header = array(NULL, t('Username'), t('Status'), t('Last Access'), t('User ID'), t('Operation'));    $header = array(
528        theme('table_select_header_cell'),
529        array('data' => t('Username'), 'field' => 'u.name'),
530        array('data' => t('Status'), 'field' => 'u.status'),
531        array('data' => t('Last access'), 'field' => 'u.access'),
532        array('data' => t('User ID'), 'field' => 'u.uid'),
533        t('Operations')
534      );
535    
536    
537    $output .= form_render($form['options_all']);    $output .= drupal_render($form['options_all']);
538    $output .= form_render($form['options_sel']);    $output .= drupal_render($form['options_sel']);
539    if (isset($form['name']) && is_array($form['name'])) {    if (isset($form['name']) && is_array($form['name'])) {
540      foreach (element_children($form['name']) as $key) {      foreach (element_children($form['name']) as $key) {
541        $row = array();        $rows[] = array(
542        $row[] = form_render($form['users'][$key]);        drupal_render($form['users'][$key]),
543        $row[] = form_render($form['name'][$key]);        drupal_render($form['name'][$key]),
544        $row[] = form_render($form['status'][$key]);        drupal_render($form['status'][$key]),
545                                                  $row[] = form_render($form['access'][$key]);        drupal_render($form['access'][$key]),
546                                                  $row[] = form_render($form['refcode'][$key]);        drupal_render($form['refcode'][$key]),
547        $row[] = form_render($form['operations'][$key]);        drupal_render($form['operations'][$key]),
548        $rows[] = $row;        );
549      }      }
550    
551    }    }
# Line 496  function theme_advuser_admin_users($form Line 554  function theme_advuser_admin_users($form
554    }    }
555    
556    $output .= theme('table', $header, $rows);    $output .= theme('table', $header, $rows);
557                  if ($form['pager']['#value']) {    if ($form['pager']['#value']) {
558    $output .= form_render($form['pager']);      $output .= drupal_render($form['pager']);
559    }    }
560    
561    $output .= form_render($form);    $output .= drupal_render($form);
562    $output .= theme('pager', NULL, 50, 0);    $output .= theme('pager', NULL, 50, 0);
563    return $output;    return $output;
564  }  }
565    
566  function theme_advuser_admin_filter_form(&$form) {  function theme_advuser_admin_filter_form(&$form) {
567    $output .= '<div id="advuser-admin-filter">';    $output .= '<div id="advuser-admin-filter">';
568    $output .= form_render($form['filters']);    $output .= drupal_render($form['filters']);
569    $output .= '</div>';    $output .= '</div>';
570    $output .= form_render($form);    $output .= drupal_render($form);
571    return $output;    return $output;
572  }  }
573    
574  function advuser_admin_users_validate($form_id, $edit) {  function advuser_admin_users_validate($form_id, $edit) {
575    $op = $_POST['op'];    $op = $form_values['op'];
576    if ( $op == 'Update' ) {    if ( $op == 'Update' ) {
577      $edit['users'] = array_diff($edit['users'], array(0));      $edit['users'] = array_diff($edit['users'], array(0));
578      if (count($edit['users']) == 0) {      if (count($edit['users']) == 0) {
# Line 560  function theme_advuser_filters(&$form) { Line 618  function theme_advuser_filters(&$form) {
618    $output .= '<ul>';    $output .= '<ul>';
619    if (sizeof($form['current'])) {    if (sizeof($form['current'])) {
620      foreach (element_children($form['current']) as $key) {      foreach (element_children($form['current']) as $key) {
621        $output .= '<li>' . form_render($form['current'][$key]) . '</li>';        $output .= '<li>'. drupal_render($form['current'][$key]) .'</li>';
622      }      }
623    }    }
624    
625    $output .= '<li><dl class="multiselect">' . (sizeof($form['current']) ? '<dt><em>'. t('and/or') .'</em> '. t('where') .'</dt>' : '') . '<dd class="a">';    $output .= '<li><dl class="multiselect">'. (sizeof($form['current']) ? '<dt><em>'. t('and/or') .'</em> '. t('where') .'</dt>' : '') .'<dd class="a">';
626    foreach(element_children($form['filter']) as $key) {    foreach (element_children($form['filter']) as $key) {
627      $output .= form_render($form['filter'][$key]);      $output .= drupal_render($form['filter'][$key]);
628    }    }
629    $output .= '</dd>';    $output .= '</dd>';
630    
631    $output .= '<dt>'. t('is') .'</dt>' . '<dd class="b">';    $output .= '<dt>'. t('is') .'</dt><dd class="b">';
632    
633    foreach(element_children($form['status']) as $key) {    foreach (element_children($form['status']) as $key) {
634      $output .= form_render($form['status'][$key]);      $output .= drupal_render($form['status'][$key]);
635    }    }
636    $output .= '</dd>';    $output .= '</dd>';
637    
638    $output .= '</dl>';    $output .= '</dl>';
639    $output .= '<div class="container-inline" id="advuser-admin-buttons">'. form_render($form['buttons']) .'</div>';    $output .= '<div class="container-inline" id="advuser-admin-buttons">'. drupal_render($form['buttons']) .'</div>';
640    $output .= '</li></ul><br class="clear" />';    $output .= '</li></ul><br class="clear" />';
641    
642    return $output;    return $output;
643  }  }
644    
645  function advuser_settings() {  function advuser_settings() {
646    $form['module_banner']    $form['module_banner'] = array(
647      = array('#type' => 'markup',        '#type' => 'markup',
648              '#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 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/>'
649    $form['module_id'] = array('#type' => 'markup', '#value' =>  ADVUSER_MODULE_VERSION .'<br/></div>');      );
650    
651      $form['module_id'] = array(
652          '#type' => 'markup',
653          '#value' =>  ADVUSER_MODULE_VERSION .'<br/></div>'
654        );
655    
656    $form['advuser_mail'] = array(    $form['advuser_mail'] = array(
657        '#type' => 'fieldset',        '#type' => 'fieldset',
# Line 597  function advuser_settings() { Line 660  function advuser_settings() {
660        '#collapsed' => FALSE,        '#collapsed' => FALSE,
661      );      );
662    
663      $form['advuser_mail']['variables'] = array(
664          '#type' => 'markup',
665          '#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>'
666        );
667    
668      //New User Notification
669    $form['advuser_mail']['advuser_new_notify'] = array(    $form['advuser_mail']['advuser_new_notify'] = array(
670        '#type' => 'checkbox',        '#type' => 'checkbox',
671        '#title' => t('Send notifications on new user registration'),        '#title' => t('Send notifications on new user registration'),
672        '#description' => t('Notify selected roles when new users register.'),        '#description' => t('Notify selected roles when new users register.'),
673        '#default_value' => variable_get('advuser_new_notify', ADVUSER_DEFAULT_NEW_NOTIFY),        '#default_value' => variable_get('advuser_new_notify', ADVUSER_DEFAULT_NEW_NOTIFY),
674      );      );
   
                 $form['advuser_mail']['advuser_modify_notify'] = array(  
       '#type' => 'checkbox',  
       '#title' => t('Send notifications on user profile updates'),  
       '#description' => t('Notify selected roles when users update their profiles.'),  
       '#default_value' => variable_get('advuser_modify_notify', ADVUSER_DEFAULT_MODIFY_NOTIFY),  
     );  
   
   $form['advuser_mail']['variables']  
     = array('#type' => 'markup',  
             '#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>');  
   
675    $form['advuser_mail']['advuser_new_subject'] = array(    $form['advuser_mail']['advuser_new_subject'] = array(
676        '#type' => 'textfield',        '#type' => 'textfield',
677        '#title' => t('Mail subject'),        '#title' => t('Mail subject'),
678        '#description' => t('The subject of the mail that is going to be sent to the user.  You may insert substitution variables within this item.'),        '#description' => t('The subject of the mail that is going to be sent to the user.  You may insert substitution variables within this item.'),
679        '#default_value' => variable_get('advuser_new_subject', ADVUSER_DEFAULT_NEW_SUBJECT),        '#default_value' => variable_get('advuser_new_subject', ADVUSER_DEFAULT_NEW_SUBJECT),
680      );      );
                 $form['advuser_mail']['advuser_modify_subject'] = array(  
       '#type' => 'textfield',  
       '#title' => t('Mail subject'),  
       '#description' => t('The subject of the mail that is going to be sent when a user modifies their profiles.  You may insert substitution variables within this item.'),  
       '#default_value' => variable_get('advuser_modify_subject', ADVUSER_DEFAULT_MODIFY_SUBJECT),  
     );  
   
681    $form['advuser_mail']['advuser_new_mail'] = array(    $form['advuser_mail']['advuser_new_mail'] = array(
682        '#type' => 'textarea',        '#type' => 'textarea',
683        '#title' => t('Mail body'),        '#title' => t('Mail body'),
684        '#description' => t('The mail that is going to be sent to the selected roles.  You may insert substitution variables within this item.'),        '#description' => t('The mail that is going to be sent to the selected roles.  You may insert substitution variables within this item.'),
685        '#default_value' => variable_get('advuser_new_mail', ADVUSER_DEFAULT_NEW_MAIL),        '#default_value' => variable_get('advuser_new_mail', ADVUSER_DEFAULT_NEW_MAIL),
686      );      );
687                  $form['advuser_mail']['advuser_modify_mail'] = array(  
688       //User change notification
689       $form['advuser_mail']['advuser_modify_notify'] = array(
690          '#type' => 'checkbox',
691          '#title' => t('Send notifications on user profile updates'),
692          '#description' => t('Notify selected roles when users update their profiles.'),
693          '#default_value' => variable_get('advuser_modify_notify', ADVUSER_DEFAULT_MODIFY_NOTIFY),
694        );
695      $form['advuser_mail']['advuser_modify_subject'] = array(
696          '#type' => 'textfield',
697          '#title' => t('Mail subject'),
698          '#description' => t('The subject of the mail that is going to be sent when a user modifies their profiles.  You may insert substitution variables within this item.'),
699          '#default_value' => variable_get('advuser_modify_subject', ADVUSER_DEFAULT_MODIFY_SUBJECT),
700        );
701      $form['advuser_mail']['advuser_modify_mail'] = array(
702        '#type' => 'textarea',        '#type' => 'textarea',
703        '#title' => t('Mail body'),        '#title' => t('Mail body'),
704        '#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.'),
705        '#default_value' => variable_get('advuser_modify_mail', ADVUSER_DEFAULT_MODIFY_MAIL),        '#default_value' => variable_get('advuser_modify_mail', ADVUSER_DEFAULT_MODIFY_MAIL),
706      );      );
707    
708                          $form['advuser_mail']['advuser_listno'] = array(      //Maximum rows in dataset to display
709        $form['advuser_mail']['advuser_listno'] = array(
710        '#type' => 'select',        '#type' => 'select',
711                                                  '#options' => drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)),        '#options' => drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)),
712        '#title' => t('Number of users in listing'),        '#title' => t('Number of users in listing'),
713        '#description' => t('Sets how many users to display in table view'),        '#description' => t('Sets how many users to display in table view'),
714        '#default_value' => variable_get('advuser_listno', ADVUSER_DEFAULT_LISTNO),        '#default_value' => variable_get('advuser_listno', ADVUSER_DEFAULT_LISTNO),
# Line 666  function advuser_settings() { Line 731  function advuser_settings() {
731    }    }
732    $form['advuser_mailonnew']['advuser_new_roles'] = array(    $form['advuser_mailonnew']['advuser_new_roles'] = array(
733        '#type' => 'checkboxes',        '#type' => 'checkboxes',
734        '#title' => t('Roles'),        '#title' => t('Notification Roles'),
735        '#description' => t('Roles that receive email notifications.'),        '#description' => t('Roles that receive email notifications.'),
736        '#options' => $roles,        '#options' => $roles,
737        '#default_value' => $values /*variable_get('advuser_new_roles', ADVUSER_DEFAULT_NEW_ROLES)*/,        '#default_value' => $values /*variable_get('advuser_new_roles', ADVUSER_DEFAULT_NEW_ROLES)*/,
# Line 678  function advuser_settings() { Line 743  function advuser_settings() {
743                '#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>');
744    }    }
745    
746    if ( module_exist('profile') ) {    if ( module_exists('profile') ) {
747      $form['advuser_profile'] = array(      $form['advuser_profile'] = array(
748          '#type' => 'fieldset',          '#type' => 'fieldset',
749          '#title' => t('Profile module special settings'),          '#title' => t('Profile module special settings'),
# Line 709  function advuser_settings() { Line 774  function advuser_settings() {
774        );        );
775    
776    }    }
777    return $form;    return system_settings_form($form);
778  }  }
779    
780  /**  /**
# Line 722  function _advuser_get_variables(&$user) Line 787  function _advuser_get_variables(&$user)
787      array(      array(
788            '%username' => $user->name,            '%username' => $user->name,
789            '%site' => variable_get("site_name", "drupal"),            '%site' => variable_get("site_name", "drupal"),
790            '%uri' => url('user/'.$user->uid, NULL, NULL, TRUE),            '%uri' => url('user/'. $user->uid, NULL, NULL, TRUE),
791            '%user_email' => $user->mail,            '%user_email' => $user->mail,
792            /* FUTURE: '%user_signature' => $user->signature, */            /* FUTURE: '%user_signature' => $user->signature, */
793            '%google_user'=> "http:/www.google.com/search?q=%22$user->mail%22",            '%google_user' => "http:/www.google.com/search?q=%22$user->mail%22",
794            '%yahoo_user'=> "http://search.yahoo.com/search/?p=%22$user->mail%22",            '%yahoo_user' => "http://search.yahoo.com/search/?p=%22$user->mail%22",
795            );            );
796    return $variables;    return $variables;
797  }  }
# Line 743  function _advuser_get_roles_query_fragme Line 808  function _advuser_get_roles_query_fragme
808        if ( $role_v > 0 ) {        if ( $role_v > 0 ) {
809          if ( $role_v == DRUPAL_AUTHENTICATED_RID ) {          if ( $role_v == DRUPAL_AUTHENTICATED_RID ) {
810            $role_where = ' OR 1';            $role_where = ' OR 1';
811          } else {          }
812             else {
813            $role_where = ' OR ur.rid = '. $role_v;            $role_where = ' OR ur.rid = '. $role_v;
814          }          }
815        }        }
# Line 754  function _advuser_get_roles_query_fragme Line 820  function _advuser_get_roles_query_fragme
820    
821  function _advuser_dbquery_users_to_notify($roles) {  function _advuser_dbquery_users_to_notify($roles) {
822    $role_where = _advuser_get_roles_query_fragment($roles);    $role_where = _advuser_get_roles_query_fragment($roles);
823    return db_query('SELECT u.mail, u.name FROM {users} u LEFT JOIN {users_roles} ur on u.uid = ur.uid WHERE 0 ' . $role_where );    return db_query('SELECT u.mail, u.name FROM {users} u LEFT JOIN {users_roles} ur on u.uid = ur.uid WHERE 0 '. $role_where );
824  }  }
825    
826    
# Line 780  function advuser_user_insert($edit, $use Line 846  function advuser_user_insert($edit, $use
846      $roles = variable_get('advuser_new_roles', ADVUSER_DEFAULT_NEW_ROLES);      $roles = variable_get('advuser_new_roles', ADVUSER_DEFAULT_NEW_ROLES);
847      $result = _advuser_dbquery_users_to_notify($roles);      $result = _advuser_dbquery_users_to_notify($roles);
848      while ($row = db_fetch_object($result)) {      while ($row = db_fetch_object($result)) {
849        user_mail($row->mail, $user_subject, $user_body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");        drupal_mail('advanced-user-mail', $row->mail, $user_subject, $user_body, $from);
850      }      }
851    }    }
852  }  }
# Line 810  function advuser_user_update($edit, $use Line 876  function advuser_user_update($edit, $use
876      $roles = variable_get('advuser_new_roles', ADVUSER_DEFAULT_NEW_ROLES);      $roles = variable_get('advuser_new_roles', ADVUSER_DEFAULT_NEW_ROLES);
877      $result = _advuser_dbquery_users_to_notify($roles);      $result = _advuser_dbquery_users_to_notify($roles);
878      while ($row = db_fetch_object($result)) {      while ($row = db_fetch_object($result)) {
879        //user_mail($row->mail, $user_subject, $user_body, ADVUSER_MAIL_MESSAGE_TEMPLATE);        drupal_mail('advanced-user-mail', $row->mail, $user_subject, $user_body, $from);
       user_mail($row->mail, $user_subject, $user_body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");  
880      }      }
881    }    }
882  }  }
# Line 831  function advuser_user($type, &$edit, &$u Line 896  function advuser_user($type, &$edit, &$u
896    //print $type;    //print $type;
897  }  }
898    
899  ?>  // vim:ft=php:et:sw=2:ts=2:sts=2:ai:sta

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.3