|
26 | 26 | require_once(__DIR__ . '/../../../config.php');
|
27 | 27 | require_once($CFG->libdir . '/adminlib.php');
|
28 | 28 |
|
29 |
| -admin_externalpage_setup('userbulk'); |
| 29 | +admin_externalpage_setup('tool_emailutils_bounces'); |
30 | 30 | require_capability('moodle/user:update', context_system::instance());
|
31 | 31 |
|
32 | 32 | $confirm = optional_param('confirm', 0, PARAM_BOOL);
|
| 33 | +$userid = optional_param('id', null, PARAM_INT); |
| 34 | +$returnurl = optional_param('returnurl', null, PARAM_LOCALURL); |
33 | 35 |
|
34 |
| -$return = new moodle_url('/admin/user/user_bulk.php'); |
35 |
| - |
36 |
| -if (empty($SESSION->bulk_users)) { |
| 36 | +$users = empty($userid) ? $SESSION->bulk_users : [$userid]; |
| 37 | +$return = new moodle_url($returnurl ?? '/admin/tool/emailutils/bounces.php'); |
| 38 | +if (empty($users)) { |
37 | 39 | redirect($return);
|
38 | 40 | }
|
39 | 41 |
|
40 |
| -echo $OUTPUT->header(); |
41 |
| -echo $OUTPUT->heading(get_string('resetbounces', 'tool_emailutils')); |
42 |
| - |
43 | 42 | if ($confirm && confirm_sesskey()) {
|
44 |
| - list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users); |
| 43 | + list($in, $params) = $DB->get_in_or_equal($users); |
45 | 44 | $rs = $DB->get_recordset_select('user', "id $in", $params, '', 'id, ' . \tool_emailutils\helper::get_username_fields());
|
46 | 45 | foreach ($rs as $user) {
|
47 | 46 | \tool_emailutils\helper::reset_bounce_count($user);
|
48 | 47 | }
|
49 | 48 | $rs->close();
|
50 |
| - echo $OUTPUT->box_start('generalbox', 'notice'); |
51 |
| - echo $OUTPUT->notification(get_string('bouncesreset', 'tool_emailutils'), 'notifysuccess'); |
| 49 | + \core\notification::success(get_string('bouncesreset', 'tool_emailutils'));; |
| 50 | + redirect($return); |
| 51 | +} |
| 52 | + |
| 53 | +echo $OUTPUT->header(); |
| 54 | +echo $OUTPUT->heading(get_string('resetbounces', 'tool_emailutils')); |
| 55 | + |
| 56 | +list($in, $params) = $DB->get_in_or_equal($users); |
| 57 | +$userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname'); |
52 | 58 |
|
53 |
| - $continue = new single_button(new moodle_url($return), get_string('continue'), 'post'); |
| 59 | +if (empty($userlist)) { |
| 60 | + echo $OUTPUT->notification(get_string('invaliduserid', 'error')); |
| 61 | + $continue = new single_button(new moodle_url($return), get_string('continue')); |
54 | 62 | echo $OUTPUT->render($continue);
|
55 |
| - echo $OUTPUT->box_end(); |
56 | 63 | } else {
|
57 |
| - list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users); |
58 |
| - $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname'); |
59 | 64 | $usernames = implode(', ', $userlist);
|
60 |
| - echo $OUTPUT->heading(get_string('confirmation', 'admin')); |
61 |
| - $formcontinue = new single_button(new moodle_url('reset_bounces.php', ['confirm' => 1]), get_string('yes')); |
62 |
| - $formcancel = new single_button(new moodle_url('/admin/user/user_bulk.php'), get_string('no'), 'get'); |
| 65 | + $params = array_filter([ |
| 66 | + 'confirm' => 1, |
| 67 | + 'id' => $userid, |
| 68 | + 'returnurl' => $returnurl, |
| 69 | + ]); |
| 70 | + $formcontinue = new single_button(new moodle_url('reset_bounces.php', $params), get_string('yes')); |
| 71 | + $formcancel = new single_button($return, get_string('no')); |
63 | 72 | echo $OUTPUT->confirm(get_string('bouncecheckfull', 'tool_emailutils', $usernames), $formcontinue, $formcancel);
|
64 | 73 | }
|
65 | 74 | echo $OUTPUT->footer();
|
0 commit comments