Annotation of loncom/interface/lonuserutils.pm, revision 1.204
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.204 ! raeburn 4: # $Id: lonuserutils.pm,v 1.203 2019/08/26 00:15:57 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ###############################################################
30:
31: package Apache::lonuserutils;
32:
1.175 raeburn 33: =pod
34:
35: =head1 NAME
36:
37: Apache::lonuserutils.pm
38:
39: =head1 SYNOPSIS
40:
41: Utilities for management of users and custom roles
42:
43: Provides subroutines called by loncreateuser.pm
44:
45: =head1 OVERVIEW
46:
47: =cut
48:
1.1 raeburn 49: use strict;
50: use Apache::lonnet;
51: use Apache::loncommon();
52: use Apache::lonhtmlcommon;
53: use Apache::lonlocal;
1.8 raeburn 54: use Apache::longroup;
1.174 raeburn 55: use HTML::Entities;
1.8 raeburn 56: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 57:
58: ###############################################################
59: ###############################################################
60: # Drop student from all sections of a course, except optional $csec
61: sub modifystudent {
1.52 raeburn 62: my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
1.1 raeburn 63: # if $csec is undefined, drop the student from all the courses matching
64: # this one. If $csec is defined, drop them from all other sections of
65: # this course and add them to section $csec
1.17 raeburn 66: my ($cnum,$cdom) = &get_course_identity($courseid);
1.138 raeburn 67: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
1.1 raeburn 68: my ($tmp) = keys(%roles);
69: # Bail out if we were unable to get the students roles
70: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
71: # Go through the roles looking for enrollment in this course
72: my $result = '';
73: foreach my $course (keys(%roles)) {
74: if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
75: # We are in this course
76: my $section=$1;
77: $section='' if ($course eq "/$cdom/$cnum".'_st');
78: if (defined($csec) && $section eq $csec) {
79: $result .= 'ok:';
80: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
81: my (undef,$end,$start)=split(/\_/,$roles{$course});
82: my $now=time;
83: # if this is an active role
84: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
85: my $reply=&Apache::lonnet::modifystudent
86: # dom name id mode pass f m l g
87: ($udom,$unam,'', '', '',undef,undef,undef,undef,
1.22 raeburn 88: $section,time,undef,undef,$desiredhost,'','manual',
1.52 raeburn 89: '',$courseid,'',$context);
1.1 raeburn 90: $result .= $reply.':';
91: }
92: }
93: }
94: }
95: if ($result eq '') {
1.37 raeburn 96: $result = &mt('Unable to find section for this student');
1.1 raeburn 97: } else {
98: $result =~ s/(ok:)+/ok/g;
99: }
100: return $result;
101: }
102:
103: sub modifyuserrole {
104: my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
105: $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
1.84 raeburn 106: $end,$start,$checkid,$inststatus) = @_;
1.5 raeburn 107: my ($scope,$userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 108: if ($setting eq 'course' || $context eq 'course') {
109: $scope = '/'.$cid;
110: $scope =~ s/\_/\//g;
1.103 raeburn 111: if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
1.1 raeburn 112: $scope .='/'.$sec;
113: }
1.5 raeburn 114: } elsif ($context eq 'domain') {
1.1 raeburn 115: $scope = '/'.$env{'request.role.domain'}.'/';
1.13 raeburn 116: } elsif ($context eq 'author') {
1.1 raeburn 117: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
118: }
119: if ($context eq 'domain') {
120: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
121: if ($uhome ne 'no_host') {
1.5 raeburn 122: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
1.1 raeburn 123: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
124: ($umode eq 'localauth')) {
125: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
126: }
127: }
1.5 raeburn 128: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
129: ($env{'form.recurseid'}) && ($checkid)) {
130: my %userupdate = (
131: lastname => $last,
132: middlename => $middle,
133: firstname => $first,
134: generation => $gene,
135: id => $uid,
136: );
137: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
138: }
1.1 raeburn 139: }
140: }
141: $userresult =
142: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
143: $middle,$last,$gene,$forceid,$desiredhome,
1.84 raeburn 144: $email,$inststatus);
1.1 raeburn 145: if ($userresult eq 'ok') {
1.5 raeburn 146: if ($role ne '') {
1.22 raeburn 147: $role =~ s/_/\//g;
1.1 raeburn 148: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
1.52 raeburn 149: $role,$end,$start,'',
150: '',$context);
1.1 raeburn 151: }
152: }
1.5 raeburn 153: return ($userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 154: }
155:
1.5 raeburn 156: sub propagate_id_change {
157: my ($uname,$udom,$user) = @_;
1.12 raeburn 158: my (@types,@roles);
1.5 raeburn 159: @types = ('active','future');
160: @roles = ('st');
161: my $idresult;
162: my %roleshash = &Apache::lonnet::get_my_roles($uname,
1.12 raeburn 163: $udom,'userroles',\@types,\@roles);
164: my %args = (
165: one_time => 1,
166: );
1.5 raeburn 167: foreach my $item (keys(%roleshash)) {
1.22 raeburn 168: my ($cnum,$cdom,$role) = split(/:/,$item,-1);
1.5 raeburn 169: my ($start,$end) = split(/:/,$roleshash{$item});
170: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.12 raeburn 171: my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
172: my %coursehash =
173: &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
174: my $cdesc = $coursehash{'description'};
175: if ($cdesc eq '') {
176: $cdesc = $cdom.'_'.$cnum;
177: }
1.5 raeburn 178: if ($result eq 'ok') {
1.12 raeburn 179: $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 180: } else {
1.12 raeburn 181: $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 182: }
183: }
184: }
185: return $idresult;
186: }
187:
188: sub update_classlist {
1.63 raeburn 189: my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
1.6 albertel 190: my ($uid,$classlistentry);
1.5 raeburn 191: my $fullname =
192: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
193: $user->{'lastname'},$user->{'generation'},
194: 'lastname');
195: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
196: $cdom,$cnum);
197: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
198: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
199: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
1.63 raeburn 200: my $endidx = &Apache::loncoursedata::CL_END() - 2;
201: my $startidx = &Apache::loncoursedata::CL_START() - 2;
1.5 raeburn 202: for (my $i=0; $i<@classinfo; $i++) {
1.63 raeburn 203: if ($i == $endidx) {
204: if ($newend ne '') {
205: $classlistentry .= $newend.':';
206: } else {
207: $classlistentry .= $classinfo[$i].':';
208: }
209: } elsif ($i == $startidx) {
210: if ($newend ne '') {
211: if ($classinfo[$i] > $newend) {
212: $classlistentry .= $newend.':';
213: } else {
214: $classlistentry .= $classinfo[$i].':';
215: }
216: } else {
217: $classlistentry .= $classinfo[$i].':';
218: }
219: } elsif ($i == $ididx) {
1.5 raeburn 220: if (defined($user->{'id'})) {
221: $classlistentry .= $user->{'id'}.':';
222: } else {
223: $classlistentry .= $classinfo[$i].':';
224: }
225: } elsif ($i == $nameidx) {
1.63 raeburn 226: if (defined($user->{'lastname'})) {
227: $classlistentry .= $fullname.':';
228: } else {
229: $classlistentry .= $classinfo[$i].':';
230: }
1.5 raeburn 231: } else {
232: $classlistentry .= $classinfo[$i].':';
233: }
234: }
235: $classlistentry =~ s/:$//;
236: my $reply=&Apache::lonnet::cput('classlist',
237: {"$uname:$udom" => $classlistentry},
238: $cdom,$cnum);
239: if (($reply eq 'ok') || ($reply eq 'delayed')) {
240: return 'ok';
241: } else {
242: return 'error: '.$reply;
243: }
244: }
245:
246:
1.1 raeburn 247: ###############################################################
248: ###############################################################
1.2 raeburn 249: # build a role type and role selection form
250: sub domain_roles_select {
251: # Set up the role type and role selection boxes when in
252: # domain context
253: #
254: # Role types
1.101 raeburn 255: my @roletypes = ('domain','author','course','community');
1.2 raeburn 256: my %lt = &role_type_names();
1.149 raeburn 257: my $onchangefirst = "updateCols('showrole')";
258: my $onchangesecond = "updateCols('showrole')";
1.1 raeburn 259: #
260: # build up the menu information to be passed to
261: # &Apache::loncommon::linked_select_forms
262: my %select_menus;
1.2 raeburn 263: if ($env{'form.roletype'} eq '') {
264: $env{'form.roletype'} = 'domain';
265: }
266: foreach my $roletype (@roletypes) {
1.1 raeburn 267: # set up the text for this domain
1.2 raeburn 268: $select_menus{$roletype}->{'text'}= $lt{$roletype};
1.102 raeburn 269: my $crstype;
270: if ($roletype eq 'community') {
271: $crstype = 'Community';
272: }
1.1 raeburn 273: # we want a choice of 'default' as the default in the second menu
1.2 raeburn 274: if ($env{'form.roletype'} ne '') {
275: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
276: } else {
277: $select_menus{$roletype}->{'default'} = 'Any';
278: }
1.1 raeburn 279: # Now build up the other items in the second menu
1.2 raeburn 280: my @roles;
281: if ($roletype eq 'domain') {
282: @roles = &domain_roles();
1.13 raeburn 283: } elsif ($roletype eq 'author') {
1.2 raeburn 284: @roles = &construction_space_roles();
285: } else {
1.17 raeburn 286: my $custom = 1;
1.101 raeburn 287: @roles = &course_roles('domain',undef,$custom,$roletype);
1.1 raeburn 288: }
1.2 raeburn 289: my $order = ['Any',@roles];
290: $select_menus{$roletype}->{'order'} = $order;
291: foreach my $role (@roles) {
1.5 raeburn 292: if ($role eq 'cr') {
293: $select_menus{$roletype}->{'select2'}->{$role} =
294: &mt('Custom role');
295: } else {
296: $select_menus{$roletype}->{'select2'}->{$role} =
1.102 raeburn 297: &Apache::lonnet::plaintext($role,$crstype);
1.5 raeburn 298: }
1.2 raeburn 299: }
300: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
1.1 raeburn 301: }
1.2 raeburn 302: my $result = &Apache::loncommon::linked_select_forms
303: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
1.101 raeburn 304: 'roletype','showrole',\%select_menus,
1.149 raeburn 305: ['domain','author','course','community'],$onchangefirst,
306: $onchangesecond);
1.1 raeburn 307: return $result;
308: }
309:
310: ###############################################################
311: ###############################################################
312: sub hidden_input {
313: my ($name,$value) = @_;
314: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
315: }
316:
317: sub print_upload_manager_header {
1.123 raeburn 318: my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
319: $can_assign)=@_;
1.1 raeburn 320: my $javascript;
321: #
322: if (! exists($env{'form.upfile_associate'})) {
323: $env{'form.upfile_associate'} = 'forward';
324: }
325: if ($env{'form.associate'} eq 'Reverse Association') {
326: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
327: $env{'form.upfile_associate'} = 'reverse';
328: } else {
329: $env{'form.upfile_associate'} = 'forward';
330: }
331: }
332: if ($env{'form.upfile_associate'} eq 'reverse') {
1.123 raeburn 333: $javascript=&upload_manager_javascript_reverse_associate($can_assign);
1.1 raeburn 334: } else {
1.123 raeburn 335: $javascript=&upload_manager_javascript_forward_associate($can_assign);
1.1 raeburn 336: }
337: #
338: # Deal with restored settings
339: my $password_choice = '';
340: if (exists($env{'form.ipwd_choice'}) &&
341: $env{'form.ipwd_choice'} ne '') {
342: # If a column was specified for password, assume it is for an
343: # internal password. This is a bug waiting to be filed (could be
344: # local or krb auth instead of internal) but I do not have the
345: # time to mess around with this now.
346: $password_choice = 'int';
347: }
348: #
1.22 raeburn 349: my $groupslist;
350: if ($context eq 'course') {
351: $groupslist = &get_groupslist();
352: }
1.1 raeburn 353: my $javascript_validations =
1.22 raeburn 354: &javascript_validations('upload',$krbdefdom,$password_choice,undef,
355: $env{'request.role.domain'},$context,
1.103 raeburn 356: $groupslist,$crstype);
1.91 bisitz 357: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.147 bisitz 358: $r->print(
359: '<h3>'.&mt('Identify fields in uploaded list')."</h3>\n".
360: '<p class="LC_info">'.
361: &mt('Total number of records found in file: [_1]'
362: ,'<b>'.$distotal.'</b>').
363: "</p>\n"
364: );
365: if ($distotal == 0) {
366: $r->print('<p class="LC_warning">'.&mt('None found').'</p>');
367: }
368: $r->print(
369: '<p>'.
370: &mt('Enter as many fields as you can.').'<br />'.
371: &mt('The system will inform you and bring you back to this page,[_1]if the data selected are insufficient to add users.','<br />').
372: "</p>\n"
373: );
1.1 raeburn 374: $r->print(&hidden_input('action','upload').
375: &hidden_input('state','got_file').
376: &hidden_input('associate','').
377: &hidden_input('datatoken',$datatoken).
378: &hidden_input('fileupload',$env{'form.fileupload'}).
379: &hidden_input('upfiletype',$env{'form.upfiletype'}).
380: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
1.147 bisitz 381: $r->print(
382: '<div class="LC_left_float">'.
383: '<fieldset><legend>'.&mt('Functions').'</legend>'.
384: '<label><input type="checkbox" name="noFirstLine"'.$checked.' />'.
385: &mt('Ignore First Line').'</label>'.
386: ' <input type="button" value="'.&mt('Reverse Association').'" '.
1.59 bisitz 387: 'name="Reverse Association" '.
1.147 bisitz 388: 'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />'.
389: '</fieldset></div><br clear="all" />'
390: );
391: $r->print(
392: '<script type="text/javascript" language="Javascript">'."\n".
393: '// <![CDATA['."\n".
394: $javascript."\n".$javascript_validations."\n".
395: '// ]]>'."\n".
396: '</script>'
397: );
1.1 raeburn 398: }
399:
400: ###############################################################
401: ###############################################################
402: sub javascript_validations {
1.22 raeburn 403: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
1.103 raeburn 404: $context,$groupslist,$crstype)=@_;
1.22 raeburn 405: my %param = (
406: kerb_def_dom => $krbdefdom,
407: curr_authtype => $curr_authtype,
408: );
1.37 raeburn 409: if ($mode eq 'upload') {
1.22 raeburn 410: $param{'formname'} = 'studentform';
1.1 raeburn 411: } elsif ($mode eq 'createcourse') {
1.22 raeburn 412: $param{'formname'} = 'ccrs';
1.1 raeburn 413: } elsif ($mode eq 'modifycourse') {
1.22 raeburn 414: $param{'formname'} = 'cmod';
415: $param{'mode'} = 'modifycourse',
416: $param{'curr_autharg'} = $curr_authfield;
417: }
418:
1.150 raeburn 419: my $showcredits;
420: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1.160 raeburn 421: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 422: $showcredits = 1;
423: }
424:
1.22 raeburn 425: my ($setsection_call,$setsections_js);
426: my $finish = " vf.submit();\n";
427: if ($mode eq 'upload') {
428: if (($context eq 'course') || ($context eq 'domain')) {
429: if ($context eq 'course') {
430: if ($env{'request.course.sec'} eq '') {
1.109 raeburn 431: $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
1.22 raeburn 432: $setsections_js =
433: &setsections_javascript($param{'formname'},$groupslist,
1.150 raeburn 434: $mode,'',$crstype,$showcredits);
1.22 raeburn 435: } else {
436: $setsection_call = "'ok'";
437: }
438: } elsif ($context eq 'domain') {
439: $setsection_call = 'setCourse()';
1.150 raeburn 440: $setsections_js = &dc_setcourse_js($param{'formname'},$mode,
1.196 raeburn 441: $context,$showcredits,$domain);
1.22 raeburn 442: }
443: $finish = " var checkSec = $setsection_call\n".
444: " if (checkSec == 'ok') {\n".
445: " vf.submit();\n".
446: " }\n";
447: }
1.1 raeburn 448: }
1.22 raeburn 449: my $authheader = &Apache::loncommon::authform_header(%param);
1.1 raeburn 450:
451: my %alert = &Apache::lonlocal::texthash
452: (username => 'You need to specify the username field.',
453: authen => 'You must choose an authentication type.',
454: krb => 'You need to specify the Kerberos domain.',
455: ipass => 'You need to specify the initial password.',
456: name => 'The optional name field was not specified.',
1.93 bisitz 457: snum => 'The optional student/employee ID field was not specified.',
1.1 raeburn 458: section => 'The optional section field was not specified.',
1.75 schafran 459: email => 'The optional e-mail address field was not specified.',
1.1 raeburn 460: role => 'The optional role field was not specified.',
1.57 raeburn 461: domain => 'The optional domain field was not specified.',
1.1 raeburn 462: continue => 'Continue adding users?',
463: );
1.150 raeburn 464: if ($showcredits) {
465: $alert{'credits'} = &mt('The optional credits field was not specified');
466: }
1.84 raeburn 467: if (($mode eq 'upload') && ($context eq 'domain')) {
468: $alert{'inststatus'} = &mt('The optional affiliation field was not specified');
469: }
1.170 damieng 470: &js_escape(\%alert);
1.37 raeburn 471: my $function_name = <<"END";
1.22 raeburn 472: $setsections_js
473:
1.150 raeburn 474: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits) {
1.1 raeburn 475: END
476: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
477: my $auth_checks;
478: if ($mode eq 'createcourse') {
479: $auth_checks .= (<<END);
480: if (vf.autoadds[0].checked == true) {
481: if (current.radiovalue == null || current.radiovalue == 'nochange') {
482: alert('$alert{'authen'}');
483: return;
484: }
485: }
486: END
487: } else {
488: $auth_checks .= (<<END);
489: var foundatype=0;
490: if (founduname==0) {
491: alert('$alert{'username'}');
492: return;
493: }
494:
495: END
496: if ($authnum > 1) {
497: $auth_checks .= (<<END);
498: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
499: // They did not check any of the login radiobuttons.
500: alert('$alert{'authen'}');
501: return;
502: }
503: END
504: }
505: }
506: if ($mode eq 'createcourse') {
507: $auth_checks .= "
508: if ( (vf.autoadds[0].checked == true) &&
509: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
510: ";
511: } elsif ($mode eq 'modifycourse') {
512: $auth_checks .= "
513: if (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') {
514: ";
515: }
516: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
517: $auth_checks .= (<<END);
518: var alertmsg = '';
519: switch (current.radiovalue) {
520: case 'krb':
521: alertmsg = '$alert{'krb'}';
522: break;
523: default:
524: alertmsg = '';
525: }
526: if (alertmsg != '') {
527: alert(alertmsg);
528: return;
529: }
530: }
1.150 raeburn 531: /* regexp here to check for non \d \. in credits */
1.1 raeburn 532: END
533: } else {
1.196 raeburn 534: my ($numrules,$intargjs) =
535: &passwd_validation_js('vf.elements[current.argfield].value',$domain);
1.1 raeburn 536: $auth_checks .= (<<END);
537: foundatype=1;
538: if (current.argfield == null || current.argfield == '') {
1.196 raeburn 539: // The login radiobutton checked does not have an associated textbox
540: } else if (vf.elements[current.argfield].value == '') {
1.1 raeburn 541: var alertmsg = '';
1.38 raeburn 542: switch (current.radiovalue) {
1.1 raeburn 543: case 'krb':
544: alertmsg = '$alert{'krb'}';
545: break;
546: case 'loc':
1.196 raeburn 547: case 'int':
1.1 raeburn 548: alertmsg = '$alert{'ipass'}';
549: break;
550: case 'fsys':
1.196 raeburn 551: alertmsg = '$alert{'ipass'}';
1.1 raeburn 552: break;
1.194 raeburn 553: case 'lti':
1.1 raeburn 554: default:
555: alertmsg = '';
556: }
557: if (alertmsg != '') {
558: alert(alertmsg);
559: return;
560: }
1.196 raeburn 561: } else if (current.radiovalue == 'int') {
562: if ($numrules > 0) {
563: $intargjs
564: }
1.1 raeburn 565: }
566: END
567: }
568: my $section_checks;
569: my $optional_checks = '';
570: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
571: $optional_checks = (<<END);
572: vf.submit();
573: }
574: END
575: } else {
576: $section_checks = §ion_check_js();
577: $optional_checks = (<<END);
578: var message='';
579: if (foundname==0) {
580: message='$alert{'name'}';
581: }
582: if (foundid==0) {
583: if (message!='') {
584: message+='\\n';
585: }
586: message+='$alert{'snum'}';
587: }
588: if (foundsec==0) {
589: if (message!='') {
590: message+='\\n';
591: }
1.130 raeburn 592: message+='$alert{'section'}';
1.1 raeburn 593: }
594: if (foundemail==0) {
595: if (message!='') {
596: message+='\\n';
597: }
598: message+='$alert{'email'}';
599: }
1.57 raeburn 600: if (foundrole==0) {
601: if (message!='') {
602: message+='\\n';
603: }
604: message+='$alert{'role'}';
605: }
606: if (founddomain==0) {
607: if (message!='') {
608: message+='\\n';
609: }
610: message+='$alert{'domain'}';
611: }
1.84 raeburn 612: END
1.150 raeburn 613: if ($showcredits) {
614: $optional_checks .= <<END;
615: if (foundcredits==0) {
616: if (message!='') {
617: message+='\\n';
618: }
619: message+='$alert{'credits'}';
620: }
621: END
622: }
1.84 raeburn 623: if (($mode eq 'upload') && ($context eq 'domain')) {
624: $optional_checks .= (<<END);
625:
626: if (foundinststatus==0) {
627: if (message!='') {
628: message+='\\n';
629: }
630: message+='$alert{'inststatus'}';
631: }
632: END
633: }
634: $optional_checks .= (<<END);
635:
1.1 raeburn 636: if (message!='') {
637: message+= '\\n$alert{'continue'}';
638: if (confirm(message)) {
639: vf.state.value='enrolling';
1.22 raeburn 640: $finish
1.1 raeburn 641: }
642: } else {
643: vf.state.value='enrolling';
1.22 raeburn 644: $finish
1.1 raeburn 645: }
646: }
647: END
648: }
1.37 raeburn 649: my $result = $function_name.$auth_checks.$optional_checks."\n".
650: $section_checks.$authheader;
1.1 raeburn 651: return $result;
652: }
1.196 raeburn 653:
654: sub passwd_validation_js {
655: my ($currpasswdval,$domain) = @_;
656: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
657: my ($min,$max,@chars,$numrules,$intargjs,%alert);
658: $numrules = 0;
1.202 raeburn 659: $min = $Apache::lonnet::passwdmin;
1.196 raeburn 660: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
661: if ($passwdconf{'min'} =~ /^\d+$/) {
1.202 raeburn 662: if ($passwdconf{'min'} > $min) {
663: $min = $passwdconf{'min'};
664: }
1.196 raeburn 665: }
666: if ($passwdconf{'max'} =~ /^\d+$/) {
667: $max = $passwdconf{'max'};
668: $numrules ++;
669: }
670: @chars = @{$passwdconf{'chars'}};
671: if (@chars) {
672: $numrules ++;
673: }
1.203 raeburn 674: }
675: if ($min > 0) {
1.196 raeburn 676: $numrules ++;
677: }
1.202 raeburn 678: if (($min > 0) || ($max ne '') || (@chars > 0)) {
1.196 raeburn 679: my $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
680: if ($min) {
681: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
682: }
683: if ($max) {
684: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
685: }
686: my (@charalerts,@charrules);
687: if (@chars) {
688: if (grep(/^uc$/,@chars)) {
689: push(@charalerts,&mt('contain at least one upper case letter'));
690: push(@charrules,'uc');
691: }
692: if (grep(/^lc$/,@chars)) {
693: push(@charalerts,&mt('contain at least one lower case letter'));
694: push(@charrules,'lc');
695: }
696: if (grep(/^num$/,@chars)) {
697: push(@charalerts,&mt('contain at least one number'));
698: push(@charrules,'num');
699: }
700: if (grep(/^spec$/,@chars)) {
701: push(@charalerts,&mt('contain at least one non-alphanumeric'));
702: push(@charrules,'spec');
703: }
704: }
705: $intargjs = qq| var rulesmsg = '';\n|.
706: qq| var currpwval = $currpasswdval;\n|;
707: if ($min) {
708: $intargjs .= qq|
709: if (currpwval.length < $min) {
710: rulesmsg += ' - $alert{min}';
711: }
712: |;
713: }
714: if ($max) {
715: $intargjs .= qq|
716: if (currpwval.length > $max) {
717: rulesmsg += ' - $alert{max}';
718: }
719: |;
720: }
721: if (@chars > 0) {
722: my $charrulestr = '"'.join('","',@charrules).'"';
723: my $charalertstr = '"'.join('","',@charalerts).'"';
724: $intargjs .= qq| var brokerules = new Array();\n|.
725: qq| var charrules = new Array($charrulestr);\n|.
726: qq| var charalerts = new Array($charalertstr);\n|;
727: my %rules;
728: map { $rules{$_} = 1; } @chars;
729: if ($rules{'uc'}) {
730: $intargjs .= qq|
731: var ucRegExp = /[A-Z]/;
732: if (!ucRegExp.test(currpwval)) {
733: brokerules.push('uc');
734: }
735: |;
736: }
737: if ($rules{'lc'}) {
738: $intargjs .= qq|
739: var lcRegExp = /[a-z]/;
740: if (!lcRegExp.test(currpwval)) {
741: brokerules.push('lc');
742: }
743: |;
744: }
745: if ($rules{'num'}) {
746: $intargjs .= qq|
747: var numRegExp = /[0-9]/;
748: if (!numRegExp.test(currpwval)) {
749: brokerules.push('num');
750: }
751: |;
752: }
753: if ($rules{'spec'}) {
754: $intargjs .= q|
1.200 raeburn 755: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
1.196 raeburn 756: if (!specRegExp.test(currpwval)) {
757: brokerules.push('spec');
758: }
759: |;
760: }
761: $intargjs .= qq|
762: if (brokerules.length > 0) {
763: for (var i=0; i<brokerules.length; i++) {
764: for (var j=0; j<charrules.length; j++) {
765: if (brokerules[i] == charrules[j]) {
766: rulesmsg += ' - '+charalerts[j]+'\\n';
767: break;
768: }
769: }
770: }
771: }
772: |;
773: }
774: $intargjs .= qq|
775: if (rulesmsg != '') {
776: rulesmsg = '$alertmsg'+rulesmsg;
777: alert(rulesmsg);
1.197 raeburn 778: return false;
1.196 raeburn 779: }
780: |;
781: }
782: return ($numrules,$intargjs);
783: }
784:
1.1 raeburn 785: ###############################################################
786: ###############################################################
787: sub upload_manager_javascript_forward_associate {
1.123 raeburn 788: my ($can_assign) = @_;
1.132 raeburn 789: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 790: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 791: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
792: $argreset .= " vf.krbarg.value='';\n";
793: $numbuttons ++ ;
794: }
795: if ($can_assign->{'int'}) {
796: $argreset .= " vf.intarg.value='';\n";
797: $numbuttons ++;
798: }
799: if ($can_assign->{'loc'}) {
800: $argreset .= " vf.locarg.value='';\n";
801: $numbuttons ++;
802: }
803: if (!$can_assign->{'int'}) {
1.170 damieng 804: my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.')."\n".
1.132 raeburn 805: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 806: &js_escape(\$warning);
1.132 raeburn 807: $auth_update = <<"END";
808: // Currently the initial password field is only supported for internal auth
809: // (see bug 6368).
810: if (nw==9) {
811: eval('vf.f'+tf+'.selectedIndex=0;')
812: alert('$warning');
813: }
814: END
815: } elsif ($numbuttons > 1) {
1.123 raeburn 816: $auth_update = <<"END";
817: // If we set the password, make the password form below correspond to
818: // the new value.
819: if (nw==9) {
820: changed_radio('int',document.studentform);
821: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 822: $argreset
823: }
824:
1.123 raeburn 825: END
826: }
827: }
828:
1.1 raeburn 829: return(<<ENDPICK);
830: function verify(vf,sec_caller) {
831: var founduname=0;
832: var foundpwd=0;
833: var foundname=0;
834: var foundid=0;
835: var foundsec=0;
836: var foundemail=0;
837: var foundrole=0;
1.57 raeburn 838: var founddomain=0;
1.84 raeburn 839: var foundinststatus=0;
1.150 raeburn 840: var foundcredits=0;
1.1 raeburn 841: var tw;
842: for (i=0;i<=vf.nfields.value;i++) {
843: tw=eval('vf.f'+i+'.selectedIndex');
844: if (tw==1) { founduname=1; }
845: if ((tw>=2) && (tw<=6)) { foundname=1; }
846: if (tw==7) { foundid=1; }
847: if (tw==8) { foundsec=1; }
848: if (tw==9) { foundpwd=1; }
849: if (tw==10) { foundemail=1; }
850: if (tw==11) { foundrole=1; }
1.57 raeburn 851: if (tw==12) { founddomain=1; }
1.84 raeburn 852: if (tw==13) { foundinststatus=1; }
1.150 raeburn 853: if (tw==14) { foundcredits=1; }
1.1 raeburn 854: }
1.150 raeburn 855: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 856: }
857:
858: //
859: // vf = this.form
860: // tf = column number
861: //
862: // values of nw
863: //
864: // 0 = none
865: // 1 = username
866: // 2 = names (lastname, firstnames)
867: // 3 = fname (firstname)
868: // 4 = mname (middlename)
869: // 5 = lname (lastname)
870: // 6 = gen (generation)
871: // 7 = id
872: // 8 = section
873: // 9 = ipwd (password)
874: // 10 = email address
875: // 11 = role
1.57 raeburn 876: // 12 = domain
1.84 raeburn 877: // 13 = inststatus
1.150 raeburn 878: // 14 = foundcredits
1.1 raeburn 879:
880: function flip(vf,tf) {
881: var nw=eval('vf.f'+tf+'.selectedIndex');
882: var i;
883: // make sure no other columns are labeled the same as this one
884: for (i=0;i<=vf.nfields.value;i++) {
885: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
886: eval('vf.f'+i+'.selectedIndex=0;')
887: }
888: }
889: // If we set this to 'lastname, firstnames', clear out all the ones
890: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
891: if (nw==2) {
892: for (i=0;i<=vf.nfields.value;i++) {
893: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
894: (eval('vf.f'+i+'.selectedIndex')<=6)) {
895: eval('vf.f'+i+'.selectedIndex=0;')
896: }
897: }
898: }
899: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
900: // clear out any that are set to 'lastname, firstnames' (2)
901: if ((nw>=3) && (nw<=6)) {
902: for (i=0;i<=vf.nfields.value;i++) {
903: if (eval('vf.f'+i+'.selectedIndex')==2) {
904: eval('vf.f'+i+'.selectedIndex=0;')
905: }
906: }
907: }
1.123 raeburn 908: $auth_update
1.1 raeburn 909: }
910:
911: function clearpwd(vf) {
912: var i;
913: for (i=0;i<=vf.nfields.value;i++) {
914: if (eval('vf.f'+i+'.selectedIndex')==9) {
915: eval('vf.f'+i+'.selectedIndex=0;')
916: }
917: }
918: }
919:
920: ENDPICK
921: }
922:
923: ###############################################################
924: ###############################################################
925: sub upload_manager_javascript_reverse_associate {
1.123 raeburn 926: my ($can_assign) = @_;
1.132 raeburn 927: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 928: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 929: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
930: $argreset .= " vf.krbarg.value='';\n";
931: $numbuttons ++ ;
932: }
933: if ($can_assign->{'int'}) {
934: $argreset .= " vf.intarg.value='';\n";
935: $numbuttons ++;
936: }
937: if ($can_assign->{'loc'}) {
938: $argreset .= " vf.locarg.value='';\n";
939: $numbuttons ++;
940: }
941: if (!$can_assign->{'int'}) {
942: my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
943: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 944: &js_escape(\$warning);
1.132 raeburn 945: $auth_update = <<"END";
946: // Currently the initial password field is only supported for internal auth
947: // (see bug 6368).
948: if (tf==8 && nw!=0) {
949: eval('vf.f'+tf+'.selectedIndex=0;')
950: alert('$warning');
951: }
952: END
953: } elsif ($numbuttons > 1) {
1.123 raeburn 954: $auth_update = <<"END";
955: // initial password specified, pick internal authentication
956: if (tf==8 && nw!=0) {
957: changed_radio('int',document.studentform);
958: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 959: $argreset
960: }
961:
1.123 raeburn 962: END
963: }
964: }
1.132 raeburn 965:
1.1 raeburn 966: return(<<ENDPICK);
967: function verify(vf,sec_caller) {
968: var founduname=0;
969: var foundpwd=0;
970: var foundname=0;
971: var foundid=0;
972: var foundsec=0;
1.131 raeburn 973: var foundemail=0;
1.1 raeburn 974: var foundrole=0;
1.57 raeburn 975: var founddomain=0;
1.84 raeburn 976: var foundinststatus=0;
1.150 raeburn 977: var foundcredits=0;
1.1 raeburn 978: var tw;
979: for (i=0;i<=vf.nfields.value;i++) {
980: tw=eval('vf.f'+i+'.selectedIndex');
981: if (i==0 && tw!=0) { founduname=1; }
982: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
983: if (i==6 && tw!=0) { foundid=1; }
984: if (i==7 && tw!=0) { foundsec=1; }
985: if (i==8 && tw!=0) { foundpwd=1; }
1.130 raeburn 986: if (i==9 && tw!=0) { foundemail=1; }
987: if (i==10 && tw!=0) { foundrole=1; }
988: if (i==11 && tw!=0) { founddomain=1; }
989: if (i==12 && tw!=0) { foundinstatus=1; }
1.150 raeburn 990: if (i==13 && tw!=0) { foundcredits=1; }
1.1 raeburn 991: }
1.150 raeburn 992: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 993: }
994:
995: function flip(vf,tf) {
996: var nw=eval('vf.f'+tf+'.selectedIndex');
997: var i;
998: // picked the all one name field, reset the other name ones to blank
999: if (tf==1 && nw!=0) {
1000: for (i=2;i<=5;i++) {
1001: eval('vf.f'+i+'.selectedIndex=0;')
1002: }
1003: }
1004: //picked one of the piecewise name fields, reset the all in
1005: //one field to blank
1006: if ((tf>=2) && (tf<=5) && (nw!=0)) {
1007: eval('vf.f1.selectedIndex=0;')
1008: }
1.123 raeburn 1009: $auth_update
1.1 raeburn 1010: }
1011:
1012: function clearpwd(vf) {
1013: var i;
1014: if (eval('vf.f8.selectedIndex')!=0) {
1015: eval('vf.f8.selectedIndex=0;')
1016: }
1017: }
1018: ENDPICK
1019: }
1020:
1021: ###############################################################
1022: ###############################################################
1023: sub print_upload_manager_footer {
1.150 raeburn 1024: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype,
1025: $showcredits) = @_;
1.22 raeburn 1026: my $form = 'document.studentform';
1027: my $formname = 'studentform';
1.1 raeburn 1028: my ($krbdef,$krbdefdom) =
1029: &Apache::loncommon::get_kerberos_defaults($defdom);
1.22 raeburn 1030: my %param = ( formname => $form,
1.1 raeburn 1031: kerb_def_dom => $krbdefdom,
1032: kerb_def_auth => $krbdef
1033: );
1034: if (exists($env{'form.ipwd_choice'}) &&
1035: defined($env{'form.ipwd_choice'}) &&
1036: $env{'form.ipwd_choice'} ne '') {
1037: $param{'curr_authtype'} = 'int';
1038: }
1039: my $krbform = &Apache::loncommon::authform_kerberos(%param);
1040: my $intform = &Apache::loncommon::authform_internal(%param);
1041: my $locform = &Apache::loncommon::authform_local(%param);
1.194 raeburn 1042: my $ltiform = &Apache::loncommon::authform_lti(%param);
1.22 raeburn 1043: my $date_table = &date_setting_table(undef,undef,$context,undef,
1.101 raeburn 1044: $formname,$permission,$crstype);
1.95 bisitz 1045:
1.1 raeburn 1046: my $Str = "\n".'<div class="LC_left_float">';
1047: $Str .= &hidden_input('nfields',$i);
1048: $Str .= &hidden_input('keyfields',$keyfields);
1.95 bisitz 1049:
1050: $Str .= '<h3>'.&mt('Options').'</h3>'
1051: .&Apache::lonhtmlcommon::start_pick_box();
1052:
1053: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type'));
1.1 raeburn 1054: if ($context eq 'domain') {
1.95 bisitz 1055: $Str .= '<p>'
1056: .&mt('Change authentication for existing users in domain "[_1]" to these settings?'
1057: ,$defdom)
1058: .' <span class="LC_nobreak"><label>'
1059: .'<input type="radio" name="changeauth" value="No" checked="checked" />'
1060: .&mt('No').'</label>'
1061: .' <label>'
1062: .'<input type="radio" name="changeauth" value="Yes" />'
1063: .&mt('Yes').'</label>'
1064: .'</span></p>';
1.1 raeburn 1065: } else {
1.95 bisitz 1066: $Str .= '<p class="LC_info">'."\n".
1067: &mt('This will not take effect if the user already exists.').
1.1 raeburn 1068: &Apache::loncommon::help_open_topic('Auth_Options').
1069: "</p>\n";
1070: }
1.194 raeburn 1071: $Str .= &set_login($defdom,$krbform,$intform,$locform,$ltiform);
1.95 bisitz 1072:
1.1 raeburn 1073: my ($home_server_pick,$numlib) =
1074: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
1075: 'default','hide');
1076: if ($numlib > 1) {
1.97 raeburn 1077: $Str .= &Apache::lonhtmlcommon::row_closure()
1078: .&Apache::lonhtmlcommon::row_title(
1.95 bisitz 1079: &mt('LON-CAPA Home Server for New Users'))
1080: .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
1081: .$home_server_pick
1082: .&Apache::lonhtmlcommon::row_closure();
1083: } else {
1.97 raeburn 1084: $Str .= $home_server_pick.
1085: &Apache::lonhtmlcommon::row_closure();
1.95 bisitz 1086: }
1087:
1.188 raeburn 1088: my ($trusted,$untrusted);
1.185 raeburn 1089: if ($context eq 'course') {
1.188 raeburn 1090: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.185 raeburn 1091: } elsif ($context eq 'author') {
1.188 raeburn 1092: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.185 raeburn 1093: }
1.95 bisitz 1094: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
1.188 raeburn 1095: .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trusted,$untrusted)
1.95 bisitz 1096: .&Apache::lonhtmlcommon::row_closure();
1097:
1098: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
1099: ."<p>\n".$date_table."</p>\n"
1100: .&Apache::lonhtmlcommon::row_closure();
1101:
1.1 raeburn 1102: if ($context eq 'domain') {
1.95 bisitz 1103: $Str .= &Apache::lonhtmlcommon::row_title(
1104: &mt('Settings for assigning roles'))
1105: .&mt('Pick the action to take on roles for these users:').'<br />'
1106: .'<span class="LC_nobreak"><label>'
1107: .'<input type="radio" name="roleaction" value="norole" checked="checked" />'
1108: .' '.&mt('No role changes').'</label>'
1109: .' <label>'
1110: .'<input type="radio" name="roleaction" value="domain" />'
1111: .' '.&mt('Add a domain role').'</label>'
1112: .' <label>'
1113: .'<input type="radio" name="roleaction" value="course" />'
1.103 raeburn 1114: .' '.&mt('Add a course/community role').'</label>'
1.95 bisitz 1115: .'</span>';
1116: } elsif ($context eq 'author') {
1117: $Str .= &Apache::lonhtmlcommon::row_title(
1118: &mt('Default role'))
1119: .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
1.1 raeburn 1120: } elsif ($context eq 'course') {
1.150 raeburn 1121: if ($showcredits) {
1122: $Str .= &Apache::lonhtmlcommon::row_title(
1123: &mt('Default role, section and credits'))
1124: .&mt('Choose the role and/or section(s) and/or credits to assign to users without values specified in the uploaded file.');
1125: } else {
1126: $Str .= &Apache::lonhtmlcommon::row_title(
1.95 bisitz 1127: &mt('Default role and section'))
1.150 raeburn 1128: .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
1129: }
1.95 bisitz 1130: } else {
1131: $Str .= &Apache::lonhtmlcommon::row_title(
1132: &mt('Default role and/or section(s)'))
1133: .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
1.1 raeburn 1134: }
1.22 raeburn 1135: if (($context eq 'domain') || ($context eq 'author')) {
1.95 bisitz 1136: $Str .= '<br />';
1.150 raeburn 1137: my ($options,$cb_script,$coursepick) =
1138: &default_role_selector($context,1,'',$showcredits);
1.22 raeburn 1139: if ($context eq 'domain') {
1.95 bisitz 1140: $Str .= '<p>'
1141: .'<b>'.&mt('Domain Level').'</b><br />'
1142: .$options
1143: .'</p><p>'
1144: .'<b>'.&mt('Course Level').'</b>'
1145: .'</p>'
1146: .$cb_script.$coursepick
1147: .&Apache::lonhtmlcommon::row_closure();
1.22 raeburn 1148: } elsif ($context eq 'author') {
1.95 bisitz 1149: $Str .= $options
1150: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.22 raeburn 1151: }
1.1 raeburn 1152: } else {
1.22 raeburn 1153: my ($cnum,$cdom) = &get_course_identity();
1154: my $rowtitle = &mt('section');
1.150 raeburn 1155: my $defaultcredits;
1156: if ($showcredits) {
1157: $defaultcredits = &get_defaultcredits();
1158: }
1159: my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,$permission,
1160: $context,'upload',$crstype,$showcredits,
1161: $defaultcredits);
1.95 bisitz 1162: $Str .= $secbox
1163: .&Apache::lonhtmlcommon::row_closure();
1.101 raeburn 1164: my %lt;
1165: if ($crstype eq 'Community') {
1166: %lt = &Apache::lonlocal::texthash (
1167: disp => 'Display members with current/future access who are not in the uploaded file',
1168: stus => 'Members selected from this list can be dropped.'
1169: );
1170: } else {
1171: %lt = &Apache::lonlocal::texthash (
1172: disp => 'Display students with current/future access who are not in the uploaded file',
1173: stus => 'Students selected from this list can be dropped.'
1174: );
1175: }
1.95 bisitz 1176: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
1.101 raeburn 1177: .'<label><input type="checkbox" name="fullup" value="yes" />'
1178: .' '.$lt{'disp'}
1.95 bisitz 1179: .'</label><br />'
1.101 raeburn 1180: .$lt{'stus'}
1.95 bisitz 1181: .&Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1182: }
1.5 raeburn 1183: if ($context eq 'course' || $context eq 'domain') {
1.161 bisitz 1184: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
1185: .&forceid_change($context)
1186: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.5 raeburn 1187: }
1.95 bisitz 1188:
1189: $Str .= &Apache::lonhtmlcommon::end_pick_box();
1.73 bisitz 1190: $Str .= '</div>';
1.95 bisitz 1191:
1192: # Footer
1193: $Str .= '<div class="LC_clear_float_footer">'
1194: .'<hr />';
1.1 raeburn 1195: if ($context eq 'course') {
1.95 bisitz 1196: $Str .= '<p class="LC_info">'
1.103 raeburn 1197: .&mt('Note: This operation may be time consuming when adding several users.')
1.95 bisitz 1198: .'</p>';
1.73 bisitz 1199: }
1.95 bisitz 1200: $Str .= '<p><input type="button"'
1.96 bisitz 1201: .' onclick="javascript:verify(this.form,this.form.csec)"'
1202: .' value="'.&mt('Update Users').'" />'
1.95 bisitz 1203: .'</p>'."\n"
1.73 bisitz 1204: .'</div>';
1.1 raeburn 1205: $r->print($Str);
1206: return;
1207: }
1208:
1.150 raeburn 1209: sub get_defaultcredits {
1210: my ($cdom,$cnum) = @_;
1211:
1212: if ($cdom eq '' || $cnum eq '') {
1213: return unless ($env{'request.course.id'});
1214: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1215: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1216: }
1217: return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));
1218: my ($defaultcredits,$domdefcredits);
1219: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
1.160 raeburn 1220: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 1221: my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
1222: if ($instcode) {
1223: $domdefcredits = $domdefaults{'officialcredits'};
1.160 raeburn 1224: } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) {
1225: $domdefcredits = $domdefaults{'textbookcredits'};
1.150 raeburn 1226: } else {
1227: $domdefcredits = $domdefaults{'unofficialcredits'};
1228: }
1229: } else {
1230: return;
1231: }
1232:
1233: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
1234: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1235: } elsif (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'})) {
1236: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1237: } else {
1238: my %crsinfo =
1239: &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
1240: $defaultcredits = $crsinfo{'internal.defaultcredits'};
1241: }
1242: if ($defaultcredits eq '') {
1243: $defaultcredits = $domdefcredits;
1244: }
1245: return $defaultcredits;
1246: }
1247:
1.5 raeburn 1248: sub forceid_change {
1249: my ($context) = @_;
1250: my $output =
1.161 bisitz 1251: '<label><input type="checkbox" name="forceid" value="yes" />'
1.164 bisitz 1252: .&mt('Force change of existing ID')
1.163 raeburn 1253: .'</label>'.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
1.5 raeburn 1254: if ($context eq 'domain') {
1.163 raeburn 1255: $output .=
1256: '<br />'
1257: .'<label><input type="checkbox" name="recurseid" value="yes" />'
1258: .&mt("Update ID in user's course(s).").'</label>'."\n";
1.5 raeburn 1259: }
1260: return $output;
1261: }
1262:
1.1 raeburn 1263: ###############################################################
1264: ###############################################################
1265: sub print_upload_manager_form {
1.150 raeburn 1266: my ($r,$context,$permission,$crstype,$showcredits) = @_;
1.1 raeburn 1267: my $firstLine;
1268: my $datatoken;
1269: if (!$env{'form.datatoken'}) {
1270: $datatoken=&Apache::loncommon::upfile_store($r);
1271: } else {
1.189 raeburn 1272: $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
1273: if ($datatoken ne '') {
1274: &Apache::loncommon::load_tmp_file($r,$datatoken);
1275: }
1.1 raeburn 1276: }
1.193 raeburn 1277: if ($datatoken eq '') {
1278: $r->print('<p class="LC_error">'.&mt('Error').': '.
1279: &mt('Invalid datatoken').'</p>');
1280: return 'missingdata';
1281: }
1.1 raeburn 1282: my @records=&Apache::loncommon::upfile_record_sep();
1283: if($env{'form.noFirstLine'}){
1284: $firstLine=shift(@records);
1285: }
1286: my $total=$#records;
1287: my $distotal=$total+1;
1288: my $today=time;
1289: my $halfyear=$today+15552000;
1290: #
1291: # Restore memorized settings
1292: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
1293: 'names_choice' => 'scalar',
1294: 'fname_choice' => 'scalar',
1295: 'mname_choice' => 'scalar',
1296: 'lname_choice' => 'scalar',
1297: 'gen_choice' => 'scalar',
1298: 'id_choice' => 'scalar',
1299: 'sec_choice' => 'scalar',
1300: 'ipwd_choice' => 'scalar',
1301: 'email_choice' => 'scalar',
1302: 'role_choice' => 'scalar',
1.57 raeburn 1303: 'domain_choice' => 'scalar',
1.84 raeburn 1304: 'inststatus_choice' => 'scalar',
1.1 raeburn 1305: };
1.150 raeburn 1306: if ($showcredits) {
1307: $col_setting_names->{'credits_choice'} = 'scalar';
1308: }
1.1 raeburn 1309: if ($context eq 'course') {
1310: &Apache::loncommon::restore_course_settings('enrollment_upload',
1311: $col_setting_names);
1312: } else {
1313: &Apache::loncommon::restore_settings($context,'user_upload',
1314: $col_setting_names);
1315: }
1.150 raeburn 1316: my $defdom = $env{'request.role.domain'};
1.1 raeburn 1317: #
1318: # Determine kerberos parameters as appropriate
1319: my ($krbdef,$krbdefdom) =
1320: &Apache::loncommon::get_kerberos_defaults($defdom);
1321: #
1.123 raeburn 1322: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
1.22 raeburn 1323: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
1.123 raeburn 1324: $permission,$crstype,\%can_assign);
1.1 raeburn 1325: my $i;
1326: my $keyfields;
1327: if ($total>=0) {
1328: my @field=
1329: (['username',&mt('Username'), $env{'form.username_choice'}],
1330: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
1331: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
1332: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
1333: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
1334: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
1.61 bisitz 1335: ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
1.1 raeburn 1336: ['sec', &mt('Section'), $env{'form.sec_choice'}],
1337: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
1338: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
1.57 raeburn 1339: ['role',&mt('Role'), $env{'form.role_choice'}],
1.84 raeburn 1340: ['domain',&mt('Domain'), $env{'form.domain_choice'}],
1341: ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
1.150 raeburn 1342: if ($showcredits) {
1343: push(@field,
1344: ['credits',&mt('Student Credits'), $env{'form.credits_choice'}]);
1345: }
1.1 raeburn 1346: if ($env{'form.upfile_associate'} eq 'reverse') {
1347: &Apache::loncommon::csv_print_samples($r,\@records);
1348: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
1349: \@field);
1350: foreach (@field) {
1351: $keyfields.=$_->[0].',';
1352: }
1353: chop($keyfields);
1354: } else {
1355: unshift(@field,['none','']);
1356: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
1357: \@field);
1358: my %sone=&Apache::loncommon::record_sep($records[0]);
1359: $keyfields=join(',',sort(keys(%sone)));
1360: }
1361: }
1362: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
1.150 raeburn 1363: $context,$permission,$crstype,$showcredits);
1.193 raeburn 1364: return 'ok';
1.1 raeburn 1365: }
1366:
1367: sub setup_date_selectors {
1.22 raeburn 1368: my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
1369: if ($formname eq '') {
1370: $formname = 'studentform';
1371: }
1.1 raeburn 1372: if (! defined($starttime)) {
1373: $starttime = time;
1374: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1375: if (exists($env{'course.'.$env{'request.course.id'}.
1376: '.default_enrollment_start_date'})) {
1377: $starttime = $env{'course.'.$env{'request.course.id'}.
1378: '.default_enrollment_start_date'};
1379: }
1380: }
1381: }
1382: if (! defined($endtime)) {
1383: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1384: unless ($mode eq 'createcourse') {
1385: if (exists($env{'course.'.$env{'request.course.id'}.
1386: '.default_enrollment_end_date'})) {
1387: $endtime = $env{'course.'.$env{'request.course.id'}.
1388: '.default_enrollment_end_date'};
1389: }
1390: }
1391: }
1.11 raeburn 1392:
1393: my $startdateform =
1.22 raeburn 1394: &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
1.11 raeburn 1395: undef,undef,undef,undef,undef,undef,undef,$nolink);
1396:
1397: my $enddateform =
1.22 raeburn 1398: &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
1.11 raeburn 1399: undef,undef,undef,undef,undef,undef,undef,$nolink);
1400:
1.1 raeburn 1401: if ($mode eq 'create_enrolldates') {
1402: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1403: 'startenroll',
1404: $starttime);
1405: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1406: 'endenroll',
1407: $endtime);
1408: }
1409: if ($mode eq 'create_defaultdates') {
1410: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1411: 'startaccess',
1412: $starttime);
1413: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1414: 'endaccess',
1415: $endtime);
1416: }
1417: return ($startdateform,$enddateform);
1418: }
1419:
1420:
1421: sub get_dates_from_form {
1.54 raeburn 1422: my ($startname,$endname) = @_;
1423: if ($startname eq '') {
1424: $startname = 'startdate';
1425: }
1426: if ($endname eq '') {
1427: $endname = 'enddate';
1428: }
1429: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1430: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.1 raeburn 1431: if ($env{'form.no_end_date'}) {
1432: $enddate = 0;
1433: }
1434: return ($startdate,$enddate);
1435: }
1436:
1437: sub date_setting_table {
1.101 raeburn 1438: my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
1.11 raeburn 1439: my $nolink;
1440: if ($bulkaction) {
1441: $nolink = 1;
1442: }
1443: my ($startform,$endform) =
1.22 raeburn 1444: &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
1.1 raeburn 1445: my $dateDefault;
1446: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1447: $dateDefault = ' ';
1.13 raeburn 1448: } elsif ($mode ne 'author' && $mode ne 'domain') {
1.11 raeburn 1449: if (($bulkaction eq 'reenable') ||
1450: ($bulkaction eq 'activate') ||
1.22 raeburn 1451: ($bulkaction eq 'chgdates') ||
1452: ($env{'form.action'} eq 'upload')) {
1453: if ($env{'request.course.sec'} eq '') {
1454: $dateDefault = '<span class="LC_nobreak">'.
1.101 raeburn 1455: '<label><input type="checkbox" name="makedatesdefault" value="1" /> ';
1456: if ($crstype eq 'Community') {
1457: $dateDefault .= &mt("make these dates the default access dates for future community enrollment");
1458: } else {
1459: $dateDefault .= &mt("make these dates the default access dates for future course enrollment");
1460: }
1461: $dateDefault .= '</label></span>';
1.22 raeburn 1462: }
1.11 raeburn 1463: }
1.1 raeburn 1464: }
1.11 raeburn 1465: my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1.1 raeburn 1466: if (defined($endtime) && $endtime == 0) {
1.70 bisitz 1467: $perpetual .= ' checked="checked"';
1.1 raeburn 1468: }
1.11 raeburn 1469: $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
1.1 raeburn 1470: if ($mode eq 'create_enrolldates') {
1471: $perpetual = ' ';
1472: }
1.11 raeburn 1473: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
1474: $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
1475: 'LC_oddrow_value')."\n".
1476: $startform."\n".
1477: &Apache::lonhtmlcommon::row_closure(1).
1478: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
1479: 'LC_oddrow_value')."\n".
1480: $endform.' '.$perpetual.
1481: &Apache::lonhtmlcommon::row_closure(1).
1.22 raeburn 1482: &Apache::lonhtmlcommon::end_pick_box();
1.1 raeburn 1483: if ($dateDefault) {
1484: $result .= $dateDefault.'<br />'."\n";
1485: }
1486: return $result;
1487: }
1488:
1489: sub make_dates_default {
1.101 raeburn 1490: my ($startdate,$enddate,$context,$crstype) = @_;
1.1 raeburn 1491: my $result = '';
1492: if ($context eq 'course') {
1.17 raeburn 1493: my ($cnum,$cdom) = &get_course_identity();
1.1 raeburn 1494: my $put_result = &Apache::lonnet::put('environment',
1495: {'default_enrollment_start_date'=>$startdate,
1.17 raeburn 1496: 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
1.1 raeburn 1497: if ($put_result eq 'ok') {
1.101 raeburn 1498: if ($crstype eq 'Community') {
1499: $result .= &mt('Set default start and end access dates for community.');
1500: } else {
1501: $result .= &mt('Set default start and end access dates for course.');
1502: }
1503: $result .= '<br />'."\n";
1.1 raeburn 1504: #
1505: # Refresh the course environment
1506: &Apache::lonnet::coursedescription($env{'request.course.id'},
1507: {'freshen_cache' => 1});
1508: } else {
1.101 raeburn 1509: if ($crstype eq 'Community') {
1510: $result .= &mt('Unable to set default access dates for community');
1511: } else {
1512: $result .= &mt('Unable to set default access dates for course');
1513: }
1514: $result .= ':'.$put_result.'<br />';
1.1 raeburn 1515: }
1516: }
1517: return $result;
1518: }
1519:
1520: sub default_role_selector {
1.150 raeburn 1521: my ($context,$checkpriv,$crstype,$showcredits) = @_;
1.1 raeburn 1522: my %customroles;
1523: my ($options,$coursepick,$cb_jscript);
1.13 raeburn 1524: if ($context ne 'author') {
1.104 raeburn 1525: %customroles = &my_custom_roles($crstype);
1.1 raeburn 1526: }
1527:
1528: my %lt=&Apache::lonlocal::texthash(
1529: 'rol' => "Role",
1530: 'grs' => "Section",
1531: 'exs' => "Existing sections",
1532: 'new' => "New section",
1.150 raeburn 1533: 'crd' => "Credits",
1.1 raeburn 1534: );
1535: $options = '<select name="defaultrole">'."\n".
1536: ' <option value="">'.&mt('Please select').'</option>'."\n";
1537: if ($context eq 'course') {
1.101 raeburn 1538: $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
1.13 raeburn 1539: } elsif ($context eq 'author') {
1.2 raeburn 1540: my @roles = &construction_space_roles($checkpriv);
1.1 raeburn 1541: foreach my $role (@roles) {
1542: my $plrole=&Apache::lonnet::plaintext($role);
1543: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1544: }
1545: } elsif ($context eq 'domain') {
1.2 raeburn 1546: my @roles = &domain_roles($checkpriv);
1.1 raeburn 1547: foreach my $role (@roles) {
1548: my $plrole=&Apache::lonnet::plaintext($role);
1549: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
1550: }
1551: my $courseform = &Apache::loncommon::selectcourse_link
1.103 raeburn 1552: ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
1.150 raeburn 1553: my ($credit_elem,$creditsinput);
1554: if ($showcredits) {
1555: $credit_elem = 'credits';
1556: $creditsinput = '<td><input type="text" name="credits" value="" /></td>';
1557: }
1.1 raeburn 1558: $cb_jscript =
1.150 raeburn 1559: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community',$credit_elem);
1.1 raeburn 1560: $coursepick = &Apache::loncommon::start_data_table().
1561: &Apache::loncommon::start_data_table_header_row().
1562: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
1563: '<th>'.$lt{'grs'}.'</th>'.
1.150 raeburn 1564: '<th>'.$lt{'crd'}.'</th>'.
1.1 raeburn 1565: &Apache::loncommon::end_data_table_header_row().
1566: &Apache::loncommon::start_data_table_row()."\n".
1.103 raeburn 1567: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
1.1 raeburn 1568: '<td><select name="courserole">'."\n".
1.101 raeburn 1569: &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
1.1 raeburn 1570: '</select></td><td>'.
1571: '<table class="LC_createuser">'.
1.162 bisitz 1572: '<tr class="LC_section_row"><td valign="top">'.
1.22 raeburn 1573: $lt{'exs'}.'<br /><select name="currsec">'.
1.162 bisitz 1574: ' <option value=""><--'.&mt('Pick course first').
1.1 raeburn 1575: '</select></td>'.
1576: '<td> </td>'.
1577: '<td valign="top">'.$lt{'new'}.'<br />'.
1578: '<input type="text" name="newsec" value="" size="5" />'.
1.22 raeburn 1579: '<input type="hidden" name="groups" value="" />'.
1580: '<input type="hidden" name="sections" value="" />'.
1581: '<input type="hidden" name="origdom" value="'.
1582: $env{'request.role.domain'}.'" />'.
1583: '<input type="hidden" name="dccourse" value="" />'.
1584: '<input type="hidden" name="dcdomain" value="" />'.
1.103 raeburn 1585: '<input type="hidden" name="crstype" value="" />'.
1.150 raeburn 1586: '</td></tr></table></td>'.$creditsinput.
1.1 raeburn 1587: &Apache::loncommon::end_data_table_row().
1.22 raeburn 1588: &Apache::loncommon::end_data_table()."\n";
1.1 raeburn 1589: }
1590: $options .= '</select>';
1591: return ($options,$cb_jscript,$coursepick);
1592: }
1593:
1594: sub default_course_roles {
1.101 raeburn 1595: my ($context,$checkpriv,$crstype,%customroles) = @_;
1.1 raeburn 1596: my $output;
1.17 raeburn 1597: my $custom = 1;
1.101 raeburn 1598: my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype));
1.1 raeburn 1599: foreach my $role (@roles) {
1.22 raeburn 1600: if ($role ne 'cr') {
1.101 raeburn 1601: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.22 raeburn 1602: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
1603: }
1.1 raeburn 1604: }
1605: if (keys(%customroles) > 0) {
1.22 raeburn 1606: if (grep(/^cr$/,@roles)) {
1607: foreach my $cust (sort(keys(%customroles))) {
1608: my $custrole='cr_'.$env{'user.domain'}.
1609: '_'.$env{'user.name'}.'_'.$cust;
1610: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1611: }
1.1 raeburn 1612: }
1613: }
1614: return $output;
1615: }
1616:
1617: sub construction_space_roles {
1.2 raeburn 1618: my ($checkpriv) = @_;
1.17 raeburn 1619: my @allroles = &roles_by_context('author');
1.1 raeburn 1620: my @roles;
1.2 raeburn 1621: if ($checkpriv) {
1622: foreach my $role (@allroles) {
1623: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
1624: push(@roles,$role);
1625: }
1.1 raeburn 1626: }
1.2 raeburn 1627: return @roles;
1628: } else {
1629: return @allroles;
1.1 raeburn 1630: }
1631: }
1632:
1633: sub domain_roles {
1.2 raeburn 1634: my ($checkpriv) = @_;
1.17 raeburn 1635: my @allroles = &roles_by_context('domain');
1.1 raeburn 1636: my @roles;
1.2 raeburn 1637: if ($checkpriv) {
1638: foreach my $role (@allroles) {
1639: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
1640: push(@roles,$role);
1641: }
1.1 raeburn 1642: }
1.2 raeburn 1643: return @roles;
1644: } else {
1645: return @allroles;
1.1 raeburn 1646: }
1647: }
1648:
1649: sub course_roles {
1.101 raeburn 1650: my ($context,$checkpriv,$custom,$roletype) = @_;
1.102 raeburn 1651: my $crstype;
1652: if ($roletype eq 'community') {
1653: $crstype = 'Community' ;
1654: } else {
1655: $crstype = 'Course';
1656: }
1657: my @allroles = &roles_by_context('course',$custom,$crstype);
1.1 raeburn 1658: my @roles;
1659: if ($context eq 'domain') {
1660: @roles = @allroles;
1661: } elsif ($context eq 'course') {
1662: if ($env{'request.course.id'}) {
1.2 raeburn 1663: if ($checkpriv) {
1664: foreach my $role (@allroles) {
1665: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
1666: push(@roles,$role);
1667: } else {
1.101 raeburn 1668: if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) {
1.22 raeburn 1669: if (&Apache::lonnet::allowed('c'.$role,
1.2 raeburn 1670: $env{'request.course.id'}.'/'.
1.22 raeburn 1671: $env{'request.course.sec'})) {
1.2 raeburn 1672: push(@roles,$role);
1673: }
1.1 raeburn 1674: }
1675: }
1676: }
1.2 raeburn 1677: } else {
1678: @roles = @allroles;
1.1 raeburn 1679: }
1680: }
1681: }
1682: return @roles;
1683: }
1684:
1685: sub curr_role_permissions {
1.101 raeburn 1686: my ($context,$setting,$checkpriv,$type) = @_;
1.17 raeburn 1687: my $custom = 1;
1.1 raeburn 1688: my @roles;
1.13 raeburn 1689: if ($context eq 'author') {
1.2 raeburn 1690: @roles = &construction_space_roles($checkpriv);
1.1 raeburn 1691: } elsif ($context eq 'domain') {
1692: if ($setting eq 'course') {
1.101 raeburn 1693: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 1694: } else {
1.2 raeburn 1695: @roles = &domain_roles($checkpriv);
1.1 raeburn 1696: }
1697: } elsif ($context eq 'course') {
1.101 raeburn 1698: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 1699: }
1700: return @roles;
1701: }
1702:
1703: # ======================================================= Existing Custom Roles
1704:
1705: sub my_custom_roles {
1.175 raeburn 1706: my ($crstype,$udom,$uname) = @_;
1.1 raeburn 1707: my %returnhash=();
1.137 raeburn 1708: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
1.175 raeburn 1709: my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
1.104 raeburn 1710: foreach my $key (keys(%rolehash)) {
1.1 raeburn 1711: if ($key=~/^rolesdef\_(\w+)$/) {
1.104 raeburn 1712: if ($crstype eq 'Community') {
1713: next if ($rolehash{$key} =~ /bre\&S/);
1714: }
1.1 raeburn 1715: $returnhash{$1}=$1;
1716: }
1717: }
1718: return %returnhash;
1719: }
1720:
1.2 raeburn 1721: sub print_userlist {
1722: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1.150 raeburn 1723: $idlist,$idlist_titles,$showcredits) = @_;
1.2 raeburn 1724: my $format = $env{'form.output'};
1.1 raeburn 1725: if (! exists($env{'form.sortby'})) {
1726: $env{'form.sortby'} = 'username';
1727: }
1.2 raeburn 1728: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
1729: $env{'form.Status'} = 'Active';
1.1 raeburn 1730: }
1.140 raeburn 1731: my $onchange = "javascript:updateCols('Status');";
1.1 raeburn 1732: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1.140 raeburn 1733: ($env{'form.Status'},undef,undef,$onchange);
1.1 raeburn 1734:
1.2 raeburn 1735: if ($env{'form.showrole'} eq '') {
1.13 raeburn 1736: if ($context eq 'course') {
1737: $env{'form.showrole'} = 'st';
1738: } else {
1739: $env{'form.showrole'} = 'Any';
1740: }
1.2 raeburn 1741: }
1.1 raeburn 1742: if (! defined($env{'form.output'}) ||
1743: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
1744: $env{'form.output'} = 'html';
1745: }
1746:
1.2 raeburn 1747: my @statuses;
1748: if ($env{'form.Status'} eq 'Any') {
1749: @statuses = ('previous','active','future');
1750: } elsif ($env{'form.Status'} eq 'Expired') {
1751: @statuses = ('previous');
1752: } elsif ($env{'form.Status'} eq 'Active') {
1753: @statuses = ('active');
1754: } elsif ($env{'form.Status'} eq 'Future') {
1755: @statuses = ('future');
1756: }
1.1 raeburn 1757:
1758: # Interface output
1.2 raeburn 1759: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
1760: '<input type="hidden" name="action" value="'.
1.1 raeburn 1761: $env{'form.action'}.'" />');
1.140 raeburn 1762: $r->print('<div>'."\n");
1.1 raeburn 1763: if ($env{'form.action'} ne 'modifystudent') {
1764: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
1765: 'excel' => "Excel",
1766: 'html' => 'HTML');
1.140 raeburn 1767: my $output_selector = '<select size="1" name="output" onchange="javascript:updateCols('."'output'".');" >';
1.1 raeburn 1768: foreach my $outputformat ('html','csv','excel') {
1.96 bisitz 1769: my $option = '<option value="'.$outputformat.'"';
1.1 raeburn 1770: if ($outputformat eq $env{'form.output'}) {
1.96 bisitz 1771: $option .= ' selected="selected"';
1.1 raeburn 1772: }
1773: $option .='>'.$lt{$outputformat}.'</option>';
1774: $output_selector .= "\n".$option;
1775: }
1776: $output_selector .= '</select>';
1.140 raeburn 1777: $r->print('<span class="LC_nobreak">'
1.70 bisitz 1778: .&mt('Output Format: [_1]',$output_selector)
1.140 raeburn 1779: .'</span>'.(' 'x3));
1.70 bisitz 1780: }
1.140 raeburn 1781: $r->print('<span class="LC_nobreak">'
1.70 bisitz 1782: .&mt('User Status: [_1]',$status_select)
1.140 raeburn 1783: .'</span>'.(' 'x3)."\n");
1.2 raeburn 1784: my $roleselected = '';
1785: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 1786: $roleselected = ' selected="selected"';
1.2 raeburn 1787: }
1.53 raeburn 1788: my ($cnum,$cdom);
1789: $r->print(&role_filter($context));
1790: if ($context eq 'course') {
1791: ($cnum,$cdom) = &get_course_identity();
1792: $r->print(§ion_group_filter($cnum,$cdom));
1.2 raeburn 1793: }
1.140 raeburn 1794: $r->print('</div><div class="LC_left_float">'.
1.150 raeburn 1795: &column_checkboxes($context,$mode,$formname,$showcredits).
1.149 raeburn 1796: '</div>');
1.78 raeburn 1797: if ($env{'form.phase'} eq '') {
1.149 raeburn 1798: $r->print('<br clear="all" />'.
1799: &list_submit_button(&mt('Display List of Users'))."\n".
1.78 raeburn 1800: '<input type="hidden" name="phase" value="" /></form>');
1801: return;
1802: }
1.106 raeburn 1803: if (!(($context eq 'domain') &&
1804: (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
1.149 raeburn 1805: $r->print('<br clear="all" />'.
1806: &list_submit_button(&mt('Update Display'))."\n");
1.140 raeburn 1807: }
1808:
1.150 raeburn 1809: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 1810: if (!@cols) {
1.152 bisitz 1811: $r->print('<hr style="clear:both;" /><span class="LC_warning">'.
1.140 raeburn 1812: &mt('No user information selected for display.').'</span>'.
1813: '<input type="hidden" name="phase" value="display" /></form>'."\n");
1814: return;
1.2 raeburn 1815: }
1816: my ($indexhash,$keylist) = &make_keylist_array();
1.159 raeburn 1817: my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
1.102 raeburn 1818: if (($context eq 'domain') &&
1819: ($env{'form.roletype'} eq 'course') ||
1820: ($env{'form.roletype'} eq 'community')) {
1821: my ($crstype,$numcodes,$title,$warning);
1822: if ($env{'form.roletype'} eq 'course') {
1823: $crstype = 'Course';
1824: $numcodes = $totcodes;
1825: $title = &mt('Select Courses');
1826: $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
1827: } elsif ($env{'form.roletype'} eq 'community') {
1828: $crstype = 'Community';
1829: $numcodes = 0;
1830: $title = &mt('Select Communities');
1831: $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
1832: }
1.120 raeburn 1833: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.3 raeburn 1834: my $courseform =
1.102 raeburn 1835: &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
1.120 raeburn 1836: $codetitles,$idlist,$idlist_titles,$crstype,
1837: \@standardnames);
1.148 bisitz 1838: $r->print('<div class="LC_left_float">'.
1839: '<fieldset><legend>'.$title.'</legend>'."\n".
1.3 raeburn 1840: $courseform."\n".
1.148 bisitz 1841: '</fieldset></div><br clear="all" />'.
1.106 raeburn 1842: '<p><input type="hidden" name="origroletype" value="'.$env{'form.roletype'}.'" />'.
1843: &list_submit_button(&mt('Update Display')).
1.102 raeburn 1844: "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
1.106 raeburn 1845: $clearcoursepick = 0;
1846: if (($env{'form.origroletype'} ne '') &&
1847: ($env{'form.origroletype'} ne $env{'form.roletype'})) {
1848: $clearcoursepick = 1;
1849: }
1850: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.147 bisitz 1851: $r->print('<hr />'.&mt('Searching ...').'<br /> <br />');
1.11 raeburn 1852: }
1853: } else {
1.152 bisitz 1854: $r->print('<hr style="clear:both;" /><div id="searching">'.&mt('Searching ...').'</div>');
1.3 raeburn 1855: }
1856: $r->rflush();
1.1 raeburn 1857: if ($context eq 'course') {
1.46 raeburn 1858: if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
1.45 raeburn 1859: my $classlist = &Apache::loncoursedata::get_classlist();
1.66 raeburn 1860: if (ref($classlist) eq 'HASH') {
1861: %userlist = %{$classlist};
1862: }
1.45 raeburn 1863: }
1.43 raeburn 1864: if ($env{'form.showrole'} ne 'st') {
1865: my $showroles;
1866: if ($env{'form.showrole'} ne 'Any') {
1867: $showroles = [$env{'form.showrole'}];
1.3 raeburn 1868: } else {
1.43 raeburn 1869: $showroles = undef;
1.1 raeburn 1870: }
1.43 raeburn 1871: my $withsec = 1;
1872: my $hidepriv = 1;
1873: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
1874: \@statuses,$showroles,undef,$withsec,$hidepriv);
1875: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1876: \%advrolehash,$permission);
1.1 raeburn 1877: }
1.2 raeburn 1878: } else {
1879: my (%cstr_roles,%dom_roles);
1.13 raeburn 1880: if ($context eq 'author') {
1.2 raeburn 1881: # List co-authors and assistant co-authors
1.17 raeburn 1882: my @possroles = &roles_by_context($context);
1.2 raeburn 1883: %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
1884: \@statuses,\@possroles);
1885: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1.11 raeburn 1886: \%cstr_roles,$permission);
1.2 raeburn 1887: } elsif ($context eq 'domain') {
1888: if ($env{'form.roletype'} eq 'domain') {
1.159 raeburn 1889: if (grep(/^authorusage$/,@cols)) {
1890: $needauthorusage = 1;
1891: }
1892: if (grep(/^authorquota$/,@cols)) {
1893: $needauthorquota = 1;
1894: }
1.2 raeburn 1895: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
1896: foreach my $key (keys(%dom_roles)) {
1897: if (ref($dom_roles{$key}) eq 'HASH') {
1898: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 1899: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 1900: }
1901: }
1.13 raeburn 1902: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 1903: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
1904: my %coauthors;
1905: foreach my $key (keys(%dom_roles)) {
1906: if (ref($dom_roles{$key}) eq 'HASH') {
1907: if ($env{'form.showrole'} eq 'au') {
1908: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 1909: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 1910: } else {
1911: my @possroles;
1912: if ($env{'form.showrole'} eq 'Any') {
1.22 raeburn 1913: @possroles = &roles_by_context('author');
1.2 raeburn 1914: } else {
1915: @possroles = ($env{'form.showrole'});
1916: }
1917: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1.22 raeburn 1918: my ($role,$authorname,$authordom) = split(/:/,$author,-1);
1.2 raeburn 1919: my $extent = '/'.$authordom.'/'.$authorname;
1920: %{$coauthors{$extent}} =
1921: &Apache::lonnet::get_my_roles($authorname,
1922: $authordom,undef,\@statuses,\@possroles);
1923: }
1924: &gather_userinfo($context,$format,\%userlist,
1.11 raeburn 1925: $indexhash,\%userinfo,\%coauthors,$permission);
1.2 raeburn 1926: }
1927: }
1928: }
1.101 raeburn 1929: } elsif (($env{'form.roletype'} eq 'course') ||
1930: ($env{'form.roletype'} eq 'community')) {
1.106 raeburn 1931: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.2 raeburn 1932: my %courses = &process_coursepick();
1.39 raeburn 1933: my %allusers;
1934: my $hidepriv = 1;
1.2 raeburn 1935: foreach my $cid (keys(%courses)) {
1.17 raeburn 1936: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
1.11 raeburn 1937: next if ($cnum eq '' || $cdom eq '');
1.17 raeburn 1938: my $custom = 1;
1.2 raeburn 1939: my (@roles,@sections,%access,%users,%userdata,
1.6 albertel 1940: %statushash);
1.2 raeburn 1941: if ($env{'form.showrole'} eq 'Any') {
1.101 raeburn 1942: @roles = &course_roles($context,undef,$custom,
1943: $env{'form.roletype'});
1.2 raeburn 1944: } else {
1945: @roles = ($env{'form.showrole'});
1946: }
1947: foreach my $role (@roles) {
1948: %{$users{$role}} = ();
1949: }
1950: foreach my $type (@statuses) {
1951: $access{$type} = $type;
1952: }
1.39 raeburn 1953: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
1.2 raeburn 1954: foreach my $user (keys(%userdata)) {
1955: next if (ref($userinfo{$user}) eq 'HASH');
1956: foreach my $item ('fullname','id') {
1957: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
1958: }
1959: }
1960: foreach my $role (keys(%users)) {
1961: foreach my $user (keys(%{$users{$role}})) {
1962: my $uniqid = $user.':'.$role;
1963: $allusers{$uniqid}{$cid} = { desc => $cdesc,
1964: secs => $statushash{$user}{$role},
1965: };
1966: }
1967: }
1968: }
1969: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 1970: \%userinfo,\%allusers,$permission);
1.2 raeburn 1971: } else {
1.10 raeburn 1972: $r->print('<input type="hidden" name="phase" value="'.
1973: $env{'form.phase'}.'" /></form>');
1.2 raeburn 1974: return;
1975: }
1.1 raeburn 1976: }
1977: }
1.3 raeburn 1978: }
1979: if (keys(%userlist) == 0) {
1.142 bisitz 1980: my $msg = '';
1.13 raeburn 1981: if ($context eq 'author') {
1.142 bisitz 1982: $msg = &mt('There are no co-authors to display.');
1.3 raeburn 1983: } elsif ($context eq 'domain') {
1984: if ($env{'form.roletype'} eq 'domain') {
1.142 bisitz 1985: $msg = &mt('There are no users with domain roles to display.');
1.13 raeburn 1986: } elsif ($env{'form.roletype'} eq 'author') {
1.142 bisitz 1987: $msg = &mt('There are no authors or co-authors to display.');
1.3 raeburn 1988: } elsif ($env{'form.roletype'} eq 'course') {
1.142 bisitz 1989: $msg = &mt('There are no course users to display');
1.101 raeburn 1990: } elsif ($env{'form.roletype'} eq 'community') {
1.142 bisitz 1991: $msg = &mt('There are no community users to display');
1.2 raeburn 1992: }
1.3 raeburn 1993: } elsif ($context eq 'course') {
1994: $r->print(&mt('There are no course users to display.')."\n");
1995: }
1.148 bisitz 1996: $r->print('<p class="LC_info">'.$msg.'</p>'."\n") if $msg;
1.3 raeburn 1997: } else {
1998: # Print out the available choices
1.4 raeburn 1999: my $usercount;
1.3 raeburn 2000: if ($env{'form.action'} eq 'modifystudent') {
1.10 raeburn 2001: ($usercount) = &show_users_list($r,$context,'view',$permission,
1.150 raeburn 2002: $env{'form.Status'},\%userlist,$keylist,'',
2003: $showcredits);
1.1 raeburn 2004: } else {
1.4 raeburn 2005: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1.150 raeburn 2006: $permission,$env{'form.Status'},\%userlist,
1.159 raeburn 2007: $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
1.4 raeburn 2008: }
2009: if (!$usercount) {
1.142 bisitz 2010: $r->print('<br /><span class="LC_info">'
1.72 bisitz 2011: .&mt('There are no users matching the search criteria.')
2012: .'</span>'
2013: );
1.2 raeburn 2014: }
2015: }
1.10 raeburn 2016: $r->print('<input type="hidden" name="phase" value="'.
2017: $env{'form.phase'}.'" /></form>');
1.140 raeburn 2018: return;
1.2 raeburn 2019: }
2020:
1.53 raeburn 2021: sub role_filter {
2022: my ($context) = @_;
2023: my $output;
2024: my $roleselected = '';
2025: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 2026: $roleselected = ' selected="selected"';
1.53 raeburn 2027: }
2028: my ($role_select);
2029: if ($context eq 'domain') {
2030: $role_select = &domain_roles_select();
1.140 raeburn 2031: $output = '<span class="LC_nobreak">'
1.70 bisitz 2032: .&mt('Role Type: [_1]',$role_select)
1.140 raeburn 2033: .'</span>';
1.53 raeburn 2034: } else {
1.140 raeburn 2035: $role_select = '<select name="showrole" onchange="javascript:updateCols('."'showrole'".');">'."\n".
1.53 raeburn 2036: '<option value="Any" '.$roleselected.'>'.
2037: &mt('Any role').'</option>';
1.101 raeburn 2038: my ($roletype,$crstype);
2039: if ($context eq 'course') {
2040: $crstype = &Apache::loncommon::course_type();
2041: if ($crstype eq 'Community') {
2042: $roletype = 'community';
2043: } else {
2044: $roletype = 'course';
2045: }
2046: }
2047: my @poss_roles = &curr_role_permissions($context,'','',$roletype);
1.53 raeburn 2048: foreach my $role (@poss_roles) {
2049: $roleselected = '';
2050: if ($role eq $env{'form.showrole'}) {
1.91 bisitz 2051: $roleselected = ' selected="selected"';
1.53 raeburn 2052: }
2053: my $plrole;
2054: if ($role eq 'cr') {
2055: $plrole = &mt('Custom role');
2056: } else {
1.101 raeburn 2057: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.53 raeburn 2058: }
2059: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
2060: }
2061: $role_select .= '</select>';
1.140 raeburn 2062: $output = '<span class="LC_nobreak">'
1.70 bisitz 2063: .&mt('Role: [_1]',$role_select)
1.140 raeburn 2064: .'</span>';
1.53 raeburn 2065: }
2066: return $output;
2067: }
2068:
1.33 raeburn 2069: sub section_group_filter {
2070: my ($cnum,$cdom) = @_;
2071: my @filters;
2072: if ($env{'request.course.sec'} eq '') {
2073: @filters = ('sec');
2074: }
2075: push(@filters,'grp');
2076: my %name = (
2077: sec => 'secfilter',
2078: grp => 'grpfilter',
2079: );
2080: my %title = &Apache::lonlocal::texthash (
2081: sec => 'Section(s)',
2082: grp => 'Group(s)',
2083: all => 'all',
2084: none => 'none',
2085: );
1.47 raeburn 2086: my $output;
1.33 raeburn 2087: foreach my $item (@filters) {
1.47 raeburn 2088: my ($markup,@options);
1.33 raeburn 2089: if ($env{'form.'.$name{$item}} eq '') {
2090: $env{'form.'.$name{$item}} = 'all';
2091: }
2092: if ($item eq 'sec') {
1.103 raeburn 2093: if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
1.33 raeburn 2094: $env{'form.'.$name{$item}} = 'none';
2095: }
2096: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
2097: @options = sort(keys(%sections_count));
2098: } elsif ($item eq 'grp') {
2099: my %curr_groups = &Apache::longroup::coursegroups();
2100: @options = sort(keys(%curr_groups));
2101: }
2102: if (@options > 0) {
2103: my $currsel;
1.112 bisitz 2104: $markup = '<select name="'.$name{$item}.'">'."\n";
1.33 raeburn 2105: foreach my $option ('all','none',@options) {
2106: $currsel = '';
2107: if ($env{'form.'.$name{$item}} eq $option) {
1.96 bisitz 2108: $currsel = ' selected="selected"';
1.33 raeburn 2109: }
2110: $markup .= ' <option value="'.$option.'"'.$currsel.'>';
2111: if (($option eq 'all') || ($option eq 'none')) {
2112: $markup .= $title{$option};
2113: } else {
2114: $markup .= $option;
2115: }
2116: $markup .= '</option>'."\n";
2117: }
2118: $markup .= '</select>'."\n";
1.111 bisitz 2119: $output .= (' 'x3).'<span class="LC_nobreak">'
2120: .'<label>'.$title{$item}.': '.$markup.'</label>'
2121: .'</span> ';
1.33 raeburn 2122: }
2123: }
2124: return $output;
2125: }
2126:
1.140 raeburn 2127: sub infocolumns {
1.150 raeburn 2128: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2129: my @cols;
2130: if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) {
1.150 raeburn 2131: @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2132: } else {
1.150 raeburn 2133: my @posscols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2134: if ($env{'form.phase'} ne '') {
2135: my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol');
2136: foreach my $col (@checkedcols) {
2137: if (grep(/^$col$/,@posscols)) {
2138: push(@cols,$col);
2139: }
2140: }
2141: } else {
2142: @cols = @posscols;
2143: }
2144: }
2145: return @cols;
2146: }
2147:
2148: sub get_cols_array {
1.150 raeburn 2149: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2150: my @cols;
2151: if ($mode eq 'pickauthor') {
2152: @cols = ('username','fullname','status','email');
2153: } else {
2154: @cols = ('username','domain','id','fullname');
2155: if ($context eq 'course') {
2156: push(@cols,'section');
2157: }
2158: push(@cols,('start','end','role'));
2159: unless (($mode eq 'autoenroll') && ($env{'form.Status'} ne 'Any')) {
2160: push(@cols,'status');
2161: }
2162: if ($context eq 'course') {
2163: push(@cols,'groups');
2164: }
2165: push(@cols,'email');
2166: if (($context eq 'course') && ($mode ne 'autoenroll')) {
1.150 raeburn 2167: if ($showcredits) {
2168: push(@cols,'credits');
2169: }
1.140 raeburn 2170: push(@cols,'lastlogin','clicker');
2171: }
2172: if (($context eq 'course') && ($mode ne 'autoenroll') &&
2173: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
1.156 raeburn 2174: push(@cols,'photo');
1.140 raeburn 2175: }
1.149 raeburn 2176: if ($context eq 'domain') {
1.159 raeburn 2177: push (@cols,('authorusage','authorquota','extent'));
1.149 raeburn 2178: }
1.140 raeburn 2179: }
2180: return @cols;
2181: }
2182:
2183: sub column_checkboxes {
1.150 raeburn 2184: my ($context,$mode,$formname,$showcredits) = @_;
2185: my @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2186: my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
2187: my (%disabledchk,%unchecked);
2188: if ($env{'form.phase'} eq '') {
2189: $disabledchk{'status'} = 1;
2190: if ($context eq 'course') {
2191: $disabledchk{'role'} = 1;
2192: $unchecked{'photo'} = 1;
1.149 raeburn 2193: $unchecked{'clicker'} = 1;
1.150 raeburn 2194: if ($showcredits) {
2195: $unchecked{'credits'} = 1;
2196: }
1.149 raeburn 2197: } elsif ($context eq 'domain') {
2198: $unchecked{'extent'} = 1;
1.140 raeburn 2199: }
2200: $unchecked{'start'} = 1;
2201: $unchecked{'end'} = 1;
2202: } else {
2203: if ($env{'form.Status'} ne 'Any') {
2204: $disabledchk{'status'} = 1;
2205: }
1.146 raeburn 2206: if (($env{'form.showrole'} ne 'Any') && ($env{'form.showrole'} ne 'cr')) {
2207: $disabledchk{'role'} = 1;
1.140 raeburn 2208: }
1.149 raeburn 2209: if ($context eq 'domain') {
2210: if (($env{'form.roletype'} eq 'course') ||
2211: ($env{'form.roletype'} eq 'community')) {
2212: $disabledchk{'status'} = 1;
1.159 raeburn 2213: $disabledchk{'authorusage'} = 1;
2214: $disabledchk{'authorquota'} = 1;
1.149 raeburn 2215: } elsif ($env{'form.roletype'} eq 'domain') {
2216: $disabledchk{'extent'} = 1;
2217: }
2218: }
1.140 raeburn 2219: }
2220: my $numposs = scalar(@cols);
1.149 raeburn 2221: my $numinrow = 7;
1.140 raeburn 2222: my %lt = &get_column_names($context);
2223: my $output = '<fieldset><legend>'.&mt('Information to show').'</legend>'."\n".'<span class="LC_nobreak">'.
2224: '<input type="button" onclick="javascript:checkAll(document.'.$formname.'.showcol);" value="'.&mt('check all').'" />'.
2225: (' 'x3).
2226: '<input type="button" onclick="javascript:uncheckAll(document.'.$formname.'.showcol);" value="'.&mt('uncheck all').'" />'.
2227: '</span><table>';
2228:
2229: for (my $i=0; $i<$numposs; $i++) {
2230: my $rem = $i%($numinrow);
2231: if ($rem == 0) {
2232: if ($i > 0) {
2233: $output .= '</tr>';
2234: }
2235: $output .= '<tr>';
2236: }
2237: my $checked;
2238: if ($env{'form.phase'} eq '') {
2239: $checked = ' checked="checked"';
2240: if ($unchecked{$cols[$i]}) {
2241: $checked = '';
2242: }
2243: if ($disabledchk{$cols[$i]}) {
2244: $checked = ' disabled="disabled"';
2245: }
2246: } elsif (grep(/^\Q$cols[$i]\E$/,@showncols)) {
2247: $checked = ' checked="checked"';
2248: } elsif ($disabledchk{$cols[$i]}) {
2249: $checked = ' disabled="disabled"';
2250: }
2251: if ($i == $numposs-1) {
2252: my $colsleft = $numinrow-$rem;
2253: if ($colsleft > 1) {
2254: $output .= '<td colspan="'.$colsleft.'">';
2255: } else {
2256: $output .= '<td>';
2257: }
2258: } else {
2259: $output .= '<td>';
2260: }
1.149 raeburn 2261: my $style;
2262: if ($cols[$i] eq 'extent') {
2263: if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
2264: $style = ' style="display: none;"';
2265: }
1.159 raeburn 2266: } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
2267: if ($env{'form.roletype'} ne 'domain') {
2268: $style = ' style="display: none;"';
2269: }
2270: }
1.149 raeburn 2271: $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.
2272: '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.
2273: $lt{$cols[$i]}.'</span>'.
2274: '</label></span></td>';
1.140 raeburn 2275: }
2276: $output .= '</tr></table></fieldset>';
2277: return $output;
2278: }
2279:
1.2 raeburn 2280: sub list_submit_button {
2281: my ($text) = @_;
1.11 raeburn 2282: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1.2 raeburn 2283: }
2284:
1.140 raeburn 2285: sub get_column_names {
2286: my ($context) = @_;
2287: my %lt = &Apache::lonlocal::texthash(
2288: 'username' => "username",
2289: 'domain' => "domain",
2290: 'id' => 'ID',
2291: 'fullname' => "name",
2292: 'section' => "section",
2293: 'groups' => "active groups",
2294: 'start' => "start date",
2295: 'end' => "end date",
2296: 'status' => "status",
2297: 'role' => "role",
1.150 raeburn 2298: 'credits' => "credits",
1.140 raeburn 2299: 'type' => "enroll type/action",
2300: 'email' => "e-mail address",
2301: 'photo' => "photo",
2302: 'lastlogin' => "last login",
2303: 'extent' => "extent",
1.159 raeburn 2304: 'authorusage' => "disk usage (%)",
2305: 'authorquota' => "disk quota (MB)",
1.140 raeburn 2306: 'ca' => "check all",
2307: 'ua' => "uncheck all",
2308: 'clicker' => "clicker-ID",
2309: );
2310: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1.149 raeburn 2311: $lt{'extent'} = &mt('course(s): description, section(s), status');
1.140 raeburn 2312: } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
1.154 raeburn 2313: $lt{'extent'} = &mt('community(s): description, section(s), status');
1.149 raeburn 2314: } elsif (($context eq 'author') ||
2315: ($context eq 'domain' && $env{'form.roletype'} eq 'author')) {
2316: $lt{'extent'} = &mt('author');
1.140 raeburn 2317: }
2318: return %lt;
2319: }
2320:
1.2 raeburn 2321: sub gather_userinfo {
1.11 raeburn 2322: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1.52 raeburn 2323: my $viewablesec;
2324: if ($context eq 'course') {
2325: $viewablesec = &viewable_section($permission);
2326: }
1.2 raeburn 2327: foreach my $item (keys(%{$rolehash})) {
2328: my %userdata;
1.22 raeburn 2329: if ($context eq 'author') {
1.2 raeburn 2330: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2331: split(/:/,$item);
2332: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2333: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2334: $item,$userlist);
1.22 raeburn 2335: } elsif ($context eq 'course') {
2336: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
2337: $userdata{'section'}) = split(/:/,$item,-1);
2338: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
2339: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
2340: next if ($viewablesec ne $userdata{'section'});
2341: }
1.24 raeburn 2342: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2343: $item,$userlist);
1.2 raeburn 2344: } elsif ($context eq 'domain') {
2345: if ($env{'form.roletype'} eq 'domain') {
2346: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
2347: split(/:/,$item);
2348: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2349: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2350: $item,$userlist);
1.13 raeburn 2351: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2352: if (ref($rolehash->{$item}) eq 'HASH') {
2353: $userdata{'extent'} = $item;
2354: foreach my $key (keys(%{$rolehash->{$item}})) {
2355: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
2356: ($userdata{'start'},$userdata{'end'}) =
2357: split(/:/,$rolehash->{$item}{$key});
2358: my $uniqid = $key.':'.$item;
1.25 raeburn 2359: &build_user_record($context,\%userdata,$userinfo,
2360: $indexhash,$uniqid,$userlist);
1.2 raeburn 2361: }
2362: }
1.102 raeburn 2363: } elsif (($env{'form.roletype'} eq 'course') ||
2364: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 2365: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2366: split(/:/,$item);
2367: if (ref($rolehash->{$item}) eq 'HASH') {
1.11 raeburn 2368: my $numcids = keys(%{$rolehash->{$item}});
1.2 raeburn 2369: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
2370: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
2371: my $spanstart = '';
2372: my $spanend = '; ';
2373: my $space = ', ';
2374: if ($format eq 'html' || $format eq 'view') {
2375: $spanstart = '<span class="LC_nobreak">';
1.23 raeburn 2376: # FIXME: actions on courses disabled for now
2377: # if ($permission->{'cusr'}) {
2378: # if ($numcids > 1) {
1.25 raeburn 2379: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2380: # } else {
1.25 raeburn 2381: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2382: # }
2383: # }
1.2 raeburn 2384: $spanend = '</span><br />';
2385: $space = ', ';
2386: }
2387: $userdata{'extent'} .= $spanstart.
2388: $rolehash->{$item}{$cid}{'desc'}.$space;
2389: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
2390: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1.25 raeburn 2391: if (($env{'form.Status'} eq 'Any') ||
2392: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
2393: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
2394: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
2395: }
1.2 raeburn 2396: }
2397: }
2398: }
2399: }
2400: }
1.25 raeburn 2401: if ($userdata{'status'} ne '') {
2402: &build_user_record($context,\%userdata,$userinfo,
2403: $indexhash,$item,$userlist);
2404: }
1.2 raeburn 2405: }
2406: }
2407: }
2408: return;
2409: }
2410:
2411: sub build_user_record {
1.24 raeburn 2412: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1.11 raeburn 2413: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1.102 raeburn 2414: if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
2415: && ($env{'form.roletype'} eq 'community')))) {
1.24 raeburn 2416: &process_date_info($userdata);
2417: }
1.2 raeburn 2418: my $username = $userdata->{'username'};
2419: my $domain = $userdata->{'domain'};
2420: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1.24 raeburn 2421: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1.2 raeburn 2422: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2423: } else {
2424: &aggregate_user_info($domain,$username,$userinfo);
2425: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
2426: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2427: }
2428: foreach my $key (keys(%{$indexhash})) {
2429: if (defined($userdata->{$key})) {
2430: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
2431: }
2432: }
2433: return;
2434: }
2435:
2436: sub courses_selector {
2437: my ($cdom,$formname) = @_;
2438: my %codes = ();
2439: my @codetitles = ();
2440: my %cat_titles = ();
2441: my %cat_order = ();
2442: my %idlist = ();
2443: my %idnums = ();
2444: my %idlist_titles = ();
2445: my $caller = 'global';
2446: my $format_reply;
2447: my $jscript = '';
2448:
1.7 albertel 2449: my $totcodes = 0;
1.201 raeburn 2450: my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
2451: if (ref($instcats) eq 'HASH') {
2452: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
2453: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
2454: %codes = %{$instcats->{'codes'}};
2455: @codetitles = @{$instcats->{'codetitles'}};
2456: %cat_titles = %{$instcats->{'cat_titles'}};
2457: %cat_order = %{$instcats->{'cat_order'}};
2458: $totcodes = scalar(keys(%codes));
1.2 raeburn 2459: my $numtypes = @codetitles;
2460: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
2461: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
2462: my $longtitles_str = join('","',@{$longtitles});
2463: my $allidlist = $idlist{$codetitles[0]};
2464: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
2465: $jscript .= $scripttext;
1.181 raeburn 2466: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
1.2 raeburn 2467: }
2468: }
2469: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
2470:
2471: my %elements = (
2472: Year => 'selectbox',
2473: coursepick => 'radio',
2474: coursetotal => 'text',
2475: courselist => 'text',
2476: );
2477: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
2478: if ($env{'form.coursepick'} eq 'category') {
2479: $jscript .= qq|
2480: function setCourseCat(formname) {
2481: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
2482: return;
2483: }
1.120 raeburn 2484: courseSet('$codetitles[0]');
1.2 raeburn 2485: for (var j=0; j<formname.Semester.length; j++) {
2486: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
2487: formname.Semester.options[j].selected = true;
2488: }
2489: }
2490: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
2491: return;
2492: }
1.120 raeburn 2493: courseSet('$codetitles[1]');
1.2 raeburn 2494: for (var j=0; j<formname.Department.length; j++) {
1.187 raeburn 2495: if (formname.Department.options[j].value == "$env{'form.Department'}") {
2496: formname.Department.options[j].selected = true;
1.2 raeburn 2497: }
2498: }
2499: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
2500: return;
2501: }
1.120 raeburn 2502: courseSet('$codetitles[2]');
1.2 raeburn 2503: for (var j=0; j<formname.Number.length; j++) {
2504: if (formname.Number.options[j].value == "$env{'form.Number'}") {
2505: formname.Number.options[j].selected = true;
2506: }
2507: }
2508: }
2509: |;
2510: }
2511: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
2512: \%idlist_titles);
2513: }
2514:
2515: sub course_selector_loadcode {
2516: my ($formname) = @_;
2517: my $loadcode;
2518: if ($env{'form.coursepick'} ne '') {
2519: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
2520: if ($env{'form.coursepick'} eq 'category') {
2521: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
2522: }
2523: }
2524: return $loadcode;
2525: }
2526:
2527: sub process_coursepick {
2528: my $coursefilter = $env{'form.coursepick'};
2529: my $cdom = $env{'request.role.domain'};
2530: my %courses;
1.105 raeburn 2531: my $crssrch = 'Course';
2532: if ($env{'form.roletype'} eq 'community') {
2533: $crssrch = 'Community';
2534: }
1.2 raeburn 2535: if ($coursefilter eq 'all') {
2536: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1.105 raeburn 2537: undef,undef,$crssrch);
1.2 raeburn 2538: } elsif ($coursefilter eq 'category') {
2539: my $instcode = &instcode_from_coursefilter();
2540: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1.105 raeburn 2541: undef,undef,$crssrch);
1.2 raeburn 2542: } elsif ($coursefilter eq 'specific') {
2543: if ($env{'form.coursetotal'} > 1) {
2544: my @course_ids = split(/&&/,$env{'form.courselist'});
2545: foreach my $cid (@course_ids) {
2546: $courses{$cid} = '';
1.1 raeburn 2547: }
1.2 raeburn 2548: } else {
2549: $courses{$env{'form.courselist'}} = '';
1.1 raeburn 2550: }
1.2 raeburn 2551: }
2552: return %courses;
2553: }
2554:
2555: sub instcode_from_coursefilter {
2556: my $instcode = '';
2557: my @cats = ('Semester','Year','Department','Number');
2558: foreach my $category (@cats) {
2559: if (defined($env{'form.'.$category})) {
2560: unless ($env{'form.'.$category} eq '-1') {
2561: $instcode .= $env{'form.'.$category};
2562: }
2563: }
2564: }
2565: if ($instcode eq '') {
2566: $instcode = '.';
2567: }
2568: return $instcode;
2569: }
2570:
2571: sub make_keylist_array {
2572: my ($index,$keylist);
2573: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
2574: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
2575: $index->{'end'} = &Apache::loncoursedata::CL_END();
2576: $index->{'start'} = &Apache::loncoursedata::CL_START();
2577: $index->{'id'} = &Apache::loncoursedata::CL_ID();
2578: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
2579: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
2580: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
2581: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
2582: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
2583: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
2584: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
2585: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
2586: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1.44 raeburn 2587: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
1.47 raeburn 2588: $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
1.150 raeburn 2589: $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
1.174 raeburn 2590: $index->{'instsec'} = &Apache::loncoursedata::CL_INSTSEC();
1.159 raeburn 2591: $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
2592: $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
1.2 raeburn 2593: foreach my $key (keys(%{$index})) {
2594: $keylist->[$index->{$key}] = $key;
2595: }
2596: return ($index,$keylist);
2597: }
2598:
2599: sub aggregate_user_info {
2600: my ($udom,$uname,$userinfo) = @_;
2601: my %info=&Apache::lonnet::get('environment',
2602: ['firstname','middlename',
2603: 'lastname','generation','id'],
2604: $udom,$uname);
2605: my ($tmp) = keys(%info);
2606: my ($fullname,$id);
2607: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
2608: $fullname = 'not available';
2609: $id = 'not available';
2610: &Apache::lonnet::logthis('unable to retrieve environment '.
2611: 'for '.$uname.':'.$udom);
1.1 raeburn 2612: } else {
1.2 raeburn 2613: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
2614: $id = $info{'id'};
2615: }
2616: $userinfo->{$uname.':'.$udom} = {
2617: fullname => $fullname,
2618: id => $id,
2619: };
2620: return;
2621: }
1.1 raeburn 2622:
1.2 raeburn 2623: sub process_date_info {
2624: my ($userdata) = @_;
2625: my $now = time;
1.83 raeburn 2626: $userdata->{'status'} = 'Active';
1.2 raeburn 2627: if ($userdata->{'start'} > 0) {
2628: if ($now < $userdata->{'start'}) {
1.83 raeburn 2629: $userdata->{'status'} = 'Future';
1.2 raeburn 2630: }
1.1 raeburn 2631: }
1.2 raeburn 2632: if ($userdata->{'end'} > 0) {
2633: if ($now > $userdata->{'end'}) {
1.83 raeburn 2634: $userdata->{'status'} = 'Expired';
1.2 raeburn 2635: }
2636: }
2637: return;
1.1 raeburn 2638: }
2639:
2640: sub show_users_list {
1.150 raeburn 2641: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
1.159 raeburn 2642: $showcredits,$needauthorquota,$needauthorusage)=@_;
1.55 raeburn 2643: if ($formname eq '') {
2644: $formname = 'studentform';
2645: }
1.159 raeburn 2646: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1 raeburn 2647: #
2648: # Variables for excel output
2649: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
2650: #
2651: # Variables for csv output
2652: my ($CSVfile,$CSVfilename);
2653: #
2654: my $sortby = $env{'form.sortby'};
1.3 raeburn 2655: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1.2 raeburn 2656: if ($context eq 'course') {
1.3 raeburn 2657: push(@sortable,('section','groups','type'));
1.150 raeburn 2658: if ($showcredits) {
2659: push(@sortable,'credits');
2660: }
1.2 raeburn 2661: } else {
1.3 raeburn 2662: push(@sortable,'extent');
1.159 raeburn 2663: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
2664: (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
2665: push(@sortable,('authorusage','authorquota'));
2666: }
1.3 raeburn 2667: }
1.55 raeburn 2668: if ($mode eq 'pickauthor') {
2669: @sortable = ('username','fullname','email','status');
2670: }
1.156 raeburn 2671: my %is_sortable;
1.158 raeburn 2672: map { $is_sortable{$_} = 1; } @sortable;
1.156 raeburn 2673: unless ($is_sortable{$sortby}) {
1.3 raeburn 2674: $sortby = 'username';
1.1 raeburn 2675: }
1.22 raeburn 2676: my $setting = $env{'form.roletype'};
1.150 raeburn 2677: my ($cid,$cdom,$cnum,$classgroups,$crstype,$defaultcredits);
1.1 raeburn 2678: if ($context eq 'course') {
1.22 raeburn 2679: $cid = $env{'request.course.id'};
1.101 raeburn 2680: $crstype = &Apache::loncommon::course_type();
1.17 raeburn 2681: ($cnum,$cdom) = &get_course_identity($cid);
1.150 raeburn 2682: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
1.2 raeburn 2683: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
2684: $userlist,$keylist,$cdom,$cnum);
1.16 raeburn 2685: if ($mode eq 'autoenroll') {
2686: $env{'form.showrole'} = 'st';
2687: } else {
2688: if ($env{'course.'.$cid.'.internal.showphoto'}) {
2689: $r->print('
1.1 raeburn 2690: <script type="text/javascript">
1.96 bisitz 2691: // <![CDATA[
1.1 raeburn 2692: function photowindow(photolink) {
2693: var title = "Photo_Viewer";
2694: var options = "scrollbars=1,resizable=1,menubar=0";
2695: options += ",width=240,height=240";
2696: stdeditbrowser = open(photolink,title,options,"1");
2697: stdeditbrowser.focus();
2698: }
1.96 bisitz 2699: // ]]>
1.1 raeburn 2700: </script>
1.16 raeburn 2701: ');
2702: }
2703: }
1.102 raeburn 2704: } elsif ($context eq 'domain') {
2705: if ($setting eq 'community') {
2706: $crstype = 'Community';
1.105 raeburn 2707: } elsif ($setting eq 'course') {
1.102 raeburn 2708: $crstype = 'Course';
2709: }
1.1 raeburn 2710: }
1.55 raeburn 2711: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.40 raeburn 2712: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1.56 raeburn 2713: my $verify_action_js = &bulkaction_javascript($formname);
1.1 raeburn 2714: $r->print(<<END);
1.10 raeburn 2715:
2716: <script type="text/javascript" language="Javascript">
1.96 bisitz 2717: // <![CDATA[
1.11 raeburn 2718:
1.56 raeburn 2719: $verify_action_js
1.10 raeburn 2720:
2721: function username_display_launch(username,domain) {
2722: var target;
1.177 raeburn 2723: if (!document.$formname.usernamelink.length) {
2724: target = document.$formname.usernamelink.value;
2725: } else {
2726: for (var i=0; i<document.$formname.usernamelink.length; i++) {
2727: if (document.$formname.usernamelink[i].checked) {
2728: target = document.$formname.usernamelink[i].value;
2729: }
1.10 raeburn 2730: }
2731: }
1.179 raeburn 2732: if ((target == 'modify') || (target == 'activity')) {
2733: var nextaction = 'singleuser';
2734: if (target == 'activity') {
2735: nextaction = 'accesslogs';
2736: }
1.55 raeburn 2737: if (document.$formname.userwin.checked == true) {
1.179 raeburn 2738: var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&srchin=dom&srchby=uname&srchtype=exact&popup=1&action='+nextaction;
1.50 raeburn 2739: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2740: modifywin = window.open(url,'',options,1);
2741: modifywin.focus();
2742: return;
2743: } else {
1.55 raeburn 2744: document.$formname.srchterm.value=username;
2745: document.$formname.srchdomain.value=domain;
2746: document.$formname.phase.value='get_user_info';
1.179 raeburn 2747: document.$formname.action.value = nextaction;
1.55 raeburn 2748: document.$formname.submit();
1.50 raeburn 2749: }
1.10 raeburn 2750: }
1.48 raeburn 2751: if (target == 'aboutme') {
1.55 raeburn 2752: if (document.$formname.userwin.checked == true) {
1.50 raeburn 2753: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
2754: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2755: aboutmewin = window.open(url,'',options,1);
2756: aboutmewin.focus();
2757: return;
2758: } else {
2759: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
2760: }
1.48 raeburn 2761: }
1.98 raeburn 2762: if (target == 'track') {
2763: if (document.$formname.userwin.checked == true) {
2764: var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
2765: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2766: var trackwin = window.open(url,'',options,1);
2767: trackwin.focus();
2768: return;
2769: } else {
2770: document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
2771: }
2772: }
1.10 raeburn 2773: }
1.96 bisitz 2774: // ]]>
1.10 raeburn 2775: </script>
1.11 raeburn 2776: $date_sec_selector
1.1 raeburn 2777: <input type="hidden" name="state" value="$env{'form.state'}" />
2778: END
2779: }
2780: $r->print(<<END);
2781: <input type="hidden" name="sortby" value="$sortby" />
2782: END
1.150 raeburn 2783: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 2784: my %coltxt = &get_column_names($context);
2785: my %acttxt = &Apache::lonlocal::texthash(
1.11 raeburn 2786: 'pr' => "Proceed",
2787: 'ac' => "Action to take for selected users",
1.56 raeburn 2788: 'link' => "Behavior of clickable username link for each user",
1.82 weissno 2789: 'aboutme' => "Display a user's personal information page",
1.50 raeburn 2790: 'owin' => "Open in a new window",
1.10 raeburn 2791: 'modify' => "Modify a user's information",
1.98 raeburn 2792: 'track' => "View a user's recent activity",
1.179 raeburn 2793: 'activity' => "View a user's access log",
1.1 raeburn 2794: );
1.140 raeburn 2795: my %lt = (%coltxt,%acttxt);
1.4 raeburn 2796: my $rolefilter = $env{'form.showrole'};
1.5 raeburn 2797: if ($env{'form.showrole'} eq 'cr') {
2798: $rolefilter = &mt('custom');
2799: } elsif ($env{'form.showrole'} ne 'Any') {
1.101 raeburn 2800: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype);
1.2 raeburn 2801: }
1.16 raeburn 2802: my $results_description;
2803: if ($mode ne 'autoenroll') {
2804: $results_description = &results_header_row($rolefilter,$statusmode,
1.102 raeburn 2805: $context,$permission,$mode,$crstype);
1.140 raeburn 2806: $r->print('<b>'.$results_description.'</b><br clear="all" />');
1.16 raeburn 2807: }
1.26 raeburn 2808: my ($output,$actionselect,%canchange,%canchangesec);
1.55 raeburn 2809: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
2810: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.16 raeburn 2811: if ($permission->{'cusr'}) {
1.105 raeburn 2812: unless (($context eq 'domain') &&
2813: (($setting eq 'course') || ($setting eq 'community'))) {
2814: $actionselect =
2815: &select_actions($context,$setting,$statusmode,$formname);
2816: }
1.16 raeburn 2817: }
2818: $r->print(<<END);
1.10 raeburn 2819: <input type="hidden" name="srchby" value="uname" />
2820: <input type="hidden" name="srchin" value="dom" />
2821: <input type="hidden" name="srchtype" value="exact" />
2822: <input type="hidden" name="srchterm" value="" />
1.11 raeburn 2823: <input type="hidden" name="srchdomain" value="" />
1.1 raeburn 2824: END
1.16 raeburn 2825: if ($actionselect) {
1.41 raeburn 2826: $output .= <<"END";
1.94 bisitz 2827: <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
1.56 raeburn 2828: $actionselect
2829: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
2830: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.$formname.actionlist)" /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action('actionlist')" /></fieldset></div>
1.11 raeburn 2831: END
1.26 raeburn 2832: my @allroles;
2833: if ($env{'form.showrole'} eq 'Any') {
2834: my $custom = 1;
2835: if ($context eq 'domain') {
1.101 raeburn 2836: @allroles = &roles_by_context($setting,$custom,$crstype);
1.26 raeburn 2837: } else {
1.101 raeburn 2838: @allroles = &roles_by_context($context,$custom,$crstype);
1.26 raeburn 2839: }
2840: } else {
2841: @allroles = ($env{'form.showrole'});
2842: }
2843: foreach my $role (@allroles) {
2844: if ($context eq 'domain') {
2845: if ($setting eq 'domain') {
2846: if (&Apache::lonnet::allowed('c'.$role,
2847: $env{'request.role.domain'})) {
2848: $canchange{$role} = 1;
2849: }
1.31 raeburn 2850: } elsif ($setting eq 'author') {
2851: if (&Apache::lonnet::allowed('c'.$role,
2852: $env{'request.role.domain'})) {
2853: $canchange{$role} = 1;
2854: }
1.26 raeburn 2855: }
2856: } elsif ($context eq 'author') {
2857: if (&Apache::lonnet::allowed('c'.$role,
2858: $env{'user.domain'}.'/'.$env{'user.name'})) {
2859: $canchange{$role} = 1;
2860: }
2861: } elsif ($context eq 'course') {
2862: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2863: $canchange{$role} = 1;
2864: } elsif ($env{'request.course.sec'} ne '') {
2865: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
2866: $canchangesec{$role} = $env{'request.course.sec'};
2867: }
1.141 raeburn 2868: } elsif ((($role eq 'co') && ($crstype eq 'Community')) ||
2869: (($role eq 'cc') && ($crstype eq 'Course'))) {
2870: if (&is_courseowner($env{'request.course.id'},
2871: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
2872: $canchange{$role} = 1;
2873: }
1.26 raeburn 2874: }
2875: }
2876: }
1.16 raeburn 2877: }
1.94 bisitz 2878: $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
1.56 raeburn 2879: '<table><tr>';
2880: my @linkdests = ('aboutme');
2881: if ($permission->{'cusr'}) {
2882: unshift (@linkdests,'modify');
2883: }
1.179 raeburn 2884: if ($context eq 'course') {
2885: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
2886: &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
2887: $env{'request.course.sec'})) {
2888: push(@linkdests,'track');
2889: }
2890: } elsif ($context eq 'domain') {
2891: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
2892: push(@linkdests,'activity');
2893: }
1.98 raeburn 2894: }
1.56 raeburn 2895: $output .= '<td>';
2896: my $usernamelink = $env{'form.usernamelink'};
2897: if ($usernamelink eq '') {
2898: $usernamelink = 'aboutme';
2899: }
2900: foreach my $item (@linkdests) {
2901: my $checkedstr = '';
2902: if ($item eq $usernamelink) {
1.86 bisitz 2903: $checkedstr = ' checked="checked"';
1.56 raeburn 2904: }
1.86 bisitz 2905: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
1.56 raeburn 2906: }
2907: my $checkwin;
2908: if ($env{'form.userwin'}) {
1.86 bisitz 2909: $checkwin = ' checked="checked"';
1.56 raeburn 2910: }
1.144 bisitz 2911: $output .=
2912: '</td><td valign="top" style="border-left: 1px solid;">'
2913: .'<span class="LC_nobreak"><label>'
2914: .'<input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}
2915: .'</label></span></td></tr></table></fieldset></div>';
1.4 raeburn 2916: }
1.184 raeburn 2917: $output .= "\n".'<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
1.1 raeburn 2918: &Apache::loncommon::start_data_table().
1.4 raeburn 2919: &Apache::loncommon::start_data_table_header_row();
1.1 raeburn 2920: if ($mode eq 'autoenroll') {
1.4 raeburn 2921: $output .= "
1.55 raeburn 2922: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
1.4 raeburn 2923: ";
1.1 raeburn 2924: } else {
1.105 raeburn 2925: $output .= "\n".'<th> </th>'."\n";
1.11 raeburn 2926: if ($actionselect) {
1.159 raeburn 2927: $output .= '<th class="LC_nobreak" valign="top">'.&mt('Select').'</th>'."\n";
1.11 raeburn 2928: }
1.1 raeburn 2929: }
2930: foreach my $item (@cols) {
1.159 raeburn 2931: $output .= '<th class="LC_nobreak" valign="top">';
1.156 raeburn 2932: if ($is_sortable{$item}) {
1.159 raeburn 2933: $output .= "<a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\" style=\"text-decoration:none;\">$lt{$item}<span class=\"LC_fontsize_small\"> ▼</span></a>";
1.156 raeburn 2934: } else {
2935: $output .= $lt{$item};
2936: }
2937: $output .= "</th>\n";
1.1 raeburn 2938: }
1.2 raeburn 2939: my %role_types = &role_type_names();
1.16 raeburn 2940: $output .= &Apache::loncommon::end_data_table_header_row();
1.1 raeburn 2941: # Done with the HTML header line
2942: } elsif ($mode eq 'csv') {
2943: #
2944: # Open a file
2945: $CSVfilename = '/prtspool/'.
1.2 raeburn 2946: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
2947: time.'_'.rand(1000000000).'.csv';
1.1 raeburn 2948: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
2949: $r->log_error("Couldn't open $CSVfilename for output $!");
1.108 bisitz 2950: $r->print(
2951: '<p class="LC_error">'
2952: .&mt('Problems occurred in writing the CSV file.')
2953: .' '.&mt('This error has been logged.')
2954: .' '.&mt('Please alert your LON-CAPA administrator.')
2955: .'</p>'
2956: );
1.1 raeburn 2957: $CSVfile = undef;
2958: }
2959: #
2960: # Write headers and data to file
1.2 raeburn 2961: print $CSVfile '"'.$results_description.'"'."\n";
1.1 raeburn 2962: print $CSVfile '"'.join('","',map {
2963: &Apache::loncommon::csv_translate($lt{$_})
1.67 droeschl 2964: } (@cols))."\"\n";
1.1 raeburn 2965: } elsif ($mode eq 'excel') {
2966: # Create the excel spreadsheet
2967: ($excel_workbook,$excel_filename,$format) =
2968: &Apache::loncommon::create_workbook($r);
2969: return if (! defined($excel_workbook));
2970: $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2 raeburn 2971: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1 raeburn 2972: #
2973: my @colnames = map {$lt{$_}} (@cols);
1.67 droeschl 2974:
1.1 raeburn 2975: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
2976: }
2977:
2978: # Done with header lines in all formats
2979: my %index;
2980: my $i;
1.2 raeburn 2981: foreach my $idx (@$keylist) {
2982: $index{$idx} = $i++;
2983: }
1.4 raeburn 2984: my $usercount = 0;
1.33 raeburn 2985: my ($secfilter,$grpfilter);
2986: if ($context eq 'course') {
2987: $secfilter = $env{'form.secfilter'};
2988: $grpfilter = $env{'form.grpfilter'};
2989: if ($secfilter eq '') {
2990: $secfilter = 'all';
2991: }
2992: if ($grpfilter eq '') {
2993: $grpfilter = 'all';
2994: }
2995: }
1.83 raeburn 2996: my %ltstatus = &Apache::lonlocal::texthash(
2997: Active => 'Active',
2998: Future => 'Future',
2999: Expired => 'Expired',
3000: );
1.139 raeburn 3001: # If this is for a single course get last course "log-in".
3002: my %crslogins;
3003: if ($context eq 'course') {
3004: %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
3005: }
1.2 raeburn 3006: # Get groups, role, permanent e-mail so we can sort on them if
3007: # necessary.
3008: foreach my $user (keys(%{$userlist})) {
1.43 raeburn 3009: if ($user eq '' ) {
3010: delete($userlist->{$user});
3011: next;
3012: }
1.11 raeburn 3013: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
3014: delete($userlist->{$user});
3015: next;
3016: }
1.2 raeburn 3017: my ($uname,$udom,$role,$groups,$email);
1.5 raeburn 3018: if (($statusmode ne 'Any') &&
3019: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
3020: delete($userlist->{$user});
3021: next;
3022: }
1.2 raeburn 3023: if ($context eq 'domain') {
3024: if ($env{'form.roletype'} eq 'domain') {
3025: ($role,$uname,$udom) = split(/:/,$user);
1.11 raeburn 3026: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
3027: ($udom eq $env{'request.role.domain'})) {
3028: delete($userlist->{$user});
3029: next;
3030: }
1.13 raeburn 3031: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3032: ($uname,$udom,$role) = split(/:/,$user,-1);
1.102 raeburn 3033: } elsif (($env{'form.roletype'} eq 'course') ||
3034: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 3035: ($uname,$udom,$role) = split(/:/,$user);
3036: }
3037: } else {
3038: ($uname,$udom,$role) = split(/:/,$user,-1);
3039: if (($context eq 'course') && $role eq '') {
3040: $role = 'st';
3041: }
3042: }
3043: $userlist->{$user}->[$index{'role'}] = $role;
3044: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
3045: delete($userlist->{$user});
3046: next;
3047: }
1.33 raeburn 3048: if ($context eq 'course') {
3049: my @ac_groups;
3050: if (ref($classgroups) eq 'HASH') {
3051: $groups = $classgroups->{$user};
3052: }
3053: if (ref($groups->{'active'}) eq 'HASH') {
3054: @ac_groups = keys(%{$groups->{'active'}});
3055: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
3056: }
3057: if ($mode ne 'autoenroll') {
3058: my $section = $userlist->{$user}->[$index{'section'}];
1.43 raeburn 3059: if (($env{'request.course.sec'} ne '') &&
3060: ($section ne $env{'request.course.sec'})) {
3061: if ($role eq 'st') {
3062: delete($userlist->{$user});
3063: next;
3064: }
3065: }
1.33 raeburn 3066: if ($secfilter eq 'none') {
3067: if ($section ne '') {
3068: delete($userlist->{$user});
3069: next;
3070: }
3071: } elsif ($secfilter ne 'all') {
3072: if ($section ne $secfilter) {
3073: delete($userlist->{$user});
3074: next;
3075: }
3076: }
3077: if ($grpfilter eq 'none') {
3078: if (@ac_groups > 0) {
3079: delete($userlist->{$user});
3080: next;
3081: }
3082: } elsif ($grpfilter ne 'all') {
3083: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
3084: delete($userlist->{$user});
3085: next;
3086: }
3087: }
1.44 raeburn 3088: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1.140 raeburn 3089: if ((grep/^photo$/,@cols) && ($role eq 'st')) {
1.44 raeburn 3090: $userlist->{$user}->[$index{'photo'}] =
1.47 raeburn 3091: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
3092: $userlist->{$user}->[$index{'thumbnail'}] =
1.44 raeburn 3093: &Apache::lonnet::retrievestudentphoto($udom,$uname,
3094: 'gif','thumbnail');
3095: }
3096: }
1.150 raeburn 3097: if (($role eq 'st') && ($defaultcredits)) {
3098: if ($userlist->{$user}->[$index{'credits'}] eq '') {
3099: $userlist->{$user}->[$index{'credits'}] = $defaultcredits;
3100: }
3101: }
1.33 raeburn 3102: }
1.2 raeburn 3103: }
3104: my %emails = &Apache::loncommon::getemails($uname,$udom);
3105: if ($emails{'permanentemail'} =~ /\S/) {
3106: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
3107: }
1.159 raeburn 3108: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3109: ($role eq 'au')) {
3110: my ($disk_quota,$current_disk_usage,$percent);
3111: if (($needauthorusage) || ($needauthorquota)) {
3112: $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
3113: }
3114: if ($needauthorusage) {
3115: $current_disk_usage =
3116: &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
3117: if ($disk_quota == 0) {
3118: $percent = 100.0;
3119: } else {
3120: $percent = $current_disk_usage/(10 * $disk_quota);
3121: }
3122: $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
3123: }
3124: if ($needauthorquota) {
3125: $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
3126: }
3127: }
1.4 raeburn 3128: $usercount ++;
3129: }
3130: my $autocount = 0;
3131: my $manualcount = 0;
3132: my $lockcount = 0;
3133: my $unlockcount = 0;
3134: if ($usercount) {
3135: $r->print($output);
3136: } else {
3137: if ($mode eq 'autoenroll') {
3138: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
3139: } else {
3140: return;
3141: }
1.1 raeburn 3142: }
1.2 raeburn 3143: #
3144: # Sort the users
1.1 raeburn 3145: my $index = $index{$sortby};
3146: my $second = $index{'username'};
3147: my $third = $index{'domain'};
1.159 raeburn 3148: my @sorted_users;
3149: if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {
3150: @sorted_users = sort {
3151: $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] ||
3152: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3153: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3154: } (keys(%$userlist));
3155: } else {
3156: @sorted_users = sort {
3157: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) ||
3158: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3159: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3160: } (keys(%$userlist));
3161: }
1.4 raeburn 3162: my $rowcount = 0;
1.178 raeburn 3163: my $disabled;
3164: if ($mode eq 'autoenroll') {
3165: unless ($permission->{'cusr'}) {
3166: $disabled = ' disabled="disabled"';
3167: }
3168: }
1.2 raeburn 3169: foreach my $user (@sorted_users) {
1.4 raeburn 3170: my %in;
1.2 raeburn 3171: my $sdata = $userlist->{$user};
1.4 raeburn 3172: $rowcount ++;
1.2 raeburn 3173: foreach my $item (@{$keylist}) {
3174: $in{$item} = $sdata->[$index{$item}];
3175: }
1.67 droeschl 3176: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3177: if ($clickers!~/\w/) { $clickers='-'; }
1.159 raeburn 3178: $in{'clicker'} = $clickers;
1.67 droeschl 3179: my $role = $in{'role'};
1.102 raeburn 3180: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
1.136 raeburn 3181: unless ($mode eq 'excel') {
3182: if (! defined($in{'start'}) || $in{'start'} == 0) {
3183: $in{'start'} = &mt('none');
3184: } else {
3185: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
3186: }
3187: if (! defined($in{'end'}) || $in{'end'} == 0) {
3188: $in{'end'} = &mt('none');
3189: } else {
3190: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
3191: }
1.1 raeburn 3192: }
1.139 raeburn 3193: if ($context eq 'course') {
3194: my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
3195: if ($lastlogin ne '') {
3196: $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
3197: }
3198: }
1.55 raeburn 3199: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3200: $r->print(&Apache::loncommon::start_data_table_row());
1.11 raeburn 3201: my $checkval;
1.16 raeburn 3202: if ($mode eq 'autoenroll') {
3203: my $cellentry;
3204: if ($in{'type'} eq 'auto') {
1.178 raeburn 3205: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label>';
1.16 raeburn 3206: $autocount ++;
3207: } else {
1.178 raeburn 3208: $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><span class="LC_nobreak"><label><input type="checkbox" name="chgmanual" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label></span></td></tr><tr><td><span class="LC_nobreak">';
1.16 raeburn 3209: $manualcount ++;
3210: if ($in{'lockedtype'}) {
1.178 raeburn 3211: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Unlock').'</label>';
1.16 raeburn 3212: $unlockcount ++;
3213: } else {
1.178 raeburn 3214: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Lock').'</label>';
1.16 raeburn 3215: $lockcount ++;
1.11 raeburn 3216: }
1.76 bisitz 3217: $cellentry .= '</span></td></tr></table>';
1.16 raeburn 3218: }
3219: $r->print("<td>$cellentry</td>\n");
3220: } else {
1.55 raeburn 3221: if ($mode ne 'pickauthor') {
3222: $r->print("<td>$rowcount</td>\n");
3223: }
1.16 raeburn 3224: if ($actionselect) {
1.26 raeburn 3225: my $showcheckbox;
3226: if ($role =~ /^cr\//) {
3227: $showcheckbox = $canchange{'cr'};
3228: } else {
3229: $showcheckbox = $canchange{$role};
3230: }
3231: if (!$showcheckbox) {
3232: if ($context eq 'course') {
3233: if ($canchangesec{$role} ne '') {
3234: if ($canchangesec{$role} eq $in{'section'}) {
3235: $showcheckbox = 1;
3236: }
3237: }
1.16 raeburn 3238: }
1.26 raeburn 3239: }
3240: if ($showcheckbox) {
3241: $checkval = $user;
3242: if ($context eq 'course') {
1.141 raeburn 3243: if (($role eq 'co' || $role eq 'cc') &&
3244: ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
3245: $showcheckbox = 0;
3246: } else {
3247: if ($role eq 'st') {
3248: $checkval .= ':st';
3249: }
3250: $checkval .= ':'.$in{'section'};
3251: if ($role eq 'st') {
3252: $checkval .= ':'.$in{'type'}.':'.
1.150 raeburn 3253: $in{'lockedtype'}.':'.
1.174 raeburn 3254: $in{'credits'}.':'.
3255: &escape($in{'instsec'});
1.141 raeburn 3256: }
3257: }
3258: }
3259: if ($showcheckbox) {
3260: $r->print('<td><input type="checkbox" name="'.
1.183 raeburn 3261: 'actionlist" value="'.
3262: &HTML::Entities::encode($checkval,'&<>"').'" />');
3263: foreach my $item ('start','end') {
3264: $r->print('<input type="hidden" name="'.
3265: &HTML::Entities::encode($checkval.'_'.$item,'&<>"').'"'.
3266: ' value="'.$sdata->[$index{$item}].'" />');
3267: }
3268: $r->print('</td>');
1.141 raeburn 3269: } else {
3270: $r->print('<td> </td>');
1.16 raeburn 3271: }
1.26 raeburn 3272: } else {
3273: $r->print('<td> </td>');
1.16 raeburn 3274: }
1.55 raeburn 3275: } elsif ($mode eq 'pickauthor') {
3276: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
1.11 raeburn 3277: }
3278: }
1.2 raeburn 3279: foreach my $item (@cols) {
1.10 raeburn 3280: if ($item eq 'username') {
1.48 raeburn 3281: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.83 raeburn 3282: } elsif ($item eq 'status') {
3283: my $showitem = $in{$item};
3284: if (defined($ltstatus{$in{$item}})) {
3285: $showitem = $ltstatus{$in{$item}};
3286: }
3287: $r->print('<td>'.$showitem.'</td>'."\n");
1.140 raeburn 3288: } elsif ($item eq 'photo') {
3289: if (($context eq 'course') && ($mode ne 'autoenroll') &&
3290: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
3291: if ($role eq 'st') {
3292: $r->print('<td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
3293: } else {
3294: $r->print('<td> </td>');
3295: }
3296: }
3297: } elsif ($item eq 'clicker') {
3298: if (($context eq 'course') && ($mode ne 'autoenroll')) {
3299: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
3300: my $clickers =
3301: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3302: if ($clickers!~/\w/) { $clickers='-'; }
3303: $r->print('<td>'.$clickers.'</td>');
3304: } else {
3305: $r->print('<td> </td>'."\n");
3306: }
1.149 raeburn 3307: }
1.159 raeburn 3308: } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
3309: $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
1.10 raeburn 3310: } else {
3311: $r->print('<td>'.$in{$item}.'</td>'."\n");
3312: }
1.2 raeburn 3313: }
3314: $r->print(&Apache::loncommon::end_data_table_row());
3315: } elsif ($mode eq 'csv') {
3316: next if (! defined($CSVfile));
3317: # no need to bother with $linkto
3318: my @line = ();
3319: foreach my $item (@cols) {
3320: push @line,&Apache::loncommon::csv_translate($in{$item});
3321: }
1.67 droeschl 3322: print $CSVfile '"'.join('","',@line)."\"\n";
1.2 raeburn 3323: } elsif ($mode eq 'excel') {
3324: my $col = 0;
3325: foreach my $item (@cols) {
3326: if ($item eq 'start' || $item eq 'end') {
1.136 raeburn 3327: if ((defined($in{$item})) && ($in{$item} != 0)) {
1.2 raeburn 3328: $excel_sheet->write($row,$col++,
1.136 raeburn 3329: &Apache::lonstathelpers::calc_serial($in{$item}),
1.2 raeburn 3330: $format->{'date'});
3331: } else {
3332: $excel_sheet->write($row,$col++,'none');
3333: }
3334: } else {
3335: $excel_sheet->write($row,$col++,$in{$item});
3336: }
3337: }
3338: $row++;
1.1 raeburn 3339: }
3340: }
1.55 raeburn 3341: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3342: $r->print(&Apache::loncommon::end_data_table().'<br />');
3343: } elsif ($mode eq 'excel') {
3344: $excel_workbook->close();
1.162 bisitz 3345: $r->print('<p>'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<a href="'.$excel_filename.'">','</a>')."</p>\n");
1.2 raeburn 3346: } elsif ($mode eq 'csv') {
3347: close($CSVfile);
1.162 bisitz 3348: $r->print('<p>'.&mt('[_1]Your CSV file[_2] is ready for download.', '<a href="'.$CSVfilename.'">','</a>')."</p>\n");
1.2 raeburn 3349: $r->rflush();
3350: }
3351: if ($mode eq 'autoenroll') {
3352: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 3353: } else {
3354: return ($usercount);
1.2 raeburn 3355: }
1.1 raeburn 3356: }
3357:
1.56 raeburn 3358: sub bulkaction_javascript {
3359: my ($formname,$caller) = @_;
3360: my $docstart = 'document';
3361: if ($caller eq 'popup') {
3362: $docstart = 'opener.document';
3363: }
3364: my %lt = &Apache::lonlocal::texthash(
3365: acwi => 'Access will be set to start immediately',
3366: asyo => 'as you did not select an end date in the pop-up window',
3367: accw => 'Access will be set to continue indefinitely',
3368: asyd => 'as you did not select an end date in the pop-up window',
3369: sewi => "Sections will be switched to 'No section'",
3370: ayes => "as you either selected the 'No section' option",
3371: oryo => 'or you did not select a section in the pop-up window',
3372: arol => 'A role with no section will be added',
3373: swbs => 'Sections will be switched to:',
3374: rwba => 'Roles will be added for section(s):',
3375: );
3376: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
3377: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
3378: my $singconfirm = &mt(' for a single user?');
3379: my $multconfirm = &mt(' for multiple users?');
1.170 damieng 3380: &js_escape(\$alert);
3381: &js_escape(\$noaction);
3382: &js_escape(\$singconfirm);
3383: &js_escape(\$multconfirm);
1.56 raeburn 3384: my $output = <<"ENDJS";
3385: function verify_action (field) {
3386: var numchecked = 0;
3387: var singconf = '$singconfirm';
3388: var multconf = '$multconfirm';
3389: if ($docstart.$formname.elements[field].length > 0) {
3390: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
3391: if ($docstart.$formname.elements[field][i].checked == true) {
3392: numchecked ++;
3393: }
3394: }
3395: } else {
3396: if ($docstart.$formname.elements[field].checked == true) {
3397: numchecked ++;
3398: }
3399: }
3400: if (numchecked == 0) {
3401: alert("$alert");
3402: return;
3403: } else {
3404: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
3405: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
3406: if (choice == '') {
3407: alert("$noaction");
3408: return;
3409: } else {
3410: if (numchecked == 1) {
3411: message += singconf;
3412: } else {
3413: message += multconf;
3414: }
3415: ENDJS
3416: if ($caller ne 'popup') {
3417: $output .= <<"NEWWIN";
3418: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
3419: opendatebrowser(document.$formname,'$formname','go');
3420: return;
3421:
3422: } else {
3423: if (confirm(message)) {
3424: document.$formname.phase.value = 'bulkchange';
3425: document.$formname.submit();
3426: return;
3427: }
3428: }
3429: NEWWIN
3430: } else {
3431: $output .= <<"POPUP";
3432: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
3433: var datemsg = '';
3434: if (($docstart.$formname.startdate_month.value == '') &&
3435: ($docstart.$formname.startdate_day.value == '') &&
3436: ($docstart.$formname.startdate_year.value == '')) {
3437: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
3438: }
3439: if (($docstart.$formname.enddate_month.value == '') &&
3440: ($docstart.$formname.enddate_day.value == '') &&
3441: ($docstart.$formname.enddate_year.value == '')) {
3442: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
3443: }
3444: if (datemsg != '') {
3445: message += "\\n"+datemsg;
3446: }
3447: }
3448: if (choice == 'chgsec') {
3449: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
3450: var retained = $docstart.$formname.retainsec.value;
3451: var secshow = $docstart.$formname.newsecs.value;
3452: if (secshow == '') {
3453: if (rolefilter == 'st' || retained == 0 || retained == "") {
3454: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3455: } else {
3456: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3457: }
3458: } else {
3459: if (rolefilter == 'st' || retained == 0 || retained == "") {
3460: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
3461: } else {
3462: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
3463: }
3464: }
3465: }
3466: if (confirm(message)) {
3467: $docstart.$formname.phase.value = 'bulkchange';
3468: $docstart.$formname.submit();
3469: window.close();
3470: }
3471: POPUP
3472: }
3473: $output .= '
3474: }
3475: }
3476: }
3477: ';
3478: return $output;
3479: }
3480:
1.10 raeburn 3481: sub print_username_link {
1.48 raeburn 3482: my ($mode,$in) = @_;
1.10 raeburn 3483: my $output;
1.16 raeburn 3484: if ($mode eq 'autoenroll') {
3485: $output = $in->{'username'};
1.10 raeburn 3486: } else {
3487: $output = '<a href="javascript:username_display_launch('.
1.112 bisitz 3488: "'$in->{'username'}','$in->{'domain'}'".')">'.
1.10 raeburn 3489: $in->{'username'}.'</a>';
3490: }
3491: return $output;
3492: }
3493:
1.2 raeburn 3494: sub role_type_names {
3495: my %lt = &Apache::lonlocal::texthash (
1.13 raeburn 3496: 'domain' => 'Domain Roles',
3497: 'author' => 'Co-Author Roles',
3498: 'course' => 'Course Roles',
1.101 raeburn 3499: 'community' => 'Community Roles',
1.2 raeburn 3500: );
3501: return %lt;
3502: }
3503:
1.11 raeburn 3504: sub select_actions {
1.55 raeburn 3505: my ($context,$setting,$statusmode,$formname) = @_;
1.11 raeburn 3506: my %lt = &Apache::lonlocal::texthash(
3507: revoke => "Revoke user roles",
3508: delete => "Delete user roles",
3509: reenable => "Re-enable expired user roles",
3510: activate => "Make future user roles active now",
3511: chgdates => "Change starting/ending dates",
3512: chgsec => "Change section associated with user roles",
3513: );
1.150 raeburn 3514: # FIXME Add an option to change credits for student roles.
1.11 raeburn 3515: my ($output,$options,%choices);
1.23 raeburn 3516: # FIXME Disable actions for now for roletype=course in domain context
3517: if ($context eq 'domain' && $setting eq 'course') {
3518: return;
3519: }
1.26 raeburn 3520: if ($context eq 'course') {
3521: if ($env{'form.showrole'} ne 'Any') {
1.141 raeburn 3522: my $showactions;
3523: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
3524: $env{'request.course.id'})) {
3525: $showactions = 1;
3526: } elsif ($env{'request.course.sec'} ne '') {
3527: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3528: $showactions = 1;
3529: }
3530: }
3531: unless ($showactions) {
3532: unless (&is_courseowner($env{'request.course.id'},
3533: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3534: return;
3535: }
1.26 raeburn 3536: }
3537: }
3538: }
1.11 raeburn 3539: if ($statusmode eq 'Any') {
3540: $options .= '
3541: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
3542: $choices{'dates'} = 1;
3543: } else {
3544: if ($statusmode eq 'Future') {
3545: $options .= '
3546: <option value="activate">'.$lt{'activate'}.'</option>';
3547: $choices{'dates'} = 1;
3548: } elsif ($statusmode eq 'Expired') {
3549: $options .= '
3550: <option value="reenable">'.$lt{'reenable'}.'</option>';
3551: $choices{'dates'} = 1;
3552: }
1.13 raeburn 3553: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
3554: $options .= '
3555: <option value="chgdates">'.$lt{'chgdates'}.'</option>
3556: <option value="revoke">'.$lt{'revoke'}.'</option>';
3557: $choices{'dates'} = 1;
3558: }
1.11 raeburn 3559: }
3560: if ($context eq 'domain') {
3561: $options .= '
3562: <option value="delete">'.$lt{'delete'}.'</option>';
3563: }
3564: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26 raeburn 3565: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11 raeburn 3566: $options .= '
3567: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
3568: $choices{'sections'} = 1;
3569: }
3570: }
3571: if ($options) {
1.56 raeburn 3572: $output = '<select name="bulkaction">'."\n".
1.11 raeburn 3573: '<option value="" selected="selected">'.
3574: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
3575: if ($choices{'dates'}) {
3576: $output .=
3577: '<input type="hidden" name="startdate_month" value="" />'."\n".
3578: '<input type="hidden" name="startdate_day" value="" />'."\n".
3579: '<input type="hidden" name="startdate_year" value="" />'."\n".
3580: '<input type="hidden" name="startdate_hour" value="" />'."\n".
3581: '<input type="hidden" name="startdate_minute" value="" />'."\n".
3582: '<input type="hidden" name="startdate_second" value="" />'."\n".
3583: '<input type="hidden" name="enddate_month" value="" />'."\n".
3584: '<input type="hidden" name="enddate_day" value="" />'."\n".
3585: '<input type="hidden" name="enddate_year" value="" />'."\n".
3586: '<input type="hidden" name="enddate_hour" value="" />'."\n".
3587: '<input type="hidden" name="enddate_minute" value="" />'."\n".
1.56 raeburn 3588: '<input type="hidden" name="enddate_second" value="" />'."\n".
3589: '<input type="hidden" name="no_end_date" value="" />'."\n";
1.11 raeburn 3590: if ($context eq 'course') {
3591: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
3592: }
3593: }
3594: if ($choices{'sections'}) {
1.91 bisitz 3595: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
3596: '<input type="hidden" name="newsecs" value="" />'."\n";
1.11 raeburn 3597: }
3598: }
3599: return $output;
3600: }
3601:
3602: sub date_section_javascript {
3603: my ($context,$setting) = @_;
1.49 raeburn 3604: my $title = 'Date_And_Section_Selector';
1.41 raeburn 3605: my %nopopup = &Apache::lonlocal::texthash (
3606: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
3607: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
3608: none => "Choose an action to take for selected users",
3609: );
1.96 bisitz 3610: my $output = <<"ENDONE";
3611: <script type="text/javascript">
3612: // <![CDATA[
1.41 raeburn 3613: function opendatebrowser(callingform,formname,calledby) {
1.11 raeburn 3614: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
3615: var url = '/adm/createuser?';
3616: var type = '';
3617: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
3618: ENDONE
3619: if ($context eq 'domain') {
3620: $output .= '
3621: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
3622: ';
3623: }
3624: my $width= '700';
3625: my $height = '400';
3626: $output .= <<"ENDTWO";
3627: url += 'action=dateselect&callingform=' + formname +
3628: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
3629: var title = '$title';
3630: var options = 'scrollbars=1,resizable=1,menubar=0';
3631: options += ',width=$width,height=$height';
3632: stdeditbrowser = open(url,title,options,'1');
3633: stdeditbrowser.focus();
3634: }
1.96 bisitz 3635: // ]]>
1.11 raeburn 3636: </script>
3637: ENDTWO
3638: return $output;
3639: }
3640:
3641: sub date_section_selector {
1.150 raeburn 3642: my ($context,$permission,$crstype,$showcredits) = @_;
1.11 raeburn 3643: my $callingform = $env{'form.callingform'};
3644: my $formname = 'dateselect';
3645: my $groupslist = &get_groupslist();
1.150 raeburn 3646: my $sec_js =
3647: &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
3648: $showcredits);
1.11 raeburn 3649: my $output = <<"END";
3650: <script type="text/javascript">
1.96 bisitz 3651: // <![CDATA[
1.11 raeburn 3652:
3653: $sec_js
3654:
3655: function saveselections(formname) {
3656:
3657: END
3658: if ($env{'form.bulkaction'} eq 'chgsec') {
3659: $output .= <<"END";
1.40 raeburn 3660: if (formname.retainsec.length > 1) {
3661: for (var i=0; i<formname.retainsec.length; i++) {
3662: if (formname.retainsec[i].checked == true) {
3663: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
3664: }
3665: }
3666: } else {
3667: opener.document.$callingform.retainsec.value = formname.retainsec.value;
3668: }
1.103 raeburn 3669: setSections(formname,'$crstype');
1.11 raeburn 3670: if (seccheck == 'ok') {
3671: opener.document.$callingform.newsecs.value = formname.sections.value;
3672: }
3673: END
3674: } else {
3675: if ($context eq 'course') {
3676: if (($env{'form.bulkaction'} eq 'reenable') ||
3677: ($env{'form.bulkaction'} eq 'activate') ||
3678: ($env{'form.bulkaction'} eq 'chgdates')) {
1.26 raeburn 3679: if ($env{'request.course.sec'} eq '') {
3680: $output .= <<"END";
1.11 raeburn 3681:
3682: if (formname.makedatesdefault.checked == true) {
3683: opener.document.$callingform.makedatesdefault.value = 1;
3684: }
3685: else {
3686: opener.document.$callingform.makedatesdefault.value = 0;
3687: }
3688:
3689: END
1.26 raeburn 3690: }
1.11 raeburn 3691: }
3692: }
3693: $output .= <<"END";
3694: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
3695: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
3696: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
3697: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
3698: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
3699: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
3700: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
3701: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
3702: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
3703: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
3704: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
3705: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
1.56 raeburn 3706: if (formname.no_end_date.checked) {
3707: opener.document.$callingform.no_end_date.value = '1';
3708: } else {
3709: opener.document.$callingform.no_end_date.value = '0';
3710: }
1.11 raeburn 3711: END
3712: }
1.56 raeburn 3713: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
3714: $output .= <<"ENDJS";
3715: verify_action('actionlist');
1.11 raeburn 3716: }
1.56 raeburn 3717:
3718: $verify_action_js
3719:
1.96 bisitz 3720: // ]]>
1.11 raeburn 3721: </script>
1.56 raeburn 3722: ENDJS
1.11 raeburn 3723: my %lt = &Apache::lonlocal::texthash (
3724: chac => 'Access dates to apply for selected users',
3725: chse => 'Changes in section affiliation to apply to selected users',
1.118 raeburn 3726: fors => 'For student roles, changing the section will result in a section switch as students may only be in one section of a course at a time.',
3727: forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
3728: reta => "Retain each user's current section affiliations?",
1.103 raeburn 3729: dnap => '(Does not apply to student roles).',
1.11 raeburn 3730: );
3731: my ($date_items,$headertext);
3732: if ($env{'form.bulkaction'} eq 'chgsec') {
3733: $headertext = $lt{'chse'};
3734: } else {
3735: $headertext = $lt{'chac'};
3736: my $starttime;
3737: if (($env{'form.bulkaction'} eq 'activate') ||
3738: ($env{'form.bulkaction'} eq 'reenable')) {
3739: $starttime = time;
3740: }
3741: $date_items = &date_setting_table($starttime,undef,$context,
1.21 raeburn 3742: $env{'form.bulkaction'},$formname,
1.101 raeburn 3743: $permission,$crstype);
1.11 raeburn 3744: }
3745: $output .= '<h3>'.$headertext.'</h3>'.
1.118 raeburn 3746: '<form name="'.$formname.'" method="post" action="">'."\n".
1.11 raeburn 3747: $date_items;
3748: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17 raeburn 3749: my ($cnum,$cdom) = &get_course_identity();
1.103 raeburn 3750: if ($crstype eq 'Community') {
1.118 raeburn 3751: $lt{'fors'} = &mt('For member roles, changing the section will result in a section switch, as members may only be in one section of a community at a time.');
3752: $lt{'forn'} = &mt('For a community role that is not "member", users may have roles in more than one section at a time.');
1.103 raeburn 3753: $lt{'dnap'} = &mt('(Does not apply to member roles).');
3754: }
1.11 raeburn 3755: my $info;
3756: if ($env{'form.showrole'} eq 'st') {
3757: $output .= '<p>'.$lt{'fors'}.'</p>';
1.26 raeburn 3758: } elsif ($env{'form.showrole'} eq 'Any') {
1.11 raeburn 3759: $output .= '<p>'.$lt{'fors'}.'</p>'.
3760: '<p>'.$lt{'forn'}.' ';
3761: $info = $lt{'reta'};
3762: } else {
3763: $output .= '<p>'.$lt{'forn'}.' ';
3764: $info = $lt{'reta'};
3765: }
3766: if ($info) {
3767: $info .= '<span class="LC_nobreak">'.
3768: '<label><input type="radio" name="retainsec" value="1" '.
3769: 'checked="checked" />'.&mt('Yes').'</label> '.
3770: '<label><input type="radio" name="retainsec" value="0" />'.
3771: &mt('No').'</label></span>';
3772: if ($env{'form.showrole'} eq 'Any') {
3773: $info .= '<br />'.$lt{'dnap'};
3774: }
3775: $info .= '</p>';
3776: } else {
3777: $info = '<input type="hidden" name="retainsec" value="0" />';
3778: }
1.21 raeburn 3779: my $rowtitle = &mt('New section to assign');
1.150 raeburn 3780: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,
3781: $permission,$context,'chgsec',$crstype);
1.11 raeburn 3782: $output .= $info.$secbox;
3783: }
3784: $output .= '<p>'.
1.81 schafran 3785: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
1.11 raeburn 3786: '</form>';
3787: return $output;
3788: }
3789:
1.17 raeburn 3790: sub section_picker {
1.150 raeburn 3791: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype,
3792: $showcredits,$credits) = @_;
1.17 raeburn 3793: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3794: my $sections_select .= &course_sections(\%sections_count,$role);
1.118 raeburn 3795: my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
1.17 raeburn 3796: if ($mode eq 'upload') {
3797: my ($options,$cb_script,$coursepick) =
1.150 raeburn 3798: &default_role_selector($context,1,$crstype,$showcredits);
1.59 bisitz 3799: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
1.17 raeburn 3800: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
3801: }
3802: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
3803: if ($env{'request.course.sec'} eq '') {
3804: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
3805: '<td align="center">'.&mt('Existing sections')."\n".
3806: '<br />'.$sections_select.'</td><td align="center">'.
3807: &mt('New section').'<br />'."\n".
1.118 raeburn 3808: '<input type="text" name="newsec" size="15" value="" />'."\n".
1.17 raeburn 3809: '<input type="hidden" name="sections" value="" />'."\n".
3810: '</td></tr></table>'."\n";
3811: } else {
1.149 raeburn 3812: $secbox .= '<input type="hidden" name="sections" value="'.
1.17 raeburn 3813: $env{'request.course.sec'}.'" />'.
3814: $env{'request.course.sec'};
3815: }
1.150 raeburn 3816: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n";
3817: unless ($mode eq 'chgsec') {
3818: if ($showcredits) {
3819: $secbox .=
3820: &Apache::lonhtmlcommon::row_title(&mt('credits (students)'),
3821: 'LC_evenrow_value')."\n".
3822: '<input type="text" name="credits" size="3" value="'.$credits.'" />'."\n".
3823: &Apache::lonhtmlcommon::row_closure(1)."\n";
3824: }
3825: }
3826: $secbox .= &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.17 raeburn 3827: return $secbox;
3828: }
3829:
1.2 raeburn 3830: sub results_header_row {
1.102 raeburn 3831: my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
1.5 raeburn 3832: my ($description,$showfilter);
3833: if ($rolefilter ne 'Any') {
3834: $showfilter = $rolefilter;
3835: }
1.2 raeburn 3836: if ($context eq 'course') {
1.24 raeburn 3837: if ($mode eq 'csv' || $mode eq 'excel') {
1.102 raeburn 3838: if ($crstype eq 'Community') {
3839: $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
3840: } else {
3841: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
3842: }
1.24 raeburn 3843: }
1.2 raeburn 3844: if ($statusmode eq 'Expired') {
1.102 raeburn 3845: if ($crstype eq 'Community') {
3846: $description .= &mt('Users in community with expired [_1] roles',$showfilter);
3847: } else {
3848: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
3849: }
1.11 raeburn 3850: } elsif ($statusmode eq 'Future') {
1.102 raeburn 3851: if ($crstype eq 'Community') {
3852: $description .= &mt('Users in community with future [_1] roles',$showfilter);
3853: } else {
3854: $description .= &mt('Users in course with future [_1] roles',$showfilter);
3855: }
1.2 raeburn 3856: } elsif ($statusmode eq 'Active') {
1.102 raeburn 3857: if ($crstype eq 'Community') {
3858: $description .= &mt('Users in community with active [_1] roles',$showfilter);
3859: } else {
3860: $description .= &mt('Users in course with active [_1] roles',$showfilter);
3861: }
1.2 raeburn 3862: } else {
3863: if ($rolefilter eq 'Any') {
1.102 raeburn 3864: if ($crstype eq 'Community') {
3865: $description .= &mt('All users in community');
3866: } else {
3867: $description .= &mt('All users in course');
3868: }
1.2 raeburn 3869: } else {
1.102 raeburn 3870: if ($crstype eq 'Community') {
3871: $description .= &mt('All users in community with [_1] roles',$rolefilter);
3872: } else {
3873: $description .= &mt('All users in course with [_1] roles',$rolefilter);
3874: }
1.2 raeburn 3875: }
3876: }
1.33 raeburn 3877: my $constraint;
1.26 raeburn 3878: my $viewablesec = &viewable_section($permission);
3879: if ($viewablesec ne '') {
1.15 raeburn 3880: if ($env{'form.showrole'} eq 'st') {
1.33 raeburn 3881: $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.103 raeburn 3882: } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
1.33 raeburn 3883: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
3884: }
3885: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
3886: if ($env{'form.grpfilter'} eq 'none') {
3887: $constraint .= &mt(' and not in any group');
3888: } else {
3889: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
3890: }
3891: }
3892: } else {
3893: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
3894: if ($env{'form.secfilter'} eq 'none') {
3895: $constraint = &mt('only users affiliated with no section');
3896: } else {
3897: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
3898: }
3899: }
3900: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
3901: if ($env{'form.grpfilter'} eq 'none') {
3902: if ($constraint eq '') {
3903: $constraint = &mt('only users not in any group');
3904: } else {
3905: $constraint .= &mt(' and also not in any group');
3906: }
3907: } else {
3908: if ($constraint eq '') {
3909: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
3910: } else {
3911: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
3912: }
3913: }
1.15 raeburn 3914: }
3915: }
1.33 raeburn 3916: if ($constraint ne '') {
3917: $description .= ' ('.$constraint.')';
3918: }
1.13 raeburn 3919: } elsif ($context eq 'author') {
1.14 raeburn 3920: $description =
1.73 bisitz 3921: &mt('Author space for [_1]'
3922: ,'<span class="LC_cusr_emph">'
3923: .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})
3924: .'</span>')
3925: .': ';
1.2 raeburn 3926: if ($statusmode eq 'Expired') {
1.5 raeburn 3927: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 3928: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3929: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 3930: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3931: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 3932: } else {
3933: if ($rolefilter eq 'Any') {
1.5 raeburn 3934: $description .= &mt('All co-authors');
1.2 raeburn 3935: } else {
3936: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
3937: }
3938: }
3939: } elsif ($context eq 'domain') {
3940: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.73 bisitz 3941: $description = &mt('Domain - [_1]:',$domdesc).' ';
1.2 raeburn 3942: if ($env{'form.roletype'} eq 'domain') {
3943: if ($statusmode eq 'Expired') {
1.5 raeburn 3944: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 3945: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3946: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 3947: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3948: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 3949: } else {
3950: if ($rolefilter eq 'Any') {
1.5 raeburn 3951: $description .= &mt('All users in domain');
1.2 raeburn 3952: } else {
3953: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
3954: }
3955: }
1.13 raeburn 3956: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3957: if ($statusmode eq 'Expired') {
1.5 raeburn 3958: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 3959: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3960: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 3961: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3962: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 3963: } else {
3964: if ($rolefilter eq 'Any') {
1.5 raeburn 3965: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 3966: } else {
1.116 bisitz 3967: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
1.2 raeburn 3968: }
3969: }
1.102 raeburn 3970: } elsif (($env{'form.roletype'} eq 'course') ||
3971: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 3972: my $coursefilter = $env{'form.coursepick'};
1.102 raeburn 3973: if ($env{'form.roletype'} eq 'course') {
3974: if ($coursefilter eq 'category') {
3975: my $instcode = &instcode_from_coursefilter();
3976: if ($instcode eq '.') {
3977: $description .= &mt('All courses in domain').' - ';
3978: } else {
3979: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
3980: }
3981: } elsif ($coursefilter eq 'selected') {
3982: $description .= &mt('Selected courses in domain').' - ';
3983: } elsif ($coursefilter eq 'all') {
1.2 raeburn 3984: $description .= &mt('All courses in domain').' - ';
3985: }
1.102 raeburn 3986: } elsif ($env{'form.roletype'} eq 'community') {
3987: if ($coursefilter eq 'selected') {
3988: $description .= &mt('Selected communities in domain').' - ';
3989: } elsif ($coursefilter eq 'all') {
3990: $description .= &mt('All communities in domain').' - ';
3991: }
1.2 raeburn 3992: }
3993: if ($statusmode eq 'Expired') {
1.5 raeburn 3994: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 3995: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3996: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 3997: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3998: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 3999: } else {
4000: if ($rolefilter eq 'Any') {
4001: $description .= &mt('all users');
4002: } else {
4003: $description .= &mt('users with [_1] roles',$rolefilter);
4004: }
4005: }
4006: }
4007: }
4008: return $description;
4009: }
1.22 raeburn 4010:
4011: sub viewable_section {
4012: my ($permission) = @_;
4013: my $viewablesec;
4014: if (ref($permission) eq 'HASH') {
4015: if (exists($permission->{'view_section'})) {
4016: $viewablesec = $permission->{'view_section'};
4017: } elsif (exists($permission->{'cusr_section'})) {
4018: $viewablesec = $permission->{'cusr_section'};
4019: }
4020: }
4021: return $viewablesec;
4022: }
4023:
1.2 raeburn 4024:
1.1 raeburn 4025: #################################################
4026: #################################################
4027: sub show_drop_list {
1.101 raeburn 4028: my ($r,$classlist,$nosort,$permission,$crstype) = @_;
1.29 raeburn 4029: my $cid = $env{'request.course.id'};
1.17 raeburn 4030: my ($cnum,$cdom) = &get_course_identity($cid);
1.1 raeburn 4031: if (! exists($env{'form.sortby'})) {
4032: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4033: ['sortby']);
4034: }
4035: my $sortby = $env{'form.sortby'};
4036: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
4037: $sortby = 'username';
4038: }
4039: my $action = "drop";
1.17 raeburn 4040: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1 raeburn 4041: $r->print(<<END);
4042: <input type="hidden" name="sortby" value="$sortby" />
4043: <input type="hidden" name="action" value="$action" />
4044: <input type="hidden" name="state" value="done" />
1.17 raeburn 4045: <script type="text/javascript" language="Javascript">
1.96 bisitz 4046: // <![CDATA[
1.17 raeburn 4047: $check_uncheck_js
1.96 bisitz 4048: // ]]>
1.1 raeburn 4049: </script>
1.86 bisitz 4050: <input type="hidden" name="phase" value="four" />
1.1 raeburn 4051: END
1.30 raeburn 4052: my ($indexhash,$keylist) = &make_keylist_array();
4053: my $studentcount = 0;
4054: if (ref($classlist) eq 'HASH') {
4055: foreach my $student (keys(%{$classlist})) {
4056: my $sdata = $classlist->{$student};
4057: my $status = $sdata->[$indexhash->{'status'}];
4058: my $section = $sdata->[$indexhash->{'section'}];
4059: if ($status ne 'Active') {
4060: delete($classlist->{$student});
4061: next;
4062: }
4063: if ($env{'request.course.sec'} ne '') {
4064: if ($section ne $env{'request.course.sec'}) {
4065: delete($classlist->{$student});
4066: next;
4067: }
4068: }
4069: $studentcount ++;
4070: }
4071: }
4072: if (!$studentcount) {
1.143 bisitz 4073: my $msg = '';
1.101 raeburn 4074: if ($crstype eq 'Community') {
1.143 bisitz 4075: $msg = &mt('There are no members to drop.');
1.101 raeburn 4076: } else {
1.143 bisitz 4077: $msg = &mt('There are no students to drop.');
1.101 raeburn 4078: }
1.143 bisitz 4079: $r->print('<p class="LC_info">'.$msg.'</p>');
1.30 raeburn 4080: return;
4081: }
4082: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
4083: $classlist,$keylist,$cdom,$cnum);
4084: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
4085: 'dom' => "domain",
1.162 bisitz 4086: 'id' => "ID",
1.30 raeburn 4087: 'sn' => "student name",
1.101 raeburn 4088: 'mn' => "member name",
1.30 raeburn 4089: 'sec' => "section",
4090: 'start' => "start date",
4091: 'end' => "end date",
4092: 'groups' => "active groups",
4093: );
1.101 raeburn 4094: my $nametitle = $lt{'sn'};
4095: if ($crstype eq 'Community') {
4096: $nametitle = $lt{'mn'};
4097: }
1.1 raeburn 4098: if ($nosort) {
1.17 raeburn 4099: $r->print(&Apache::loncommon::start_data_table().
4100: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4101: $r->print(<<END);
4102: <th> </th>
4103: <th>$lt{'usrn'}</th>
4104: <th>$lt{'dom'}</th>
1.162 bisitz 4105: <th>$lt{'id'}</th>
1.101 raeburn 4106: <th>$nametitle</th>
1.1 raeburn 4107: <th>$lt{'sec'}</th>
4108: <th>$lt{'start'}</th>
4109: <th>$lt{'end'}</th>
4110: <th>$lt{'groups'}</th>
4111: END
1.17 raeburn 4112: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4113: } else {
1.17 raeburn 4114: $r->print(&Apache::loncommon::start_data_table().
4115: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4116: $r->print(<<END);
1.17 raeburn 4117: <th> </th>
1.1 raeburn 4118: <th>
1.162 bisitz 4119: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1 raeburn 4120: </th><th>
1.162 bisitz 4121: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1 raeburn 4122: </th><th>
1.162 bisitz 4123: <a href="/adm/createuser?action=$action&sortby=id">$lt{'id'}</a>
1.1 raeburn 4124: </th><th>
1.162 bisitz 4125: <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
1.1 raeburn 4126: </th><th>
1.162 bisitz 4127: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1 raeburn 4128: </th><th>
1.162 bisitz 4129: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1 raeburn 4130: </th><th>
1.162 bisitz 4131: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1 raeburn 4132: </th><th>
1.162 bisitz 4133: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1 raeburn 4134: </th>
4135: END
1.17 raeburn 4136: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4137: }
4138: #
4139: # Sort the students
1.30 raeburn 4140: my $index = $indexhash->{$sortby};
4141: my $second = $indexhash->{'username'};
4142: my $third = $indexhash->{'domain'};
1.1 raeburn 4143: my @Sorted_Students = sort {
4144: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
4145: ||
4146: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
4147: ||
4148: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30 raeburn 4149: } (keys(%{$classlist}));
1.1 raeburn 4150: foreach my $student (@Sorted_Students) {
4151: my $error;
4152: my $sdata = $classlist->{$student};
1.30 raeburn 4153: my $username = $sdata->[$indexhash->{'username'}];
4154: my $domain = $sdata->[$indexhash->{'domain'}];
4155: my $section = $sdata->[$indexhash->{'section'}];
4156: my $name = $sdata->[$indexhash->{'fullname'}];
4157: my $id = $sdata->[$indexhash->{'id'}];
4158: my $start = $sdata->[$indexhash->{'start'}];
4159: my $end = $sdata->[$indexhash->{'end'}];
1.1 raeburn 4160: my $groups = $classgroups->{$student};
4161: my $active_groups;
4162: if (ref($groups->{active}) eq 'HASH') {
4163: $active_groups = join(', ',keys(%{$groups->{'active'}}));
4164: }
4165: if (! defined($start) || $start == 0) {
4166: $start = &mt('none');
4167: } else {
4168: $start = &Apache::lonlocal::locallocaltime($start);
4169: }
4170: if (! defined($end) || $end == 0) {
4171: $end = &mt('none');
4172: } else {
4173: $end = &Apache::lonlocal::locallocaltime($end);
4174: }
1.17 raeburn 4175: my $studentkey = $student.':'.$section;
1.30 raeburn 4176: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1 raeburn 4177: #
4178: $r->print(&Apache::loncommon::start_data_table_row());
4179: $r->print(<<"END");
1.86 bisitz 4180: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
1.1 raeburn 4181: <td>$username</td>
4182: <td>$domain</td>
4183: <td>$id</td>
4184: <td>$name</td>
4185: <td>$section</td>
1.29 raeburn 4186: <td>$start $startitem</td>
1.1 raeburn 4187: <td>$end</td>
4188: <td>$active_groups</td>
4189: END
4190: $r->print(&Apache::loncommon::end_data_table_row());
4191: }
4192: $r->print(&Apache::loncommon::end_data_table().'<br />');
4193: %lt=&Apache::lonlocal::texthash(
1.29 raeburn 4194: 'dp' => "Drop Students",
1.101 raeburn 4195: 'dm' => "Drop Members",
1.1 raeburn 4196: 'ca' => "check all",
4197: 'ua' => "uncheck all",
4198: );
1.101 raeburn 4199: my $btn = $lt{'dp'};
4200: if ($crstype eq 'Community') {
4201: $btn = $lt{'dm'};
4202: }
1.1 raeburn 4203: $r->print(<<"END");
1.89 bisitz 4204: <p>
1.86 bisitz 4205: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
4206: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
1.89 bisitz 4207: </p>
4208: <p>
1.101 raeburn 4209: <input type="submit" value="$btn" />
1.89 bisitz 4210: </p>
1.1 raeburn 4211: END
4212: return;
4213: }
4214:
4215: #
4216: # Print out the initial form to get the file containing a list of users
4217: #
4218: sub print_first_users_upload_form {
4219: my ($r,$context) = @_;
4220: my $str;
1.86 bisitz 4221: $str = '<input type="hidden" name="phase" value="two" />';
1.1 raeburn 4222: $str .= '<input type="hidden" name="action" value="upload" />';
1.101 raeburn 4223: $str .= '<input type="hidden" name="state" value="got_file" />';
1.95 bisitz 4224:
1.147 bisitz 4225: $str .= &Apache::grades::checkforfile_js();
4226:
1.85 bisitz 4227: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
1.95 bisitz 4228:
4229: # Excel and CSV Help
1.147 bisitz 4230: $str .= '<div class="LC_columnSection">'
1.95 bisitz 4231: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
4232: &mt("How do I create a users list from a spreadsheet"))
1.147 bisitz 4233: .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.95 bisitz 4234: &mt("How do I create a CSV file from a spreadsheet"))
1.147 bisitz 4235: ."</div>\n";
1.95 bisitz 4236: $str .= &Apache::lonhtmlcommon::start_pick_box()
1.103 raeburn 4237: .&Apache::lonhtmlcommon::row_title(&mt('File'));
4238: if (&Apache::lonlocal::current_language() ne 'en') {
4239: if ($context eq 'course') {
4240: $str .= '<p class="LC_info">'."\n"
4241: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
4242: .'</p>'."\n";
4243: }
4244: }
4245: $str .= &Apache::loncommon::upfile_select_html()
1.95 bisitz 4246: .&Apache::lonhtmlcommon::row_closure()
4247: .&Apache::lonhtmlcommon::row_title(
4248: '<label for="noFirstLine">'
4249: .&mt('Ignore First Line')
4250: .'</label>')
4251: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
4252: .&Apache::lonhtmlcommon::row_closure(1)
4253: .&Apache::lonhtmlcommon::end_pick_box();
4254:
4255: $str .= '<p>'
1.198 raeburn 4256: .'<input type="button" name="fileupload" value="'.&mt('Next').'"'
1.147 bisitz 4257: .' onclick="javascript:checkUpload(this.form);" />'
1.95 bisitz 4258: .'</p>';
4259:
1.1 raeburn 4260: $r->print($str);
4261: return;
4262: }
4263:
4264: # ================================================= Drop/Add from uploaded file
4265: sub upfile_drop_add {
1.150 raeburn 4266: my ($r,$context,$permission,$showcredits) = @_;
1.189 raeburn 4267: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4268: if ($datatoken ne '') {
4269: &Apache::loncommon::load_tmp_file($r,$datatoken);
4270: }
1.1 raeburn 4271: my @userdata=&Apache::loncommon::upfile_record_sep();
4272: if($env{'form.noFirstLine'}){shift(@userdata);}
4273: my @keyfields = split(/\,/,$env{'form.keyfields'});
4274: my %fields=();
4275: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4276: if ($env{'form.upfile_associate'} eq 'reverse') {
4277: if ($env{'form.f'.$i} ne 'none') {
4278: $fields{$keyfields[$i]}=$env{'form.f'.$i};
4279: }
4280: } else {
4281: $fields{$env{'form.f'.$i}}=$keyfields[$i];
4282: }
4283: }
4284: #
4285: # Store the field choices away
1.150 raeburn 4286: my @storefields = qw/username names fname mname lname gen id
4287: sec ipwd email role domain inststatus/;
4288: if ($showcredits) {
4289: push (@storefields,'credits');
4290: }
4291: my %fieldstype;
4292: foreach my $field (@storefields) {
1.1 raeburn 4293: $env{'form.'.$field.'_choice'}=$fields{$field};
1.150 raeburn 4294: $fieldstype{$field.'_choice'} = 'scalar';
1.1 raeburn 4295: }
1.150 raeburn 4296: &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
1.185 raeburn 4297: my ($cid,$crstype,$setting,$crsdom);
1.101 raeburn 4298: if ($context eq 'domain') {
4299: $setting = $env{'form.roleaction'};
4300: }
4301: if ($env{'request.course.id'} ne '') {
4302: $cid = $env{'request.course.id'};
4303: $crstype = &Apache::loncommon::course_type();
1.185 raeburn 4304: $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.101 raeburn 4305: } elsif ($setting eq 'course') {
4306: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
4307: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
4308: $crstype = &Apache::loncommon::course_type($cid);
1.185 raeburn 4309: $crsdom = $env{'form.dcdomain'};
1.101 raeburn 4310: }
4311: }
1.1 raeburn 4312: my ($startdate,$enddate) = &get_dates_from_form();
4313: if ($env{'form.makedatesdefault'}) {
1.101 raeburn 4314: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 4315: }
4316: # Determine domain and desired host (home server)
1.57 raeburn 4317: my $defdom=$env{'request.role.domain'};
4318: my $domain;
4319: if ($env{'form.defaultdomain'} ne '') {
1.185 raeburn 4320: if (($context eq 'course') || ($setting eq 'course')) {
1.190 raeburn 4321: if ($env{'form.defaultdomain'} eq $crsdom) {
4322: $domain = $env{'form.defaultdomain'};
4323: } else {
1.185 raeburn 4324: if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
4325: $domain = $env{'form.defaultdomain'};
4326: } else {
1.192 raeburn 4327: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4328: &mt('Enrollment of users not permitted for specified default domain: [_1].',
4329: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4330: return 'untrusted';
1.185 raeburn 4331: }
4332: }
4333: } elsif ($context eq 'author') {
1.190 raeburn 4334: if ($env{'form.defaultdomain'} eq $defdom) {
4335: $domain = $env{'form.defaultdomain'};
4336: } else {
1.185 raeburn 4337: if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
1.186 raeburn 4338: (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
1.185 raeburn 4339: $domain = $env{'form.defaultdomain'};
4340: } else {
1.192 raeburn 4341: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4342: &mt('Addition of users not permitted for specified default domain: [_1].',
4343: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4344: return 'untrusted';
1.185 raeburn 4345: }
4346: }
4347: } elsif (($context eq 'domain') && ($setting eq 'domain')) {
1.190 raeburn 4348: if ($env{'form.defaultdomain'} eq $defdom) {
4349: $domain = $env{'form.defaultdomain'};
4350: } else {
1.185 raeburn 4351: if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
4352: $domain = $env{'form.defaultdomain'};
4353: } else {
1.192 raeburn 4354: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4355: &mt('Addition of users not permitted for specified default domain: [_1].',
4356: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4357: return 'untrusted';
1.185 raeburn 4358: }
4359: }
4360: }
1.57 raeburn 4361: } else {
4362: $domain = $defdom;
4363: }
1.1 raeburn 4364: my $desiredhost = $env{'form.lcserver'};
4365: if (lc($desiredhost) eq 'default') {
4366: $desiredhost = undef;
4367: } else {
1.57 raeburn 4368: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1 raeburn 4369: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 4370: $r->print('<p class="LC_error">'.&mt('Error').': '.
4371: &mt('Invalid home server specified').'</p>');
4372: return 'invalidhome';
1.1 raeburn 4373: }
4374: }
4375: # Determine authentication mechanism
4376: my $changeauth;
4377: if ($context eq 'domain') {
4378: $changeauth = $env{'form.changeauth'};
4379: }
4380: my $amode = '';
4381: my $genpwd = '';
1.200 raeburn 4382: my @genpwdfail;
1.1 raeburn 4383: if ($env{'form.login'} eq 'krb') {
4384: $amode='krb';
4385: $amode.=$env{'form.krbver'};
4386: $genpwd=$env{'form.krbarg'};
4387: } elsif ($env{'form.login'} eq 'int') {
4388: $amode='internal';
4389: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
4390: $genpwd=$env{'form.intarg'};
1.200 raeburn 4391: @genpwdfail =
1.202 raeburn 4392: &Apache::loncommon::check_passwd_rules($domain,$genpwd);
1.1 raeburn 4393: }
4394: } elsif ($env{'form.login'} eq 'loc') {
4395: $amode='localauth';
4396: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
4397: $genpwd=$env{'form.locarg'};
4398: }
1.194 raeburn 4399: } elsif ($env{'form.login'} eq 'lti') {
4400: $amode='lti';
1.1 raeburn 4401: }
4402: if ($amode =~ /^krb/) {
4403: if (! defined($genpwd) || $genpwd eq '') {
1.193 raeburn 4404: $r->print('<span class="Error">'.
1.1 raeburn 4405: &mt('Unable to enroll users').' '.
4406: &mt('No Kerberos domain was specified.').'</span></p>');
4407: $amode = ''; # This causes the loop below to be skipped
4408: }
4409: }
1.150 raeburn 4410: my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
1.1 raeburn 4411: if ($context eq 'domain') {
4412: if ($setting eq 'domain') {
4413: $defaultrole = $env{'form.defaultrole'};
4414: } elsif ($setting eq 'course') {
4415: $defaultrole = $env{'form.courserole'};
1.27 raeburn 4416: $defaultsec = $env{'form.sections'};
1.150 raeburn 4417: if ($showcredits) {
4418: $commoncredits = $env{'form.credits'};
4419: if ($crstype ne 'Community') {
4420: my %coursehash=&Apache::lonnet::coursedescription($cid);
4421: $defaultcredits = $coursehash{'internal.defaultcredits'};
4422: }
4423: }
1.149 raeburn 4424: }
1.13 raeburn 4425: } elsif ($context eq 'author') {
1.1 raeburn 4426: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 4427: } elsif ($context eq 'course') {
4428: $defaultrole = $env{'form.defaultrole'};
4429: $defaultsec = $env{'form.sections'};
1.150 raeburn 4430: if ($showcredits) {
4431: $commoncredits = $env{'form.credits'};
4432: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
4433: }
1.1 raeburn 4434: }
1.27 raeburn 4435: # Check to see if user information can be changed
4436: my @userinfo = ('firstname','middlename','lastname','generation',
4437: 'permanentemail','id');
4438: my %canmodify;
4439: if (&Apache::lonnet::allowed('mau',$domain)) {
1.84 raeburn 4440: push(@userinfo,'inststatus');
1.27 raeburn 4441: foreach my $field (@userinfo) {
4442: $canmodify{$field} = 1;
4443: }
4444: }
4445: my (%userlist,%modifiable_fields,@poss_roles);
4446: my $secidx = &Apache::loncoursedata::CL_SECTION();
1.102 raeburn 4447: my @courseroles = &roles_by_context('course',1,$crstype);
1.27 raeburn 4448: if (!&Apache::lonnet::allowed('mau',$domain)) {
4449: if ($context eq 'course' || $context eq 'author') {
1.101 raeburn 4450: @poss_roles = &curr_role_permissions($context,'','',$crstype);
1.27 raeburn 4451: my @statuses = ('active','future');
4452: my ($indexhash,$keylist) = &make_keylist_array();
4453: my %info;
4454: foreach my $role (@poss_roles) {
4455: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
4456: \@userinfo,[$role]);
4457: }
4458: if ($context eq 'course') {
4459: my ($cnum,$cdom) = &get_course_identity();
4460: my $roster = &Apache::loncoursedata::get_classlist();
1.66 raeburn 4461: if (ref($roster) eq 'HASH') {
4462: %userlist = %{$roster};
4463: }
1.27 raeburn 4464: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
4465: \@statuses,\@poss_roles);
4466: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4467: \%advrolehash,$permission);
4468: } elsif ($context eq 'author') {
4469: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
4470: \@statuses,\@poss_roles);
4471: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4472: \%cstr_roles,$permission);
4473: }
4474: }
1.1 raeburn 4475: }
1.193 raeburn 4476: if ($datatoken eq '') {
4477: $r->print('<p class="LC_error">'.&mt('Error').': '.
4478: &mt('Invalid datatoken').'</p>');
4479: return 'missingdata';
4480: }
1.1 raeburn 4481: if ( $domain eq &LONCAPA::clean_domain($domain)
4482: && ($amode ne '')) {
4483: #######################################
4484: ## Add/Modify Users ##
4485: #######################################
4486: if ($context eq 'course') {
4487: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 4488: } elsif ($context eq 'author') {
1.1 raeburn 4489: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
4490: } else {
4491: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
4492: }
1.87 bisitz 4493: $r->rflush;
4494:
1.1 raeburn 4495: my %counts = (
4496: user => 0,
4497: auth => 0,
4498: role => 0,
4499: );
4500: my $flushc=0;
4501: my %student=();
1.42 raeburn 4502: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 4503: my %userchg;
1.27 raeburn 4504: if ($context eq 'course' || $setting eq 'course') {
4505: if ($context eq 'course') {
4506: # Get information about course groups
4507: %curr_groups = &Apache::longroup::coursegroups();
4508: } elsif ($setting eq 'course') {
4509: if ($cid) {
4510: %curr_groups =
4511: &Apache::longroup::coursegroups($env{'form.dcdomain'},
4512: $env{'form.dccourse'});
4513: }
4514: }
4515: # determine section number
4516: if ($defaultsec =~ /,/) {
4517: push(@sections,split(/,/,$defaultsec));
4518: } else {
4519: push(@sections,$defaultsec);
4520: }
4521: # remove non alphanumeric values from section
4522: foreach my $item (@sections) {
4523: $item =~ s/\W//g;
4524: if ($item eq "none" || $item eq 'all') {
4525: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
4526: } elsif ($item ne '' && exists($curr_groups{$item})) {
4527: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
4528: } elsif ($item ne '') {
4529: push(@cleansec,$item);
4530: }
4531: }
4532: if ($defaultwarn) {
4533: $r->print($defaultwarn.'<br />');
4534: }
4535: if ($groupwarn) {
4536: $r->print($groupwarn.'<br />');
4537: }
1.1 raeburn 4538: }
1.124 raeburn 4539: my (%curr_rules,%got_rules,%alerts,%cancreate);
1.104 raeburn 4540: my %customroles = &my_custom_roles($crstype);
1.101 raeburn 4541: my @permitted_roles =
1.124 raeburn 4542: &roles_on_upload($context,$setting,$crstype,%customroles);
4543: my %longtypes = &Apache::lonlocal::texthash(
4544: official => 'Institutional',
4545: unofficial => 'Non-institutional',
4546: );
1.135 raeburn 4547: my $newuserdom = $env{'request.role.domain'};
4548: map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
1.1 raeburn 4549: # Get new users list
1.200 raeburn 4550: my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname,
4551: %showpasswdrules,$haspasswdmap);
1.171 raeburn 4552: my $counter = -1;
1.185 raeburn 4553: my (%willtrust,%trustchecked);
1.27 raeburn 4554: foreach my $line (@userdata) {
1.171 raeburn 4555: $counter ++;
1.42 raeburn 4556: my @secs;
1.27 raeburn 4557: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 4558: # Determine user name
1.128 raeburn 4559: $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 4560: unless (($entries{$fields{'username'}} eq '') ||
4561: (!defined($entries{$fields{'username'}}))) {
4562: my ($fname, $mname, $lname,$gen) = ('','','','');
4563: if (defined($fields{'names'})) {
4564: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
4565: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
4566: } else {
4567: if (defined($fields{'fname'})) {
4568: $fname=$entries{$fields{'fname'}};
4569: }
4570: if (defined($fields{'mname'})) {
4571: $mname=$entries{$fields{'mname'}};
4572: }
4573: if (defined($fields{'lname'})) {
4574: $lname=$entries{$fields{'lname'}};
4575: }
4576: if (defined($fields{'gen'})) {
4577: $gen=$entries{$fields{'gen'}};
4578: }
4579: }
1.128 raeburn 4580:
1.1 raeburn 4581: if ($entries{$fields{'username'}}
4582: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
1.128 raeburn 4583: my $nowhitespace;
4584: if ($entries{$fields{'username'}} =~ /\s/) {
4585: $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
4586: }
1.171 raeburn 4587: $disallow{$counter} =
1.157 bisitz 4588: &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 4589: '"<b>'.$entries{$fields{'username'}}.'</b>"',
4590: $fname,$mname,$lname,$gen).$nowhitespace;
1.27 raeburn 4591: next;
1.1 raeburn 4592: } else {
1.129 raeburn 4593: $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
1.71 droeschl 4594: if ($entries{$fields{'domain'}}
1.57 raeburn 4595: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
1.171 raeburn 4596: $disallow{$counter} =
1.157 bisitz 4597: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 4598: '"<b>'.$entries{$fields{'domain'}}.'</b>"',
4599: $fname,$mname,$lname,$gen);
4600: next;
1.185 raeburn 4601: } elsif ($entries{$fields{'domain'}} ne $domain) {
4602: my $possdom = $entries{$fields{'domain'}};
4603: if ($context eq 'course' || $setting eq 'course') {
4604: unless ($trustchecked{$possdom}) {
4605: $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
4606: $trustchecked{$possdom} = 1;
4607: }
4608: } elsif ($context eq 'author') {
4609: unless ($trustchecked{$possdom}) {
4610: $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
4611: }
4612: if ($willtrust{$possdom}) {
4613: $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
4614: }
4615: }
4616: unless ($willtrust{$possdom}) {
4617: $disallow{$counter} =
4618: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
4619: '"<b>'.$possdom.'</b>"',
4620: $fname,$mname,$lname,$gen);
4621: next;
4622: }
1.57 raeburn 4623: }
1.5 raeburn 4624: my $username = $entries{$fields{'username'}};
1.57 raeburn 4625: my $userdomain = $entries{$fields{'domain'}};
4626: if ($userdomain eq '') {
4627: $userdomain = $domain;
4628: }
1.27 raeburn 4629: if (defined($fields{'sec'})) {
4630: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 4631: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 4632: my $item = $entries{$fields{'sec'}};
4633: if ($item eq "none" || $item eq 'all') {
1.171 raeburn 4634: $disallow{$counter} =
4635: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
4636: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item);
1.27 raeburn 4637: next;
4638: } elsif (exists($curr_groups{$item})) {
1.171 raeburn 4639: $disallow{$counter} =
4640: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
4641: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.
4642: &mt('Section names and group names must be distinct.');
1.27 raeburn 4643: next;
4644: } else {
4645: push(@secs,$item);
4646: }
4647: }
4648: }
4649: if ($env{'request.course.sec'} ne '') {
4650: @secs = ($env{'request.course.sec'});
1.57 raeburn 4651: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
4652: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27 raeburn 4653: if ($currsec ne $env{'request.course.sec'}) {
1.171 raeburn 4654: $disallow{$counter} =
4655: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
4656: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]);
1.27 raeburn 4657: if ($currsec eq '') {
1.171 raeburn 4658: $disallow{$counter} .=
4659: &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
1.27 raeburn 4660:
4661: } else {
1.171 raeburn 4662: $disallow{$counter} .=
4663: &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
1.27 raeburn 4664: }
1.171 raeburn 4665: $disallow{$counter} .=
4666: '<br />'.
4667: &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',
4668: $secs[0]);
1.27 raeburn 4669: next;
1.1 raeburn 4670: }
4671: }
1.27 raeburn 4672: } elsif ($context eq 'course' || $setting eq 'course') {
4673: if (@secs == 0) {
4674: @secs = @cleansec;
1.1 raeburn 4675: }
4676: }
4677: # determine id number
4678: my $id='';
4679: if (defined($fields{'id'})) {
4680: if (defined($entries{$fields{'id'}})) {
4681: $id=$entries{$fields{'id'}};
4682: }
4683: $id=~tr/A-Z/a-z/;
4684: }
4685: # determine email address
4686: my $email='';
4687: if (defined($fields{'email'})) {
1.129 raeburn 4688: $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 4689: if (defined($entries{$fields{'email'}})) {
4690: $email=$entries{$fields{'email'}};
1.84 raeburn 4691: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
4692: }
4693: }
4694: # determine affiliation
4695: my $inststatus='';
4696: if (defined($fields{'inststatus'})) {
4697: if (defined($entries{$fields{'inststatus'}})) {
4698: $inststatus=$entries{$fields{'inststatus'}};
4699: }
1.1 raeburn 4700: }
4701: # determine user password
1.200 raeburn 4702: my $password;
4703: my $passwdfromfile;
1.1 raeburn 4704: if (defined($fields{'ipwd'})) {
4705: if ($entries{$fields{'ipwd'}}) {
4706: $password=$entries{$fields{'ipwd'}};
1.200 raeburn 4707: $passwdfromfile = 1;
4708: if ($env{'form.login'} eq 'int') {
4709: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
4710: if (($uhome eq 'no_host') || ($changeauth)) {
4711: my @brokepwdrules =
4712: &Apache::loncommon::check_passwd_rules($domain,$password);
4713: if (@brokepwdrules) {
4714: $disallow{$counter} = &mt('[_1]: Password included in file for this user did not meet requirements.',
4715: '<b>'.$username.'</b>');
4716: map { $showpasswdrules{$_} = 1; } @brokepwdrules;
4717: next;
4718: }
4719: }
4720: }
4721: }
4722: }
4723: unless ($passwdfromfile) {
4724: if ($env{'form.login'} eq 'int') {
4725: if (@genpwdfail) {
4726: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
4727: if (($uhome eq 'no_host') || ($changeauth)) {
4728: $disallow{$counter} = &mt('[_1]: No specific password in file for this user; default password did not meet requirements',
4729: '<b>'.$username.'</b>');
4730: unless ($haspasswdmap) {
4731: map { $showpasswdrules{$_} = 1; } @genpwdfail;
4732: $haspasswdmap = 1;
4733: }
4734: }
4735: next;
4736: }
1.1 raeburn 4737: }
1.200 raeburn 4738: $password = $genpwd;
1.1 raeburn 4739: }
4740: # determine user role
4741: my $role = '';
4742: if (defined($fields{'role'})) {
4743: if ($entries{$fields{'role'}}) {
1.42 raeburn 4744: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
4745: if ($entries{$fields{'role'}} ne '') {
4746: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
4747: $role = $entries{$fields{'role'}};
1.27 raeburn 4748: }
4749: }
4750: if ($role eq '') {
4751: my $rolestr = join(', ',@permitted_roles);
1.171 raeburn 4752: $disallow{$counter} =
4753: &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
4754: ,'<b>'.$entries{$fields{'username'}}.'</b>'
4755: ,$entries{$fields{'role'}})
4756: .'<br />'
4757: .&mt('Allowable role(s) is/are: [_1].',$rolestr);
1.1 raeburn 4758: next;
4759: }
4760: }
4761: }
4762: if ($role eq '') {
4763: $role = $defaultrole;
4764: }
4765: # Clean up whitespace
1.129 raeburn 4766: foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
1.1 raeburn 4767: $$_ =~ s/(\s+$|^\s+)//g;
4768: }
1.150 raeburn 4769: my $credits;
4770: if ($showcredits) {
4771: if (($role eq 'st') && ($crstype ne 'Community')) {
4772: $credits = $entries{$fields{'credits'}};
4773: if ($credits ne '') {
4774: $credits =~ s/[^\d\.]//g;
4775: }
4776: if ($credits eq '') {
4777: $credits = $commoncredits;
4778: }
4779: if ($credits eq $defaultcredits) {
4780: undef($credits);
4781: }
4782: }
4783: }
1.5 raeburn 4784: # check against rules
4785: my $checkid = 0;
4786: my $newuser = 0;
1.57 raeburn 4787: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5 raeburn 4788: if ($uhome eq 'no_host') {
1.135 raeburn 4789: if ($userdomain ne $newuserdom) {
4790: if ($context eq 'course') {
1.171 raeburn 4791: $disallow{$counter} =
4792: &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
4793: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 4794: } elsif ($context eq 'author') {
1.171 raeburn 4795: $disallow{$counter} =
4796: &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
4797: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 4798: } else {
1.171 raeburn 4799: $disallow{$counter} =
4800: &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
4801: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 4802: }
1.171 raeburn 4803: $disallow{$counter} .=
4804: &mt('The user does not already exist, and you may not create a new user in a different domain.');
1.124 raeburn 4805: next;
1.171 raeburn 4806: } else {
1.194 raeburn 4807: unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
1.171 raeburn 4808: $disallow{$counter} =
4809: &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
4810: '<b>'.$username.'</b>');
4811: next;
4812: }
1.124 raeburn 4813: }
1.5 raeburn 4814: $checkid = 1;
4815: $newuser = 1;
1.172 raeburn 4816: $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
1.13 raeburn 4817: } else {
1.27 raeburn 4818: if ($context eq 'course' || $context eq 'author') {
1.57 raeburn 4819: if ($userdomain eq $domain ) {
4820: if ($role eq '') {
4821: my @checkroles;
4822: foreach my $role (@poss_roles) {
4823: my $endkey;
4824: if ($role ne 'st') {
4825: $endkey = ':'.$role;
4826: }
4827: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
4828: if (!grep(/^\Q$role\E$/,@checkroles)) {
4829: push(@checkroles,$role);
4830: }
4831: }
1.27 raeburn 4832: }
1.57 raeburn 4833: if (@checkroles > 0) {
4834: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27 raeburn 4835: }
1.57 raeburn 4836: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
4837: %canmodify = %{$modifiable_fields{$role}};
1.27 raeburn 4838: }
4839: }
1.57 raeburn 4840: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84 raeburn 4841: for (my $i=0; $i<@newinfo; $i++) {
1.57 raeburn 4842: if (${$newinfo[$i]} ne '') {
4843: if (!$canmodify{$userinfo[$i]}) {
4844: ${$newinfo[$i]} = '';
4845: }
1.27 raeburn 4846: }
4847: }
4848: }
1.171 raeburn 4849: if ($id) {
4850: $existinguser{$userdomain}{$username} = $id;
4851: }
1.5 raeburn 4852: }
1.171 raeburn 4853: $userinfo{$counter} = {
4854: username => $username,
4855: domain => $userdomain,
4856: fname => $fname,
4857: mname => $mname,
4858: lname => $lname,
4859: gen => $gen,
4860: email => $email,
4861: id => $id,
4862: password => $password,
4863: inststatus => $inststatus,
4864: role => $role,
4865: sections => \@secs,
4866: credits => $credits,
4867: newuser => $newuser,
4868: checkid => $checkid,
4869: };
4870: }
4871: }
4872: } # end of foreach (@userdata)
4873: if ($counter > -1) {
4874: my $total = $counter + 1;
4875: my %checkids;
1.172 raeburn 4876: if ((keys(%existinguser)) || (keys(%checkuname))) {
4877: $r->print(&mt('Please be patient -- checking for institutional data ...'));
4878: $r->rflush();
4879: if (keys(%existinguser)) {
4880: foreach my $dom (keys(%existinguser)) {
4881: if (ref($existinguser{$dom}) eq 'HASH') {
4882: my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
4883: foreach my $username (keys(%{$existinguser{$dom}})) {
4884: if ($idhash{$username} ne $existinguser{$dom}{$username}) {
4885: $checkids{$username.':'.$dom} = {
4886: 'id' => $existinguser{$dom}{$username},
4887: };
4888: }
4889: }
4890: if (keys(%checkids)) {
4891: &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
4892: \%alerts,\%rulematch,
4893: \%inst_results,\%curr_rules,
4894: \%got_rules);
1.171 raeburn 4895: }
4896: }
4897: }
4898: }
1.172 raeburn 4899: if (keys(%checkuname)) {
4900: &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
4901: \%alerts,\%rulematch,\%inst_results,
4902: \%curr_rules,\%got_rules);
4903: }
4904: $r->print(' '.&mt('done').'<br /><br />');
4905: $r->rflush();
1.171 raeburn 4906: }
1.172 raeburn 4907: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
1.171 raeburn 4908: $r->print('<ul>');
4909: for (my $i=0; $i<=$counter; $i++) {
4910: if ($disallow{$i}) {
4911: $r->print('<li>'.$disallow{$i}.'</li>');
4912: } elsif (ref($userinfo{$i}) eq 'HASH') {
4913: my $password = $userinfo{$i}{'password'};
4914: my $newuser = $userinfo{$i}{'newuser'};
4915: my $checkid = $userinfo{$i}{'checkid'};
4916: my $id = $userinfo{$i}{'id'};
4917: my $role = $userinfo{$i}{'role'};
4918: my @secs;
4919: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
4920: @secs = @{$userinfo{$i}{'sections'}};
4921: }
4922: my $fname = $userinfo{$i}{'fname'};
4923: my $mname = $userinfo{$i}{'mname'};
4924: my $lname = $userinfo{$i}{'lname'};
4925: my $gen = $userinfo{$i}{'gen'};
4926: my $email = $userinfo{$i}{'email'};
4927: my $inststatus = $userinfo{$i}{'inststatus'};
4928: my $credits = $userinfo{$i}{'credits'};
4929: my $username = $userinfo{$i}{'username'};
4930: my $userdomain = $userinfo{$i}{'domain'};
4931: my $user = $username.':'.$userdomain;
4932: if ($newuser) {
4933: if (ref($alerts{'username'}) eq 'HASH') {
4934: if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
4935: if ($alerts{'username'}{$userdomain}{$username}) {
4936: $r->print('<li>'.
4937: &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
4938: &mt('Consequently, the user was not created.').'</li>');
4939: next;
4940: }
4941: }
4942: }
1.172 raeburn 4943: if (ref($inst_results{$user}) eq 'HASH') {
4944: if ($inst_results{$user}{'firstname'} ne '') {
4945: $fname = $inst_results{$user}{'firstname'};
4946: }
4947: if ($inst_results{$user}{'middlename'} ne '') {
4948: $mname = $inst_results{$user}{'middlename'};
4949: }
4950: if ($inst_results{$user}{'lasttname'} ne '') {
4951: $lname = $inst_results{$user}{'lastname'};
4952: }
4953: if ($inst_results{$user}{'permanentemail'} ne '') {
4954: $email = $inst_results{$user}{'permanentemail'};
4955: }
4956: if ($inst_results{$user}{'id'} ne '') {
4957: $id = $inst_results{$user}{'id'};
4958: $checkid = 0;
4959: }
4960: if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
4961: $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
4962: }
4963: }
4964: if (($checkid) && ($id ne '')) {
4965: if (ref($alerts{'id'}) eq 'HASH') {
4966: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
4967: if ($alerts{'id'}{$userdomain}{$username}) {
4968: $r->print('<li>'.
4969: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
4970: '<b>'.$username.'</b>').'<br />'.
4971: &mt('Consequently, the user was not created.').'</li>');
4972: next;
4973: }
4974: }
4975: }
4976: }
1.171 raeburn 4977: my $usertype = 'unofficial';
4978: if (ref($rulematch{$user}) eq 'HASH') {
4979: if ($rulematch{$user}{'username'}) {
4980: $usertype = 'official';
1.5 raeburn 4981: }
4982: }
1.171 raeburn 4983: unless ($cancreate{$usertype}) {
4984: my $showtype = $longtypes{$usertype};
4985: $r->print('<li>'.
4986: &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
4987: next;
4988: }
1.172 raeburn 4989: } elsif ($id ne '') {
1.171 raeburn 4990: if (exists($checkids{$user})) {
4991: $checkid = 1;
1.5 raeburn 4992: if (ref($alerts{'id'}) eq 'HASH') {
1.57 raeburn 4993: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
1.172 raeburn 4994: if ($alerts{'id'}{$userdomain}{$username}) {
1.171 raeburn 4995: $r->print('<li>'.
1.172 raeburn 4996: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
1.124 raeburn 4997: '<b>'.$username.'</b>').'<br />'.
1.172 raeburn 4998: &mt('Consequently, the ID was not changed.').'</li>');
4999: $id = '';
1.124 raeburn 5000: }
1.5 raeburn 5001: }
5002: }
5003: }
5004: }
1.171 raeburn 5005: my $multiple = 0;
5006: my ($userresult,$authresult,$roleresult,$idresult);
5007: my (%userres,%authres,%roleres,%idres);
5008: my $singlesec = '';
5009: if ($role eq 'st') {
5010: my $sec;
5011: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
1.42 raeburn 5012: if (@secs > 0) {
5013: $sec = $secs[0];
1.27 raeburn 5014: }
1.171 raeburn 5015: }
5016: &modifystudent($userdomain,$username,$cid,$sec,
5017: $desiredhost,$context);
5018: $roleresult =
5019: &Apache::lonnet::modifystudent
5020: ($userdomain,$username,$id,$amode,$password,
5021: $fname,$mname,$lname,$gen,$sec,$enddate,
5022: $startdate,$env{'form.forceid'},
5023: $desiredhost,$email,'manual','',$cid,
5024: '',$context,$inststatus,$credits);
5025: $userresult = $roleresult;
5026: } else {
5027: if ($role ne '') {
5028: if ($context eq 'course' || $setting eq 'course') {
5029: if ($customroles{$role}) {
5030: $role = 'cr_'.$env{'user.domain'}.'_'.
5031: $env{'user.name'}.'_'.$role;
5032: }
5033: if (($role ne 'cc') && ($role ne 'co')) {
5034: if (@secs > 1) {
5035: $multiple = 1;
5036: foreach my $sec (@secs) {
5037: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
5038: &modifyuserrole($context,$setting,
5039: $changeauth,$cid,$userdomain,$username,
5040: $id,$amode,$password,$fname,
5041: $mname,$lname,$gen,$sec,
5042: $env{'form.forceid'},$desiredhost,
5043: $email,$role,$enddate,
5044: $startdate,$checkid,$inststatus);
1.42 raeburn 5045: }
1.171 raeburn 5046: } elsif (@secs > 0) {
5047: $singlesec = $secs[0];
1.27 raeburn 5048: }
5049: }
5050: }
1.204 ! raeburn 5051: }
! 5052: if (!$multiple) {
! 5053: ($userresult,$authresult,$roleresult,$idresult) =
! 5054: &modifyuserrole($context,$setting,
! 5055: $changeauth,$cid,$userdomain,$username,
! 5056: $id,$amode,$password,$fname,
! 5057: $mname,$lname,$gen,$singlesec,
! 5058: $env{'form.forceid'},$desiredhost,
! 5059: $email,$role,$enddate,$startdate,
! 5060: $checkid,$inststatus);
1.27 raeburn 5061: }
1.171 raeburn 5062: }
5063: if ($multiple) {
5064: foreach my $sec (sort(keys(%userres))) {
5065: $flushc =
1.27 raeburn 5066: &user_change_result($r,$userres{$sec},$authres{$sec},
5067: $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57 raeburn 5068: $username,$userdomain,\%userchg);
1.27 raeburn 5069:
1.1 raeburn 5070: }
5071: } else {
1.171 raeburn 5072: $flushc =
5073: &user_change_result($r,$userresult,$authresult,
5074: $roleresult,$idresult,\%counts,$flushc,
5075: $username,$userdomain,\%userchg);
1.1 raeburn 5076: }
5077: }
1.172 raeburn 5078: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
1.171 raeburn 5079: } # end of loop
1.172 raeburn 5080: $r->print('</ul>');
1.171 raeburn 5081: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
5082: }
1.1 raeburn 5083: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 5084: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.29 raeburn 5085: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 5086: "</p>\n");
5087: if ($counts{'role'} > 0) {
5088: $r->print("<p>\n".
1.192 raeburn 5089: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
5090: &mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.').
5091: "</p>\n");
1.29 raeburn 5092: } else {
5093: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 5094: }
5095: if ($counts{'auth'} > 0) {
5096: $r->print("<p>\n".
5097: &mt('Authentication changed for [_1] existing users.',
5098: $counts{'auth'})."</p>\n");
5099: }
1.13 raeburn 5100: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.200 raeburn 5101: $r->print(&passwdrule_alerts($domain,\%showpasswdrules));
1.1 raeburn 5102: #####################################
1.29 raeburn 5103: # Display list of students to drop #
1.1 raeburn 5104: #####################################
5105: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 5106: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 5107: # Get current classlist
1.30 raeburn 5108: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5109: if (! defined($classlist)) {
1.192 raeburn 5110: $r->print('<p class="LC_info">'.
5111: &mt('There are no students with current/future access to the course.').
5112: '</p>'."\n");
1.66 raeburn 5113: } elsif (ref($classlist) eq 'HASH') {
1.1 raeburn 5114: # Remove the students we just added from the list of students.
1.30 raeburn 5115: foreach my $line (@userdata) {
5116: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5117: unless (($entries{$fields{'username'}} eq '') ||
5118: (!defined($entries{$fields{'username'}}))) {
5119: delete($classlist->{$entries{$fields{'username'}}.
5120: ':'.$domain});
5121: }
5122: }
5123: # Print out list of dropped students.
1.30 raeburn 5124: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 5125: }
5126: }
5127: } # end of unless
1.193 raeburn 5128: return 'ok';
1.1 raeburn 5129: }
5130:
1.13 raeburn 5131: sub print_namespacing_alerts {
5132: my ($domain,$alerts,$curr_rules) = @_;
5133: my $output;
5134: if (ref($alerts) eq 'HASH') {
5135: if (keys(%{$alerts}) > 0) {
5136: if (ref($alerts->{'username'}) eq 'HASH') {
5137: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
5138: my $count;
5139: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
5140: $count = keys(%{$alerts->{'username'}{$dom}});
5141: }
5142: my $domdesc = &Apache::lonnet::domain($domain,'description');
5143: if (ref($curr_rules->{$dom}) eq 'HASH') {
5144: $output .= &Apache::loncommon::instrule_disallow_msg(
5145: 'username',$domdesc,$count,'upload');
5146: }
5147: $output .= &Apache::loncommon::user_rule_formats($dom,
5148: $domdesc,$curr_rules->{$dom}{'username'},
5149: 'username');
5150: }
5151: }
5152: if (ref($alerts->{'id'}) eq 'HASH') {
5153: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
5154: my $count;
5155: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
5156: $count = keys(%{$alerts->{'id'}{$dom}});
5157: }
5158: my $domdesc = &Apache::lonnet::domain($domain,'description');
5159: if (ref($curr_rules->{$dom}) eq 'HASH') {
5160: $output .= &Apache::loncommon::instrule_disallow_msg(
5161: 'id',$domdesc,$count,'upload');
5162: }
5163: $output .= &Apache::loncommon::user_rule_formats($dom,
5164: $domdesc,$curr_rules->{$dom}{'id'},'id');
5165: }
5166: }
5167: }
5168: }
5169: }
5170:
1.200 raeburn 5171: sub passwdrule_alerts {
5172: my ($domain,$passwdrules) = @_;
5173: my $warning;
5174: if (ref($passwdrules) eq 'HASH') {
5175: my %showrules = %{$passwdrules};
5176: if (keys(%showrules)) {
5177: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
5178: $warning = '<b>'.&mt('Password requirement(s) unmet for one or more users:').'</b><ul>';
5179: if ($showrules{'min'}) {
5180: $warning .= '<li>'.&mt('minimum [quant,_1,character]',$passwdconf{'min'}).'</li>';
5181: }
5182: if ($showrules{'max'}) {
5183: $warning .= '<li>'.&mt('maximum [quant,_1,character]',$passwdconf{'max'}).'</li>';
5184: }
5185: if ($showrules{'uc'}) {
5186: $warning .= '<li>'.&mt('contain at least one upper case letter').'</li>';
5187: }
5188: if ($showrules{'lc'}) {
5189: $warning .= '<li>'.&mt('contain at least one lower case letter').'</li>';
5190: }
5191: if ($showrules{'num'}) {
5192: $warning .= '<li>'.&mt('contain at least one number').'</li>';
5193: }
5194: if ($showrules{'spec'}) {
5195: $warning .= '<li>'.&mt('contain at least one non-alphanumeric').'</li>';
5196: }
5197: $warning .= '</ul>';
5198: }
5199: }
5200: return $warning;
5201: }
5202:
1.1 raeburn 5203: sub user_change_result {
1.29 raeburn 5204: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57 raeburn 5205: $username,$userdomain,$userchg) = @_;
1.1 raeburn 5206: my $okresult = 0;
1.171 raeburn 5207: my @status;
1.1 raeburn 5208: if ($userresult ne 'ok') {
5209: if ($userresult =~ /^error:(.+)$/) {
5210: my $error = $1;
1.171 raeburn 5211: push(@status,
5212: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5213: }
5214: } else {
5215: $counts->{'user'} ++;
5216: $okresult = 1;
5217: }
5218: if ($authresult ne 'ok') {
5219: if ($authresult =~ /^error:(.+)$/) {
5220: my $error = $1;
1.171 raeburn 5221: push(@status,
5222: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5223: }
5224: } else {
5225: $counts->{'auth'} ++;
5226: $okresult = 1;
5227: }
5228: if ($roleresult ne 'ok') {
5229: if ($roleresult =~ /^error:(.+)$/) {
5230: my $error = $1;
1.171 raeburn 5231: push(@status,
5232: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5233: }
5234: } else {
5235: $counts->{'role'} ++;
5236: $okresult = 1;
5237: }
5238: if ($okresult) {
5239: $flushc++;
1.57 raeburn 5240: $userchg->{$username.':'.$userdomain}=1;
1.1 raeburn 5241: if ($flushc>15) {
5242: $r->rflush;
5243: $flushc=0;
5244: }
5245: }
1.29 raeburn 5246: if ($idresult) {
1.171 raeburn 5247: push(@status,$idresult);
5248: }
5249: if (@status) {
5250: $r->print('<li>'.join('<br />',@status).'</li>');
1.29 raeburn 5251: }
1.1 raeburn 5252: return $flushc;
5253: }
5254:
5255: # ========================================================= Menu Phase Two Drop
1.17 raeburn 5256: sub print_drop_menu {
1.101 raeburn 5257: my ($r,$context,$permission,$crstype) = @_;
5258: my $heading;
5259: if ($crstype eq 'Community') {
5260: $heading = &mt("Drop Members");
5261: } else {
5262: $heading = &mt("Drop Students");
5263: }
5264: $r->print('<h3>'.$heading.'</h3>'."\n".
1.153 bisitz 5265: '<form name="studentform" method="post" action="">'."\n");
1.30 raeburn 5266: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5267: if (! defined($classlist)) {
1.143 bisitz 5268: my $msg = '';
1.101 raeburn 5269: if ($crstype eq 'Community') {
1.143 bisitz 5270: $msg = &mt('There are no members currently enrolled.');
1.101 raeburn 5271: } else {
1.143 bisitz 5272: $msg = &mt('There are no students currently enrolled.');
1.101 raeburn 5273: }
1.143 bisitz 5274: $r->print('<p class="LC_info">'.$msg."</p>\n");
1.30 raeburn 5275: } else {
1.101 raeburn 5276: &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
1.1 raeburn 5277: }
1.162 bisitz 5278: $r->print('</form>');
1.1 raeburn 5279: return;
5280: }
5281:
5282: # ================================================================== Phase four
5283:
1.11 raeburn 5284: sub update_user_list {
1.118 raeburn 5285: my ($r,$context,$setting,$choice,$crstype) = @_;
1.11 raeburn 5286: my $now = time;
1.1 raeburn 5287: my $count=0;
1.101 raeburn 5288: if ($context eq 'course') {
5289: $crstype = &Apache::loncommon::course_type();
5290: }
1.11 raeburn 5291: my @changelist;
1.29 raeburn 5292: if ($choice eq 'drop') {
5293: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
5294: } else {
1.11 raeburn 5295: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
5296: }
5297: my %result_text = ( ok => { 'revoke' => 'Revoked',
5298: 'delete' => 'Deleted',
5299: 'reenable' => 'Re-enabled',
1.17 raeburn 5300: 'activate' => 'Activated',
5301: 'chgdates' => 'Changed Access Dates for',
1.118 raeburn 5302: 'chgsec' => 'Changed section(s) for',
1.17 raeburn 5303: 'drop' => 'Dropped',
1.11 raeburn 5304: },
5305: error => {'revoke' => 'revoking',
5306: 'delete' => 'deleting',
5307: 'reenable' => 're-enabling',
5308: 'activate' => 'activating',
1.17 raeburn 5309: 'chgdates' => 'changing access dates for',
5310: 'chgsec' => 'changing section for',
5311: 'drop' => 'dropping',
1.11 raeburn 5312: },
5313: );
5314: my ($startdate,$enddate);
5315: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
5316: ($startdate,$enddate) = &get_dates_from_form();
5317: }
5318: foreach my $item (@changelist) {
1.118 raeburn 5319: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
5320: @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
1.174 raeburn 5321: $nothingtodo,$keepnosection,$credits,$instsec);
1.17 raeburn 5322: if ($choice eq 'drop') {
5323: ($uname,$udom,$sec) = split(/:/,$item,-1);
5324: $role = 'st';
5325: $cid = $env{'request.course.id'};
5326: $scopestem = '/'.$cid;
5327: $scopestem =~s/\_/\//g;
5328: if ($sec eq '') {
5329: $scope = $scopestem;
5330: } else {
5331: $scope = $scopestem.'/'.$sec;
5332: }
5333: } elsif ($context eq 'course') {
1.174 raeburn 5334: ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
5335: split(/\:/,$item,8);
5336: $instsec = &unescape($instsec);
1.11 raeburn 5337: $cid = $env{'request.course.id'};
5338: $scopestem = '/'.$cid;
5339: $scopestem =~s/\_/\//g;
5340: if ($sec eq '') {
5341: $scope = $scopestem;
5342: } else {
5343: $scope = $scopestem.'/'.$sec;
5344: }
1.13 raeburn 5345: } elsif ($context eq 'author') {
1.11 raeburn 5346: ($uname,$udom,$role) = split(/\:/,$item,-1);
5347: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
5348: } elsif ($context eq 'domain') {
5349: if ($setting eq 'domain') {
5350: ($role,$uname,$udom) = split(/\:/,$item,-1);
5351: $scope = '/'.$env{'request.role.domain'}.'/';
1.13 raeburn 5352: } elsif ($setting eq 'author') {
1.11 raeburn 5353: ($uname,$udom,$role,$scope) = split(/\:/,$item);
5354: } elsif ($setting eq 'course') {
1.174 raeburn 5355: ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
5356: split(/\:/,$item,9);
5357: $instsec = &unescape($instsec);
1.11 raeburn 5358: $scope = '/'.$cid;
5359: $scope =~s/\_/\//g;
5360: if ($sec ne '') {
5361: $scope .= '/'.$sec;
5362: }
5363: }
5364: }
1.101 raeburn 5365: my $plrole = &Apache::lonnet::plaintext($role,$crstype);
1.11 raeburn 5366: my $start = $env{'form.'.$item.'_start'};
5367: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 5368: if ($choice eq 'drop') {
5369: # drop students
5370: $end = $now;
5371: $type = 'manual';
5372: $result =
1.52 raeburn 5373: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 5374: } elsif ($choice eq 'revoke') {
5375: # revoke or delete user role
1.11 raeburn 5376: $end = $now;
5377: if ($role eq 'st') {
5378: $result =
1.174 raeburn 5379: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5380: } else {
5381: $result =
1.52 raeburn 5382: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
5383: '','',$context);
1.11 raeburn 5384: }
5385: } elsif ($choice eq 'delete') {
5386: if ($role eq 'st') {
1.174 raeburn 5387: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.29 raeburn 5388: }
5389: $result =
5390: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 5391: $start,1,'',$context);
1.11 raeburn 5392: } else {
5393: #reenable, activate, change access dates or change section
5394: if ($choice ne 'chgsec') {
5395: $start = $startdate;
5396: $end = $enddate;
5397: }
5398: if ($choice eq 'reenable') {
5399: if ($role eq 'st') {
1.174 raeburn 5400: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5401: } else {
5402: $result =
5403: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5404: $now,'','',$context);
1.11 raeburn 5405: }
5406: } elsif ($choice eq 'activate') {
5407: if ($role eq 'st') {
1.174 raeburn 5408: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5409: } else {
5410: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5411: $now,'','',$context);
1.11 raeburn 5412: }
5413: } elsif ($choice eq 'chgdates') {
5414: if ($role eq 'st') {
1.174 raeburn 5415: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5416: } else {
5417: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5418: $start,'','',$context);
1.11 raeburn 5419: }
5420: } elsif ($choice eq 'chgsec') {
5421: my (@newsecs,$revresult,$nochg,@retained);
1.103 raeburn 5422: if (($role ne 'cc') && ($role ne 'co')) {
1.117 raeburn 5423: my @secs = sort(split(/,/,$env{'form.newsecs'}));
5424: if (@secs) {
5425: my %curr_groups = &Apache::longroup::coursegroups();
5426: foreach my $sec (@secs) {
5427: next if (($sec =~ /\W/) || ($sec eq 'none') ||
5428: (exists($curr_groups{$sec})));
5429: push(@newsecs,$sec);
5430: }
5431: }
1.11 raeburn 5432: }
5433: # remove existing section if not to be retained.
1.118 raeburn 5434: if (!$env{'form.retainsec'} || ($role eq 'st')) {
1.11 raeburn 5435: if ($sec eq '') {
5436: if (@newsecs == 0) {
1.118 raeburn 5437: $result = 'ok';
1.11 raeburn 5438: $nochg = 1;
1.118 raeburn 5439: $nothingtodo = 1;
1.40 raeburn 5440: } else {
5441: $revresult =
5442: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 5443: $scope,$role,
5444: '','',$context);
1.40 raeburn 5445: }
1.11 raeburn 5446: } else {
1.28 raeburn 5447: if (@newsecs > 0) {
5448: if (grep(/^\Q$sec\E$/,@newsecs)) {
5449: push(@retained,$sec);
5450: } else {
5451: $revresult =
5452: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 5453: $scope,$role,
5454: '','',$context);
1.28 raeburn 5455: }
5456: } else {
1.11 raeburn 5457: $revresult =
1.28 raeburn 5458: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 5459: $scope,$role,
5460: '','',$context);
1.11 raeburn 5461: }
5462: }
5463: } else {
1.28 raeburn 5464: if ($sec eq '') {
5465: $nochg = 1;
1.118 raeburn 5466: $keepnosection = 1;
5467: } else {
1.28 raeburn 5468: push(@retained,$sec);
5469: }
1.11 raeburn 5470: }
5471: # add new sections
1.118 raeburn 5472: my (@diffs,@shownew);
5473: if (@retained) {
5474: @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
5475: } else {
5476: @diffs = @newsecs;
5477: }
1.11 raeburn 5478: if (@newsecs == 0) {
1.118 raeburn 5479: if ($nochg) {
5480: $result = 'ok';
5481: $nothingtodo = 1;
5482: } else {
1.28 raeburn 5483: if ($role eq 'st') {
5484: $result =
1.174 raeburn 5485: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.28 raeburn 5486: } else {
5487: my $newscope = $scopestem;
1.52 raeburn 5488: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 5489: }
5490: }
1.118 raeburn 5491: $showsecs = &mt('No section');
5492: } elsif (@diffs == 0) {
5493: $result = 'ok';
5494: $nothingtodo = 1;
1.11 raeburn 5495: } else {
1.118 raeburn 5496: foreach my $newsec (@newsecs) {
1.11 raeburn 5497: if (!grep(/^\Q$newsec\E$/,@retained)) {
5498: if ($role eq 'st') {
1.174 raeburn 5499: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.118 raeburn 5500: if (@newsecs > 1) {
5501: my $showsingle;
5502: if ($newsec eq '') {
5503: $showsingle = &mt('No section');
5504: } else {
5505: $showsingle = $newsec;
5506: }
5507: if ($crstype eq 'Community') {
5508: $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each community member may only be in one section at a time.','<i>'.$showsingle.'</i>');
5509: } else {
5510: $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each student may only be in one section of a course at a time.','<i>'.$showsingle.'</i>');
5511: }
5512: $showsecs = $showsingle;
5513: last;
5514: } else {
5515: if ($newsec eq '') {
5516: $showsecs = &mt('No section');
5517: } else {
5518: $showsecs = $newsec;
5519: }
5520: }
1.11 raeburn 5521: } else {
5522: my $newscope = $scopestem;
5523: if ($newsec ne '') {
5524: $newscope .= '/'.$newsec;
1.118 raeburn 5525: push(@shownew,$newsec);
1.11 raeburn 5526: }
5527: $result = &Apache::lonnet::assignrole($udom,$uname,
5528: $newscope,$role,$end,$start);
1.118 raeburn 5529:
1.11 raeburn 5530: }
5531: }
5532: }
5533: }
1.118 raeburn 5534: unless ($role eq 'st') {
5535: unless ($showsecs) {
5536: my @tolist = sort(@shownew,@retained);
5537: if ($keepnosection) {
5538: push(@tolist,&mt('No section'));
5539: }
5540: $showsecs = join(', ',@tolist);
5541: }
5542: }
1.11 raeburn 5543: }
5544: }
1.17 raeburn 5545: my $extent = $scope;
5546: if ($choice eq 'drop' || $context eq 'course') {
5547: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
5548: if ($cdesc) {
5549: $extent = $cdesc;
5550: }
5551: }
1.1 raeburn 5552: if ($result eq 'ok' || $result eq 'ok:') {
1.118 raeburn 5553: my $dates;
5554: if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
5555: $dates = &dates_feedback($start,$end,$now);
5556: }
5557: if ($choice eq 'chgsec') {
5558: if ($nothingtodo) {
5559: $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
5560: &Apache::loncommon::plainname($uname,$udom).
5561: '</i>').' ');
5562: if ($sec eq '') {
5563: $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
5564: } else {
5565: $r->print(&mt('Section(s): [_1] - [_2]',
5566: '<b>'.$showsecs.'</b>',$dates));
5567: }
5568: $r->print('<br />');
5569: } else {
5570: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
5571: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
5572: '<b>'.$showsecs.'</b>',$dates).'<br />');
5573: $count ++;
5574: }
5575: if ($warn_singlesec) {
5576: $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
5577: }
5578: } elsif ($choice eq 'chgdates') {
5579: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
1.121 raeburn 5580: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 5581: $dates).'<br />');
5582: $count ++;
5583: } else {
5584: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
1.121 raeburn 5585: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
1.118 raeburn 5586: '<br />');
5587: $count ++;
5588: }
1.1 raeburn 5589: } else {
5590: $r->print(
1.118 raeburn 5591: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
5592: $plrole,$extent,
1.121 raeburn 5593: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 5594: $result).'<br />');
1.11 raeburn 5595: }
5596: }
1.32 raeburn 5597: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 5598: if ($choice eq 'drop') {
5599: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
5600: '<input type="hidden" name="Status" value="Active" />'."\n".
5601: '<input type="hidden" name="showrole" value="st" />'."\n");
5602: } else {
5603: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
5604: if ($env{'form.'.$item} ne '') {
5605: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
5606: '" />'."\n");
5607: }
1.32 raeburn 5608: }
5609: }
1.144 bisitz 5610: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
1.11 raeburn 5611: if ($count > 0) {
1.17 raeburn 5612: if ($choice eq 'revoke' || $choice eq 'drop') {
1.74 bisitz 5613: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11 raeburn 5614: }
5615: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 5616: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.11 raeburn 5617: }
5618: if ($env{'form.makedatesdefault'}) {
5619: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.101 raeburn 5620: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 5621: }
5622: }
1.33 raeburn 5623: my $linktext = &mt('Display User Lists');
5624: if ($choice eq 'drop') {
5625: $linktext = &mt('Display current class roster');
5626: }
1.144 bisitz 5627: $r->print(
5628: &Apache::lonhtmlcommon::actionbox(
5629: ['<a href="javascript:document.studentform.submit()">'.$linktext.'</a>'])
5630: .'</form>'."\n");
1.1 raeburn 5631: }
5632:
1.118 raeburn 5633: sub dates_feedback {
5634: my ($start,$end,$now) = @_;
5635: my $dates;
5636: if ($start < $now) {
5637: if ($end == 0) {
1.147 bisitz 5638: $dates = &mt('role(s) active now; no end date');
1.118 raeburn 5639: } elsif ($end > $now) {
5640: $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
5641: } else {
5642: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
5643: }
5644: } else {
5645: if ($end == 0 || $end > $now) {
5646: $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
5647: } else {
5648: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
5649: }
5650: }
5651: return $dates;
5652: }
5653:
1.8 raeburn 5654: sub classlist_drop {
1.29 raeburn 5655: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 5656: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 5657: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8 raeburn 5658: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63 raeburn 5659: my %user;
5660: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8 raeburn 5661: return &mt('Drop from classlist: [_1]',
5662: '<b>'.$result.'</b>').'<br />';
5663: }
5664: }
5665: }
5666:
5667: sub active_student_roles {
5668: my ($cnum,$cdom,$uname,$udom) = @_;
5669: my %roles =
5670: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
5671: ['future','active'],['st']);
5672: return exists($roles{"$cnum:$cdom:st"});
5673: }
5674:
1.1 raeburn 5675: sub section_check_js {
1.8 raeburn 5676: my $groupslist= &get_groupslist();
1.170 damieng 5677: my %js_lt = &Apache::lonlocal::texthash(
5678: mayn => 'may not be used as the name for a section, as it is a reserved word.',
5679: plch => 'Please choose a different section name.',
5680: mnot => 'may not be used as a section name, as it is the name of a course group.',
5681: secn => 'Section names and group names must be distinct. Please choose a different section name.',
5682: );
5683: &js_escape(\%js_lt);
1.1 raeburn 5684: return <<"END";
5685: function validate(caller) {
1.9 raeburn 5686: var groups = new Array($groupslist);
1.1 raeburn 5687: var secname = caller.value;
5688: if ((secname == 'all') || (secname == 'none')) {
1.170 damieng 5689: alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
1.1 raeburn 5690: return 'error';
5691: }
5692: if (secname != '') {
5693: for (var k=0; k<groups.length; k++) {
5694: if (secname == groups[k]) {
1.170 damieng 5695: alert("'"+secname+"' $js_lt{'mnot'}\\n$js_lt{'secn'}");
1.1 raeburn 5696: return 'error';
5697: }
5698: }
5699: }
5700: return 'ok';
5701: }
5702: END
5703: }
5704:
5705: sub set_login {
1.194 raeburn 5706: my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
1.1 raeburn 5707: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5708: my $response;
5709: my ($authnum,%can_assign) =
5710: &Apache::loncommon::get_assignable_auth($dom);
5711: if ($authnum) {
5712: $response = &Apache::loncommon::start_data_table();
5713: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
5714: $response .= &Apache::loncommon::start_data_table_row().
5715: '<td>'.$authformkrb.'</td>'.
5716: &Apache::loncommon::end_data_table_row()."\n";
5717: }
5718: if ($can_assign{'int'}) {
5719: $response .= &Apache::loncommon::start_data_table_row().
5720: '<td>'.$authformint.'</td>'.
5721: &Apache::loncommon::end_data_table_row()."\n"
5722: }
5723: if ($can_assign{'loc'}) {
5724: $response .= &Apache::loncommon::start_data_table_row().
5725: '<td>'.$authformloc.'</td>'.
5726: &Apache::loncommon::end_data_table_row()."\n";
5727: }
1.194 raeburn 5728: if ($can_assign{'lti'}) {
5729: $response .= &Apache::loncommon::start_data_table_row().
5730: '<td>'.$authformlti.'</td>'.
5731: &Apache::loncommon::end_data_table_row()."\n";
5732: }
1.1 raeburn 5733: $response .= &Apache::loncommon::end_data_table();
5734: }
5735: return $response;
5736: }
5737:
1.8 raeburn 5738: sub course_sections {
1.178 raeburn 5739: my ($sections_count,$role,$current_sec,$disabled) = @_;
1.8 raeburn 5740: my $output = '';
1.169 raeburn 5741: my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
1.29 raeburn 5742: my $numsec = scalar(@sections);
1.92 bisitz 5743: my $is_selected = ' selected="selected"';
1.29 raeburn 5744: if ($numsec <= 1) {
1.178 raeburn 5745: $output = '<select name="currsec_'.$role.'"'.$disabled.'>'."\n".
1.51 raeburn 5746: ' <option value="">'.&mt('Select').'</option>'."\n";
5747: if ($current_sec eq 'none') {
5748: $output .=
5749: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
5750: } else {
5751: $output .=
1.29 raeburn 5752: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 5753: }
1.29 raeburn 5754: if ($numsec == 1) {
1.51 raeburn 5755: if ($current_sec eq $sections[0]) {
5756: $output .=
5757: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
5758: } else {
5759: $output .=
1.8 raeburn 5760: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 5761: }
1.29 raeburn 5762: }
1.8 raeburn 5763: } else {
5764: $output = '<select name="currsec_'.$role.'" ';
5765: my $multiple = 4;
5766: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 5767: if ($role eq 'st') {
1.178 raeburn 5768: $output .= $disabled.'>'."\n".
1.51 raeburn 5769: ' <option value="">'.&mt('Select').'</option>'."\n";
5770: if ($current_sec eq 'none') {
5771: $output .=
5772: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
5773: } else {
5774: $output .=
1.29 raeburn 5775: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 5776: }
1.29 raeburn 5777: } else {
1.178 raeburn 5778: $output .= 'multiple="multiple" size="'.$multiple.'"'.$disabled.'>'."\n";
1.29 raeburn 5779: }
1.8 raeburn 5780: foreach my $sec (@sections) {
1.51 raeburn 5781: if ($current_sec eq $sec) {
5782: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
5783: } else {
5784: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
5785: }
1.8 raeburn 5786: }
5787: }
5788: $output .= '</select>';
5789: return $output;
5790: }
5791:
5792: sub get_groupslist {
5793: my $groupslist;
5794: my %curr_groups = &Apache::longroup::coursegroups();
5795: if (%curr_groups) {
5796: $groupslist = join('","',sort(keys(%curr_groups)));
5797: $groupslist = '"'.$groupslist.'"';
5798: }
1.11 raeburn 5799: return $groupslist;
1.8 raeburn 5800: }
5801:
5802: sub setsections_javascript {
1.150 raeburn 5803: my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
1.28 raeburn 5804: my ($checkincluded,$finish,$rolecode,$setsection_js);
5805: if ($mode eq 'upload') {
5806: $checkincluded = 'formname.name == "'.$formname.'"';
5807: $finish = "return 'ok';";
5808: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
5809: } elsif ($formname eq 'cu') {
1.150 raeburn 5810: if (($crstype eq 'Course') && ($showcredits)) {
5811: $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
5812: } else {
5813: $checkincluded = 'formname.elements[i-1].checked == true';
5814: }
1.37 raeburn 5815: if ($checkauth) {
5816: $finish = "var authcheck = auth_check();\n".
5817: " if (authcheck == 'ok') {\n".
5818: " formname.submit();\n".
5819: " }\n";
5820: } else {
5821: $finish = 'formname.submit()';
5822: }
1.28 raeburn 5823: $rolecode = "var match = str.split('_');
5824: var role = match[3];\n";
1.165 raeburn 5825: } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
1.28 raeburn 5826: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 5827: if ($checkauth) {
5828: $finish = "var authcheck = auth_check();\n".
5829: " if (authcheck == 'ok') {\n".
5830: " formname.submit();\n".
5831: " }\n";
5832: } else {
5833: $finish = 'formname.submit()';
5834: }
1.28 raeburn 5835: $rolecode = "var match = str.split('_');
5836: var role = match[1];\n";
1.8 raeburn 5837: } else {
1.28 raeburn 5838: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 5839: $finish = "seccheck = 'ok';";
1.28 raeburn 5840: $rolecode = "var match = str.split('_');
5841: var role = match[1];\n";
1.11 raeburn 5842: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 5843: }
5844: my %alerts = &Apache::lonlocal::texthash(
5845: secd => 'Section designations do not apply to Course Coordinator roles.',
1.103 raeburn 5846: sedn => 'Section designations do not apply to Coordinator roles.',
1.8 raeburn 5847: accr => 'A course coordinator role will be added with access to all sections.',
1.103 raeburn 5848: acor => 'A coordinator role will be added with access to all sections',
1.8 raeburn 5849: inea => 'In each course, each user may only have one student role at a time.',
1.125 raeburn 5850: inco => 'In each community, each user may only have one member role at a time.',
1.145 raeburn 5851: youh => 'You had selected',
1.8 raeburn 5852: secs => 'sections.',
5853: plmo => 'Please modify your selections so they include no more than one section.',
5854: mayn => 'may not be used as the name for a section, as it is a reserved word.',
5855: plch => 'Please choose a different section name.',
5856: mnot => 'may not be used as a section name, as it is the name of a course group.',
5857: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.113 raeburn 5858: nonw => 'Section names may only contain letters or numbers.',
1.170 damieng 5859: );
5860: &js_escape(\%alerts);
1.8 raeburn 5861: $setsection_js .= <<"ENDSECCODE";
5862:
1.103 raeburn 5863: function setSections(formname,crstype) {
1.8 raeburn 5864: var re1 = /^currsec_/;
1.113 raeburn 5865: var re2 =/\\W/;
1.115 raeburn 5866: var trimleading = /^\\s+/;
5867: var trimtrailing = /\\s+\$/;
1.8 raeburn 5868: var groups = new Array($groupslist);
5869: for (var i=0;i<formname.elements.length;i++) {
5870: var str = formname.elements[i].name;
1.168 raeburn 5871: if (typeof(str) === "undefined") {
5872: continue;
5873: }
1.8 raeburn 5874: var checkcurr = str.match(re1);
5875: if (checkcurr != null) {
1.115 raeburn 5876: var num = i;
1.150 raeburn 5877: $rolecode
1.8 raeburn 5878: if ($checkincluded) {
1.103 raeburn 5879: if (role == 'cc' || role == 'co') {
5880: if (role == 'cc') {
5881: alert("$alerts{'secd'}\\n$alerts{'accr'}");
5882: } else {
5883: alert("$alerts{'sedn'}\\n$alerts{'acor'}");
5884: }
5885: } else {
1.8 raeburn 5886: var sections = '';
5887: var numsec = 0;
1.115 raeburn 5888: var fromexisting = new Array();
5889: for (var j=0; j<formname.elements[num].length; j++) {
5890: if (formname.elements[num].options[j].selected == true ) {
5891: var addsec = formname.elements[num].options[j].value;
1.119 raeburn 5892: if ((addsec != "") && (addsec != null)) {
1.115 raeburn 5893: fromexisting.push(addsec);
1.8 raeburn 5894: if (numsec == 0) {
1.115 raeburn 5895: sections = addsec;
5896: } else {
5897: sections = sections + "," + addsec;
1.8 raeburn 5898: }
1.115 raeburn 5899: numsec ++;
1.8 raeburn 5900: }
5901: }
5902: }
1.115 raeburn 5903: var newsecs = formname.elements[num+1].value;
1.113 raeburn 5904: var validsecs = new Array();
1.115 raeburn 5905: var validsecstr = '';
1.113 raeburn 5906: var badsecs = new Array();
1.8 raeburn 5907: if (newsecs != null && newsecs != "") {
1.115 raeburn 5908: var numsplit;
5909: if (newsecs.indexOf(',') == -1) {
5910: numsplit = new Array(newsecs);
5911: } else {
5912: numsplit = newsecs.split(/,/g);
5913: }
1.117 raeburn 5914: for (var m=0; m<numsplit.length; m++) {
5915: var newsec = numsplit[m];
1.115 raeburn 5916: newsec = newsec.replace(trimleading,'');
5917: newsec = newsec.replace(trimtrailing,'');
5918: if (re2.test(newsec) == true) {
5919: badsecs.push(newsec);
1.113 raeburn 5920: } else {
1.115 raeburn 5921: if (newsec != '') {
5922: var isnew = 1;
5923: if (fromexisting != null) {
1.117 raeburn 5924: for (var n=0; n<fromexisting.length; n++) {
5925: if (newsec == fromexisting[n]) {
1.115 raeburn 5926: isnew = 0;
5927: }
5928: }
5929: }
5930: if (isnew == 1) {
5931: validsecs.push(newsec);
5932: }
5933: }
1.113 raeburn 5934: }
5935: }
5936: if (badsecs.length > 0) {
5937: alert("$alerts{'nonw'}\\n$alerts{'plch'}");
5938: return;
5939: }
5940: numsec = numsec + validsecs.length;
1.8 raeburn 5941: }
5942: if ((role == 'st') && (numsec > 1)) {
1.103 raeburn 5943: if (crstype == 'Community') {
5944: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
5945: } else {
5946: alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
5947: }
1.8 raeburn 5948: return;
1.115 raeburn 5949: } else {
5950: if (validsecs != null) {
5951: for (var j=0; j<validsecs.length; j++) {
5952: if (validsecstr == '' || validsecstr == null) {
5953: validsecstr = validsecs[j];
5954: } else {
5955: validsecstr += ','+validsecs[j];
5956: }
5957: if ((validsecs[j] == 'all') ||
5958: (validsecs[j] == 'none')) {
5959: alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
1.8 raeburn 5960: return;
5961: }
5962: for (var k=0; k<groups.length; k++) {
1.115 raeburn 5963: if (validsecs[j] == groups[k]) {
5964: alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
1.8 raeburn 5965: return;
5966: }
5967: }
5968: }
5969: }
5970: }
1.115 raeburn 5971: if ((validsecstr != '') && (validsecstr != null)) {
1.117 raeburn 5972: if ((sections == '') || (sections == null)) {
5973: sections = validsecstr;
5974: } else {
1.115 raeburn 5975: sections = sections + "," + validsecstr;
5976: }
5977: }
5978: formname.elements[num+2].value = sections;
1.8 raeburn 5979: }
5980: }
5981: }
5982: }
5983: $finish
5984: }
5985: ENDSECCODE
1.11 raeburn 5986: return $setsection_js;
1.8 raeburn 5987: }
5988:
1.15 raeburn 5989: sub can_create_user {
5990: my ($dom,$context,$usertype) = @_;
5991: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5992: my $cancreate = 1;
1.28 raeburn 5993: if (&Apache::lonnet::allowed('mau',$dom)) {
5994: return $cancreate;
1.178 raeburn 5995: } elsif ($context eq 'domain') {
5996: $cancreate = 0;
5997: return $cancreate;
1.28 raeburn 5998: }
1.15 raeburn 5999: if (ref($domconf{'usercreation'}) eq 'HASH') {
6000: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
1.100 raeburn 6001: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
1.15 raeburn 6002: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
6003: if ($creation eq 'none') {
6004: $cancreate = 0;
6005: } elsif ($creation ne 'any') {
6006: if (defined($usertype)) {
6007: if ($creation ne $usertype) {
6008: $cancreate = 0;
6009: }
6010: }
6011: }
6012: }
6013: }
6014: }
6015: return $cancreate;
6016: }
6017:
1.20 raeburn 6018: sub can_modify_userinfo {
6019: my ($context,$dom,$fields,$userroles) = @_;
6020: my %domconfig =
6021: &Apache::lonnet::get_dom('configuration',['usermodification'],
6022: $dom);
6023: my %canmodify;
6024: if (ref($fields) eq 'ARRAY') {
6025: foreach my $field (@{$fields}) {
6026: $canmodify{$field} = 0;
6027: if (&Apache::lonnet::allowed('mau',$dom)) {
6028: $canmodify{$field} = 1;
6029: } else {
6030: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6031: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
6032: if (ref($userroles) eq 'ARRAY') {
6033: foreach my $role (@{$userroles}) {
6034: my $testrole;
1.60 raeburn 6035: if ($context eq 'selfcreate') {
6036: $testrole = $role;
1.20 raeburn 6037: } else {
1.60 raeburn 6038: if ($role =~ /^cr\//) {
6039: $testrole = 'cr';
6040: } else {
6041: $testrole = $role;
6042: }
1.20 raeburn 6043: }
6044: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
6045: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
6046: $canmodify{$field} = 1;
6047: last;
6048: }
6049: }
6050: }
6051: } else {
6052: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
6053: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
6054: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
6055: $canmodify{$field} = 1;
6056: last;
6057: }
6058: }
6059: }
6060: }
6061: }
6062: } elsif ($context eq 'course') {
6063: if (ref($userroles) eq 'ARRAY') {
6064: if (grep(/^st$/,@{$userroles})) {
6065: $canmodify{$field} = 1;
6066: }
6067: } else {
6068: $canmodify{$field} = 1;
6069: }
6070: }
6071: }
6072: }
6073: }
6074: return %canmodify;
6075: }
6076:
1.195 raeburn 6077: sub can_change_internalpass {
6078: my ($uname,$udom,$crstype,$permission) = @_;
6079: my $canchange;
6080: if (&Apache::lonnet::allowed('mau',$udom)) {
6081: $canchange = 1;
6082: } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
6083: ($udom eq $env{'request.role.domain'})) {
6084: unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
6085: my ($cnum,$cdom) = &get_course_identity();
6086: if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
1.199 raeburn 6087: my @userstatuses = ('default');
6088: my %userenv = &Apache::lonnet::userenvironment($udom,$uname,'inststatus');
6089: if ($userenv{'inststatus'} ne '') {
6090: @userstatuses = split(/:/,$userenv{'inststatus'});
6091: }
6092: my $noupdate = 1;
6093: my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
6094: if (ref($passwdconf{'crsownerchg'}) eq 'HASH') {
6095: if (ref($passwdconf{'crsownerchg'}{'for'}) eq 'ARRAY') {
6096: foreach my $status (@userstatuses) {
6097: if (grep(/^\Q$status\E$/,@{$passwdconf{'crsownerchg'}{'for'}})) {
6098: undef($noupdate);
6099: last;
6100: }
6101: }
6102: }
6103: }
6104: if ($noupdate) {
6105: return;
6106: }
1.195 raeburn 6107: my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
6108: $env{'user.name'}.':'.$env{'user.domain'},
6109: undef,undef,undef,'.');
6110: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6111: ['active','future']);
6112: foreach my $key (keys(%roleshash)) {
6113: my ($name,$domain,$role) = split(/:/,$key);
6114: if ($role eq 'st') {
6115: next if (($name eq $cnum) && ($domain eq $cdom));
6116: if ($owned{$domain.'_'.$name}) {
6117: if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
6118: if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
6119: $noupdate = 1;
6120: last;
6121: }
6122: }
6123: } else {
6124: $noupdate = 1;
6125: last;
6126: }
6127: } else {
6128: $noupdate = 1;
6129: last;
6130: }
6131: }
6132: unless ($noupdate) {
6133: $canchange = 1;
6134: }
6135: }
6136: }
6137: }
6138: return $canchange;
6139: }
6140:
1.18 raeburn 6141: sub check_usertype {
1.134 raeburn 6142: my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
1.18 raeburn 6143: my $usertype;
1.134 raeburn 6144: if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
6145: if (!$got_rules->{$dom}) {
6146: my %domconfig = &Apache::lonnet::get_dom('configuration',
6147: ['usercreation'],$dom);
6148: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6149: foreach my $item ('username','id') {
6150: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6151: $curr_rules->{$dom}{$item} =
6152: $domconfig{'usercreation'}{$item.'_rule'};
6153: }
6154: }
6155: }
6156: $got_rules->{$dom} = 1;
6157: }
6158: if (ref($rules) eq 'HASH') {
6159: my @user_rules;
6160: if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
6161: foreach my $rule (keys(%{$rules})) {
6162: if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
6163: push(@user_rules,$rule);
6164: }
6165: }
6166: }
6167: if (@user_rules > 0) {
6168: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
6169: if (keys(%rule_check) > 0) {
6170: $usertype = 'unofficial';
6171: foreach my $item (keys(%rule_check)) {
6172: if ($rule_check{$item}) {
6173: $usertype = 'official';
6174: last;
6175: }
1.18 raeburn 6176: }
6177: }
6178: }
6179: }
6180: }
6181: return $usertype;
6182: }
6183:
1.17 raeburn 6184: sub roles_by_context {
1.101 raeburn 6185: my ($context,$custom,$crstype) = @_;
1.17 raeburn 6186: my @allroles;
6187: if ($context eq 'course') {
1.99 raeburn 6188: @allroles = ('st');
6189: if ($env{'request.role'} =~ m{^dc\./}) {
6190: push(@allroles,'ad');
6191: }
1.101 raeburn 6192: push(@allroles,('ta','ep','in'));
6193: if ($crstype eq 'Community') {
6194: push(@allroles,'co');
6195: } else {
6196: push(@allroles,'cc');
6197: }
1.17 raeburn 6198: if ($custom) {
6199: push(@allroles,'cr');
6200: }
6201: } elsif ($context eq 'author') {
6202: @allroles = ('ca','aa');
6203: } elsif ($context eq 'domain') {
1.182 raeburn 6204: @allroles = ('li','ad','dg','dh','da','sc','au','dc');
1.17 raeburn 6205: }
6206: return @allroles;
6207: }
6208:
1.16 raeburn 6209: sub get_permission {
1.101 raeburn 6210: my ($context,$crstype) = @_;
1.16 raeburn 6211: my %permission;
6212: if ($context eq 'course') {
1.17 raeburn 6213: my $custom = 1;
1.101 raeburn 6214: my @allroles = &roles_by_context($context,$custom,$crstype);
1.17 raeburn 6215: foreach my $role (@allroles) {
6216: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
6217: $permission{'cusr'} = 1;
6218: last;
6219: }
1.16 raeburn 6220: }
6221: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
6222: $permission{'custom'} = 1;
6223: }
6224: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
6225: $permission{'view'} = 1;
6226: }
6227: if (!$permission{'view'}) {
6228: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6229: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
6230: if ($permission{'view'}) {
6231: $permission{'view_section'} = $env{'request.course.sec'};
6232: }
6233: }
1.17 raeburn 6234: if (!$permission{'cusr'}) {
6235: if ($env{'request.course.sec'} ne '') {
6236: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6237: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
6238: if ($permission{'cusr'}) {
6239: $permission{'cusr_section'} = $env{'request.course.sec'};
6240: }
6241: }
6242: }
1.16 raeburn 6243: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
6244: $permission{'grp_manage'} = 1;
6245: }
1.165 raeburn 6246: if ($permission{'cusr'}) {
6247: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6248: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6249: my %coursehash = (
6250: 'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
6251: 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
6252: 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
6253: 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
6254: );
6255: my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
6256: if (ref($managed_by_cc) eq 'ARRAY') {
6257: if (@{$managed_by_cc}) {
6258: $permission{'selfenrolladmin'} = 1;
6259: }
6260: }
6261: }
1.180 raeburn 6262: if ($env{'request.course.id'}) {
1.195 raeburn 6263: my $user;
6264: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
6265: $user = $env{'user.name'}.':'.$env{'user.domain'};
6266: }
1.180 raeburn 6267: if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
6268: $user)) {
6269: $permission{'owner'} = 1;
1.195 raeburn 6270: if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
6271: $permission{'mip'} = 1;
6272: }
1.180 raeburn 6273: } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
6274: if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
6275: $permission{'co-owner'} = 1;
6276: }
6277: }
6278: }
1.16 raeburn 6279: } elsif ($context eq 'author') {
6280: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
6281: $permission{'view'} = $permission{'cusr'};
6282: } else {
1.17 raeburn 6283: my @allroles = &roles_by_context($context);
6284: foreach my $role (@allroles) {
1.28 raeburn 6285: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
6286: $permission{'cusr'} = 1;
1.17 raeburn 6287: last;
6288: }
6289: }
6290: if (!$permission{'cusr'}) {
6291: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
6292: $permission{'cusr'} = 1;
6293: }
1.16 raeburn 6294: }
6295: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
6296: $permission{'custom'} = 1;
6297: }
1.176 raeburn 6298: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
6299: $permission{'activity'} = 1;
6300: }
1.178 raeburn 6301: if (&Apache::lonnet::allowed('vur',$env{'request.role.domain'})) {
6302: $permission{'view'} = 1;
6303: }
1.180 raeburn 6304: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
6305: $permission{'owner'} = 1;
6306: }
1.16 raeburn 6307: }
6308: my $allowed = 0;
6309: foreach my $perm (values(%permission)) {
6310: if ($perm) { $allowed=1; last; }
6311: }
6312: return (\%permission,$allowed);
6313: }
6314:
6315: # ==================================================== Figure out author access
6316:
6317: sub authorpriv {
6318: my ($auname,$audom)=@_;
6319: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
6320: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
6321: }
6322:
1.27 raeburn 6323: sub roles_on_upload {
1.101 raeburn 6324: my ($context,$setting,$crstype,%customroles) = @_;
1.27 raeburn 6325: my (@possible_roles,@permitted_roles);
1.101 raeburn 6326: @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
1.27 raeburn 6327: foreach my $role (@possible_roles) {
6328: if ($role eq 'cr') {
6329: push(@permitted_roles,keys(%customroles));
6330: } else {
6331: push(@permitted_roles,$role);
6332: }
6333: }
1.42 raeburn 6334: return @permitted_roles;
1.27 raeburn 6335: }
6336:
1.17 raeburn 6337: sub get_course_identity {
6338: my ($cid) = @_;
6339: my ($cnum,$cdom,$cdesc);
6340: if ($cid eq '') {
6341: $cid = $env{'request.course.id'}
6342: }
6343: if ($cid ne '') {
6344: $cnum = $env{'course.'.$cid.'.num'};
6345: $cdom = $env{'course.'.$cid.'.domain'};
6346: $cdesc = $env{'course.'.$cid.'.description'};
6347: if ($cnum eq '' || $cdom eq '') {
6348: my %coursehash =
6349: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
6350: $cdom = $coursehash{'domain'};
6351: $cnum = $coursehash{'num'};
6352: $cdesc = $coursehash{'description'};
6353: }
6354: }
6355: return ($cnum,$cdom,$cdesc);
6356: }
6357:
1.19 raeburn 6358: sub dc_setcourse_js {
1.196 raeburn 6359: my ($formname,$mode,$context,$showcredits,$domain) = @_;
1.37 raeburn 6360: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 6361: my $cctext = &Apache::lonnet::plaintext('cc');
1.103 raeburn 6362: my $cotext = &Apache::lonnet::plaintext('co');
1.19 raeburn 6363: my %alerts = §ioncheck_alerts();
6364: my $role = 'role';
6365: if ($mode eq 'upload') {
6366: $role = 'courserole';
1.37 raeburn 6367: } else {
1.196 raeburn 6368: $authen_check = &verify_authen($formname,$context,$domain);
1.19 raeburn 6369: }
6370: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 6371: $authen_check
6372:
1.19 raeburn 6373: function setCourse() {
6374: var course = document.$formname.dccourse.value;
6375: if (course != "") {
6376: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
6377: alert("$alerts{'curd'}");
6378: return;
6379: }
6380: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
6381: var section="";
6382: var numsections = 0;
6383: var newsecs = new Array();
6384: for (var i=0; i<document.$formname.currsec.length; i++) {
6385: if (document.$formname.currsec.options[i].selected == true ) {
6386: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
6387: if (numsections == 0) {
6388: section = document.$formname.currsec.options[i].value
6389: numsections = 1;
6390: }
6391: else {
6392: section = section + "," + document.$formname.currsec.options[i].value
6393: numsections ++;
6394: }
6395: }
6396: }
6397: }
6398: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
6399: if (numsections == 0) {
6400: section = document.$formname.newsec.value
6401: }
6402: else {
6403: section = section + "," + document.$formname.newsec.value
6404: }
6405: newsecs = document.$formname.newsec.value.split(/,/g);
6406: numsections = numsections + newsecs.length;
6407: }
6408: if ((userrole == 'st') && (numsections > 1)) {
1.103 raeburn 6409: if (document.$formname.crstype.value == 'Community') {
6410: alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
6411: } else {
6412: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
6413: }
1.19 raeburn 6414: return;
6415: }
6416: for (var j=0; j<newsecs.length; j++) {
6417: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
6418: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
6419: return;
6420: }
6421: if (document.$formname.groups.value != '') {
6422: var groups = document.$formname.groups.value.split(/,/g);
6423: for (var k=0; k<groups.length; k++) {
6424: if (newsecs[j] == groups[k]) {
1.103 raeburn 6425: if (document.$formname.crstype.value == 'Community') {
6426: alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
6427: } else {
6428: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
6429: }
1.19 raeburn 6430: return;
6431: }
6432: }
6433: }
6434: }
6435: if ((userrole == 'cc') && (numsections > 0)) {
6436: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
6437: section = "";
6438: }
1.103 raeburn 6439: if ((userrole == 'co') && (numsections > 0)) {
6440: alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
6441: section = "";
6442: }
1.19 raeburn 6443: SCRIPTTOP
6444: if ($mode ne 'upload') {
1.150 raeburn 6445: $dc_setcourse_code .= (<<"SCRIPTMID");
1.19 raeburn 6446: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
6447: var numcourse = getIndex(document.$formname.dccourse);
6448: if (numcourse == "-1") {
1.103 raeburn 6449: if (document.$formname.type == 'Community') {
6450: alert("$alerts{'thwc'}");
6451: } else {
6452: alert("$alerts{'thwa'}");
6453: }
1.19 raeburn 6454: return;
6455: }
6456: else {
6457: document.$formname.elements[numcourse].name = "act"+coursename;
6458: var numnewsec = getIndex(document.$formname.newsec);
6459: if (numnewsec != "-1") {
6460: document.$formname.elements[numnewsec].name = "sec"+coursename;
6461: document.$formname.elements[numnewsec].value = section;
6462: }
6463: var numstart = getIndex(document.$formname.start);
6464: if (numstart != "-1") {
6465: document.$formname.elements[numstart].name = "start"+coursename;
6466: }
6467: var numend = getIndex(document.$formname.end);
6468: if (numend != "-1") {
6469: document.$formname.elements[numend].name = "end"+coursename
6470: }
1.150 raeburn 6471: SCRIPTMID
6472: if ($showcredits) {
6473: $dc_setcourse_code .= <<ENDCRED;
6474: var numcredits = getIndex(document.$formname.credits);
6475: if (numcredits != "-1") {
6476: document.$formname.elements[numcredits].name = "credits"+coursename;
6477: }
6478: ENDCRED
6479: }
6480: $dc_setcourse_code .= <<ENDSCRIPT;
1.19 raeburn 6481: }
6482: }
1.37 raeburn 6483: var authcheck = auth_check();
6484: if (authcheck == 'ok') {
6485: document.$formname.submit();
6486: }
1.19 raeburn 6487: }
6488: ENDSCRIPT
6489: } else {
6490: $dc_setcourse_code .= "
6491: document.$formname.sections.value = section;
6492: }
6493: return 'ok';
6494: }
6495: ";
6496: }
6497: $dc_setcourse_code .= (<<"ENDSCRIPT");
6498:
6499: function getIndex(caller) {
6500: for (var i=0;i<document.$formname.elements.length;i++) {
6501: if (document.$formname.elements[i] == caller) {
6502: return i;
6503: }
6504: }
6505: return -1;
6506: }
6507: ENDSCRIPT
1.37 raeburn 6508: return $dc_setcourse_code;
6509: }
6510:
6511: sub verify_authen {
1.196 raeburn 6512: my ($formname,$context,$domain) = @_;
1.37 raeburn 6513: my %alerts = &authcheck_alerts();
6514: my $finish = "return 'ok';";
6515: if ($context eq 'author') {
6516: $finish = "document.$formname.submit();";
6517: }
1.196 raeburn 6518: my ($numrules,$intargjs) =
6519: &passwd_validation_js('argpicked',$domain);
1.37 raeburn 6520: my $outcome = <<"ENDSCRIPT";
6521:
6522: function auth_check() {
6523: var logintype;
6524: if (document.$formname.login.length) {
6525: if (document.$formname.login.length > 0) {
6526: var loginpicked = 0;
6527: for (var i=0; i<document.$formname.login.length; i++) {
6528: if (document.$formname.login[i].checked == true) {
6529: loginpicked = 1;
6530: logintype = document.$formname.login[i].value;
6531: }
6532: }
6533: if (loginpicked == 0) {
6534: alert("$alerts{'authen'}");
6535: return;
6536: }
6537: }
6538: } else {
6539: logintype = document.$formname.login.value;
6540: }
6541: if (logintype == 'nochange') {
6542: return 'ok';
6543: }
6544: var argpicked = document.$formname.elements[logintype+'arg'].value;
6545: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
6546: var alertmsg = '';
6547: switch (logintype) {
6548: case 'krb':
6549: alertmsg = '$alerts{'krb'}';
6550: break;
6551: case 'int':
6552: alertmsg = '$alerts{'ipass'}';
1.196 raeburn 6553: break;
1.37 raeburn 6554: case 'fsys':
6555: alertmsg = '$alerts{'ipass'}';
6556: break;
6557: case 'loc':
6558: alertmsg = '';
6559: break;
6560: default:
6561: alertmsg = '';
6562: }
6563: if (alertmsg != '') {
6564: alert(alertmsg);
6565: return;
6566: }
1.196 raeburn 6567: } else if (logintype == 'int') {
6568: var numrules = $numrules;
6569: if (numrules > 0) {
6570: $intargjs
6571: }
1.37 raeburn 6572: }
6573: $finish
6574: }
6575: ENDSCRIPT
1.19 raeburn 6576: }
6577:
6578: sub sectioncheck_alerts {
6579: my %alerts = &Apache::lonlocal::texthash(
1.103 raeburn 6580: curd => 'You must select a course or community in the current domain',
1.19 raeburn 6581: inea => 'In each course, each user may only have one student role at a time',
1.103 raeburn 6582: inco => 'In each community, each user may only have one member role at a time',
1.19 raeburn 6583: youh => 'You had selected',
6584: sect => 'sections',
6585: plsm => 'Please modify your selections so they include no more than one section',
6586: mayn => 'may not be used as the name for a section, as it is a reserved word',
6587: plsc => 'Please choose a different section name',
6588: mayt => 'may not be used as the name for a section, as it is the name of a course group',
1.103 raeburn 6589: mayc => 'may not be used as the name for a section, as it is the name of a community group',
1.19 raeburn 6590: secn => 'Section names and group names must be distinct',
6591: secd => 'Section designations do not apply to ',
6592: role => 'roles',
6593: accr => 'role will be added with access to all sections',
1.103 raeburn 6594: thwa => 'There was a problem with your course selection',
6595: thwc => 'There was a problem with your community selection',
1.19 raeburn 6596: );
1.170 damieng 6597: &js_escape(\%alerts);
1.19 raeburn 6598: return %alerts;
6599: }
1.17 raeburn 6600:
1.37 raeburn 6601: sub authcheck_alerts {
6602: my %alerts =
6603: &Apache::lonlocal::texthash(
6604: authen => 'You must choose an authentication type.',
6605: krb => 'You need to specify the Kerberos domain.',
6606: ipass => 'You need to specify the initial password.',
6607: );
1.170 damieng 6608: &js_escape(\%alerts);
1.37 raeburn 6609: return %alerts;
6610: }
6611:
1.141 raeburn 6612: sub is_courseowner {
6613: my ($thiscourse,$courseowner) = @_;
6614: if ($courseowner eq '') {
6615: if ($env{'request.course.id'} eq $thiscourse) {
6616: $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
6617: }
6618: }
6619: if ($courseowner ne '') {
6620: if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
6621: return 1;
6622: }
6623: }
6624: return;
6625: }
6626:
1.165 raeburn 6627: sub get_selfenroll_titles {
6628: my @row = ('types','registered','enroll_dates','access_dates','section',
6629: 'approval','limit');
6630: my %lt = &Apache::lonlocal::texthash (
6631: types => 'Users allowed to self-enroll',
6632: registered => 'Registration status (official courses)' ,
6633: enroll_dates => 'Dates self-enrollment available',
6634: access_dates => 'Access dates for self-enrolling users',
6635: section => "Self-enrolling users' section",
6636: approval => 'Processing of requests',
6637: limit => 'Enrollment limit',
6638: );
6639: return (\@row,\%lt);
6640: }
6641:
6642: sub selfenroll_default_descs {
6643: my %desc = (
6644: types => {
6645: dom => &mt('Course domain'),
6646: all => &mt('Any domain'),
6647: '' => &mt('None'),
6648: },
6649: limit => {
6650: none => &mt('No limit'),
6651: allstudents => &mt('Limit by total students'),
6652: selfenrolled => &mt('Limit by total self-enrolled'),
6653: },
6654: approval => {
6655: '0' => &mt('Processed automatically'),
6656: '1' => &mt('Queued for approval'),
6657: '2' => &mt('Queued, pending validation'),
6658: },
6659: registered => {
6660: 0 => 'No registration required',
6661: 1 => 'Registered students only',
6662: },
6663: );
6664: return %desc;
6665: }
6666:
6667: sub selfenroll_validation_types {
6668: my @items = ('url','fields','button','markup');
6669: my %names = &Apache::lonlocal::texthash (
6670: url => 'Web address of validation server/script',
6671: fields => 'Form fields to send to validator',
6672: button => 'Text for validation button',
6673: markup => 'Validation description (HTML)',
6674: );
1.167 raeburn 6675: my @fields = ('username','domain','uniquecode','course','coursetype','description');
1.165 raeburn 6676: return (\@items,\%names,\@fields);
6677: }
6678:
6679: sub get_extended_type {
6680: my ($cdom,$cnum,$crstype,$current) = @_;
6681: my $type = 'unofficial';
6682: my %settings;
6683: if (ref($current) eq 'HASH') {
6684: %settings = %{$current};
6685: } else {
6686: %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
6687: }
6688: if ($crstype eq 'Community') {
6689: $type = 'community';
1.173 raeburn 6690: } elsif ($crstype eq 'Placement') {
6691: $type = 'placement';
1.165 raeburn 6692: } elsif ($settings{'internal.coursecode'}) {
6693: $type = 'official';
6694: } elsif ($settings{'internal.textbook'}) {
6695: $type = 'textbook';
6696: }
6697: return $type;
6698: }
6699:
6700: sub selfenrollment_administration {
6701: my ($cdom,$cnum,$crstype,$coursehash) = @_;
6702: my %settings;
6703: if (ref($coursehash) eq 'HASH') {
6704: %settings = %{$coursehash};
6705: } else {
6706: %settings = &Apache::lonnet::get('environment',
6707: ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
6708: 'internal.coursecode','internal.textbook'],$cdom,$cnum);
6709: }
6710: my ($possconfigs) = &get_selfenroll_titles();
6711: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6712: my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
6713:
6714: my (@in_course,@in_domain);
6715: if ($settings{'internal.selfenrollmgrcc'} ne '') {
6716: @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
6717: my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
6718: unless (@diffs) {
6719: return (\@in_course,\@in_domain);
6720: }
6721: }
6722: if ($settings{'internal.selfenrollmgrdc'} ne '') {
6723: my @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
6724: my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
6725: unless (@diffs) {
6726: return (\@in_course,\@in_domain);
6727: }
6728: }
6729: my @combined = @in_course;
6730: push(@combined,@in_domain);
6731: my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
6732: unless (@diffs) {
6733: return (\@in_course,\@in_domain);
6734: }
6735: if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
6736: push(@in_course,@diffs);
6737: } else {
6738: my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
6739: foreach my $item (@diffs) {
6740: if (grep(/^\Q$item\E$/,@defaultdc)) {
6741: push(@in_domain,$item);
6742: } else {
6743: push(@in_course,$item);
6744: }
6745: }
6746: }
6747: return (\@in_course,\@in_domain);
6748: }
6749:
1.175 raeburn 6750: sub custom_role_header {
6751: my ($context,$crstype,$templaterolerefs,$prefix) = @_;
6752: my %lt = &Apache::lonlocal::texthash(
6753: sele => 'Select a Template',
6754: );
6755: my ($context_code,$button_code);
6756: if ($context eq 'domain') {
6757: $context_code = &custom_coursetype_switch($crstype,$prefix);
6758: }
6759: if (ref($templaterolerefs) eq 'ARRAY') {
6760: foreach my $role (@{$templaterolerefs}) {
6761: my $display = 'inline';
6762: if (($context eq 'domain') && ($role eq 'co')) {
6763: $display = 'none';
6764: }
6765: $button_code .= &make_button_code($role,$crstype,$display,$prefix).' ';
6766: }
6767: }
6768: return <<"END";
6769: <div class="LC_left_float">
6770: <fieldset>
6771: <legend>$lt{'sele'}</legend>
6772: $button_code
6773: </fieldset></div>
6774: $context_code
6775: <br clear="all" />
6776: END
6777: }
6778:
6779: sub custom_coursetype_switch {
6780: my ($crstype,$prefix) = @_;
6781: my ($checkedcourse,$checkedcommunity);
6782: if ($crstype eq 'Community') {
6783: $checkedcommunity = ' checked="checked"';
6784: } else {
6785: $checkedcourse = ' checked="checked"';
6786: }
6787: my %lt = &Apache::lonlocal::texthash(
6788: cont => 'Context',
6789: cour => 'Course',
6790: comm => 'Community',
6791: );
6792: return <<"END";
6793: <div class="LC_left_float">
6794: <fieldset>
6795: <legend>$lt{'cont'}</legend>
6796: <label>
6797: <input type="radio" name="${prefix}_custrolecrstype" value="Course"$checkedcourse onclick="javascript:customSwitchType('$prefix');" />
6798: $lt{'cour'}
6799: </label>
6800: <label>
6801: <input type="radio" name="${prefix}_custrolecrstype" value="Community"$checkedcommunity onclick="javascript:customSwitchType('$prefix');" />
6802: $lt{'comm'}
6803: </label>
6804: </fieldset>
6805: </div>
6806: END
6807: }
6808:
6809: sub custom_role_table {
1.180 raeburn 6810: my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
1.175 raeburn 6811: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
6812: (ref($levelscurrent) eq 'HASH'));
6813: my %lt=&Apache::lonlocal::texthash (
6814: 'prv' => "Privilege",
6815: 'crl' => "Course Level",
6816: 'dml' => "Domain Level",
6817: 'ssl' => "System Level");
6818: my %cr = (
6819: course => '_c',
6820: domain => '_d',
6821: system => '_s',
6822: );
6823:
1.180 raeburn 6824: my $output=&Apache::loncommon::start_data_table($add_class,$id).
1.175 raeburn 6825: &Apache::loncommon::start_data_table_header_row().
6826: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
6827: '</th><th>'.$lt{'ssl'}.'</th>'.
6828: &Apache::loncommon::end_data_table_header_row();
6829: foreach my $priv (sort(keys(%{$full}))) {
6830: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
6831: $output .= &Apache::loncommon::start_data_table_row().
6832: '<td><span id="'.$prefix.$priv.'">'.$privtext.'</span></td>';
6833: foreach my $type ('course','domain','system') {
6834: if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
6835: $output .= '<td> </td>';
6836: } else {
6837: $output .= '<td>'.
6838: ($levels->{$type}{$priv}?'<input type="checkbox" id="'.$prefix.$priv.$cr{$type}.'"'.
6839: ' name="'.$prefix.$priv.$cr{$type}.'"'.
6840: ($levelscurrent->{$type}{$priv}?' checked="checked"':'').' />':' ').
6841: '</td>';
6842: }
6843: }
6844: $output .= &Apache::loncommon::end_data_table_row();
6845: }
6846: $output .= &Apache::loncommon::end_data_table();
6847: return $output;
6848: }
6849:
6850: sub custom_role_privs {
6851: my ($privs,$full,$levels,$levelscurrent)= @_;
6852: return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
6853: (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
6854: my %cr = (
6855: course => 'cr:c',
6856: domain => 'cr:d',
6857: system => 'cr:s',
6858: );
6859: foreach my $type ('course','domain','system') {
6860: foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
6861: my ($priv,$restrict)=split(/\&/,$item);
6862: if (!$restrict) { $restrict='F'; }
6863: $levels->{$type}->{$priv}=$restrict;
6864: if ($privs->{$type}=~/\:$priv/) {
6865: $levelscurrent->{$type}->{$priv}=1;
6866: }
6867: $full->{$priv}=1;
6868: }
6869: }
6870: return;
6871: }
6872:
6873: sub custom_template_roles {
6874: my ($context,$crstype) = @_;
6875: my @template_roles = ("in","ta","ep");
6876: if (($context eq 'domain') || ($context eq 'domprefs')) {
6877: push(@template_roles,"ad");
6878: }
6879: push(@template_roles,"st");
6880: if ($context eq 'domain') {
6881: unshift(@template_roles,('co','cc'));
6882: } else {
6883: if ($crstype eq 'Community') {
6884: unshift(@template_roles,'co');
6885: } else {
6886: unshift(@template_roles,'cc');
6887: }
6888: }
6889: return @template_roles;
6890: }
6891:
6892: sub custom_roledefs_js {
6893: my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
6894: my $button_code = "\n";
6895: my $head_script = "\n";
6896: my (%roletitlestr,$rolenamestr);
6897: my %role_titles = (
6898: Course => [],
6899: Community => [],
6900: );
6901: $head_script .= '<script type="text/javascript">'."\n"
6902: .'// <![CDATA['."\n";
6903: if (ref($templaterolesref) eq 'ARRAY') {
6904: if ($context eq 'domain') {
6905: $rolenamestr = join("','",@{$templaterolesref});
6906: }
6907: foreach my $role (@{$templaterolesref}) {
6908: $head_script .= &make_script_template($role,$crstype,$formname);
6909: if ($context eq 'domain') {
6910: foreach my $type ('Course','Community') {
6911: push(@{$role_titles{$type}},&Apache::lonnet::plaintext($role,$type));
6912: }
6913: }
6914: }
6915: }
6916: if ($context eq 'domain') {
6917: foreach my $type ('Course','Community') {
6918: $roletitlestr{$type} = join("','",@{$role_titles{$type}});
6919: }
6920: my %pt = (
6921: Community => {
6922: cst => &mt('Grant/revoke role of Member'),
6923: mdc => &mt('Edit community contents'),
6924: pch => &mt('Post discussion on community resources'),
6925: pfo => &mt('Print for other users and entire community'),
6926: },
6927: Course => {
6928: cst => &mt('Grant/revoke role of Student'),
6929: mdc => &mt('Edit course contents'),
6930: pch => &mt('Post discussion on course resources'),
6931: pfo => &mt('Print for other users and entire course'),
6932: },
6933: );
6934: $head_script .= <<"ENDJS";
6935: function customSwitchType(prefix) {
6936: var privnames = new Array('cst','mdc','pch','pfo');
6937: var privtxtcrs = new Array('$pt{Course}{cst}','$pt{Course}{mdc}','$pt{Course}{pch}','$pt{Course}{pfo}');
6938: var privtxtcom = new Array('$pt{Community}{cst}','$pt{Community}{mdc}','$pt{Community}{pch}','$pt{Community}{pfo}');
6939: var rolenames = new Array('$rolenamestr');
6940: var rolescrs = new Array('$roletitlestr{Course}');
6941: var rolescom = new Array('$roletitlestr{Community}');
6942: var radio = prefix+'_custrolecrstype';
6943: if (document.$formname.elements[radio].length > 1) {
6944: for (var i=0; i<document.$formname.elements[radio].length; i++) {
6945: if (document.$formname.elements[radio][i].checked) {
6946: if ((document.getElementById(prefix+'bre_s')) && (document.getElementById(prefix+'bro_s'))) {
6947: if (document.$formname.elements[radio][i].value == 'Community') {
6948: if (document.getElementById(prefix+'bre_s').checked) {
6949: document.getElementById(prefix+'bro_s').checked = true;
6950: document.getElementById(prefix+'bre_s').checked = false;
6951:
6952: }
6953: document.getElementById(prefix+'bre_s').style.visibility = 'hidden';
6954: } else {
6955: document.getElementById(prefix+'bre_s').style.visibility = 'visible';
6956: if (document.getElementById(prefix+'bro_s').checked) {
6957: document.getElementById(prefix+'bre_s').checked = true;
6958: document.getElementById(prefix+'bro_s').checked = false;
6959: }
6960: }
6961: }
6962: for (var j=0; j<privnames.length; j++) {
6963: if (document.getElementById(prefix+privnames[j])) {
6964: if (document.getElementById(prefix+privnames[j])) {
6965: if (document.$formname.elements[radio][i].value == 'Course') {
6966: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcrs[j];
6967: } else {
6968: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcom[j];
6969: }
6970: }
6971: }
6972: }
6973: for (var j=0; j<rolenames.length; j++) {
6974: if (document.getElementById(prefix+rolenames[j])) {
6975: if (document.getElementById(prefix+rolenames[j])) {
6976: if (document.$formname.elements[radio][i].value == 'Course') {
6977: document.getElementById(prefix+rolenames[j]).value = rolescrs[j];
6978: if (rolenames[j] == 'cc') {
6979: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
6980: }
6981: if (rolenames[j] == 'co') {
6982: document.getElementById(prefix+rolenames[j]).style.display = 'none';
6983: }
6984: } else {
6985: document.getElementById(prefix+rolenames[j]).value = rolescom[j];
6986: if (rolenames[j] == 'cc') {
6987: document.getElementById(prefix+rolenames[j]).style.display = 'none';
6988: }
6989: if (rolenames[j] == 'co') {
6990: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
6991: }
6992: }
6993: }
6994: }
6995: }
6996: }
6997: }
6998: }
6999: return;
7000: }
7001: ENDJS
7002: }
7003: $head_script .= "\n".$jsback."\n"
7004: .'// ]]>'."\n"
7005: .'</script>'."\n";
7006: return $head_script;
7007: }
7008:
7009: # --------------------------------------------------------
7010: sub make_script_template {
7011: my ($role,$crstype,$formname) = @_;
7012: my $return_script = 'function set_'.$role.'(prefix) {'."\n";
7013: my (%full_by_level,%role_priv);
7014: foreach my $level ('c','d','s') {
7015: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7016: next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
7017: my ($priv,$restrict)=split(/\&/,$item);
7018: $full_by_level{$level}{$priv}=1;
7019: }
7020: $role_priv{$level} = {};
7021: my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
7022: foreach my $priv (@temp) {
7023: my ($priv_item, $dummy) = split(/\&/,$priv);
7024: $role_priv{$level}{$priv_item} = 1;
7025: }
7026: }
7027: my %to_check = (
7028: c => ['c','d','s'],
7029: d => ['d','s'],
7030: s => ['s'],
7031: );
7032: foreach my $level ('c','d','s') {
7033: if (ref($full_by_level{$level}) eq 'HASH') {
7034: foreach my $priv (keys(%{$full_by_level{$level}})) {
7035: my $value = 'false';
7036: if (ref($to_check{$level}) eq 'ARRAY') {
7037: foreach my $lett (@{$to_check{$level}}) {
7038: if (exists($role_priv{$lett}{$priv})) {
7039: $value = 'true';
7040: last;
7041: }
7042: }
7043: $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
7044: }
7045: }
7046: }
7047: }
7048: $return_script .= '}'."\n";
7049: return ($return_script);
7050: }
7051: # ----------------------------------------------------------
7052: sub make_button_code {
7053: my ($role,$crstype,$display,$prefix) = @_;
7054: my $label = &Apache::lonnet::plaintext($role,$crstype);
7055: my $button_code = '<input type="button" onclick="set_'.$role."('$prefix'".')" '.
7056: 'id="'.$prefix.$role.'" value="'.$label.'" '.
7057: 'style="display:'.$display.'" />';
7058: return ($button_code);
7059: }
7060:
7061: sub custom_role_update {
7062: my ($rolename,$prefix) = @_;
7063: # ------------------------------------------------------- What can be assigned?
7064: my %privs = (
7065: c => '',
7066: d => '',
7067: s => '',
7068: );
7069: foreach my $level (keys(%privs)) {
7070: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
7071: my ($priv,$restrict)=split(/\&/,$item);
7072: if (!$restrict) { $restrict=''; }
7073: if ($env{'form.'.$prefix.$priv.'_'.$level}) {
7074: $privs{$level} .=':'.$item;
7075: }
7076: }
7077: }
7078: return %privs;
7079: }
7080:
1.180 raeburn 7081: sub adhoc_status_types {
7082: my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
7083: my $output = &Apache::loncommon::start_data_table();
7084: my $numinrow = 3;
7085: my $rem;
7086: if (ref($types) eq 'ARRAY') {
7087: for (my $i=0; $i<@{$types}; $i++) {
7088: if (defined($usertypes->{$types->[$i]})) {
7089: my $rem = $i%($numinrow);
7090: if ($rem == 0) {
7091: if ($i > 0) {
7092: $output .= &Apache::loncommon::end_data_table_row();
7093: }
7094: $output .= &Apache::loncommon::start_data_table_row();
7095: }
7096: my $check;
7097: if (ref($selectedref) eq 'ARRAY') {
7098: if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
7099: $check = ' checked="checked"';
7100: }
7101: }
7102: $output .= '<td>'.
7103: '<span class="LC_nobreak"><label>'.
7104: '<input type="checkbox" name="'.$context.$role.'_status" '.
7105: 'value="'.$types->[$i].'"'.$check.$disabled.' />'.
7106: $usertypes->{$types->[$i]}.'</label></span></td>';
7107: }
7108: }
7109: $rem = @{$types}%($numinrow);
7110: }
7111: my $colsleft = $numinrow - $rem;
7112: if (($rem == 0) && (@{$types} > 0)) {
7113: $output .= &Apache::loncommon::start_data_table_row();
7114: }
7115: if ($colsleft > 1) {
7116: $output .= '<td colspan="'.$colsleft.'">';
7117: } else {
7118: $output .= '<td>';
7119: }
7120: my $defcheck;
7121: if (ref($selectedref) eq 'ARRAY') {
7122: if (grep(/^default$/,@{$selectedref})) {
7123: $defcheck = ' checked="checked"';
7124: }
7125: }
7126: $output .= '<span class="LC_nobreak"><label>'.
7127: '<input type="checkbox" name="'.$context.$role.'_status"'.
7128: 'value="default"'.$defcheck.$disabled.' />'.
7129: $othertitle.'</label></span></td>'.
7130: &Apache::loncommon::end_data_table_row().
7131: &Apache::loncommon::end_data_table();
7132: return $output;
7133: }
7134:
7135: sub adhoc_staff {
7136: my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
7137: my $output;
7138: if (ref($adhocref) eq 'HASH') {
7139: my %by_fullname;
7140: my $numinrow = 4;
7141: my $rem;
7142: my @personnel = keys(%{$adhocref});
7143: if (@personnel) {
7144: foreach my $person (@personnel) {
7145: my ($uname,$udom) = split(/:/,$person);
7146: my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
7147: $by_fullname{$fullname} = $person;
7148: }
7149: my @sorted = sort(keys(%by_fullname));
7150: my $count = scalar(@sorted);
7151: $output = &Apache::loncommon::start_data_table();
7152: for (my $i=0; $i<$count; $i++) {
7153: my $rem = $i%($numinrow);
7154: if ($rem == 0) {
7155: if ($i > 0) {
7156: $output .= &Apache::loncommon::end_data_table_row();
7157: }
7158: $output .= &Apache::loncommon::start_data_table_row();
7159: }
7160: my $check;
7161: my $user = $by_fullname{$sorted[$i]};
7162: if (ref($selectedref) eq 'ARRAY') {
7163: if (grep(/^\Q$user\E$/,@{$selectedref})) {
7164: $check = ' checked="checked"';
7165: }
7166: }
7167: if ($i == $count-1) {
7168: my $colsleft = $numinrow - $rem;
7169: if ($colsleft > 1) {
7170: $output .= '<td colspan="'.$colsleft.'">';
7171: } else {
7172: $output .= '<td>';
7173: }
7174: } else {
7175: $output .= '<td>';
7176: }
7177: $output .= '<span class="LC_nobreak"><label>'.
7178: '<input type="checkbox" name="'.$context.$role.'_staff_'.$access.'" '.
7179: 'value="'.$user.'"'.$check.$disabled.' />'.$sorted[$i].
7180: '</label></span></td>';
7181: if ($i == $count-1) {
7182: $output .= &Apache::loncommon::end_data_table_row();
7183: }
7184: }
7185: $output .= &Apache::loncommon::end_data_table();
7186: }
7187: }
7188: return $output;
7189: }
7190:
7191:
1.1 raeburn 7192: 1;
7193:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>