Index: og_mandatory_group.module =================================================================== --- og_mandatory_group.module (revision 300) +++ og_mandatory_group.module (revision 303) @@ -97,3 +97,47 @@ return $form; } } + +/** hook_menu **/ +function og_mandatory_group_menu($may_cache) { + $items = array(); + $items[] = array( + 'path' => 'admin/settings/og_mandatory_group/update_existing_users', + 'title' => t('update existing users'), + 'callback' => 'og_mandatory_group_update_existing_users_form', + 'access' => user_access('access administration pages'), + 'type' => MENU_NORMAL_ITEM, + ); + return $items; +} + +function og_mandatory_group_update_existing_users_form() { +// note,currently this does not email the group admin +$output = ''; + $form['desc1'] = array( + '#value' => t('Click Update to retro-actively place existing users into current mandatory groups.
+ Note, unchecking groups in og_mandatory_groups and then pressing Update will not + remove users from groups, so use this sparingly.
'), + ); + $form['submit'] = array('#type' => 'submit', '#value' => t('Update')); + + $output .= drupal_get_form('og_mandatory_group_update_existing_users_form',$form); + return $output; +} + +function og_mandatory_group_update_existing_users_form_submit() { + $output = ''; + $result = db_query("select uid from users where uid > 0"); + $count = db_num_rows($result); + $groups = variable_get('og_mandatory_group',array()); + while($user = db_fetch_array($result)){ + foreach($groups as $group){ + // og handles duplicates for us + og_save_subscription($group, $user['uid'], array('is_active' => 1)); + } + } + + drupal_set_message("$count users updated",'status'); + $output .= t("All existing users now belong to the current Mandatory Groups"); + print theme('page',$output); +} \ No newline at end of file