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