|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00006 die('this needs to be rewritten to use new enrol framework, sorry'); //TODO: MDL-24064 00007 00008 require_once('../../config.php'); 00009 require_once($CFG->libdir.'/adminlib.php'); 00010 $processed = optional_param('processed', '', PARAM_BOOL); 00011 $sort = optional_param('sort', 'fullname', PARAM_ALPHA); //Sort by full name 00012 $dir = optional_param('dir', 'asc', PARAM_ALPHA); //Order to sort (ASC) 00013 00014 require_login(); 00015 admin_externalpage_setup('userbulk'); 00016 require_capability('moodle/role:assign', get_context_instance(CONTEXT_SYSTEM)); //TODO: use some enrol cap 00017 $return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; 00018 //If no users selected then return to user_bulk.php 00019 if (empty($SESSION->bulk_users)) { 00020 redirect($return); 00021 } 00022 $users = $SESSION->bulk_users; //Get users to display 00023 $usertotal = get_users(false); //Total number of users registered 00024 $usercount = count($users); //number of users 00025 00026 echo $OUTPUT->header(); 00027 00028 //take user info 00029 foreach ($users as $key => $id) { 00030 $user = $DB->get_record('user', array('id'=>$id)); 00031 $user->fullname = fullname($user, true); 00032 unset($user->firstname); 00033 unset($user->lastname); 00034 $users[$key] = $user; 00035 } 00036 00037 // Need to sort by date 00038 function sort_compare($a, $b) { 00039 global $sort, $dir; 00040 if($sort == 'lastaccess') { 00041 $rez = $b->lastaccess - $a->lastaccess; 00042 } else { 00043 $rez = strcasecmp(@$a->$sort, @$b->$sort); 00044 } 00045 return $dir == 'desc' ? -$rez : $rez; 00046 } 00047 usort($users, 'sort_compare'); 00048 00049 //Take courses data (id, shortname, and fullname) 00050 $courses = get_courses_page(1, 'c.sortorder ASC', 'c.id,c.shortname,c.fullname,c.visible', $totalcount); 00051 $table = new html_table(); 00052 $table->width = "95%"; 00053 $columns = array('fullname'); 00054 foreach ($courses as $v) 00055 { 00056 $columns[] = $v->shortname; 00057 } 00058 00059 //Print columns headers from table 00060 foreach ($columns as $column) { 00061 $strtitle = $column; 00062 if ($sort != $column) { 00063 $columnicon = ''; 00064 $columndir = 'asc'; 00065 } else { 00066 $columndir = ($dir == 'asc') ? 'desc' : 'asc'; 00067 $columnicon = ' <img src="'.$OUTPUT->pix_url('t/'.($dir == 'asc' ? 'down' : 'up' )).'" alt="" />'; 00068 } 00069 $table->head[] = '<a href="user_bulk_enrol.php?sort='.$column.'&dir='.$columndir.'">'.$strtitle.'</a>'.$columnicon; 00070 $table->align[] = 'left'; 00071 } 00072 00073 // process data submitting 00074 if(!empty($processed)) { 00075 //Process data form here 00076 $total = count($courses) * count($users); 00077 00078 for ( $i = 0; $i < $total; $i++ ) 00079 { 00080 $param = "selected".$i; 00081 $info = optional_param($param, '', PARAM_SEQUENCE); 00087 $ids = explode(',', $info); 00088 if(!empty($ids[2])) { 00089 $context = get_context_instance(CONTEXT_COURSE, $ids[1]); 00090 role_assign(5, $ids[0], $context->id); //TODO: horrible!! 00091 } else { 00092 if( empty($ids[1] ) ) { 00093 continue; 00094 } 00095 $context = get_context_instance(CONTEXT_COURSE, $ids[1]); 00096 role_unassign(5, $ids[0], $context->id); 00097 } 00098 } 00099 redirect($return, get_string('changessaved')); //TODO: horrible!! 00100 } 00101 00102 //Form beginning 00103 echo '<form id="multienrol" name="multienrol" method="post" action="user_bulk_enrol.php">'; 00104 echo '<input type="hidden" name="processed" value="yes" />'; 00105 $count = 0; 00106 foreach($users as $user) { 00107 $temparray = array ( 00108 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.SITEID.'">'.$user->fullname.'</a>' 00109 ); 00110 $mycourses = enrol_get_users_courses($user->id, false); 00111 foreach($courses as $acourse) { 00112 $state = ''; 00113 if (isset($mycourses[$acourse->id])) { 00114 $state = 'checked="checked"'; 00115 } 00116 $temparray[] = '<input type="hidden" name="selected' . $count . 00117 '" value="' . $user->id . ',' . $acourse->id . ',0" />' . 00118 '<input type="checkbox" name="selected' . $count . 00119 '" value="' . $user->id . ',' . $acourse->id . ',1" ' . $state . '/>'; 00120 $count++; 00121 } 00122 $table->data[] = $temparray; 00123 } 00124 echo $OUTPUT->heading("$usercount / $usertotal ".get_string('users')); 00125 echo html_writer::table($table); 00126 echo '<div class="continuebutton">'; 00127 echo '<input type="submit" name="multienrolsubmit" value="save changes" />'; 00128 echo '</div>'; 00129 echo '</form>'; 00130 00131 echo $OUTPUT->footer();