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