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