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