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