Annotation of loncom/interface/lonuserutils.pm, revision 1.100
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.100 ! raeburn 4: # $Id: lonuserutils.pm,v 1.99 2009/09/05 01:13:02 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ###############################################################
30:
31: package Apache::lonuserutils;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonhtmlcommon;
37: use Apache::lonlocal;
1.8 raeburn 38: use Apache::longroup;
39: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 40:
41: ###############################################################
42: ###############################################################
43: # Drop student from all sections of a course, except optional $csec
44: sub modifystudent {
1.52 raeburn 45: my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
1.1 raeburn 46: # if $csec is undefined, drop the student from all the courses matching
47: # this one. If $csec is defined, drop them from all other sections of
48: # this course and add them to section $csec
1.17 raeburn 49: my ($cnum,$cdom) = &get_course_identity($courseid);
1.1 raeburn 50: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
51: my ($tmp) = keys(%roles);
52: # Bail out if we were unable to get the students roles
53: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
54: # Go through the roles looking for enrollment in this course
55: my $result = '';
56: foreach my $course (keys(%roles)) {
57: if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
58: # We are in this course
59: my $section=$1;
60: $section='' if ($course eq "/$cdom/$cnum".'_st');
61: if (defined($csec) && $section eq $csec) {
62: $result .= 'ok:';
63: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
64: my (undef,$end,$start)=split(/\_/,$roles{$course});
65: my $now=time;
66: # if this is an active role
67: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
68: my $reply=&Apache::lonnet::modifystudent
69: # dom name id mode pass f m l g
70: ($udom,$unam,'', '', '',undef,undef,undef,undef,
1.22 raeburn 71: $section,time,undef,undef,$desiredhost,'','manual',
1.52 raeburn 72: '',$courseid,'',$context);
1.1 raeburn 73: $result .= $reply.':';
74: }
75: }
76: }
77: }
78: if ($result eq '') {
1.37 raeburn 79: $result = &mt('Unable to find section for this student');
1.1 raeburn 80: } else {
81: $result =~ s/(ok:)+/ok/g;
82: }
83: return $result;
84: }
85:
86: sub modifyuserrole {
87: my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
88: $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
1.84 raeburn 89: $end,$start,$checkid,$inststatus) = @_;
1.5 raeburn 90: my ($scope,$userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 91: if ($setting eq 'course' || $context eq 'course') {
92: $scope = '/'.$cid;
93: $scope =~ s/\_/\//g;
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.98 raeburn 2125: if (target == 'track') {
2126: if (document.$formname.userwin.checked == true) {
2127: var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
2128: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2129: var trackwin = window.open(url,'',options,1);
2130: trackwin.focus();
2131: return;
2132: } else {
2133: document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
2134: }
2135: }
1.10 raeburn 2136: }
1.96 bisitz 2137: // ]]>
1.10 raeburn 2138: </script>
1.11 raeburn 2139: $date_sec_selector
1.1 raeburn 2140: <input type="hidden" name="state" value="$env{'form.state'}" />
2141: END
2142: }
2143: $r->print(<<END);
2144: <input type="hidden" name="sortby" value="$sortby" />
2145: END
2146:
2147: my %lt=&Apache::lonlocal::texthash(
2148: 'username' => "username",
2149: 'domain' => "domain",
2150: 'id' => 'ID',
2151: 'fullname' => "name",
2152: 'section' => "section",
2153: 'groups' => "active groups",
2154: 'start' => "start date",
2155: 'end' => "end date",
2156: 'status' => "status",
1.2 raeburn 2157: 'role' => "role",
1.1 raeburn 2158: 'type' => "enroll type/action",
1.79 schafran 2159: 'email' => "e-mail address",
1.1 raeburn 2160: 'photo' => "photo",
1.2 raeburn 2161: 'extent' => "extent",
1.11 raeburn 2162: 'pr' => "Proceed",
2163: 'ca' => "check all",
2164: 'ua' => "uncheck all",
2165: 'ac' => "Action to take for selected users",
1.56 raeburn 2166: 'link' => "Behavior of clickable username link for each user",
1.82 weissno 2167: 'aboutme' => "Display a user's personal information page",
1.50 raeburn 2168: 'owin' => "Open in a new window",
1.10 raeburn 2169: 'modify' => "Modify a user's information",
1.98 raeburn 2170: 'track' => "View a user's recent activity",
1.67 droeschl 2171: 'clicker' => "Clicker-ID",
1.1 raeburn 2172: );
1.2 raeburn 2173: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2174: $lt{'extent'} = &mt('Course(s): description, section(s), status');
1.13 raeburn 2175: } elsif ($context eq 'author') {
1.2 raeburn 2176: $lt{'extent'} = &mt('Author');
2177: }
1.55 raeburn 2178: my @cols;
2179: if ($mode eq 'pickauthor') {
2180: @cols = ('username','fullname','status','email');
2181: } else {
2182: @cols = ('username','domain','id','fullname');
2183: if ($context eq 'course') {
2184: push(@cols,'section');
2185: }
2186: if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
2187: push(@cols,('start','end'));
2188: }
2189: if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
2190: push(@cols,'role');
2191: }
2192: if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
2193: $env{'form.roletype'} eq 'course')) {
2194: push (@cols,'extent');
2195: }
2196: if (($statusmode eq 'Any') &&
2197: (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
2198: push(@cols,'status');
2199: }
2200: if ($context eq 'course') {
2201: push(@cols,'groups');
2202: }
2203: push(@cols,'email');
1.2 raeburn 2204: }
1.1 raeburn 2205:
1.4 raeburn 2206: my $rolefilter = $env{'form.showrole'};
1.5 raeburn 2207: if ($env{'form.showrole'} eq 'cr') {
2208: $rolefilter = &mt('custom');
2209: } elsif ($env{'form.showrole'} ne 'Any') {
1.2 raeburn 2210: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
2211: }
1.16 raeburn 2212: my $results_description;
2213: if ($mode ne 'autoenroll') {
2214: $results_description = &results_header_row($rolefilter,$statusmode,
1.24 raeburn 2215: $context,$permission,$mode);
1.56 raeburn 2216: $r->print('<b>'.$results_description.'</b><br /><br />');
1.16 raeburn 2217: }
1.26 raeburn 2218: my ($output,$actionselect,%canchange,%canchangesec);
1.55 raeburn 2219: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
2220: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.16 raeburn 2221: if ($permission->{'cusr'}) {
1.55 raeburn 2222: $actionselect = &select_actions($context,$setting,$statusmode,$formname);
1.16 raeburn 2223: }
2224: $r->print(<<END);
1.10 raeburn 2225: <input type="hidden" name="srchby" value="uname" />
2226: <input type="hidden" name="srchin" value="dom" />
2227: <input type="hidden" name="srchtype" value="exact" />
2228: <input type="hidden" name="srchterm" value="" />
1.11 raeburn 2229: <input type="hidden" name="srchdomain" value="" />
1.1 raeburn 2230: END
1.16 raeburn 2231: if ($actionselect) {
1.41 raeburn 2232: $output .= <<"END";
1.94 bisitz 2233: <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
1.56 raeburn 2234: $actionselect
2235: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
2236: <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 2237: END
1.26 raeburn 2238: my @allroles;
2239: if ($env{'form.showrole'} eq 'Any') {
2240: my $custom = 1;
2241: if ($context eq 'domain') {
2242: @allroles = &roles_by_context($setting,$custom);
2243: } else {
2244: @allroles = &roles_by_context($context,$custom);
2245: }
2246: } else {
2247: @allroles = ($env{'form.showrole'});
2248: }
2249: foreach my $role (@allroles) {
2250: if ($context eq 'domain') {
2251: if ($setting eq 'domain') {
2252: if (&Apache::lonnet::allowed('c'.$role,
2253: $env{'request.role.domain'})) {
2254: $canchange{$role} = 1;
2255: }
1.31 raeburn 2256: } elsif ($setting eq 'author') {
2257: if (&Apache::lonnet::allowed('c'.$role,
2258: $env{'request.role.domain'})) {
2259: $canchange{$role} = 1;
2260: }
1.26 raeburn 2261: }
2262: } elsif ($context eq 'author') {
2263: if (&Apache::lonnet::allowed('c'.$role,
2264: $env{'user.domain'}.'/'.$env{'user.name'})) {
2265: $canchange{$role} = 1;
2266: }
2267: } elsif ($context eq 'course') {
2268: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2269: $canchange{$role} = 1;
2270: } elsif ($env{'request.course.sec'} ne '') {
2271: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
2272: $canchangesec{$role} = $env{'request.course.sec'};
2273: }
2274: }
2275: }
2276: }
1.16 raeburn 2277: }
1.94 bisitz 2278: $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
1.56 raeburn 2279: '<table><tr>';
2280: my @linkdests = ('aboutme');
2281: if ($permission->{'cusr'}) {
2282: unshift (@linkdests,'modify');
2283: }
1.98 raeburn 2284: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
2285: &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
2286: $env{'request.course.sec'})) {
2287: push(@linkdests,'track');
2288: }
2289:
1.56 raeburn 2290: $output .= '<td>';
2291: my $usernamelink = $env{'form.usernamelink'};
2292: if ($usernamelink eq '') {
2293: $usernamelink = 'aboutme';
2294: }
2295: foreach my $item (@linkdests) {
2296: my $checkedstr = '';
2297: if ($item eq $usernamelink) {
1.86 bisitz 2298: $checkedstr = ' checked="checked"';
1.56 raeburn 2299: }
1.86 bisitz 2300: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
1.56 raeburn 2301: }
2302: my $checkwin;
2303: if ($env{'form.userwin'}) {
1.86 bisitz 2304: $checkwin = ' checked="checked"';
1.56 raeburn 2305: }
1.86 bisitz 2306: $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 2307: }
1.56 raeburn 2308: $output .= "\n".'<div class="LC_clear_float_footer"> </div>'."\n".
1.1 raeburn 2309: &Apache::loncommon::start_data_table().
1.4 raeburn 2310: &Apache::loncommon::start_data_table_header_row();
1.1 raeburn 2311: if ($mode eq 'autoenroll') {
1.4 raeburn 2312: $output .= "
1.55 raeburn 2313: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
1.4 raeburn 2314: ";
1.1 raeburn 2315: } else {
1.55 raeburn 2316: if ($mode eq 'pickauthor') {
2317: $output .= "\n".'<th> </th>'."\n";
2318: } else {
2319: $output .= "\n".'<th>'.&mt('Count').'</th>'."\n";
2320: }
1.11 raeburn 2321: if ($actionselect) {
2322: $output .= '<th>'.&mt('Select').'</th>'."\n";
2323: }
1.1 raeburn 2324: }
2325: foreach my $item (@cols) {
1.55 raeburn 2326: $output .= "<th><a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\">$lt{$item}</a></th>\n";
1.1 raeburn 2327: }
1.2 raeburn 2328: my %role_types = &role_type_names();
1.16 raeburn 2329: if ($context eq 'course' && $mode ne 'autoenroll') {
1.4 raeburn 2330: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2331: # Clicker display on or off?
1.58 bisitz 2332: my %clicker_options = (
2333: 'on' => 'Show',
2334: 'off' => 'Hide',
2335: );
1.4 raeburn 2336: my $clickerchg = 'on';
2337: if ($displayclickers eq 'on') {
2338: $clickerchg = 'off';
2339: }
1.58 bisitz 2340: $output .= ' <th>'."\n".' '
2341: .&mt('[_1]'.$clicker_options{$clickerchg}.'[_2] clicker id'
2342: ,'<a href="javascript:document.'.$formname.'.displayclickers.value='
2343: ."'".$clickerchg."'".';document.'.$formname.'.submit();">'
2344: ,'</a>')
2345: ."\n".' </th>'."\n";
1.1 raeburn 2346:
1.4 raeburn 2347: # Photo display on or off?
2348: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2349: my %photo_options = &Apache::lonlocal::texthash(
2350: 'on' => 'Show',
2351: 'off' => 'Hide',
2352: );
2353: my $photochg = 'on';
2354: if ($displayphotos eq 'on') {
2355: $photochg = 'off';
2356: }
2357: $output .= ' <th>'."\n".' '.
1.55 raeburn 2358: '<a href="javascript:document.'.$formname.'.displayphotos.value='.
2359: "'".$photochg."'".';document.'.$formname.'.submit();">'.
1.1 raeburn 2360: $photo_options{$photochg}.'</a> '.$lt{'photo'}."\n".
1.4 raeburn 2361: ' </th>'."\n";
2362: }
1.1 raeburn 2363: }
1.4 raeburn 2364: }
1.16 raeburn 2365: $output .= &Apache::loncommon::end_data_table_header_row();
1.1 raeburn 2366: # Done with the HTML header line
2367: } elsif ($mode eq 'csv') {
2368: #
2369: # Open a file
2370: $CSVfilename = '/prtspool/'.
1.2 raeburn 2371: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
2372: time.'_'.rand(1000000000).'.csv';
1.1 raeburn 2373: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
2374: $r->log_error("Couldn't open $CSVfilename for output $!");
1.69 bisitz 2375: $r->print(&mt('Problems occurred in writing the CSV file. '
1.64 bisitz 2376: .'This error has been logged. '
2377: .'Please alert your LON-CAPA administrator.'));
1.1 raeburn 2378: $CSVfile = undef;
2379: }
2380: #
1.67 droeschl 2381: push @cols,'clicker';
1.1 raeburn 2382: # Write headers and data to file
1.2 raeburn 2383: print $CSVfile '"'.$results_description.'"'."\n";
1.1 raeburn 2384: print $CSVfile '"'.join('","',map {
2385: &Apache::loncommon::csv_translate($lt{$_})
1.67 droeschl 2386: } (@cols))."\"\n";
1.1 raeburn 2387: } elsif ($mode eq 'excel') {
1.67 droeschl 2388: push @cols,'clicker';
1.1 raeburn 2389: # Create the excel spreadsheet
2390: ($excel_workbook,$excel_filename,$format) =
2391: &Apache::loncommon::create_workbook($r);
2392: return if (! defined($excel_workbook));
2393: $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2 raeburn 2394: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1 raeburn 2395: #
2396: my @colnames = map {$lt{$_}} (@cols);
1.67 droeschl 2397:
1.1 raeburn 2398: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
2399: }
2400:
2401: # Done with header lines in all formats
2402: my %index;
2403: my $i;
1.2 raeburn 2404: foreach my $idx (@$keylist) {
2405: $index{$idx} = $i++;
2406: }
1.4 raeburn 2407: my $usercount = 0;
1.33 raeburn 2408: my ($secfilter,$grpfilter);
2409: if ($context eq 'course') {
2410: $secfilter = $env{'form.secfilter'};
2411: $grpfilter = $env{'form.grpfilter'};
2412: if ($secfilter eq '') {
2413: $secfilter = 'all';
2414: }
2415: if ($grpfilter eq '') {
2416: $grpfilter = 'all';
2417: }
2418: }
1.83 raeburn 2419: my %ltstatus = &Apache::lonlocal::texthash(
2420: Active => 'Active',
2421: Future => 'Future',
2422: Expired => 'Expired',
2423: );
1.2 raeburn 2424: # Get groups, role, permanent e-mail so we can sort on them if
2425: # necessary.
2426: foreach my $user (keys(%{$userlist})) {
1.43 raeburn 2427: if ($user eq '' ) {
2428: delete($userlist->{$user});
2429: next;
2430: }
1.11 raeburn 2431: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
2432: delete($userlist->{$user});
2433: next;
2434: }
1.2 raeburn 2435: my ($uname,$udom,$role,$groups,$email);
1.5 raeburn 2436: if (($statusmode ne 'Any') &&
2437: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
2438: delete($userlist->{$user});
2439: next;
2440: }
1.2 raeburn 2441: if ($context eq 'domain') {
2442: if ($env{'form.roletype'} eq 'domain') {
2443: ($role,$uname,$udom) = split(/:/,$user);
1.11 raeburn 2444: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
2445: ($udom eq $env{'request.role.domain'})) {
2446: delete($userlist->{$user});
2447: next;
2448: }
1.13 raeburn 2449: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2450: ($uname,$udom,$role) = split(/:/,$user,-1);
2451: } elsif ($env{'form.roletype'} eq 'course') {
2452: ($uname,$udom,$role) = split(/:/,$user);
2453: }
2454: } else {
2455: ($uname,$udom,$role) = split(/:/,$user,-1);
2456: if (($context eq 'course') && $role eq '') {
2457: $role = 'st';
2458: }
2459: }
2460: $userlist->{$user}->[$index{'role'}] = $role;
2461: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
2462: delete($userlist->{$user});
2463: next;
2464: }
1.33 raeburn 2465: if ($context eq 'course') {
2466: my @ac_groups;
2467: if (ref($classgroups) eq 'HASH') {
2468: $groups = $classgroups->{$user};
2469: }
2470: if (ref($groups->{'active'}) eq 'HASH') {
2471: @ac_groups = keys(%{$groups->{'active'}});
2472: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
2473: }
2474: if ($mode ne 'autoenroll') {
2475: my $section = $userlist->{$user}->[$index{'section'}];
1.43 raeburn 2476: if (($env{'request.course.sec'} ne '') &&
2477: ($section ne $env{'request.course.sec'})) {
2478: if ($role eq 'st') {
2479: delete($userlist->{$user});
2480: next;
2481: }
2482: }
1.33 raeburn 2483: if ($secfilter eq 'none') {
2484: if ($section ne '') {
2485: delete($userlist->{$user});
2486: next;
2487: }
2488: } elsif ($secfilter ne 'all') {
2489: if ($section ne $secfilter) {
2490: delete($userlist->{$user});
2491: next;
2492: }
2493: }
2494: if ($grpfilter eq 'none') {
2495: if (@ac_groups > 0) {
2496: delete($userlist->{$user});
2497: next;
2498: }
2499: } elsif ($grpfilter ne 'all') {
2500: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
2501: delete($userlist->{$user});
2502: next;
2503: }
2504: }
1.44 raeburn 2505: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2506: if (($displayphotos eq 'on') && ($role eq 'st')) {
2507: $userlist->{$user}->[$index{'photo'}] =
1.47 raeburn 2508: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
2509: $userlist->{$user}->[$index{'thumbnail'}] =
1.44 raeburn 2510: &Apache::lonnet::retrievestudentphoto($udom,$uname,
2511: 'gif','thumbnail');
2512: }
2513: }
1.33 raeburn 2514: }
1.2 raeburn 2515: }
2516: my %emails = &Apache::loncommon::getemails($uname,$udom);
2517: if ($emails{'permanentemail'} =~ /\S/) {
2518: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
2519: }
1.4 raeburn 2520: $usercount ++;
2521: }
2522: my $autocount = 0;
2523: my $manualcount = 0;
2524: my $lockcount = 0;
2525: my $unlockcount = 0;
2526: if ($usercount) {
2527: $r->print($output);
2528: } else {
2529: if ($mode eq 'autoenroll') {
2530: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2531: } else {
2532: return;
2533: }
1.1 raeburn 2534: }
1.2 raeburn 2535: #
2536: # Sort the users
1.1 raeburn 2537: my $index = $index{$sortby};
2538: my $second = $index{'username'};
2539: my $third = $index{'domain'};
1.2 raeburn 2540: my @sorted_users = sort {
2541: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
1.1 raeburn 2542: ||
1.2 raeburn 2543: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
2544: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
2545: } (keys(%$userlist));
1.4 raeburn 2546: my $rowcount = 0;
1.2 raeburn 2547: foreach my $user (@sorted_users) {
1.4 raeburn 2548: my %in;
1.2 raeburn 2549: my $sdata = $userlist->{$user};
1.4 raeburn 2550: $rowcount ++;
1.2 raeburn 2551: foreach my $item (@{$keylist}) {
2552: $in{$item} = $sdata->[$index{$item}];
2553: }
1.67 droeschl 2554: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
2555: if ($clickers!~/\w/) { $clickers='-'; }
2556: $in{'clicker'} = $clickers;
2557: my $role = $in{'role'};
1.2 raeburn 2558: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
2559: if (! defined($in{'start'}) || $in{'start'} == 0) {
2560: $in{'start'} = &mt('none');
2561: } else {
2562: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
1.1 raeburn 2563: }
1.2 raeburn 2564: if (! defined($in{'end'}) || $in{'end'} == 0) {
2565: $in{'end'} = &mt('none');
1.1 raeburn 2566: } else {
1.2 raeburn 2567: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
1.1 raeburn 2568: }
1.55 raeburn 2569: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 2570: $r->print(&Apache::loncommon::start_data_table_row());
1.11 raeburn 2571: my $checkval;
1.16 raeburn 2572: if ($mode eq 'autoenroll') {
2573: my $cellentry;
2574: if ($in{'type'} eq 'auto') {
2575: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'" /> Change</label>';
2576: $autocount ++;
2577: } else {
1.76 bisitz 2578: $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 2579: $manualcount ++;
2580: if ($in{'lockedtype'}) {
2581: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Unlock').'</label>';
2582: $unlockcount ++;
2583: } else {
2584: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Lock').'</label>';
2585: $lockcount ++;
1.11 raeburn 2586: }
1.76 bisitz 2587: $cellentry .= '</span></td></tr></table>';
1.16 raeburn 2588: }
2589: $r->print("<td>$cellentry</td>\n");
2590: } else {
1.55 raeburn 2591: if ($mode ne 'pickauthor') {
2592: $r->print("<td>$rowcount</td>\n");
2593: }
1.16 raeburn 2594: if ($actionselect) {
1.26 raeburn 2595: my $showcheckbox;
2596: if ($role =~ /^cr\//) {
2597: $showcheckbox = $canchange{'cr'};
2598: } else {
2599: $showcheckbox = $canchange{$role};
2600: }
2601: if (!$showcheckbox) {
2602: if ($context eq 'course') {
2603: if ($canchangesec{$role} ne '') {
2604: if ($canchangesec{$role} eq $in{'section'}) {
2605: $showcheckbox = 1;
2606: }
2607: }
1.16 raeburn 2608: }
1.26 raeburn 2609: }
2610: if ($showcheckbox) {
2611: $checkval = $user;
2612: if ($context eq 'course') {
2613: if ($role eq 'st') {
2614: $checkval .= ':st';
2615: }
2616: $checkval .= ':'.$in{'section'};
2617: if ($role eq 'st') {
2618: $checkval .= ':'.$in{'type'}.':'.
2619: $in{'lockedtype'};
2620: }
1.16 raeburn 2621: }
1.26 raeburn 2622: $r->print('<td><input type="checkbox" name="'.
1.86 bisitz 2623: 'actionlist" value="'.$checkval.'" /></td>');
1.26 raeburn 2624: } else {
2625: $r->print('<td> </td>');
1.16 raeburn 2626: }
1.55 raeburn 2627: } elsif ($mode eq 'pickauthor') {
2628: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
1.11 raeburn 2629: }
2630: }
1.2 raeburn 2631: foreach my $item (@cols) {
1.10 raeburn 2632: if ($item eq 'username') {
1.48 raeburn 2633: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.16 raeburn 2634: } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) {
1.11 raeburn 2635: $r->print('<td>'.$in{$item}.'<input type="hidden" name="'.$checkval.'_'.$item.'" value="'.$sdata->[$index{$item}].'" /></td>'."\n");
1.83 raeburn 2636: } elsif ($item eq 'status') {
2637: my $showitem = $in{$item};
2638: if (defined($ltstatus{$in{$item}})) {
2639: $showitem = $ltstatus{$in{$item}};
2640: }
2641: $r->print('<td>'.$showitem.'</td>'."\n");
1.10 raeburn 2642: } else {
2643: $r->print('<td>'.$in{$item}.'</td>'."\n");
2644: }
1.2 raeburn 2645: }
1.16 raeburn 2646: if (($context eq 'course') && ($mode ne 'autoenroll')) {
1.4 raeburn 2647: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2648: if ($displayclickers eq 'on') {
2649: my $clickers =
1.2 raeburn 2650: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
1.4 raeburn 2651: if ($clickers!~/\w/) { $clickers='-'; }
2652: $r->print('<td>'.$clickers.'</td>');
1.2 raeburn 2653: } else {
2654: $r->print(' <td> </td> ');
2655: }
1.4 raeburn 2656: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1.44 raeburn 2657: if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {
1.90 bisitz 2658: $r->print(' <td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
1.4 raeburn 2659: } else {
2660: $r->print(' <td> </td> ');
2661: }
2662: }
1.2 raeburn 2663: }
2664: }
2665: $r->print(&Apache::loncommon::end_data_table_row());
2666: } elsif ($mode eq 'csv') {
2667: next if (! defined($CSVfile));
2668: # no need to bother with $linkto
2669: if (! defined($in{'start'}) || $in{'start'} == 0) {
2670: $in{'start'} = &mt('none');
2671: } else {
2672: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2673: }
2674: if (! defined($in{'end'}) || $in{'end'} == 0) {
2675: $in{'end'} = &mt('none');
2676: } else {
2677: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2678: }
2679: my @line = ();
2680: foreach my $item (@cols) {
2681: push @line,&Apache::loncommon::csv_translate($in{$item});
2682: }
1.67 droeschl 2683: print $CSVfile '"'.join('","',@line)."\"\n";
1.2 raeburn 2684: } elsif ($mode eq 'excel') {
2685: my $col = 0;
2686: foreach my $item (@cols) {
2687: if ($item eq 'start' || $item eq 'end') {
2688: if (defined($item) && $item != 0) {
2689: $excel_sheet->write($row,$col++,
2690: &Apache::lonstathelpers::calc_serial($in{item}),
2691: $format->{'date'});
2692: } else {
2693: $excel_sheet->write($row,$col++,'none');
2694: }
2695: } else {
2696: $excel_sheet->write($row,$col++,$in{$item});
2697: }
2698: }
2699: $row++;
1.1 raeburn 2700: }
2701: }
1.55 raeburn 2702: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 2703: $r->print(&Apache::loncommon::end_data_table().'<br />');
2704: } elsif ($mode eq 'excel') {
2705: $excel_workbook->close();
1.68 droeschl 2706: $r->print(&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<p><a href="'.$excel_filename.'">','</a>')."</p>\n");
1.2 raeburn 2707: } elsif ($mode eq 'csv') {
2708: close($CSVfile);
1.68 droeschl 2709: $r->print(&mt('[_1]Your CSV file[_2] is ready for download.', '<p><a href="'.$CSVfilename.'">','</a>')."</p>\n");
1.2 raeburn 2710: $r->rflush();
2711: }
2712: if ($mode eq 'autoenroll') {
2713: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 2714: } else {
2715: return ($usercount);
1.2 raeburn 2716: }
1.1 raeburn 2717: }
2718:
1.56 raeburn 2719: sub bulkaction_javascript {
2720: my ($formname,$caller) = @_;
2721: my $docstart = 'document';
2722: if ($caller eq 'popup') {
2723: $docstart = 'opener.document';
2724: }
2725: my %lt = &Apache::lonlocal::texthash(
2726: acwi => 'Access will be set to start immediately',
2727: asyo => 'as you did not select an end date in the pop-up window',
2728: accw => 'Access will be set to continue indefinitely',
2729: asyd => 'as you did not select an end date in the pop-up window',
2730: sewi => "Sections will be switched to 'No section'",
2731: ayes => "as you either selected the 'No section' option",
2732: oryo => 'or you did not select a section in the pop-up window',
2733: arol => 'A role with no section will be added',
2734: swbs => 'Sections will be switched to:',
2735: rwba => 'Roles will be added for section(s):',
2736: );
2737: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
2738: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
2739: my $singconfirm = &mt(' for a single user?');
2740: my $multconfirm = &mt(' for multiple users?');
2741: my $output = <<"ENDJS";
2742: function verify_action (field) {
2743: var numchecked = 0;
2744: var singconf = '$singconfirm';
2745: var multconf = '$multconfirm';
2746: if ($docstart.$formname.elements[field].length > 0) {
2747: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
2748: if ($docstart.$formname.elements[field][i].checked == true) {
2749: numchecked ++;
2750: }
2751: }
2752: } else {
2753: if ($docstart.$formname.elements[field].checked == true) {
2754: numchecked ++;
2755: }
2756: }
2757: if (numchecked == 0) {
2758: alert("$alert");
2759: return;
2760: } else {
2761: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
2762: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
2763: if (choice == '') {
2764: alert("$noaction");
2765: return;
2766: } else {
2767: if (numchecked == 1) {
2768: message += singconf;
2769: } else {
2770: message += multconf;
2771: }
2772: ENDJS
2773: if ($caller ne 'popup') {
2774: $output .= <<"NEWWIN";
2775: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
2776: opendatebrowser(document.$formname,'$formname','go');
2777: return;
2778:
2779: } else {
2780: if (confirm(message)) {
2781: document.$formname.phase.value = 'bulkchange';
2782: document.$formname.submit();
2783: return;
2784: }
2785: }
2786: NEWWIN
2787: } else {
2788: $output .= <<"POPUP";
2789: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
2790: var datemsg = '';
2791: if (($docstart.$formname.startdate_month.value == '') &&
2792: ($docstart.$formname.startdate_day.value == '') &&
2793: ($docstart.$formname.startdate_year.value == '')) {
2794: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
2795: }
2796: if (($docstart.$formname.enddate_month.value == '') &&
2797: ($docstart.$formname.enddate_day.value == '') &&
2798: ($docstart.$formname.enddate_year.value == '')) {
2799: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
2800: }
2801: if (datemsg != '') {
2802: message += "\\n"+datemsg;
2803: }
2804: }
2805: if (choice == 'chgsec') {
2806: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
2807: var retained = $docstart.$formname.retainsec.value;
2808: var secshow = $docstart.$formname.newsecs.value;
2809: if (secshow == '') {
2810: if (rolefilter == 'st' || retained == 0 || retained == "") {
2811: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
2812: } else {
2813: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
2814: }
2815: } else {
2816: if (rolefilter == 'st' || retained == 0 || retained == "") {
2817: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
2818: } else {
2819: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
2820: }
2821: }
2822: }
2823: if (confirm(message)) {
2824: $docstart.$formname.phase.value = 'bulkchange';
2825: $docstart.$formname.submit();
2826: window.close();
2827: }
2828: POPUP
2829: }
2830: $output .= '
2831: }
2832: }
2833: }
2834: ';
2835: return $output;
2836: }
2837:
1.10 raeburn 2838: sub print_username_link {
1.48 raeburn 2839: my ($mode,$in) = @_;
1.10 raeburn 2840: my $output;
1.16 raeburn 2841: if ($mode eq 'autoenroll') {
2842: $output = $in->{'username'};
1.10 raeburn 2843: } else {
2844: $output = '<a href="javascript:username_display_launch('.
2845: "'$in->{'username'}','$in->{'domain'}'".')" />'.
2846: $in->{'username'}.'</a>';
2847: }
2848: return $output;
2849: }
2850:
1.2 raeburn 2851: sub role_type_names {
2852: my %lt = &Apache::lonlocal::texthash (
1.13 raeburn 2853: 'domain' => 'Domain Roles',
2854: 'author' => 'Co-Author Roles',
2855: 'course' => 'Course Roles',
1.2 raeburn 2856: );
2857: return %lt;
2858: }
2859:
1.11 raeburn 2860: sub select_actions {
1.55 raeburn 2861: my ($context,$setting,$statusmode,$formname) = @_;
1.11 raeburn 2862: my %lt = &Apache::lonlocal::texthash(
2863: revoke => "Revoke user roles",
2864: delete => "Delete user roles",
2865: reenable => "Re-enable expired user roles",
2866: activate => "Make future user roles active now",
2867: chgdates => "Change starting/ending dates",
2868: chgsec => "Change section associated with user roles",
2869: );
2870: my ($output,$options,%choices);
1.23 raeburn 2871: # FIXME Disable actions for now for roletype=course in domain context
2872: if ($context eq 'domain' && $setting eq 'course') {
2873: return;
2874: }
1.26 raeburn 2875: if ($context eq 'course') {
2876: if ($env{'form.showrole'} ne 'Any') {
2877: if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},
2878: $env{'request.course.id'})) {
2879: if ($env{'request.course.sec'} eq '') {
2880: return;
2881: } else {
2882: if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
2883: return;
2884: }
2885: }
2886: }
2887: }
2888: }
1.11 raeburn 2889: if ($statusmode eq 'Any') {
2890: $options .= '
2891: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
2892: $choices{'dates'} = 1;
2893: } else {
2894: if ($statusmode eq 'Future') {
2895: $options .= '
2896: <option value="activate">'.$lt{'activate'}.'</option>';
2897: $choices{'dates'} = 1;
2898: } elsif ($statusmode eq 'Expired') {
2899: $options .= '
2900: <option value="reenable">'.$lt{'reenable'}.'</option>';
2901: $choices{'dates'} = 1;
2902: }
1.13 raeburn 2903: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
2904: $options .= '
2905: <option value="chgdates">'.$lt{'chgdates'}.'</option>
2906: <option value="revoke">'.$lt{'revoke'}.'</option>';
2907: $choices{'dates'} = 1;
2908: }
1.11 raeburn 2909: }
2910: if ($context eq 'domain') {
2911: $options .= '
2912: <option value="delete">'.$lt{'delete'}.'</option>';
2913: }
2914: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26 raeburn 2915: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11 raeburn 2916: $options .= '
2917: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
2918: $choices{'sections'} = 1;
2919: }
2920: }
2921: if ($options) {
1.56 raeburn 2922: $output = '<select name="bulkaction">'."\n".
1.11 raeburn 2923: '<option value="" selected="selected">'.
2924: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
2925: if ($choices{'dates'}) {
2926: $output .=
2927: '<input type="hidden" name="startdate_month" value="" />'."\n".
2928: '<input type="hidden" name="startdate_day" value="" />'."\n".
2929: '<input type="hidden" name="startdate_year" value="" />'."\n".
2930: '<input type="hidden" name="startdate_hour" value="" />'."\n".
2931: '<input type="hidden" name="startdate_minute" value="" />'."\n".
2932: '<input type="hidden" name="startdate_second" value="" />'."\n".
2933: '<input type="hidden" name="enddate_month" value="" />'."\n".
2934: '<input type="hidden" name="enddate_day" value="" />'."\n".
2935: '<input type="hidden" name="enddate_year" value="" />'."\n".
2936: '<input type="hidden" name="enddate_hour" value="" />'."\n".
2937: '<input type="hidden" name="enddate_minute" value="" />'."\n".
1.56 raeburn 2938: '<input type="hidden" name="enddate_second" value="" />'."\n".
2939: '<input type="hidden" name="no_end_date" value="" />'."\n";
1.11 raeburn 2940: if ($context eq 'course') {
2941: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
2942: }
2943: }
2944: if ($choices{'sections'}) {
1.91 bisitz 2945: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
2946: '<input type="hidden" name="newsecs" value="" />'."\n";
1.11 raeburn 2947: }
2948: }
2949: return $output;
2950: }
2951:
2952: sub date_section_javascript {
2953: my ($context,$setting) = @_;
1.49 raeburn 2954: my $title = 'Date_And_Section_Selector';
1.41 raeburn 2955: my %nopopup = &Apache::lonlocal::texthash (
2956: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
2957: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
2958: none => "Choose an action to take for selected users",
2959: );
1.96 bisitz 2960: my $output = <<"ENDONE";
2961: <script type="text/javascript">
2962: // <![CDATA[
1.41 raeburn 2963: function opendatebrowser(callingform,formname,calledby) {
1.11 raeburn 2964: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
2965: var url = '/adm/createuser?';
2966: var type = '';
2967: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
2968: ENDONE
2969: if ($context eq 'domain') {
2970: $output .= '
2971: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
2972: ';
2973: }
2974: my $width= '700';
2975: my $height = '400';
2976: $output .= <<"ENDTWO";
2977: url += 'action=dateselect&callingform=' + formname +
2978: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
2979: var title = '$title';
2980: var options = 'scrollbars=1,resizable=1,menubar=0';
2981: options += ',width=$width,height=$height';
2982: stdeditbrowser = open(url,title,options,'1');
2983: stdeditbrowser.focus();
2984: }
1.96 bisitz 2985: // ]]>
1.11 raeburn 2986: </script>
2987: ENDTWO
2988: return $output;
2989: }
2990:
2991: sub date_section_selector {
1.21 raeburn 2992: my ($context,$permission) = @_;
1.11 raeburn 2993: my $callingform = $env{'form.callingform'};
2994: my $formname = 'dateselect';
2995: my $groupslist = &get_groupslist();
2996: my $sec_js = &setsections_javascript($formname,$groupslist);
2997: my $output = <<"END";
2998: <script type="text/javascript">
1.96 bisitz 2999: // <![CDATA[
1.11 raeburn 3000:
3001: $sec_js
3002:
3003: function saveselections(formname) {
3004:
3005: END
3006: if ($env{'form.bulkaction'} eq 'chgsec') {
3007: $output .= <<"END";
1.40 raeburn 3008: if (formname.retainsec.length > 1) {
3009: for (var i=0; i<formname.retainsec.length; i++) {
3010: if (formname.retainsec[i].checked == true) {
3011: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
3012: }
3013: }
3014: } else {
3015: opener.document.$callingform.retainsec.value = formname.retainsec.value;
3016: }
1.11 raeburn 3017: setSections(formname);
3018: if (seccheck == 'ok') {
3019: opener.document.$callingform.newsecs.value = formname.sections.value;
3020: }
3021: END
3022: } else {
3023: if ($context eq 'course') {
3024: if (($env{'form.bulkaction'} eq 'reenable') ||
3025: ($env{'form.bulkaction'} eq 'activate') ||
3026: ($env{'form.bulkaction'} eq 'chgdates')) {
1.26 raeburn 3027: if ($env{'request.course.sec'} eq '') {
3028: $output .= <<"END";
1.11 raeburn 3029:
3030: if (formname.makedatesdefault.checked == true) {
3031: opener.document.$callingform.makedatesdefault.value = 1;
3032: }
3033: else {
3034: opener.document.$callingform.makedatesdefault.value = 0;
3035: }
3036:
3037: END
1.26 raeburn 3038: }
1.11 raeburn 3039: }
3040: }
3041: $output .= <<"END";
3042: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
3043: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
3044: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
3045: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
3046: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
3047: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
3048: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
3049: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
3050: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
3051: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
3052: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
3053: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
1.56 raeburn 3054: if (formname.no_end_date.checked) {
3055: opener.document.$callingform.no_end_date.value = '1';
3056: } else {
3057: opener.document.$callingform.no_end_date.value = '0';
3058: }
1.11 raeburn 3059: END
3060: }
1.56 raeburn 3061: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
3062: $output .= <<"ENDJS";
3063: verify_action('actionlist');
1.11 raeburn 3064: }
1.56 raeburn 3065:
3066: $verify_action_js
3067:
1.96 bisitz 3068: // ]]>
1.11 raeburn 3069: </script>
1.56 raeburn 3070: ENDJS
1.11 raeburn 3071: my %lt = &Apache::lonlocal::texthash (
3072: chac => 'Access dates to apply for selected users',
3073: chse => 'Changes in section affiliation to apply to selected users',
3074: 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.',
3075: 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.',
3076: reta => "Retain each user's current section affiliations?",
3077: dnap => '(Does not apply to student roles).',
3078: );
3079: my ($date_items,$headertext);
3080: if ($env{'form.bulkaction'} eq 'chgsec') {
3081: $headertext = $lt{'chse'};
3082: } else {
3083: $headertext = $lt{'chac'};
3084: my $starttime;
3085: if (($env{'form.bulkaction'} eq 'activate') ||
3086: ($env{'form.bulkaction'} eq 'reenable')) {
3087: $starttime = time;
3088: }
3089: $date_items = &date_setting_table($starttime,undef,$context,
1.21 raeburn 3090: $env{'form.bulkaction'},$formname,
3091: $permission);
1.11 raeburn 3092: }
3093: $output .= '<h3>'.$headertext.'</h3>'.
3094: '<form name="'.$formname.'" method="post">'."\n".
3095: $date_items;
3096: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17 raeburn 3097: my ($cnum,$cdom) = &get_course_identity();
1.11 raeburn 3098: my $info;
3099: if ($env{'form.showrole'} eq 'st') {
3100: $output .= '<p>'.$lt{'fors'}.'</p>';
1.26 raeburn 3101: } elsif ($env{'form.showrole'} eq 'Any') {
1.11 raeburn 3102: $output .= '<p>'.$lt{'fors'}.'</p>'.
3103: '<p>'.$lt{'forn'}.' ';
3104: $info = $lt{'reta'};
3105: } else {
3106: $output .= '<p>'.$lt{'forn'}.' ';
3107: $info = $lt{'reta'};
3108: }
3109: if ($info) {
3110: $info .= '<span class="LC_nobreak">'.
3111: '<label><input type="radio" name="retainsec" value="1" '.
3112: 'checked="checked" />'.&mt('Yes').'</label> '.
3113: '<label><input type="radio" name="retainsec" value="0" />'.
3114: &mt('No').'</label></span>';
3115: if ($env{'form.showrole'} eq 'Any') {
3116: $info .= '<br />'.$lt{'dnap'};
3117: }
3118: $info .= '</p>';
3119: } else {
3120: $info = '<input type="hidden" name="retainsec" value="0" />';
3121: }
1.21 raeburn 3122: my $rowtitle = &mt('New section to assign');
3123: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context);
1.11 raeburn 3124: $output .= $info.$secbox;
3125: }
3126: $output .= '<p>'.
1.81 schafran 3127: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
1.11 raeburn 3128: '</form>';
3129: return $output;
3130: }
3131:
1.17 raeburn 3132: sub section_picker {
3133: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode) = @_;
3134: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3135: my $sections_select .= &course_sections(\%sections_count,$role);
3136: my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
3137: if ($mode eq 'upload') {
3138: my ($options,$cb_script,$coursepick) =
3139: &default_role_selector($context,1);
1.59 bisitz 3140: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
1.17 raeburn 3141: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
3142: }
3143: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
3144: if ($env{'request.course.sec'} eq '') {
3145: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
3146: '<td align="center">'.&mt('Existing sections')."\n".
3147: '<br />'.$sections_select.'</td><td align="center">'.
3148: &mt('New section').'<br />'."\n".
3149: '<input type="text" name="newsec" size="15" />'."\n".
3150: '<input type="hidden" name="sections" value="" />'."\n".
3151: '</td></tr></table>'."\n";
3152: } else {
3153: $secbox .= '<input type="hidden" name="sections" value="'.
3154: $env{'request.course.sec'}.'" />'.
3155: $env{'request.course.sec'};
3156: }
3157: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n".
3158: &Apache::lonhtmlcommon::end_pick_box().'</p>';
3159: return $secbox;
3160: }
3161:
1.2 raeburn 3162: sub results_header_row {
1.24 raeburn 3163: my ($rolefilter,$statusmode,$context,$permission,$mode) = @_;
1.5 raeburn 3164: my ($description,$showfilter);
3165: if ($rolefilter ne 'Any') {
3166: $showfilter = $rolefilter;
3167: }
1.2 raeburn 3168: if ($context eq 'course') {
1.24 raeburn 3169: if ($mode eq 'csv' || $mode eq 'excel') {
1.73 bisitz 3170: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
1.24 raeburn 3171: }
1.2 raeburn 3172: if ($statusmode eq 'Expired') {
1.5 raeburn 3173: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
1.11 raeburn 3174: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3175: $description .= &mt('Users in course with future [_1] roles',$showfilter);
1.2 raeburn 3176: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3177: $description .= &mt('Users in course with active [_1] roles',$showfilter);
1.2 raeburn 3178: } else {
3179: if ($rolefilter eq 'Any') {
3180: $description .= &mt('All users in course');
3181: } else {
3182: $description .= &mt('All users in course with [_1] roles',$rolefilter);
3183: }
3184: }
1.33 raeburn 3185: my $constraint;
1.26 raeburn 3186: my $viewablesec = &viewable_section($permission);
3187: if ($viewablesec ne '') {
1.15 raeburn 3188: if ($env{'form.showrole'} eq 'st') {
1.33 raeburn 3189: $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.26 raeburn 3190: } elsif ($env{'form.showrole'} ne 'cc') {
1.33 raeburn 3191: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
3192: }
3193: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
3194: if ($env{'form.grpfilter'} eq 'none') {
3195: $constraint .= &mt(' and not in any group');
3196: } else {
3197: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
3198: }
3199: }
3200: } else {
3201: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
3202: if ($env{'form.secfilter'} eq 'none') {
3203: $constraint = &mt('only users affiliated with no section');
3204: } else {
3205: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
3206: }
3207: }
3208: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
3209: if ($env{'form.grpfilter'} eq 'none') {
3210: if ($constraint eq '') {
3211: $constraint = &mt('only users not in any group');
3212: } else {
3213: $constraint .= &mt(' and also not in any group');
3214: }
3215: } else {
3216: if ($constraint eq '') {
3217: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
3218: } else {
3219: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
3220: }
3221: }
1.15 raeburn 3222: }
3223: }
1.33 raeburn 3224: if ($constraint ne '') {
3225: $description .= ' ('.$constraint.')';
3226: }
1.13 raeburn 3227: } elsif ($context eq 'author') {
1.14 raeburn 3228: $description =
1.73 bisitz 3229: &mt('Author space for [_1]'
3230: ,'<span class="LC_cusr_emph">'
3231: .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})
3232: .'</span>')
3233: .': ';
1.2 raeburn 3234: if ($statusmode eq 'Expired') {
1.5 raeburn 3235: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 3236: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3237: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 3238: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3239: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 3240: } else {
3241: if ($rolefilter eq 'Any') {
1.5 raeburn 3242: $description .= &mt('All co-authors');
1.2 raeburn 3243: } else {
3244: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
3245: }
3246: }
3247: } elsif ($context eq 'domain') {
3248: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.73 bisitz 3249: $description = &mt('Domain - [_1]:',$domdesc).' ';
1.2 raeburn 3250: if ($env{'form.roletype'} eq 'domain') {
3251: if ($statusmode eq 'Expired') {
1.5 raeburn 3252: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 3253: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3254: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 3255: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3256: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 3257: } else {
3258: if ($rolefilter eq 'Any') {
1.5 raeburn 3259: $description .= &mt('All users in domain');
1.2 raeburn 3260: } else {
3261: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
3262: }
3263: }
1.13 raeburn 3264: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3265: if ($statusmode eq 'Expired') {
1.5 raeburn 3266: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 3267: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3268: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 3269: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3270: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 3271: } else {
3272: if ($rolefilter eq 'Any') {
1.5 raeburn 3273: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 3274: } else {
3275: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
3276: }
3277: }
3278: } elsif ($env{'form.roletype'} eq 'course') {
3279: my $coursefilter = $env{'form.coursepick'};
3280: if ($coursefilter eq 'category') {
3281: my $instcode = &instcode_from_coursefilter();
3282: if ($instcode eq '.') {
3283: $description .= &mt('All courses in domain').' - ';
3284: } else {
3285: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
3286: }
3287: } elsif ($coursefilter eq 'selected') {
3288: $description .= &mt('Selected courses in domain').' - ';
3289: } elsif ($coursefilter eq 'all') {
3290: $description .= &mt('All courses in domain').' - ';
3291: }
3292: if ($statusmode eq 'Expired') {
1.5 raeburn 3293: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 3294: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3295: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 3296: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3297: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 3298: } else {
3299: if ($rolefilter eq 'Any') {
3300: $description .= &mt('all users');
3301: } else {
3302: $description .= &mt('users with [_1] roles',$rolefilter);
3303: }
3304: }
3305: }
3306: }
3307: return $description;
3308: }
1.22 raeburn 3309:
3310: sub viewable_section {
3311: my ($permission) = @_;
3312: my $viewablesec;
3313: if (ref($permission) eq 'HASH') {
3314: if (exists($permission->{'view_section'})) {
3315: $viewablesec = $permission->{'view_section'};
3316: } elsif (exists($permission->{'cusr_section'})) {
3317: $viewablesec = $permission->{'cusr_section'};
3318: }
3319: }
3320: return $viewablesec;
3321: }
3322:
1.2 raeburn 3323:
1.1 raeburn 3324: #################################################
3325: #################################################
3326: sub show_drop_list {
1.30 raeburn 3327: my ($r,$classlist,$nosort,$permission) = @_;
1.29 raeburn 3328: my $cid = $env{'request.course.id'};
1.17 raeburn 3329: my ($cnum,$cdom) = &get_course_identity($cid);
1.1 raeburn 3330: if (! exists($env{'form.sortby'})) {
3331: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3332: ['sortby']);
3333: }
3334: my $sortby = $env{'form.sortby'};
3335: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
3336: $sortby = 'username';
3337: }
3338: my $action = "drop";
1.17 raeburn 3339: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1 raeburn 3340: $r->print(<<END);
3341: <input type="hidden" name="sortby" value="$sortby" />
3342: <input type="hidden" name="action" value="$action" />
3343: <input type="hidden" name="state" value="done" />
1.17 raeburn 3344: <script type="text/javascript" language="Javascript">
1.96 bisitz 3345: // <![CDATA[
1.17 raeburn 3346: $check_uncheck_js
1.96 bisitz 3347: // ]]>
1.1 raeburn 3348: </script>
3349: <p>
1.86 bisitz 3350: <input type="hidden" name="phase" value="four" />
1.1 raeburn 3351: END
1.30 raeburn 3352: my ($indexhash,$keylist) = &make_keylist_array();
3353: my $studentcount = 0;
3354: if (ref($classlist) eq 'HASH') {
3355: foreach my $student (keys(%{$classlist})) {
3356: my $sdata = $classlist->{$student};
3357: my $status = $sdata->[$indexhash->{'status'}];
3358: my $section = $sdata->[$indexhash->{'section'}];
3359: if ($status ne 'Active') {
3360: delete($classlist->{$student});
3361: next;
3362: }
3363: if ($env{'request.course.sec'} ne '') {
3364: if ($section ne $env{'request.course.sec'}) {
3365: delete($classlist->{$student});
3366: next;
3367: }
3368: }
3369: $studentcount ++;
3370: }
3371: }
3372: if (!$studentcount) {
3373: $r->print(&mt('There are no students to drop.'));
3374: return;
3375: }
3376: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3377: $classlist,$keylist,$cdom,$cnum);
3378: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
3379: 'dom' => "domain",
3380: 'sn' => "student name",
3381: 'sec' => "section",
3382: 'start' => "start date",
3383: 'end' => "end date",
3384: 'groups' => "active groups",
3385: );
1.1 raeburn 3386: if ($nosort) {
1.17 raeburn 3387: $r->print(&Apache::loncommon::start_data_table().
3388: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 3389: $r->print(<<END);
3390: <th> </th>
3391: <th>$lt{'usrn'}</th>
3392: <th>$lt{'dom'}</th>
3393: <th>ID</th>
3394: <th>$lt{'sn'}</th>
3395: <th>$lt{'sec'}</th>
3396: <th>$lt{'start'}</th>
3397: <th>$lt{'end'}</th>
3398: <th>$lt{'groups'}</th>
3399: END
1.17 raeburn 3400: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 3401: } else {
1.17 raeburn 3402: $r->print(&Apache::loncommon::start_data_table().
3403: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 3404: $r->print(<<END);
1.17 raeburn 3405: <th> </th>
1.1 raeburn 3406: <th>
1.17 raeburn 3407: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1 raeburn 3408: </th><th>
1.17 raeburn 3409: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1 raeburn 3410: </th><th>
1.17 raeburn 3411: <a href="/adm/createuser?action=$action&sortby=id">ID</a>
1.1 raeburn 3412: </th><th>
1.17 raeburn 3413: <a href="/adm/createuser?action=$action&sortby=fullname">$lt{'sn'}</a>
1.1 raeburn 3414: </th><th>
1.17 raeburn 3415: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1 raeburn 3416: </th><th>
1.17 raeburn 3417: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1 raeburn 3418: </th><th>
1.17 raeburn 3419: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1 raeburn 3420: </th><th>
1.17 raeburn 3421: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1 raeburn 3422: </th>
3423: END
1.17 raeburn 3424: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 3425: }
3426: #
3427: # Sort the students
1.30 raeburn 3428: my $index = $indexhash->{$sortby};
3429: my $second = $indexhash->{'username'};
3430: my $third = $indexhash->{'domain'};
1.1 raeburn 3431: my @Sorted_Students = sort {
3432: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
3433: ||
3434: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
3435: ||
3436: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30 raeburn 3437: } (keys(%{$classlist}));
1.1 raeburn 3438: foreach my $student (@Sorted_Students) {
3439: my $error;
3440: my $sdata = $classlist->{$student};
1.30 raeburn 3441: my $username = $sdata->[$indexhash->{'username'}];
3442: my $domain = $sdata->[$indexhash->{'domain'}];
3443: my $section = $sdata->[$indexhash->{'section'}];
3444: my $name = $sdata->[$indexhash->{'fullname'}];
3445: my $id = $sdata->[$indexhash->{'id'}];
3446: my $start = $sdata->[$indexhash->{'start'}];
3447: my $end = $sdata->[$indexhash->{'end'}];
1.1 raeburn 3448: my $groups = $classgroups->{$student};
3449: my $active_groups;
3450: if (ref($groups->{active}) eq 'HASH') {
3451: $active_groups = join(', ',keys(%{$groups->{'active'}}));
3452: }
3453: if (! defined($start) || $start == 0) {
3454: $start = &mt('none');
3455: } else {
3456: $start = &Apache::lonlocal::locallocaltime($start);
3457: }
3458: if (! defined($end) || $end == 0) {
3459: $end = &mt('none');
3460: } else {
3461: $end = &Apache::lonlocal::locallocaltime($end);
3462: }
1.17 raeburn 3463: my $studentkey = $student.':'.$section;
1.30 raeburn 3464: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1 raeburn 3465: #
3466: $r->print(&Apache::loncommon::start_data_table_row());
3467: $r->print(<<"END");
1.86 bisitz 3468: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
1.1 raeburn 3469: <td>$username</td>
3470: <td>$domain</td>
3471: <td>$id</td>
3472: <td>$name</td>
3473: <td>$section</td>
1.29 raeburn 3474: <td>$start $startitem</td>
1.1 raeburn 3475: <td>$end</td>
3476: <td>$active_groups</td>
3477: END
3478: $r->print(&Apache::loncommon::end_data_table_row());
3479: }
3480: $r->print(&Apache::loncommon::end_data_table().'<br />');
3481: %lt=&Apache::lonlocal::texthash(
1.29 raeburn 3482: 'dp' => "Drop Students",
1.1 raeburn 3483: 'ca' => "check all",
3484: 'ua' => "uncheck all",
3485: );
3486: $r->print(<<"END");
1.89 bisitz 3487: </p>
3488: <p>
1.86 bisitz 3489: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
3490: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
1.89 bisitz 3491: </p>
3492: <p>
3493: <input type="submit" value="$lt{'dp'}" />
3494: </p>
1.1 raeburn 3495: END
3496: return;
3497: }
3498:
3499: #
3500: # Print out the initial form to get the file containing a list of users
3501: #
3502: sub print_first_users_upload_form {
3503: my ($r,$context) = @_;
3504: my $str;
1.86 bisitz 3505: $str = '<input type="hidden" name="phase" value="two" />';
1.1 raeburn 3506: $str .= '<input type="hidden" name="action" value="upload" />';
3507: $str .= '<input type="hidden" name="state" value="got_file" />';
1.95 bisitz 3508:
1.85 bisitz 3509: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
1.95 bisitz 3510:
3511: # Excel and CSV Help
3512: $str .= '<p>'
3513: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
3514: &mt("How do I create a users list from a spreadsheet"))
3515: ."<br />\n"
3516: .&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3517: &mt("How do I create a CSV file from a spreadsheet"))
3518: ."</p>\n";
3519:
3520: $str .= &Apache::lonhtmlcommon::start_pick_box()
3521: .&Apache::lonhtmlcommon::row_title(&mt('File'))
3522: .'<p class="LC_info">'."\n"
3523: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
3524: .'</p>'."\n"
3525: .&Apache::loncommon::upfile_select_html()
3526: .&Apache::lonhtmlcommon::row_closure()
3527: .&Apache::lonhtmlcommon::row_title(
3528: '<label for="noFirstLine">'
3529: .&mt('Ignore First Line')
3530: .'</label>')
3531: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
3532: .&Apache::lonhtmlcommon::row_closure(1)
3533: .&Apache::lonhtmlcommon::end_pick_box();
3534:
3535: $str .= '<p>'
3536: .'<input type="submit" name="fileupload" value="'.&mt('Next').'" />'
3537: .'</p>';
3538:
1.1 raeburn 3539: $str .= &Apache::loncommon::end_page();
1.95 bisitz 3540:
1.1 raeburn 3541: $r->print($str);
3542: return;
3543: }
3544:
3545: # ================================================= Drop/Add from uploaded file
3546: sub upfile_drop_add {
1.21 raeburn 3547: my ($r,$context,$permission) = @_;
1.1 raeburn 3548: &Apache::loncommon::load_tmp_file($r);
3549: my @userdata=&Apache::loncommon::upfile_record_sep();
3550: if($env{'form.noFirstLine'}){shift(@userdata);}
3551: my @keyfields = split(/\,/,$env{'form.keyfields'});
3552: my %fields=();
3553: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3554: if ($env{'form.upfile_associate'} eq 'reverse') {
3555: if ($env{'form.f'.$i} ne 'none') {
3556: $fields{$keyfields[$i]}=$env{'form.f'.$i};
3557: }
3558: } else {
3559: $fields{$env{'form.f'.$i}}=$keyfields[$i];
3560: }
3561: }
1.29 raeburn 3562: if ($env{'form.fullup'} ne 'yes') {
3563: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
3564: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
3565: }
1.1 raeburn 3566: #
3567: # Store the field choices away
3568: foreach my $field (qw/username names
1.57 raeburn 3569: fname mname lname gen id sec ipwd email role domain/) {
1.1 raeburn 3570: $env{'form.'.$field.'_choice'}=$fields{$field};
3571: }
3572: &Apache::loncommon::store_course_settings('enrollment_upload',
3573: { 'username_choice' => 'scalar',
3574: 'names_choice' => 'scalar',
3575: 'fname_choice' => 'scalar',
3576: 'mname_choice' => 'scalar',
3577: 'lname_choice' => 'scalar',
3578: 'gen_choice' => 'scalar',
3579: 'id_choice' => 'scalar',
3580: 'sec_choice' => 'scalar',
3581: 'ipwd_choice' => 'scalar',
3582: 'email_choice' => 'scalar',
1.57 raeburn 3583: 'role_choice' => 'scalar',
1.84 raeburn 3584: 'domain_choice' => 'scalar',
3585: 'inststatus_choice' => 'scalar'});
1.1 raeburn 3586: #
3587: my ($startdate,$enddate) = &get_dates_from_form();
3588: if ($env{'form.makedatesdefault'}) {
1.27 raeburn 3589: $r->print(&make_dates_default($startdate,$enddate,$context));
1.1 raeburn 3590: }
3591: # Determine domain and desired host (home server)
1.57 raeburn 3592: my $defdom=$env{'request.role.domain'};
3593: my $domain;
3594: if ($env{'form.defaultdomain'} ne '') {
3595: $domain = $env{'form.defaultdomain'};
3596: } else {
3597: $domain = $defdom;
3598: }
1.1 raeburn 3599: my $desiredhost = $env{'form.lcserver'};
3600: if (lc($desiredhost) eq 'default') {
3601: $desiredhost = undef;
3602: } else {
1.57 raeburn 3603: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1 raeburn 3604: if (! exists($home_servers{$desiredhost})) {
3605: $r->print('<span class="LC_error">'.&mt('Error').
3606: &mt('Invalid home server specified').'</span>');
3607: $r->print(&Apache::loncommon::end_page());
3608: return;
3609: }
3610: }
3611: # Determine authentication mechanism
3612: my $changeauth;
3613: if ($context eq 'domain') {
3614: $changeauth = $env{'form.changeauth'};
3615: }
3616: my $amode = '';
3617: my $genpwd = '';
3618: if ($env{'form.login'} eq 'krb') {
3619: $amode='krb';
3620: $amode.=$env{'form.krbver'};
3621: $genpwd=$env{'form.krbarg'};
3622: } elsif ($env{'form.login'} eq 'int') {
3623: $amode='internal';
3624: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
3625: $genpwd=$env{'form.intarg'};
3626: }
3627: } elsif ($env{'form.login'} eq 'loc') {
3628: $amode='localauth';
3629: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
3630: $genpwd=$env{'form.locarg'};
3631: }
3632: }
3633: if ($amode =~ /^krb/) {
3634: if (! defined($genpwd) || $genpwd eq '') {
3635: $r->print('<span class="Error">'.
3636: &mt('Unable to enroll users').' '.
3637: &mt('No Kerberos domain was specified.').'</span></p>');
3638: $amode = ''; # This causes the loop below to be skipped
3639: }
3640: }
3641: my ($cid,$defaultsec,$defaultrole,$setting);
3642: if ($context eq 'domain') {
3643: $setting = $env{'form.roleaction'};
3644: if ($setting eq 'domain') {
3645: $defaultrole = $env{'form.defaultrole'};
3646: } elsif ($setting eq 'course') {
3647: $defaultrole = $env{'form.courserole'};
1.27 raeburn 3648: $defaultsec = $env{'form.sections'};
1.1 raeburn 3649: }
1.13 raeburn 3650: } elsif ($context eq 'author') {
1.1 raeburn 3651: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 3652: } elsif ($context eq 'course') {
3653: $defaultrole = $env{'form.defaultrole'};
3654: $defaultsec = $env{'form.sections'};
1.1 raeburn 3655: }
1.27 raeburn 3656: if ($env{'request.course.id'} ne '') {
3657: $cid = $env{'request.course.id'};
3658: } elsif ($setting eq 'course') {
3659: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
3660: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
1.1 raeburn 3661: }
3662: }
1.27 raeburn 3663: # Check to see if user information can be changed
3664: my @userinfo = ('firstname','middlename','lastname','generation',
3665: 'permanentemail','id');
3666: my %canmodify;
3667: if (&Apache::lonnet::allowed('mau',$domain)) {
1.84 raeburn 3668: push(@userinfo,'inststatus');
1.27 raeburn 3669: foreach my $field (@userinfo) {
3670: $canmodify{$field} = 1;
3671: }
3672: }
3673: my (%userlist,%modifiable_fields,@poss_roles);
3674: my $secidx = &Apache::loncoursedata::CL_SECTION();
3675: my @courseroles = &roles_by_context('course',1);
3676: if (!&Apache::lonnet::allowed('mau',$domain)) {
3677: if ($context eq 'course' || $context eq 'author') {
3678: @poss_roles = &curr_role_permissions($context);
3679: my @statuses = ('active','future');
3680: my ($indexhash,$keylist) = &make_keylist_array();
3681: my %info;
3682: foreach my $role (@poss_roles) {
3683: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
3684: \@userinfo,[$role]);
3685: }
3686: if ($context eq 'course') {
3687: my ($cnum,$cdom) = &get_course_identity();
3688: my $roster = &Apache::loncoursedata::get_classlist();
1.66 raeburn 3689: if (ref($roster) eq 'HASH') {
3690: %userlist = %{$roster};
3691: }
1.27 raeburn 3692: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
3693: \@statuses,\@poss_roles);
3694: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3695: \%advrolehash,$permission);
3696: } elsif ($context eq 'author') {
3697: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
3698: \@statuses,\@poss_roles);
3699: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3700: \%cstr_roles,$permission);
3701:
3702: }
3703: }
1.1 raeburn 3704: }
3705: if ( $domain eq &LONCAPA::clean_domain($domain)
3706: && ($amode ne '')) {
3707: #######################################
3708: ## Add/Modify Users ##
3709: #######################################
3710: if ($context eq 'course') {
3711: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 3712: } elsif ($context eq 'author') {
1.1 raeburn 3713: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
3714: } else {
3715: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
3716: }
1.87 bisitz 3717: $r->rflush;
3718:
1.1 raeburn 3719: my %counts = (
3720: user => 0,
3721: auth => 0,
3722: role => 0,
3723: );
3724: my $flushc=0;
3725: my %student=();
1.42 raeburn 3726: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 3727: my %userchg;
1.27 raeburn 3728: if ($context eq 'course' || $setting eq 'course') {
3729: if ($context eq 'course') {
3730: # Get information about course groups
3731: %curr_groups = &Apache::longroup::coursegroups();
3732: } elsif ($setting eq 'course') {
3733: if ($cid) {
3734: %curr_groups =
3735: &Apache::longroup::coursegroups($env{'form.dcdomain'},
3736: $env{'form.dccourse'});
3737: }
3738: }
3739: # determine section number
3740: if ($defaultsec =~ /,/) {
3741: push(@sections,split(/,/,$defaultsec));
3742: } else {
3743: push(@sections,$defaultsec);
3744: }
3745: # remove non alphanumeric values from section
3746: foreach my $item (@sections) {
3747: $item =~ s/\W//g;
3748: if ($item eq "none" || $item eq 'all') {
3749: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
3750: } elsif ($item ne '' && exists($curr_groups{$item})) {
3751: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
3752: } elsif ($item ne '') {
3753: push(@cleansec,$item);
3754: }
3755: }
3756: if ($defaultwarn) {
3757: $r->print($defaultwarn.'<br />');
3758: }
3759: if ($groupwarn) {
3760: $r->print($groupwarn.'<br />');
3761: }
1.1 raeburn 3762: }
1.5 raeburn 3763: my (%curr_rules,%got_rules,%alerts);
1.27 raeburn 3764: my %customroles = &my_custom_roles();
1.42 raeburn 3765: my @permitted_roles = &roles_on_upload($context,$setting,%customroles);
1.1 raeburn 3766: # Get new users list
1.27 raeburn 3767: foreach my $line (@userdata) {
1.42 raeburn 3768: my @secs;
1.27 raeburn 3769: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 3770: # Determine user name
3771: unless (($entries{$fields{'username'}} eq '') ||
3772: (!defined($entries{$fields{'username'}}))) {
3773: my ($fname, $mname, $lname,$gen) = ('','','','');
3774: if (defined($fields{'names'})) {
3775: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
3776: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
3777: } else {
3778: if (defined($fields{'fname'})) {
3779: $fname=$entries{$fields{'fname'}};
3780: }
3781: if (defined($fields{'mname'})) {
3782: $mname=$entries{$fields{'mname'}};
3783: }
3784: if (defined($fields{'lname'})) {
3785: $lname=$entries{$fields{'lname'}};
3786: }
3787: if (defined($fields{'gen'})) {
3788: $gen=$entries{$fields{'gen'}};
3789: }
3790: }
3791: if ($entries{$fields{'username'}}
3792: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
3793: $r->print('<br />'.
1.74 bisitz 3794: &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
1.77 raeburn 3795: '<b>'.$entries{$fields{'username'}}.'</b>',$fname,$mname,$lname,$gen));
1.27 raeburn 3796: next;
1.1 raeburn 3797: } else {
1.71 droeschl 3798: if ($entries{$fields{'domain'}}
1.57 raeburn 3799: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
3800: $r->print('<br />'. '<b>'.$entries{$fields{'domain'}}.
1.77 raeburn 3801: '</b>: '.&mt('Unacceptable domain for user [_2] [_3] [_4] [_5]',$fname,$mname,$lname,$gen));
1.57 raeburn 3802: next;
3803: }
1.5 raeburn 3804: my $username = $entries{$fields{'username'}};
1.57 raeburn 3805: my $userdomain = $entries{$fields{'domain'}};
3806: if ($userdomain eq '') {
3807: $userdomain = $domain;
3808: }
1.27 raeburn 3809: if (defined($fields{'sec'})) {
3810: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 3811: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 3812: my $item = $entries{$fields{'sec'}};
3813: if ($item eq "none" || $item eq 'all') {
1.74 bisitz 3814: $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 3815: next;
3816: } elsif (exists($curr_groups{$item})) {
1.74 bisitz 3817: $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 3818: next;
3819: } else {
3820: push(@secs,$item);
3821: }
3822: }
3823: }
3824: if ($env{'request.course.sec'} ne '') {
3825: @secs = ($env{'request.course.sec'});
1.57 raeburn 3826: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
3827: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27 raeburn 3828: if ($currsec ne $env{'request.course.sec'}) {
1.74 bisitz 3829: $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 3830: if ($currsec eq '') {
3831: $r->print(&mt('This user already has an active/future student role in the course, unaffiliated to any section.'));
3832:
3833: } else {
3834: $r->print(&mt('This user already has an active/future role in section "[_1]" of the course.',$currsec));
3835: }
3836: $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 />');
3837: next;
1.1 raeburn 3838: }
3839: }
1.27 raeburn 3840: } elsif ($context eq 'course' || $setting eq 'course') {
3841: if (@secs == 0) {
3842: @secs = @cleansec;
1.1 raeburn 3843: }
3844: }
3845: # determine id number
3846: my $id='';
3847: if (defined($fields{'id'})) {
3848: if (defined($entries{$fields{'id'}})) {
3849: $id=$entries{$fields{'id'}};
3850: }
3851: $id=~tr/A-Z/a-z/;
3852: }
3853: # determine email address
3854: my $email='';
3855: if (defined($fields{'email'})) {
3856: if (defined($entries{$fields{'email'}})) {
3857: $email=$entries{$fields{'email'}};
1.84 raeburn 3858: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
3859: }
3860: }
3861: # determine affiliation
3862: my $inststatus='';
3863: if (defined($fields{'inststatus'})) {
3864: if (defined($entries{$fields{'inststatus'}})) {
3865: $inststatus=$entries{$fields{'inststatus'}};
3866: }
1.1 raeburn 3867: }
3868: # determine user password
3869: my $password = $genpwd;
3870: if (defined($fields{'ipwd'})) {
3871: if ($entries{$fields{'ipwd'}}) {
3872: $password=$entries{$fields{'ipwd'}};
3873: }
3874: }
3875: # determine user role
3876: my $role = '';
3877: if (defined($fields{'role'})) {
3878: if ($entries{$fields{'role'}}) {
1.42 raeburn 3879: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
3880: if ($entries{$fields{'role'}} ne '') {
3881: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
3882: $role = $entries{$fields{'role'}};
1.27 raeburn 3883: }
3884: }
3885: if ($role eq '') {
3886: my $rolestr = join(', ',@permitted_roles);
1.74 bisitz 3887: $r->print('<br />'
3888: .&mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
3889: ,'<b>'.$entries{$fields{'username'}}.'</b>'
3890: ,$entries{$fields{'role'}})
3891: .'<br />'
3892: .&mt('Allowable role(s) is/are: [_1].',$rolestr)."\n"
3893: );
1.1 raeburn 3894: next;
3895: }
3896: }
3897: }
3898: if ($role eq '') {
3899: $role = $defaultrole;
3900: }
3901: # Clean up whitespace
1.57 raeburn 3902: foreach (\$id,\$fname,\$mname,\$lname,\$gen) {
1.1 raeburn 3903: $$_ =~ s/(\s+$|^\s+)//g;
3904: }
1.5 raeburn 3905: # check against rules
3906: my $checkid = 0;
3907: my $newuser = 0;
3908: my (%rulematch,%inst_results,%idinst_results);
1.57 raeburn 3909: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5 raeburn 3910: if ($uhome eq 'no_host') {
1.57 raeburn 3911: next if ($userdomain ne $domain);
1.5 raeburn 3912: $checkid = 1;
3913: $newuser = 1;
3914: my $checkhash;
3915: my $checks = { 'username' => 1 };
3916: $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
3917: &Apache::loncommon::user_rule_check($checkhash,$checks,
3918: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
3919: \%got_rules);
3920: if (ref($alerts{'username'}) eq 'HASH') {
3921: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
3922: next if ($alerts{'username'}{$domain}{$username});
3923: }
3924: }
1.13 raeburn 3925: } else {
1.27 raeburn 3926: if ($context eq 'course' || $context eq 'author') {
1.57 raeburn 3927: if ($userdomain eq $domain ) {
3928: if ($role eq '') {
3929: my @checkroles;
3930: foreach my $role (@poss_roles) {
3931: my $endkey;
3932: if ($role ne 'st') {
3933: $endkey = ':'.$role;
3934: }
3935: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
3936: if (!grep(/^\Q$role\E$/,@checkroles)) {
3937: push(@checkroles,$role);
3938: }
3939: }
1.27 raeburn 3940: }
1.57 raeburn 3941: if (@checkroles > 0) {
3942: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27 raeburn 3943: }
1.57 raeburn 3944: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
3945: %canmodify = %{$modifiable_fields{$role}};
1.27 raeburn 3946: }
3947: }
1.57 raeburn 3948: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84 raeburn 3949: for (my $i=0; $i<@newinfo; $i++) {
1.57 raeburn 3950: if (${$newinfo[$i]} ne '') {
3951: if (!$canmodify{$userinfo[$i]}) {
3952: ${$newinfo[$i]} = '';
3953: }
1.27 raeburn 3954: }
3955: }
3956: }
1.5 raeburn 3957: }
3958: if ($id ne '') {
3959: if (!$newuser) {
1.57 raeburn 3960: my %idhash = &Apache::lonnet::idrget($userdomain,($username));
1.5 raeburn 3961: if ($idhash{$username} ne $id) {
3962: $checkid = 1;
3963: }
3964: }
3965: if ($checkid) {
3966: my $checkhash;
3967: my $checks = { 'id' => 1 };
1.57 raeburn 3968: $checkhash->{$username.':'.$userdomain} = { 'newuser' => $newuser,
1.5 raeburn 3969: 'id' => $id };
3970: &Apache::loncommon::user_rule_check($checkhash,$checks,
3971: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
3972: \%got_rules);
3973: if (ref($alerts{'id'}) eq 'HASH') {
1.57 raeburn 3974: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
3975: next if ($alerts{'id'}{$userdomain}{$id});
1.5 raeburn 3976: }
3977: }
3978: }
3979: }
1.1 raeburn 3980: if ($password || $env{'form.login'} eq 'loc') {
1.27 raeburn 3981: my $multiple = 0;
3982: my ($userresult,$authresult,$roleresult,$idresult);
3983: my (%userres,%authres,%roleres,%idres);
1.42 raeburn 3984: my $singlesec = '';
1.1 raeburn 3985: if ($role eq 'st') {
1.27 raeburn 3986: my $sec;
1.42 raeburn 3987: if (@secs > 0) {
3988: $sec = $secs[0];
1.27 raeburn 3989: }
1.57 raeburn 3990: &modifystudent($userdomain,$username,$cid,$sec,
1.52 raeburn 3991: $desiredhost,$context);
1.42 raeburn 3992: $roleresult =
3993: &Apache::lonnet::modifystudent
1.57 raeburn 3994: ($userdomain,$username,$id,$amode,$password,
1.42 raeburn 3995: $fname,$mname,$lname,$gen,$sec,$enddate,
3996: $startdate,$env{'form.forceid'},
1.52 raeburn 3997: $desiredhost,$email,'manual','',$cid,
1.84 raeburn 3998: '',$context,$inststatus);
1.42 raeburn 3999: $userresult = $roleresult;
1.1 raeburn 4000: } else {
1.42 raeburn 4001: if ($role ne '') {
4002: if ($context eq 'course' || $setting eq 'course') {
4003: if ($customroles{$role}) {
4004: $role = 'cr_'.$env{'user.domain'}.'_'.
4005: $env{'user.name'}.'_'.$role;
4006: }
4007: if ($role ne 'cc') {
4008: if (@secs > 1) {
4009: $multiple = 1;
4010: foreach my $sec (@secs) {
4011: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
4012: &modifyuserrole($context,$setting,
1.57 raeburn 4013: $changeauth,$cid,$userdomain,$username,
1.42 raeburn 4014: $id,$amode,$password,$fname,
4015: $mname,$lname,$gen,$sec,
4016: $env{'form.forceid'},$desiredhost,
4017: $email,$role,$enddate,
1.84 raeburn 4018: $startdate,$checkid,$inststatus);
1.42 raeburn 4019: }
4020: } elsif (@secs > 0) {
4021: $singlesec = $secs[0];
4022: }
1.27 raeburn 4023: }
4024: }
4025: }
4026: if (!$multiple) {
1.28 raeburn 4027: ($userresult,$authresult,$roleresult,$idresult) =
1.27 raeburn 4028: &modifyuserrole($context,$setting,
1.57 raeburn 4029: $changeauth,$cid,$userdomain,$username,
1.42 raeburn 4030: $id,$amode,$password,$fname,
4031: $mname,$lname,$gen,$singlesec,
4032: $env{'form.forceid'},$desiredhost,
1.84 raeburn 4033: $email,$role,$enddate,$startdate,
4034: $checkid,$inststatus);
1.27 raeburn 4035: }
4036: }
4037: if ($multiple) {
4038: foreach my $sec (sort(keys(%userres))) {
1.42 raeburn 4039: $flushc =
1.27 raeburn 4040: &user_change_result($r,$userres{$sec},$authres{$sec},
4041: $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57 raeburn 4042: $username,$userdomain,\%userchg);
1.27 raeburn 4043:
4044: }
4045: } else {
4046: $flushc =
4047: &user_change_result($r,$userresult,$authresult,
1.28 raeburn 4048: $roleresult,$idresult,\%counts,$flushc,
1.57 raeburn 4049: $username,$userdomain,\%userchg);
1.1 raeburn 4050: }
4051: } else {
4052: if ($context eq 'course') {
4053: $r->print('<br />'.
1.74 bisitz 4054: &mt('[_1]: Unable to enroll. No password specified.','<b>'.$username.'</b>')
1.1 raeburn 4055: );
1.13 raeburn 4056: } elsif ($context eq 'author') {
1.1 raeburn 4057: $r->print('<br />'.
1.74 bisitz 4058: &mt('[_1]: Unable to add co-author. No password specified.','<b>'.$username.'</b>')
1.1 raeburn 4059: );
4060: } else {
4061: $r->print('<br />'.
1.74 bisitz 4062: &mt('[_1]: Unable to add user. No password specified.','<b>'.$username.'</b>')
1.1 raeburn 4063: );
4064: }
4065: }
4066: }
4067: }
4068: } # end of foreach (@userdata)
4069: # Flush the course logs so reverse user roles immediately updated
1.5 raeburn 4070: &Apache::lonnet::flushcourselogs();
1.29 raeburn 4071: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 4072: "</p>\n");
4073: if ($counts{'role'} > 0) {
4074: $r->print("<p>\n".
1.29 raeburn 4075: &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");
4076: } else {
4077: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 4078: }
4079: if ($counts{'auth'} > 0) {
4080: $r->print("<p>\n".
4081: &mt('Authentication changed for [_1] existing users.',
4082: $counts{'auth'})."</p>\n");
4083: }
1.13 raeburn 4084: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.1 raeburn 4085: #####################################
1.29 raeburn 4086: # Display list of students to drop #
1.1 raeburn 4087: #####################################
4088: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 4089: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 4090: # Get current classlist
1.30 raeburn 4091: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 4092: if (! defined($classlist)) {
1.29 raeburn 4093: $r->print('<form name="studentform" method="post" action="/adm/createuser" />'.
4094: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
4095: &mt('There are no students with current/future access to the course.').
4096: '</form>'."\n");
1.66 raeburn 4097: } elsif (ref($classlist) eq 'HASH') {
1.1 raeburn 4098: # Remove the students we just added from the list of students.
1.30 raeburn 4099: foreach my $line (@userdata) {
4100: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 4101: unless (($entries{$fields{'username'}} eq '') ||
4102: (!defined($entries{$fields{'username'}}))) {
4103: delete($classlist->{$entries{$fields{'username'}}.
4104: ':'.$domain});
4105: }
4106: }
4107: # Print out list of dropped students.
1.30 raeburn 4108: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 4109: }
4110: }
4111: } # end of unless
1.29 raeburn 4112: if ($env{'form.fullup'} ne 'yes') {
4113: $r->print('</form>');
4114: }
1.1 raeburn 4115: }
4116:
1.13 raeburn 4117: sub print_namespacing_alerts {
4118: my ($domain,$alerts,$curr_rules) = @_;
4119: my $output;
4120: if (ref($alerts) eq 'HASH') {
4121: if (keys(%{$alerts}) > 0) {
4122: if (ref($alerts->{'username'}) eq 'HASH') {
4123: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
4124: my $count;
4125: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
4126: $count = keys(%{$alerts->{'username'}{$dom}});
4127: }
4128: my $domdesc = &Apache::lonnet::domain($domain,'description');
4129: if (ref($curr_rules->{$dom}) eq 'HASH') {
4130: $output .= &Apache::loncommon::instrule_disallow_msg(
4131: 'username',$domdesc,$count,'upload');
4132: }
4133: $output .= &Apache::loncommon::user_rule_formats($dom,
4134: $domdesc,$curr_rules->{$dom}{'username'},
4135: 'username');
4136: }
4137: }
4138: if (ref($alerts->{'id'}) eq 'HASH') {
4139: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
4140: my $count;
4141: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
4142: $count = keys(%{$alerts->{'id'}{$dom}});
4143: }
4144: my $domdesc = &Apache::lonnet::domain($domain,'description');
4145: if (ref($curr_rules->{$dom}) eq 'HASH') {
4146: $output .= &Apache::loncommon::instrule_disallow_msg(
4147: 'id',$domdesc,$count,'upload');
4148: }
4149: $output .= &Apache::loncommon::user_rule_formats($dom,
4150: $domdesc,$curr_rules->{$dom}{'id'},'id');
4151: }
4152: }
4153: }
4154: }
4155: }
4156:
1.1 raeburn 4157: sub user_change_result {
1.29 raeburn 4158: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57 raeburn 4159: $username,$userdomain,$userchg) = @_;
1.1 raeburn 4160: my $okresult = 0;
4161: if ($userresult ne 'ok') {
4162: if ($userresult =~ /^error:(.+)$/) {
4163: my $error = $1;
4164: $r->print('<br />'.
1.74 bisitz 4165: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 4166: }
4167: } else {
4168: $counts->{'user'} ++;
4169: $okresult = 1;
4170: }
4171: if ($authresult ne 'ok') {
4172: if ($authresult =~ /^error:(.+)$/) {
4173: my $error = $1;
4174: $r->print('<br />'.
1.74 bisitz 4175: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 4176: }
4177: } else {
4178: $counts->{'auth'} ++;
4179: $okresult = 1;
4180: }
4181: if ($roleresult ne 'ok') {
4182: if ($roleresult =~ /^error:(.+)$/) {
4183: my $error = $1;
4184: $r->print('<br />'.
1.74 bisitz 4185: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 4186: }
4187: } else {
4188: $counts->{'role'} ++;
4189: $okresult = 1;
4190: }
4191: if ($okresult) {
4192: $flushc++;
1.57 raeburn 4193: $userchg->{$username.':'.$userdomain}=1;
1.1 raeburn 4194: $r->print('. ');
4195: if ($flushc>15) {
4196: $r->rflush;
4197: $flushc=0;
4198: }
4199: }
1.29 raeburn 4200: if ($idresult) {
4201: $r->print($idresult);
4202: }
1.1 raeburn 4203: return $flushc;
4204: }
4205:
4206: # ========================================================= Menu Phase Two Drop
1.17 raeburn 4207: sub print_drop_menu {
4208: my ($r,$context,$permission) = @_;
4209: $r->print('<h3>'.&mt("Drop Students").'</h3>'."\n".
4210: '<form name="studentform" method="post">'."\n");
1.30 raeburn 4211: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 4212: if (! defined($classlist)) {
4213: $r->print(&mt('There are no students currently enrolled.')."\n");
1.30 raeburn 4214: } else {
4215: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 4216: }
1.17 raeburn 4217: $r->print('</form>'. &Apache::loncommon::end_page());
1.1 raeburn 4218: return;
4219: }
4220:
4221: # ================================================================== Phase four
4222:
1.11 raeburn 4223: sub update_user_list {
4224: my ($r,$context,$setting,$choice) = @_;
4225: my $now = time;
1.1 raeburn 4226: my $count=0;
1.11 raeburn 4227: my @changelist;
1.29 raeburn 4228: if ($choice eq 'drop') {
4229: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
4230: } else {
1.11 raeburn 4231: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
4232: }
4233: my %result_text = ( ok => { 'revoke' => 'Revoked',
4234: 'delete' => 'Deleted',
4235: 'reenable' => 'Re-enabled',
1.17 raeburn 4236: 'activate' => 'Activated',
4237: 'chgdates' => 'Changed Access Dates for',
4238: 'chgsec' => 'Changed section for',
4239: 'drop' => 'Dropped',
1.11 raeburn 4240: },
4241: error => {'revoke' => 'revoking',
4242: 'delete' => 'deleting',
4243: 'reenable' => 're-enabling',
4244: 'activate' => 'activating',
1.17 raeburn 4245: 'chgdates' => 'changing access dates for',
4246: 'chgsec' => 'changing section for',
4247: 'drop' => 'dropping',
1.11 raeburn 4248: },
4249: );
4250: my ($startdate,$enddate);
4251: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
4252: ($startdate,$enddate) = &get_dates_from_form();
4253: }
4254: foreach my $item (@changelist) {
4255: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
4256: $scopestem);
1.17 raeburn 4257: if ($choice eq 'drop') {
4258: ($uname,$udom,$sec) = split(/:/,$item,-1);
4259: $role = 'st';
4260: $cid = $env{'request.course.id'};
4261: $scopestem = '/'.$cid;
4262: $scopestem =~s/\_/\//g;
4263: if ($sec eq '') {
4264: $scope = $scopestem;
4265: } else {
4266: $scope = $scopestem.'/'.$sec;
4267: }
4268: } elsif ($context eq 'course') {
1.11 raeburn 4269: ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
4270: $cid = $env{'request.course.id'};
4271: $scopestem = '/'.$cid;
4272: $scopestem =~s/\_/\//g;
4273: if ($sec eq '') {
4274: $scope = $scopestem;
4275: } else {
4276: $scope = $scopestem.'/'.$sec;
4277: }
1.13 raeburn 4278: } elsif ($context eq 'author') {
1.11 raeburn 4279: ($uname,$udom,$role) = split(/\:/,$item,-1);
4280: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
4281: } elsif ($context eq 'domain') {
4282: if ($setting eq 'domain') {
4283: ($role,$uname,$udom) = split(/\:/,$item,-1);
4284: $scope = '/'.$env{'request.role.domain'}.'/';
1.13 raeburn 4285: } elsif ($setting eq 'author') {
1.11 raeburn 4286: ($uname,$udom,$role,$scope) = split(/\:/,$item);
4287: } elsif ($setting eq 'course') {
4288: ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
4289: split(/\:/,$item);
4290: $scope = '/'.$cid;
4291: $scope =~s/\_/\//g;
4292: if ($sec ne '') {
4293: $scope .= '/'.$sec;
4294: }
4295: }
4296: }
4297: my $plrole = &Apache::lonnet::plaintext($role);
4298: my $start = $env{'form.'.$item.'_start'};
4299: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 4300: if ($choice eq 'drop') {
4301: # drop students
4302: $end = $now;
4303: $type = 'manual';
4304: $result =
1.52 raeburn 4305: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 4306: } elsif ($choice eq 'revoke') {
4307: # revoke or delete user role
1.11 raeburn 4308: $end = $now;
4309: if ($role eq 'st') {
4310: $result =
1.52 raeburn 4311: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4312: } else {
4313: $result =
1.52 raeburn 4314: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
4315: '','',$context);
1.11 raeburn 4316: }
4317: } elsif ($choice eq 'delete') {
4318: if ($role eq 'st') {
1.52 raeburn 4319: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context);
1.29 raeburn 4320: }
4321: $result =
4322: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 4323: $start,1,'',$context);
1.11 raeburn 4324: } else {
4325: #reenable, activate, change access dates or change section
4326: if ($choice ne 'chgsec') {
4327: $start = $startdate;
4328: $end = $enddate;
4329: }
4330: if ($choice eq 'reenable') {
4331: if ($role eq 'st') {
1.52 raeburn 4332: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4333: } else {
4334: $result =
4335: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4336: $now,'','',$context);
1.11 raeburn 4337: }
4338: } elsif ($choice eq 'activate') {
4339: if ($role eq 'st') {
1.52 raeburn 4340: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4341: } else {
4342: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4343: $now,'','',$context);
1.11 raeburn 4344: }
4345: } elsif ($choice eq 'chgdates') {
4346: if ($role eq 'st') {
1.52 raeburn 4347: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4348: } else {
4349: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4350: $start,'','',$context);
1.11 raeburn 4351: }
4352: } elsif ($choice eq 'chgsec') {
4353: my (@newsecs,$revresult,$nochg,@retained);
4354: if ($role ne 'cc') {
4355: @newsecs = split(/,/,$env{'form.newsecs'});
4356: }
4357: # remove existing section if not to be retained.
4358: if (!$env{'form.retainsec'}) {
4359: if ($sec eq '') {
4360: if (@newsecs == 0) {
4361: $result = &mt('No change in section assignment (none)');
4362: $nochg = 1;
1.40 raeburn 4363: } else {
4364: $revresult =
4365: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4366: $scope,$role,
4367: '','',$context);
1.40 raeburn 4368: }
1.11 raeburn 4369: } else {
1.28 raeburn 4370: if (@newsecs > 0) {
4371: if (grep(/^\Q$sec\E$/,@newsecs)) {
4372: push(@retained,$sec);
4373: } else {
4374: $revresult =
4375: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4376: $scope,$role,
4377: '','',$context);
1.28 raeburn 4378: }
4379: } else {
1.11 raeburn 4380: $revresult =
1.28 raeburn 4381: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4382: $scope,$role,
4383: '','',$context);
1.11 raeburn 4384: }
4385: }
4386: } else {
1.28 raeburn 4387: if ($sec eq '') {
4388: $nochg = 1;
4389: } else {
4390: push(@retained,$sec);
4391: }
1.11 raeburn 4392: }
4393: # add new sections
4394: if (@newsecs == 0) {
4395: if (!$nochg) {
1.28 raeburn 4396: if ($role eq 'st') {
4397: $result =
1.52 raeburn 4398: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
1.28 raeburn 4399: } else {
4400: my $newscope = $scopestem;
1.52 raeburn 4401: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 4402: }
4403: }
4404: } else {
4405: foreach my $newsec (@newsecs) {
4406: if (!grep(/^\Q$newsec\E$/,@retained)) {
4407: if ($role eq 'st') {
1.52 raeburn 4408: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4409: } else {
4410: my $newscope = $scopestem;
4411: if ($newsec ne '') {
4412: $newscope .= '/'.$newsec;
4413: }
4414: $result = &Apache::lonnet::assignrole($udom,$uname,
4415: $newscope,$role,$end,$start);
4416: }
4417: }
4418: }
4419: }
4420: }
4421: }
1.17 raeburn 4422: my $extent = $scope;
4423: if ($choice eq 'drop' || $context eq 'course') {
4424: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
4425: if ($cdesc) {
4426: $extent = $cdesc;
4427: }
4428: }
1.1 raeburn 4429: if ($result eq 'ok' || $result eq 'ok:') {
1.11 raeburn 4430: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
1.17 raeburn 4431: $plrole,$extent,$uname.':'.$udom).'<br />');
1.1 raeburn 4432: $count++;
4433: } else {
4434: $r->print(
1.29 raeburn 4435: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
1.17 raeburn 4436: $plrole,$extent,$uname.':'.$udom,$result).'<br />');
1.11 raeburn 4437: }
4438: }
1.32 raeburn 4439: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 4440: if ($choice eq 'drop') {
4441: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
4442: '<input type="hidden" name="Status" value="Active" />'."\n".
4443: '<input type="hidden" name="showrole" value="st" />'."\n");
4444: } else {
4445: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
4446: if ($env{'form.'.$item} ne '') {
4447: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
4448: '" />'."\n");
4449: }
1.32 raeburn 4450: }
4451: }
1.29 raeburn 4452: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'</b></p>');
1.11 raeburn 4453: if ($count > 0) {
1.17 raeburn 4454: if ($choice eq 'revoke' || $choice eq 'drop') {
1.74 bisitz 4455: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11 raeburn 4456: }
4457: # Flush the course logs so reverse user roles immediately updated
4458: &Apache::lonnet::flushcourselogs();
4459: }
4460: if ($env{'form.makedatesdefault'}) {
4461: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.29 raeburn 4462: $r->print(&make_dates_default($startdate,$enddate,$context));
1.1 raeburn 4463: }
4464: }
1.33 raeburn 4465: my $linktext = &mt('Display User Lists');
4466: if ($choice eq 'drop') {
4467: $linktext = &mt('Display current class roster');
4468: }
4469: $r->print('<a href="javascript:document.studentform.submit()">'.$linktext.'</a></form>'."\n");
1.1 raeburn 4470: }
4471:
1.8 raeburn 4472: sub classlist_drop {
1.29 raeburn 4473: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 4474: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 4475: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8 raeburn 4476: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63 raeburn 4477: my %user;
4478: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8 raeburn 4479: return &mt('Drop from classlist: [_1]',
4480: '<b>'.$result.'</b>').'<br />';
4481: }
4482: }
4483: }
4484:
4485: sub active_student_roles {
4486: my ($cnum,$cdom,$uname,$udom) = @_;
4487: my %roles =
4488: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
4489: ['future','active'],['st']);
4490: return exists($roles{"$cnum:$cdom:st"});
4491: }
4492:
1.1 raeburn 4493: sub section_check_js {
1.8 raeburn 4494: my $groupslist= &get_groupslist();
1.1 raeburn 4495: return <<"END";
4496: function validate(caller) {
1.9 raeburn 4497: var groups = new Array($groupslist);
1.1 raeburn 4498: var secname = caller.value;
4499: if ((secname == 'all') || (secname == 'none')) {
4500: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
4501: return 'error';
4502: }
4503: if (secname != '') {
4504: for (var k=0; k<groups.length; k++) {
4505: if (secname == groups[k]) {
4506: 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.");
4507: return 'error';
4508: }
4509: }
4510: }
4511: return 'ok';
4512: }
4513: END
4514: }
4515:
4516: sub set_login {
4517: my ($dom,$authformkrb,$authformint,$authformloc) = @_;
4518: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4519: my $response;
4520: my ($authnum,%can_assign) =
4521: &Apache::loncommon::get_assignable_auth($dom);
4522: if ($authnum) {
4523: $response = &Apache::loncommon::start_data_table();
4524: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
4525: $response .= &Apache::loncommon::start_data_table_row().
4526: '<td>'.$authformkrb.'</td>'.
4527: &Apache::loncommon::end_data_table_row()."\n";
4528: }
4529: if ($can_assign{'int'}) {
4530: $response .= &Apache::loncommon::start_data_table_row().
4531: '<td>'.$authformint.'</td>'.
4532: &Apache::loncommon::end_data_table_row()."\n"
4533: }
4534: if ($can_assign{'loc'}) {
4535: $response .= &Apache::loncommon::start_data_table_row().
4536: '<td>'.$authformloc.'</td>'.
4537: &Apache::loncommon::end_data_table_row()."\n";
4538: }
4539: $response .= &Apache::loncommon::end_data_table();
4540: }
4541: return $response;
4542: }
4543:
1.8 raeburn 4544: sub course_sections {
1.51 raeburn 4545: my ($sections_count,$role,$current_sec) = @_;
1.8 raeburn 4546: my $output = '';
4547: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.29 raeburn 4548: my $numsec = scalar(@sections);
1.92 bisitz 4549: my $is_selected = ' selected="selected"';
1.29 raeburn 4550: if ($numsec <= 1) {
1.8 raeburn 4551: $output = '<select name="currsec_'.$role.'" >'."\n".
1.51 raeburn 4552: ' <option value="">'.&mt('Select').'</option>'."\n";
4553: if ($current_sec eq 'none') {
4554: $output .=
4555: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
4556: } else {
4557: $output .=
1.29 raeburn 4558: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 4559: }
1.29 raeburn 4560: if ($numsec == 1) {
1.51 raeburn 4561: if ($current_sec eq $sections[0]) {
4562: $output .=
4563: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
4564: } else {
4565: $output .=
1.8 raeburn 4566: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 4567: }
1.29 raeburn 4568: }
1.8 raeburn 4569: } else {
4570: $output = '<select name="currsec_'.$role.'" ';
4571: my $multiple = 4;
4572: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 4573: if ($role eq 'st') {
4574: $output .= '>'."\n".
1.51 raeburn 4575: ' <option value="">'.&mt('Select').'</option>'."\n";
4576: if ($current_sec eq 'none') {
4577: $output .=
4578: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
4579: } else {
4580: $output .=
1.29 raeburn 4581: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 4582: }
1.29 raeburn 4583: } else {
4584: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
4585: }
1.8 raeburn 4586: foreach my $sec (@sections) {
1.51 raeburn 4587: if ($current_sec eq $sec) {
4588: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
4589: } else {
4590: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
4591: }
1.8 raeburn 4592: }
4593: }
4594: $output .= '</select>';
4595: return $output;
4596: }
4597:
4598: sub get_groupslist {
4599: my $groupslist;
4600: my %curr_groups = &Apache::longroup::coursegroups();
4601: if (%curr_groups) {
4602: $groupslist = join('","',sort(keys(%curr_groups)));
4603: $groupslist = '"'.$groupslist.'"';
4604: }
1.11 raeburn 4605: return $groupslist;
1.8 raeburn 4606: }
4607:
4608: sub setsections_javascript {
1.37 raeburn 4609: my ($formname,$groupslist,$mode,$checkauth) = @_;
1.28 raeburn 4610: my ($checkincluded,$finish,$rolecode,$setsection_js);
4611: if ($mode eq 'upload') {
4612: $checkincluded = 'formname.name == "'.$formname.'"';
4613: $finish = "return 'ok';";
4614: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
4615: } elsif ($formname eq 'cu') {
1.8 raeburn 4616: $checkincluded = 'formname.elements[i-1].checked == true';
1.37 raeburn 4617: if ($checkauth) {
4618: $finish = "var authcheck = auth_check();\n".
4619: " if (authcheck == 'ok') {\n".
4620: " formname.submit();\n".
4621: " }\n";
4622: } else {
4623: $finish = 'formname.submit()';
4624: }
1.28 raeburn 4625: $rolecode = "var match = str.split('_');
4626: var role = match[3];\n";
4627: } elsif ($formname eq 'enrollstudent') {
4628: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 4629: if ($checkauth) {
4630: $finish = "var authcheck = auth_check();\n".
4631: " if (authcheck == 'ok') {\n".
4632: " formname.submit();\n".
4633: " }\n";
4634: } else {
4635: $finish = 'formname.submit()';
4636: }
1.28 raeburn 4637: $rolecode = "var match = str.split('_');
4638: var role = match[1];\n";
1.8 raeburn 4639: } else {
1.28 raeburn 4640: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 4641: $finish = "seccheck = 'ok';";
1.28 raeburn 4642: $rolecode = "var match = str.split('_');
4643: var role = match[1];\n";
1.11 raeburn 4644: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 4645: }
4646: my %alerts = &Apache::lonlocal::texthash(
4647: secd => 'Section designations do not apply to Course Coordinator roles.',
4648: accr => 'A course coordinator role will be added with access to all sections.',
4649: inea => 'In each course, each user may only have one student role at a time.',
4650: youh => 'You had selected ',
4651: secs => 'sections.',
4652: plmo => 'Please modify your selections so they include no more than one section.',
4653: mayn => 'may not be used as the name for a section, as it is a reserved word.',
4654: plch => 'Please choose a different section name.',
4655: mnot => 'may not be used as a section name, as it is the name of a course group.',
4656: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.11 raeburn 4657: );
1.8 raeburn 4658: $setsection_js .= <<"ENDSECCODE";
4659:
4660: function setSections(formname) {
4661: var re1 = /^currsec_/;
4662: var groups = new Array($groupslist);
4663: for (var i=0;i<formname.elements.length;i++) {
4664: var str = formname.elements[i].name;
4665: var checkcurr = str.match(re1);
4666: if (checkcurr != null) {
4667: if ($checkincluded) {
1.28 raeburn 4668: $rolecode
1.8 raeburn 4669: if (role == 'cc') {
4670: alert("$alerts{'secd'}\\n$alerts{'accr'}");
4671: }
4672: else {
4673: var sections = '';
4674: var numsec = 0;
4675: var sections;
4676: for (var j=0; j<formname.elements[i].length; j++) {
4677: if (formname.elements[i].options[j].selected == true ) {
4678: if (formname.elements[i].options[j].value != "") {
4679: if (numsec == 0) {
4680: if (formname.elements[i].options[j].value != "") {
4681: sections = formname.elements[i].options[j].value;
4682: numsec ++;
4683: }
4684: }
4685: else {
4686: sections = sections + "," + formname.elements[i].options[j].value
4687: numsec ++;
4688: }
4689: }
4690: }
4691: }
4692: if (numsec > 0) {
4693: if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
4694: sections = sections + "," + formname.elements[i+1].value;
4695: }
4696: }
4697: else {
4698: sections = formname.elements[i+1].value;
4699: }
4700: var newsecs = formname.elements[i+1].value;
4701: var numsplit;
4702: if (newsecs != null && newsecs != "") {
4703: numsplit = newsecs.split(/,/g);
4704: numsec = numsec + numsplit.length;
4705: }
4706:
4707: if ((role == 'st') && (numsec > 1)) {
4708: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
4709: return;
4710: }
4711: else {
4712: if (numsplit != null) {
4713: for (var j=0; j<numsplit.length; j++) {
4714: if ((numsplit[j] == 'all') ||
4715: (numsplit[j] == 'none')) {
4716: alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
4717: return;
4718: }
4719: for (var k=0; k<groups.length; k++) {
4720: if (numsplit[j] == groups[k]) {
4721: alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
4722: return;
4723: }
4724: }
4725: }
4726: }
4727: formname.elements[i+2].value = sections;
4728: }
4729: }
4730: }
4731: }
4732: }
4733: $finish
4734: }
4735: ENDSECCODE
1.11 raeburn 4736: return $setsection_js;
1.8 raeburn 4737: }
4738:
1.15 raeburn 4739: sub can_create_user {
4740: my ($dom,$context,$usertype) = @_;
4741: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4742: my $cancreate = 1;
1.28 raeburn 4743: if (&Apache::lonnet::allowed('mau',$dom)) {
4744: return $cancreate;
4745: }
1.15 raeburn 4746: if (ref($domconf{'usercreation'}) eq 'HASH') {
4747: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
1.100 ! raeburn 4748: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
1.15 raeburn 4749: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
4750: if ($creation eq 'none') {
4751: $cancreate = 0;
4752: } elsif ($creation ne 'any') {
4753: if (defined($usertype)) {
4754: if ($creation ne $usertype) {
4755: $cancreate = 0;
4756: }
4757: }
4758: }
4759: }
4760: }
4761: }
4762: return $cancreate;
4763: }
4764:
1.20 raeburn 4765: sub can_modify_userinfo {
4766: my ($context,$dom,$fields,$userroles) = @_;
4767: my %domconfig =
4768: &Apache::lonnet::get_dom('configuration',['usermodification'],
4769: $dom);
4770: my %canmodify;
4771: if (ref($fields) eq 'ARRAY') {
4772: foreach my $field (@{$fields}) {
4773: $canmodify{$field} = 0;
4774: if (&Apache::lonnet::allowed('mau',$dom)) {
4775: $canmodify{$field} = 1;
4776: } else {
4777: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4778: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
4779: if (ref($userroles) eq 'ARRAY') {
4780: foreach my $role (@{$userroles}) {
4781: my $testrole;
1.60 raeburn 4782: if ($context eq 'selfcreate') {
4783: $testrole = $role;
1.20 raeburn 4784: } else {
1.60 raeburn 4785: if ($role =~ /^cr\//) {
4786: $testrole = 'cr';
4787: } else {
4788: $testrole = $role;
4789: }
1.20 raeburn 4790: }
4791: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
4792: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
4793: $canmodify{$field} = 1;
4794: last;
4795: }
4796: }
4797: }
4798: } else {
4799: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
4800: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
4801: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
4802: $canmodify{$field} = 1;
4803: last;
4804: }
4805: }
4806: }
4807: }
4808: }
4809: } elsif ($context eq 'course') {
4810: if (ref($userroles) eq 'ARRAY') {
4811: if (grep(/^st$/,@{$userroles})) {
4812: $canmodify{$field} = 1;
4813: }
4814: } else {
4815: $canmodify{$field} = 1;
4816: }
4817: }
4818: }
4819: }
4820: }
4821: return %canmodify;
4822: }
4823:
1.18 raeburn 4824: sub check_usertype {
4825: my ($dom,$uname,$rules) = @_;
4826: my $usertype;
4827: if (ref($rules) eq 'HASH') {
4828: my @user_rules = keys(%{$rules});
4829: if (@user_rules > 0) {
4830: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
4831: if (keys(%rule_check) > 0) {
4832: $usertype = 'unofficial';
4833: foreach my $item (keys(%rule_check)) {
4834: if ($rule_check{$item}) {
4835: $usertype = 'official';
4836: last;
4837: }
4838: }
4839: }
4840: }
4841: }
4842: return $usertype;
4843: }
4844:
1.17 raeburn 4845: sub roles_by_context {
4846: my ($context,$custom) = @_;
4847: my @allroles;
4848: if ($context eq 'course') {
1.99 raeburn 4849: @allroles = ('st');
4850: if ($env{'request.role'} =~ m{^dc\./}) {
4851: push(@allroles,'ad');
4852: }
4853: push(@allroles,('ta','ep','in','cc'));
1.17 raeburn 4854: if ($custom) {
4855: push(@allroles,'cr');
4856: }
4857: } elsif ($context eq 'author') {
4858: @allroles = ('ca','aa');
4859: } elsif ($context eq 'domain') {
1.99 raeburn 4860: @allroles = ('li','ad','dg','sc','au','dc');
1.17 raeburn 4861: }
4862: return @allroles;
4863: }
4864:
1.16 raeburn 4865: sub get_permission {
1.17 raeburn 4866: my ($context,$roles) = @_;
1.16 raeburn 4867: my %permission;
4868: if ($context eq 'course') {
1.17 raeburn 4869: my $custom = 1;
4870: my @allroles = &roles_by_context($context,$custom);
4871: foreach my $role (@allroles) {
4872: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
4873: $permission{'cusr'} = 1;
4874: last;
4875: }
1.16 raeburn 4876: }
4877: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
4878: $permission{'custom'} = 1;
4879: }
4880: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
4881: $permission{'view'} = 1;
4882: }
4883: if (!$permission{'view'}) {
4884: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
4885: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
4886: if ($permission{'view'}) {
4887: $permission{'view_section'} = $env{'request.course.sec'};
4888: }
4889: }
1.17 raeburn 4890: if (!$permission{'cusr'}) {
4891: if ($env{'request.course.sec'} ne '') {
4892: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
4893: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
4894: if ($permission{'cusr'}) {
4895: $permission{'cusr_section'} = $env{'request.course.sec'};
4896: }
4897: }
4898: }
1.16 raeburn 4899: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
4900: $permission{'grp_manage'} = 1;
4901: }
4902: } elsif ($context eq 'author') {
4903: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
4904: $permission{'view'} = $permission{'cusr'};
4905: } else {
1.17 raeburn 4906: my @allroles = &roles_by_context($context);
4907: foreach my $role (@allroles) {
1.28 raeburn 4908: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
4909: $permission{'cusr'} = 1;
1.17 raeburn 4910: last;
4911: }
4912: }
4913: if (!$permission{'cusr'}) {
4914: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
4915: $permission{'cusr'} = 1;
4916: }
1.16 raeburn 4917: }
4918: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
4919: $permission{'custom'} = 1;
4920: }
4921: $permission{'view'} = $permission{'cusr'};
4922: }
4923: my $allowed = 0;
4924: foreach my $perm (values(%permission)) {
4925: if ($perm) { $allowed=1; last; }
4926: }
4927: return (\%permission,$allowed);
4928: }
4929:
4930: # ==================================================== Figure out author access
4931:
4932: sub authorpriv {
4933: my ($auname,$audom)=@_;
4934: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
4935: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
4936: }
4937:
1.27 raeburn 4938: sub roles_on_upload {
1.42 raeburn 4939: my ($context,$setting,%customroles) = @_;
1.27 raeburn 4940: my (@possible_roles,@permitted_roles);
1.42 raeburn 4941: @possible_roles = &curr_role_permissions($context,$setting,1);
1.27 raeburn 4942: foreach my $role (@possible_roles) {
4943: if ($role eq 'cr') {
4944: push(@permitted_roles,keys(%customroles));
4945: } else {
4946: push(@permitted_roles,$role);
4947: }
4948: }
1.42 raeburn 4949: return @permitted_roles;
1.27 raeburn 4950: }
4951:
1.17 raeburn 4952: sub get_course_identity {
4953: my ($cid) = @_;
4954: my ($cnum,$cdom,$cdesc);
4955: if ($cid eq '') {
4956: $cid = $env{'request.course.id'}
4957: }
4958: if ($cid ne '') {
4959: $cnum = $env{'course.'.$cid.'.num'};
4960: $cdom = $env{'course.'.$cid.'.domain'};
4961: $cdesc = $env{'course.'.$cid.'.description'};
4962: if ($cnum eq '' || $cdom eq '') {
4963: my %coursehash =
4964: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
4965: $cdom = $coursehash{'domain'};
4966: $cnum = $coursehash{'num'};
4967: $cdesc = $coursehash{'description'};
4968: }
4969: }
4970: return ($cnum,$cdom,$cdesc);
4971: }
4972:
1.19 raeburn 4973: sub dc_setcourse_js {
1.37 raeburn 4974: my ($formname,$mode,$context) = @_;
4975: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 4976: my $cctext = &Apache::lonnet::plaintext('cc');
4977: my %alerts = §ioncheck_alerts();
4978: my $role = 'role';
4979: if ($mode eq 'upload') {
4980: $role = 'courserole';
1.37 raeburn 4981: } else {
4982: $authen_check = &verify_authen($formname,$context);
1.19 raeburn 4983: }
4984: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 4985: $authen_check
4986:
1.19 raeburn 4987: function setCourse() {
4988: var course = document.$formname.dccourse.value;
4989: if (course != "") {
4990: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
4991: alert("$alerts{'curd'}");
4992: return;
4993: }
4994: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
4995: var section="";
4996: var numsections = 0;
4997: var newsecs = new Array();
4998: for (var i=0; i<document.$formname.currsec.length; i++) {
4999: if (document.$formname.currsec.options[i].selected == true ) {
5000: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
5001: if (numsections == 0) {
5002: section = document.$formname.currsec.options[i].value
5003: numsections = 1;
5004: }
5005: else {
5006: section = section + "," + document.$formname.currsec.options[i].value
5007: numsections ++;
5008: }
5009: }
5010: }
5011: }
5012: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
5013: if (numsections == 0) {
5014: section = document.$formname.newsec.value
5015: }
5016: else {
5017: section = section + "," + document.$formname.newsec.value
5018: }
5019: newsecs = document.$formname.newsec.value.split(/,/g);
5020: numsections = numsections + newsecs.length;
5021: }
5022: if ((userrole == 'st') && (numsections > 1)) {
5023: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
5024: return;
5025: }
5026: for (var j=0; j<newsecs.length; j++) {
5027: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
5028: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
5029: return;
5030: }
5031: if (document.$formname.groups.value != '') {
5032: var groups = document.$formname.groups.value.split(/,/g);
5033: for (var k=0; k<groups.length; k++) {
5034: if (newsecs[j] == groups[k]) {
5035: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
5036: return;
5037: }
5038: }
5039: }
5040: }
5041: if ((userrole == 'cc') && (numsections > 0)) {
5042: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
5043: section = "";
5044: }
5045: SCRIPTTOP
5046: if ($mode ne 'upload') {
5047: $dc_setcourse_code .= (<<"ENDSCRIPT");
5048: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
5049: var numcourse = getIndex(document.$formname.dccourse);
5050: if (numcourse == "-1") {
5051: alert("$alerts{'thwa'}");
5052: return;
5053: }
5054: else {
5055: document.$formname.elements[numcourse].name = "act"+coursename;
5056: var numnewsec = getIndex(document.$formname.newsec);
5057: if (numnewsec != "-1") {
5058: document.$formname.elements[numnewsec].name = "sec"+coursename;
5059: document.$formname.elements[numnewsec].value = section;
5060: }
5061: var numstart = getIndex(document.$formname.start);
5062: if (numstart != "-1") {
5063: document.$formname.elements[numstart].name = "start"+coursename;
5064: }
5065: var numend = getIndex(document.$formname.end);
5066: if (numend != "-1") {
5067: document.$formname.elements[numend].name = "end"+coursename
5068: }
5069: }
5070: }
1.37 raeburn 5071: var authcheck = auth_check();
5072: if (authcheck == 'ok') {
5073: document.$formname.submit();
5074: }
1.19 raeburn 5075: }
5076: ENDSCRIPT
5077: } else {
5078: $dc_setcourse_code .= "
5079: document.$formname.sections.value = section;
5080: }
5081: return 'ok';
5082: }
5083: ";
5084: }
5085: $dc_setcourse_code .= (<<"ENDSCRIPT");
5086:
5087: function getIndex(caller) {
5088: for (var i=0;i<document.$formname.elements.length;i++) {
5089: if (document.$formname.elements[i] == caller) {
5090: return i;
5091: }
5092: }
5093: return -1;
5094: }
5095: ENDSCRIPT
1.37 raeburn 5096: return $dc_setcourse_code;
5097: }
5098:
5099: sub verify_authen {
5100: my ($formname,$context) = @_;
5101: my %alerts = &authcheck_alerts();
5102: my $finish = "return 'ok';";
5103: if ($context eq 'author') {
5104: $finish = "document.$formname.submit();";
5105: }
5106: my $outcome = <<"ENDSCRIPT";
5107:
5108: function auth_check() {
5109: var logintype;
5110: if (document.$formname.login.length) {
5111: if (document.$formname.login.length > 0) {
5112: var loginpicked = 0;
5113: for (var i=0; i<document.$formname.login.length; i++) {
5114: if (document.$formname.login[i].checked == true) {
5115: loginpicked = 1;
5116: logintype = document.$formname.login[i].value;
5117: }
5118: }
5119: if (loginpicked == 0) {
5120: alert("$alerts{'authen'}");
5121: return;
5122: }
5123: }
5124: } else {
5125: logintype = document.$formname.login.value;
5126: }
5127: if (logintype == 'nochange') {
5128: return 'ok';
5129: }
5130: var argpicked = document.$formname.elements[logintype+'arg'].value;
5131: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
5132: var alertmsg = '';
5133: switch (logintype) {
5134: case 'krb':
5135: alertmsg = '$alerts{'krb'}';
5136: break;
5137: case 'int':
5138: alertmsg = '$alerts{'ipass'}';
5139: case 'fsys':
5140: alertmsg = '$alerts{'ipass'}';
5141: break;
5142: case 'loc':
5143: alertmsg = '';
5144: break;
5145: default:
5146: alertmsg = '';
5147: }
5148: if (alertmsg != '') {
5149: alert(alertmsg);
5150: return;
5151: }
5152: }
5153: $finish
5154: }
5155: ENDSCRIPT
1.19 raeburn 5156: }
5157:
5158: sub sectioncheck_alerts {
5159: my %alerts = &Apache::lonlocal::texthash(
5160: curd => 'You must select a course in the current domain',
5161: inea => 'In each course, each user may only have one student role at a time',
5162: youh => 'You had selected',
5163: sect => 'sections',
5164: plsm => 'Please modify your selections so they include no more than one section',
5165: mayn => 'may not be used as the name for a section, as it is a reserved word',
5166: plsc => 'Please choose a different section name',
5167: mayt => 'may not be used as the name for a section, as it is the name of a course group',
5168: secn => 'Section names and group names must be distinct',
5169: secd => 'Section designations do not apply to ',
5170: role => 'roles',
5171: accr => 'role will be added with access to all sections',
5172: thwa => 'There was a problem with your course selection'
5173: );
5174: return %alerts;
5175: }
1.17 raeburn 5176:
1.37 raeburn 5177: sub authcheck_alerts {
5178: my %alerts =
5179: &Apache::lonlocal::texthash(
5180: authen => 'You must choose an authentication type.',
5181: krb => 'You need to specify the Kerberos domain.',
5182: ipass => 'You need to specify the initial password.',
5183: );
5184: return %alerts;
5185: }
5186:
1.1 raeburn 5187: 1;
5188:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>