### Eclipse Workspace Patch 1.0 #P moodle Index: admin/user/user_bulk_forms.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/user/user_bulk_forms.php,v retrieving revision 1.1.2.3 diff -u -r1.1.2.3 user_bulk_forms.php --- admin/user/user_bulk_forms.php 20 Dec 2007 10:54:07 -0000 1.1.2.3 +++ admin/user/user_bulk_forms.php 25 Oct 2008 12:34:49 -0000 @@ -11,18 +11,9 @@ $syscontext = get_context_instance(CONTEXT_SYSTEM); $actions = array(0=>get_string('choose').'...'); - if (has_capability('moodle/user:update', $syscontext)) { - $actions[1] = get_string('confirm'); - } - if (has_capability('moodle/site:readallmessages', $syscontext) && !empty($CFG->messaging)) { - $actions[2] = get_string('messageselectadd'); - } - if (has_capability('moodle/user:delete', $syscontext)) { - $actions[3] = get_string('delete'); - } - $actions[4] = get_string('displayonpage'); - if (has_capability('moodle/user:update', $syscontext)) { - $actions[5] = get_string('download', 'admin'); + $plugins = get_list_of_plugins($CFG->admin.'/user/actions', 'CVS'); + foreach ($plugins as $dir) { + $actions[] = get_string('pluginname', 'bulkuseractions_'.$dir, NULL, $CFG->dirroot.'/admin/user/actions/'.$dir.'/lang/'); } $objs = array(); Index: admin/user/user_message_form.php =================================================================== RCS file: admin/user/user_message_form.php diff -N admin/user/user_message_form.php --- admin/user/user_message_form.php 13 Nov 2007 09:02:12 -0000 1.2.2.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,20 +0,0 @@ -libdir.'/formslib.php'); - -class user_message_form extends moodleform { - - function definition() { - $mform =& $this->_form; - $mform->addElement('header', 'general', get_string('message', 'message')); - - - $mform->addElement('textarea', 'messagebody', get_string('messagebody'), array('rows'=>15, 'cols'=>60)); - $mform->addRule('messagebody', '', 'required', null, 'client'); - $mform->setHelpButton('messagebody', array('writing', 'reading', 'questions', 'richtext'), false, 'editorhelpbutton'); - $mform->addElement('format', 'format', get_string('format')); - - $this->add_action_buttons(); - } -} -?> \ No newline at end of file Index: admin/user/user_bulk_message.php =================================================================== RCS file: admin/user/user_bulk_message.php diff -N admin/user/user_bulk_message.php --- admin/user/user_bulk_message.php 13 Nov 2007 09:02:12 -0000 1.2.2.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,71 +0,0 @@ -libdir.'/adminlib.php'); -require_once($CFG->dirroot.'/message/lib.php'); -require_once('user_message_form.php'); - -$msg = optional_param('msg', '', PARAM_CLEAN); -$confirm = optional_param('confirm', 0, PARAM_BOOL); - -admin_externalpage_setup('userbulk'); -require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM)); - -$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; - -if (empty($SESSION->bulk_users)) { - redirect($return); -} - -if (empty($CFG->messaging)) { - error("Messaging is disabled on this site"); -} - -//TODO: add support for large number of users - -if ($confirm and !empty($msg) and confirm_sesskey()) { - $in = implode(',', $SESSION->bulk_users); - if ($rs = get_recordset_select('user', "id IN ($in)")) { - while ($user = rs_fetch_next_record($rs)) { - message_post_message($USER, $user, $msg, FORMAT_HTML, 'direct'); - } - } - redirect($return); -} - -// disable html editor if not enabled in preferences -if (!get_user_preferences('message_usehtmleditor', 0)) { - $CFG->htmleditor = ''; -} - -$msgform = new user_message_form('user_bulk_message.php'); - -if ($msgform->is_cancelled()) { - redirect($return); - -} else if ($formdata = $msgform->get_data(false)) { - $options = new object(); - $options->para = false; - $options->newlines = true; - $options->smiley = false; - - $msg = format_text($formdata->messagebody, $formdata->format, $options); - - $in = implode(',', $SESSION->bulk_users); - $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname'); - $usernames = implode(', ', $userlist); - $optionsyes = array(); - $optionsyes['confirm'] = 1; - $optionsyes['sesskey'] = sesskey(); - $optionsyes['msg'] = $msg; - admin_externalpage_print_header(); - print_heading(get_string('confirmation', 'admin')); - print_box($msg, 'boxwidthnarrow boxaligncenter generalbox', 'preview'); - notice_yesno(get_string('confirmmessage', 'bulkusers', $usernames), 'user_bulk_message.php', 'user_bulk.php', $optionsyes, NULL, 'post', 'get'); - admin_externalpage_print_footer(); - die; -} - -admin_externalpage_print_header(); -$msgform->display(); -admin_externalpage_print_footer(); -?> \ No newline at end of file Index: admin/user/user_bulk_delete.php =================================================================== RCS file: admin/user/user_bulk_delete.php diff -N admin/user/user_bulk_delete.php --- admin/user/user_bulk_delete.php 13 Nov 2007 09:02:12 -0000 1.3.2.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,52 +0,0 @@ -libdir.'/adminlib.php'); - -$confirm = optional_param('confirm', 0, PARAM_BOOL); - -admin_externalpage_setup('userbulk'); -require_capability('moodle/user:delete', get_context_instance(CONTEXT_SYSTEM)); - -$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; - -if (empty($SESSION->bulk_users)) { - redirect($return); -} - -admin_externalpage_print_header(); - -//TODO: add support for large number of users - -if ($confirm and confirm_sesskey()) { - $primaryadmin = get_admin(); - - $in = implode(',', $SESSION->bulk_users); - if ($rs = get_recordset_select('user', "id IN ($in)")) { - while ($user = rs_fetch_next_record($rs)) { - if ($primaryadmin->id != $user->id and $USER->id != $user->id and delete_user($user)) { - unset($SESSION->bulk_users[$user->id]); - } else { - notify(get_string('deletednot', '', fullname($user, true))); - } - } - rs_close($rs); - } - redirect($return, get_string('changessaved')); - -} else { - $in = implode(',', $SESSION->bulk_users); - $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname'); - $usernames = implode(', ', $userlist); - $optionsyes = array(); - $optionsyes['confirm'] = 1; - $optionsyes['sesskey'] = sesskey(); - print_heading(get_string('confirmation', 'admin')); - notice_yesno(get_string('deletecheckfull', '', $usernames), 'user_bulk_delete.php', 'user_bulk.php', $optionsyes, NULL, 'post', 'get'); -} - -admin_externalpage_print_footer(); -?> Index: admin/user/user_bulk.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/user/user_bulk.php,v retrieving revision 1.4.2.4 diff -u -r1.4.2.4 user_bulk.php --- admin/user/user_bulk.php 5 Feb 2008 15:22:08 -0000 1.4.2.4 +++ admin/user/user_bulk.php 25 Oct 2008 12:34:49 -0000 @@ -17,13 +17,11 @@ // create the bulk operations form $action_form = new user_bulk_action_form(); if ($data = $action_form->get_data(false)) { - // check if an action should be performed and do so - switch ($data->action) { - case 1: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_confirm.php'); - case 2: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_message.php'); - case 3: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_delete.php'); - case 4: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_display.php'); - case 5: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_download.php'); + // check if an action should be performed and do so using plugin list + if ($data->action) { + $plugins = get_list_of_plugins($CFG->admin.'/user/actions', 'CVS'); + sort($plugins); + redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/actions/'.$plugins[$data->action - 1].'/index.php'); } } Index: admin/user/user_bulk_display.php =================================================================== RCS file: admin/user/user_bulk_display.php diff -N admin/user/user_bulk_display.php --- admin/user/user_bulk_display.php 13 Nov 2007 09:02:12 -0000 1.1.2.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,81 +0,0 @@ -libdir.'/adminlib.php'); - -$sort = optional_param('sort', 'fullname', PARAM_ALPHA); -$dir = optional_param('dir', 'asc', PARAM_ALPHA); - -admin_externalpage_setup('userbulk'); - -$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; - -if (empty($SESSION->bulk_users)) { - redirect($return); -} - -$users = $SESSION->bulk_users; -$usertotal = get_users(false); -$usercount = count($users); - -$strnever = get_string('never'); - -admin_externalpage_print_header(); - -$countries = get_list_of_countries(); - -foreach ($users as $key => $id) { - $user = get_record('user', 'id', $id, null, null, null, null, 'id, firstname, lastname, username, email, country, lastaccess, city'); - $user->fullname = fullname($user, true); - $user->country = @$countries[$user->country]; - unset($user->firstname); - unset($user->lastname); - $users[$key] = $user; -} -unset($countries); - -// Need to sort by date -function sort_compare($a, $b) { - global $sort, $dir; - if($sort == 'lastaccess') { - $rez = $b->lastaccess - $a->lastaccess; - } else { - $rez = strcasecmp(@$a->$sort, @$b->$sort); - } - return $dir == 'desc' ? -$rez : $rez; -} -usort($users, 'sort_compare'); - -$table->width = "95%"; -$columns = array('fullname', /*'username', */'email', 'city', 'country', 'lastaccess'); -foreach ($columns as $column) { - $strtitle = get_string($column); - if ($sort != $column) { - $columnicon = ''; - $columndir = 'asc'; - } else { - $columndir = $dir == 'asc' ? 'desc' : 'asc'; - $columnicon = ' '; - } - $table->head[] = ''.$strtitle.''.$columnicon; - $table->align[] = 'left'; -} - -foreach($users as $user) { - $table->data[] = array ( - ''.$user->fullname.'', -// $user->username, - $user->email, - $user->city, - $user->country, - $user->lastaccess ? format_time(time() - $user->lastaccess) : $strnever - ); -} - -print_heading("$usercount / $usertotal ".get_string('users')); -print_table($table); - -print_continue($return); - -admin_externalpage_print_footer(); -?> \ No newline at end of file Index: admin/user/user_bulk_confirm.php =================================================================== RCS file: admin/user/user_bulk_confirm.php diff -N admin/user/user_bulk_confirm.php --- admin/user/user_bulk_confirm.php 13 Nov 2007 09:02:12 -0000 1.3.2.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,53 +0,0 @@ -libdir.'/adminlib.php'); - -$confirm = optional_param('confirm', 0, PARAM_BOOL); - -admin_externalpage_setup('userbulk'); -require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM)); - -$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; - -if (empty($SESSION->bulk_users)) { - redirect($return); -} - -admin_externalpage_print_header(); - -//TODO: add support for large number of users - -if ($confirm and confirm_sesskey()) { - $in = implode(',', $SESSION->bulk_users); - if ($rs = get_recordset_select('user', "id IN ($in)", '', 'id, username, secret, confirmed, auth, firstname, lastname')) { - while ($user = rs_fetch_next_record($rs)) { - if ($user->confirmed) { - continue; - } - $auth = get_auth_plugin($user->auth); - $result = $auth->user_confirm(addslashes($user->username), addslashes($user->secret)); - if ($result != AUTH_CONFIRM_OK && $result != AUTH_CONFIRM_ALREADY) { - notify(get_string('usernotconfirmed', '', fullname($user, true))); - } - } - rs_close($rs); - } - redirect($return, get_string('changessaved')); - -} else { - $in = implode(',', $SESSION->bulk_users); - $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname'); - $usernames = implode(', ', $userlist); - $optionsyes = array(); - $optionsyes['confirm'] = 1; - $optionsyes['sesskey'] = sesskey(); - print_heading(get_string('confirmation', 'admin')); - notice_yesno(get_string('confirmcheckfull', '', $usernames), 'user_bulk_confirm.php', 'user_bulk.php', $optionsyes, NULL, 'post', 'get'); -} - -admin_externalpage_print_footer(); -?> \ No newline at end of file Index: admin/user/user_bulk_download.php =================================================================== RCS file: admin/user/user_bulk_download.php diff -N admin/user/user_bulk_download.php --- admin/user/user_bulk_download.php 22 Oct 2008 01:32:22 -0000 1.1.2.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,182 +0,0 @@ -libdir.'/adminlib.php'); - -$format = optional_param('format', '', PARAM_ALPHA); - -admin_externalpage_setup('userbulk'); -require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM)); - -$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; - -if (empty($SESSION->bulk_users)) { - redirect($return); -} - -if ($format) { - $fields = array('id' => 'id', - 'username' => 'username', - 'email' => 'email', - 'firstname' => 'firstname', - 'lastname' => 'lastname', - 'idnumber' => 'idnumber', - 'institution' => 'institution', - 'department' => 'department', - 'phone1' => 'phone1', - 'phone2' => 'phone2', - 'city' => 'city', - 'url' => 'url', - 'icq' => 'icq', - 'skype' => 'skype', - 'aim' => 'aim', - 'yahoo' => 'yahoo', - 'msn' => 'msn', - 'country' => 'country'); - - if ($extrafields = get_records_select('user_info_field')) { - foreach ($extrafields as $n=>$v){ - $fields['profile_field_'.$v->shortname] = 'profile_field_'.$v->shortname; - } - } - - switch ($format) { - case 'csv' : user_download_csv($fields); - case 'ods' : user_download_ods($fields); - case 'xls' : user_download_xls($fields); - - } - die; -} - -admin_externalpage_print_header(); -print_heading(get_string('download', 'admin')); - -print_box_start(); -echo ''; -print_box_end(); - -print_continue($return); - -print_footer(); - -function user_download_ods($fields) { - global $CFG, $SESSION; - - require_once("$CFG->libdir/odslib.class.php"); - require_once($CFG->dirroot.'/user/profile/lib.php'); - - $filename = clean_filename(get_string('users').'.ods'); - - $workbook = new MoodleODSWorkbook('-'); - $workbook->send($filename); - - $worksheet = array(); - - $worksheet[0] =& $workbook->add_worksheet(''); - $col = 0; - foreach ($fields as $fieldname) { - $worksheet[0]->write(0, $col, $fieldname); - $col++; - } - - $row = 1; - foreach ($SESSION->bulk_users as $userid) { - if (!$user = get_record('user', 'id', $userid)) { - continue; - } - $col = 0; - profile_load_data($user); - foreach ($fields as $field=>$unused) { - $worksheet[0]->write($row, $col, $user->$field); - $col++; - } - $row++; - } - - $workbook->close(); - die; -} - -function user_download_xls($fields) { - global $CFG, $SESSION; - - require_once("$CFG->libdir/excellib.class.php"); - require_once($CFG->dirroot.'/user/profile/lib.php'); - - $filename = clean_filename(get_string('users').'.xls'); - - $workbook = new MoodleExcelWorkbook('-'); - $workbook->send($filename); - - $worksheet = array(); - - $worksheet[0] =& $workbook->add_worksheet(''); - $col = 0; - foreach ($fields as $fieldname) { - $worksheet[0]->write(0, $col, $fieldname); - $col++; - } - - $row = 1; - foreach ($SESSION->bulk_users as $userid) { - if (!$user = get_record('user', 'id', $userid)) { - continue; - } - $col = 0; - profile_load_data($user); - foreach ($fields as $field=>$unused) { - $worksheet[0]->write($row, $col, $user->$field); - $col++; - } - $row++; - } - - $workbook->close(); - die; -} - -function user_download_csv($fields) { - global $CFG, $SESSION; - - require_once($CFG->dirroot.'/user/profile/lib.php'); - - $filename = clean_filename(get_string('users').'.csv'); - - header("Content-Type: application/download\n"); - header("Content-Disposition: attachment; filename=$filename"); - header("Expires: 0"); - header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); - header("Pragma: public"); - - $delimiter = get_string('listsep'); - $encdelim = '&#'.ord($delimiter); - - $row = array(); - foreach ($fields as $fieldname) { - $row[] = str_replace($delimiter, $encdelim, $fieldname); - } - echo implode($delimiter, $row)."\n"; - - foreach ($SESSION->bulk_users as $userid) { - $row = array(); - if (!$user = get_record('user', 'id', $userid)) { - continue; - } - profile_load_data($user); - foreach ($fields as $field=>$unused) { - $row[] = str_replace($delimiter, $encdelim, $user->$field); - } - echo implode($delimiter, $row)."\n"; - } - die; -} - -?> Index: admin/user/actions/removefromcourses/lang/en_utf8/bulkuseractions_removefromcourses.php =================================================================== RCS file: admin/user/actions/removefromcourses/lang/en_utf8/bulkuseractions_removefromcourses.php diff -N admin/user/actions/removefromcourses/lang/en_utf8/bulkuseractions_removefromcourses.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/removefromcourses/lang/en_utf8/bulkuseractions_removefromcourses.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,12 @@ +'; +$string['confirmpart2'] = '
from courses:
'; +$string['removeall'] = 'Remove all from selection'; + +?> Index: admin/user/actions/message/version.php =================================================================== RCS file: admin/user/actions/message/version.php diff -N admin/user/actions/message/version.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/message/version.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +version = 2007111300; +$plugin->requires = 2007111300; + +?> Index: admin/user/actions/message/lang/ru_utf8/bulkuseractions_message.php =================================================================== RCS file: admin/user/actions/message/lang/ru_utf8/bulkuseractions_message.php diff -N admin/user/actions/message/lang/ru_utf8/bulkuseractions_message.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/message/lang/ru_utf8/bulkuseractions_message.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ + Index: admin/user/actions/enroltocourses/version.php =================================================================== RCS file: admin/user/actions/enroltocourses/version.php diff -N admin/user/actions/enroltocourses/version.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/enroltocourses/version.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +version = 2008101800; +$plugin->requires = 2008101800; + +?> Index: admin/user/actions/delete/index.php =================================================================== RCS file: admin/user/actions/delete/index.php diff -N admin/user/actions/delete/index.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/delete/index.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,52 @@ +libdir.'/adminlib.php'); + +$confirm = optional_param('confirm', 0, PARAM_BOOL); + +admin_externalpage_setup('userbulk'); +require_capability('moodle/user:delete', get_context_instance(CONTEXT_SYSTEM)); + +$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; + +if (empty($SESSION->bulk_users)) { + redirect($return); +} + +admin_externalpage_print_header(); + +//TODO: add support for large number of users + +if ($confirm and confirm_sesskey()) { + $primaryadmin = get_admin(); + + $in = implode(',', $SESSION->bulk_users); + if ($rs = get_recordset_select('user', "id IN ($in)")) { + while ($user = rs_fetch_next_record($rs)) { + if ($primaryadmin->id != $user->id and $USER->id != $user->id and delete_user($user)) { + unset($SESSION->bulk_users[$user->id]); + } else { + notify(get_string('deletednot', '', fullname($user, true))); + } + } + rs_close($rs); + } + redirect($return, get_string('changessaved')); + +} else { + $in = implode(',', $SESSION->bulk_users); + $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname'); + $usernames = implode(', ', $userlist); + $optionsyes = array(); + $optionsyes['confirm'] = 1; + $optionsyes['sesskey'] = sesskey(); + print_heading(get_string('confirmation', 'admin')); + notice_yesno(get_string('deletecheckfull', '', $usernames), 'index.php', $return, $optionsyes, NULL, 'post', 'get'); +} + +admin_externalpage_print_footer(); +?> Index: admin/user/actions/enroltocourses/lang/ru_utf8/bulkuseractions_enroltocourses.php =================================================================== RCS file: admin/user/actions/enroltocourses/lang/ru_utf8/bulkuseractions_enroltocourses.php diff -N admin/user/actions/enroltocourses/lang/ru_utf8/bulkuseractions_enroltocourses.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/enroltocourses/lang/ru_utf8/bulkuseractions_enroltocourses.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,18 @@ +'; +$string['default'] = 'По умолчанию'; +$string['accept'] = 'Принять'; +$string['autogroup'] = 'Автоматически
добавлять в группу'; +$string['nogroup'] = 'Не добавлять'; +$string['confirmpart1'] = 'Вы уверены, что хотите записать пользователей:
'; +$string['confirmpart2'] = '
на курсы:
'; +$string['confirmpart3'] = '
и добавить их в соответствующие группы '; +$string['confirmpart4'] = '
с ролью '; +$string['removeall'] = 'Удалить все из выбранных'; + +?> Index: admin/user/actions/enroltocourses/lang/en_utf8/bulkuseractions_enroltocourses.php =================================================================== RCS file: admin/user/actions/enroltocourses/lang/en_utf8/bulkuseractions_enroltocourses.php diff -N admin/user/actions/enroltocourses/lang/en_utf8/bulkuseractions_enroltocourses.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/enroltocourses/lang/en_utf8/bulkuseractions_enroltocourses.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,18 @@ +'; +$string['default'] = 'Course default'; +$string['accept'] = 'Accept'; +$string['autogroup'] = 'Automatically
add to group'; +$string['nogroup'] = 'Do not add'; +$string['confirmpart1'] = 'Are you sure you want to enrol users:
'; +$string['confirmpart2'] = '
on courses:
'; +$string['confirmpart3'] = '
and add them in corresponding groups '; +$string['confirmpart4'] = '
with role of '; +$string['removeall'] = 'Remove all from selection'; + +?> Index: admin/user/actions/display/index.php =================================================================== RCS file: admin/user/actions/display/index.php diff -N admin/user/actions/display/index.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/display/index.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,81 @@ +libdir.'/adminlib.php'); + +$sort = optional_param('sort', 'fullname', PARAM_ALPHA); +$dir = optional_param('dir', 'asc', PARAM_ALPHA); + +admin_externalpage_setup('userbulk'); + +$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; + +if (empty($SESSION->bulk_users)) { + redirect($return); +} + +$users = $SESSION->bulk_users; +$usertotal = get_users(false); +$usercount = count($users); + +$strnever = get_string('never'); + +admin_externalpage_print_header(); + +$countries = get_list_of_countries(); + +foreach ($users as $key => $id) { + $user = get_record('user', 'id', $id, null, null, null, null, 'id, firstname, lastname, username, email, country, lastaccess, city'); + $user->fullname = fullname($user, true); + $user->country = @$countries[$user->country]; + unset($user->firstname); + unset($user->lastname); + $users[$key] = $user; +} +unset($countries); + +// Need to sort by date +function sort_compare($a, $b) { + global $sort, $dir; + if($sort == 'lastaccess') { + $rez = $b->lastaccess - $a->lastaccess; + } else { + $rez = strcasecmp(@$a->$sort, @$b->$sort); + } + return $dir == 'desc' ? -$rez : $rez; +} +usort($users, 'sort_compare'); + +$table->width = "95%"; +$columns = array('fullname', /*'username', */'email', 'city', 'country', 'lastaccess'); +foreach ($columns as $column) { + $strtitle = get_string($column); + if ($sort != $column) { + $columnicon = ''; + $columndir = 'asc'; + } else { + $columndir = $dir == 'asc' ? 'desc' : 'asc'; + $columnicon = ' '; + } + $table->head[] = ''.$strtitle.''.$columnicon; + $table->align[] = 'left'; +} + +foreach($users as $user) { + $table->data[] = array ( + ''.$user->fullname.'', +// $user->username, + $user->email, + $user->city, + $user->country, + $user->lastaccess ? format_time(time() - $user->lastaccess) : $strnever + ); +} + +print_heading("$usercount / $usertotal ".get_string('users')); +print_table($table); + +print_continue($return); + +admin_externalpage_print_footer(); +?> Index: admin/user/actions/download/lang/ru_utf8/bulkuseractions_download.php =================================================================== RCS file: admin/user/actions/download/lang/ru_utf8/bulkuseractions_download.php diff -N admin/user/actions/download/lang/ru_utf8/bulkuseractions_download.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/download/lang/ru_utf8/bulkuseractions_download.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ + Index: admin/user/actions/emailactive/version.php =================================================================== RCS file: admin/user/actions/emailactive/version.php diff -N admin/user/actions/emailactive/version.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/emailactive/version.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +version = 2008100400; +$plugin->requires = 2008100400; + +?> Index: admin/user/actions/message/user_message_form.php =================================================================== RCS file: admin/user/actions/message/user_message_form.php diff -N admin/user/actions/message/user_message_form.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/message/user_message_form.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,20 @@ +libdir.'/formslib.php'); + +class user_message_form extends moodleform { + + function definition() { + $mform =& $this->_form; + $mform->addElement('header', 'general', get_string('message', 'message')); + + + $mform->addElement('textarea', 'messagebody', get_string('messagebody'), array('rows'=>15, 'cols'=>60)); + $mform->addRule('messagebody', '', 'required', null, 'client'); + $mform->setHelpButton('messagebody', array('writing', 'reading', 'questions', 'richtext'), false, 'editorhelpbutton'); + $mform->addElement('format', 'format', get_string('format')); + + $this->add_action_buttons(); + } +} +?> Index: admin/user/actions/message/index.php =================================================================== RCS file: admin/user/actions/message/index.php diff -N admin/user/actions/message/index.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/message/index.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,71 @@ +libdir.'/adminlib.php'); +require_once($CFG->dirroot.'/message/lib.php'); +require_once('user_message_form.php'); + +$msg = optional_param('msg', '', PARAM_CLEAN); +$confirm = optional_param('confirm', 0, PARAM_BOOL); + +admin_externalpage_setup('userbulk'); +require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM)); + +$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; + +if (empty($SESSION->bulk_users)) { + redirect($return); +} + +if (empty($CFG->messaging)) { + error("Messaging is disabled on this site"); +} + +//TODO: add support for large number of users + +if ($confirm and !empty($msg) and confirm_sesskey()) { + $in = implode(',', $SESSION->bulk_users); + if ($rs = get_recordset_select('user', "id IN ($in)")) { + while ($user = rs_fetch_next_record($rs)) { + message_post_message($USER, $user, $msg, FORMAT_HTML, 'direct'); + } + } + redirect($return); +} + +// disable html editor if not enabled in preferences +if (!get_user_preferences('message_usehtmleditor', 0)) { + $CFG->htmleditor = ''; +} + +$msgform = new user_message_form('index.php'); + +if ($msgform->is_cancelled()) { + redirect($return); + +} else if ($formdata = $msgform->get_data(false)) { + $options = new object(); + $options->para = false; + $options->newlines = true; + $options->smiley = false; + + $msg = format_text($formdata->messagebody, $formdata->format, $options); + + $in = implode(',', $SESSION->bulk_users); + $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname'); + $usernames = implode(', ', $userlist); + $optionsyes = array(); + $optionsyes['confirm'] = 1; + $optionsyes['sesskey'] = sesskey(); + $optionsyes['msg'] = $msg; + admin_externalpage_print_header(); + print_heading(get_string('confirmation', 'admin')); + print_box($msg, 'boxwidthnarrow boxaligncenter generalbox', 'preview'); + notice_yesno(get_string('confirmmessage', 'bulkusers', $usernames), 'index.php', $return, $optionsyes, NULL, 'post', 'get'); + admin_externalpage_print_footer(); + die; +} + +admin_externalpage_print_header(); +$msgform->display(); +admin_externalpage_print_footer(); +?> Index: admin/user/actions/confirm/index.php =================================================================== RCS file: admin/user/actions/confirm/index.php diff -N admin/user/actions/confirm/index.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/confirm/index.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,53 @@ +libdir.'/adminlib.php'); + +$confirm = optional_param('confirm', 0, PARAM_BOOL); + +admin_externalpage_setup('userbulk'); +require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM)); + +$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; + +if (empty($SESSION->bulk_users)) { + redirect($return); +} + +admin_externalpage_print_header(); + +//TODO: add support for large number of users + +if ($confirm and confirm_sesskey()) { + $in = implode(',', $SESSION->bulk_users); + if ($rs = get_recordset_select('user', "id IN ($in)", '', 'id, username, secret, confirmed, auth, firstname, lastname')) { + while ($user = rs_fetch_next_record($rs)) { + if ($user->confirmed) { + continue; + } + $auth = get_auth_plugin($user->auth); + $result = $auth->user_confirm(addslashes($user->username), addslashes($user->secret)); + if ($result != AUTH_CONFIRM_OK && $result != AUTH_CONFIRM_ALREADY) { + notify(get_string('usernotconfirmed', '', fullname($user, true))); + } + } + rs_close($rs); + } + redirect($return, get_string('changessaved')); + +} else { + $in = implode(',', $SESSION->bulk_users); + $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname'); + $usernames = implode(', ', $userlist); + $optionsyes = array(); + $optionsyes['confirm'] = 1; + $optionsyes['sesskey'] = sesskey(); + print_heading(get_string('confirmation', 'admin')); + notice_yesno(get_string('confirmcheckfull', '', $usernames), 'index.php', $return, $optionsyes, NULL, 'post', 'get'); +} + +admin_externalpage_print_footer(); +?> Index: admin/user/actions/removefromcourses/version.php =================================================================== RCS file: admin/user/actions/removefromcourses/version.php diff -N admin/user/actions/removefromcourses/version.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/removefromcourses/version.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +version = 2008101800; +$plugin->requires = 2008101800; + +?> Index: admin/user/actions/message/lang/en_utf8/bulkuseractions_message.php =================================================================== RCS file: admin/user/actions/message/lang/en_utf8/bulkuseractions_message.php diff -N admin/user/actions/message/lang/en_utf8/bulkuseractions_message.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/message/lang/en_utf8/bulkuseractions_message.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ + Index: admin/user/actions/delete/lang/ru_utf8/bulkuseractions_delete.php =================================================================== RCS file: admin/user/actions/delete/lang/ru_utf8/bulkuseractions_delete.php diff -N admin/user/actions/delete/lang/ru_utf8/bulkuseractions_delete.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/delete/lang/ru_utf8/bulkuseractions_delete.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ + Index: admin/user/actions/download/version.php =================================================================== RCS file: admin/user/actions/download/version.php diff -N admin/user/actions/download/version.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/download/version.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +version = 2008042300; +$plugin->requires = 2008042300; + +?> Index: admin/user/actions/display/version.php =================================================================== RCS file: admin/user/actions/display/version.php diff -N admin/user/actions/display/version.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/display/version.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +version = 2007111300; +$plugin->requires = 2007111300; + +?> Index: admin/user/actions/confirm/lang/ru_utf8/bulkuseractions_confirm.php =================================================================== RCS file: admin/user/actions/confirm/lang/ru_utf8/bulkuseractions_confirm.php diff -N admin/user/actions/confirm/lang/ru_utf8/bulkuseractions_confirm.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/confirm/lang/ru_utf8/bulkuseractions_confirm.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ + Index: admin/user/actions/delete/lang/en_utf8/bulkuseractions_delete.php =================================================================== RCS file: admin/user/actions/delete/lang/en_utf8/bulkuseractions_delete.php diff -N admin/user/actions/delete/lang/en_utf8/bulkuseractions_delete.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/delete/lang/en_utf8/bulkuseractions_delete.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ + Index: admin/user/actions/emailactive/lang/ru_utf8/bulkuseractions_emailactive.php =================================================================== RCS file: admin/user/actions/emailactive/lang/ru_utf8/bulkuseractions_emailactive.php diff -N admin/user/actions/emailactive/lang/ru_utf8/bulkuseractions_emailactive.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/emailactive/lang/ru_utf8/bulkuseractions_emailactive.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,9 @@ + Index: admin/user/actions/download/index.php =================================================================== RCS file: admin/user/actions/download/index.php diff -N admin/user/actions/download/index.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/download/index.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,182 @@ +libdir.'/adminlib.php'); + +$format = optional_param('format', '', PARAM_ALPHA); + +admin_externalpage_setup('userbulk'); +require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM)); + +$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; + +if (empty($SESSION->bulk_users)) { + redirect($return); +} + +if ($format) { + $fields = array('id' => 'id', + 'username' => 'username', + 'email' => 'email', + 'firstname' => 'firstname', + 'lastname' => 'lastname', + 'idnumber' => 'idnumber', + 'institution' => 'institution', + 'department' => 'department', + 'phone1' => 'phone1', + 'phone2' => 'phone2', + 'city' => 'city', + 'url' => 'url', + 'icq' => 'icq', + 'skype' => 'skype', + 'aim' => 'aim', + 'yahoo' => 'yahoo', + 'msn' => 'msn', + 'country' => 'country'); + + if ($extrafields = get_records_select('user_info_field')) { + foreach ($extrafields as $n=>$v){ + $fields['profile_field_'.$v->shortname] = 'profile_field_'.$v->shortname; + } + } + + switch ($format) { + case 'csv' : user_download_csv($fields); + case 'ods' : user_download_ods($fields); + case 'xls' : user_download_xls($fields); + + } + die; +} + +admin_externalpage_print_header(); +print_heading(get_string('download', 'admin')); + +print_box_start(); +echo ''; +print_box_end(); + +print_continue($return); + +print_footer(); + +function user_download_ods($fields) { + global $CFG, $SESSION; + + require_once("$CFG->libdir/odslib.class.php"); + require_once($CFG->dirroot.'/user/profile/lib.php'); + + $filename = clean_filename(get_string('users').'.ods'); + + $workbook = new MoodleODSWorkbook('-'); + $workbook->send($filename); + + $worksheet = array(); + + $worksheet[0] =& $workbook->add_worksheet(''); + $col = 0; + foreach ($fields as $fieldname) { + $worksheet[0]->write(0, $col, $fieldname); + $col++; + } + + $row = 1; + foreach ($SESSION->bulk_users as $userid) { + if (!$user = get_record('user', 'id', $userid)) { + continue; + } + $col = 0; + profile_load_data($user); + foreach ($fields as $field=>$unused) { + $worksheet[0]->write($row, $col, $user->$field); + $col++; + } + $row++; + } + + $workbook->close(); + die; +} + +function user_download_xls($fields) { + global $CFG, $SESSION; + + require_once("$CFG->libdir/excellib.class.php"); + require_once($CFG->dirroot.'/user/profile/lib.php'); + + $filename = clean_filename(get_string('users').'.xls'); + + $workbook = new MoodleExcelWorkbook('-'); + $workbook->send($filename); + + $worksheet = array(); + + $worksheet[0] =& $workbook->add_worksheet(''); + $col = 0; + foreach ($fields as $fieldname) { + $worksheet[0]->write(0, $col, $fieldname); + $col++; + } + + $row = 1; + foreach ($SESSION->bulk_users as $userid) { + if (!$user = get_record('user', 'id', $userid)) { + continue; + } + $col = 0; + profile_load_data($user); + foreach ($fields as $field=>$unused) { + $worksheet[0]->write($row, $col, $user->$field); + $col++; + } + $row++; + } + + $workbook->close(); + die; +} + +function user_download_csv($fields) { + global $CFG, $SESSION; + + require_once($CFG->dirroot.'/user/profile/lib.php'); + + $filename = clean_filename(get_string('users').'.csv'); + + header("Content-Type: application/download\n"); + header("Content-Disposition: attachment; filename=$filename"); + header("Expires: 0"); + header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); + header("Pragma: public"); + + $delimiter = get_string('listsep'); + $encdelim = '&#'.ord($delimiter); + + $row = array(); + foreach ($fields as $fieldname) { + $row[] = str_replace($delimiter, $encdelim, $fieldname); + } + echo implode($delimiter, $row)."\n"; + + foreach ($SESSION->bulk_users as $userid) { + $row = array(); + if (!$user = get_record('user', 'id', $userid)) { + continue; + } + profile_load_data($user); + foreach ($fields as $field=>$unused) { + $row[] = str_replace($delimiter, $encdelim, $user->$field); + } + echo implode($delimiter, $row)."\n"; + } + die; +} + +?> Index: admin/user/actions/download/lang/en_utf8/bulkuseractions_download.php =================================================================== RCS file: admin/user/actions/download/lang/en_utf8/bulkuseractions_download.php diff -N admin/user/actions/download/lang/en_utf8/bulkuseractions_download.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/download/lang/en_utf8/bulkuseractions_download.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ + Index: admin/user/actions/display/lang/en_utf8/bulkuseractions_display.php =================================================================== RCS file: admin/user/actions/display/lang/en_utf8/bulkuseractions_display.php diff -N admin/user/actions/display/lang/en_utf8/bulkuseractions_display.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/display/lang/en_utf8/bulkuseractions_display.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ + Index: admin/user/actions/display/lang/ru_utf8/bulkuseractions_display.php =================================================================== RCS file: admin/user/actions/display/lang/ru_utf8/bulkuseractions_display.php diff -N admin/user/actions/display/lang/ru_utf8/bulkuseractions_display.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/display/lang/ru_utf8/bulkuseractions_display.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ + Index: admin/user/actions/removefromcourses/lang/ru_utf8/bulkuseractions_removefromcourses.php =================================================================== RCS file: admin/user/actions/removefromcourses/lang/ru_utf8/bulkuseractions_removefromcourses.php diff -N admin/user/actions/removefromcourses/lang/ru_utf8/bulkuseractions_removefromcourses.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/removefromcourses/lang/ru_utf8/bulkuseractions_removefromcourses.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,12 @@ +'; +$string['confirmpart2'] = '
с курсов:
'; +$string['removeall'] = 'Удалить все из выбранных'; + +?> Index: admin/user/actions/removefromcourses/index.php =================================================================== RCS file: admin/user/actions/removefromcourses/index.php diff -N admin/user/actions/removefromcourses/index.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/removefromcourses/index.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,244 @@ +libdir.'/adminlib.php'); + +$allcourses = optional_param('allcourses', '', PARAM_CLEAN); +$selcourses = optional_param('selcourses', '', PARAM_CLEAN); +$accept = optional_param('accept', 0, PARAM_BOOL); +$confirm = optional_param('confirm', 0, PARAM_BOOL); +$cancel = optional_param('cancel', 0, PARAM_BOOL); +$searchtext = optional_param('searchtext', '', PARAM_RAW); +$showall = optional_param('showall', 0, PARAM_BOOL); +$listadd = optional_param('add', 0, PARAM_BOOL); +$listremove = optional_param('remove', 0, PARAM_BOOL); +$removeall = optional_param('removeall', 0, PARAM_BOOL); + +admin_externalpage_setup('userbulk'); + +$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; + +if ($showall) { + $searchtext = ''; +} + +$strsearch = get_string('search'); +$langdir = $CFG->dirroot.'/admin/user/actions/removefromcourses/lang/'; +$pluginname = 'bulkuseractions_removefromcourses'; + +if (empty($SESSION->bulk_users) || $cancel) { + redirect($return); +} + +if (!isset($SESSION->bulk_courses) || $removeall) + $SESSION->bulk_courses = array(); + +// course selection add/remove actions +if ($listadd && !empty($allcourses)) { + foreach ($allcourses as $course) { + if (!in_array( $course, $SESSION->bulk_courses )) { + $SESSION->bulk_courses[] = $course; + } + } +} + +if ($listremove && !empty($selcourses)) { + foreach ($selcourses as $course) { + unset($SESSION->bulk_courses[ array_search($course, $SESSION->bulk_courses) ]); + } +} + +// show the confirmation message +if( $accept ) { + if( empty( $SESSION->bulk_courses ) ) + redirect( $return ); + + // generate user name list + $in = implode(',', $SESSION->bulk_users); + $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname'); + $usernames = implode('
', $userlist); + + // generate course name list + $courselist = array(); + $courses = get_courses(0, 'c.sortorder ASC', 'c.id, c.fullname'); + foreach ($courses as $course) { + if (in_array( $course->id, $SESSION->bulk_courses )) { + $courselist[] = $course->fullname; + } + } + + // generate the message + $confmsg = get_string('confirmpart1', $pluginname, NULL, $langdir).$usernames; + $confmsg .= get_string('confirmpart2', $pluginname, NULL, $langdir); + $confmsg .= implode('
', $courselist) . '?'; + $optionsyes = array(); + $optionsyes['confirm'] = true; + + // print the message + admin_externalpage_print_header(); + print_heading(get_string('confirmation', 'admin')); + notice_yesno($confmsg, 'index.php', $return, $optionsyes, NULL, 'post', 'get'); + admin_externalpage_print_footer(); + die; +} + +// action confirmed, perform it +if ($confirm) { + if (empty( $SESSION->bulk_courses)) { + redirect($return); + } + + foreach ($SESSION->bulk_courses as $course) { + $context = get_context_instance(CONTEXT_COURSE, $course); + $in = implode(',', $SESSION->bulk_users); + // for each user, unenrol them from the course + if ($rs = get_recordset_select('user', "id IN ($in)")) { + while ($user = rs_fetch_next_record($rs)) + role_unassign(0, $user->id, 0, $context->id); + } + rs_close($rs); + } + + // we're done, exit now + admin_externalpage_print_header(); + redirect($return, get_string('changessaved')); +} + +/** +* This function generates the list of courses for + + + +
+ + + + '."\n"; + } + ?> + + + + +


+ +
+ +

+ + + +

+ +

+ +
+ + +

+

+ + + + + + + Index: admin/user/actions/confirm/version.php =================================================================== RCS file: admin/user/actions/confirm/version.php diff -N admin/user/actions/confirm/version.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/confirm/version.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +version = 2007111300; +$plugin->requires = 2007111300; + +?> Index: admin/user/actions/emailactive/index.php =================================================================== RCS file: admin/user/actions/emailactive/index.php diff -N admin/user/actions/emailactive/index.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/emailactive/index.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,68 @@ +libdir.'/adminlib.php'); + +$confirm = optional_param('confirm', 0, PARAM_BOOL); +$mailstop = optional_param('mailstop', false, PARAM_RAW); + +admin_externalpage_setup('userbulk'); +require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM)); + +$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; +$langdir = $CFG->dirroot.'/admin/user/actions/emailactive/lang/'; +$pluginname = 'bulkuseractions_emailactive'; + +if (empty($SESSION->bulk_users)) { + redirect($return); +} + +admin_externalpage_print_header(); + +if ($confirm and confirm_sesskey()) { + foreach ($SESSION->bulk_users as $user) { + set_field('user', 'emailstop', $mailstop, 'id', $user); + } + redirect($return, get_string('changessaved')); +} + +if ($mailstop !== false) { + $in = implode(',', $SESSION->bulk_users); + $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname'); + $usernames = implode(', ', $userlist); + $confstr = get_string( 'confirm1', $pluginname, NULL, $langdir ); + if ($mailstop == 0) { + $confstr .= get_string( 'activate', $pluginname, NULL, $langdir ); + } else { + $confstr .= get_string( 'deactivate', $pluginname, NULL, $langdir ); + } + $confstr .= get_string( 'confirm2', $pluginname, NULL, $langdir ) . '
'; + $confstr .= $usernames . '?'; + $optionsyes = array(); + $optionsyes['confirm'] = 1; + $optionsyes['mailstop'] = $mailstop; + $optionsyes['sesskey'] = sesskey(); + print_heading(get_string('confirmation', 'admin')); + notice_yesno($confstr, 'index.php', $return, $optionsyes, NULL, 'post', 'get'); +} else { +?> +
+
+ +
+ +
+ +
+
+ Index: admin/user/actions/emailactive/lang/en_utf8/bulkuseractions_emailactive.php =================================================================== RCS file: admin/user/actions/emailactive/lang/en_utf8/bulkuseractions_emailactive.php diff -N admin/user/actions/emailactive/lang/en_utf8/bulkuseractions_emailactive.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/emailactive/lang/en_utf8/bulkuseractions_emailactive.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,9 @@ + Index: admin/user/actions/enroltocourses/index.php =================================================================== RCS file: admin/user/actions/enroltocourses/index.php diff -N admin/user/actions/enroltocourses/index.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/enroltocourses/index.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,321 @@ +libdir.'/adminlib.php'); + +$allcourses = optional_param('allcourses', '', PARAM_CLEAN); +$selcourses = optional_param('selcourses', '', PARAM_CLEAN); +$accept = optional_param('accept', 0, PARAM_BOOL); +$confirm = optional_param('confirm', 0, PARAM_BOOL); +$cancel = optional_param('cancel', 0, PARAM_BOOL); +$searchtext = optional_param('searchtext', '', PARAM_RAW); +$groupname = optional_param('groupname', '', PARAM_RAW); +$roleassign = optional_param('roleassign', '', PARAM_RAW); +$showall = optional_param('showall', 0, PARAM_BOOL); +$listadd = optional_param('add', 0, PARAM_BOOL); +$listremove = optional_param('remove', 0, PARAM_BOOL); +$removeall = optional_param('removeall', 0, PARAM_BOOL); +$hidden = optional_param('hidden', 0, PARAM_BOOL); + +admin_externalpage_setup('userbulk'); + +$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; + +if ($showall) { + $searchtext = ''; +} + +$strsearch = get_string('search'); +$langdir = $CFG->dirroot.'/admin/user/actions/enroltocourses/lang/'; +$pluginname = 'bulkuseractions_enroltocourses'; + +if (empty($SESSION->bulk_users) || $cancel) { + redirect($return); +} + +if (!isset($SESSION->bulk_courses) || $removeall) { + $SESSION->bulk_courses = array(); +} + +// course selection add/remove actions +if ($listadd && !empty($allcourses)) { + foreach ($allcourses as $course) { + if (!in_array( $course, $SESSION->bulk_courses )) { + $SESSION->bulk_courses[] = $course; + } + } +} + +if ($listremove && !empty($selcourses)) { + foreach ($selcourses as $course) { + unset($SESSION->bulk_courses[ array_search($course, $SESSION->bulk_courses) ]); + } +} + +// show the confirmation message +if ($accept) { + if (empty( $SESSION->bulk_courses )) { + redirect( $return ); + } + + // generate user name list + $in = implode(',', $SESSION->bulk_users); + $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname'); + $usernames = implode('
', $userlist); + + // generate course name list + $courselist = array(); + $courses = get_courses(0, 'c.sortorder ASC', 'c.id, c.fullname'); + foreach ($courses as $course) { + if (in_array( $course->id, $SESSION->bulk_courses )) { + $courselist[] = $course->fullname; + } + } + + // generate the message + $confmsg = get_string('confirmpart1', $pluginname, NULL, $langdir).$usernames; + $confmsg .= get_string('confirmpart2', $pluginname, NULL, $langdir); + $confmsg .= implode('
', $courselist); + $groupname = stripslashes($groupname); + if (!empty($groupname)) { + $confmsg .= get_string('confirmpart3', $pluginname, NULL, $langdir).s($groupname, false); + } + + // get system roles info and add the selected role to the message + $context = get_context_instance(CONTEXT_SYSTEM); + $roles = array(0 => get_string( 'default', $pluginname, NULL, $langdir )) + get_assignable_roles($context); + $confmsg .= get_string( 'confirmpart4', $pluginname, NULL, $langdir ).$roles[$roleassign]; + if ($hidden) { + $confmsg .= ' ('.get_string( 'hiddenassign' ).')'; + } + $confmsg .= '?'; + + $optionsyes['confirm'] = true; + $optionsyes['groupname'] = $groupname; + $optionsyes['roleassign'] = $roleassign; + $optionsyes['hidden'] = $hidden; + + // print the message + admin_externalpage_print_header(); + print_heading(get_string('confirmation', 'admin')); + notice_yesno( $confmsg, 'index.php', $return, $optionsyes, NULL, 'post', 'get'); + admin_externalpage_print_footer(); + die; +} + +// action confirmed, perform it +if( $confirm ) { + if(empty($SESSION->bulk_courses)) { + redirect($return); + } + + // for each course, get the default role if needed and check the selected group + foreach ($SESSION->bulk_courses as $course) { + $context = get_context_instance(CONTEXT_COURSE, $course); + $in = implode(',', $SESSION->bulk_users); + $groupid = false; + if ($roleassign == 0) { + $roleassign = get_default_course_role( $context )->id; + } + if (!empty($groupname)) { + $groupid = groups_get_group_by_name($course, stripslashes($groupname)); + } + // for each user, enrol them to the course with the selected role, + // and add to the selected group if available + if ($rs = get_recordset_select('user', "id IN ($in)")) { + while ($user = rs_fetch_next_record($rs)) { + role_assign($roleassign, $user->id, 0, $context->id, 0, 0, $hidden); + if ($groupid !== false) { + groups_add_member($groupid, $user->id); + } + } + } + rs_close($rs); + } + // we're done, exit now + admin_externalpage_print_header(); + redirect($return, get_string('changessaved')); +} + +/** +* This function generates the list of courses for + + + +
+ + + + '."\n"; + } + ?> + + + + +


+ +
+ +

+
+ + + + + +

+ +

+ +
+ + + +
+ + + +
+ + + +

+

+ + + + + + + Index: admin/user/actions/confirm/lang/en_utf8/bulkuseractions_confirm.php =================================================================== RCS file: admin/user/actions/confirm/lang/en_utf8/bulkuseractions_confirm.php diff -N admin/user/actions/confirm/lang/en_utf8/bulkuseractions_confirm.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/confirm/lang/en_utf8/bulkuseractions_confirm.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ + Index: admin/user/actions/delete/version.php =================================================================== RCS file: admin/user/actions/delete/version.php diff -N admin/user/actions/delete/version.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/delete/version.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +version = 2007111300; +$plugin->requires = 2007111300; + +?>