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