Annotation of loncom/interface/lonuserutils.pm, revision 1.138
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.138 ! raeburn 4: # $Id: lonuserutils.pm,v 1.137 2012/04/25 21:05:30 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: }
1447: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1.2 raeburn 1448: ($env{'form.Status'});
1.1 raeburn 1449:
1.2 raeburn 1450: if ($env{'form.showrole'} eq '') {
1.13 raeburn 1451: if ($context eq 'course') {
1452: $env{'form.showrole'} = 'st';
1453: } else {
1454: $env{'form.showrole'} = 'Any';
1455: }
1.2 raeburn 1456: }
1.1 raeburn 1457: if (! defined($env{'form.output'}) ||
1458: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
1459: $env{'form.output'} = 'html';
1460: }
1461:
1.2 raeburn 1462: my @statuses;
1463: if ($env{'form.Status'} eq 'Any') {
1464: @statuses = ('previous','active','future');
1465: } elsif ($env{'form.Status'} eq 'Expired') {
1466: @statuses = ('previous');
1467: } elsif ($env{'form.Status'} eq 'Active') {
1468: @statuses = ('active');
1469: } elsif ($env{'form.Status'} eq 'Future') {
1470: @statuses = ('future');
1471: }
1.1 raeburn 1472:
1.2 raeburn 1473: # if ($context eq 'course') {
1474: # $r->print(&display_adv_courseroles());
1475: # }
1.1 raeburn 1476: #
1477: # Interface output
1.2 raeburn 1478: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
1479: '<input type="hidden" name="action" value="'.
1.1 raeburn 1480: $env{'form.action'}.'" />');
1481: $r->print("<p>\n");
1482: if ($env{'form.action'} ne 'modifystudent') {
1483: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
1484: 'excel' => "Excel",
1485: 'html' => 'HTML');
1486: my $output_selector = '<select size="1" name="output" >';
1487: foreach my $outputformat ('html','csv','excel') {
1.96 bisitz 1488: my $option = '<option value="'.$outputformat.'"';
1.1 raeburn 1489: if ($outputformat eq $env{'form.output'}) {
1.96 bisitz 1490: $option .= ' selected="selected"';
1.1 raeburn 1491: }
1492: $option .='>'.$lt{$outputformat}.'</option>';
1493: $output_selector .= "\n".$option;
1494: }
1495: $output_selector .= '</select>';
1.70 bisitz 1496: $r->print('<label><span class="LC_nobreak">'
1497: .&mt('Output Format: [_1]',$output_selector)
1498: .'</span></label>'.(' 'x3));
1499: }
1500: $r->print('<label><span class="LC_nobreak">'
1501: .&mt('User Status: [_1]',$status_select)
1502: .'</span></label>'.(' 'x3)."\n");
1.2 raeburn 1503: my $roleselected = '';
1504: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 1505: $roleselected = ' selected="selected"';
1.2 raeburn 1506: }
1.53 raeburn 1507: my ($cnum,$cdom);
1508: $r->print(&role_filter($context));
1509: if ($context eq 'course') {
1510: ($cnum,$cdom) = &get_course_identity();
1511: $r->print(§ion_group_filter($cnum,$cdom));
1.2 raeburn 1512: }
1.78 raeburn 1513: if ($env{'form.phase'} eq '') {
1514: $r->print('<br /><br />'.&list_submit_button(&mt('Display List of Users')).
1515: "\n</p>\n".
1516: '<input type="hidden" name="phase" value="" /></form>');
1517: return;
1518: }
1.106 raeburn 1519: if (!(($context eq 'domain') &&
1520: (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
1.111 bisitz 1521: $r->print(
1522: "\n</p>\n"
1523: .'<p>'
1524: .&list_submit_button(&mt('Update Display'))
1525: ."</p>\n"
1526: );
1.2 raeburn 1527: }
1528: my ($indexhash,$keylist) = &make_keylist_array();
1.106 raeburn 1529: my (%userlist,%userinfo,$clearcoursepick);
1.102 raeburn 1530: if (($context eq 'domain') &&
1531: ($env{'form.roletype'} eq 'course') ||
1532: ($env{'form.roletype'} eq 'community')) {
1533: my ($crstype,$numcodes,$title,$warning);
1534: if ($env{'form.roletype'} eq 'course') {
1535: $crstype = 'Course';
1536: $numcodes = $totcodes;
1537: $title = &mt('Select Courses');
1538: $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
1539: } elsif ($env{'form.roletype'} eq 'community') {
1540: $crstype = 'Community';
1541: $numcodes = 0;
1542: $title = &mt('Select Communities');
1543: $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
1544: }
1.120 raeburn 1545: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.3 raeburn 1546: my $courseform =
1.102 raeburn 1547: &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
1.120 raeburn 1548: $codetitles,$idlist,$idlist_titles,$crstype,
1549: \@standardnames);
1.3 raeburn 1550: $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
1551: &Apache::lonhtmlcommon::start_pick_box()."\n".
1.102 raeburn 1552: &Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n".
1.3 raeburn 1553: $courseform."\n".
1554: &Apache::lonhtmlcommon::row_closure(1).
1555: &Apache::lonhtmlcommon::end_pick_box().'</p>'.
1.106 raeburn 1556: '<p><input type="hidden" name="origroletype" value="'.$env{'form.roletype'}.'" />'.
1557: &list_submit_button(&mt('Update Display')).
1.102 raeburn 1558: "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
1.106 raeburn 1559: $clearcoursepick = 0;
1560: if (($env{'form.origroletype'} ne '') &&
1561: ($env{'form.origroletype'} ne $env{'form.roletype'})) {
1562: $clearcoursepick = 1;
1563: }
1564: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.11 raeburn 1565: $r->print('<hr />'.&mt('Searching').' ...<br /> <br />');
1566: }
1567: } else {
1568: $r->print('<hr />'.&mt('Searching').' ...<br /> <br />');
1.3 raeburn 1569: }
1570: $r->rflush();
1.1 raeburn 1571: if ($context eq 'course') {
1.46 raeburn 1572: if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
1.45 raeburn 1573: my $classlist = &Apache::loncoursedata::get_classlist();
1.66 raeburn 1574: if (ref($classlist) eq 'HASH') {
1575: %userlist = %{$classlist};
1576: }
1.45 raeburn 1577: }
1.43 raeburn 1578: if ($env{'form.showrole'} ne 'st') {
1579: my $showroles;
1580: if ($env{'form.showrole'} ne 'Any') {
1581: $showroles = [$env{'form.showrole'}];
1.3 raeburn 1582: } else {
1.43 raeburn 1583: $showroles = undef;
1.1 raeburn 1584: }
1.43 raeburn 1585: my $withsec = 1;
1586: my $hidepriv = 1;
1587: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
1588: \@statuses,$showroles,undef,$withsec,$hidepriv);
1589: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1590: \%advrolehash,$permission);
1.1 raeburn 1591: }
1.2 raeburn 1592: } else {
1593: my (%cstr_roles,%dom_roles);
1.13 raeburn 1594: if ($context eq 'author') {
1.2 raeburn 1595: # List co-authors and assistant co-authors
1.17 raeburn 1596: my @possroles = &roles_by_context($context);
1.2 raeburn 1597: %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
1598: \@statuses,\@possroles);
1599: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1.11 raeburn 1600: \%cstr_roles,$permission);
1.2 raeburn 1601: } elsif ($context eq 'domain') {
1602: if ($env{'form.roletype'} eq 'domain') {
1603: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
1604: foreach my $key (keys(%dom_roles)) {
1605: if (ref($dom_roles{$key}) eq 'HASH') {
1606: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 1607: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 1608: }
1609: }
1.13 raeburn 1610: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 1611: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
1612: my %coauthors;
1613: foreach my $key (keys(%dom_roles)) {
1614: if (ref($dom_roles{$key}) eq 'HASH') {
1615: if ($env{'form.showrole'} eq 'au') {
1616: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 1617: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 1618: } else {
1619: my @possroles;
1620: if ($env{'form.showrole'} eq 'Any') {
1.22 raeburn 1621: @possroles = &roles_by_context('author');
1.2 raeburn 1622: } else {
1623: @possroles = ($env{'form.showrole'});
1624: }
1625: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1.22 raeburn 1626: my ($role,$authorname,$authordom) = split(/:/,$author,-1);
1.2 raeburn 1627: my $extent = '/'.$authordom.'/'.$authorname;
1628: %{$coauthors{$extent}} =
1629: &Apache::lonnet::get_my_roles($authorname,
1630: $authordom,undef,\@statuses,\@possroles);
1631: }
1632: &gather_userinfo($context,$format,\%userlist,
1.11 raeburn 1633: $indexhash,\%userinfo,\%coauthors,$permission);
1.2 raeburn 1634: }
1635: }
1636: }
1.101 raeburn 1637: } elsif (($env{'form.roletype'} eq 'course') ||
1638: ($env{'form.roletype'} eq 'community')) {
1.106 raeburn 1639: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.2 raeburn 1640: my %courses = &process_coursepick();
1.39 raeburn 1641: my %allusers;
1642: my $hidepriv = 1;
1.2 raeburn 1643: foreach my $cid (keys(%courses)) {
1.17 raeburn 1644: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
1.11 raeburn 1645: next if ($cnum eq '' || $cdom eq '');
1.17 raeburn 1646: my $custom = 1;
1.2 raeburn 1647: my (@roles,@sections,%access,%users,%userdata,
1.6 albertel 1648: %statushash);
1.2 raeburn 1649: if ($env{'form.showrole'} eq 'Any') {
1.101 raeburn 1650: @roles = &course_roles($context,undef,$custom,
1651: $env{'form.roletype'});
1.2 raeburn 1652: } else {
1653: @roles = ($env{'form.showrole'});
1654: }
1655: foreach my $role (@roles) {
1656: %{$users{$role}} = ();
1657: }
1658: foreach my $type (@statuses) {
1659: $access{$type} = $type;
1660: }
1.39 raeburn 1661: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
1.2 raeburn 1662: foreach my $user (keys(%userdata)) {
1663: next if (ref($userinfo{$user}) eq 'HASH');
1664: foreach my $item ('fullname','id') {
1665: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
1666: }
1667: }
1668: foreach my $role (keys(%users)) {
1669: foreach my $user (keys(%{$users{$role}})) {
1670: my $uniqid = $user.':'.$role;
1671: $allusers{$uniqid}{$cid} = { desc => $cdesc,
1672: secs => $statushash{$user}{$role},
1673: };
1674: }
1675: }
1676: }
1677: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 1678: \%userinfo,\%allusers,$permission);
1.2 raeburn 1679: } else {
1.10 raeburn 1680: $r->print('<input type="hidden" name="phase" value="'.
1681: $env{'form.phase'}.'" /></form>');
1.2 raeburn 1682: return;
1683: }
1.1 raeburn 1684: }
1685: }
1.3 raeburn 1686: }
1687: if (keys(%userlist) == 0) {
1.13 raeburn 1688: if ($context eq 'author') {
1.3 raeburn 1689: $r->print(&mt('There are no co-authors to display.')."\n");
1690: } elsif ($context eq 'domain') {
1691: if ($env{'form.roletype'} eq 'domain') {
1692: $r->print(&mt('There are no users with domain roles to display.')."\n");
1.13 raeburn 1693: } elsif ($env{'form.roletype'} eq 'author') {
1.3 raeburn 1694: $r->print(&mt('There are no authors or co-authors to display.')."\n");
1695: } elsif ($env{'form.roletype'} eq 'course') {
1696: $r->print(&mt('There are no course users to display')."\n");
1.101 raeburn 1697: } elsif ($env{'form.roletype'} eq 'community') {
1698: $r->print(&mt('There are no community users to display')."\n");
1.2 raeburn 1699: }
1.3 raeburn 1700: } elsif ($context eq 'course') {
1701: $r->print(&mt('There are no course users to display.')."\n");
1702: }
1703: } else {
1704: # Print out the available choices
1.4 raeburn 1705: my $usercount;
1.3 raeburn 1706: if ($env{'form.action'} eq 'modifystudent') {
1.10 raeburn 1707: ($usercount) = &show_users_list($r,$context,'view',$permission,
1.4 raeburn 1708: $env{'form.Status'},\%userlist,$keylist);
1.1 raeburn 1709: } else {
1.4 raeburn 1710: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1.10 raeburn 1711: $permission,$env{'form.Status'},\%userlist,$keylist);
1.4 raeburn 1712: }
1713: if (!$usercount) {
1.72 bisitz 1714: $r->print('<br /><span class="LC_warning">'
1715: .&mt('There are no users matching the search criteria.')
1716: .'</span>'
1717: );
1.2 raeburn 1718: }
1719: }
1.10 raeburn 1720: $r->print('<input type="hidden" name="phase" value="'.
1721: $env{'form.phase'}.'" /></form>');
1.2 raeburn 1722: }
1723:
1.53 raeburn 1724: sub role_filter {
1725: my ($context) = @_;
1726: my $output;
1727: my $roleselected = '';
1728: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 1729: $roleselected = ' selected="selected"';
1.53 raeburn 1730: }
1731: my ($role_select);
1732: if ($context eq 'domain') {
1733: $role_select = &domain_roles_select();
1.70 bisitz 1734: $output = '<label><span class="LC_nobreak">'
1735: .&mt('Role Type: [_1]',$role_select)
1736: .'</span></label>';
1.53 raeburn 1737: } else {
1738: $role_select = '<select name="showrole">'."\n".
1739: '<option value="Any" '.$roleselected.'>'.
1740: &mt('Any role').'</option>';
1.101 raeburn 1741: my ($roletype,$crstype);
1742: if ($context eq 'course') {
1743: $crstype = &Apache::loncommon::course_type();
1744: if ($crstype eq 'Community') {
1745: $roletype = 'community';
1746: } else {
1747: $roletype = 'course';
1748: }
1749: }
1750: my @poss_roles = &curr_role_permissions($context,'','',$roletype);
1.53 raeburn 1751: foreach my $role (@poss_roles) {
1752: $roleselected = '';
1753: if ($role eq $env{'form.showrole'}) {
1.91 bisitz 1754: $roleselected = ' selected="selected"';
1.53 raeburn 1755: }
1756: my $plrole;
1757: if ($role eq 'cr') {
1758: $plrole = &mt('Custom role');
1759: } else {
1.101 raeburn 1760: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.53 raeburn 1761: }
1762: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
1763: }
1764: $role_select .= '</select>';
1.70 bisitz 1765: $output = '<label><span class="LC_nobreak">'
1766: .&mt('Role: [_1]',$role_select)
1.111 bisitz 1767: .'</span></label> ';
1.53 raeburn 1768: }
1769: return $output;
1770: }
1771:
1.33 raeburn 1772: sub section_group_filter {
1773: my ($cnum,$cdom) = @_;
1774: my @filters;
1775: if ($env{'request.course.sec'} eq '') {
1776: @filters = ('sec');
1777: }
1778: push(@filters,'grp');
1779: my %name = (
1780: sec => 'secfilter',
1781: grp => 'grpfilter',
1782: );
1783: my %title = &Apache::lonlocal::texthash (
1784: sec => 'Section(s)',
1785: grp => 'Group(s)',
1786: all => 'all',
1787: none => 'none',
1788: );
1.47 raeburn 1789: my $output;
1.33 raeburn 1790: foreach my $item (@filters) {
1.47 raeburn 1791: my ($markup,@options);
1.33 raeburn 1792: if ($env{'form.'.$name{$item}} eq '') {
1793: $env{'form.'.$name{$item}} = 'all';
1794: }
1795: if ($item eq 'sec') {
1.103 raeburn 1796: if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
1.33 raeburn 1797: $env{'form.'.$name{$item}} = 'none';
1798: }
1799: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
1800: @options = sort(keys(%sections_count));
1801: } elsif ($item eq 'grp') {
1802: my %curr_groups = &Apache::longroup::coursegroups();
1803: @options = sort(keys(%curr_groups));
1804: }
1805: if (@options > 0) {
1806: my $currsel;
1.112 bisitz 1807: $markup = '<select name="'.$name{$item}.'">'."\n";
1.33 raeburn 1808: foreach my $option ('all','none',@options) {
1809: $currsel = '';
1810: if ($env{'form.'.$name{$item}} eq $option) {
1.96 bisitz 1811: $currsel = ' selected="selected"';
1.33 raeburn 1812: }
1813: $markup .= ' <option value="'.$option.'"'.$currsel.'>';
1814: if (($option eq 'all') || ($option eq 'none')) {
1815: $markup .= $title{$option};
1816: } else {
1817: $markup .= $option;
1818: }
1819: $markup .= '</option>'."\n";
1820: }
1821: $markup .= '</select>'."\n";
1.111 bisitz 1822: $output .= (' 'x3).'<span class="LC_nobreak">'
1823: .'<label>'.$title{$item}.': '.$markup.'</label>'
1824: .'</span> ';
1.33 raeburn 1825: }
1826: }
1827: return $output;
1828: }
1829:
1.2 raeburn 1830: sub list_submit_button {
1831: my ($text) = @_;
1.11 raeburn 1832: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1.2 raeburn 1833: }
1834:
1835: sub gather_userinfo {
1.11 raeburn 1836: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1.52 raeburn 1837: my $viewablesec;
1838: if ($context eq 'course') {
1839: $viewablesec = &viewable_section($permission);
1840: }
1.2 raeburn 1841: foreach my $item (keys(%{$rolehash})) {
1842: my %userdata;
1.22 raeburn 1843: if ($context eq 'author') {
1.2 raeburn 1844: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1845: split(/:/,$item);
1846: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1.24 raeburn 1847: &build_user_record($context,\%userdata,$userinfo,$indexhash,
1848: $item,$userlist);
1.22 raeburn 1849: } elsif ($context eq 'course') {
1850: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
1851: $userdata{'section'}) = split(/:/,$item,-1);
1852: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1853: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
1854: next if ($viewablesec ne $userdata{'section'});
1855: }
1.24 raeburn 1856: &build_user_record($context,\%userdata,$userinfo,$indexhash,
1857: $item,$userlist);
1.2 raeburn 1858: } elsif ($context eq 'domain') {
1859: if ($env{'form.roletype'} eq 'domain') {
1860: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
1861: split(/:/,$item);
1862: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1.24 raeburn 1863: &build_user_record($context,\%userdata,$userinfo,$indexhash,
1864: $item,$userlist);
1.13 raeburn 1865: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 1866: if (ref($rolehash->{$item}) eq 'HASH') {
1867: $userdata{'extent'} = $item;
1868: foreach my $key (keys(%{$rolehash->{$item}})) {
1869: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
1870: ($userdata{'start'},$userdata{'end'}) =
1871: split(/:/,$rolehash->{$item}{$key});
1872: my $uniqid = $key.':'.$item;
1.25 raeburn 1873: &build_user_record($context,\%userdata,$userinfo,
1874: $indexhash,$uniqid,$userlist);
1.2 raeburn 1875: }
1876: }
1.102 raeburn 1877: } elsif (($env{'form.roletype'} eq 'course') ||
1878: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 1879: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1880: split(/:/,$item);
1881: if (ref($rolehash->{$item}) eq 'HASH') {
1.11 raeburn 1882: my $numcids = keys(%{$rolehash->{$item}});
1.2 raeburn 1883: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
1884: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
1885: my $spanstart = '';
1886: my $spanend = '; ';
1887: my $space = ', ';
1888: if ($format eq 'html' || $format eq 'view') {
1889: $spanstart = '<span class="LC_nobreak">';
1.23 raeburn 1890: # FIXME: actions on courses disabled for now
1891: # if ($permission->{'cusr'}) {
1892: # if ($numcids > 1) {
1.25 raeburn 1893: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 1894: # } else {
1.25 raeburn 1895: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 1896: # }
1897: # }
1.2 raeburn 1898: $spanend = '</span><br />';
1899: $space = ', ';
1900: }
1901: $userdata{'extent'} .= $spanstart.
1902: $rolehash->{$item}{$cid}{'desc'}.$space;
1903: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
1904: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1.25 raeburn 1905: if (($env{'form.Status'} eq 'Any') ||
1906: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
1907: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
1908: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
1909: }
1.2 raeburn 1910: }
1911: }
1912: }
1913: }
1914: }
1.25 raeburn 1915: if ($userdata{'status'} ne '') {
1916: &build_user_record($context,\%userdata,$userinfo,
1917: $indexhash,$item,$userlist);
1918: }
1.2 raeburn 1919: }
1920: }
1921: }
1922: return;
1923: }
1924:
1925: sub build_user_record {
1.24 raeburn 1926: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1.11 raeburn 1927: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1.102 raeburn 1928: if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
1929: && ($env{'form.roletype'} eq 'community')))) {
1.24 raeburn 1930: &process_date_info($userdata);
1931: }
1.2 raeburn 1932: my $username = $userdata->{'username'};
1933: my $domain = $userdata->{'domain'};
1934: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1.24 raeburn 1935: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1.2 raeburn 1936: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1937: } else {
1938: &aggregate_user_info($domain,$username,$userinfo);
1939: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1940: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1941: }
1942: foreach my $key (keys(%{$indexhash})) {
1943: if (defined($userdata->{$key})) {
1944: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
1945: }
1946: }
1947: return;
1948: }
1949:
1950: sub courses_selector {
1951: my ($cdom,$formname) = @_;
1952: my %coursecodes = ();
1953: my %codes = ();
1954: my @codetitles = ();
1955: my %cat_titles = ();
1956: my %cat_order = ();
1957: my %idlist = ();
1958: my %idnums = ();
1959: my %idlist_titles = ();
1960: my $caller = 'global';
1961: my $format_reply;
1962: my $jscript = '';
1963:
1.7 albertel 1964: my $totcodes = 0;
1965: $totcodes =
1.2 raeburn 1966: &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,
1967: $cdom,$totcodes);
1968: if ($totcodes > 0) {
1969: $format_reply =
1970: &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
1971: \%codes,\@codetitles,\%cat_titles,\%cat_order);
1972: if ($format_reply eq 'ok') {
1973: my $numtypes = @codetitles;
1974: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
1975: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
1976: my $longtitles_str = join('","',@{$longtitles});
1977: my $allidlist = $idlist{$codetitles[0]};
1978: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
1979: $jscript .= $scripttext;
1980: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
1981: }
1982: }
1983: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
1984:
1985: my %elements = (
1986: Year => 'selectbox',
1987: coursepick => 'radio',
1988: coursetotal => 'text',
1989: courselist => 'text',
1990: );
1991: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
1992: if ($env{'form.coursepick'} eq 'category') {
1993: $jscript .= qq|
1994: function setCourseCat(formname) {
1995: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
1996: return;
1997: }
1.120 raeburn 1998: courseSet('$codetitles[0]');
1.2 raeburn 1999: for (var j=0; j<formname.Semester.length; j++) {
2000: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
2001: formname.Semester.options[j].selected = true;
2002: }
2003: }
2004: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
2005: return;
2006: }
1.120 raeburn 2007: courseSet('$codetitles[1]');
1.2 raeburn 2008: for (var j=0; j<formname.Department.length; j++) {
2009: if (formname.Department.options[j].value == "$env{'form.Department'}") { formname.Department.options[j].selected = true;
2010: }
2011: }
2012: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
2013: return;
2014: }
1.120 raeburn 2015: courseSet('$codetitles[2]');
1.2 raeburn 2016: for (var j=0; j<formname.Number.length; j++) {
2017: if (formname.Number.options[j].value == "$env{'form.Number'}") {
2018: formname.Number.options[j].selected = true;
2019: }
2020: }
2021: }
2022: |;
2023: }
2024: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
2025: \%idlist_titles);
2026: }
2027:
2028: sub course_selector_loadcode {
2029: my ($formname) = @_;
2030: my $loadcode;
2031: if ($env{'form.coursepick'} ne '') {
2032: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
2033: if ($env{'form.coursepick'} eq 'category') {
2034: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
2035: }
2036: }
2037: return $loadcode;
2038: }
2039:
2040: sub process_coursepick {
2041: my $coursefilter = $env{'form.coursepick'};
2042: my $cdom = $env{'request.role.domain'};
2043: my %courses;
1.105 raeburn 2044: my $crssrch = 'Course';
2045: if ($env{'form.roletype'} eq 'community') {
2046: $crssrch = 'Community';
2047: }
1.2 raeburn 2048: if ($coursefilter eq 'all') {
2049: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1.105 raeburn 2050: undef,undef,$crssrch);
1.2 raeburn 2051: } elsif ($coursefilter eq 'category') {
2052: my $instcode = &instcode_from_coursefilter();
2053: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1.105 raeburn 2054: undef,undef,$crssrch);
1.2 raeburn 2055: } elsif ($coursefilter eq 'specific') {
2056: if ($env{'form.coursetotal'} > 1) {
2057: my @course_ids = split(/&&/,$env{'form.courselist'});
2058: foreach my $cid (@course_ids) {
2059: $courses{$cid} = '';
1.1 raeburn 2060: }
1.2 raeburn 2061: } else {
2062: $courses{$env{'form.courselist'}} = '';
1.1 raeburn 2063: }
1.2 raeburn 2064: }
2065: return %courses;
2066: }
2067:
2068: sub instcode_from_coursefilter {
2069: my $instcode = '';
2070: my @cats = ('Semester','Year','Department','Number');
2071: foreach my $category (@cats) {
2072: if (defined($env{'form.'.$category})) {
2073: unless ($env{'form.'.$category} eq '-1') {
2074: $instcode .= $env{'form.'.$category};
2075: }
2076: }
2077: }
2078: if ($instcode eq '') {
2079: $instcode = '.';
2080: }
2081: return $instcode;
2082: }
2083:
2084: sub display_adv_courseroles {
2085: my $output;
2086: #
2087: # List course personnel
2088: my %coursepersonnel =
2089: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'});
2090: #
2091: $output = '<br />'.&Apache::loncommon::start_data_table();
2092: foreach my $role (sort(keys(%coursepersonnel))) {
2093: next if ($role =~ /^\s*$/);
2094: $output .= &Apache::loncommon::start_data_table_row().
2095: '<td>'.$role.'</td><td>';
2096: foreach my $user (split(',',$coursepersonnel{$role})) {
2097: my ($puname,$pudom)=split(':',$user);
2098: $output .= ' '.&Apache::loncommon::aboutmewrapper(
2099: &Apache::loncommon::plainname($puname,$pudom),
2100: $puname,$pudom);
2101: }
2102: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
2103: }
2104: $output .= &Apache::loncommon::end_data_table();
2105: }
2106:
2107: sub make_keylist_array {
2108: my ($index,$keylist);
2109: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
2110: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
2111: $index->{'end'} = &Apache::loncoursedata::CL_END();
2112: $index->{'start'} = &Apache::loncoursedata::CL_START();
2113: $index->{'id'} = &Apache::loncoursedata::CL_ID();
2114: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
2115: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
2116: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
2117: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
2118: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
2119: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
2120: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
2121: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
2122: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1.44 raeburn 2123: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
1.47 raeburn 2124: $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
1.2 raeburn 2125: foreach my $key (keys(%{$index})) {
2126: $keylist->[$index->{$key}] = $key;
2127: }
2128: return ($index,$keylist);
2129: }
2130:
2131: sub aggregate_user_info {
2132: my ($udom,$uname,$userinfo) = @_;
2133: my %info=&Apache::lonnet::get('environment',
2134: ['firstname','middlename',
2135: 'lastname','generation','id'],
2136: $udom,$uname);
2137: my ($tmp) = keys(%info);
2138: my ($fullname,$id);
2139: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
2140: $fullname = 'not available';
2141: $id = 'not available';
2142: &Apache::lonnet::logthis('unable to retrieve environment '.
2143: 'for '.$uname.':'.$udom);
1.1 raeburn 2144: } else {
1.2 raeburn 2145: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
2146: $id = $info{'id'};
2147: }
2148: $userinfo->{$uname.':'.$udom} = {
2149: fullname => $fullname,
2150: id => $id,
2151: };
2152: return;
2153: }
1.1 raeburn 2154:
1.2 raeburn 2155: sub process_date_info {
2156: my ($userdata) = @_;
2157: my $now = time;
1.83 raeburn 2158: $userdata->{'status'} = 'Active';
1.2 raeburn 2159: if ($userdata->{'start'} > 0) {
2160: if ($now < $userdata->{'start'}) {
1.83 raeburn 2161: $userdata->{'status'} = 'Future';
1.2 raeburn 2162: }
1.1 raeburn 2163: }
1.2 raeburn 2164: if ($userdata->{'end'} > 0) {
2165: if ($now > $userdata->{'end'}) {
1.83 raeburn 2166: $userdata->{'status'} = 'Expired';
1.2 raeburn 2167: }
2168: }
2169: return;
1.1 raeburn 2170: }
2171:
2172: sub show_users_list {
1.55 raeburn 2173: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_;
2174: if ($formname eq '') {
2175: $formname = 'studentform';
2176: }
1.1 raeburn 2177: #
2178: # Variables for excel output
2179: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
2180: #
2181: # Variables for csv output
2182: my ($CSVfile,$CSVfilename);
2183: #
2184: my $sortby = $env{'form.sortby'};
1.3 raeburn 2185: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1.2 raeburn 2186: if ($context eq 'course') {
1.3 raeburn 2187: push(@sortable,('section','groups','type'));
1.2 raeburn 2188: } else {
1.3 raeburn 2189: push(@sortable,'extent');
2190: }
1.55 raeburn 2191: if ($mode eq 'pickauthor') {
2192: @sortable = ('username','fullname','email','status');
2193: }
1.3 raeburn 2194: if (!grep(/^\Q$sortby\E$/,@sortable)) {
2195: $sortby = 'username';
1.1 raeburn 2196: }
1.22 raeburn 2197: my $setting = $env{'form.roletype'};
1.101 raeburn 2198: my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers,$crstype);
1.1 raeburn 2199: if ($context eq 'course') {
1.22 raeburn 2200: $cid = $env{'request.course.id'};
1.101 raeburn 2201: $crstype = &Apache::loncommon::course_type();
1.17 raeburn 2202: ($cnum,$cdom) = &get_course_identity($cid);
1.2 raeburn 2203: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
2204: $userlist,$keylist,$cdom,$cnum);
1.16 raeburn 2205: if ($mode eq 'autoenroll') {
2206: $env{'form.showrole'} = 'st';
2207: } else {
2208: if (! exists($env{'form.displayphotos'})) {
2209: $env{'form.displayphotos'} = 'off';
2210: }
2211: $displayphotos = $env{'form.displayphotos'};
2212: if (! exists($env{'form.displayclickers'})) {
2213: $env{'form.displayclickers'} = 'off';
2214: }
2215: $displayclickers = $env{'form.displayclickers'};
2216: if ($env{'course.'.$cid.'.internal.showphoto'}) {
2217: $r->print('
1.1 raeburn 2218: <script type="text/javascript">
1.96 bisitz 2219: // <![CDATA[
1.1 raeburn 2220: function photowindow(photolink) {
2221: var title = "Photo_Viewer";
2222: var options = "scrollbars=1,resizable=1,menubar=0";
2223: options += ",width=240,height=240";
2224: stdeditbrowser = open(photolink,title,options,"1");
2225: stdeditbrowser.focus();
2226: }
1.96 bisitz 2227: // ]]>
1.1 raeburn 2228: </script>
1.16 raeburn 2229: ');
2230: }
2231: $r->print(<<END);
1.1 raeburn 2232: <input type="hidden" name="displayphotos" value="$displayphotos" />
2233: <input type="hidden" name="displayclickers" value="$displayclickers" />
2234: END
1.16 raeburn 2235: }
1.102 raeburn 2236: } elsif ($context eq 'domain') {
2237: if ($setting eq 'community') {
2238: $crstype = 'Community';
1.105 raeburn 2239: } elsif ($setting eq 'course') {
1.102 raeburn 2240: $crstype = 'Course';
2241: }
1.1 raeburn 2242: }
1.55 raeburn 2243: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.11 raeburn 2244: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.40 raeburn 2245: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1.56 raeburn 2246: my $verify_action_js = &bulkaction_javascript($formname);
1.1 raeburn 2247: $r->print(<<END);
1.10 raeburn 2248:
2249: <script type="text/javascript" language="Javascript">
1.96 bisitz 2250: // <![CDATA[
1.11 raeburn 2251: $check_uncheck_js
2252:
1.56 raeburn 2253: $verify_action_js
1.10 raeburn 2254:
2255: function username_display_launch(username,domain) {
2256: var target;
1.55 raeburn 2257: for (var i=0; i<document.$formname.usernamelink.length; i++) {
2258: if (document.$formname.usernamelink[i].checked) {
2259: target = document.$formname.usernamelink[i].value;
1.10 raeburn 2260: }
2261: }
2262: if (target == 'modify') {
1.55 raeburn 2263: if (document.$formname.userwin.checked == true) {
1.50 raeburn 2264: var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&action=singleuser&srchin=dom&srchby=uname&srchtype=exact&popup=1';
2265: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2266: modifywin = window.open(url,'',options,1);
2267: modifywin.focus();
2268: return;
2269: } else {
1.55 raeburn 2270: document.$formname.srchterm.value=username;
2271: document.$formname.srchdomain.value=domain;
2272: document.$formname.phase.value='get_user_info';
2273: document.$formname.action.value = 'singleuser';
2274: document.$formname.submit();
1.50 raeburn 2275: }
1.10 raeburn 2276: }
1.48 raeburn 2277: if (target == 'aboutme') {
1.55 raeburn 2278: if (document.$formname.userwin.checked == true) {
1.50 raeburn 2279: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
2280: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2281: aboutmewin = window.open(url,'',options,1);
2282: aboutmewin.focus();
2283: return;
2284: } else {
2285: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
2286: }
1.48 raeburn 2287: }
1.98 raeburn 2288: if (target == 'track') {
2289: if (document.$formname.userwin.checked == true) {
2290: var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
2291: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2292: var trackwin = window.open(url,'',options,1);
2293: trackwin.focus();
2294: return;
2295: } else {
2296: document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
2297: }
2298: }
1.10 raeburn 2299: }
1.96 bisitz 2300: // ]]>
1.10 raeburn 2301: </script>
1.11 raeburn 2302: $date_sec_selector
1.1 raeburn 2303: <input type="hidden" name="state" value="$env{'form.state'}" />
2304: END
2305: }
2306: $r->print(<<END);
2307: <input type="hidden" name="sortby" value="$sortby" />
2308: END
2309:
2310: my %lt=&Apache::lonlocal::texthash(
2311: 'username' => "username",
2312: 'domain' => "domain",
2313: 'id' => 'ID',
2314: 'fullname' => "name",
2315: 'section' => "section",
2316: 'groups' => "active groups",
2317: 'start' => "start date",
2318: 'end' => "end date",
2319: 'status' => "status",
1.2 raeburn 2320: 'role' => "role",
1.1 raeburn 2321: 'type' => "enroll type/action",
1.79 schafran 2322: 'email' => "e-mail address",
1.1 raeburn 2323: 'photo' => "photo",
1.2 raeburn 2324: 'extent' => "extent",
1.11 raeburn 2325: 'pr' => "Proceed",
2326: 'ca' => "check all",
2327: 'ua' => "uncheck all",
2328: 'ac' => "Action to take for selected users",
1.56 raeburn 2329: 'link' => "Behavior of clickable username link for each user",
1.82 weissno 2330: 'aboutme' => "Display a user's personal information page",
1.50 raeburn 2331: 'owin' => "Open in a new window",
1.10 raeburn 2332: 'modify' => "Modify a user's information",
1.98 raeburn 2333: 'track' => "View a user's recent activity",
1.67 droeschl 2334: 'clicker' => "Clicker-ID",
1.1 raeburn 2335: );
1.2 raeburn 2336: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2337: $lt{'extent'} = &mt('Course(s): description, section(s), status');
1.102 raeburn 2338: } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
2339: $lt{'extent'} = &mt('Communities: description, section(s), status');
1.13 raeburn 2340: } elsif ($context eq 'author') {
1.2 raeburn 2341: $lt{'extent'} = &mt('Author');
2342: }
1.55 raeburn 2343: my @cols;
2344: if ($mode eq 'pickauthor') {
2345: @cols = ('username','fullname','status','email');
2346: } else {
2347: @cols = ('username','domain','id','fullname');
2348: if ($context eq 'course') {
2349: push(@cols,'section');
2350: }
1.102 raeburn 2351: if (!($context eq 'domain' && ($env{'form.roletype'} eq 'course')
2352: && ($env{'form.roletype'} eq 'community'))) {
1.55 raeburn 2353: push(@cols,('start','end'));
2354: }
2355: if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
2356: push(@cols,'role');
2357: }
2358: if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
1.102 raeburn 2359: $env{'form.roletype'} eq 'course' ||
2360: $env{'form.roletype'} eq 'community')) {
1.55 raeburn 2361: push (@cols,'extent');
2362: }
2363: if (($statusmode eq 'Any') &&
1.102 raeburn 2364: (!($context eq 'domain' && (($env{'form.roletype'} eq 'course')
2365: || ($env{'form.roletype'} eq 'community'))))) {
1.55 raeburn 2366: push(@cols,'status');
2367: }
2368: if ($context eq 'course') {
2369: push(@cols,'groups');
2370: }
2371: push(@cols,'email');
1.2 raeburn 2372: }
1.1 raeburn 2373:
1.4 raeburn 2374: my $rolefilter = $env{'form.showrole'};
1.5 raeburn 2375: if ($env{'form.showrole'} eq 'cr') {
2376: $rolefilter = &mt('custom');
2377: } elsif ($env{'form.showrole'} ne 'Any') {
1.101 raeburn 2378: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype);
1.2 raeburn 2379: }
1.16 raeburn 2380: my $results_description;
2381: if ($mode ne 'autoenroll') {
2382: $results_description = &results_header_row($rolefilter,$statusmode,
1.102 raeburn 2383: $context,$permission,$mode,$crstype);
1.56 raeburn 2384: $r->print('<b>'.$results_description.'</b><br /><br />');
1.16 raeburn 2385: }
1.26 raeburn 2386: my ($output,$actionselect,%canchange,%canchangesec);
1.55 raeburn 2387: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
2388: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.16 raeburn 2389: if ($permission->{'cusr'}) {
1.105 raeburn 2390: unless (($context eq 'domain') &&
2391: (($setting eq 'course') || ($setting eq 'community'))) {
2392: $actionselect =
2393: &select_actions($context,$setting,$statusmode,$formname);
2394: }
1.16 raeburn 2395: }
2396: $r->print(<<END);
1.10 raeburn 2397: <input type="hidden" name="srchby" value="uname" />
2398: <input type="hidden" name="srchin" value="dom" />
2399: <input type="hidden" name="srchtype" value="exact" />
2400: <input type="hidden" name="srchterm" value="" />
1.11 raeburn 2401: <input type="hidden" name="srchdomain" value="" />
1.1 raeburn 2402: END
1.16 raeburn 2403: if ($actionselect) {
1.41 raeburn 2404: $output .= <<"END";
1.94 bisitz 2405: <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
1.56 raeburn 2406: $actionselect
2407: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
2408: <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 2409: END
1.26 raeburn 2410: my @allroles;
2411: if ($env{'form.showrole'} eq 'Any') {
2412: my $custom = 1;
2413: if ($context eq 'domain') {
1.101 raeburn 2414: @allroles = &roles_by_context($setting,$custom,$crstype);
1.26 raeburn 2415: } else {
1.101 raeburn 2416: @allroles = &roles_by_context($context,$custom,$crstype);
1.26 raeburn 2417: }
2418: } else {
2419: @allroles = ($env{'form.showrole'});
2420: }
2421: foreach my $role (@allroles) {
2422: if ($context eq 'domain') {
2423: if ($setting eq 'domain') {
2424: if (&Apache::lonnet::allowed('c'.$role,
2425: $env{'request.role.domain'})) {
2426: $canchange{$role} = 1;
2427: }
1.31 raeburn 2428: } elsif ($setting eq 'author') {
2429: if (&Apache::lonnet::allowed('c'.$role,
2430: $env{'request.role.domain'})) {
2431: $canchange{$role} = 1;
2432: }
1.26 raeburn 2433: }
2434: } elsif ($context eq 'author') {
2435: if (&Apache::lonnet::allowed('c'.$role,
2436: $env{'user.domain'}.'/'.$env{'user.name'})) {
2437: $canchange{$role} = 1;
2438: }
2439: } elsif ($context eq 'course') {
2440: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2441: $canchange{$role} = 1;
2442: } elsif ($env{'request.course.sec'} ne '') {
2443: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
2444: $canchangesec{$role} = $env{'request.course.sec'};
2445: }
2446: }
2447: }
2448: }
1.16 raeburn 2449: }
1.94 bisitz 2450: $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
1.56 raeburn 2451: '<table><tr>';
2452: my @linkdests = ('aboutme');
2453: if ($permission->{'cusr'}) {
2454: unshift (@linkdests,'modify');
2455: }
1.98 raeburn 2456: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
2457: &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
2458: $env{'request.course.sec'})) {
2459: push(@linkdests,'track');
2460: }
2461:
1.56 raeburn 2462: $output .= '<td>';
2463: my $usernamelink = $env{'form.usernamelink'};
2464: if ($usernamelink eq '') {
2465: $usernamelink = 'aboutme';
2466: }
2467: foreach my $item (@linkdests) {
2468: my $checkedstr = '';
2469: if ($item eq $usernamelink) {
1.86 bisitz 2470: $checkedstr = ' checked="checked"';
1.56 raeburn 2471: }
1.86 bisitz 2472: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
1.56 raeburn 2473: }
2474: my $checkwin;
2475: if ($env{'form.userwin'}) {
1.86 bisitz 2476: $checkwin = ' checked="checked"';
1.56 raeburn 2477: }
1.110 bisitz 2478: $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 2479: }
1.56 raeburn 2480: $output .= "\n".'<div class="LC_clear_float_footer"> </div>'."\n".
1.1 raeburn 2481: &Apache::loncommon::start_data_table().
1.4 raeburn 2482: &Apache::loncommon::start_data_table_header_row();
1.1 raeburn 2483: if ($mode eq 'autoenroll') {
1.4 raeburn 2484: $output .= "
1.55 raeburn 2485: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
1.4 raeburn 2486: ";
1.1 raeburn 2487: } else {
1.105 raeburn 2488: $output .= "\n".'<th> </th>'."\n";
1.11 raeburn 2489: if ($actionselect) {
2490: $output .= '<th>'.&mt('Select').'</th>'."\n";
2491: }
1.1 raeburn 2492: }
2493: foreach my $item (@cols) {
1.55 raeburn 2494: $output .= "<th><a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\">$lt{$item}</a></th>\n";
1.1 raeburn 2495: }
1.2 raeburn 2496: my %role_types = &role_type_names();
1.16 raeburn 2497: if ($context eq 'course' && $mode ne 'autoenroll') {
1.4 raeburn 2498: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2499: # Clicker display on or off?
1.58 bisitz 2500: my %clicker_options = (
2501: 'on' => 'Show',
2502: 'off' => 'Hide',
2503: );
1.4 raeburn 2504: my $clickerchg = 'on';
2505: if ($displayclickers eq 'on') {
2506: $clickerchg = 'off';
2507: }
1.58 bisitz 2508: $output .= ' <th>'."\n".' '
2509: .&mt('[_1]'.$clicker_options{$clickerchg}.'[_2] clicker id'
2510: ,'<a href="javascript:document.'.$formname.'.displayclickers.value='
2511: ."'".$clickerchg."'".';document.'.$formname.'.submit();">'
2512: ,'</a>')
2513: ."\n".' </th>'."\n";
1.1 raeburn 2514:
1.4 raeburn 2515: # Photo display on or off?
2516: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2517: my %photo_options = &Apache::lonlocal::texthash(
2518: 'on' => 'Show',
2519: 'off' => 'Hide',
2520: );
2521: my $photochg = 'on';
2522: if ($displayphotos eq 'on') {
2523: $photochg = 'off';
2524: }
2525: $output .= ' <th>'."\n".' '.
1.55 raeburn 2526: '<a href="javascript:document.'.$formname.'.displayphotos.value='.
2527: "'".$photochg."'".';document.'.$formname.'.submit();">'.
1.1 raeburn 2528: $photo_options{$photochg}.'</a> '.$lt{'photo'}."\n".
1.4 raeburn 2529: ' </th>'."\n";
2530: }
1.1 raeburn 2531: }
1.4 raeburn 2532: }
1.16 raeburn 2533: $output .= &Apache::loncommon::end_data_table_header_row();
1.1 raeburn 2534: # Done with the HTML header line
2535: } elsif ($mode eq 'csv') {
2536: #
2537: # Open a file
2538: $CSVfilename = '/prtspool/'.
1.2 raeburn 2539: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
2540: time.'_'.rand(1000000000).'.csv';
1.1 raeburn 2541: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
2542: $r->log_error("Couldn't open $CSVfilename for output $!");
1.108 bisitz 2543: $r->print(
2544: '<p class="LC_error">'
2545: .&mt('Problems occurred in writing the CSV file.')
2546: .' '.&mt('This error has been logged.')
2547: .' '.&mt('Please alert your LON-CAPA administrator.')
2548: .'</p>'
2549: );
1.1 raeburn 2550: $CSVfile = undef;
2551: }
2552: #
1.67 droeschl 2553: push @cols,'clicker';
1.1 raeburn 2554: # Write headers and data to file
1.2 raeburn 2555: print $CSVfile '"'.$results_description.'"'."\n";
1.1 raeburn 2556: print $CSVfile '"'.join('","',map {
2557: &Apache::loncommon::csv_translate($lt{$_})
1.67 droeschl 2558: } (@cols))."\"\n";
1.1 raeburn 2559: } elsif ($mode eq 'excel') {
1.67 droeschl 2560: push @cols,'clicker';
1.1 raeburn 2561: # Create the excel spreadsheet
2562: ($excel_workbook,$excel_filename,$format) =
2563: &Apache::loncommon::create_workbook($r);
2564: return if (! defined($excel_workbook));
2565: $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2 raeburn 2566: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1 raeburn 2567: #
2568: my @colnames = map {$lt{$_}} (@cols);
1.67 droeschl 2569:
1.1 raeburn 2570: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
2571: }
2572:
2573: # Done with header lines in all formats
2574: my %index;
2575: my $i;
1.2 raeburn 2576: foreach my $idx (@$keylist) {
2577: $index{$idx} = $i++;
2578: }
1.4 raeburn 2579: my $usercount = 0;
1.33 raeburn 2580: my ($secfilter,$grpfilter);
2581: if ($context eq 'course') {
2582: $secfilter = $env{'form.secfilter'};
2583: $grpfilter = $env{'form.grpfilter'};
2584: if ($secfilter eq '') {
2585: $secfilter = 'all';
2586: }
2587: if ($grpfilter eq '') {
2588: $grpfilter = 'all';
2589: }
2590: }
1.83 raeburn 2591: my %ltstatus = &Apache::lonlocal::texthash(
2592: Active => 'Active',
2593: Future => 'Future',
2594: Expired => 'Expired',
2595: );
1.2 raeburn 2596: # Get groups, role, permanent e-mail so we can sort on them if
2597: # necessary.
2598: foreach my $user (keys(%{$userlist})) {
1.43 raeburn 2599: if ($user eq '' ) {
2600: delete($userlist->{$user});
2601: next;
2602: }
1.11 raeburn 2603: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
2604: delete($userlist->{$user});
2605: next;
2606: }
1.2 raeburn 2607: my ($uname,$udom,$role,$groups,$email);
1.5 raeburn 2608: if (($statusmode ne 'Any') &&
2609: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
2610: delete($userlist->{$user});
2611: next;
2612: }
1.2 raeburn 2613: if ($context eq 'domain') {
2614: if ($env{'form.roletype'} eq 'domain') {
2615: ($role,$uname,$udom) = split(/:/,$user);
1.11 raeburn 2616: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
2617: ($udom eq $env{'request.role.domain'})) {
2618: delete($userlist->{$user});
2619: next;
2620: }
1.13 raeburn 2621: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2622: ($uname,$udom,$role) = split(/:/,$user,-1);
1.102 raeburn 2623: } elsif (($env{'form.roletype'} eq 'course') ||
2624: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 2625: ($uname,$udom,$role) = split(/:/,$user);
2626: }
2627: } else {
2628: ($uname,$udom,$role) = split(/:/,$user,-1);
2629: if (($context eq 'course') && $role eq '') {
2630: $role = 'st';
2631: }
2632: }
2633: $userlist->{$user}->[$index{'role'}] = $role;
2634: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
2635: delete($userlist->{$user});
2636: next;
2637: }
1.33 raeburn 2638: if ($context eq 'course') {
2639: my @ac_groups;
2640: if (ref($classgroups) eq 'HASH') {
2641: $groups = $classgroups->{$user};
2642: }
2643: if (ref($groups->{'active'}) eq 'HASH') {
2644: @ac_groups = keys(%{$groups->{'active'}});
2645: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
2646: }
2647: if ($mode ne 'autoenroll') {
2648: my $section = $userlist->{$user}->[$index{'section'}];
1.43 raeburn 2649: if (($env{'request.course.sec'} ne '') &&
2650: ($section ne $env{'request.course.sec'})) {
2651: if ($role eq 'st') {
2652: delete($userlist->{$user});
2653: next;
2654: }
2655: }
1.33 raeburn 2656: if ($secfilter eq 'none') {
2657: if ($section ne '') {
2658: delete($userlist->{$user});
2659: next;
2660: }
2661: } elsif ($secfilter ne 'all') {
2662: if ($section ne $secfilter) {
2663: delete($userlist->{$user});
2664: next;
2665: }
2666: }
2667: if ($grpfilter eq 'none') {
2668: if (@ac_groups > 0) {
2669: delete($userlist->{$user});
2670: next;
2671: }
2672: } elsif ($grpfilter ne 'all') {
2673: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
2674: delete($userlist->{$user});
2675: next;
2676: }
2677: }
1.44 raeburn 2678: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2679: if (($displayphotos eq 'on') && ($role eq 'st')) {
2680: $userlist->{$user}->[$index{'photo'}] =
1.47 raeburn 2681: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
2682: $userlist->{$user}->[$index{'thumbnail'}] =
1.44 raeburn 2683: &Apache::lonnet::retrievestudentphoto($udom,$uname,
2684: 'gif','thumbnail');
2685: }
2686: }
1.33 raeburn 2687: }
1.2 raeburn 2688: }
2689: my %emails = &Apache::loncommon::getemails($uname,$udom);
2690: if ($emails{'permanentemail'} =~ /\S/) {
2691: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
2692: }
1.4 raeburn 2693: $usercount ++;
2694: }
2695: my $autocount = 0;
2696: my $manualcount = 0;
2697: my $lockcount = 0;
2698: my $unlockcount = 0;
2699: if ($usercount) {
2700: $r->print($output);
2701: } else {
2702: if ($mode eq 'autoenroll') {
2703: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2704: } else {
2705: return;
2706: }
1.1 raeburn 2707: }
1.2 raeburn 2708: #
2709: # Sort the users
1.1 raeburn 2710: my $index = $index{$sortby};
2711: my $second = $index{'username'};
2712: my $third = $index{'domain'};
1.2 raeburn 2713: my @sorted_users = sort {
2714: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
1.1 raeburn 2715: ||
1.2 raeburn 2716: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
2717: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
2718: } (keys(%$userlist));
1.4 raeburn 2719: my $rowcount = 0;
1.2 raeburn 2720: foreach my $user (@sorted_users) {
1.4 raeburn 2721: my %in;
1.2 raeburn 2722: my $sdata = $userlist->{$user};
1.4 raeburn 2723: $rowcount ++;
1.2 raeburn 2724: foreach my $item (@{$keylist}) {
2725: $in{$item} = $sdata->[$index{$item}];
2726: }
1.67 droeschl 2727: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
2728: if ($clickers!~/\w/) { $clickers='-'; }
2729: $in{'clicker'} = $clickers;
2730: my $role = $in{'role'};
1.102 raeburn 2731: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
1.136 raeburn 2732: unless ($mode eq 'excel') {
2733: if (! defined($in{'start'}) || $in{'start'} == 0) {
2734: $in{'start'} = &mt('none');
2735: } else {
2736: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2737: }
2738: if (! defined($in{'end'}) || $in{'end'} == 0) {
2739: $in{'end'} = &mt('none');
2740: } else {
2741: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2742: }
1.1 raeburn 2743: }
1.55 raeburn 2744: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 2745: $r->print(&Apache::loncommon::start_data_table_row());
1.11 raeburn 2746: my $checkval;
1.16 raeburn 2747: if ($mode eq 'autoenroll') {
2748: my $cellentry;
2749: if ($in{'type'} eq 'auto') {
2750: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'" /> Change</label>';
2751: $autocount ++;
2752: } else {
1.76 bisitz 2753: $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 2754: $manualcount ++;
2755: if ($in{'lockedtype'}) {
2756: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Unlock').'</label>';
2757: $unlockcount ++;
2758: } else {
2759: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Lock').'</label>';
2760: $lockcount ++;
1.11 raeburn 2761: }
1.76 bisitz 2762: $cellentry .= '</span></td></tr></table>';
1.16 raeburn 2763: }
2764: $r->print("<td>$cellentry</td>\n");
2765: } else {
1.55 raeburn 2766: if ($mode ne 'pickauthor') {
2767: $r->print("<td>$rowcount</td>\n");
2768: }
1.16 raeburn 2769: if ($actionselect) {
1.26 raeburn 2770: my $showcheckbox;
2771: if ($role =~ /^cr\//) {
2772: $showcheckbox = $canchange{'cr'};
2773: } else {
2774: $showcheckbox = $canchange{$role};
2775: }
2776: if (!$showcheckbox) {
2777: if ($context eq 'course') {
2778: if ($canchangesec{$role} ne '') {
2779: if ($canchangesec{$role} eq $in{'section'}) {
2780: $showcheckbox = 1;
2781: }
2782: }
1.16 raeburn 2783: }
1.26 raeburn 2784: }
2785: if ($showcheckbox) {
2786: $checkval = $user;
2787: if ($context eq 'course') {
2788: if ($role eq 'st') {
2789: $checkval .= ':st';
2790: }
2791: $checkval .= ':'.$in{'section'};
2792: if ($role eq 'st') {
2793: $checkval .= ':'.$in{'type'}.':'.
2794: $in{'lockedtype'};
2795: }
1.16 raeburn 2796: }
1.26 raeburn 2797: $r->print('<td><input type="checkbox" name="'.
1.86 bisitz 2798: 'actionlist" value="'.$checkval.'" /></td>');
1.26 raeburn 2799: } else {
2800: $r->print('<td> </td>');
1.16 raeburn 2801: }
1.55 raeburn 2802: } elsif ($mode eq 'pickauthor') {
2803: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
1.11 raeburn 2804: }
2805: }
1.2 raeburn 2806: foreach my $item (@cols) {
1.10 raeburn 2807: if ($item eq 'username') {
1.48 raeburn 2808: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.16 raeburn 2809: } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) {
1.11 raeburn 2810: $r->print('<td>'.$in{$item}.'<input type="hidden" name="'.$checkval.'_'.$item.'" value="'.$sdata->[$index{$item}].'" /></td>'."\n");
1.83 raeburn 2811: } elsif ($item eq 'status') {
2812: my $showitem = $in{$item};
2813: if (defined($ltstatus{$in{$item}})) {
2814: $showitem = $ltstatus{$in{$item}};
2815: }
2816: $r->print('<td>'.$showitem.'</td>'."\n");
1.10 raeburn 2817: } else {
2818: $r->print('<td>'.$in{$item}.'</td>'."\n");
2819: }
1.2 raeburn 2820: }
1.16 raeburn 2821: if (($context eq 'course') && ($mode ne 'autoenroll')) {
1.4 raeburn 2822: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2823: if ($displayclickers eq 'on') {
2824: my $clickers =
1.2 raeburn 2825: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
1.4 raeburn 2826: if ($clickers!~/\w/) { $clickers='-'; }
2827: $r->print('<td>'.$clickers.'</td>');
1.2 raeburn 2828: } else {
2829: $r->print(' <td> </td> ');
2830: }
1.4 raeburn 2831: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1.44 raeburn 2832: if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {
1.90 bisitz 2833: $r->print(' <td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
1.4 raeburn 2834: } else {
2835: $r->print(' <td> </td> ');
2836: }
2837: }
1.2 raeburn 2838: }
2839: }
2840: $r->print(&Apache::loncommon::end_data_table_row());
2841: } elsif ($mode eq 'csv') {
2842: next if (! defined($CSVfile));
2843: # no need to bother with $linkto
2844: my @line = ();
2845: foreach my $item (@cols) {
2846: push @line,&Apache::loncommon::csv_translate($in{$item});
2847: }
1.67 droeschl 2848: print $CSVfile '"'.join('","',@line)."\"\n";
1.2 raeburn 2849: } elsif ($mode eq 'excel') {
2850: my $col = 0;
2851: foreach my $item (@cols) {
2852: if ($item eq 'start' || $item eq 'end') {
1.136 raeburn 2853: if ((defined($in{$item})) && ($in{$item} != 0)) {
1.2 raeburn 2854: $excel_sheet->write($row,$col++,
1.136 raeburn 2855: &Apache::lonstathelpers::calc_serial($in{$item}),
1.2 raeburn 2856: $format->{'date'});
2857: } else {
2858: $excel_sheet->write($row,$col++,'none');
2859: }
2860: } else {
2861: $excel_sheet->write($row,$col++,$in{$item});
2862: }
2863: }
2864: $row++;
1.1 raeburn 2865: }
2866: }
1.55 raeburn 2867: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 2868: $r->print(&Apache::loncommon::end_data_table().'<br />');
2869: } elsif ($mode eq 'excel') {
2870: $excel_workbook->close();
1.68 droeschl 2871: $r->print(&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<p><a href="'.$excel_filename.'">','</a>')."</p>\n");
1.2 raeburn 2872: } elsif ($mode eq 'csv') {
2873: close($CSVfile);
1.68 droeschl 2874: $r->print(&mt('[_1]Your CSV file[_2] is ready for download.', '<p><a href="'.$CSVfilename.'">','</a>')."</p>\n");
1.2 raeburn 2875: $r->rflush();
2876: }
2877: if ($mode eq 'autoenroll') {
2878: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 2879: } else {
2880: return ($usercount);
1.2 raeburn 2881: }
1.1 raeburn 2882: }
2883:
1.56 raeburn 2884: sub bulkaction_javascript {
2885: my ($formname,$caller) = @_;
2886: my $docstart = 'document';
2887: if ($caller eq 'popup') {
2888: $docstart = 'opener.document';
2889: }
2890: my %lt = &Apache::lonlocal::texthash(
2891: acwi => 'Access will be set to start immediately',
2892: asyo => 'as you did not select an end date in the pop-up window',
2893: accw => 'Access will be set to continue indefinitely',
2894: asyd => 'as you did not select an end date in the pop-up window',
2895: sewi => "Sections will be switched to 'No section'",
2896: ayes => "as you either selected the 'No section' option",
2897: oryo => 'or you did not select a section in the pop-up window',
2898: arol => 'A role with no section will be added',
2899: swbs => 'Sections will be switched to:',
2900: rwba => 'Roles will be added for section(s):',
2901: );
2902: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
2903: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
2904: my $singconfirm = &mt(' for a single user?');
2905: my $multconfirm = &mt(' for multiple users?');
2906: my $output = <<"ENDJS";
2907: function verify_action (field) {
2908: var numchecked = 0;
2909: var singconf = '$singconfirm';
2910: var multconf = '$multconfirm';
2911: if ($docstart.$formname.elements[field].length > 0) {
2912: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
2913: if ($docstart.$formname.elements[field][i].checked == true) {
2914: numchecked ++;
2915: }
2916: }
2917: } else {
2918: if ($docstart.$formname.elements[field].checked == true) {
2919: numchecked ++;
2920: }
2921: }
2922: if (numchecked == 0) {
2923: alert("$alert");
2924: return;
2925: } else {
2926: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
2927: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
2928: if (choice == '') {
2929: alert("$noaction");
2930: return;
2931: } else {
2932: if (numchecked == 1) {
2933: message += singconf;
2934: } else {
2935: message += multconf;
2936: }
2937: ENDJS
2938: if ($caller ne 'popup') {
2939: $output .= <<"NEWWIN";
2940: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
2941: opendatebrowser(document.$formname,'$formname','go');
2942: return;
2943:
2944: } else {
2945: if (confirm(message)) {
2946: document.$formname.phase.value = 'bulkchange';
2947: document.$formname.submit();
2948: return;
2949: }
2950: }
2951: NEWWIN
2952: } else {
2953: $output .= <<"POPUP";
2954: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
2955: var datemsg = '';
2956: if (($docstart.$formname.startdate_month.value == '') &&
2957: ($docstart.$formname.startdate_day.value == '') &&
2958: ($docstart.$formname.startdate_year.value == '')) {
2959: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
2960: }
2961: if (($docstart.$formname.enddate_month.value == '') &&
2962: ($docstart.$formname.enddate_day.value == '') &&
2963: ($docstart.$formname.enddate_year.value == '')) {
2964: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
2965: }
2966: if (datemsg != '') {
2967: message += "\\n"+datemsg;
2968: }
2969: }
2970: if (choice == 'chgsec') {
2971: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
2972: var retained = $docstart.$formname.retainsec.value;
2973: var secshow = $docstart.$formname.newsecs.value;
2974: if (secshow == '') {
2975: if (rolefilter == 'st' || retained == 0 || retained == "") {
2976: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
2977: } else {
2978: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
2979: }
2980: } else {
2981: if (rolefilter == 'st' || retained == 0 || retained == "") {
2982: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
2983: } else {
2984: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
2985: }
2986: }
2987: }
2988: if (confirm(message)) {
2989: $docstart.$formname.phase.value = 'bulkchange';
2990: $docstart.$formname.submit();
2991: window.close();
2992: }
2993: POPUP
2994: }
2995: $output .= '
2996: }
2997: }
2998: }
2999: ';
3000: return $output;
3001: }
3002:
1.10 raeburn 3003: sub print_username_link {
1.48 raeburn 3004: my ($mode,$in) = @_;
1.10 raeburn 3005: my $output;
1.16 raeburn 3006: if ($mode eq 'autoenroll') {
3007: $output = $in->{'username'};
1.10 raeburn 3008: } else {
3009: $output = '<a href="javascript:username_display_launch('.
1.112 bisitz 3010: "'$in->{'username'}','$in->{'domain'}'".')">'.
1.10 raeburn 3011: $in->{'username'}.'</a>';
3012: }
3013: return $output;
3014: }
3015:
1.2 raeburn 3016: sub role_type_names {
3017: my %lt = &Apache::lonlocal::texthash (
1.13 raeburn 3018: 'domain' => 'Domain Roles',
3019: 'author' => 'Co-Author Roles',
3020: 'course' => 'Course Roles',
1.101 raeburn 3021: 'community' => 'Community Roles',
1.2 raeburn 3022: );
3023: return %lt;
3024: }
3025:
1.11 raeburn 3026: sub select_actions {
1.55 raeburn 3027: my ($context,$setting,$statusmode,$formname) = @_;
1.11 raeburn 3028: my %lt = &Apache::lonlocal::texthash(
3029: revoke => "Revoke user roles",
3030: delete => "Delete user roles",
3031: reenable => "Re-enable expired user roles",
3032: activate => "Make future user roles active now",
3033: chgdates => "Change starting/ending dates",
3034: chgsec => "Change section associated with user roles",
3035: );
3036: my ($output,$options,%choices);
1.23 raeburn 3037: # FIXME Disable actions for now for roletype=course in domain context
3038: if ($context eq 'domain' && $setting eq 'course') {
3039: return;
3040: }
1.26 raeburn 3041: if ($context eq 'course') {
3042: if ($env{'form.showrole'} ne 'Any') {
3043: if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},
3044: $env{'request.course.id'})) {
3045: if ($env{'request.course.sec'} eq '') {
3046: return;
3047: } else {
3048: if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3049: return;
3050: }
3051: }
3052: }
3053: }
3054: }
1.11 raeburn 3055: if ($statusmode eq 'Any') {
3056: $options .= '
3057: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
3058: $choices{'dates'} = 1;
3059: } else {
3060: if ($statusmode eq 'Future') {
3061: $options .= '
3062: <option value="activate">'.$lt{'activate'}.'</option>';
3063: $choices{'dates'} = 1;
3064: } elsif ($statusmode eq 'Expired') {
3065: $options .= '
3066: <option value="reenable">'.$lt{'reenable'}.'</option>';
3067: $choices{'dates'} = 1;
3068: }
1.13 raeburn 3069: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
3070: $options .= '
3071: <option value="chgdates">'.$lt{'chgdates'}.'</option>
3072: <option value="revoke">'.$lt{'revoke'}.'</option>';
3073: $choices{'dates'} = 1;
3074: }
1.11 raeburn 3075: }
3076: if ($context eq 'domain') {
3077: $options .= '
3078: <option value="delete">'.$lt{'delete'}.'</option>';
3079: }
3080: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26 raeburn 3081: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11 raeburn 3082: $options .= '
3083: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
3084: $choices{'sections'} = 1;
3085: }
3086: }
3087: if ($options) {
1.56 raeburn 3088: $output = '<select name="bulkaction">'."\n".
1.11 raeburn 3089: '<option value="" selected="selected">'.
3090: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
3091: if ($choices{'dates'}) {
3092: $output .=
3093: '<input type="hidden" name="startdate_month" value="" />'."\n".
3094: '<input type="hidden" name="startdate_day" value="" />'."\n".
3095: '<input type="hidden" name="startdate_year" value="" />'."\n".
3096: '<input type="hidden" name="startdate_hour" value="" />'."\n".
3097: '<input type="hidden" name="startdate_minute" value="" />'."\n".
3098: '<input type="hidden" name="startdate_second" value="" />'."\n".
3099: '<input type="hidden" name="enddate_month" value="" />'."\n".
3100: '<input type="hidden" name="enddate_day" value="" />'."\n".
3101: '<input type="hidden" name="enddate_year" value="" />'."\n".
3102: '<input type="hidden" name="enddate_hour" value="" />'."\n".
3103: '<input type="hidden" name="enddate_minute" value="" />'."\n".
1.56 raeburn 3104: '<input type="hidden" name="enddate_second" value="" />'."\n".
3105: '<input type="hidden" name="no_end_date" value="" />'."\n";
1.11 raeburn 3106: if ($context eq 'course') {
3107: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
3108: }
3109: }
3110: if ($choices{'sections'}) {
1.91 bisitz 3111: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
3112: '<input type="hidden" name="newsecs" value="" />'."\n";
1.11 raeburn 3113: }
3114: }
3115: return $output;
3116: }
3117:
3118: sub date_section_javascript {
3119: my ($context,$setting) = @_;
1.49 raeburn 3120: my $title = 'Date_And_Section_Selector';
1.41 raeburn 3121: my %nopopup = &Apache::lonlocal::texthash (
3122: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
3123: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
3124: none => "Choose an action to take for selected users",
3125: );
1.96 bisitz 3126: my $output = <<"ENDONE";
3127: <script type="text/javascript">
3128: // <![CDATA[
1.41 raeburn 3129: function opendatebrowser(callingform,formname,calledby) {
1.11 raeburn 3130: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
3131: var url = '/adm/createuser?';
3132: var type = '';
3133: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
3134: ENDONE
3135: if ($context eq 'domain') {
3136: $output .= '
3137: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
3138: ';
3139: }
3140: my $width= '700';
3141: my $height = '400';
3142: $output .= <<"ENDTWO";
3143: url += 'action=dateselect&callingform=' + formname +
3144: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
3145: var title = '$title';
3146: var options = 'scrollbars=1,resizable=1,menubar=0';
3147: options += ',width=$width,height=$height';
3148: stdeditbrowser = open(url,title,options,'1');
3149: stdeditbrowser.focus();
3150: }
1.96 bisitz 3151: // ]]>
1.11 raeburn 3152: </script>
3153: ENDTWO
3154: return $output;
3155: }
3156:
3157: sub date_section_selector {
1.101 raeburn 3158: my ($context,$permission,$crstype) = @_;
1.11 raeburn 3159: my $callingform = $env{'form.callingform'};
3160: my $formname = 'dateselect';
3161: my $groupslist = &get_groupslist();
3162: my $sec_js = &setsections_javascript($formname,$groupslist);
3163: my $output = <<"END";
3164: <script type="text/javascript">
1.96 bisitz 3165: // <![CDATA[
1.11 raeburn 3166:
3167: $sec_js
3168:
3169: function saveselections(formname) {
3170:
3171: END
3172: if ($env{'form.bulkaction'} eq 'chgsec') {
3173: $output .= <<"END";
1.40 raeburn 3174: if (formname.retainsec.length > 1) {
3175: for (var i=0; i<formname.retainsec.length; i++) {
3176: if (formname.retainsec[i].checked == true) {
3177: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
3178: }
3179: }
3180: } else {
3181: opener.document.$callingform.retainsec.value = formname.retainsec.value;
3182: }
1.103 raeburn 3183: setSections(formname,'$crstype');
1.11 raeburn 3184: if (seccheck == 'ok') {
3185: opener.document.$callingform.newsecs.value = formname.sections.value;
3186: }
3187: END
3188: } else {
3189: if ($context eq 'course') {
3190: if (($env{'form.bulkaction'} eq 'reenable') ||
3191: ($env{'form.bulkaction'} eq 'activate') ||
3192: ($env{'form.bulkaction'} eq 'chgdates')) {
1.26 raeburn 3193: if ($env{'request.course.sec'} eq '') {
3194: $output .= <<"END";
1.11 raeburn 3195:
3196: if (formname.makedatesdefault.checked == true) {
3197: opener.document.$callingform.makedatesdefault.value = 1;
3198: }
3199: else {
3200: opener.document.$callingform.makedatesdefault.value = 0;
3201: }
3202:
3203: END
1.26 raeburn 3204: }
1.11 raeburn 3205: }
3206: }
3207: $output .= <<"END";
3208: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
3209: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
3210: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
3211: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
3212: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
3213: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
3214: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
3215: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
3216: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
3217: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
3218: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
3219: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
1.56 raeburn 3220: if (formname.no_end_date.checked) {
3221: opener.document.$callingform.no_end_date.value = '1';
3222: } else {
3223: opener.document.$callingform.no_end_date.value = '0';
3224: }
1.11 raeburn 3225: END
3226: }
1.56 raeburn 3227: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
3228: $output .= <<"ENDJS";
3229: verify_action('actionlist');
1.11 raeburn 3230: }
1.56 raeburn 3231:
3232: $verify_action_js
3233:
1.96 bisitz 3234: // ]]>
1.11 raeburn 3235: </script>
1.56 raeburn 3236: ENDJS
1.11 raeburn 3237: my %lt = &Apache::lonlocal::texthash (
3238: chac => 'Access dates to apply for selected users',
3239: chse => 'Changes in section affiliation to apply to selected users',
1.118 raeburn 3240: 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.',
3241: forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
3242: reta => "Retain each user's current section affiliations?",
1.103 raeburn 3243: dnap => '(Does not apply to student roles).',
1.11 raeburn 3244: );
3245: my ($date_items,$headertext);
3246: if ($env{'form.bulkaction'} eq 'chgsec') {
3247: $headertext = $lt{'chse'};
3248: } else {
3249: $headertext = $lt{'chac'};
3250: my $starttime;
3251: if (($env{'form.bulkaction'} eq 'activate') ||
3252: ($env{'form.bulkaction'} eq 'reenable')) {
3253: $starttime = time;
3254: }
3255: $date_items = &date_setting_table($starttime,undef,$context,
1.21 raeburn 3256: $env{'form.bulkaction'},$formname,
1.101 raeburn 3257: $permission,$crstype);
1.11 raeburn 3258: }
3259: $output .= '<h3>'.$headertext.'</h3>'.
1.118 raeburn 3260: '<form name="'.$formname.'" method="post" action="">'."\n".
1.11 raeburn 3261: $date_items;
3262: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17 raeburn 3263: my ($cnum,$cdom) = &get_course_identity();
1.103 raeburn 3264: if ($crstype eq 'Community') {
1.118 raeburn 3265: $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.');
3266: $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 3267: $lt{'dnap'} = &mt('(Does not apply to member roles).');
3268: }
1.11 raeburn 3269: my $info;
3270: if ($env{'form.showrole'} eq 'st') {
3271: $output .= '<p>'.$lt{'fors'}.'</p>';
1.26 raeburn 3272: } elsif ($env{'form.showrole'} eq 'Any') {
1.11 raeburn 3273: $output .= '<p>'.$lt{'fors'}.'</p>'.
3274: '<p>'.$lt{'forn'}.' ';
3275: $info = $lt{'reta'};
3276: } else {
3277: $output .= '<p>'.$lt{'forn'}.' ';
3278: $info = $lt{'reta'};
3279: }
3280: if ($info) {
3281: $info .= '<span class="LC_nobreak">'.
3282: '<label><input type="radio" name="retainsec" value="1" '.
3283: 'checked="checked" />'.&mt('Yes').'</label> '.
3284: '<label><input type="radio" name="retainsec" value="0" />'.
3285: &mt('No').'</label></span>';
3286: if ($env{'form.showrole'} eq 'Any') {
3287: $info .= '<br />'.$lt{'dnap'};
3288: }
3289: $info .= '</p>';
3290: } else {
3291: $info = '<input type="hidden" name="retainsec" value="0" />';
3292: }
1.21 raeburn 3293: my $rowtitle = &mt('New section to assign');
1.101 raeburn 3294: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context,'',$crstype);
1.11 raeburn 3295: $output .= $info.$secbox;
3296: }
3297: $output .= '<p>'.
1.81 schafran 3298: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
1.11 raeburn 3299: '</form>';
3300: return $output;
3301: }
3302:
1.17 raeburn 3303: sub section_picker {
1.101 raeburn 3304: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype) = @_;
1.17 raeburn 3305: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3306: my $sections_select .= &course_sections(\%sections_count,$role);
1.118 raeburn 3307: my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
1.17 raeburn 3308: if ($mode eq 'upload') {
3309: my ($options,$cb_script,$coursepick) =
1.101 raeburn 3310: &default_role_selector($context,1,$crstype);
1.59 bisitz 3311: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
1.17 raeburn 3312: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
3313: }
3314: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
3315: if ($env{'request.course.sec'} eq '') {
3316: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
3317: '<td align="center">'.&mt('Existing sections')."\n".
3318: '<br />'.$sections_select.'</td><td align="center">'.
3319: &mt('New section').'<br />'."\n".
1.118 raeburn 3320: '<input type="text" name="newsec" size="15" value="" />'."\n".
1.17 raeburn 3321: '<input type="hidden" name="sections" value="" />'."\n".
3322: '</td></tr></table>'."\n";
3323: } else {
3324: $secbox .= '<input type="hidden" name="sections" value="'.
3325: $env{'request.course.sec'}.'" />'.
3326: $env{'request.course.sec'};
3327: }
3328: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n".
1.118 raeburn 3329: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.17 raeburn 3330: return $secbox;
3331: }
3332:
1.2 raeburn 3333: sub results_header_row {
1.102 raeburn 3334: my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
1.5 raeburn 3335: my ($description,$showfilter);
3336: if ($rolefilter ne 'Any') {
3337: $showfilter = $rolefilter;
3338: }
1.2 raeburn 3339: if ($context eq 'course') {
1.24 raeburn 3340: if ($mode eq 'csv' || $mode eq 'excel') {
1.102 raeburn 3341: if ($crstype eq 'Community') {
3342: $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
3343: } else {
3344: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
3345: }
1.24 raeburn 3346: }
1.2 raeburn 3347: if ($statusmode eq 'Expired') {
1.102 raeburn 3348: if ($crstype eq 'Community') {
3349: $description .= &mt('Users in community with expired [_1] roles',$showfilter);
3350: } else {
3351: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
3352: }
1.11 raeburn 3353: } elsif ($statusmode eq 'Future') {
1.102 raeburn 3354: if ($crstype eq 'Community') {
3355: $description .= &mt('Users in community with future [_1] roles',$showfilter);
3356: } else {
3357: $description .= &mt('Users in course with future [_1] roles',$showfilter);
3358: }
1.2 raeburn 3359: } elsif ($statusmode eq 'Active') {
1.102 raeburn 3360: if ($crstype eq 'Community') {
3361: $description .= &mt('Users in community with active [_1] roles',$showfilter);
3362: } else {
3363: $description .= &mt('Users in course with active [_1] roles',$showfilter);
3364: }
1.2 raeburn 3365: } else {
3366: if ($rolefilter eq 'Any') {
1.102 raeburn 3367: if ($crstype eq 'Community') {
3368: $description .= &mt('All users in community');
3369: } else {
3370: $description .= &mt('All users in course');
3371: }
1.2 raeburn 3372: } else {
1.102 raeburn 3373: if ($crstype eq 'Community') {
3374: $description .= &mt('All users in community with [_1] roles',$rolefilter);
3375: } else {
3376: $description .= &mt('All users in course with [_1] roles',$rolefilter);
3377: }
1.2 raeburn 3378: }
3379: }
1.33 raeburn 3380: my $constraint;
1.26 raeburn 3381: my $viewablesec = &viewable_section($permission);
3382: if ($viewablesec ne '') {
1.15 raeburn 3383: if ($env{'form.showrole'} eq 'st') {
1.33 raeburn 3384: $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.103 raeburn 3385: } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
1.33 raeburn 3386: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
3387: }
3388: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
3389: if ($env{'form.grpfilter'} eq 'none') {
3390: $constraint .= &mt(' and not in any group');
3391: } else {
3392: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
3393: }
3394: }
3395: } else {
3396: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
3397: if ($env{'form.secfilter'} eq 'none') {
3398: $constraint = &mt('only users affiliated with no section');
3399: } else {
3400: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
3401: }
3402: }
3403: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
3404: if ($env{'form.grpfilter'} eq 'none') {
3405: if ($constraint eq '') {
3406: $constraint = &mt('only users not in any group');
3407: } else {
3408: $constraint .= &mt(' and also not in any group');
3409: }
3410: } else {
3411: if ($constraint eq '') {
3412: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
3413: } else {
3414: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
3415: }
3416: }
1.15 raeburn 3417: }
3418: }
1.33 raeburn 3419: if ($constraint ne '') {
3420: $description .= ' ('.$constraint.')';
3421: }
1.13 raeburn 3422: } elsif ($context eq 'author') {
1.14 raeburn 3423: $description =
1.73 bisitz 3424: &mt('Author space for [_1]'
3425: ,'<span class="LC_cusr_emph">'
3426: .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})
3427: .'</span>')
3428: .': ';
1.2 raeburn 3429: if ($statusmode eq 'Expired') {
1.5 raeburn 3430: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 3431: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3432: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 3433: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3434: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 3435: } else {
3436: if ($rolefilter eq 'Any') {
1.5 raeburn 3437: $description .= &mt('All co-authors');
1.2 raeburn 3438: } else {
3439: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
3440: }
3441: }
3442: } elsif ($context eq 'domain') {
3443: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.73 bisitz 3444: $description = &mt('Domain - [_1]:',$domdesc).' ';
1.2 raeburn 3445: if ($env{'form.roletype'} eq 'domain') {
3446: if ($statusmode eq 'Expired') {
1.5 raeburn 3447: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 3448: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3449: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 3450: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3451: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 3452: } else {
3453: if ($rolefilter eq 'Any') {
1.5 raeburn 3454: $description .= &mt('All users in domain');
1.2 raeburn 3455: } else {
3456: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
3457: }
3458: }
1.13 raeburn 3459: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3460: if ($statusmode eq 'Expired') {
1.5 raeburn 3461: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 3462: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3463: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 3464: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3465: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 3466: } else {
3467: if ($rolefilter eq 'Any') {
1.5 raeburn 3468: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 3469: } else {
1.116 bisitz 3470: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
1.2 raeburn 3471: }
3472: }
1.102 raeburn 3473: } elsif (($env{'form.roletype'} eq 'course') ||
3474: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 3475: my $coursefilter = $env{'form.coursepick'};
1.102 raeburn 3476: if ($env{'form.roletype'} eq 'course') {
3477: if ($coursefilter eq 'category') {
3478: my $instcode = &instcode_from_coursefilter();
3479: if ($instcode eq '.') {
3480: $description .= &mt('All courses in domain').' - ';
3481: } else {
3482: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
3483: }
3484: } elsif ($coursefilter eq 'selected') {
3485: $description .= &mt('Selected courses in domain').' - ';
3486: } elsif ($coursefilter eq 'all') {
1.2 raeburn 3487: $description .= &mt('All courses in domain').' - ';
3488: }
1.102 raeburn 3489: } elsif ($env{'form.roletype'} eq 'community') {
3490: if ($coursefilter eq 'selected') {
3491: $description .= &mt('Selected communities in domain').' - ';
3492: } elsif ($coursefilter eq 'all') {
3493: $description .= &mt('All communities in domain').' - ';
3494: }
1.2 raeburn 3495: }
3496: if ($statusmode eq 'Expired') {
1.5 raeburn 3497: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 3498: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3499: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 3500: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3501: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 3502: } else {
3503: if ($rolefilter eq 'Any') {
3504: $description .= &mt('all users');
3505: } else {
3506: $description .= &mt('users with [_1] roles',$rolefilter);
3507: }
3508: }
3509: }
3510: }
3511: return $description;
3512: }
1.22 raeburn 3513:
3514: sub viewable_section {
3515: my ($permission) = @_;
3516: my $viewablesec;
3517: if (ref($permission) eq 'HASH') {
3518: if (exists($permission->{'view_section'})) {
3519: $viewablesec = $permission->{'view_section'};
3520: } elsif (exists($permission->{'cusr_section'})) {
3521: $viewablesec = $permission->{'cusr_section'};
3522: }
3523: }
3524: return $viewablesec;
3525: }
3526:
1.2 raeburn 3527:
1.1 raeburn 3528: #################################################
3529: #################################################
3530: sub show_drop_list {
1.101 raeburn 3531: my ($r,$classlist,$nosort,$permission,$crstype) = @_;
1.29 raeburn 3532: my $cid = $env{'request.course.id'};
1.17 raeburn 3533: my ($cnum,$cdom) = &get_course_identity($cid);
1.1 raeburn 3534: if (! exists($env{'form.sortby'})) {
3535: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3536: ['sortby']);
3537: }
3538: my $sortby = $env{'form.sortby'};
3539: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
3540: $sortby = 'username';
3541: }
3542: my $action = "drop";
1.17 raeburn 3543: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1 raeburn 3544: $r->print(<<END);
3545: <input type="hidden" name="sortby" value="$sortby" />
3546: <input type="hidden" name="action" value="$action" />
3547: <input type="hidden" name="state" value="done" />
1.17 raeburn 3548: <script type="text/javascript" language="Javascript">
1.96 bisitz 3549: // <![CDATA[
1.17 raeburn 3550: $check_uncheck_js
1.96 bisitz 3551: // ]]>
1.1 raeburn 3552: </script>
3553: <p>
1.86 bisitz 3554: <input type="hidden" name="phase" value="four" />
1.1 raeburn 3555: END
1.30 raeburn 3556: my ($indexhash,$keylist) = &make_keylist_array();
3557: my $studentcount = 0;
3558: if (ref($classlist) eq 'HASH') {
3559: foreach my $student (keys(%{$classlist})) {
3560: my $sdata = $classlist->{$student};
3561: my $status = $sdata->[$indexhash->{'status'}];
3562: my $section = $sdata->[$indexhash->{'section'}];
3563: if ($status ne 'Active') {
3564: delete($classlist->{$student});
3565: next;
3566: }
3567: if ($env{'request.course.sec'} ne '') {
3568: if ($section ne $env{'request.course.sec'}) {
3569: delete($classlist->{$student});
3570: next;
3571: }
3572: }
3573: $studentcount ++;
3574: }
3575: }
3576: if (!$studentcount) {
1.101 raeburn 3577: if ($crstype eq 'Community') {
3578: $r->print(&mt('There are no members to drop.'));
3579: } else {
3580: $r->print(&mt('There are no students to drop.'));
3581: }
1.30 raeburn 3582: return;
3583: }
3584: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3585: $classlist,$keylist,$cdom,$cnum);
3586: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
3587: 'dom' => "domain",
3588: 'sn' => "student name",
1.101 raeburn 3589: 'mn' => "member name",
1.30 raeburn 3590: 'sec' => "section",
3591: 'start' => "start date",
3592: 'end' => "end date",
3593: 'groups' => "active groups",
3594: );
1.101 raeburn 3595: my $nametitle = $lt{'sn'};
3596: if ($crstype eq 'Community') {
3597: $nametitle = $lt{'mn'};
3598: }
1.1 raeburn 3599: if ($nosort) {
1.17 raeburn 3600: $r->print(&Apache::loncommon::start_data_table().
3601: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 3602: $r->print(<<END);
3603: <th> </th>
3604: <th>$lt{'usrn'}</th>
3605: <th>$lt{'dom'}</th>
3606: <th>ID</th>
1.101 raeburn 3607: <th>$nametitle</th>
1.1 raeburn 3608: <th>$lt{'sec'}</th>
3609: <th>$lt{'start'}</th>
3610: <th>$lt{'end'}</th>
3611: <th>$lt{'groups'}</th>
3612: END
1.17 raeburn 3613: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 3614: } else {
1.17 raeburn 3615: $r->print(&Apache::loncommon::start_data_table().
3616: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 3617: $r->print(<<END);
1.17 raeburn 3618: <th> </th>
1.1 raeburn 3619: <th>
1.17 raeburn 3620: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1 raeburn 3621: </th><th>
1.17 raeburn 3622: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1 raeburn 3623: </th><th>
1.17 raeburn 3624: <a href="/adm/createuser?action=$action&sortby=id">ID</a>
1.1 raeburn 3625: </th><th>
1.101 raeburn 3626: <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
1.1 raeburn 3627: </th><th>
1.17 raeburn 3628: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1 raeburn 3629: </th><th>
1.17 raeburn 3630: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1 raeburn 3631: </th><th>
1.17 raeburn 3632: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1 raeburn 3633: </th><th>
1.17 raeburn 3634: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1 raeburn 3635: </th>
3636: END
1.17 raeburn 3637: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 3638: }
3639: #
3640: # Sort the students
1.30 raeburn 3641: my $index = $indexhash->{$sortby};
3642: my $second = $indexhash->{'username'};
3643: my $third = $indexhash->{'domain'};
1.1 raeburn 3644: my @Sorted_Students = sort {
3645: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
3646: ||
3647: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
3648: ||
3649: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30 raeburn 3650: } (keys(%{$classlist}));
1.1 raeburn 3651: foreach my $student (@Sorted_Students) {
3652: my $error;
3653: my $sdata = $classlist->{$student};
1.30 raeburn 3654: my $username = $sdata->[$indexhash->{'username'}];
3655: my $domain = $sdata->[$indexhash->{'domain'}];
3656: my $section = $sdata->[$indexhash->{'section'}];
3657: my $name = $sdata->[$indexhash->{'fullname'}];
3658: my $id = $sdata->[$indexhash->{'id'}];
3659: my $start = $sdata->[$indexhash->{'start'}];
3660: my $end = $sdata->[$indexhash->{'end'}];
1.1 raeburn 3661: my $groups = $classgroups->{$student};
3662: my $active_groups;
3663: if (ref($groups->{active}) eq 'HASH') {
3664: $active_groups = join(', ',keys(%{$groups->{'active'}}));
3665: }
3666: if (! defined($start) || $start == 0) {
3667: $start = &mt('none');
3668: } else {
3669: $start = &Apache::lonlocal::locallocaltime($start);
3670: }
3671: if (! defined($end) || $end == 0) {
3672: $end = &mt('none');
3673: } else {
3674: $end = &Apache::lonlocal::locallocaltime($end);
3675: }
1.17 raeburn 3676: my $studentkey = $student.':'.$section;
1.30 raeburn 3677: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1 raeburn 3678: #
3679: $r->print(&Apache::loncommon::start_data_table_row());
3680: $r->print(<<"END");
1.86 bisitz 3681: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
1.1 raeburn 3682: <td>$username</td>
3683: <td>$domain</td>
3684: <td>$id</td>
3685: <td>$name</td>
3686: <td>$section</td>
1.29 raeburn 3687: <td>$start $startitem</td>
1.1 raeburn 3688: <td>$end</td>
3689: <td>$active_groups</td>
3690: END
3691: $r->print(&Apache::loncommon::end_data_table_row());
3692: }
3693: $r->print(&Apache::loncommon::end_data_table().'<br />');
3694: %lt=&Apache::lonlocal::texthash(
1.29 raeburn 3695: 'dp' => "Drop Students",
1.101 raeburn 3696: 'dm' => "Drop Members",
1.1 raeburn 3697: 'ca' => "check all",
3698: 'ua' => "uncheck all",
3699: );
1.101 raeburn 3700: my $btn = $lt{'dp'};
3701: if ($crstype eq 'Community') {
3702: $btn = $lt{'dm'};
3703: }
1.1 raeburn 3704: $r->print(<<"END");
1.89 bisitz 3705: </p>
3706: <p>
1.86 bisitz 3707: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
3708: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
1.89 bisitz 3709: </p>
3710: <p>
1.101 raeburn 3711: <input type="submit" value="$btn" />
1.89 bisitz 3712: </p>
1.1 raeburn 3713: END
3714: return;
3715: }
3716:
3717: #
3718: # Print out the initial form to get the file containing a list of users
3719: #
3720: sub print_first_users_upload_form {
3721: my ($r,$context) = @_;
3722: my $str;
1.86 bisitz 3723: $str = '<input type="hidden" name="phase" value="two" />';
1.1 raeburn 3724: $str .= '<input type="hidden" name="action" value="upload" />';
1.101 raeburn 3725: $str .= '<input type="hidden" name="state" value="got_file" />';
1.95 bisitz 3726:
1.85 bisitz 3727: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
1.95 bisitz 3728:
3729: # Excel and CSV Help
1.107 raeburn 3730: $str .= '<div class="LC_left_float">'
1.95 bisitz 3731: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
3732: &mt("How do I create a users list from a spreadsheet"))
1.107 raeburn 3733: .'</div><div class="LC_left_float">'."\n"
1.95 bisitz 3734: .&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3735: &mt("How do I create a CSV file from a spreadsheet"))
1.107 raeburn 3736: .'</div><br clear="all" />'."\n";
1.95 bisitz 3737: $str .= &Apache::lonhtmlcommon::start_pick_box()
1.103 raeburn 3738: .&Apache::lonhtmlcommon::row_title(&mt('File'));
3739: if (&Apache::lonlocal::current_language() ne 'en') {
3740: if ($context eq 'course') {
3741: $str .= '<p class="LC_info">'."\n"
3742: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
3743: .'</p>'."\n";
3744: }
3745: }
3746: $str .= &Apache::loncommon::upfile_select_html()
1.95 bisitz 3747: .&Apache::lonhtmlcommon::row_closure()
3748: .&Apache::lonhtmlcommon::row_title(
3749: '<label for="noFirstLine">'
3750: .&mt('Ignore First Line')
3751: .'</label>')
3752: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
3753: .&Apache::lonhtmlcommon::row_closure(1)
3754: .&Apache::lonhtmlcommon::end_pick_box();
3755:
3756: $str .= '<p>'
3757: .'<input type="submit" name="fileupload" value="'.&mt('Next').'" />'
3758: .'</p>';
3759:
1.1 raeburn 3760: $r->print($str);
3761: return;
3762: }
3763:
3764: # ================================================= Drop/Add from uploaded file
3765: sub upfile_drop_add {
1.21 raeburn 3766: my ($r,$context,$permission) = @_;
1.1 raeburn 3767: &Apache::loncommon::load_tmp_file($r);
3768: my @userdata=&Apache::loncommon::upfile_record_sep();
3769: if($env{'form.noFirstLine'}){shift(@userdata);}
3770: my @keyfields = split(/\,/,$env{'form.keyfields'});
3771: my %fields=();
3772: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3773: if ($env{'form.upfile_associate'} eq 'reverse') {
3774: if ($env{'form.f'.$i} ne 'none') {
3775: $fields{$keyfields[$i]}=$env{'form.f'.$i};
3776: }
3777: } else {
3778: $fields{$env{'form.f'.$i}}=$keyfields[$i];
3779: }
3780: }
1.29 raeburn 3781: if ($env{'form.fullup'} ne 'yes') {
3782: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
3783: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
3784: }
1.1 raeburn 3785: #
3786: # Store the field choices away
3787: foreach my $field (qw/username names
1.57 raeburn 3788: fname mname lname gen id sec ipwd email role domain/) {
1.1 raeburn 3789: $env{'form.'.$field.'_choice'}=$fields{$field};
3790: }
3791: &Apache::loncommon::store_course_settings('enrollment_upload',
3792: { 'username_choice' => 'scalar',
3793: 'names_choice' => 'scalar',
3794: 'fname_choice' => 'scalar',
3795: 'mname_choice' => 'scalar',
3796: 'lname_choice' => 'scalar',
3797: 'gen_choice' => 'scalar',
3798: 'id_choice' => 'scalar',
3799: 'sec_choice' => 'scalar',
3800: 'ipwd_choice' => 'scalar',
3801: 'email_choice' => 'scalar',
1.57 raeburn 3802: 'role_choice' => 'scalar',
1.84 raeburn 3803: 'domain_choice' => 'scalar',
3804: 'inststatus_choice' => 'scalar'});
1.1 raeburn 3805: #
1.101 raeburn 3806: my ($cid,$crstype,$setting);
3807: if ($context eq 'domain') {
3808: $setting = $env{'form.roleaction'};
3809: }
3810: if ($env{'request.course.id'} ne '') {
3811: $cid = $env{'request.course.id'};
3812: $crstype = &Apache::loncommon::course_type();
3813: } elsif ($setting eq 'course') {
3814: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
3815: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
3816: $crstype = &Apache::loncommon::course_type($cid);
3817: }
3818: }
1.1 raeburn 3819: my ($startdate,$enddate) = &get_dates_from_form();
3820: if ($env{'form.makedatesdefault'}) {
1.101 raeburn 3821: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 3822: }
3823: # Determine domain and desired host (home server)
1.57 raeburn 3824: my $defdom=$env{'request.role.domain'};
3825: my $domain;
3826: if ($env{'form.defaultdomain'} ne '') {
3827: $domain = $env{'form.defaultdomain'};
3828: } else {
3829: $domain = $defdom;
3830: }
1.1 raeburn 3831: my $desiredhost = $env{'form.lcserver'};
3832: if (lc($desiredhost) eq 'default') {
3833: $desiredhost = undef;
3834: } else {
1.57 raeburn 3835: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1 raeburn 3836: if (! exists($home_servers{$desiredhost})) {
3837: $r->print('<span class="LC_error">'.&mt('Error').
3838: &mt('Invalid home server specified').'</span>');
3839: $r->print(&Apache::loncommon::end_page());
3840: return;
3841: }
3842: }
3843: # Determine authentication mechanism
3844: my $changeauth;
3845: if ($context eq 'domain') {
3846: $changeauth = $env{'form.changeauth'};
3847: }
3848: my $amode = '';
3849: my $genpwd = '';
3850: if ($env{'form.login'} eq 'krb') {
3851: $amode='krb';
3852: $amode.=$env{'form.krbver'};
3853: $genpwd=$env{'form.krbarg'};
3854: } elsif ($env{'form.login'} eq 'int') {
3855: $amode='internal';
3856: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
3857: $genpwd=$env{'form.intarg'};
3858: }
3859: } elsif ($env{'form.login'} eq 'loc') {
3860: $amode='localauth';
3861: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
3862: $genpwd=$env{'form.locarg'};
3863: }
3864: }
3865: if ($amode =~ /^krb/) {
3866: if (! defined($genpwd) || $genpwd eq '') {
3867: $r->print('<span class="Error">'.
3868: &mt('Unable to enroll users').' '.
3869: &mt('No Kerberos domain was specified.').'</span></p>');
3870: $amode = ''; # This causes the loop below to be skipped
3871: }
3872: }
1.101 raeburn 3873: my ($defaultsec,$defaultrole);
1.1 raeburn 3874: if ($context eq 'domain') {
3875: if ($setting eq 'domain') {
3876: $defaultrole = $env{'form.defaultrole'};
3877: } elsif ($setting eq 'course') {
3878: $defaultrole = $env{'form.courserole'};
1.27 raeburn 3879: $defaultsec = $env{'form.sections'};
1.1 raeburn 3880: }
1.13 raeburn 3881: } elsif ($context eq 'author') {
1.1 raeburn 3882: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 3883: } elsif ($context eq 'course') {
3884: $defaultrole = $env{'form.defaultrole'};
3885: $defaultsec = $env{'form.sections'};
1.1 raeburn 3886: }
1.27 raeburn 3887: # Check to see if user information can be changed
3888: my @userinfo = ('firstname','middlename','lastname','generation',
3889: 'permanentemail','id');
3890: my %canmodify;
3891: if (&Apache::lonnet::allowed('mau',$domain)) {
1.84 raeburn 3892: push(@userinfo,'inststatus');
1.27 raeburn 3893: foreach my $field (@userinfo) {
3894: $canmodify{$field} = 1;
3895: }
3896: }
3897: my (%userlist,%modifiable_fields,@poss_roles);
3898: my $secidx = &Apache::loncoursedata::CL_SECTION();
1.102 raeburn 3899: my @courseroles = &roles_by_context('course',1,$crstype);
1.27 raeburn 3900: if (!&Apache::lonnet::allowed('mau',$domain)) {
3901: if ($context eq 'course' || $context eq 'author') {
1.101 raeburn 3902: @poss_roles = &curr_role_permissions($context,'','',$crstype);
1.27 raeburn 3903: my @statuses = ('active','future');
3904: my ($indexhash,$keylist) = &make_keylist_array();
3905: my %info;
3906: foreach my $role (@poss_roles) {
3907: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
3908: \@userinfo,[$role]);
3909: }
3910: if ($context eq 'course') {
3911: my ($cnum,$cdom) = &get_course_identity();
3912: my $roster = &Apache::loncoursedata::get_classlist();
1.66 raeburn 3913: if (ref($roster) eq 'HASH') {
3914: %userlist = %{$roster};
3915: }
1.27 raeburn 3916: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
3917: \@statuses,\@poss_roles);
3918: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3919: \%advrolehash,$permission);
3920: } elsif ($context eq 'author') {
3921: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
3922: \@statuses,\@poss_roles);
3923: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3924: \%cstr_roles,$permission);
3925:
3926: }
3927: }
1.1 raeburn 3928: }
3929: if ( $domain eq &LONCAPA::clean_domain($domain)
3930: && ($amode ne '')) {
3931: #######################################
3932: ## Add/Modify Users ##
3933: #######################################
3934: if ($context eq 'course') {
3935: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 3936: } elsif ($context eq 'author') {
1.1 raeburn 3937: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
3938: } else {
3939: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
3940: }
1.87 bisitz 3941: $r->rflush;
3942:
1.1 raeburn 3943: my %counts = (
3944: user => 0,
3945: auth => 0,
3946: role => 0,
3947: );
3948: my $flushc=0;
3949: my %student=();
1.42 raeburn 3950: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 3951: my %userchg;
1.27 raeburn 3952: if ($context eq 'course' || $setting eq 'course') {
3953: if ($context eq 'course') {
3954: # Get information about course groups
3955: %curr_groups = &Apache::longroup::coursegroups();
3956: } elsif ($setting eq 'course') {
3957: if ($cid) {
3958: %curr_groups =
3959: &Apache::longroup::coursegroups($env{'form.dcdomain'},
3960: $env{'form.dccourse'});
3961: }
3962: }
3963: # determine section number
3964: if ($defaultsec =~ /,/) {
3965: push(@sections,split(/,/,$defaultsec));
3966: } else {
3967: push(@sections,$defaultsec);
3968: }
3969: # remove non alphanumeric values from section
3970: foreach my $item (@sections) {
3971: $item =~ s/\W//g;
3972: if ($item eq "none" || $item eq 'all') {
3973: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
3974: } elsif ($item ne '' && exists($curr_groups{$item})) {
3975: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
3976: } elsif ($item ne '') {
3977: push(@cleansec,$item);
3978: }
3979: }
3980: if ($defaultwarn) {
3981: $r->print($defaultwarn.'<br />');
3982: }
3983: if ($groupwarn) {
3984: $r->print($groupwarn.'<br />');
3985: }
1.1 raeburn 3986: }
1.124 raeburn 3987: my (%curr_rules,%got_rules,%alerts,%cancreate);
1.104 raeburn 3988: my %customroles = &my_custom_roles($crstype);
1.101 raeburn 3989: my @permitted_roles =
1.124 raeburn 3990: &roles_on_upload($context,$setting,$crstype,%customroles);
3991: my %longtypes = &Apache::lonlocal::texthash(
3992: official => 'Institutional',
3993: unofficial => 'Non-institutional',
3994: );
1.135 raeburn 3995: my $newuserdom = $env{'request.role.domain'};
3996: map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
1.1 raeburn 3997: # Get new users list
1.27 raeburn 3998: foreach my $line (@userdata) {
1.42 raeburn 3999: my @secs;
1.27 raeburn 4000: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 4001: # Determine user name
1.128 raeburn 4002: $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 4003: unless (($entries{$fields{'username'}} eq '') ||
4004: (!defined($entries{$fields{'username'}}))) {
4005: my ($fname, $mname, $lname,$gen) = ('','','','');
4006: if (defined($fields{'names'})) {
4007: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
4008: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
4009: } else {
4010: if (defined($fields{'fname'})) {
4011: $fname=$entries{$fields{'fname'}};
4012: }
4013: if (defined($fields{'mname'})) {
4014: $mname=$entries{$fields{'mname'}};
4015: }
4016: if (defined($fields{'lname'})) {
4017: $lname=$entries{$fields{'lname'}};
4018: }
4019: if (defined($fields{'gen'})) {
4020: $gen=$entries{$fields{'gen'}};
4021: }
4022: }
1.128 raeburn 4023:
1.1 raeburn 4024: if ($entries{$fields{'username'}}
4025: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
1.128 raeburn 4026: my $nowhitespace;
4027: if ($entries{$fields{'username'}} =~ /\s/) {
4028: $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
4029: }
1.1 raeburn 4030: $r->print('<br />'.
1.74 bisitz 4031: &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
1.128 raeburn 4032: '<b>'.$entries{$fields{'username'}}.'</b>',$fname,$mname,$lname,$gen).
4033: $nowhitespace);
1.27 raeburn 4034: next;
1.1 raeburn 4035: } else {
1.129 raeburn 4036: $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
1.71 droeschl 4037: if ($entries{$fields{'domain'}}
1.57 raeburn 4038: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
4039: $r->print('<br />'. '<b>'.$entries{$fields{'domain'}}.
1.77 raeburn 4040: '</b>: '.&mt('Unacceptable domain for user [_2] [_3] [_4] [_5]',$fname,$mname,$lname,$gen));
1.57 raeburn 4041: next;
4042: }
1.5 raeburn 4043: my $username = $entries{$fields{'username'}};
1.57 raeburn 4044: my $userdomain = $entries{$fields{'domain'}};
4045: if ($userdomain eq '') {
4046: $userdomain = $domain;
4047: }
1.27 raeburn 4048: if (defined($fields{'sec'})) {
4049: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 4050: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 4051: my $item = $entries{$fields{'sec'}};
4052: if ($item eq "none" || $item eq 'all') {
1.74 bisitz 4053: $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 4054: next;
4055: } elsif (exists($curr_groups{$item})) {
1.74 bisitz 4056: $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 4057: next;
4058: } else {
4059: push(@secs,$item);
4060: }
4061: }
4062: }
4063: if ($env{'request.course.sec'} ne '') {
4064: @secs = ($env{'request.course.sec'});
1.57 raeburn 4065: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
4066: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27 raeburn 4067: if ($currsec ne $env{'request.course.sec'}) {
1.74 bisitz 4068: $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 4069: if ($currsec eq '') {
4070: $r->print(&mt('This user already has an active/future student role in the course, unaffiliated to any section.'));
4071:
4072: } else {
4073: $r->print(&mt('This user already has an active/future role in section "[_1]" of the course.',$currsec));
4074: }
4075: $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 />');
4076: next;
1.1 raeburn 4077: }
4078: }
1.27 raeburn 4079: } elsif ($context eq 'course' || $setting eq 'course') {
4080: if (@secs == 0) {
4081: @secs = @cleansec;
1.1 raeburn 4082: }
4083: }
4084: # determine id number
4085: my $id='';
4086: if (defined($fields{'id'})) {
4087: if (defined($entries{$fields{'id'}})) {
4088: $id=$entries{$fields{'id'}};
4089: }
4090: $id=~tr/A-Z/a-z/;
4091: }
4092: # determine email address
4093: my $email='';
4094: if (defined($fields{'email'})) {
1.129 raeburn 4095: $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 4096: if (defined($entries{$fields{'email'}})) {
4097: $email=$entries{$fields{'email'}};
1.84 raeburn 4098: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
4099: }
4100: }
4101: # determine affiliation
4102: my $inststatus='';
4103: if (defined($fields{'inststatus'})) {
4104: if (defined($entries{$fields{'inststatus'}})) {
4105: $inststatus=$entries{$fields{'inststatus'}};
4106: }
1.1 raeburn 4107: }
4108: # determine user password
4109: my $password = $genpwd;
4110: if (defined($fields{'ipwd'})) {
4111: if ($entries{$fields{'ipwd'}}) {
4112: $password=$entries{$fields{'ipwd'}};
4113: }
4114: }
4115: # determine user role
4116: my $role = '';
4117: if (defined($fields{'role'})) {
4118: if ($entries{$fields{'role'}}) {
1.42 raeburn 4119: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
4120: if ($entries{$fields{'role'}} ne '') {
4121: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
4122: $role = $entries{$fields{'role'}};
1.27 raeburn 4123: }
4124: }
4125: if ($role eq '') {
4126: my $rolestr = join(', ',@permitted_roles);
1.74 bisitz 4127: $r->print('<br />'
4128: .&mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
4129: ,'<b>'.$entries{$fields{'username'}}.'</b>'
4130: ,$entries{$fields{'role'}})
4131: .'<br />'
4132: .&mt('Allowable role(s) is/are: [_1].',$rolestr)."\n"
4133: );
1.1 raeburn 4134: next;
4135: }
4136: }
4137: }
4138: if ($role eq '') {
4139: $role = $defaultrole;
4140: }
4141: # Clean up whitespace
1.129 raeburn 4142: foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
1.1 raeburn 4143: $$_ =~ s/(\s+$|^\s+)//g;
4144: }
1.5 raeburn 4145: # check against rules
4146: my $checkid = 0;
4147: my $newuser = 0;
4148: my (%rulematch,%inst_results,%idinst_results);
1.57 raeburn 4149: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5 raeburn 4150: if ($uhome eq 'no_host') {
1.135 raeburn 4151: if ($userdomain ne $newuserdom) {
4152: if ($context eq 'course') {
4153: $r->print('<br />'.
4154: &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
4155: '<b>'.$username.'</b>',$userdomain).'<br />');
4156: } elsif ($context eq 'author') {
4157: $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of the author.',
4158: '<b>'.$username.'</b>',$userdomain).'<br />');
4159: } else {
4160: $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
4161: '<b>'.$username.'</b>',$userdomain).'<br />');
4162: }
4163: $r->print(&mt('The user does not already exist, and you may not create a new user in a different domain.'));
1.124 raeburn 4164: next;
4165: }
1.5 raeburn 4166: $checkid = 1;
4167: $newuser = 1;
1.135 raeburn 4168: my $user = $username.':'.$newuserdom;
1.5 raeburn 4169: my $checkhash;
4170: my $checks = { 'username' => 1 };
1.135 raeburn 4171: $checkhash->{$username.':'.$newuserdom} = { 'newuser' => 1, };
1.5 raeburn 4172: &Apache::loncommon::user_rule_check($checkhash,$checks,
4173: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
4174: \%got_rules);
4175: if (ref($alerts{'username'}) eq 'HASH') {
1.135 raeburn 4176: if (ref($alerts{'username'}{$newuserdom}) eq 'HASH') {
4177: if ($alerts{'username'}{$newuserdom}{$username}) {
1.124 raeburn 4178: $r->print('<br />'.
4179: &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
4180: &mt('Consequently, the user was not created.'));
4181: next;
4182: }
4183: }
4184: }
4185: my $usertype = 'unofficial';
4186: if (ref($rulematch{$user}) eq 'HASH') {
4187: if ($rulematch{$user}{'username'}) {
4188: $usertype = 'official';
1.5 raeburn 4189: }
4190: }
1.124 raeburn 4191: unless ($cancreate{$usertype}) {
4192: my $showtype = $longtypes{$usertype};
4193: $r->print('<br />'.
1.133 raeburn 4194: &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 4195: next;
4196: }
1.13 raeburn 4197: } else {
1.27 raeburn 4198: if ($context eq 'course' || $context eq 'author') {
1.57 raeburn 4199: if ($userdomain eq $domain ) {
4200: if ($role eq '') {
4201: my @checkroles;
4202: foreach my $role (@poss_roles) {
4203: my $endkey;
4204: if ($role ne 'st') {
4205: $endkey = ':'.$role;
4206: }
4207: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
4208: if (!grep(/^\Q$role\E$/,@checkroles)) {
4209: push(@checkroles,$role);
4210: }
4211: }
1.27 raeburn 4212: }
1.57 raeburn 4213: if (@checkroles > 0) {
4214: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27 raeburn 4215: }
1.57 raeburn 4216: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
4217: %canmodify = %{$modifiable_fields{$role}};
1.27 raeburn 4218: }
4219: }
1.57 raeburn 4220: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84 raeburn 4221: for (my $i=0; $i<@newinfo; $i++) {
1.57 raeburn 4222: if (${$newinfo[$i]} ne '') {
4223: if (!$canmodify{$userinfo[$i]}) {
4224: ${$newinfo[$i]} = '';
4225: }
1.27 raeburn 4226: }
4227: }
4228: }
1.5 raeburn 4229: }
4230: if ($id ne '') {
4231: if (!$newuser) {
1.57 raeburn 4232: my %idhash = &Apache::lonnet::idrget($userdomain,($username));
1.5 raeburn 4233: if ($idhash{$username} ne $id) {
4234: $checkid = 1;
4235: }
4236: }
4237: if ($checkid) {
4238: my $checkhash;
4239: my $checks = { 'id' => 1 };
1.57 raeburn 4240: $checkhash->{$username.':'.$userdomain} = { 'newuser' => $newuser,
1.5 raeburn 4241: 'id' => $id };
4242: &Apache::loncommon::user_rule_check($checkhash,$checks,
4243: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
4244: \%got_rules);
4245: if (ref($alerts{'id'}) eq 'HASH') {
1.57 raeburn 4246: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
1.124 raeburn 4247: if ($alerts{'id'}{$userdomain}{$id}) {
4248: $r->print(&mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is found by your directory service.',
4249: '<b>'.$username.'</b>').'<br />'.
4250: &mt('Consequently, the user was not created.'));
4251: next;
4252: }
1.5 raeburn 4253: }
4254: }
4255: }
4256: }
1.1 raeburn 4257: if ($password || $env{'form.login'} eq 'loc') {
1.27 raeburn 4258: my $multiple = 0;
4259: my ($userresult,$authresult,$roleresult,$idresult);
4260: my (%userres,%authres,%roleres,%idres);
1.42 raeburn 4261: my $singlesec = '';
1.1 raeburn 4262: if ($role eq 'st') {
1.27 raeburn 4263: my $sec;
1.42 raeburn 4264: if (@secs > 0) {
4265: $sec = $secs[0];
1.27 raeburn 4266: }
1.57 raeburn 4267: &modifystudent($userdomain,$username,$cid,$sec,
1.52 raeburn 4268: $desiredhost,$context);
1.42 raeburn 4269: $roleresult =
4270: &Apache::lonnet::modifystudent
1.57 raeburn 4271: ($userdomain,$username,$id,$amode,$password,
1.42 raeburn 4272: $fname,$mname,$lname,$gen,$sec,$enddate,
4273: $startdate,$env{'form.forceid'},
1.52 raeburn 4274: $desiredhost,$email,'manual','',$cid,
1.84 raeburn 4275: '',$context,$inststatus);
1.42 raeburn 4276: $userresult = $roleresult;
1.1 raeburn 4277: } else {
1.42 raeburn 4278: if ($role ne '') {
4279: if ($context eq 'course' || $setting eq 'course') {
4280: if ($customroles{$role}) {
4281: $role = 'cr_'.$env{'user.domain'}.'_'.
4282: $env{'user.name'}.'_'.$role;
4283: }
1.103 raeburn 4284: if (($role ne 'cc') && ($role ne 'co')) {
1.42 raeburn 4285: if (@secs > 1) {
4286: $multiple = 1;
4287: foreach my $sec (@secs) {
4288: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
4289: &modifyuserrole($context,$setting,
1.57 raeburn 4290: $changeauth,$cid,$userdomain,$username,
1.42 raeburn 4291: $id,$amode,$password,$fname,
4292: $mname,$lname,$gen,$sec,
4293: $env{'form.forceid'},$desiredhost,
4294: $email,$role,$enddate,
1.84 raeburn 4295: $startdate,$checkid,$inststatus);
1.42 raeburn 4296: }
4297: } elsif (@secs > 0) {
4298: $singlesec = $secs[0];
4299: }
1.27 raeburn 4300: }
4301: }
4302: }
4303: if (!$multiple) {
1.28 raeburn 4304: ($userresult,$authresult,$roleresult,$idresult) =
1.27 raeburn 4305: &modifyuserrole($context,$setting,
1.57 raeburn 4306: $changeauth,$cid,$userdomain,$username,
1.42 raeburn 4307: $id,$amode,$password,$fname,
4308: $mname,$lname,$gen,$singlesec,
4309: $env{'form.forceid'},$desiredhost,
1.84 raeburn 4310: $email,$role,$enddate,$startdate,
4311: $checkid,$inststatus);
1.27 raeburn 4312: }
4313: }
4314: if ($multiple) {
4315: foreach my $sec (sort(keys(%userres))) {
1.42 raeburn 4316: $flushc =
1.27 raeburn 4317: &user_change_result($r,$userres{$sec},$authres{$sec},
4318: $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57 raeburn 4319: $username,$userdomain,\%userchg);
1.27 raeburn 4320:
4321: }
4322: } else {
4323: $flushc =
4324: &user_change_result($r,$userresult,$authresult,
1.28 raeburn 4325: $roleresult,$idresult,\%counts,$flushc,
1.57 raeburn 4326: $username,$userdomain,\%userchg);
1.1 raeburn 4327: }
4328: } else {
4329: if ($context eq 'course') {
4330: $r->print('<br />'.
1.74 bisitz 4331: &mt('[_1]: Unable to enroll. No password specified.','<b>'.$username.'</b>')
1.1 raeburn 4332: );
1.13 raeburn 4333: } elsif ($context eq 'author') {
1.1 raeburn 4334: $r->print('<br />'.
1.74 bisitz 4335: &mt('[_1]: Unable to add co-author. No password specified.','<b>'.$username.'</b>')
1.1 raeburn 4336: );
4337: } else {
4338: $r->print('<br />'.
1.74 bisitz 4339: &mt('[_1]: Unable to add user. No password specified.','<b>'.$username.'</b>')
1.1 raeburn 4340: );
4341: }
4342: }
4343: }
4344: }
4345: } # end of foreach (@userdata)
4346: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 4347: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.29 raeburn 4348: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 4349: "</p>\n");
4350: if ($counts{'role'} > 0) {
4351: $r->print("<p>\n".
1.29 raeburn 4352: &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");
4353: } else {
4354: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 4355: }
4356: if ($counts{'auth'} > 0) {
4357: $r->print("<p>\n".
4358: &mt('Authentication changed for [_1] existing users.',
4359: $counts{'auth'})."</p>\n");
4360: }
1.13 raeburn 4361: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.1 raeburn 4362: #####################################
1.29 raeburn 4363: # Display list of students to drop #
1.1 raeburn 4364: #####################################
4365: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 4366: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 4367: # Get current classlist
1.30 raeburn 4368: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 4369: if (! defined($classlist)) {
1.29 raeburn 4370: $r->print('<form name="studentform" method="post" action="/adm/createuser" />'.
4371: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
4372: &mt('There are no students with current/future access to the course.').
4373: '</form>'."\n");
1.66 raeburn 4374: } elsif (ref($classlist) eq 'HASH') {
1.1 raeburn 4375: # Remove the students we just added from the list of students.
1.30 raeburn 4376: foreach my $line (@userdata) {
4377: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 4378: unless (($entries{$fields{'username'}} eq '') ||
4379: (!defined($entries{$fields{'username'}}))) {
4380: delete($classlist->{$entries{$fields{'username'}}.
4381: ':'.$domain});
4382: }
4383: }
4384: # Print out list of dropped students.
1.30 raeburn 4385: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 4386: }
4387: }
4388: } # end of unless
1.29 raeburn 4389: if ($env{'form.fullup'} ne 'yes') {
4390: $r->print('</form>');
4391: }
1.1 raeburn 4392: }
4393:
1.13 raeburn 4394: sub print_namespacing_alerts {
4395: my ($domain,$alerts,$curr_rules) = @_;
4396: my $output;
4397: if (ref($alerts) eq 'HASH') {
4398: if (keys(%{$alerts}) > 0) {
4399: if (ref($alerts->{'username'}) eq 'HASH') {
4400: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
4401: my $count;
4402: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
4403: $count = keys(%{$alerts->{'username'}{$dom}});
4404: }
4405: my $domdesc = &Apache::lonnet::domain($domain,'description');
4406: if (ref($curr_rules->{$dom}) eq 'HASH') {
4407: $output .= &Apache::loncommon::instrule_disallow_msg(
4408: 'username',$domdesc,$count,'upload');
4409: }
4410: $output .= &Apache::loncommon::user_rule_formats($dom,
4411: $domdesc,$curr_rules->{$dom}{'username'},
4412: 'username');
4413: }
4414: }
4415: if (ref($alerts->{'id'}) eq 'HASH') {
4416: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
4417: my $count;
4418: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
4419: $count = keys(%{$alerts->{'id'}{$dom}});
4420: }
4421: my $domdesc = &Apache::lonnet::domain($domain,'description');
4422: if (ref($curr_rules->{$dom}) eq 'HASH') {
4423: $output .= &Apache::loncommon::instrule_disallow_msg(
4424: 'id',$domdesc,$count,'upload');
4425: }
4426: $output .= &Apache::loncommon::user_rule_formats($dom,
4427: $domdesc,$curr_rules->{$dom}{'id'},'id');
4428: }
4429: }
4430: }
4431: }
4432: }
4433:
1.1 raeburn 4434: sub user_change_result {
1.29 raeburn 4435: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57 raeburn 4436: $username,$userdomain,$userchg) = @_;
1.1 raeburn 4437: my $okresult = 0;
4438: if ($userresult ne 'ok') {
4439: if ($userresult =~ /^error:(.+)$/) {
4440: my $error = $1;
4441: $r->print('<br />'.
1.74 bisitz 4442: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 4443: }
4444: } else {
4445: $counts->{'user'} ++;
4446: $okresult = 1;
4447: }
4448: if ($authresult ne 'ok') {
4449: if ($authresult =~ /^error:(.+)$/) {
4450: my $error = $1;
4451: $r->print('<br />'.
1.74 bisitz 4452: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 4453: }
4454: } else {
4455: $counts->{'auth'} ++;
4456: $okresult = 1;
4457: }
4458: if ($roleresult ne 'ok') {
4459: if ($roleresult =~ /^error:(.+)$/) {
4460: my $error = $1;
4461: $r->print('<br />'.
1.74 bisitz 4462: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 4463: }
4464: } else {
4465: $counts->{'role'} ++;
4466: $okresult = 1;
4467: }
4468: if ($okresult) {
4469: $flushc++;
1.57 raeburn 4470: $userchg->{$username.':'.$userdomain}=1;
1.1 raeburn 4471: $r->print('. ');
4472: if ($flushc>15) {
4473: $r->rflush;
4474: $flushc=0;
4475: }
4476: }
1.29 raeburn 4477: if ($idresult) {
4478: $r->print($idresult);
4479: }
1.1 raeburn 4480: return $flushc;
4481: }
4482:
4483: # ========================================================= Menu Phase Two Drop
1.17 raeburn 4484: sub print_drop_menu {
1.101 raeburn 4485: my ($r,$context,$permission,$crstype) = @_;
4486: my $heading;
4487: if ($crstype eq 'Community') {
4488: $heading = &mt("Drop Members");
4489: } else {
4490: $heading = &mt("Drop Students");
4491: }
4492: $r->print('<h3>'.$heading.'</h3>'."\n".
1.17 raeburn 4493: '<form name="studentform" method="post">'."\n");
1.30 raeburn 4494: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 4495: if (! defined($classlist)) {
1.101 raeburn 4496: if ($crstype eq 'Community') {
4497: $r->print(&mt('There are no members currently enrolled.')."\n");
4498: } else {
4499: $r->print(&mt('There are no students currently enrolled.')."\n");
4500: }
1.30 raeburn 4501: } else {
1.101 raeburn 4502: &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
1.1 raeburn 4503: }
1.17 raeburn 4504: $r->print('</form>'. &Apache::loncommon::end_page());
1.1 raeburn 4505: return;
4506: }
4507:
4508: # ================================================================== Phase four
4509:
1.11 raeburn 4510: sub update_user_list {
1.118 raeburn 4511: my ($r,$context,$setting,$choice,$crstype) = @_;
1.11 raeburn 4512: my $now = time;
1.1 raeburn 4513: my $count=0;
1.101 raeburn 4514: if ($context eq 'course') {
4515: $crstype = &Apache::loncommon::course_type();
4516: }
1.11 raeburn 4517: my @changelist;
1.29 raeburn 4518: if ($choice eq 'drop') {
4519: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
4520: } else {
1.11 raeburn 4521: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
4522: }
4523: my %result_text = ( ok => { 'revoke' => 'Revoked',
4524: 'delete' => 'Deleted',
4525: 'reenable' => 'Re-enabled',
1.17 raeburn 4526: 'activate' => 'Activated',
4527: 'chgdates' => 'Changed Access Dates for',
1.118 raeburn 4528: 'chgsec' => 'Changed section(s) for',
1.17 raeburn 4529: 'drop' => 'Dropped',
1.11 raeburn 4530: },
4531: error => {'revoke' => 'revoking',
4532: 'delete' => 'deleting',
4533: 'reenable' => 're-enabling',
4534: 'activate' => 'activating',
1.17 raeburn 4535: 'chgdates' => 'changing access dates for',
4536: 'chgsec' => 'changing section for',
4537: 'drop' => 'dropping',
1.11 raeburn 4538: },
4539: );
4540: my ($startdate,$enddate);
4541: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
4542: ($startdate,$enddate) = &get_dates_from_form();
4543: }
4544: foreach my $item (@changelist) {
1.118 raeburn 4545: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
4546: @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
4547: $nothingtodo,$keepnosection);
1.17 raeburn 4548: if ($choice eq 'drop') {
4549: ($uname,$udom,$sec) = split(/:/,$item,-1);
4550: $role = 'st';
4551: $cid = $env{'request.course.id'};
4552: $scopestem = '/'.$cid;
4553: $scopestem =~s/\_/\//g;
4554: if ($sec eq '') {
4555: $scope = $scopestem;
4556: } else {
4557: $scope = $scopestem.'/'.$sec;
4558: }
4559: } elsif ($context eq 'course') {
1.11 raeburn 4560: ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
4561: $cid = $env{'request.course.id'};
4562: $scopestem = '/'.$cid;
4563: $scopestem =~s/\_/\//g;
4564: if ($sec eq '') {
4565: $scope = $scopestem;
4566: } else {
4567: $scope = $scopestem.'/'.$sec;
4568: }
1.13 raeburn 4569: } elsif ($context eq 'author') {
1.11 raeburn 4570: ($uname,$udom,$role) = split(/\:/,$item,-1);
4571: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
4572: } elsif ($context eq 'domain') {
4573: if ($setting eq 'domain') {
4574: ($role,$uname,$udom) = split(/\:/,$item,-1);
4575: $scope = '/'.$env{'request.role.domain'}.'/';
1.13 raeburn 4576: } elsif ($setting eq 'author') {
1.11 raeburn 4577: ($uname,$udom,$role,$scope) = split(/\:/,$item);
4578: } elsif ($setting eq 'course') {
4579: ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
4580: split(/\:/,$item);
4581: $scope = '/'.$cid;
4582: $scope =~s/\_/\//g;
4583: if ($sec ne '') {
4584: $scope .= '/'.$sec;
4585: }
4586: }
4587: }
1.101 raeburn 4588: my $plrole = &Apache::lonnet::plaintext($role,$crstype);
1.11 raeburn 4589: my $start = $env{'form.'.$item.'_start'};
4590: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 4591: if ($choice eq 'drop') {
4592: # drop students
4593: $end = $now;
4594: $type = 'manual';
4595: $result =
1.52 raeburn 4596: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 4597: } elsif ($choice eq 'revoke') {
4598: # revoke or delete user role
1.11 raeburn 4599: $end = $now;
4600: if ($role eq 'st') {
4601: $result =
1.52 raeburn 4602: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4603: } else {
4604: $result =
1.52 raeburn 4605: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
4606: '','',$context);
1.11 raeburn 4607: }
4608: } elsif ($choice eq 'delete') {
4609: if ($role eq 'st') {
1.52 raeburn 4610: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context);
1.29 raeburn 4611: }
4612: $result =
4613: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 4614: $start,1,'',$context);
1.11 raeburn 4615: } else {
4616: #reenable, activate, change access dates or change section
4617: if ($choice ne 'chgsec') {
4618: $start = $startdate;
4619: $end = $enddate;
4620: }
4621: if ($choice eq 'reenable') {
4622: if ($role eq 'st') {
1.52 raeburn 4623: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4624: } else {
4625: $result =
4626: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4627: $now,'','',$context);
1.11 raeburn 4628: }
4629: } elsif ($choice eq 'activate') {
4630: if ($role eq 'st') {
1.52 raeburn 4631: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4632: } else {
4633: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4634: $now,'','',$context);
1.11 raeburn 4635: }
4636: } elsif ($choice eq 'chgdates') {
4637: if ($role eq 'st') {
1.52 raeburn 4638: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4639: } else {
4640: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4641: $start,'','',$context);
1.11 raeburn 4642: }
4643: } elsif ($choice eq 'chgsec') {
4644: my (@newsecs,$revresult,$nochg,@retained);
1.103 raeburn 4645: if (($role ne 'cc') && ($role ne 'co')) {
1.117 raeburn 4646: my @secs = sort(split(/,/,$env{'form.newsecs'}));
4647: if (@secs) {
4648: my %curr_groups = &Apache::longroup::coursegroups();
4649: foreach my $sec (@secs) {
4650: next if (($sec =~ /\W/) || ($sec eq 'none') ||
4651: (exists($curr_groups{$sec})));
4652: push(@newsecs,$sec);
4653: }
4654: }
1.11 raeburn 4655: }
4656: # remove existing section if not to be retained.
1.118 raeburn 4657: if (!$env{'form.retainsec'} || ($role eq 'st')) {
1.11 raeburn 4658: if ($sec eq '') {
4659: if (@newsecs == 0) {
1.118 raeburn 4660: $result = 'ok';
1.11 raeburn 4661: $nochg = 1;
1.118 raeburn 4662: $nothingtodo = 1;
1.40 raeburn 4663: } else {
4664: $revresult =
4665: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4666: $scope,$role,
4667: '','',$context);
1.40 raeburn 4668: }
1.11 raeburn 4669: } else {
1.28 raeburn 4670: if (@newsecs > 0) {
4671: if (grep(/^\Q$sec\E$/,@newsecs)) {
4672: push(@retained,$sec);
4673: } else {
4674: $revresult =
4675: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4676: $scope,$role,
4677: '','',$context);
1.28 raeburn 4678: }
4679: } else {
1.11 raeburn 4680: $revresult =
1.28 raeburn 4681: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4682: $scope,$role,
4683: '','',$context);
1.11 raeburn 4684: }
4685: }
4686: } else {
1.28 raeburn 4687: if ($sec eq '') {
4688: $nochg = 1;
1.118 raeburn 4689: $keepnosection = 1;
4690: } else {
1.28 raeburn 4691: push(@retained,$sec);
4692: }
1.11 raeburn 4693: }
4694: # add new sections
1.118 raeburn 4695: my (@diffs,@shownew);
4696: if (@retained) {
4697: @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
4698: } else {
4699: @diffs = @newsecs;
4700: }
1.11 raeburn 4701: if (@newsecs == 0) {
1.118 raeburn 4702: if ($nochg) {
4703: $result = 'ok';
4704: $nothingtodo = 1;
4705: } else {
1.28 raeburn 4706: if ($role eq 'st') {
4707: $result =
1.52 raeburn 4708: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
1.28 raeburn 4709: } else {
4710: my $newscope = $scopestem;
1.52 raeburn 4711: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 4712: }
4713: }
1.118 raeburn 4714: $showsecs = &mt('No section');
4715: } elsif (@diffs == 0) {
4716: $result = 'ok';
4717: $nothingtodo = 1;
1.11 raeburn 4718: } else {
1.118 raeburn 4719: foreach my $newsec (@newsecs) {
1.11 raeburn 4720: if (!grep(/^\Q$newsec\E$/,@retained)) {
4721: if ($role eq 'st') {
1.52 raeburn 4722: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
1.118 raeburn 4723: if (@newsecs > 1) {
4724: my $showsingle;
4725: if ($newsec eq '') {
4726: $showsingle = &mt('No section');
4727: } else {
4728: $showsingle = $newsec;
4729: }
4730: if ($crstype eq 'Community') {
4731: $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>');
4732: } else {
4733: $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>');
4734: }
4735: $showsecs = $showsingle;
4736: last;
4737: } else {
4738: if ($newsec eq '') {
4739: $showsecs = &mt('No section');
4740: } else {
4741: $showsecs = $newsec;
4742: }
4743: }
1.11 raeburn 4744: } else {
4745: my $newscope = $scopestem;
4746: if ($newsec ne '') {
4747: $newscope .= '/'.$newsec;
1.118 raeburn 4748: push(@shownew,$newsec);
1.11 raeburn 4749: }
4750: $result = &Apache::lonnet::assignrole($udom,$uname,
4751: $newscope,$role,$end,$start);
1.118 raeburn 4752:
1.11 raeburn 4753: }
4754: }
4755: }
4756: }
1.118 raeburn 4757: unless ($role eq 'st') {
4758: unless ($showsecs) {
4759: my @tolist = sort(@shownew,@retained);
4760: if ($keepnosection) {
4761: push(@tolist,&mt('No section'));
4762: }
4763: $showsecs = join(', ',@tolist);
4764: }
4765: }
1.11 raeburn 4766: }
4767: }
1.17 raeburn 4768: my $extent = $scope;
4769: if ($choice eq 'drop' || $context eq 'course') {
4770: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
4771: if ($cdesc) {
4772: $extent = $cdesc;
4773: }
4774: }
1.1 raeburn 4775: if ($result eq 'ok' || $result eq 'ok:') {
1.118 raeburn 4776: my $dates;
4777: if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
4778: $dates = &dates_feedback($start,$end,$now);
4779: }
4780: if ($choice eq 'chgsec') {
4781: if ($nothingtodo) {
4782: $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
4783: &Apache::loncommon::plainname($uname,$udom).
4784: '</i>').' ');
4785: if ($sec eq '') {
4786: $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
4787: } else {
4788: $r->print(&mt('Section(s): [_1] - [_2]',
4789: '<b>'.$showsecs.'</b>',$dates));
4790: }
4791: $r->print('<br />');
4792: } else {
4793: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
4794: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
4795: '<b>'.$showsecs.'</b>',$dates).'<br />');
4796: $count ++;
4797: }
4798: if ($warn_singlesec) {
4799: $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
4800: }
4801: } elsif ($choice eq 'chgdates') {
4802: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
1.121 raeburn 4803: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 4804: $dates).'<br />');
4805: $count ++;
4806: } else {
4807: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
1.121 raeburn 4808: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
1.118 raeburn 4809: '<br />');
4810: $count ++;
4811: }
1.1 raeburn 4812: } else {
4813: $r->print(
1.118 raeburn 4814: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
4815: $plrole,$extent,
1.121 raeburn 4816: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 4817: $result).'<br />');
1.11 raeburn 4818: }
4819: }
1.32 raeburn 4820: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 4821: if ($choice eq 'drop') {
4822: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
4823: '<input type="hidden" name="Status" value="Active" />'."\n".
4824: '<input type="hidden" name="showrole" value="st" />'."\n");
4825: } else {
4826: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
4827: if ($env{'form.'.$item} ne '') {
4828: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
4829: '" />'."\n");
4830: }
1.32 raeburn 4831: }
4832: }
1.118 raeburn 4833: $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 4834: if ($count > 0) {
1.17 raeburn 4835: if ($choice eq 'revoke' || $choice eq 'drop') {
1.74 bisitz 4836: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11 raeburn 4837: }
4838: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 4839: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.11 raeburn 4840: }
4841: if ($env{'form.makedatesdefault'}) {
4842: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.101 raeburn 4843: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 4844: }
4845: }
1.33 raeburn 4846: my $linktext = &mt('Display User Lists');
4847: if ($choice eq 'drop') {
4848: $linktext = &mt('Display current class roster');
4849: }
4850: $r->print('<a href="javascript:document.studentform.submit()">'.$linktext.'</a></form>'."\n");
1.1 raeburn 4851: }
4852:
1.118 raeburn 4853: sub dates_feedback {
4854: my ($start,$end,$now) = @_;
4855: my $dates;
4856: if ($start < $now) {
4857: if ($end == 0) {
4858: $dates .= &mt('role(s) active now; no end date');
4859: } elsif ($end > $now) {
4860: $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
4861: } else {
4862: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
4863: }
4864: } else {
4865: if ($end == 0 || $end > $now) {
4866: $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
4867: } else {
4868: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
4869: }
4870: }
4871: return $dates;
4872: }
4873:
1.8 raeburn 4874: sub classlist_drop {
1.29 raeburn 4875: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 4876: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 4877: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8 raeburn 4878: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63 raeburn 4879: my %user;
4880: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8 raeburn 4881: return &mt('Drop from classlist: [_1]',
4882: '<b>'.$result.'</b>').'<br />';
4883: }
4884: }
4885: }
4886:
4887: sub active_student_roles {
4888: my ($cnum,$cdom,$uname,$udom) = @_;
4889: my %roles =
4890: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
4891: ['future','active'],['st']);
4892: return exists($roles{"$cnum:$cdom:st"});
4893: }
4894:
1.1 raeburn 4895: sub section_check_js {
1.8 raeburn 4896: my $groupslist= &get_groupslist();
1.1 raeburn 4897: return <<"END";
4898: function validate(caller) {
1.9 raeburn 4899: var groups = new Array($groupslist);
1.1 raeburn 4900: var secname = caller.value;
4901: if ((secname == 'all') || (secname == 'none')) {
4902: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
4903: return 'error';
4904: }
4905: if (secname != '') {
4906: for (var k=0; k<groups.length; k++) {
4907: if (secname == groups[k]) {
4908: 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.");
4909: return 'error';
4910: }
4911: }
4912: }
4913: return 'ok';
4914: }
4915: END
4916: }
4917:
4918: sub set_login {
4919: my ($dom,$authformkrb,$authformint,$authformloc) = @_;
4920: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4921: my $response;
4922: my ($authnum,%can_assign) =
4923: &Apache::loncommon::get_assignable_auth($dom);
4924: if ($authnum) {
4925: $response = &Apache::loncommon::start_data_table();
4926: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
4927: $response .= &Apache::loncommon::start_data_table_row().
4928: '<td>'.$authformkrb.'</td>'.
4929: &Apache::loncommon::end_data_table_row()."\n";
4930: }
4931: if ($can_assign{'int'}) {
4932: $response .= &Apache::loncommon::start_data_table_row().
4933: '<td>'.$authformint.'</td>'.
4934: &Apache::loncommon::end_data_table_row()."\n"
4935: }
4936: if ($can_assign{'loc'}) {
4937: $response .= &Apache::loncommon::start_data_table_row().
4938: '<td>'.$authformloc.'</td>'.
4939: &Apache::loncommon::end_data_table_row()."\n";
4940: }
4941: $response .= &Apache::loncommon::end_data_table();
4942: }
4943: return $response;
4944: }
4945:
1.8 raeburn 4946: sub course_sections {
1.51 raeburn 4947: my ($sections_count,$role,$current_sec) = @_;
1.8 raeburn 4948: my $output = '';
4949: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.29 raeburn 4950: my $numsec = scalar(@sections);
1.92 bisitz 4951: my $is_selected = ' selected="selected"';
1.29 raeburn 4952: if ($numsec <= 1) {
1.8 raeburn 4953: $output = '<select name="currsec_'.$role.'" >'."\n".
1.51 raeburn 4954: ' <option value="">'.&mt('Select').'</option>'."\n";
4955: if ($current_sec eq 'none') {
4956: $output .=
4957: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
4958: } else {
4959: $output .=
1.29 raeburn 4960: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 4961: }
1.29 raeburn 4962: if ($numsec == 1) {
1.51 raeburn 4963: if ($current_sec eq $sections[0]) {
4964: $output .=
4965: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
4966: } else {
4967: $output .=
1.8 raeburn 4968: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 4969: }
1.29 raeburn 4970: }
1.8 raeburn 4971: } else {
4972: $output = '<select name="currsec_'.$role.'" ';
4973: my $multiple = 4;
4974: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 4975: if ($role eq 'st') {
4976: $output .= '>'."\n".
1.51 raeburn 4977: ' <option value="">'.&mt('Select').'</option>'."\n";
4978: if ($current_sec eq 'none') {
4979: $output .=
4980: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
4981: } else {
4982: $output .=
1.29 raeburn 4983: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 4984: }
1.29 raeburn 4985: } else {
4986: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
4987: }
1.8 raeburn 4988: foreach my $sec (@sections) {
1.51 raeburn 4989: if ($current_sec eq $sec) {
4990: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
4991: } else {
4992: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
4993: }
1.8 raeburn 4994: }
4995: }
4996: $output .= '</select>';
4997: return $output;
4998: }
4999:
5000: sub get_groupslist {
5001: my $groupslist;
5002: my %curr_groups = &Apache::longroup::coursegroups();
5003: if (%curr_groups) {
5004: $groupslist = join('","',sort(keys(%curr_groups)));
5005: $groupslist = '"'.$groupslist.'"';
5006: }
1.11 raeburn 5007: return $groupslist;
1.8 raeburn 5008: }
5009:
5010: sub setsections_javascript {
1.103 raeburn 5011: my ($formname,$groupslist,$mode,$checkauth,$crstype) = @_;
1.28 raeburn 5012: my ($checkincluded,$finish,$rolecode,$setsection_js);
5013: if ($mode eq 'upload') {
5014: $checkincluded = 'formname.name == "'.$formname.'"';
5015: $finish = "return 'ok';";
5016: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
5017: } elsif ($formname eq 'cu') {
1.8 raeburn 5018: $checkincluded = 'formname.elements[i-1].checked == true';
1.37 raeburn 5019: if ($checkauth) {
5020: $finish = "var authcheck = auth_check();\n".
5021: " if (authcheck == 'ok') {\n".
5022: " formname.submit();\n".
5023: " }\n";
5024: } else {
5025: $finish = 'formname.submit()';
5026: }
1.28 raeburn 5027: $rolecode = "var match = str.split('_');
5028: var role = match[3];\n";
5029: } elsif ($formname eq 'enrollstudent') {
5030: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 5031: if ($checkauth) {
5032: $finish = "var authcheck = auth_check();\n".
5033: " if (authcheck == 'ok') {\n".
5034: " formname.submit();\n".
5035: " }\n";
5036: } else {
5037: $finish = 'formname.submit()';
5038: }
1.28 raeburn 5039: $rolecode = "var match = str.split('_');
5040: var role = match[1];\n";
1.8 raeburn 5041: } else {
1.28 raeburn 5042: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 5043: $finish = "seccheck = 'ok';";
1.28 raeburn 5044: $rolecode = "var match = str.split('_');
5045: var role = match[1];\n";
1.11 raeburn 5046: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 5047: }
5048: my %alerts = &Apache::lonlocal::texthash(
5049: secd => 'Section designations do not apply to Course Coordinator roles.',
1.103 raeburn 5050: sedn => 'Section designations do not apply to Coordinator roles.',
1.8 raeburn 5051: accr => 'A course coordinator role will be added with access to all sections.',
1.103 raeburn 5052: acor => 'A coordinator role will be added with access to all sections',
1.8 raeburn 5053: inea => 'In each course, each user may only have one student role at a time.',
1.125 raeburn 5054: inco => 'In each community, each user may only have one member role at a time.',
1.8 raeburn 5055: youh => 'You had selected ',
5056: secs => 'sections.',
5057: plmo => 'Please modify your selections so they include no more than one section.',
5058: mayn => 'may not be used as the name for a section, as it is a reserved word.',
5059: plch => 'Please choose a different section name.',
5060: mnot => 'may not be used as a section name, as it is the name of a course group.',
5061: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.113 raeburn 5062: nonw => 'Section names may only contain letters or numbers.',
1.11 raeburn 5063: );
1.8 raeburn 5064: $setsection_js .= <<"ENDSECCODE";
5065:
1.103 raeburn 5066: function setSections(formname,crstype) {
1.8 raeburn 5067: var re1 = /^currsec_/;
1.113 raeburn 5068: var re2 =/\\W/;
1.115 raeburn 5069: var trimleading = /^\\s+/;
5070: var trimtrailing = /\\s+\$/;
1.8 raeburn 5071: var groups = new Array($groupslist);
5072: for (var i=0;i<formname.elements.length;i++) {
5073: var str = formname.elements[i].name;
5074: var checkcurr = str.match(re1);
5075: if (checkcurr != null) {
1.115 raeburn 5076: var num = i;
1.8 raeburn 5077: if ($checkincluded) {
1.28 raeburn 5078: $rolecode
1.103 raeburn 5079: if (role == 'cc' || role == 'co') {
5080: if (role == 'cc') {
5081: alert("$alerts{'secd'}\\n$alerts{'accr'}");
5082: } else {
5083: alert("$alerts{'sedn'}\\n$alerts{'acor'}");
5084: }
5085: } else {
1.8 raeburn 5086: var sections = '';
5087: var numsec = 0;
1.115 raeburn 5088: var fromexisting = new Array();
5089: for (var j=0; j<formname.elements[num].length; j++) {
5090: if (formname.elements[num].options[j].selected == true ) {
5091: var addsec = formname.elements[num].options[j].value;
1.119 raeburn 5092: if ((addsec != "") && (addsec != null)) {
1.115 raeburn 5093: fromexisting.push(addsec);
1.8 raeburn 5094: if (numsec == 0) {
1.115 raeburn 5095: sections = addsec;
5096: } else {
5097: sections = sections + "," + addsec;
1.8 raeburn 5098: }
1.115 raeburn 5099: numsec ++;
1.8 raeburn 5100: }
5101: }
5102: }
1.115 raeburn 5103: var newsecs = formname.elements[num+1].value;
1.113 raeburn 5104: var validsecs = new Array();
1.115 raeburn 5105: var validsecstr = '';
1.113 raeburn 5106: var badsecs = new Array();
1.8 raeburn 5107: if (newsecs != null && newsecs != "") {
1.115 raeburn 5108: var numsplit;
5109: if (newsecs.indexOf(',') == -1) {
5110: numsplit = new Array(newsecs);
5111: } else {
5112: numsplit = newsecs.split(/,/g);
5113: }
1.117 raeburn 5114: for (var m=0; m<numsplit.length; m++) {
5115: var newsec = numsplit[m];
1.115 raeburn 5116: newsec = newsec.replace(trimleading,'');
5117: newsec = newsec.replace(trimtrailing,'');
5118: if (re2.test(newsec) == true) {
5119: badsecs.push(newsec);
1.113 raeburn 5120: } else {
1.115 raeburn 5121: if (newsec != '') {
5122: var isnew = 1;
5123: if (fromexisting != null) {
1.117 raeburn 5124: for (var n=0; n<fromexisting.length; n++) {
5125: if (newsec == fromexisting[n]) {
1.115 raeburn 5126: isnew = 0;
5127: }
5128: }
5129: }
5130: if (isnew == 1) {
5131: validsecs.push(newsec);
5132: }
5133: }
1.113 raeburn 5134: }
5135: }
5136: if (badsecs.length > 0) {
5137: alert("$alerts{'nonw'}\\n$alerts{'plch'}");
5138: return;
5139: }
5140: numsec = numsec + validsecs.length;
1.8 raeburn 5141: }
5142: if ((role == 'st') && (numsec > 1)) {
1.103 raeburn 5143: if (crstype == 'Community') {
5144: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
5145: } else {
5146: alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
5147: }
1.8 raeburn 5148: return;
1.115 raeburn 5149: } else {
5150: if (validsecs != null) {
5151: for (var j=0; j<validsecs.length; j++) {
5152: if (validsecstr == '' || validsecstr == null) {
5153: validsecstr = validsecs[j];
5154: } else {
5155: validsecstr += ','+validsecs[j];
5156: }
5157: if ((validsecs[j] == 'all') ||
5158: (validsecs[j] == 'none')) {
5159: alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
1.8 raeburn 5160: return;
5161: }
5162: for (var k=0; k<groups.length; k++) {
1.115 raeburn 5163: if (validsecs[j] == groups[k]) {
5164: alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
1.8 raeburn 5165: return;
5166: }
5167: }
5168: }
5169: }
5170: }
1.115 raeburn 5171: if ((validsecstr != '') && (validsecstr != null)) {
1.117 raeburn 5172: if ((sections == '') || (sections == null)) {
5173: sections = validsecstr;
5174: } else {
1.115 raeburn 5175: sections = sections + "," + validsecstr;
5176: }
5177: }
5178: formname.elements[num+2].value = sections;
1.8 raeburn 5179: }
5180: }
5181: }
5182: }
5183: $finish
5184: }
5185: ENDSECCODE
1.11 raeburn 5186: return $setsection_js;
1.8 raeburn 5187: }
5188:
1.15 raeburn 5189: sub can_create_user {
5190: my ($dom,$context,$usertype) = @_;
5191: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5192: my $cancreate = 1;
1.28 raeburn 5193: if (&Apache::lonnet::allowed('mau',$dom)) {
5194: return $cancreate;
5195: }
1.15 raeburn 5196: if (ref($domconf{'usercreation'}) eq 'HASH') {
5197: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
1.100 raeburn 5198: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
1.15 raeburn 5199: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
5200: if ($creation eq 'none') {
5201: $cancreate = 0;
5202: } elsif ($creation ne 'any') {
5203: if (defined($usertype)) {
5204: if ($creation ne $usertype) {
5205: $cancreate = 0;
5206: }
5207: }
5208: }
5209: }
5210: }
5211: }
5212: return $cancreate;
5213: }
5214:
1.20 raeburn 5215: sub can_modify_userinfo {
5216: my ($context,$dom,$fields,$userroles) = @_;
5217: my %domconfig =
5218: &Apache::lonnet::get_dom('configuration',['usermodification'],
5219: $dom);
5220: my %canmodify;
5221: if (ref($fields) eq 'ARRAY') {
5222: foreach my $field (@{$fields}) {
5223: $canmodify{$field} = 0;
5224: if (&Apache::lonnet::allowed('mau',$dom)) {
5225: $canmodify{$field} = 1;
5226: } else {
5227: if (ref($domconfig{'usermodification'}) eq 'HASH') {
5228: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
5229: if (ref($userroles) eq 'ARRAY') {
5230: foreach my $role (@{$userroles}) {
5231: my $testrole;
1.60 raeburn 5232: if ($context eq 'selfcreate') {
5233: $testrole = $role;
1.20 raeburn 5234: } else {
1.60 raeburn 5235: if ($role =~ /^cr\//) {
5236: $testrole = 'cr';
5237: } else {
5238: $testrole = $role;
5239: }
1.20 raeburn 5240: }
5241: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
5242: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
5243: $canmodify{$field} = 1;
5244: last;
5245: }
5246: }
5247: }
5248: } else {
5249: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
5250: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
5251: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
5252: $canmodify{$field} = 1;
5253: last;
5254: }
5255: }
5256: }
5257: }
5258: }
5259: } elsif ($context eq 'course') {
5260: if (ref($userroles) eq 'ARRAY') {
5261: if (grep(/^st$/,@{$userroles})) {
5262: $canmodify{$field} = 1;
5263: }
5264: } else {
5265: $canmodify{$field} = 1;
5266: }
5267: }
5268: }
5269: }
5270: }
5271: return %canmodify;
5272: }
5273:
1.18 raeburn 5274: sub check_usertype {
1.134 raeburn 5275: my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
1.18 raeburn 5276: my $usertype;
1.134 raeburn 5277: if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
5278: if (!$got_rules->{$dom}) {
5279: my %domconfig = &Apache::lonnet::get_dom('configuration',
5280: ['usercreation'],$dom);
5281: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5282: foreach my $item ('username','id') {
5283: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
5284: $curr_rules->{$dom}{$item} =
5285: $domconfig{'usercreation'}{$item.'_rule'};
5286: }
5287: }
5288: }
5289: $got_rules->{$dom} = 1;
5290: }
5291: if (ref($rules) eq 'HASH') {
5292: my @user_rules;
5293: if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
5294: foreach my $rule (keys(%{$rules})) {
5295: if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
5296: push(@user_rules,$rule);
5297: }
5298: }
5299: }
5300: if (@user_rules > 0) {
5301: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
5302: if (keys(%rule_check) > 0) {
5303: $usertype = 'unofficial';
5304: foreach my $item (keys(%rule_check)) {
5305: if ($rule_check{$item}) {
5306: $usertype = 'official';
5307: last;
5308: }
1.18 raeburn 5309: }
5310: }
5311: }
5312: }
5313: }
5314: return $usertype;
5315: }
5316:
1.17 raeburn 5317: sub roles_by_context {
1.101 raeburn 5318: my ($context,$custom,$crstype) = @_;
1.17 raeburn 5319: my @allroles;
5320: if ($context eq 'course') {
1.99 raeburn 5321: @allroles = ('st');
5322: if ($env{'request.role'} =~ m{^dc\./}) {
5323: push(@allroles,'ad');
5324: }
1.101 raeburn 5325: push(@allroles,('ta','ep','in'));
5326: if ($crstype eq 'Community') {
5327: push(@allroles,'co');
5328: } else {
5329: push(@allroles,'cc');
5330: }
1.17 raeburn 5331: if ($custom) {
5332: push(@allroles,'cr');
5333: }
5334: } elsif ($context eq 'author') {
5335: @allroles = ('ca','aa');
5336: } elsif ($context eq 'domain') {
1.99 raeburn 5337: @allroles = ('li','ad','dg','sc','au','dc');
1.17 raeburn 5338: }
5339: return @allroles;
5340: }
5341:
1.16 raeburn 5342: sub get_permission {
1.101 raeburn 5343: my ($context,$crstype) = @_;
1.16 raeburn 5344: my %permission;
5345: if ($context eq 'course') {
1.17 raeburn 5346: my $custom = 1;
1.101 raeburn 5347: my @allroles = &roles_by_context($context,$custom,$crstype);
1.17 raeburn 5348: foreach my $role (@allroles) {
5349: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
5350: $permission{'cusr'} = 1;
5351: last;
5352: }
1.16 raeburn 5353: }
5354: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
5355: $permission{'custom'} = 1;
5356: }
5357: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
5358: $permission{'view'} = 1;
5359: }
5360: if (!$permission{'view'}) {
5361: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
5362: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
5363: if ($permission{'view'}) {
5364: $permission{'view_section'} = $env{'request.course.sec'};
5365: }
5366: }
1.17 raeburn 5367: if (!$permission{'cusr'}) {
5368: if ($env{'request.course.sec'} ne '') {
5369: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
5370: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
5371: if ($permission{'cusr'}) {
5372: $permission{'cusr_section'} = $env{'request.course.sec'};
5373: }
5374: }
5375: }
1.16 raeburn 5376: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
5377: $permission{'grp_manage'} = 1;
5378: }
5379: } elsif ($context eq 'author') {
5380: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
5381: $permission{'view'} = $permission{'cusr'};
5382: } else {
1.17 raeburn 5383: my @allroles = &roles_by_context($context);
5384: foreach my $role (@allroles) {
1.28 raeburn 5385: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
5386: $permission{'cusr'} = 1;
1.17 raeburn 5387: last;
5388: }
5389: }
5390: if (!$permission{'cusr'}) {
5391: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
5392: $permission{'cusr'} = 1;
5393: }
1.16 raeburn 5394: }
5395: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
5396: $permission{'custom'} = 1;
5397: }
5398: $permission{'view'} = $permission{'cusr'};
5399: }
5400: my $allowed = 0;
5401: foreach my $perm (values(%permission)) {
5402: if ($perm) { $allowed=1; last; }
5403: }
5404: return (\%permission,$allowed);
5405: }
5406:
5407: # ==================================================== Figure out author access
5408:
5409: sub authorpriv {
5410: my ($auname,$audom)=@_;
5411: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
5412: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
5413: }
5414:
1.27 raeburn 5415: sub roles_on_upload {
1.101 raeburn 5416: my ($context,$setting,$crstype,%customroles) = @_;
1.27 raeburn 5417: my (@possible_roles,@permitted_roles);
1.101 raeburn 5418: @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
1.27 raeburn 5419: foreach my $role (@possible_roles) {
5420: if ($role eq 'cr') {
5421: push(@permitted_roles,keys(%customroles));
5422: } else {
5423: push(@permitted_roles,$role);
5424: }
5425: }
1.42 raeburn 5426: return @permitted_roles;
1.27 raeburn 5427: }
5428:
1.17 raeburn 5429: sub get_course_identity {
5430: my ($cid) = @_;
5431: my ($cnum,$cdom,$cdesc);
5432: if ($cid eq '') {
5433: $cid = $env{'request.course.id'}
5434: }
5435: if ($cid ne '') {
5436: $cnum = $env{'course.'.$cid.'.num'};
5437: $cdom = $env{'course.'.$cid.'.domain'};
5438: $cdesc = $env{'course.'.$cid.'.description'};
5439: if ($cnum eq '' || $cdom eq '') {
5440: my %coursehash =
5441: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
5442: $cdom = $coursehash{'domain'};
5443: $cnum = $coursehash{'num'};
5444: $cdesc = $coursehash{'description'};
5445: }
5446: }
5447: return ($cnum,$cdom,$cdesc);
5448: }
5449:
1.19 raeburn 5450: sub dc_setcourse_js {
1.37 raeburn 5451: my ($formname,$mode,$context) = @_;
5452: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 5453: my $cctext = &Apache::lonnet::plaintext('cc');
1.103 raeburn 5454: my $cotext = &Apache::lonnet::plaintext('co');
1.19 raeburn 5455: my %alerts = §ioncheck_alerts();
5456: my $role = 'role';
5457: if ($mode eq 'upload') {
5458: $role = 'courserole';
1.37 raeburn 5459: } else {
5460: $authen_check = &verify_authen($formname,$context);
1.19 raeburn 5461: }
5462: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 5463: $authen_check
5464:
1.19 raeburn 5465: function setCourse() {
5466: var course = document.$formname.dccourse.value;
5467: if (course != "") {
5468: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
5469: alert("$alerts{'curd'}");
5470: return;
5471: }
5472: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
5473: var section="";
5474: var numsections = 0;
5475: var newsecs = new Array();
5476: for (var i=0; i<document.$formname.currsec.length; i++) {
5477: if (document.$formname.currsec.options[i].selected == true ) {
5478: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
5479: if (numsections == 0) {
5480: section = document.$formname.currsec.options[i].value
5481: numsections = 1;
5482: }
5483: else {
5484: section = section + "," + document.$formname.currsec.options[i].value
5485: numsections ++;
5486: }
5487: }
5488: }
5489: }
5490: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
5491: if (numsections == 0) {
5492: section = document.$formname.newsec.value
5493: }
5494: else {
5495: section = section + "," + document.$formname.newsec.value
5496: }
5497: newsecs = document.$formname.newsec.value.split(/,/g);
5498: numsections = numsections + newsecs.length;
5499: }
5500: if ((userrole == 'st') && (numsections > 1)) {
1.103 raeburn 5501: if (document.$formname.crstype.value == 'Community') {
5502: alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
5503: } else {
5504: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
5505: }
1.19 raeburn 5506: return;
5507: }
5508: for (var j=0; j<newsecs.length; j++) {
5509: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
5510: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
5511: return;
5512: }
5513: if (document.$formname.groups.value != '') {
5514: var groups = document.$formname.groups.value.split(/,/g);
5515: for (var k=0; k<groups.length; k++) {
5516: if (newsecs[j] == groups[k]) {
1.103 raeburn 5517: if (document.$formname.crstype.value == 'Community') {
5518: alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
5519: } else {
5520: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
5521: }
1.19 raeburn 5522: return;
5523: }
5524: }
5525: }
5526: }
5527: if ((userrole == 'cc') && (numsections > 0)) {
5528: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
5529: section = "";
5530: }
1.103 raeburn 5531: if ((userrole == 'co') && (numsections > 0)) {
5532: alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
5533: section = "";
5534: }
1.19 raeburn 5535: SCRIPTTOP
5536: if ($mode ne 'upload') {
5537: $dc_setcourse_code .= (<<"ENDSCRIPT");
5538: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
5539: var numcourse = getIndex(document.$formname.dccourse);
5540: if (numcourse == "-1") {
1.103 raeburn 5541: if (document.$formname.type == 'Community') {
5542: alert("$alerts{'thwc'}");
5543: } else {
5544: alert("$alerts{'thwa'}");
5545: }
1.19 raeburn 5546: return;
5547: }
5548: else {
5549: document.$formname.elements[numcourse].name = "act"+coursename;
5550: var numnewsec = getIndex(document.$formname.newsec);
5551: if (numnewsec != "-1") {
5552: document.$formname.elements[numnewsec].name = "sec"+coursename;
5553: document.$formname.elements[numnewsec].value = section;
5554: }
5555: var numstart = getIndex(document.$formname.start);
5556: if (numstart != "-1") {
5557: document.$formname.elements[numstart].name = "start"+coursename;
5558: }
5559: var numend = getIndex(document.$formname.end);
5560: if (numend != "-1") {
5561: document.$formname.elements[numend].name = "end"+coursename
5562: }
5563: }
5564: }
1.37 raeburn 5565: var authcheck = auth_check();
5566: if (authcheck == 'ok') {
5567: document.$formname.submit();
5568: }
1.19 raeburn 5569: }
5570: ENDSCRIPT
5571: } else {
5572: $dc_setcourse_code .= "
5573: document.$formname.sections.value = section;
5574: }
5575: return 'ok';
5576: }
5577: ";
5578: }
5579: $dc_setcourse_code .= (<<"ENDSCRIPT");
5580:
5581: function getIndex(caller) {
5582: for (var i=0;i<document.$formname.elements.length;i++) {
5583: if (document.$formname.elements[i] == caller) {
5584: return i;
5585: }
5586: }
5587: return -1;
5588: }
5589: ENDSCRIPT
1.37 raeburn 5590: return $dc_setcourse_code;
5591: }
5592:
5593: sub verify_authen {
5594: my ($formname,$context) = @_;
5595: my %alerts = &authcheck_alerts();
5596: my $finish = "return 'ok';";
5597: if ($context eq 'author') {
5598: $finish = "document.$formname.submit();";
5599: }
5600: my $outcome = <<"ENDSCRIPT";
5601:
5602: function auth_check() {
5603: var logintype;
5604: if (document.$formname.login.length) {
5605: if (document.$formname.login.length > 0) {
5606: var loginpicked = 0;
5607: for (var i=0; i<document.$formname.login.length; i++) {
5608: if (document.$formname.login[i].checked == true) {
5609: loginpicked = 1;
5610: logintype = document.$formname.login[i].value;
5611: }
5612: }
5613: if (loginpicked == 0) {
5614: alert("$alerts{'authen'}");
5615: return;
5616: }
5617: }
5618: } else {
5619: logintype = document.$formname.login.value;
5620: }
5621: if (logintype == 'nochange') {
5622: return 'ok';
5623: }
5624: var argpicked = document.$formname.elements[logintype+'arg'].value;
5625: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
5626: var alertmsg = '';
5627: switch (logintype) {
5628: case 'krb':
5629: alertmsg = '$alerts{'krb'}';
5630: break;
5631: case 'int':
5632: alertmsg = '$alerts{'ipass'}';
5633: case 'fsys':
5634: alertmsg = '$alerts{'ipass'}';
5635: break;
5636: case 'loc':
5637: alertmsg = '';
5638: break;
5639: default:
5640: alertmsg = '';
5641: }
5642: if (alertmsg != '') {
5643: alert(alertmsg);
5644: return;
5645: }
5646: }
5647: $finish
5648: }
5649: ENDSCRIPT
1.19 raeburn 5650: }
5651:
5652: sub sectioncheck_alerts {
5653: my %alerts = &Apache::lonlocal::texthash(
1.103 raeburn 5654: curd => 'You must select a course or community in the current domain',
1.19 raeburn 5655: inea => 'In each course, each user may only have one student role at a time',
1.103 raeburn 5656: inco => 'In each community, each user may only have one member role at a time',
1.19 raeburn 5657: youh => 'You had selected',
5658: sect => 'sections',
5659: plsm => 'Please modify your selections so they include no more than one section',
5660: mayn => 'may not be used as the name for a section, as it is a reserved word',
5661: plsc => 'Please choose a different section name',
5662: mayt => 'may not be used as the name for a section, as it is the name of a course group',
1.103 raeburn 5663: mayc => 'may not be used as the name for a section, as it is the name of a community group',
1.19 raeburn 5664: secn => 'Section names and group names must be distinct',
5665: secd => 'Section designations do not apply to ',
5666: role => 'roles',
5667: accr => 'role will be added with access to all sections',
1.103 raeburn 5668: thwa => 'There was a problem with your course selection',
5669: thwc => 'There was a problem with your community selection',
1.19 raeburn 5670: );
5671: return %alerts;
5672: }
1.17 raeburn 5673:
1.37 raeburn 5674: sub authcheck_alerts {
5675: my %alerts =
5676: &Apache::lonlocal::texthash(
5677: authen => 'You must choose an authentication type.',
5678: krb => 'You need to specify the Kerberos domain.',
5679: ipass => 'You need to specify the initial password.',
5680: );
5681: return %alerts;
5682: }
5683:
1.1 raeburn 5684: 1;
5685:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>