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