Skip to content

Commit

Permalink
MDL-14679 towards /admin/user conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed May 31, 2008
1 parent 68dfee6 commit ca8d6e3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
16 changes: 8 additions & 8 deletions admin/user/lib.php
Expand Up @@ -7,18 +7,18 @@
}

function add_selection_all($ufiltering) {
global $SESSION;
global $SESSION, $DB;

$guest = get_guest();
$sqlwhere = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$guest->id));
list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$guest->id));

if ($rs = get_recordset_select('user', $sqlwhere, 'fullname', 'id,'.sql_fullname().' AS fullname')) {
while ($user = rs_fetch_next_record($rs)) {
if (! isset($SESSION->bulk_users[$user->id])) {
if ($rs = $DB->get_recordset_select('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname')) {
foreach ($rs as $user) {
if (!isset($SESSION->bulk_users[$user->id])) {
$SESSION->bulk_users[$user->id] = $user->id;
}
}
rs_close($rs);
$rs->close();
}
}

Expand All @@ -34,7 +34,7 @@ function get_selection_data($ufiltering) {
$scount = count($SESSION->bulk_users);

$userlist = array('acount'=>$acount, 'scount'=>$scount, 'ausers'=>false, 'susers'=>false, 'total'=>$total);
$userlist['ausers'] = $DB->get_records_select_menu('user', $sqlwhere, $params, 'fullname', 'id,'.sql_fullname().' AS fullname', 0, MAX_BULK_USERS);
$userlist['ausers'] = $DB->get_records_select_menu('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname', 0, MAX_BULK_USERS);

if ($scount) {
if ($scount < MAX_BULK_USERS) {
Expand All @@ -43,7 +43,7 @@ function get_selection_data($ufiltering) {
$bulkusers = array_slice($SESSION->bulk_users, 0, MAX_BULK_USERS, true);
$in = implode(',', $bulkusers);
}
$userlist['susers'] = $DB->get_records_select_menu('user', "id IN ($in)", null, 'fullname', 'id,'.sql_fullname().' AS fullname');
$userlist['susers'] = $DB->get_records_select_menu('user', "id IN ($in)", null, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
}

return $userlist;
Expand Down
8 changes: 4 additions & 4 deletions admin/user/user_bulk_confirm.php
Expand Up @@ -23,8 +23,8 @@

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 ($rs = $DB->get_recordset_select('user', "id IN ($in)", null, '', 'id, username, secret, confirmed, auth, firstname, lastname')) {
foreach ($rs as $user) {
if ($user->confirmed) {
continue;
}
Expand All @@ -34,13 +34,13 @@
notify(get_string('usernotconfirmed', '', fullname($user, true)));
}
}
rs_close($rs);
$rs->close();
}
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');
$userlist = $DB->get_records_select_menu('user', "id IN ($in)", null, 'fullname', 'id,'.sql_fullname().' AS fullname');
$usernames = implode(', ', $userlist);
$optionsyes = array();
$optionsyes['confirm'] = 1;
Expand Down
8 changes: 4 additions & 4 deletions admin/user/user_bulk_delete.php
Expand Up @@ -25,21 +25,21 @@
$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 ($rs = $DB->get_recordset_select('user', "id IN ($in)", null)) {
foreach ($rs as $user) {
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);
$rs->close;
}
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');
$userlist = $DB->get_records_select_menu('user', "id IN ($in)", null, 'fullname', 'id,'.sql_fullname().' AS fullname');
$usernames = implode(', ', $userlist);
$optionsyes = array();
$optionsyes['confirm'] = 1;
Expand Down
2 changes: 1 addition & 1 deletion admin/user/user_bulk_display.php
Expand Up @@ -25,7 +25,7 @@
$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 = $DB->get_record('user', array('id'=>$id), 'id, firstname, lastname, username, email, country, lastaccess, city');
$user->fullname = fullname($user, true);
$user->country = @$countries[$user->country];
unset($user->firstname);
Expand Down
14 changes: 7 additions & 7 deletions admin/user/user_bulk_download.php
Expand Up @@ -37,7 +37,7 @@
'msn' => 'msn',
'country' => 'country');

if ($extrafields = get_records_select('user_info_field')) {
if ($extrafields = $DB->get_records_select('user_info_field')) {
foreach ($extrafields as $n=>$v){
$fields['profile_field_'.$v->shortname] = 'profile_field_'.$v->name;
}
Expand Down Expand Up @@ -68,7 +68,7 @@
print_footer();

function user_download_ods($fields) {
global $CFG, $SESSION;
global $CFG, $SESSION, $DB;

require_once("$CFG->libdir/odslib.class.php");
require_once($CFG->dirroot.'/user/profile/lib.php');
Expand All @@ -89,7 +89,7 @@ function user_download_ods($fields) {

$row = 1;
foreach ($SESSION->bulk_users as $userid) {
if (!$user = get_record('user', 'id', $userid)) {
if (!$user = $DB->get_record('user', array('id'=>$userid))) {
continue;
}
$col = 0;
Expand All @@ -106,7 +106,7 @@ function user_download_ods($fields) {
}

function user_download_xls($fields) {
global $CFG, $SESSION;
global $CFG, $SESSION, $DB;

require_once("$CFG->libdir/excellib.class.php");
require_once($CFG->dirroot.'/user/profile/lib.php');
Expand All @@ -127,7 +127,7 @@ function user_download_xls($fields) {

$row = 1;
foreach ($SESSION->bulk_users as $userid) {
if (!$user = get_record('user', 'id', $userid)) {
if (!$user = $DB->get_record('user', array('id'=>$userid))) {
continue;
}
$col = 0;
Expand All @@ -144,7 +144,7 @@ function user_download_xls($fields) {
}

function user_download_csv($fields) {
global $CFG, $SESSION;
global $CFG, $SESSION, $DB;

require_once($CFG->dirroot.'/user/profile/lib.php');

Expand All @@ -167,7 +167,7 @@ function user_download_csv($fields) {

foreach ($SESSION->bulk_users as $userid) {
$row = array();
if (!$user = get_record('user', 'id', $userid)) {
if (!$user = $DB->get_record('user', array('id'=>$userid))) {
continue;
}
profile_load_data($user);
Expand Down
7 changes: 4 additions & 3 deletions admin/user/user_bulk_message.php
Expand Up @@ -24,10 +24,11 @@

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)) {
if ($rs = $DB->get_recordset_select('user', "id IN ($in)", null)) {
foreach ($rs as $user) {
message_post_message($USER, $user, $msg, FORMAT_HTML, 'direct');
}
$rs->close();
}
redirect($return);
}
Expand All @@ -51,7 +52,7 @@
$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');
$userlist = $DB->get_records_select_menu('user', "id IN ($in)", null, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
$usernames = implode(', ', $userlist);
$optionsyes = array();
$optionsyes['confirm'] = 1;
Expand Down

0 comments on commit ca8d6e3

Please sign in to comment.