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