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