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