Annotation of loncom/interface/lonuserutils.pm, revision 1.197
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.197 ! raeburn 4: # $Id: lonuserutils.pm,v 1.196 2019/05/04 19:57:29 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ###############################################################
30:
31: package Apache::lonuserutils;
32:
1.175 raeburn 33: =pod
34:
35: =head1 NAME
36:
37: Apache::lonuserutils.pm
38:
39: =head1 SYNOPSIS
40:
41: Utilities for management of users and custom roles
42:
43: Provides subroutines called by loncreateuser.pm
44:
45: =head1 OVERVIEW
46:
47: =cut
48:
1.1 raeburn 49: use strict;
50: use Apache::lonnet;
51: use Apache::loncommon();
52: use Apache::lonhtmlcommon;
53: use Apache::lonlocal;
1.8 raeburn 54: use Apache::longroup;
1.174 raeburn 55: use HTML::Entities;
1.8 raeburn 56: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 57:
58: ###############################################################
59: ###############################################################
60: # Drop student from all sections of a course, except optional $csec
61: sub modifystudent {
1.52 raeburn 62: my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
1.1 raeburn 63: # if $csec is undefined, drop the student from all the courses matching
64: # this one. If $csec is defined, drop them from all other sections of
65: # this course and add them to section $csec
1.17 raeburn 66: my ($cnum,$cdom) = &get_course_identity($courseid);
1.138 raeburn 67: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
1.1 raeburn 68: my ($tmp) = keys(%roles);
69: # Bail out if we were unable to get the students roles
70: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
71: # Go through the roles looking for enrollment in this course
72: my $result = '';
73: foreach my $course (keys(%roles)) {
74: if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
75: # We are in this course
76: my $section=$1;
77: $section='' if ($course eq "/$cdom/$cnum".'_st');
78: if (defined($csec) && $section eq $csec) {
79: $result .= 'ok:';
80: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
81: my (undef,$end,$start)=split(/\_/,$roles{$course});
82: my $now=time;
83: # if this is an active role
84: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
85: my $reply=&Apache::lonnet::modifystudent
86: # dom name id mode pass f m l g
87: ($udom,$unam,'', '', '',undef,undef,undef,undef,
1.22 raeburn 88: $section,time,undef,undef,$desiredhost,'','manual',
1.52 raeburn 89: '',$courseid,'',$context);
1.1 raeburn 90: $result .= $reply.':';
91: }
92: }
93: }
94: }
95: if ($result eq '') {
1.37 raeburn 96: $result = &mt('Unable to find section for this student');
1.1 raeburn 97: } else {
98: $result =~ s/(ok:)+/ok/g;
99: }
100: return $result;
101: }
102:
103: sub modifyuserrole {
104: my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
105: $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
1.84 raeburn 106: $end,$start,$checkid,$inststatus) = @_;
1.5 raeburn 107: my ($scope,$userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 108: if ($setting eq 'course' || $context eq 'course') {
109: $scope = '/'.$cid;
110: $scope =~ s/\_/\//g;
1.103 raeburn 111: if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
1.1 raeburn 112: $scope .='/'.$sec;
113: }
1.5 raeburn 114: } elsif ($context eq 'domain') {
1.1 raeburn 115: $scope = '/'.$env{'request.role.domain'}.'/';
1.13 raeburn 116: } elsif ($context eq 'author') {
1.1 raeburn 117: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
118: }
119: if ($context eq 'domain') {
120: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
121: if ($uhome ne 'no_host') {
1.5 raeburn 122: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
1.1 raeburn 123: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
124: ($umode eq 'localauth')) {
125: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
126: }
127: }
1.5 raeburn 128: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
129: ($env{'form.recurseid'}) && ($checkid)) {
130: my %userupdate = (
131: lastname => $last,
132: middlename => $middle,
133: firstname => $first,
134: generation => $gene,
135: id => $uid,
136: );
137: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
138: }
1.1 raeburn 139: }
140: }
141: $userresult =
142: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
143: $middle,$last,$gene,$forceid,$desiredhome,
1.84 raeburn 144: $email,$inststatus);
1.1 raeburn 145: if ($userresult eq 'ok') {
1.5 raeburn 146: if ($role ne '') {
1.22 raeburn 147: $role =~ s/_/\//g;
1.1 raeburn 148: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
1.52 raeburn 149: $role,$end,$start,'',
150: '',$context);
1.1 raeburn 151: }
152: }
1.5 raeburn 153: return ($userresult,$authresult,$roleresult,$idresult);
1.1 raeburn 154: }
155:
1.5 raeburn 156: sub propagate_id_change {
157: my ($uname,$udom,$user) = @_;
1.12 raeburn 158: my (@types,@roles);
1.5 raeburn 159: @types = ('active','future');
160: @roles = ('st');
161: my $idresult;
162: my %roleshash = &Apache::lonnet::get_my_roles($uname,
1.12 raeburn 163: $udom,'userroles',\@types,\@roles);
164: my %args = (
165: one_time => 1,
166: );
1.5 raeburn 167: foreach my $item (keys(%roleshash)) {
1.22 raeburn 168: my ($cnum,$cdom,$role) = split(/:/,$item,-1);
1.5 raeburn 169: my ($start,$end) = split(/:/,$roleshash{$item});
170: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.12 raeburn 171: my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
172: my %coursehash =
173: &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
174: my $cdesc = $coursehash{'description'};
175: if ($cdesc eq '') {
176: $cdesc = $cdom.'_'.$cnum;
177: }
1.5 raeburn 178: if ($result eq 'ok') {
1.12 raeburn 179: $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 180: } else {
1.12 raeburn 181: $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5 raeburn 182: }
183: }
184: }
185: return $idresult;
186: }
187:
188: sub update_classlist {
1.63 raeburn 189: my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
1.6 albertel 190: my ($uid,$classlistentry);
1.5 raeburn 191: my $fullname =
192: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
193: $user->{'lastname'},$user->{'generation'},
194: 'lastname');
195: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
196: $cdom,$cnum);
197: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
198: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
199: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
1.63 raeburn 200: my $endidx = &Apache::loncoursedata::CL_END() - 2;
201: my $startidx = &Apache::loncoursedata::CL_START() - 2;
1.5 raeburn 202: for (my $i=0; $i<@classinfo; $i++) {
1.63 raeburn 203: if ($i == $endidx) {
204: if ($newend ne '') {
205: $classlistentry .= $newend.':';
206: } else {
207: $classlistentry .= $classinfo[$i].':';
208: }
209: } elsif ($i == $startidx) {
210: if ($newend ne '') {
211: if ($classinfo[$i] > $newend) {
212: $classlistentry .= $newend.':';
213: } else {
214: $classlistentry .= $classinfo[$i].':';
215: }
216: } else {
217: $classlistentry .= $classinfo[$i].':';
218: }
219: } elsif ($i == $ididx) {
1.5 raeburn 220: if (defined($user->{'id'})) {
221: $classlistentry .= $user->{'id'}.':';
222: } else {
223: $classlistentry .= $classinfo[$i].':';
224: }
225: } elsif ($i == $nameidx) {
1.63 raeburn 226: if (defined($user->{'lastname'})) {
227: $classlistentry .= $fullname.':';
228: } else {
229: $classlistentry .= $classinfo[$i].':';
230: }
1.5 raeburn 231: } else {
232: $classlistentry .= $classinfo[$i].':';
233: }
234: }
235: $classlistentry =~ s/:$//;
236: my $reply=&Apache::lonnet::cput('classlist',
237: {"$uname:$udom" => $classlistentry},
238: $cdom,$cnum);
239: if (($reply eq 'ok') || ($reply eq 'delayed')) {
240: return 'ok';
241: } else {
242: return 'error: '.$reply;
243: }
244: }
245:
246:
1.1 raeburn 247: ###############################################################
248: ###############################################################
1.2 raeburn 249: # build a role type and role selection form
250: sub domain_roles_select {
251: # Set up the role type and role selection boxes when in
252: # domain context
253: #
254: # Role types
1.101 raeburn 255: my @roletypes = ('domain','author','course','community');
1.2 raeburn 256: my %lt = &role_type_names();
1.149 raeburn 257: my $onchangefirst = "updateCols('showrole')";
258: my $onchangesecond = "updateCols('showrole')";
1.1 raeburn 259: #
260: # build up the menu information to be passed to
261: # &Apache::loncommon::linked_select_forms
262: my %select_menus;
1.2 raeburn 263: if ($env{'form.roletype'} eq '') {
264: $env{'form.roletype'} = 'domain';
265: }
266: foreach my $roletype (@roletypes) {
1.1 raeburn 267: # set up the text for this domain
1.2 raeburn 268: $select_menus{$roletype}->{'text'}= $lt{$roletype};
1.102 raeburn 269: my $crstype;
270: if ($roletype eq 'community') {
271: $crstype = 'Community';
272: }
1.1 raeburn 273: # we want a choice of 'default' as the default in the second menu
1.2 raeburn 274: if ($env{'form.roletype'} ne '') {
275: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
276: } else {
277: $select_menus{$roletype}->{'default'} = 'Any';
278: }
1.1 raeburn 279: # Now build up the other items in the second menu
1.2 raeburn 280: my @roles;
281: if ($roletype eq 'domain') {
282: @roles = &domain_roles();
1.13 raeburn 283: } elsif ($roletype eq 'author') {
1.2 raeburn 284: @roles = &construction_space_roles();
285: } else {
1.17 raeburn 286: my $custom = 1;
1.101 raeburn 287: @roles = &course_roles('domain',undef,$custom,$roletype);
1.1 raeburn 288: }
1.2 raeburn 289: my $order = ['Any',@roles];
290: $select_menus{$roletype}->{'order'} = $order;
291: foreach my $role (@roles) {
1.5 raeburn 292: if ($role eq 'cr') {
293: $select_menus{$roletype}->{'select2'}->{$role} =
294: &mt('Custom role');
295: } else {
296: $select_menus{$roletype}->{'select2'}->{$role} =
1.102 raeburn 297: &Apache::lonnet::plaintext($role,$crstype);
1.5 raeburn 298: }
1.2 raeburn 299: }
300: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
1.1 raeburn 301: }
1.2 raeburn 302: my $result = &Apache::loncommon::linked_select_forms
303: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
1.101 raeburn 304: 'roletype','showrole',\%select_menus,
1.149 raeburn 305: ['domain','author','course','community'],$onchangefirst,
306: $onchangesecond);
1.1 raeburn 307: return $result;
308: }
309:
310: ###############################################################
311: ###############################################################
312: sub hidden_input {
313: my ($name,$value) = @_;
314: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
315: }
316:
317: sub print_upload_manager_header {
1.123 raeburn 318: my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
319: $can_assign)=@_;
1.1 raeburn 320: my $javascript;
321: #
322: if (! exists($env{'form.upfile_associate'})) {
323: $env{'form.upfile_associate'} = 'forward';
324: }
325: if ($env{'form.associate'} eq 'Reverse Association') {
326: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
327: $env{'form.upfile_associate'} = 'reverse';
328: } else {
329: $env{'form.upfile_associate'} = 'forward';
330: }
331: }
332: if ($env{'form.upfile_associate'} eq 'reverse') {
1.123 raeburn 333: $javascript=&upload_manager_javascript_reverse_associate($can_assign);
1.1 raeburn 334: } else {
1.123 raeburn 335: $javascript=&upload_manager_javascript_forward_associate($can_assign);
1.1 raeburn 336: }
337: #
338: # Deal with restored settings
339: my $password_choice = '';
340: if (exists($env{'form.ipwd_choice'}) &&
341: $env{'form.ipwd_choice'} ne '') {
342: # If a column was specified for password, assume it is for an
343: # internal password. This is a bug waiting to be filed (could be
344: # local or krb auth instead of internal) but I do not have the
345: # time to mess around with this now.
346: $password_choice = 'int';
347: }
348: #
1.22 raeburn 349: my $groupslist;
350: if ($context eq 'course') {
351: $groupslist = &get_groupslist();
352: }
1.1 raeburn 353: my $javascript_validations =
1.22 raeburn 354: &javascript_validations('upload',$krbdefdom,$password_choice,undef,
355: $env{'request.role.domain'},$context,
1.103 raeburn 356: $groupslist,$crstype);
1.91 bisitz 357: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.147 bisitz 358: $r->print(
359: '<h3>'.&mt('Identify fields in uploaded list')."</h3>\n".
360: '<p class="LC_info">'.
361: &mt('Total number of records found in file: [_1]'
362: ,'<b>'.$distotal.'</b>').
363: "</p>\n"
364: );
365: if ($distotal == 0) {
366: $r->print('<p class="LC_warning">'.&mt('None found').'</p>');
367: }
368: $r->print(
369: '<p>'.
370: &mt('Enter as many fields as you can.').'<br />'.
371: &mt('The system will inform you and bring you back to this page,[_1]if the data selected are insufficient to add users.','<br />').
372: "</p>\n"
373: );
1.1 raeburn 374: $r->print(&hidden_input('action','upload').
375: &hidden_input('state','got_file').
376: &hidden_input('associate','').
377: &hidden_input('datatoken',$datatoken).
378: &hidden_input('fileupload',$env{'form.fileupload'}).
379: &hidden_input('upfiletype',$env{'form.upfiletype'}).
380: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
1.147 bisitz 381: $r->print(
382: '<div class="LC_left_float">'.
383: '<fieldset><legend>'.&mt('Functions').'</legend>'.
384: '<label><input type="checkbox" name="noFirstLine"'.$checked.' />'.
385: &mt('Ignore First Line').'</label>'.
386: ' <input type="button" value="'.&mt('Reverse Association').'" '.
1.59 bisitz 387: 'name="Reverse Association" '.
1.147 bisitz 388: 'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />'.
389: '</fieldset></div><br clear="all" />'
390: );
391: $r->print(
392: '<script type="text/javascript" language="Javascript">'."\n".
393: '// <![CDATA['."\n".
394: $javascript."\n".$javascript_validations."\n".
395: '// ]]>'."\n".
396: '</script>'
397: );
1.1 raeburn 398: }
399:
400: ###############################################################
401: ###############################################################
402: sub javascript_validations {
1.22 raeburn 403: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
1.103 raeburn 404: $context,$groupslist,$crstype)=@_;
1.22 raeburn 405: my %param = (
406: kerb_def_dom => $krbdefdom,
407: curr_authtype => $curr_authtype,
408: );
1.37 raeburn 409: if ($mode eq 'upload') {
1.22 raeburn 410: $param{'formname'} = 'studentform';
1.1 raeburn 411: } elsif ($mode eq 'createcourse') {
1.22 raeburn 412: $param{'formname'} = 'ccrs';
1.1 raeburn 413: } elsif ($mode eq 'modifycourse') {
1.22 raeburn 414: $param{'formname'} = 'cmod';
415: $param{'mode'} = 'modifycourse',
416: $param{'curr_autharg'} = $curr_authfield;
417: }
418:
1.150 raeburn 419: my $showcredits;
420: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1.160 raeburn 421: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 422: $showcredits = 1;
423: }
424:
1.22 raeburn 425: my ($setsection_call,$setsections_js);
426: my $finish = " vf.submit();\n";
427: if ($mode eq 'upload') {
428: if (($context eq 'course') || ($context eq 'domain')) {
429: if ($context eq 'course') {
430: if ($env{'request.course.sec'} eq '') {
1.109 raeburn 431: $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
1.22 raeburn 432: $setsections_js =
433: &setsections_javascript($param{'formname'},$groupslist,
1.150 raeburn 434: $mode,'',$crstype,$showcredits);
1.22 raeburn 435: } else {
436: $setsection_call = "'ok'";
437: }
438: } elsif ($context eq 'domain') {
439: $setsection_call = 'setCourse()';
1.150 raeburn 440: $setsections_js = &dc_setcourse_js($param{'formname'},$mode,
1.196 raeburn 441: $context,$showcredits,$domain);
1.22 raeburn 442: }
443: $finish = " var checkSec = $setsection_call\n".
444: " if (checkSec == 'ok') {\n".
445: " vf.submit();\n".
446: " }\n";
447: }
1.1 raeburn 448: }
1.22 raeburn 449: my $authheader = &Apache::loncommon::authform_header(%param);
1.1 raeburn 450:
451: my %alert = &Apache::lonlocal::texthash
452: (username => 'You need to specify the username field.',
453: authen => 'You must choose an authentication type.',
454: krb => 'You need to specify the Kerberos domain.',
455: ipass => 'You need to specify the initial password.',
456: name => 'The optional name field was not specified.',
1.93 bisitz 457: snum => 'The optional student/employee ID field was not specified.',
1.1 raeburn 458: section => 'The optional section field was not specified.',
1.75 schafran 459: email => 'The optional e-mail address field was not specified.',
1.1 raeburn 460: role => 'The optional role field was not specified.',
1.57 raeburn 461: domain => 'The optional domain field was not specified.',
1.1 raeburn 462: continue => 'Continue adding users?',
463: );
1.150 raeburn 464: if ($showcredits) {
465: $alert{'credits'} = &mt('The optional credits field was not specified');
466: }
1.84 raeburn 467: if (($mode eq 'upload') && ($context eq 'domain')) {
468: $alert{'inststatus'} = &mt('The optional affiliation field was not specified');
469: }
1.170 damieng 470: &js_escape(\%alert);
1.37 raeburn 471: my $function_name = <<"END";
1.22 raeburn 472: $setsections_js
473:
1.150 raeburn 474: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits) {
1.1 raeburn 475: END
476: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
477: my $auth_checks;
478: if ($mode eq 'createcourse') {
479: $auth_checks .= (<<END);
480: if (vf.autoadds[0].checked == true) {
481: if (current.radiovalue == null || current.radiovalue == 'nochange') {
482: alert('$alert{'authen'}');
483: return;
484: }
485: }
486: END
487: } else {
488: $auth_checks .= (<<END);
489: var foundatype=0;
490: if (founduname==0) {
491: alert('$alert{'username'}');
492: return;
493: }
494:
495: END
496: if ($authnum > 1) {
497: $auth_checks .= (<<END);
498: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
499: // They did not check any of the login radiobuttons.
500: alert('$alert{'authen'}');
501: return;
502: }
503: END
504: }
505: }
506: if ($mode eq 'createcourse') {
507: $auth_checks .= "
508: if ( (vf.autoadds[0].checked == true) &&
509: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
510: ";
511: } elsif ($mode eq 'modifycourse') {
512: $auth_checks .= "
513: if (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') {
514: ";
515: }
516: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
517: $auth_checks .= (<<END);
518: var alertmsg = '';
519: switch (current.radiovalue) {
520: case 'krb':
521: alertmsg = '$alert{'krb'}';
522: break;
523: default:
524: alertmsg = '';
525: }
526: if (alertmsg != '') {
527: alert(alertmsg);
528: return;
529: }
530: }
1.150 raeburn 531: /* regexp here to check for non \d \. in credits */
1.1 raeburn 532: END
533: } else {
1.196 raeburn 534: my ($numrules,$intargjs) =
535: &passwd_validation_js('vf.elements[current.argfield].value',$domain);
1.1 raeburn 536: $auth_checks .= (<<END);
537: foundatype=1;
538: if (current.argfield == null || current.argfield == '') {
1.196 raeburn 539: // The login radiobutton checked does not have an associated textbox
540: } else if (vf.elements[current.argfield].value == '') {
1.1 raeburn 541: var alertmsg = '';
1.38 raeburn 542: switch (current.radiovalue) {
1.1 raeburn 543: case 'krb':
544: alertmsg = '$alert{'krb'}';
545: break;
546: case 'loc':
1.196 raeburn 547: case 'int':
1.1 raeburn 548: alertmsg = '$alert{'ipass'}';
549: break;
550: case 'fsys':
1.196 raeburn 551: alertmsg = '$alert{'ipass'}';
1.1 raeburn 552: break;
1.194 raeburn 553: case 'lti':
1.1 raeburn 554: default:
555: alertmsg = '';
556: }
557: if (alertmsg != '') {
558: alert(alertmsg);
559: return;
560: }
1.196 raeburn 561: } else if (current.radiovalue == 'int') {
562: if ($numrules > 0) {
563: $intargjs
564: }
1.1 raeburn 565: }
566: END
567: }
568: my $section_checks;
569: my $optional_checks = '';
570: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
571: $optional_checks = (<<END);
572: vf.submit();
573: }
574: END
575: } else {
576: $section_checks = §ion_check_js();
577: $optional_checks = (<<END);
578: var message='';
579: if (foundname==0) {
580: message='$alert{'name'}';
581: }
582: if (foundid==0) {
583: if (message!='') {
584: message+='\\n';
585: }
586: message+='$alert{'snum'}';
587: }
588: if (foundsec==0) {
589: if (message!='') {
590: message+='\\n';
591: }
1.130 raeburn 592: message+='$alert{'section'}';
1.1 raeburn 593: }
594: if (foundemail==0) {
595: if (message!='') {
596: message+='\\n';
597: }
598: message+='$alert{'email'}';
599: }
1.57 raeburn 600: if (foundrole==0) {
601: if (message!='') {
602: message+='\\n';
603: }
604: message+='$alert{'role'}';
605: }
606: if (founddomain==0) {
607: if (message!='') {
608: message+='\\n';
609: }
610: message+='$alert{'domain'}';
611: }
1.84 raeburn 612: END
1.150 raeburn 613: if ($showcredits) {
614: $optional_checks .= <<END;
615: if (foundcredits==0) {
616: if (message!='') {
617: message+='\\n';
618: }
619: message+='$alert{'credits'}';
620: }
621: END
622: }
1.84 raeburn 623: if (($mode eq 'upload') && ($context eq 'domain')) {
624: $optional_checks .= (<<END);
625:
626: if (foundinststatus==0) {
627: if (message!='') {
628: message+='\\n';
629: }
630: message+='$alert{'inststatus'}';
631: }
632: END
633: }
634: $optional_checks .= (<<END);
635:
1.1 raeburn 636: if (message!='') {
637: message+= '\\n$alert{'continue'}';
638: if (confirm(message)) {
639: vf.state.value='enrolling';
1.22 raeburn 640: $finish
1.1 raeburn 641: }
642: } else {
643: vf.state.value='enrolling';
1.22 raeburn 644: $finish
1.1 raeburn 645: }
646: }
647: END
648: }
1.37 raeburn 649: my $result = $function_name.$auth_checks.$optional_checks."\n".
650: $section_checks.$authheader;
1.1 raeburn 651: return $result;
652: }
1.196 raeburn 653:
654: sub passwd_validation_js {
655: my ($currpasswdval,$domain) = @_;
656: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
657: my ($min,$max,@chars,$numrules,$intargjs,%alert);
658: $numrules = 0;
659: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
660: if ($passwdconf{'min'} =~ /^\d+$/) {
661: $min = $passwdconf{'min'};
662: $numrules ++;
663: }
664: if ($passwdconf{'max'} =~ /^\d+$/) {
665: $max = $passwdconf{'max'};
666: $numrules ++;
667: }
668: @chars = @{$passwdconf{'chars'}};
669: if (@chars) {
670: $numrules ++;
671: }
672: } else {
673: $min = 7;
674: $numrules ++;
675: }
676: if (($min ne '') || ($max ne '') || (@chars > 0)) {
677: my $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
678: if ($min) {
679: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
680: }
681: if ($max) {
682: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
683: }
684: my (@charalerts,@charrules);
685: if (@chars) {
686: if (grep(/^uc$/,@chars)) {
687: push(@charalerts,&mt('contain at least one upper case letter'));
688: push(@charrules,'uc');
689: }
690: if (grep(/^lc$/,@chars)) {
691: push(@charalerts,&mt('contain at least one lower case letter'));
692: push(@charrules,'lc');
693: }
694: if (grep(/^num$/,@chars)) {
695: push(@charalerts,&mt('contain at least one number'));
696: push(@charrules,'num');
697: }
698: if (grep(/^spec$/,@chars)) {
699: push(@charalerts,&mt('contain at least one non-alphanumeric'));
700: push(@charrules,'spec');
701: }
702: }
703: $intargjs = qq| var rulesmsg = '';\n|.
704: qq| var currpwval = $currpasswdval;\n|;
705: if ($min) {
706: $intargjs .= qq|
707: if (currpwval.length < $min) {
708: rulesmsg += ' - $alert{min}';
709: }
710: |;
711: }
712: if ($max) {
713: $intargjs .= qq|
714: if (currpwval.length > $max) {
715: rulesmsg += ' - $alert{max}';
716: }
717: |;
718: }
719: if (@chars > 0) {
720: my $charrulestr = '"'.join('","',@charrules).'"';
721: my $charalertstr = '"'.join('","',@charalerts).'"';
722: $intargjs .= qq| var brokerules = new Array();\n|.
723: qq| var charrules = new Array($charrulestr);\n|.
724: qq| var charalerts = new Array($charalertstr);\n|;
725: my %rules;
726: map { $rules{$_} = 1; } @chars;
727: if ($rules{'uc'}) {
728: $intargjs .= qq|
729: var ucRegExp = /[A-Z]/;
730: if (!ucRegExp.test(currpwval)) {
731: brokerules.push('uc');
732: }
733: |;
734: }
735: if ($rules{'lc'}) {
736: $intargjs .= qq|
737: var lcRegExp = /[a-z]/;
738: if (!lcRegExp.test(currpwval)) {
739: brokerules.push('lc');
740: }
741: |;
742: }
743: if ($rules{'num'}) {
744: $intargjs .= qq|
745: var numRegExp = /[0-9]/;
746: if (!numRegExp.test(currpwval)) {
747: brokerules.push('num');
748: }
749: |;
750: }
751: if ($rules{'spec'}) {
752: $intargjs .= q|
753: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{\|}~]/;
754: if (!specRegExp.test(currpwval)) {
755: brokerules.push('spec');
756: }
757: |;
758: }
759: $intargjs .= qq|
760: if (brokerules.length > 0) {
761: for (var i=0; i<brokerules.length; i++) {
762: for (var j=0; j<charrules.length; j++) {
763: if (brokerules[i] == charrules[j]) {
764: rulesmsg += ' - '+charalerts[j]+'\\n';
765: break;
766: }
767: }
768: }
769: }
770: |;
771: }
772: $intargjs .= qq|
773: if (rulesmsg != '') {
774: rulesmsg = '$alertmsg'+rulesmsg;
775: alert(rulesmsg);
1.197 ! raeburn 776: return false;
1.196 raeburn 777: }
778: |;
779: }
780: return ($numrules,$intargjs);
781: }
782:
1.1 raeburn 783: ###############################################################
784: ###############################################################
785: sub upload_manager_javascript_forward_associate {
1.123 raeburn 786: my ($can_assign) = @_;
1.132 raeburn 787: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 788: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 789: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
790: $argreset .= " vf.krbarg.value='';\n";
791: $numbuttons ++ ;
792: }
793: if ($can_assign->{'int'}) {
794: $argreset .= " vf.intarg.value='';\n";
795: $numbuttons ++;
796: }
797: if ($can_assign->{'loc'}) {
798: $argreset .= " vf.locarg.value='';\n";
799: $numbuttons ++;
800: }
801: if (!$can_assign->{'int'}) {
1.170 damieng 802: 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".
1.132 raeburn 803: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 804: &js_escape(\$warning);
1.132 raeburn 805: $auth_update = <<"END";
806: // Currently the initial password field is only supported for internal auth
807: // (see bug 6368).
808: if (nw==9) {
809: eval('vf.f'+tf+'.selectedIndex=0;')
810: alert('$warning');
811: }
812: END
813: } elsif ($numbuttons > 1) {
1.123 raeburn 814: $auth_update = <<"END";
815: // If we set the password, make the password form below correspond to
816: // the new value.
817: if (nw==9) {
818: changed_radio('int',document.studentform);
819: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 820: $argreset
821: }
822:
1.123 raeburn 823: END
824: }
825: }
826:
1.1 raeburn 827: return(<<ENDPICK);
828: function verify(vf,sec_caller) {
829: var founduname=0;
830: var foundpwd=0;
831: var foundname=0;
832: var foundid=0;
833: var foundsec=0;
834: var foundemail=0;
835: var foundrole=0;
1.57 raeburn 836: var founddomain=0;
1.84 raeburn 837: var foundinststatus=0;
1.150 raeburn 838: var foundcredits=0;
1.1 raeburn 839: var tw;
840: for (i=0;i<=vf.nfields.value;i++) {
841: tw=eval('vf.f'+i+'.selectedIndex');
842: if (tw==1) { founduname=1; }
843: if ((tw>=2) && (tw<=6)) { foundname=1; }
844: if (tw==7) { foundid=1; }
845: if (tw==8) { foundsec=1; }
846: if (tw==9) { foundpwd=1; }
847: if (tw==10) { foundemail=1; }
848: if (tw==11) { foundrole=1; }
1.57 raeburn 849: if (tw==12) { founddomain=1; }
1.84 raeburn 850: if (tw==13) { foundinststatus=1; }
1.150 raeburn 851: if (tw==14) { foundcredits=1; }
1.1 raeburn 852: }
1.150 raeburn 853: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 854: }
855:
856: //
857: // vf = this.form
858: // tf = column number
859: //
860: // values of nw
861: //
862: // 0 = none
863: // 1 = username
864: // 2 = names (lastname, firstnames)
865: // 3 = fname (firstname)
866: // 4 = mname (middlename)
867: // 5 = lname (lastname)
868: // 6 = gen (generation)
869: // 7 = id
870: // 8 = section
871: // 9 = ipwd (password)
872: // 10 = email address
873: // 11 = role
1.57 raeburn 874: // 12 = domain
1.84 raeburn 875: // 13 = inststatus
1.150 raeburn 876: // 14 = foundcredits
1.1 raeburn 877:
878: function flip(vf,tf) {
879: var nw=eval('vf.f'+tf+'.selectedIndex');
880: var i;
881: // make sure no other columns are labeled the same as this one
882: for (i=0;i<=vf.nfields.value;i++) {
883: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
884: eval('vf.f'+i+'.selectedIndex=0;')
885: }
886: }
887: // If we set this to 'lastname, firstnames', clear out all the ones
888: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
889: if (nw==2) {
890: for (i=0;i<=vf.nfields.value;i++) {
891: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
892: (eval('vf.f'+i+'.selectedIndex')<=6)) {
893: eval('vf.f'+i+'.selectedIndex=0;')
894: }
895: }
896: }
897: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
898: // clear out any that are set to 'lastname, firstnames' (2)
899: if ((nw>=3) && (nw<=6)) {
900: for (i=0;i<=vf.nfields.value;i++) {
901: if (eval('vf.f'+i+'.selectedIndex')==2) {
902: eval('vf.f'+i+'.selectedIndex=0;')
903: }
904: }
905: }
1.123 raeburn 906: $auth_update
1.1 raeburn 907: }
908:
909: function clearpwd(vf) {
910: var i;
911: for (i=0;i<=vf.nfields.value;i++) {
912: if (eval('vf.f'+i+'.selectedIndex')==9) {
913: eval('vf.f'+i+'.selectedIndex=0;')
914: }
915: }
916: }
917:
918: ENDPICK
919: }
920:
921: ###############################################################
922: ###############################################################
923: sub upload_manager_javascript_reverse_associate {
1.123 raeburn 924: my ($can_assign) = @_;
1.132 raeburn 925: my ($auth_update,$numbuttons,$argreset);
1.123 raeburn 926: if (ref($can_assign) eq 'HASH') {
1.132 raeburn 927: if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
928: $argreset .= " vf.krbarg.value='';\n";
929: $numbuttons ++ ;
930: }
931: if ($can_assign->{'int'}) {
932: $argreset .= " vf.intarg.value='';\n";
933: $numbuttons ++;
934: }
935: if ($can_assign->{'loc'}) {
936: $argreset .= " vf.locarg.value='';\n";
937: $numbuttons ++;
938: }
939: if (!$can_assign->{'int'}) {
940: my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
941: &mt('Your current role does not have rights to create users with that authentication type.');
1.170 damieng 942: &js_escape(\$warning);
1.132 raeburn 943: $auth_update = <<"END";
944: // Currently the initial password field is only supported for internal auth
945: // (see bug 6368).
946: if (tf==8 && nw!=0) {
947: eval('vf.f'+tf+'.selectedIndex=0;')
948: alert('$warning');
949: }
950: END
951: } elsif ($numbuttons > 1) {
1.123 raeburn 952: $auth_update = <<"END";
953: // initial password specified, pick internal authentication
954: if (tf==8 && nw!=0) {
955: changed_radio('int',document.studentform);
956: set_auth_radio_buttons('int',document.studentform);
1.132 raeburn 957: $argreset
958: }
959:
1.123 raeburn 960: END
961: }
962: }
1.132 raeburn 963:
1.1 raeburn 964: return(<<ENDPICK);
965: function verify(vf,sec_caller) {
966: var founduname=0;
967: var foundpwd=0;
968: var foundname=0;
969: var foundid=0;
970: var foundsec=0;
1.131 raeburn 971: var foundemail=0;
1.1 raeburn 972: var foundrole=0;
1.57 raeburn 973: var founddomain=0;
1.84 raeburn 974: var foundinststatus=0;
1.150 raeburn 975: var foundcredits=0;
1.1 raeburn 976: var tw;
977: for (i=0;i<=vf.nfields.value;i++) {
978: tw=eval('vf.f'+i+'.selectedIndex');
979: if (i==0 && tw!=0) { founduname=1; }
980: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
981: if (i==6 && tw!=0) { foundid=1; }
982: if (i==7 && tw!=0) { foundsec=1; }
983: if (i==8 && tw!=0) { foundpwd=1; }
1.130 raeburn 984: if (i==9 && tw!=0) { foundemail=1; }
985: if (i==10 && tw!=0) { foundrole=1; }
986: if (i==11 && tw!=0) { founddomain=1; }
987: if (i==12 && tw!=0) { foundinstatus=1; }
1.150 raeburn 988: if (i==13 && tw!=0) { foundcredits=1; }
1.1 raeburn 989: }
1.150 raeburn 990: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
1.1 raeburn 991: }
992:
993: function flip(vf,tf) {
994: var nw=eval('vf.f'+tf+'.selectedIndex');
995: var i;
996: // picked the all one name field, reset the other name ones to blank
997: if (tf==1 && nw!=0) {
998: for (i=2;i<=5;i++) {
999: eval('vf.f'+i+'.selectedIndex=0;')
1000: }
1001: }
1002: //picked one of the piecewise name fields, reset the all in
1003: //one field to blank
1004: if ((tf>=2) && (tf<=5) && (nw!=0)) {
1005: eval('vf.f1.selectedIndex=0;')
1006: }
1.123 raeburn 1007: $auth_update
1.1 raeburn 1008: }
1009:
1010: function clearpwd(vf) {
1011: var i;
1012: if (eval('vf.f8.selectedIndex')!=0) {
1013: eval('vf.f8.selectedIndex=0;')
1014: }
1015: }
1016: ENDPICK
1017: }
1018:
1019: ###############################################################
1020: ###############################################################
1021: sub print_upload_manager_footer {
1.150 raeburn 1022: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype,
1023: $showcredits) = @_;
1.22 raeburn 1024: my $form = 'document.studentform';
1025: my $formname = 'studentform';
1.1 raeburn 1026: my ($krbdef,$krbdefdom) =
1027: &Apache::loncommon::get_kerberos_defaults($defdom);
1.22 raeburn 1028: my %param = ( formname => $form,
1.1 raeburn 1029: kerb_def_dom => $krbdefdom,
1030: kerb_def_auth => $krbdef
1031: );
1032: if (exists($env{'form.ipwd_choice'}) &&
1033: defined($env{'form.ipwd_choice'}) &&
1034: $env{'form.ipwd_choice'} ne '') {
1035: $param{'curr_authtype'} = 'int';
1036: }
1037: my $krbform = &Apache::loncommon::authform_kerberos(%param);
1038: my $intform = &Apache::loncommon::authform_internal(%param);
1039: my $locform = &Apache::loncommon::authform_local(%param);
1.194 raeburn 1040: my $ltiform = &Apache::loncommon::authform_lti(%param);
1.22 raeburn 1041: my $date_table = &date_setting_table(undef,undef,$context,undef,
1.101 raeburn 1042: $formname,$permission,$crstype);
1.95 bisitz 1043:
1.1 raeburn 1044: my $Str = "\n".'<div class="LC_left_float">';
1045: $Str .= &hidden_input('nfields',$i);
1046: $Str .= &hidden_input('keyfields',$keyfields);
1.95 bisitz 1047:
1048: $Str .= '<h3>'.&mt('Options').'</h3>'
1049: .&Apache::lonhtmlcommon::start_pick_box();
1050:
1051: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type'));
1.1 raeburn 1052: if ($context eq 'domain') {
1.95 bisitz 1053: $Str .= '<p>'
1054: .&mt('Change authentication for existing users in domain "[_1]" to these settings?'
1055: ,$defdom)
1056: .' <span class="LC_nobreak"><label>'
1057: .'<input type="radio" name="changeauth" value="No" checked="checked" />'
1058: .&mt('No').'</label>'
1059: .' <label>'
1060: .'<input type="radio" name="changeauth" value="Yes" />'
1061: .&mt('Yes').'</label>'
1062: .'</span></p>';
1.1 raeburn 1063: } else {
1.95 bisitz 1064: $Str .= '<p class="LC_info">'."\n".
1065: &mt('This will not take effect if the user already exists.').
1.1 raeburn 1066: &Apache::loncommon::help_open_topic('Auth_Options').
1067: "</p>\n";
1068: }
1.194 raeburn 1069: $Str .= &set_login($defdom,$krbform,$intform,$locform,$ltiform);
1.95 bisitz 1070:
1.1 raeburn 1071: my ($home_server_pick,$numlib) =
1072: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
1073: 'default','hide');
1074: if ($numlib > 1) {
1.97 raeburn 1075: $Str .= &Apache::lonhtmlcommon::row_closure()
1076: .&Apache::lonhtmlcommon::row_title(
1.95 bisitz 1077: &mt('LON-CAPA Home Server for New Users'))
1078: .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
1079: .$home_server_pick
1080: .&Apache::lonhtmlcommon::row_closure();
1081: } else {
1.97 raeburn 1082: $Str .= $home_server_pick.
1083: &Apache::lonhtmlcommon::row_closure();
1.95 bisitz 1084: }
1085:
1.188 raeburn 1086: my ($trusted,$untrusted);
1.185 raeburn 1087: if ($context eq 'course') {
1.188 raeburn 1088: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.185 raeburn 1089: } elsif ($context eq 'author') {
1.188 raeburn 1090: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.185 raeburn 1091: }
1.95 bisitz 1092: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
1.188 raeburn 1093: .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trusted,$untrusted)
1.95 bisitz 1094: .&Apache::lonhtmlcommon::row_closure();
1095:
1096: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
1097: ."<p>\n".$date_table."</p>\n"
1098: .&Apache::lonhtmlcommon::row_closure();
1099:
1.1 raeburn 1100: if ($context eq 'domain') {
1.95 bisitz 1101: $Str .= &Apache::lonhtmlcommon::row_title(
1102: &mt('Settings for assigning roles'))
1103: .&mt('Pick the action to take on roles for these users:').'<br />'
1104: .'<span class="LC_nobreak"><label>'
1105: .'<input type="radio" name="roleaction" value="norole" checked="checked" />'
1106: .' '.&mt('No role changes').'</label>'
1107: .' <label>'
1108: .'<input type="radio" name="roleaction" value="domain" />'
1109: .' '.&mt('Add a domain role').'</label>'
1110: .' <label>'
1111: .'<input type="radio" name="roleaction" value="course" />'
1.103 raeburn 1112: .' '.&mt('Add a course/community role').'</label>'
1.95 bisitz 1113: .'</span>';
1114: } elsif ($context eq 'author') {
1115: $Str .= &Apache::lonhtmlcommon::row_title(
1116: &mt('Default role'))
1117: .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
1.1 raeburn 1118: } elsif ($context eq 'course') {
1.150 raeburn 1119: if ($showcredits) {
1120: $Str .= &Apache::lonhtmlcommon::row_title(
1121: &mt('Default role, section and credits'))
1122: .&mt('Choose the role and/or section(s) and/or credits to assign to users without values specified in the uploaded file.');
1123: } else {
1124: $Str .= &Apache::lonhtmlcommon::row_title(
1.95 bisitz 1125: &mt('Default role and section'))
1.150 raeburn 1126: .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
1127: }
1.95 bisitz 1128: } else {
1129: $Str .= &Apache::lonhtmlcommon::row_title(
1130: &mt('Default role and/or section(s)'))
1131: .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
1.1 raeburn 1132: }
1.22 raeburn 1133: if (($context eq 'domain') || ($context eq 'author')) {
1.95 bisitz 1134: $Str .= '<br />';
1.150 raeburn 1135: my ($options,$cb_script,$coursepick) =
1136: &default_role_selector($context,1,'',$showcredits);
1.22 raeburn 1137: if ($context eq 'domain') {
1.95 bisitz 1138: $Str .= '<p>'
1139: .'<b>'.&mt('Domain Level').'</b><br />'
1140: .$options
1141: .'</p><p>'
1142: .'<b>'.&mt('Course Level').'</b>'
1143: .'</p>'
1144: .$cb_script.$coursepick
1145: .&Apache::lonhtmlcommon::row_closure();
1.22 raeburn 1146: } elsif ($context eq 'author') {
1.95 bisitz 1147: $Str .= $options
1148: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.22 raeburn 1149: }
1.1 raeburn 1150: } else {
1.22 raeburn 1151: my ($cnum,$cdom) = &get_course_identity();
1152: my $rowtitle = &mt('section');
1.150 raeburn 1153: my $defaultcredits;
1154: if ($showcredits) {
1155: $defaultcredits = &get_defaultcredits();
1156: }
1157: my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,$permission,
1158: $context,'upload',$crstype,$showcredits,
1159: $defaultcredits);
1.95 bisitz 1160: $Str .= $secbox
1161: .&Apache::lonhtmlcommon::row_closure();
1.101 raeburn 1162: my %lt;
1163: if ($crstype eq 'Community') {
1164: %lt = &Apache::lonlocal::texthash (
1165: disp => 'Display members with current/future access who are not in the uploaded file',
1166: stus => 'Members selected from this list can be dropped.'
1167: );
1168: } else {
1169: %lt = &Apache::lonlocal::texthash (
1170: disp => 'Display students with current/future access who are not in the uploaded file',
1171: stus => 'Students selected from this list can be dropped.'
1172: );
1173: }
1.95 bisitz 1174: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
1.101 raeburn 1175: .'<label><input type="checkbox" name="fullup" value="yes" />'
1176: .' '.$lt{'disp'}
1.95 bisitz 1177: .'</label><br />'
1.101 raeburn 1178: .$lt{'stus'}
1.95 bisitz 1179: .&Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1180: }
1.5 raeburn 1181: if ($context eq 'course' || $context eq 'domain') {
1.161 bisitz 1182: $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
1183: .&forceid_change($context)
1184: .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.5 raeburn 1185: }
1.95 bisitz 1186:
1187: $Str .= &Apache::lonhtmlcommon::end_pick_box();
1.73 bisitz 1188: $Str .= '</div>';
1.95 bisitz 1189:
1190: # Footer
1191: $Str .= '<div class="LC_clear_float_footer">'
1192: .'<hr />';
1.1 raeburn 1193: if ($context eq 'course') {
1.95 bisitz 1194: $Str .= '<p class="LC_info">'
1.103 raeburn 1195: .&mt('Note: This operation may be time consuming when adding several users.')
1.95 bisitz 1196: .'</p>';
1.73 bisitz 1197: }
1.95 bisitz 1198: $Str .= '<p><input type="button"'
1.96 bisitz 1199: .' onclick="javascript:verify(this.form,this.form.csec)"'
1200: .' value="'.&mt('Update Users').'" />'
1.95 bisitz 1201: .'</p>'."\n"
1.73 bisitz 1202: .'</div>';
1.1 raeburn 1203: $r->print($Str);
1204: return;
1205: }
1206:
1.150 raeburn 1207: sub get_defaultcredits {
1208: my ($cdom,$cnum) = @_;
1209:
1210: if ($cdom eq '' || $cnum eq '') {
1211: return unless ($env{'request.course.id'});
1212: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1213: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1214: }
1215: return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));
1216: my ($defaultcredits,$domdefcredits);
1217: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
1.160 raeburn 1218: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.150 raeburn 1219: my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
1220: if ($instcode) {
1221: $domdefcredits = $domdefaults{'officialcredits'};
1.160 raeburn 1222: } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) {
1223: $domdefcredits = $domdefaults{'textbookcredits'};
1.150 raeburn 1224: } else {
1225: $domdefcredits = $domdefaults{'unofficialcredits'};
1226: }
1227: } else {
1228: return;
1229: }
1230:
1231: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
1232: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1233: } elsif (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'})) {
1234: $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
1235: } else {
1236: my %crsinfo =
1237: &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
1238: $defaultcredits = $crsinfo{'internal.defaultcredits'};
1239: }
1240: if ($defaultcredits eq '') {
1241: $defaultcredits = $domdefcredits;
1242: }
1243: return $defaultcredits;
1244: }
1245:
1.5 raeburn 1246: sub forceid_change {
1247: my ($context) = @_;
1248: my $output =
1.161 bisitz 1249: '<label><input type="checkbox" name="forceid" value="yes" />'
1.164 bisitz 1250: .&mt('Force change of existing ID')
1.163 raeburn 1251: .'</label>'.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
1.5 raeburn 1252: if ($context eq 'domain') {
1.163 raeburn 1253: $output .=
1254: '<br />'
1255: .'<label><input type="checkbox" name="recurseid" value="yes" />'
1256: .&mt("Update ID in user's course(s).").'</label>'."\n";
1.5 raeburn 1257: }
1258: return $output;
1259: }
1260:
1.1 raeburn 1261: ###############################################################
1262: ###############################################################
1263: sub print_upload_manager_form {
1.150 raeburn 1264: my ($r,$context,$permission,$crstype,$showcredits) = @_;
1.1 raeburn 1265: my $firstLine;
1266: my $datatoken;
1267: if (!$env{'form.datatoken'}) {
1268: $datatoken=&Apache::loncommon::upfile_store($r);
1269: } else {
1.189 raeburn 1270: $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
1271: if ($datatoken ne '') {
1272: &Apache::loncommon::load_tmp_file($r,$datatoken);
1273: }
1.1 raeburn 1274: }
1.193 raeburn 1275: if ($datatoken eq '') {
1276: $r->print('<p class="LC_error">'.&mt('Error').': '.
1277: &mt('Invalid datatoken').'</p>');
1278: return 'missingdata';
1279: }
1.1 raeburn 1280: my @records=&Apache::loncommon::upfile_record_sep();
1281: if($env{'form.noFirstLine'}){
1282: $firstLine=shift(@records);
1283: }
1284: my $total=$#records;
1285: my $distotal=$total+1;
1286: my $today=time;
1287: my $halfyear=$today+15552000;
1288: #
1289: # Restore memorized settings
1290: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
1291: 'names_choice' => 'scalar',
1292: 'fname_choice' => 'scalar',
1293: 'mname_choice' => 'scalar',
1294: 'lname_choice' => 'scalar',
1295: 'gen_choice' => 'scalar',
1296: 'id_choice' => 'scalar',
1297: 'sec_choice' => 'scalar',
1298: 'ipwd_choice' => 'scalar',
1299: 'email_choice' => 'scalar',
1300: 'role_choice' => 'scalar',
1.57 raeburn 1301: 'domain_choice' => 'scalar',
1.84 raeburn 1302: 'inststatus_choice' => 'scalar',
1.1 raeburn 1303: };
1.150 raeburn 1304: if ($showcredits) {
1305: $col_setting_names->{'credits_choice'} = 'scalar';
1306: }
1.1 raeburn 1307: if ($context eq 'course') {
1308: &Apache::loncommon::restore_course_settings('enrollment_upload',
1309: $col_setting_names);
1310: } else {
1311: &Apache::loncommon::restore_settings($context,'user_upload',
1312: $col_setting_names);
1313: }
1.150 raeburn 1314: my $defdom = $env{'request.role.domain'};
1.1 raeburn 1315: #
1316: # Determine kerberos parameters as appropriate
1317: my ($krbdef,$krbdefdom) =
1318: &Apache::loncommon::get_kerberos_defaults($defdom);
1319: #
1.123 raeburn 1320: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
1.22 raeburn 1321: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
1.123 raeburn 1322: $permission,$crstype,\%can_assign);
1.1 raeburn 1323: my $i;
1324: my $keyfields;
1325: if ($total>=0) {
1326: my @field=
1327: (['username',&mt('Username'), $env{'form.username_choice'}],
1328: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
1329: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
1330: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
1331: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
1332: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
1.61 bisitz 1333: ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
1.1 raeburn 1334: ['sec', &mt('Section'), $env{'form.sec_choice'}],
1335: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
1336: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
1.57 raeburn 1337: ['role',&mt('Role'), $env{'form.role_choice'}],
1.84 raeburn 1338: ['domain',&mt('Domain'), $env{'form.domain_choice'}],
1339: ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
1.150 raeburn 1340: if ($showcredits) {
1341: push(@field,
1342: ['credits',&mt('Student Credits'), $env{'form.credits_choice'}]);
1343: }
1.1 raeburn 1344: if ($env{'form.upfile_associate'} eq 'reverse') {
1345: &Apache::loncommon::csv_print_samples($r,\@records);
1346: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
1347: \@field);
1348: foreach (@field) {
1349: $keyfields.=$_->[0].',';
1350: }
1351: chop($keyfields);
1352: } else {
1353: unshift(@field,['none','']);
1354: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
1355: \@field);
1356: my %sone=&Apache::loncommon::record_sep($records[0]);
1357: $keyfields=join(',',sort(keys(%sone)));
1358: }
1359: }
1360: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
1.150 raeburn 1361: $context,$permission,$crstype,$showcredits);
1.193 raeburn 1362: return 'ok';
1.1 raeburn 1363: }
1364:
1365: sub setup_date_selectors {
1.22 raeburn 1366: my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
1367: if ($formname eq '') {
1368: $formname = 'studentform';
1369: }
1.1 raeburn 1370: if (! defined($starttime)) {
1371: $starttime = time;
1372: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1373: if (exists($env{'course.'.$env{'request.course.id'}.
1374: '.default_enrollment_start_date'})) {
1375: $starttime = $env{'course.'.$env{'request.course.id'}.
1376: '.default_enrollment_start_date'};
1377: }
1378: }
1379: }
1380: if (! defined($endtime)) {
1381: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1382: unless ($mode eq 'createcourse') {
1383: if (exists($env{'course.'.$env{'request.course.id'}.
1384: '.default_enrollment_end_date'})) {
1385: $endtime = $env{'course.'.$env{'request.course.id'}.
1386: '.default_enrollment_end_date'};
1387: }
1388: }
1389: }
1.11 raeburn 1390:
1391: my $startdateform =
1.22 raeburn 1392: &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
1.11 raeburn 1393: undef,undef,undef,undef,undef,undef,undef,$nolink);
1394:
1395: my $enddateform =
1.22 raeburn 1396: &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
1.11 raeburn 1397: undef,undef,undef,undef,undef,undef,undef,$nolink);
1398:
1.1 raeburn 1399: if ($mode eq 'create_enrolldates') {
1400: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1401: 'startenroll',
1402: $starttime);
1403: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1404: 'endenroll',
1405: $endtime);
1406: }
1407: if ($mode eq 'create_defaultdates') {
1408: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1409: 'startaccess',
1410: $starttime);
1411: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
1412: 'endaccess',
1413: $endtime);
1414: }
1415: return ($startdateform,$enddateform);
1416: }
1417:
1418:
1419: sub get_dates_from_form {
1.54 raeburn 1420: my ($startname,$endname) = @_;
1421: if ($startname eq '') {
1422: $startname = 'startdate';
1423: }
1424: if ($endname eq '') {
1425: $endname = 'enddate';
1426: }
1427: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1428: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.1 raeburn 1429: if ($env{'form.no_end_date'}) {
1430: $enddate = 0;
1431: }
1432: return ($startdate,$enddate);
1433: }
1434:
1435: sub date_setting_table {
1.101 raeburn 1436: my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
1.11 raeburn 1437: my $nolink;
1438: if ($bulkaction) {
1439: $nolink = 1;
1440: }
1441: my ($startform,$endform) =
1.22 raeburn 1442: &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
1.1 raeburn 1443: my $dateDefault;
1444: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
1445: $dateDefault = ' ';
1.13 raeburn 1446: } elsif ($mode ne 'author' && $mode ne 'domain') {
1.11 raeburn 1447: if (($bulkaction eq 'reenable') ||
1448: ($bulkaction eq 'activate') ||
1.22 raeburn 1449: ($bulkaction eq 'chgdates') ||
1450: ($env{'form.action'} eq 'upload')) {
1451: if ($env{'request.course.sec'} eq '') {
1452: $dateDefault = '<span class="LC_nobreak">'.
1.101 raeburn 1453: '<label><input type="checkbox" name="makedatesdefault" value="1" /> ';
1454: if ($crstype eq 'Community') {
1455: $dateDefault .= &mt("make these dates the default access dates for future community enrollment");
1456: } else {
1457: $dateDefault .= &mt("make these dates the default access dates for future course enrollment");
1458: }
1459: $dateDefault .= '</label></span>';
1.22 raeburn 1460: }
1.11 raeburn 1461: }
1.1 raeburn 1462: }
1.11 raeburn 1463: my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1.1 raeburn 1464: if (defined($endtime) && $endtime == 0) {
1.70 bisitz 1465: $perpetual .= ' checked="checked"';
1.1 raeburn 1466: }
1.11 raeburn 1467: $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
1.1 raeburn 1468: if ($mode eq 'create_enrolldates') {
1469: $perpetual = ' ';
1470: }
1.11 raeburn 1471: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
1472: $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
1473: 'LC_oddrow_value')."\n".
1474: $startform."\n".
1475: &Apache::lonhtmlcommon::row_closure(1).
1476: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
1477: 'LC_oddrow_value')."\n".
1478: $endform.' '.$perpetual.
1479: &Apache::lonhtmlcommon::row_closure(1).
1.22 raeburn 1480: &Apache::lonhtmlcommon::end_pick_box();
1.1 raeburn 1481: if ($dateDefault) {
1482: $result .= $dateDefault.'<br />'."\n";
1483: }
1484: return $result;
1485: }
1486:
1487: sub make_dates_default {
1.101 raeburn 1488: my ($startdate,$enddate,$context,$crstype) = @_;
1.1 raeburn 1489: my $result = '';
1490: if ($context eq 'course') {
1.17 raeburn 1491: my ($cnum,$cdom) = &get_course_identity();
1.1 raeburn 1492: my $put_result = &Apache::lonnet::put('environment',
1493: {'default_enrollment_start_date'=>$startdate,
1.17 raeburn 1494: 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
1.1 raeburn 1495: if ($put_result eq 'ok') {
1.101 raeburn 1496: if ($crstype eq 'Community') {
1497: $result .= &mt('Set default start and end access dates for community.');
1498: } else {
1499: $result .= &mt('Set default start and end access dates for course.');
1500: }
1501: $result .= '<br />'."\n";
1.1 raeburn 1502: #
1503: # Refresh the course environment
1504: &Apache::lonnet::coursedescription($env{'request.course.id'},
1505: {'freshen_cache' => 1});
1506: } else {
1.101 raeburn 1507: if ($crstype eq 'Community') {
1508: $result .= &mt('Unable to set default access dates for community');
1509: } else {
1510: $result .= &mt('Unable to set default access dates for course');
1511: }
1512: $result .= ':'.$put_result.'<br />';
1.1 raeburn 1513: }
1514: }
1515: return $result;
1516: }
1517:
1518: sub default_role_selector {
1.150 raeburn 1519: my ($context,$checkpriv,$crstype,$showcredits) = @_;
1.1 raeburn 1520: my %customroles;
1521: my ($options,$coursepick,$cb_jscript);
1.13 raeburn 1522: if ($context ne 'author') {
1.104 raeburn 1523: %customroles = &my_custom_roles($crstype);
1.1 raeburn 1524: }
1525:
1526: my %lt=&Apache::lonlocal::texthash(
1527: 'rol' => "Role",
1528: 'grs' => "Section",
1529: 'exs' => "Existing sections",
1530: 'new' => "New section",
1.150 raeburn 1531: 'crd' => "Credits",
1.1 raeburn 1532: );
1533: $options = '<select name="defaultrole">'."\n".
1534: ' <option value="">'.&mt('Please select').'</option>'."\n";
1535: if ($context eq 'course') {
1.101 raeburn 1536: $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
1.13 raeburn 1537: } elsif ($context eq 'author') {
1.2 raeburn 1538: my @roles = &construction_space_roles($checkpriv);
1.1 raeburn 1539: foreach my $role (@roles) {
1540: my $plrole=&Apache::lonnet::plaintext($role);
1541: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1542: }
1543: } elsif ($context eq 'domain') {
1.2 raeburn 1544: my @roles = &domain_roles($checkpriv);
1.1 raeburn 1545: foreach my $role (@roles) {
1546: my $plrole=&Apache::lonnet::plaintext($role);
1547: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
1548: }
1549: my $courseform = &Apache::loncommon::selectcourse_link
1.103 raeburn 1550: ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
1.150 raeburn 1551: my ($credit_elem,$creditsinput);
1552: if ($showcredits) {
1553: $credit_elem = 'credits';
1554: $creditsinput = '<td><input type="text" name="credits" value="" /></td>';
1555: }
1.1 raeburn 1556: $cb_jscript =
1.150 raeburn 1557: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community',$credit_elem);
1.1 raeburn 1558: $coursepick = &Apache::loncommon::start_data_table().
1559: &Apache::loncommon::start_data_table_header_row().
1560: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
1561: '<th>'.$lt{'grs'}.'</th>'.
1.150 raeburn 1562: '<th>'.$lt{'crd'}.'</th>'.
1.1 raeburn 1563: &Apache::loncommon::end_data_table_header_row().
1564: &Apache::loncommon::start_data_table_row()."\n".
1.103 raeburn 1565: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
1.1 raeburn 1566: '<td><select name="courserole">'."\n".
1.101 raeburn 1567: &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
1.1 raeburn 1568: '</select></td><td>'.
1569: '<table class="LC_createuser">'.
1.162 bisitz 1570: '<tr class="LC_section_row"><td valign="top">'.
1.22 raeburn 1571: $lt{'exs'}.'<br /><select name="currsec">'.
1.162 bisitz 1572: ' <option value=""><--'.&mt('Pick course first').
1.1 raeburn 1573: '</select></td>'.
1574: '<td> </td>'.
1575: '<td valign="top">'.$lt{'new'}.'<br />'.
1576: '<input type="text" name="newsec" value="" size="5" />'.
1.22 raeburn 1577: '<input type="hidden" name="groups" value="" />'.
1578: '<input type="hidden" name="sections" value="" />'.
1579: '<input type="hidden" name="origdom" value="'.
1580: $env{'request.role.domain'}.'" />'.
1581: '<input type="hidden" name="dccourse" value="" />'.
1582: '<input type="hidden" name="dcdomain" value="" />'.
1.103 raeburn 1583: '<input type="hidden" name="crstype" value="" />'.
1.150 raeburn 1584: '</td></tr></table></td>'.$creditsinput.
1.1 raeburn 1585: &Apache::loncommon::end_data_table_row().
1.22 raeburn 1586: &Apache::loncommon::end_data_table()."\n";
1.1 raeburn 1587: }
1588: $options .= '</select>';
1589: return ($options,$cb_jscript,$coursepick);
1590: }
1591:
1592: sub default_course_roles {
1.101 raeburn 1593: my ($context,$checkpriv,$crstype,%customroles) = @_;
1.1 raeburn 1594: my $output;
1.17 raeburn 1595: my $custom = 1;
1.101 raeburn 1596: my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype));
1.1 raeburn 1597: foreach my $role (@roles) {
1.22 raeburn 1598: if ($role ne 'cr') {
1.101 raeburn 1599: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.22 raeburn 1600: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
1601: }
1.1 raeburn 1602: }
1603: if (keys(%customroles) > 0) {
1.22 raeburn 1604: if (grep(/^cr$/,@roles)) {
1605: foreach my $cust (sort(keys(%customroles))) {
1606: my $custrole='cr_'.$env{'user.domain'}.
1607: '_'.$env{'user.name'}.'_'.$cust;
1608: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1609: }
1.1 raeburn 1610: }
1611: }
1612: return $output;
1613: }
1614:
1615: sub construction_space_roles {
1.2 raeburn 1616: my ($checkpriv) = @_;
1.17 raeburn 1617: my @allroles = &roles_by_context('author');
1.1 raeburn 1618: my @roles;
1.2 raeburn 1619: if ($checkpriv) {
1620: foreach my $role (@allroles) {
1621: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
1622: push(@roles,$role);
1623: }
1.1 raeburn 1624: }
1.2 raeburn 1625: return @roles;
1626: } else {
1627: return @allroles;
1.1 raeburn 1628: }
1629: }
1630:
1631: sub domain_roles {
1.2 raeburn 1632: my ($checkpriv) = @_;
1.17 raeburn 1633: my @allroles = &roles_by_context('domain');
1.1 raeburn 1634: my @roles;
1.2 raeburn 1635: if ($checkpriv) {
1636: foreach my $role (@allroles) {
1637: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
1638: push(@roles,$role);
1639: }
1.1 raeburn 1640: }
1.2 raeburn 1641: return @roles;
1642: } else {
1643: return @allroles;
1.1 raeburn 1644: }
1645: }
1646:
1647: sub course_roles {
1.101 raeburn 1648: my ($context,$checkpriv,$custom,$roletype) = @_;
1.102 raeburn 1649: my $crstype;
1650: if ($roletype eq 'community') {
1651: $crstype = 'Community' ;
1652: } else {
1653: $crstype = 'Course';
1654: }
1655: my @allroles = &roles_by_context('course',$custom,$crstype);
1.1 raeburn 1656: my @roles;
1657: if ($context eq 'domain') {
1658: @roles = @allroles;
1659: } elsif ($context eq 'course') {
1660: if ($env{'request.course.id'}) {
1.2 raeburn 1661: if ($checkpriv) {
1662: foreach my $role (@allroles) {
1663: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
1664: push(@roles,$role);
1665: } else {
1.101 raeburn 1666: if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) {
1.22 raeburn 1667: if (&Apache::lonnet::allowed('c'.$role,
1.2 raeburn 1668: $env{'request.course.id'}.'/'.
1.22 raeburn 1669: $env{'request.course.sec'})) {
1.2 raeburn 1670: push(@roles,$role);
1671: }
1.1 raeburn 1672: }
1673: }
1674: }
1.2 raeburn 1675: } else {
1676: @roles = @allroles;
1.1 raeburn 1677: }
1678: }
1679: }
1680: return @roles;
1681: }
1682:
1683: sub curr_role_permissions {
1.101 raeburn 1684: my ($context,$setting,$checkpriv,$type) = @_;
1.17 raeburn 1685: my $custom = 1;
1.1 raeburn 1686: my @roles;
1.13 raeburn 1687: if ($context eq 'author') {
1.2 raeburn 1688: @roles = &construction_space_roles($checkpriv);
1.1 raeburn 1689: } elsif ($context eq 'domain') {
1690: if ($setting eq 'course') {
1.101 raeburn 1691: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 1692: } else {
1.2 raeburn 1693: @roles = &domain_roles($checkpriv);
1.1 raeburn 1694: }
1695: } elsif ($context eq 'course') {
1.101 raeburn 1696: @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1 raeburn 1697: }
1698: return @roles;
1699: }
1700:
1701: # ======================================================= Existing Custom Roles
1702:
1703: sub my_custom_roles {
1.175 raeburn 1704: my ($crstype,$udom,$uname) = @_;
1.1 raeburn 1705: my %returnhash=();
1.137 raeburn 1706: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
1.175 raeburn 1707: my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
1.104 raeburn 1708: foreach my $key (keys(%rolehash)) {
1.1 raeburn 1709: if ($key=~/^rolesdef\_(\w+)$/) {
1.104 raeburn 1710: if ($crstype eq 'Community') {
1711: next if ($rolehash{$key} =~ /bre\&S/);
1712: }
1.1 raeburn 1713: $returnhash{$1}=$1;
1714: }
1715: }
1716: return %returnhash;
1717: }
1718:
1.2 raeburn 1719: sub print_userlist {
1720: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1.150 raeburn 1721: $idlist,$idlist_titles,$showcredits) = @_;
1.2 raeburn 1722: my $format = $env{'form.output'};
1.1 raeburn 1723: if (! exists($env{'form.sortby'})) {
1724: $env{'form.sortby'} = 'username';
1725: }
1.2 raeburn 1726: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
1727: $env{'form.Status'} = 'Active';
1.1 raeburn 1728: }
1.140 raeburn 1729: my $onchange = "javascript:updateCols('Status');";
1.1 raeburn 1730: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1.140 raeburn 1731: ($env{'form.Status'},undef,undef,$onchange);
1.1 raeburn 1732:
1.2 raeburn 1733: if ($env{'form.showrole'} eq '') {
1.13 raeburn 1734: if ($context eq 'course') {
1735: $env{'form.showrole'} = 'st';
1736: } else {
1737: $env{'form.showrole'} = 'Any';
1738: }
1.2 raeburn 1739: }
1.1 raeburn 1740: if (! defined($env{'form.output'}) ||
1741: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
1742: $env{'form.output'} = 'html';
1743: }
1744:
1.2 raeburn 1745: my @statuses;
1746: if ($env{'form.Status'} eq 'Any') {
1747: @statuses = ('previous','active','future');
1748: } elsif ($env{'form.Status'} eq 'Expired') {
1749: @statuses = ('previous');
1750: } elsif ($env{'form.Status'} eq 'Active') {
1751: @statuses = ('active');
1752: } elsif ($env{'form.Status'} eq 'Future') {
1753: @statuses = ('future');
1754: }
1.1 raeburn 1755:
1756: # Interface output
1.2 raeburn 1757: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
1758: '<input type="hidden" name="action" value="'.
1.1 raeburn 1759: $env{'form.action'}.'" />');
1.140 raeburn 1760: $r->print('<div>'."\n");
1.1 raeburn 1761: if ($env{'form.action'} ne 'modifystudent') {
1762: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
1763: 'excel' => "Excel",
1764: 'html' => 'HTML');
1.140 raeburn 1765: my $output_selector = '<select size="1" name="output" onchange="javascript:updateCols('."'output'".');" >';
1.1 raeburn 1766: foreach my $outputformat ('html','csv','excel') {
1.96 bisitz 1767: my $option = '<option value="'.$outputformat.'"';
1.1 raeburn 1768: if ($outputformat eq $env{'form.output'}) {
1.96 bisitz 1769: $option .= ' selected="selected"';
1.1 raeburn 1770: }
1771: $option .='>'.$lt{$outputformat}.'</option>';
1772: $output_selector .= "\n".$option;
1773: }
1774: $output_selector .= '</select>';
1.140 raeburn 1775: $r->print('<span class="LC_nobreak">'
1.70 bisitz 1776: .&mt('Output Format: [_1]',$output_selector)
1.140 raeburn 1777: .'</span>'.(' 'x3));
1.70 bisitz 1778: }
1.140 raeburn 1779: $r->print('<span class="LC_nobreak">'
1.70 bisitz 1780: .&mt('User Status: [_1]',$status_select)
1.140 raeburn 1781: .'</span>'.(' 'x3)."\n");
1.2 raeburn 1782: my $roleselected = '';
1783: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 1784: $roleselected = ' selected="selected"';
1.2 raeburn 1785: }
1.53 raeburn 1786: my ($cnum,$cdom);
1787: $r->print(&role_filter($context));
1788: if ($context eq 'course') {
1789: ($cnum,$cdom) = &get_course_identity();
1790: $r->print(§ion_group_filter($cnum,$cdom));
1.2 raeburn 1791: }
1.140 raeburn 1792: $r->print('</div><div class="LC_left_float">'.
1.150 raeburn 1793: &column_checkboxes($context,$mode,$formname,$showcredits).
1.149 raeburn 1794: '</div>');
1.78 raeburn 1795: if ($env{'form.phase'} eq '') {
1.149 raeburn 1796: $r->print('<br clear="all" />'.
1797: &list_submit_button(&mt('Display List of Users'))."\n".
1.78 raeburn 1798: '<input type="hidden" name="phase" value="" /></form>');
1799: return;
1800: }
1.106 raeburn 1801: if (!(($context eq 'domain') &&
1802: (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
1.149 raeburn 1803: $r->print('<br clear="all" />'.
1804: &list_submit_button(&mt('Update Display'))."\n");
1.140 raeburn 1805: }
1806:
1.150 raeburn 1807: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 1808: if (!@cols) {
1.152 bisitz 1809: $r->print('<hr style="clear:both;" /><span class="LC_warning">'.
1.140 raeburn 1810: &mt('No user information selected for display.').'</span>'.
1811: '<input type="hidden" name="phase" value="display" /></form>'."\n");
1812: return;
1.2 raeburn 1813: }
1814: my ($indexhash,$keylist) = &make_keylist_array();
1.159 raeburn 1815: my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
1.102 raeburn 1816: if (($context eq 'domain') &&
1817: ($env{'form.roletype'} eq 'course') ||
1818: ($env{'form.roletype'} eq 'community')) {
1819: my ($crstype,$numcodes,$title,$warning);
1820: if ($env{'form.roletype'} eq 'course') {
1821: $crstype = 'Course';
1822: $numcodes = $totcodes;
1823: $title = &mt('Select Courses');
1824: $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
1825: } elsif ($env{'form.roletype'} eq 'community') {
1826: $crstype = 'Community';
1827: $numcodes = 0;
1828: $title = &mt('Select Communities');
1829: $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
1830: }
1.120 raeburn 1831: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.3 raeburn 1832: my $courseform =
1.102 raeburn 1833: &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
1.120 raeburn 1834: $codetitles,$idlist,$idlist_titles,$crstype,
1835: \@standardnames);
1.148 bisitz 1836: $r->print('<div class="LC_left_float">'.
1837: '<fieldset><legend>'.$title.'</legend>'."\n".
1.3 raeburn 1838: $courseform."\n".
1.148 bisitz 1839: '</fieldset></div><br clear="all" />'.
1.106 raeburn 1840: '<p><input type="hidden" name="origroletype" value="'.$env{'form.roletype'}.'" />'.
1841: &list_submit_button(&mt('Update Display')).
1.102 raeburn 1842: "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
1.106 raeburn 1843: $clearcoursepick = 0;
1844: if (($env{'form.origroletype'} ne '') &&
1845: ($env{'form.origroletype'} ne $env{'form.roletype'})) {
1846: $clearcoursepick = 1;
1847: }
1848: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.147 bisitz 1849: $r->print('<hr />'.&mt('Searching ...').'<br /> <br />');
1.11 raeburn 1850: }
1851: } else {
1.152 bisitz 1852: $r->print('<hr style="clear:both;" /><div id="searching">'.&mt('Searching ...').'</div>');
1.3 raeburn 1853: }
1854: $r->rflush();
1.1 raeburn 1855: if ($context eq 'course') {
1.46 raeburn 1856: if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
1.45 raeburn 1857: my $classlist = &Apache::loncoursedata::get_classlist();
1.66 raeburn 1858: if (ref($classlist) eq 'HASH') {
1859: %userlist = %{$classlist};
1860: }
1.45 raeburn 1861: }
1.43 raeburn 1862: if ($env{'form.showrole'} ne 'st') {
1863: my $showroles;
1864: if ($env{'form.showrole'} ne 'Any') {
1865: $showroles = [$env{'form.showrole'}];
1.3 raeburn 1866: } else {
1.43 raeburn 1867: $showroles = undef;
1.1 raeburn 1868: }
1.43 raeburn 1869: my $withsec = 1;
1870: my $hidepriv = 1;
1871: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
1872: \@statuses,$showroles,undef,$withsec,$hidepriv);
1873: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1874: \%advrolehash,$permission);
1.1 raeburn 1875: }
1.2 raeburn 1876: } else {
1877: my (%cstr_roles,%dom_roles);
1.13 raeburn 1878: if ($context eq 'author') {
1.2 raeburn 1879: # List co-authors and assistant co-authors
1.17 raeburn 1880: my @possroles = &roles_by_context($context);
1.2 raeburn 1881: %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
1882: \@statuses,\@possroles);
1883: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1.11 raeburn 1884: \%cstr_roles,$permission);
1.2 raeburn 1885: } elsif ($context eq 'domain') {
1886: if ($env{'form.roletype'} eq 'domain') {
1.159 raeburn 1887: if (grep(/^authorusage$/,@cols)) {
1888: $needauthorusage = 1;
1889: }
1890: if (grep(/^authorquota$/,@cols)) {
1891: $needauthorquota = 1;
1892: }
1.2 raeburn 1893: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
1894: foreach my $key (keys(%dom_roles)) {
1895: if (ref($dom_roles{$key}) eq 'HASH') {
1896: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 1897: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 1898: }
1899: }
1.13 raeburn 1900: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 1901: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
1902: my %coauthors;
1903: foreach my $key (keys(%dom_roles)) {
1904: if (ref($dom_roles{$key}) eq 'HASH') {
1905: if ($env{'form.showrole'} eq 'au') {
1906: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 1907: \%userinfo,$dom_roles{$key},$permission);
1.2 raeburn 1908: } else {
1909: my @possroles;
1910: if ($env{'form.showrole'} eq 'Any') {
1.22 raeburn 1911: @possroles = &roles_by_context('author');
1.2 raeburn 1912: } else {
1913: @possroles = ($env{'form.showrole'});
1914: }
1915: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1.22 raeburn 1916: my ($role,$authorname,$authordom) = split(/:/,$author,-1);
1.2 raeburn 1917: my $extent = '/'.$authordom.'/'.$authorname;
1918: %{$coauthors{$extent}} =
1919: &Apache::lonnet::get_my_roles($authorname,
1920: $authordom,undef,\@statuses,\@possroles);
1921: }
1922: &gather_userinfo($context,$format,\%userlist,
1.11 raeburn 1923: $indexhash,\%userinfo,\%coauthors,$permission);
1.2 raeburn 1924: }
1925: }
1926: }
1.101 raeburn 1927: } elsif (($env{'form.roletype'} eq 'course') ||
1928: ($env{'form.roletype'} eq 'community')) {
1.106 raeburn 1929: if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.2 raeburn 1930: my %courses = &process_coursepick();
1.39 raeburn 1931: my %allusers;
1932: my $hidepriv = 1;
1.2 raeburn 1933: foreach my $cid (keys(%courses)) {
1.17 raeburn 1934: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
1.11 raeburn 1935: next if ($cnum eq '' || $cdom eq '');
1.17 raeburn 1936: my $custom = 1;
1.2 raeburn 1937: my (@roles,@sections,%access,%users,%userdata,
1.6 albertel 1938: %statushash);
1.2 raeburn 1939: if ($env{'form.showrole'} eq 'Any') {
1.101 raeburn 1940: @roles = &course_roles($context,undef,$custom,
1941: $env{'form.roletype'});
1.2 raeburn 1942: } else {
1943: @roles = ($env{'form.showrole'});
1944: }
1945: foreach my $role (@roles) {
1946: %{$users{$role}} = ();
1947: }
1948: foreach my $type (@statuses) {
1949: $access{$type} = $type;
1950: }
1.39 raeburn 1951: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
1.2 raeburn 1952: foreach my $user (keys(%userdata)) {
1953: next if (ref($userinfo{$user}) eq 'HASH');
1954: foreach my $item ('fullname','id') {
1955: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
1956: }
1957: }
1958: foreach my $role (keys(%users)) {
1959: foreach my $user (keys(%{$users{$role}})) {
1960: my $uniqid = $user.':'.$role;
1961: $allusers{$uniqid}{$cid} = { desc => $cdesc,
1962: secs => $statushash{$user}{$role},
1963: };
1964: }
1965: }
1966: }
1967: &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11 raeburn 1968: \%userinfo,\%allusers,$permission);
1.2 raeburn 1969: } else {
1.10 raeburn 1970: $r->print('<input type="hidden" name="phase" value="'.
1971: $env{'form.phase'}.'" /></form>');
1.2 raeburn 1972: return;
1973: }
1.1 raeburn 1974: }
1975: }
1.3 raeburn 1976: }
1977: if (keys(%userlist) == 0) {
1.142 bisitz 1978: my $msg = '';
1.13 raeburn 1979: if ($context eq 'author') {
1.142 bisitz 1980: $msg = &mt('There are no co-authors to display.');
1.3 raeburn 1981: } elsif ($context eq 'domain') {
1982: if ($env{'form.roletype'} eq 'domain') {
1.142 bisitz 1983: $msg = &mt('There are no users with domain roles to display.');
1.13 raeburn 1984: } elsif ($env{'form.roletype'} eq 'author') {
1.142 bisitz 1985: $msg = &mt('There are no authors or co-authors to display.');
1.3 raeburn 1986: } elsif ($env{'form.roletype'} eq 'course') {
1.142 bisitz 1987: $msg = &mt('There are no course users to display');
1.101 raeburn 1988: } elsif ($env{'form.roletype'} eq 'community') {
1.142 bisitz 1989: $msg = &mt('There are no community users to display');
1.2 raeburn 1990: }
1.3 raeburn 1991: } elsif ($context eq 'course') {
1992: $r->print(&mt('There are no course users to display.')."\n");
1993: }
1.148 bisitz 1994: $r->print('<p class="LC_info">'.$msg.'</p>'."\n") if $msg;
1.3 raeburn 1995: } else {
1996: # Print out the available choices
1.4 raeburn 1997: my $usercount;
1.3 raeburn 1998: if ($env{'form.action'} eq 'modifystudent') {
1.10 raeburn 1999: ($usercount) = &show_users_list($r,$context,'view',$permission,
1.150 raeburn 2000: $env{'form.Status'},\%userlist,$keylist,'',
2001: $showcredits);
1.1 raeburn 2002: } else {
1.4 raeburn 2003: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1.150 raeburn 2004: $permission,$env{'form.Status'},\%userlist,
1.159 raeburn 2005: $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
1.4 raeburn 2006: }
2007: if (!$usercount) {
1.142 bisitz 2008: $r->print('<br /><span class="LC_info">'
1.72 bisitz 2009: .&mt('There are no users matching the search criteria.')
2010: .'</span>'
2011: );
1.2 raeburn 2012: }
2013: }
1.10 raeburn 2014: $r->print('<input type="hidden" name="phase" value="'.
2015: $env{'form.phase'}.'" /></form>');
1.140 raeburn 2016: return;
1.2 raeburn 2017: }
2018:
1.53 raeburn 2019: sub role_filter {
2020: my ($context) = @_;
2021: my $output;
2022: my $roleselected = '';
2023: if ($env{'form.showrole'} eq 'Any') {
1.91 bisitz 2024: $roleselected = ' selected="selected"';
1.53 raeburn 2025: }
2026: my ($role_select);
2027: if ($context eq 'domain') {
2028: $role_select = &domain_roles_select();
1.140 raeburn 2029: $output = '<span class="LC_nobreak">'
1.70 bisitz 2030: .&mt('Role Type: [_1]',$role_select)
1.140 raeburn 2031: .'</span>';
1.53 raeburn 2032: } else {
1.140 raeburn 2033: $role_select = '<select name="showrole" onchange="javascript:updateCols('."'showrole'".');">'."\n".
1.53 raeburn 2034: '<option value="Any" '.$roleselected.'>'.
2035: &mt('Any role').'</option>';
1.101 raeburn 2036: my ($roletype,$crstype);
2037: if ($context eq 'course') {
2038: $crstype = &Apache::loncommon::course_type();
2039: if ($crstype eq 'Community') {
2040: $roletype = 'community';
2041: } else {
2042: $roletype = 'course';
2043: }
2044: }
2045: my @poss_roles = &curr_role_permissions($context,'','',$roletype);
1.53 raeburn 2046: foreach my $role (@poss_roles) {
2047: $roleselected = '';
2048: if ($role eq $env{'form.showrole'}) {
1.91 bisitz 2049: $roleselected = ' selected="selected"';
1.53 raeburn 2050: }
2051: my $plrole;
2052: if ($role eq 'cr') {
2053: $plrole = &mt('Custom role');
2054: } else {
1.101 raeburn 2055: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.53 raeburn 2056: }
2057: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
2058: }
2059: $role_select .= '</select>';
1.140 raeburn 2060: $output = '<span class="LC_nobreak">'
1.70 bisitz 2061: .&mt('Role: [_1]',$role_select)
1.140 raeburn 2062: .'</span>';
1.53 raeburn 2063: }
2064: return $output;
2065: }
2066:
1.33 raeburn 2067: sub section_group_filter {
2068: my ($cnum,$cdom) = @_;
2069: my @filters;
2070: if ($env{'request.course.sec'} eq '') {
2071: @filters = ('sec');
2072: }
2073: push(@filters,'grp');
2074: my %name = (
2075: sec => 'secfilter',
2076: grp => 'grpfilter',
2077: );
2078: my %title = &Apache::lonlocal::texthash (
2079: sec => 'Section(s)',
2080: grp => 'Group(s)',
2081: all => 'all',
2082: none => 'none',
2083: );
1.47 raeburn 2084: my $output;
1.33 raeburn 2085: foreach my $item (@filters) {
1.47 raeburn 2086: my ($markup,@options);
1.33 raeburn 2087: if ($env{'form.'.$name{$item}} eq '') {
2088: $env{'form.'.$name{$item}} = 'all';
2089: }
2090: if ($item eq 'sec') {
1.103 raeburn 2091: if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
1.33 raeburn 2092: $env{'form.'.$name{$item}} = 'none';
2093: }
2094: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
2095: @options = sort(keys(%sections_count));
2096: } elsif ($item eq 'grp') {
2097: my %curr_groups = &Apache::longroup::coursegroups();
2098: @options = sort(keys(%curr_groups));
2099: }
2100: if (@options > 0) {
2101: my $currsel;
1.112 bisitz 2102: $markup = '<select name="'.$name{$item}.'">'."\n";
1.33 raeburn 2103: foreach my $option ('all','none',@options) {
2104: $currsel = '';
2105: if ($env{'form.'.$name{$item}} eq $option) {
1.96 bisitz 2106: $currsel = ' selected="selected"';
1.33 raeburn 2107: }
2108: $markup .= ' <option value="'.$option.'"'.$currsel.'>';
2109: if (($option eq 'all') || ($option eq 'none')) {
2110: $markup .= $title{$option};
2111: } else {
2112: $markup .= $option;
2113: }
2114: $markup .= '</option>'."\n";
2115: }
2116: $markup .= '</select>'."\n";
1.111 bisitz 2117: $output .= (' 'x3).'<span class="LC_nobreak">'
2118: .'<label>'.$title{$item}.': '.$markup.'</label>'
2119: .'</span> ';
1.33 raeburn 2120: }
2121: }
2122: return $output;
2123: }
2124:
1.140 raeburn 2125: sub infocolumns {
1.150 raeburn 2126: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2127: my @cols;
2128: if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) {
1.150 raeburn 2129: @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2130: } else {
1.150 raeburn 2131: my @posscols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2132: if ($env{'form.phase'} ne '') {
2133: my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol');
2134: foreach my $col (@checkedcols) {
2135: if (grep(/^$col$/,@posscols)) {
2136: push(@cols,$col);
2137: }
2138: }
2139: } else {
2140: @cols = @posscols;
2141: }
2142: }
2143: return @cols;
2144: }
2145:
2146: sub get_cols_array {
1.150 raeburn 2147: my ($context,$mode,$showcredits) = @_;
1.140 raeburn 2148: my @cols;
2149: if ($mode eq 'pickauthor') {
2150: @cols = ('username','fullname','status','email');
2151: } else {
2152: @cols = ('username','domain','id','fullname');
2153: if ($context eq 'course') {
2154: push(@cols,'section');
2155: }
2156: push(@cols,('start','end','role'));
2157: unless (($mode eq 'autoenroll') && ($env{'form.Status'} ne 'Any')) {
2158: push(@cols,'status');
2159: }
2160: if ($context eq 'course') {
2161: push(@cols,'groups');
2162: }
2163: push(@cols,'email');
2164: if (($context eq 'course') && ($mode ne 'autoenroll')) {
1.150 raeburn 2165: if ($showcredits) {
2166: push(@cols,'credits');
2167: }
1.140 raeburn 2168: push(@cols,'lastlogin','clicker');
2169: }
2170: if (($context eq 'course') && ($mode ne 'autoenroll') &&
2171: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
1.156 raeburn 2172: push(@cols,'photo');
1.140 raeburn 2173: }
1.149 raeburn 2174: if ($context eq 'domain') {
1.159 raeburn 2175: push (@cols,('authorusage','authorquota','extent'));
1.149 raeburn 2176: }
1.140 raeburn 2177: }
2178: return @cols;
2179: }
2180:
2181: sub column_checkboxes {
1.150 raeburn 2182: my ($context,$mode,$formname,$showcredits) = @_;
2183: my @cols = &get_cols_array($context,$mode,$showcredits);
1.140 raeburn 2184: my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
2185: my (%disabledchk,%unchecked);
2186: if ($env{'form.phase'} eq '') {
2187: $disabledchk{'status'} = 1;
2188: if ($context eq 'course') {
2189: $disabledchk{'role'} = 1;
2190: $unchecked{'photo'} = 1;
1.149 raeburn 2191: $unchecked{'clicker'} = 1;
1.150 raeburn 2192: if ($showcredits) {
2193: $unchecked{'credits'} = 1;
2194: }
1.149 raeburn 2195: } elsif ($context eq 'domain') {
2196: $unchecked{'extent'} = 1;
1.140 raeburn 2197: }
2198: $unchecked{'start'} = 1;
2199: $unchecked{'end'} = 1;
2200: } else {
2201: if ($env{'form.Status'} ne 'Any') {
2202: $disabledchk{'status'} = 1;
2203: }
1.146 raeburn 2204: if (($env{'form.showrole'} ne 'Any') && ($env{'form.showrole'} ne 'cr')) {
2205: $disabledchk{'role'} = 1;
1.140 raeburn 2206: }
1.149 raeburn 2207: if ($context eq 'domain') {
2208: if (($env{'form.roletype'} eq 'course') ||
2209: ($env{'form.roletype'} eq 'community')) {
2210: $disabledchk{'status'} = 1;
1.159 raeburn 2211: $disabledchk{'authorusage'} = 1;
2212: $disabledchk{'authorquota'} = 1;
1.149 raeburn 2213: } elsif ($env{'form.roletype'} eq 'domain') {
2214: $disabledchk{'extent'} = 1;
2215: }
2216: }
1.140 raeburn 2217: }
2218: my $numposs = scalar(@cols);
1.149 raeburn 2219: my $numinrow = 7;
1.140 raeburn 2220: my %lt = &get_column_names($context);
2221: my $output = '<fieldset><legend>'.&mt('Information to show').'</legend>'."\n".'<span class="LC_nobreak">'.
2222: '<input type="button" onclick="javascript:checkAll(document.'.$formname.'.showcol);" value="'.&mt('check all').'" />'.
2223: (' 'x3).
2224: '<input type="button" onclick="javascript:uncheckAll(document.'.$formname.'.showcol);" value="'.&mt('uncheck all').'" />'.
2225: '</span><table>';
2226:
2227: for (my $i=0; $i<$numposs; $i++) {
2228: my $rem = $i%($numinrow);
2229: if ($rem == 0) {
2230: if ($i > 0) {
2231: $output .= '</tr>';
2232: }
2233: $output .= '<tr>';
2234: }
2235: my $checked;
2236: if ($env{'form.phase'} eq '') {
2237: $checked = ' checked="checked"';
2238: if ($unchecked{$cols[$i]}) {
2239: $checked = '';
2240: }
2241: if ($disabledchk{$cols[$i]}) {
2242: $checked = ' disabled="disabled"';
2243: }
2244: } elsif (grep(/^\Q$cols[$i]\E$/,@showncols)) {
2245: $checked = ' checked="checked"';
2246: } elsif ($disabledchk{$cols[$i]}) {
2247: $checked = ' disabled="disabled"';
2248: }
2249: if ($i == $numposs-1) {
2250: my $colsleft = $numinrow-$rem;
2251: if ($colsleft > 1) {
2252: $output .= '<td colspan="'.$colsleft.'">';
2253: } else {
2254: $output .= '<td>';
2255: }
2256: } else {
2257: $output .= '<td>';
2258: }
1.149 raeburn 2259: my $style;
2260: if ($cols[$i] eq 'extent') {
2261: if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
2262: $style = ' style="display: none;"';
2263: }
1.159 raeburn 2264: } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
2265: if ($env{'form.roletype'} ne 'domain') {
2266: $style = ' style="display: none;"';
2267: }
2268: }
1.149 raeburn 2269: $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.
2270: '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.
2271: $lt{$cols[$i]}.'</span>'.
2272: '</label></span></td>';
1.140 raeburn 2273: }
2274: $output .= '</tr></table></fieldset>';
2275: return $output;
2276: }
2277:
1.2 raeburn 2278: sub list_submit_button {
2279: my ($text) = @_;
1.11 raeburn 2280: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1.2 raeburn 2281: }
2282:
1.140 raeburn 2283: sub get_column_names {
2284: my ($context) = @_;
2285: my %lt = &Apache::lonlocal::texthash(
2286: 'username' => "username",
2287: 'domain' => "domain",
2288: 'id' => 'ID',
2289: 'fullname' => "name",
2290: 'section' => "section",
2291: 'groups' => "active groups",
2292: 'start' => "start date",
2293: 'end' => "end date",
2294: 'status' => "status",
2295: 'role' => "role",
1.150 raeburn 2296: 'credits' => "credits",
1.140 raeburn 2297: 'type' => "enroll type/action",
2298: 'email' => "e-mail address",
2299: 'photo' => "photo",
2300: 'lastlogin' => "last login",
2301: 'extent' => "extent",
1.159 raeburn 2302: 'authorusage' => "disk usage (%)",
2303: 'authorquota' => "disk quota (MB)",
1.140 raeburn 2304: 'ca' => "check all",
2305: 'ua' => "uncheck all",
2306: 'clicker' => "clicker-ID",
2307: );
2308: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1.149 raeburn 2309: $lt{'extent'} = &mt('course(s): description, section(s), status');
1.140 raeburn 2310: } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
1.154 raeburn 2311: $lt{'extent'} = &mt('community(s): description, section(s), status');
1.149 raeburn 2312: } elsif (($context eq 'author') ||
2313: ($context eq 'domain' && $env{'form.roletype'} eq 'author')) {
2314: $lt{'extent'} = &mt('author');
1.140 raeburn 2315: }
2316: return %lt;
2317: }
2318:
1.2 raeburn 2319: sub gather_userinfo {
1.11 raeburn 2320: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1.52 raeburn 2321: my $viewablesec;
2322: if ($context eq 'course') {
2323: $viewablesec = &viewable_section($permission);
2324: }
1.2 raeburn 2325: foreach my $item (keys(%{$rolehash})) {
2326: my %userdata;
1.22 raeburn 2327: if ($context eq 'author') {
1.2 raeburn 2328: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2329: split(/:/,$item);
2330: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2331: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2332: $item,$userlist);
1.22 raeburn 2333: } elsif ($context eq 'course') {
2334: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
2335: $userdata{'section'}) = split(/:/,$item,-1);
2336: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
2337: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
2338: next if ($viewablesec ne $userdata{'section'});
2339: }
1.24 raeburn 2340: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2341: $item,$userlist);
1.2 raeburn 2342: } elsif ($context eq 'domain') {
2343: if ($env{'form.roletype'} eq 'domain') {
2344: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
2345: split(/:/,$item);
2346: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1.24 raeburn 2347: &build_user_record($context,\%userdata,$userinfo,$indexhash,
2348: $item,$userlist);
1.13 raeburn 2349: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2350: if (ref($rolehash->{$item}) eq 'HASH') {
2351: $userdata{'extent'} = $item;
2352: foreach my $key (keys(%{$rolehash->{$item}})) {
2353: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
2354: ($userdata{'start'},$userdata{'end'}) =
2355: split(/:/,$rolehash->{$item}{$key});
2356: my $uniqid = $key.':'.$item;
1.25 raeburn 2357: &build_user_record($context,\%userdata,$userinfo,
2358: $indexhash,$uniqid,$userlist);
1.2 raeburn 2359: }
2360: }
1.102 raeburn 2361: } elsif (($env{'form.roletype'} eq 'course') ||
2362: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 2363: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
2364: split(/:/,$item);
2365: if (ref($rolehash->{$item}) eq 'HASH') {
1.11 raeburn 2366: my $numcids = keys(%{$rolehash->{$item}});
1.2 raeburn 2367: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
2368: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
2369: my $spanstart = '';
2370: my $spanend = '; ';
2371: my $space = ', ';
2372: if ($format eq 'html' || $format eq 'view') {
2373: $spanstart = '<span class="LC_nobreak">';
1.23 raeburn 2374: # FIXME: actions on courses disabled for now
2375: # if ($permission->{'cusr'}) {
2376: # if ($numcids > 1) {
1.25 raeburn 2377: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2378: # } else {
1.25 raeburn 2379: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
1.23 raeburn 2380: # }
2381: # }
1.2 raeburn 2382: $spanend = '</span><br />';
2383: $space = ', ';
2384: }
2385: $userdata{'extent'} .= $spanstart.
2386: $rolehash->{$item}{$cid}{'desc'}.$space;
2387: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
2388: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1.25 raeburn 2389: if (($env{'form.Status'} eq 'Any') ||
2390: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
2391: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
2392: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
2393: }
1.2 raeburn 2394: }
2395: }
2396: }
2397: }
2398: }
1.25 raeburn 2399: if ($userdata{'status'} ne '') {
2400: &build_user_record($context,\%userdata,$userinfo,
2401: $indexhash,$item,$userlist);
2402: }
1.2 raeburn 2403: }
2404: }
2405: }
2406: return;
2407: }
2408:
2409: sub build_user_record {
1.24 raeburn 2410: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1.11 raeburn 2411: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1.102 raeburn 2412: if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
2413: && ($env{'form.roletype'} eq 'community')))) {
1.24 raeburn 2414: &process_date_info($userdata);
2415: }
1.2 raeburn 2416: my $username = $userdata->{'username'};
2417: my $domain = $userdata->{'domain'};
2418: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1.24 raeburn 2419: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1.2 raeburn 2420: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2421: } else {
2422: &aggregate_user_info($domain,$username,$userinfo);
2423: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
2424: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
2425: }
2426: foreach my $key (keys(%{$indexhash})) {
2427: if (defined($userdata->{$key})) {
2428: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
2429: }
2430: }
2431: return;
2432: }
2433:
2434: sub courses_selector {
2435: my ($cdom,$formname) = @_;
2436: my %coursecodes = ();
2437: my %codes = ();
2438: my @codetitles = ();
2439: my %cat_titles = ();
2440: my %cat_order = ();
2441: my %idlist = ();
2442: my %idnums = ();
2443: my %idlist_titles = ();
2444: my $caller = 'global';
2445: my $format_reply;
2446: my $jscript = '';
2447:
1.7 albertel 2448: my $totcodes = 0;
2449: $totcodes =
1.2 raeburn 2450: &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,
2451: $cdom,$totcodes);
2452: if ($totcodes > 0) {
2453: $format_reply =
2454: &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
2455: \%codes,\@codetitles,\%cat_titles,\%cat_order);
2456: if ($format_reply eq 'ok') {
2457: my $numtypes = @codetitles;
2458: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
2459: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
2460: my $longtitles_str = join('","',@{$longtitles});
2461: my $allidlist = $idlist{$codetitles[0]};
2462: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
2463: $jscript .= $scripttext;
1.181 raeburn 2464: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
1.2 raeburn 2465: }
2466: }
2467: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
2468:
2469: my %elements = (
2470: Year => 'selectbox',
2471: coursepick => 'radio',
2472: coursetotal => 'text',
2473: courselist => 'text',
2474: );
2475: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
2476: if ($env{'form.coursepick'} eq 'category') {
2477: $jscript .= qq|
2478: function setCourseCat(formname) {
2479: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
2480: return;
2481: }
1.120 raeburn 2482: courseSet('$codetitles[0]');
1.2 raeburn 2483: for (var j=0; j<formname.Semester.length; j++) {
2484: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
2485: formname.Semester.options[j].selected = true;
2486: }
2487: }
2488: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
2489: return;
2490: }
1.120 raeburn 2491: courseSet('$codetitles[1]');
1.2 raeburn 2492: for (var j=0; j<formname.Department.length; j++) {
1.187 raeburn 2493: if (formname.Department.options[j].value == "$env{'form.Department'}") {
2494: formname.Department.options[j].selected = true;
1.2 raeburn 2495: }
2496: }
2497: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
2498: return;
2499: }
1.120 raeburn 2500: courseSet('$codetitles[2]');
1.2 raeburn 2501: for (var j=0; j<formname.Number.length; j++) {
2502: if (formname.Number.options[j].value == "$env{'form.Number'}") {
2503: formname.Number.options[j].selected = true;
2504: }
2505: }
2506: }
2507: |;
2508: }
2509: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
2510: \%idlist_titles);
2511: }
2512:
2513: sub course_selector_loadcode {
2514: my ($formname) = @_;
2515: my $loadcode;
2516: if ($env{'form.coursepick'} ne '') {
2517: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
2518: if ($env{'form.coursepick'} eq 'category') {
2519: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
2520: }
2521: }
2522: return $loadcode;
2523: }
2524:
2525: sub process_coursepick {
2526: my $coursefilter = $env{'form.coursepick'};
2527: my $cdom = $env{'request.role.domain'};
2528: my %courses;
1.105 raeburn 2529: my $crssrch = 'Course';
2530: if ($env{'form.roletype'} eq 'community') {
2531: $crssrch = 'Community';
2532: }
1.2 raeburn 2533: if ($coursefilter eq 'all') {
2534: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1.105 raeburn 2535: undef,undef,$crssrch);
1.2 raeburn 2536: } elsif ($coursefilter eq 'category') {
2537: my $instcode = &instcode_from_coursefilter();
2538: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1.105 raeburn 2539: undef,undef,$crssrch);
1.2 raeburn 2540: } elsif ($coursefilter eq 'specific') {
2541: if ($env{'form.coursetotal'} > 1) {
2542: my @course_ids = split(/&&/,$env{'form.courselist'});
2543: foreach my $cid (@course_ids) {
2544: $courses{$cid} = '';
1.1 raeburn 2545: }
1.2 raeburn 2546: } else {
2547: $courses{$env{'form.courselist'}} = '';
1.1 raeburn 2548: }
1.2 raeburn 2549: }
2550: return %courses;
2551: }
2552:
2553: sub instcode_from_coursefilter {
2554: my $instcode = '';
2555: my @cats = ('Semester','Year','Department','Number');
2556: foreach my $category (@cats) {
2557: if (defined($env{'form.'.$category})) {
2558: unless ($env{'form.'.$category} eq '-1') {
2559: $instcode .= $env{'form.'.$category};
2560: }
2561: }
2562: }
2563: if ($instcode eq '') {
2564: $instcode = '.';
2565: }
2566: return $instcode;
2567: }
2568:
2569: sub make_keylist_array {
2570: my ($index,$keylist);
2571: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
2572: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
2573: $index->{'end'} = &Apache::loncoursedata::CL_END();
2574: $index->{'start'} = &Apache::loncoursedata::CL_START();
2575: $index->{'id'} = &Apache::loncoursedata::CL_ID();
2576: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
2577: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
2578: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
2579: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
2580: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
2581: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
2582: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
2583: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
2584: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1.44 raeburn 2585: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
1.47 raeburn 2586: $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
1.150 raeburn 2587: $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
1.174 raeburn 2588: $index->{'instsec'} = &Apache::loncoursedata::CL_INSTSEC();
1.159 raeburn 2589: $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
2590: $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
1.2 raeburn 2591: foreach my $key (keys(%{$index})) {
2592: $keylist->[$index->{$key}] = $key;
2593: }
2594: return ($index,$keylist);
2595: }
2596:
2597: sub aggregate_user_info {
2598: my ($udom,$uname,$userinfo) = @_;
2599: my %info=&Apache::lonnet::get('environment',
2600: ['firstname','middlename',
2601: 'lastname','generation','id'],
2602: $udom,$uname);
2603: my ($tmp) = keys(%info);
2604: my ($fullname,$id);
2605: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
2606: $fullname = 'not available';
2607: $id = 'not available';
2608: &Apache::lonnet::logthis('unable to retrieve environment '.
2609: 'for '.$uname.':'.$udom);
1.1 raeburn 2610: } else {
1.2 raeburn 2611: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
2612: $id = $info{'id'};
2613: }
2614: $userinfo->{$uname.':'.$udom} = {
2615: fullname => $fullname,
2616: id => $id,
2617: };
2618: return;
2619: }
1.1 raeburn 2620:
1.2 raeburn 2621: sub process_date_info {
2622: my ($userdata) = @_;
2623: my $now = time;
1.83 raeburn 2624: $userdata->{'status'} = 'Active';
1.2 raeburn 2625: if ($userdata->{'start'} > 0) {
2626: if ($now < $userdata->{'start'}) {
1.83 raeburn 2627: $userdata->{'status'} = 'Future';
1.2 raeburn 2628: }
1.1 raeburn 2629: }
1.2 raeburn 2630: if ($userdata->{'end'} > 0) {
2631: if ($now > $userdata->{'end'}) {
1.83 raeburn 2632: $userdata->{'status'} = 'Expired';
1.2 raeburn 2633: }
2634: }
2635: return;
1.1 raeburn 2636: }
2637:
2638: sub show_users_list {
1.150 raeburn 2639: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
1.159 raeburn 2640: $showcredits,$needauthorquota,$needauthorusage)=@_;
1.55 raeburn 2641: if ($formname eq '') {
2642: $formname = 'studentform';
2643: }
1.159 raeburn 2644: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1 raeburn 2645: #
2646: # Variables for excel output
2647: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
2648: #
2649: # Variables for csv output
2650: my ($CSVfile,$CSVfilename);
2651: #
2652: my $sortby = $env{'form.sortby'};
1.3 raeburn 2653: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1.2 raeburn 2654: if ($context eq 'course') {
1.3 raeburn 2655: push(@sortable,('section','groups','type'));
1.150 raeburn 2656: if ($showcredits) {
2657: push(@sortable,'credits');
2658: }
1.2 raeburn 2659: } else {
1.3 raeburn 2660: push(@sortable,'extent');
1.159 raeburn 2661: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
2662: (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
2663: push(@sortable,('authorusage','authorquota'));
2664: }
1.3 raeburn 2665: }
1.55 raeburn 2666: if ($mode eq 'pickauthor') {
2667: @sortable = ('username','fullname','email','status');
2668: }
1.156 raeburn 2669: my %is_sortable;
1.158 raeburn 2670: map { $is_sortable{$_} = 1; } @sortable;
1.156 raeburn 2671: unless ($is_sortable{$sortby}) {
1.3 raeburn 2672: $sortby = 'username';
1.1 raeburn 2673: }
1.22 raeburn 2674: my $setting = $env{'form.roletype'};
1.150 raeburn 2675: my ($cid,$cdom,$cnum,$classgroups,$crstype,$defaultcredits);
1.1 raeburn 2676: if ($context eq 'course') {
1.22 raeburn 2677: $cid = $env{'request.course.id'};
1.101 raeburn 2678: $crstype = &Apache::loncommon::course_type();
1.17 raeburn 2679: ($cnum,$cdom) = &get_course_identity($cid);
1.150 raeburn 2680: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
1.2 raeburn 2681: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
2682: $userlist,$keylist,$cdom,$cnum);
1.16 raeburn 2683: if ($mode eq 'autoenroll') {
2684: $env{'form.showrole'} = 'st';
2685: } else {
2686: if ($env{'course.'.$cid.'.internal.showphoto'}) {
2687: $r->print('
1.1 raeburn 2688: <script type="text/javascript">
1.96 bisitz 2689: // <![CDATA[
1.1 raeburn 2690: function photowindow(photolink) {
2691: var title = "Photo_Viewer";
2692: var options = "scrollbars=1,resizable=1,menubar=0";
2693: options += ",width=240,height=240";
2694: stdeditbrowser = open(photolink,title,options,"1");
2695: stdeditbrowser.focus();
2696: }
1.96 bisitz 2697: // ]]>
1.1 raeburn 2698: </script>
1.16 raeburn 2699: ');
2700: }
2701: }
1.102 raeburn 2702: } elsif ($context eq 'domain') {
2703: if ($setting eq 'community') {
2704: $crstype = 'Community';
1.105 raeburn 2705: } elsif ($setting eq 'course') {
1.102 raeburn 2706: $crstype = 'Course';
2707: }
1.1 raeburn 2708: }
1.55 raeburn 2709: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.40 raeburn 2710: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1.56 raeburn 2711: my $verify_action_js = &bulkaction_javascript($formname);
1.1 raeburn 2712: $r->print(<<END);
1.10 raeburn 2713:
2714: <script type="text/javascript" language="Javascript">
1.96 bisitz 2715: // <![CDATA[
1.11 raeburn 2716:
1.56 raeburn 2717: $verify_action_js
1.10 raeburn 2718:
2719: function username_display_launch(username,domain) {
2720: var target;
1.177 raeburn 2721: if (!document.$formname.usernamelink.length) {
2722: target = document.$formname.usernamelink.value;
2723: } else {
2724: for (var i=0; i<document.$formname.usernamelink.length; i++) {
2725: if (document.$formname.usernamelink[i].checked) {
2726: target = document.$formname.usernamelink[i].value;
2727: }
1.10 raeburn 2728: }
2729: }
1.179 raeburn 2730: if ((target == 'modify') || (target == 'activity')) {
2731: var nextaction = 'singleuser';
2732: if (target == 'activity') {
2733: nextaction = 'accesslogs';
2734: }
1.55 raeburn 2735: if (document.$formname.userwin.checked == true) {
1.179 raeburn 2736: var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&srchin=dom&srchby=uname&srchtype=exact&popup=1&action='+nextaction;
1.50 raeburn 2737: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2738: modifywin = window.open(url,'',options,1);
2739: modifywin.focus();
2740: return;
2741: } else {
1.55 raeburn 2742: document.$formname.srchterm.value=username;
2743: document.$formname.srchdomain.value=domain;
2744: document.$formname.phase.value='get_user_info';
1.179 raeburn 2745: document.$formname.action.value = nextaction;
1.55 raeburn 2746: document.$formname.submit();
1.50 raeburn 2747: }
1.10 raeburn 2748: }
1.48 raeburn 2749: if (target == 'aboutme') {
1.55 raeburn 2750: if (document.$formname.userwin.checked == true) {
1.50 raeburn 2751: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
2752: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2753: aboutmewin = window.open(url,'',options,1);
2754: aboutmewin.focus();
2755: return;
2756: } else {
2757: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
2758: }
1.48 raeburn 2759: }
1.98 raeburn 2760: if (target == 'track') {
2761: if (document.$formname.userwin.checked == true) {
2762: var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
2763: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2764: var trackwin = window.open(url,'',options,1);
2765: trackwin.focus();
2766: return;
2767: } else {
2768: document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
2769: }
2770: }
1.10 raeburn 2771: }
1.96 bisitz 2772: // ]]>
1.10 raeburn 2773: </script>
1.11 raeburn 2774: $date_sec_selector
1.1 raeburn 2775: <input type="hidden" name="state" value="$env{'form.state'}" />
2776: END
2777: }
2778: $r->print(<<END);
2779: <input type="hidden" name="sortby" value="$sortby" />
2780: END
1.150 raeburn 2781: my @cols = &infocolumns($context,$mode,$showcredits);
1.140 raeburn 2782: my %coltxt = &get_column_names($context);
2783: my %acttxt = &Apache::lonlocal::texthash(
1.11 raeburn 2784: 'pr' => "Proceed",
2785: 'ac' => "Action to take for selected users",
1.56 raeburn 2786: 'link' => "Behavior of clickable username link for each user",
1.82 weissno 2787: 'aboutme' => "Display a user's personal information page",
1.50 raeburn 2788: 'owin' => "Open in a new window",
1.10 raeburn 2789: 'modify' => "Modify a user's information",
1.98 raeburn 2790: 'track' => "View a user's recent activity",
1.179 raeburn 2791: 'activity' => "View a user's access log",
1.1 raeburn 2792: );
1.140 raeburn 2793: my %lt = (%coltxt,%acttxt);
1.4 raeburn 2794: my $rolefilter = $env{'form.showrole'};
1.5 raeburn 2795: if ($env{'form.showrole'} eq 'cr') {
2796: $rolefilter = &mt('custom');
2797: } elsif ($env{'form.showrole'} ne 'Any') {
1.101 raeburn 2798: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype);
1.2 raeburn 2799: }
1.16 raeburn 2800: my $results_description;
2801: if ($mode ne 'autoenroll') {
2802: $results_description = &results_header_row($rolefilter,$statusmode,
1.102 raeburn 2803: $context,$permission,$mode,$crstype);
1.140 raeburn 2804: $r->print('<b>'.$results_description.'</b><br clear="all" />');
1.16 raeburn 2805: }
1.26 raeburn 2806: my ($output,$actionselect,%canchange,%canchangesec);
1.55 raeburn 2807: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
2808: if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.16 raeburn 2809: if ($permission->{'cusr'}) {
1.105 raeburn 2810: unless (($context eq 'domain') &&
2811: (($setting eq 'course') || ($setting eq 'community'))) {
2812: $actionselect =
2813: &select_actions($context,$setting,$statusmode,$formname);
2814: }
1.16 raeburn 2815: }
2816: $r->print(<<END);
1.10 raeburn 2817: <input type="hidden" name="srchby" value="uname" />
2818: <input type="hidden" name="srchin" value="dom" />
2819: <input type="hidden" name="srchtype" value="exact" />
2820: <input type="hidden" name="srchterm" value="" />
1.11 raeburn 2821: <input type="hidden" name="srchdomain" value="" />
1.1 raeburn 2822: END
1.16 raeburn 2823: if ($actionselect) {
1.41 raeburn 2824: $output .= <<"END";
1.94 bisitz 2825: <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
1.56 raeburn 2826: $actionselect
2827: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" />
2828: <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 2829: END
1.26 raeburn 2830: my @allroles;
2831: if ($env{'form.showrole'} eq 'Any') {
2832: my $custom = 1;
2833: if ($context eq 'domain') {
1.101 raeburn 2834: @allroles = &roles_by_context($setting,$custom,$crstype);
1.26 raeburn 2835: } else {
1.101 raeburn 2836: @allroles = &roles_by_context($context,$custom,$crstype);
1.26 raeburn 2837: }
2838: } else {
2839: @allroles = ($env{'form.showrole'});
2840: }
2841: foreach my $role (@allroles) {
2842: if ($context eq 'domain') {
2843: if ($setting eq 'domain') {
2844: if (&Apache::lonnet::allowed('c'.$role,
2845: $env{'request.role.domain'})) {
2846: $canchange{$role} = 1;
2847: }
1.31 raeburn 2848: } elsif ($setting eq 'author') {
2849: if (&Apache::lonnet::allowed('c'.$role,
2850: $env{'request.role.domain'})) {
2851: $canchange{$role} = 1;
2852: }
1.26 raeburn 2853: }
2854: } elsif ($context eq 'author') {
2855: if (&Apache::lonnet::allowed('c'.$role,
2856: $env{'user.domain'}.'/'.$env{'user.name'})) {
2857: $canchange{$role} = 1;
2858: }
2859: } elsif ($context eq 'course') {
2860: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2861: $canchange{$role} = 1;
2862: } elsif ($env{'request.course.sec'} ne '') {
2863: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
2864: $canchangesec{$role} = $env{'request.course.sec'};
2865: }
1.141 raeburn 2866: } elsif ((($role eq 'co') && ($crstype eq 'Community')) ||
2867: (($role eq 'cc') && ($crstype eq 'Course'))) {
2868: if (&is_courseowner($env{'request.course.id'},
2869: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
2870: $canchange{$role} = 1;
2871: }
1.26 raeburn 2872: }
2873: }
2874: }
1.16 raeburn 2875: }
1.94 bisitz 2876: $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
1.56 raeburn 2877: '<table><tr>';
2878: my @linkdests = ('aboutme');
2879: if ($permission->{'cusr'}) {
2880: unshift (@linkdests,'modify');
2881: }
1.179 raeburn 2882: if ($context eq 'course') {
2883: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
2884: &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
2885: $env{'request.course.sec'})) {
2886: push(@linkdests,'track');
2887: }
2888: } elsif ($context eq 'domain') {
2889: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
2890: push(@linkdests,'activity');
2891: }
1.98 raeburn 2892: }
1.56 raeburn 2893: $output .= '<td>';
2894: my $usernamelink = $env{'form.usernamelink'};
2895: if ($usernamelink eq '') {
2896: $usernamelink = 'aboutme';
2897: }
2898: foreach my $item (@linkdests) {
2899: my $checkedstr = '';
2900: if ($item eq $usernamelink) {
1.86 bisitz 2901: $checkedstr = ' checked="checked"';
1.56 raeburn 2902: }
1.86 bisitz 2903: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
1.56 raeburn 2904: }
2905: my $checkwin;
2906: if ($env{'form.userwin'}) {
1.86 bisitz 2907: $checkwin = ' checked="checked"';
1.56 raeburn 2908: }
1.144 bisitz 2909: $output .=
2910: '</td><td valign="top" style="border-left: 1px solid;">'
2911: .'<span class="LC_nobreak"><label>'
2912: .'<input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}
2913: .'</label></span></td></tr></table></fieldset></div>';
1.4 raeburn 2914: }
1.184 raeburn 2915: $output .= "\n".'<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
1.1 raeburn 2916: &Apache::loncommon::start_data_table().
1.4 raeburn 2917: &Apache::loncommon::start_data_table_header_row();
1.1 raeburn 2918: if ($mode eq 'autoenroll') {
1.4 raeburn 2919: $output .= "
1.55 raeburn 2920: <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
1.4 raeburn 2921: ";
1.1 raeburn 2922: } else {
1.105 raeburn 2923: $output .= "\n".'<th> </th>'."\n";
1.11 raeburn 2924: if ($actionselect) {
1.159 raeburn 2925: $output .= '<th class="LC_nobreak" valign="top">'.&mt('Select').'</th>'."\n";
1.11 raeburn 2926: }
1.1 raeburn 2927: }
2928: foreach my $item (@cols) {
1.159 raeburn 2929: $output .= '<th class="LC_nobreak" valign="top">';
1.156 raeburn 2930: if ($is_sortable{$item}) {
1.159 raeburn 2931: $output .= "<a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\" style=\"text-decoration:none;\">$lt{$item}<span class=\"LC_fontsize_small\"> ▼</span></a>";
1.156 raeburn 2932: } else {
2933: $output .= $lt{$item};
2934: }
2935: $output .= "</th>\n";
1.1 raeburn 2936: }
1.2 raeburn 2937: my %role_types = &role_type_names();
1.16 raeburn 2938: $output .= &Apache::loncommon::end_data_table_header_row();
1.1 raeburn 2939: # Done with the HTML header line
2940: } elsif ($mode eq 'csv') {
2941: #
2942: # Open a file
2943: $CSVfilename = '/prtspool/'.
1.2 raeburn 2944: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
2945: time.'_'.rand(1000000000).'.csv';
1.1 raeburn 2946: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
2947: $r->log_error("Couldn't open $CSVfilename for output $!");
1.108 bisitz 2948: $r->print(
2949: '<p class="LC_error">'
2950: .&mt('Problems occurred in writing the CSV file.')
2951: .' '.&mt('This error has been logged.')
2952: .' '.&mt('Please alert your LON-CAPA administrator.')
2953: .'</p>'
2954: );
1.1 raeburn 2955: $CSVfile = undef;
2956: }
2957: #
2958: # Write headers and data to file
1.2 raeburn 2959: print $CSVfile '"'.$results_description.'"'."\n";
1.1 raeburn 2960: print $CSVfile '"'.join('","',map {
2961: &Apache::loncommon::csv_translate($lt{$_})
1.67 droeschl 2962: } (@cols))."\"\n";
1.1 raeburn 2963: } elsif ($mode eq 'excel') {
2964: # Create the excel spreadsheet
2965: ($excel_workbook,$excel_filename,$format) =
2966: &Apache::loncommon::create_workbook($r);
2967: return if (! defined($excel_workbook));
2968: $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2 raeburn 2969: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1 raeburn 2970: #
2971: my @colnames = map {$lt{$_}} (@cols);
1.67 droeschl 2972:
1.1 raeburn 2973: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
2974: }
2975:
2976: # Done with header lines in all formats
2977: my %index;
2978: my $i;
1.2 raeburn 2979: foreach my $idx (@$keylist) {
2980: $index{$idx} = $i++;
2981: }
1.4 raeburn 2982: my $usercount = 0;
1.33 raeburn 2983: my ($secfilter,$grpfilter);
2984: if ($context eq 'course') {
2985: $secfilter = $env{'form.secfilter'};
2986: $grpfilter = $env{'form.grpfilter'};
2987: if ($secfilter eq '') {
2988: $secfilter = 'all';
2989: }
2990: if ($grpfilter eq '') {
2991: $grpfilter = 'all';
2992: }
2993: }
1.83 raeburn 2994: my %ltstatus = &Apache::lonlocal::texthash(
2995: Active => 'Active',
2996: Future => 'Future',
2997: Expired => 'Expired',
2998: );
1.139 raeburn 2999: # If this is for a single course get last course "log-in".
3000: my %crslogins;
3001: if ($context eq 'course') {
3002: %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
3003: }
1.2 raeburn 3004: # Get groups, role, permanent e-mail so we can sort on them if
3005: # necessary.
3006: foreach my $user (keys(%{$userlist})) {
1.43 raeburn 3007: if ($user eq '' ) {
3008: delete($userlist->{$user});
3009: next;
3010: }
1.11 raeburn 3011: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
3012: delete($userlist->{$user});
3013: next;
3014: }
1.2 raeburn 3015: my ($uname,$udom,$role,$groups,$email);
1.5 raeburn 3016: if (($statusmode ne 'Any') &&
3017: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
3018: delete($userlist->{$user});
3019: next;
3020: }
1.2 raeburn 3021: if ($context eq 'domain') {
3022: if ($env{'form.roletype'} eq 'domain') {
3023: ($role,$uname,$udom) = split(/:/,$user);
1.11 raeburn 3024: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
3025: ($udom eq $env{'request.role.domain'})) {
3026: delete($userlist->{$user});
3027: next;
3028: }
1.13 raeburn 3029: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3030: ($uname,$udom,$role) = split(/:/,$user,-1);
1.102 raeburn 3031: } elsif (($env{'form.roletype'} eq 'course') ||
3032: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 3033: ($uname,$udom,$role) = split(/:/,$user);
3034: }
3035: } else {
3036: ($uname,$udom,$role) = split(/:/,$user,-1);
3037: if (($context eq 'course') && $role eq '') {
3038: $role = 'st';
3039: }
3040: }
3041: $userlist->{$user}->[$index{'role'}] = $role;
3042: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
3043: delete($userlist->{$user});
3044: next;
3045: }
1.33 raeburn 3046: if ($context eq 'course') {
3047: my @ac_groups;
3048: if (ref($classgroups) eq 'HASH') {
3049: $groups = $classgroups->{$user};
3050: }
3051: if (ref($groups->{'active'}) eq 'HASH') {
3052: @ac_groups = keys(%{$groups->{'active'}});
3053: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
3054: }
3055: if ($mode ne 'autoenroll') {
3056: my $section = $userlist->{$user}->[$index{'section'}];
1.43 raeburn 3057: if (($env{'request.course.sec'} ne '') &&
3058: ($section ne $env{'request.course.sec'})) {
3059: if ($role eq 'st') {
3060: delete($userlist->{$user});
3061: next;
3062: }
3063: }
1.33 raeburn 3064: if ($secfilter eq 'none') {
3065: if ($section ne '') {
3066: delete($userlist->{$user});
3067: next;
3068: }
3069: } elsif ($secfilter ne 'all') {
3070: if ($section ne $secfilter) {
3071: delete($userlist->{$user});
3072: next;
3073: }
3074: }
3075: if ($grpfilter eq 'none') {
3076: if (@ac_groups > 0) {
3077: delete($userlist->{$user});
3078: next;
3079: }
3080: } elsif ($grpfilter ne 'all') {
3081: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
3082: delete($userlist->{$user});
3083: next;
3084: }
3085: }
1.44 raeburn 3086: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1.140 raeburn 3087: if ((grep/^photo$/,@cols) && ($role eq 'st')) {
1.44 raeburn 3088: $userlist->{$user}->[$index{'photo'}] =
1.47 raeburn 3089: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
3090: $userlist->{$user}->[$index{'thumbnail'}] =
1.44 raeburn 3091: &Apache::lonnet::retrievestudentphoto($udom,$uname,
3092: 'gif','thumbnail');
3093: }
3094: }
1.150 raeburn 3095: if (($role eq 'st') && ($defaultcredits)) {
3096: if ($userlist->{$user}->[$index{'credits'}] eq '') {
3097: $userlist->{$user}->[$index{'credits'}] = $defaultcredits;
3098: }
3099: }
1.33 raeburn 3100: }
1.2 raeburn 3101: }
3102: my %emails = &Apache::loncommon::getemails($uname,$udom);
3103: if ($emails{'permanentemail'} =~ /\S/) {
3104: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
3105: }
1.159 raeburn 3106: if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
3107: ($role eq 'au')) {
3108: my ($disk_quota,$current_disk_usage,$percent);
3109: if (($needauthorusage) || ($needauthorquota)) {
3110: $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
3111: }
3112: if ($needauthorusage) {
3113: $current_disk_usage =
3114: &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
3115: if ($disk_quota == 0) {
3116: $percent = 100.0;
3117: } else {
3118: $percent = $current_disk_usage/(10 * $disk_quota);
3119: }
3120: $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
3121: }
3122: if ($needauthorquota) {
3123: $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
3124: }
3125: }
1.4 raeburn 3126: $usercount ++;
3127: }
3128: my $autocount = 0;
3129: my $manualcount = 0;
3130: my $lockcount = 0;
3131: my $unlockcount = 0;
3132: if ($usercount) {
3133: $r->print($output);
3134: } else {
3135: if ($mode eq 'autoenroll') {
3136: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
3137: } else {
3138: return;
3139: }
1.1 raeburn 3140: }
1.2 raeburn 3141: #
3142: # Sort the users
1.1 raeburn 3143: my $index = $index{$sortby};
3144: my $second = $index{'username'};
3145: my $third = $index{'domain'};
1.159 raeburn 3146: my @sorted_users;
3147: if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {
3148: @sorted_users = sort {
3149: $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] ||
3150: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3151: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3152: } (keys(%$userlist));
3153: } else {
3154: @sorted_users = sort {
3155: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) ||
3156: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
3157: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
3158: } (keys(%$userlist));
3159: }
1.4 raeburn 3160: my $rowcount = 0;
1.178 raeburn 3161: my $disabled;
3162: if ($mode eq 'autoenroll') {
3163: unless ($permission->{'cusr'}) {
3164: $disabled = ' disabled="disabled"';
3165: }
3166: }
1.2 raeburn 3167: foreach my $user (@sorted_users) {
1.4 raeburn 3168: my %in;
1.2 raeburn 3169: my $sdata = $userlist->{$user};
1.4 raeburn 3170: $rowcount ++;
1.2 raeburn 3171: foreach my $item (@{$keylist}) {
3172: $in{$item} = $sdata->[$index{$item}];
3173: }
1.67 droeschl 3174: my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3175: if ($clickers!~/\w/) { $clickers='-'; }
1.159 raeburn 3176: $in{'clicker'} = $clickers;
1.67 droeschl 3177: my $role = $in{'role'};
1.102 raeburn 3178: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
1.136 raeburn 3179: unless ($mode eq 'excel') {
3180: if (! defined($in{'start'}) || $in{'start'} == 0) {
3181: $in{'start'} = &mt('none');
3182: } else {
3183: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
3184: }
3185: if (! defined($in{'end'}) || $in{'end'} == 0) {
3186: $in{'end'} = &mt('none');
3187: } else {
3188: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
3189: }
1.1 raeburn 3190: }
1.139 raeburn 3191: if ($context eq 'course') {
3192: my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
3193: if ($lastlogin ne '') {
3194: $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
3195: }
3196: }
1.55 raeburn 3197: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3198: $r->print(&Apache::loncommon::start_data_table_row());
1.11 raeburn 3199: my $checkval;
1.16 raeburn 3200: if ($mode eq 'autoenroll') {
3201: my $cellentry;
3202: if ($in{'type'} eq 'auto') {
1.178 raeburn 3203: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Change').'</label>';
1.16 raeburn 3204: $autocount ++;
3205: } else {
1.178 raeburn 3206: $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'}.'"'.$disabled.' /> '.&mt('Change').'</label></span></td></tr><tr><td><span class="LC_nobreak">';
1.16 raeburn 3207: $manualcount ++;
3208: if ($in{'lockedtype'}) {
1.178 raeburn 3209: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Unlock').'</label>';
1.16 raeburn 3210: $unlockcount ++;
3211: } else {
1.178 raeburn 3212: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' /> '.&mt('Lock').'</label>';
1.16 raeburn 3213: $lockcount ++;
1.11 raeburn 3214: }
1.76 bisitz 3215: $cellentry .= '</span></td></tr></table>';
1.16 raeburn 3216: }
3217: $r->print("<td>$cellentry</td>\n");
3218: } else {
1.55 raeburn 3219: if ($mode ne 'pickauthor') {
3220: $r->print("<td>$rowcount</td>\n");
3221: }
1.16 raeburn 3222: if ($actionselect) {
1.26 raeburn 3223: my $showcheckbox;
3224: if ($role =~ /^cr\//) {
3225: $showcheckbox = $canchange{'cr'};
3226: } else {
3227: $showcheckbox = $canchange{$role};
3228: }
3229: if (!$showcheckbox) {
3230: if ($context eq 'course') {
3231: if ($canchangesec{$role} ne '') {
3232: if ($canchangesec{$role} eq $in{'section'}) {
3233: $showcheckbox = 1;
3234: }
3235: }
1.16 raeburn 3236: }
1.26 raeburn 3237: }
3238: if ($showcheckbox) {
3239: $checkval = $user;
3240: if ($context eq 'course') {
1.141 raeburn 3241: if (($role eq 'co' || $role eq 'cc') &&
3242: ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
3243: $showcheckbox = 0;
3244: } else {
3245: if ($role eq 'st') {
3246: $checkval .= ':st';
3247: }
3248: $checkval .= ':'.$in{'section'};
3249: if ($role eq 'st') {
3250: $checkval .= ':'.$in{'type'}.':'.
1.150 raeburn 3251: $in{'lockedtype'}.':'.
1.174 raeburn 3252: $in{'credits'}.':'.
3253: &escape($in{'instsec'});
1.141 raeburn 3254: }
3255: }
3256: }
3257: if ($showcheckbox) {
3258: $r->print('<td><input type="checkbox" name="'.
1.183 raeburn 3259: 'actionlist" value="'.
3260: &HTML::Entities::encode($checkval,'&<>"').'" />');
3261: foreach my $item ('start','end') {
3262: $r->print('<input type="hidden" name="'.
3263: &HTML::Entities::encode($checkval.'_'.$item,'&<>"').'"'.
3264: ' value="'.$sdata->[$index{$item}].'" />');
3265: }
3266: $r->print('</td>');
1.141 raeburn 3267: } else {
3268: $r->print('<td> </td>');
1.16 raeburn 3269: }
1.26 raeburn 3270: } else {
3271: $r->print('<td> </td>');
1.16 raeburn 3272: }
1.55 raeburn 3273: } elsif ($mode eq 'pickauthor') {
3274: $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
1.11 raeburn 3275: }
3276: }
1.2 raeburn 3277: foreach my $item (@cols) {
1.10 raeburn 3278: if ($item eq 'username') {
1.48 raeburn 3279: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.83 raeburn 3280: } elsif ($item eq 'status') {
3281: my $showitem = $in{$item};
3282: if (defined($ltstatus{$in{$item}})) {
3283: $showitem = $ltstatus{$in{$item}};
3284: }
3285: $r->print('<td>'.$showitem.'</td>'."\n");
1.140 raeburn 3286: } elsif ($item eq 'photo') {
3287: if (($context eq 'course') && ($mode ne 'autoenroll') &&
3288: ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
3289: if ($role eq 'st') {
3290: $r->print('<td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
3291: } else {
3292: $r->print('<td> </td>');
3293: }
3294: }
3295: } elsif ($item eq 'clicker') {
3296: if (($context eq 'course') && ($mode ne 'autoenroll')) {
3297: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
3298: my $clickers =
3299: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
3300: if ($clickers!~/\w/) { $clickers='-'; }
3301: $r->print('<td>'.$clickers.'</td>');
3302: } else {
3303: $r->print('<td> </td>'."\n");
3304: }
1.149 raeburn 3305: }
1.159 raeburn 3306: } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
3307: $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
1.10 raeburn 3308: } else {
3309: $r->print('<td>'.$in{$item}.'</td>'."\n");
3310: }
1.2 raeburn 3311: }
3312: $r->print(&Apache::loncommon::end_data_table_row());
3313: } elsif ($mode eq 'csv') {
3314: next if (! defined($CSVfile));
3315: # no need to bother with $linkto
3316: my @line = ();
3317: foreach my $item (@cols) {
3318: push @line,&Apache::loncommon::csv_translate($in{$item});
3319: }
1.67 droeschl 3320: print $CSVfile '"'.join('","',@line)."\"\n";
1.2 raeburn 3321: } elsif ($mode eq 'excel') {
3322: my $col = 0;
3323: foreach my $item (@cols) {
3324: if ($item eq 'start' || $item eq 'end') {
1.136 raeburn 3325: if ((defined($in{$item})) && ($in{$item} != 0)) {
1.2 raeburn 3326: $excel_sheet->write($row,$col++,
1.136 raeburn 3327: &Apache::lonstathelpers::calc_serial($in{$item}),
1.2 raeburn 3328: $format->{'date'});
3329: } else {
3330: $excel_sheet->write($row,$col++,'none');
3331: }
3332: } else {
3333: $excel_sheet->write($row,$col++,$in{$item});
3334: }
3335: }
3336: $row++;
1.1 raeburn 3337: }
3338: }
1.55 raeburn 3339: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2 raeburn 3340: $r->print(&Apache::loncommon::end_data_table().'<br />');
3341: } elsif ($mode eq 'excel') {
3342: $excel_workbook->close();
1.162 bisitz 3343: $r->print('<p>'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<a href="'.$excel_filename.'">','</a>')."</p>\n");
1.2 raeburn 3344: } elsif ($mode eq 'csv') {
3345: close($CSVfile);
1.162 bisitz 3346: $r->print('<p>'.&mt('[_1]Your CSV file[_2] is ready for download.', '<a href="'.$CSVfilename.'">','</a>')."</p>\n");
1.2 raeburn 3347: $r->rflush();
3348: }
3349: if ($mode eq 'autoenroll') {
3350: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 3351: } else {
3352: return ($usercount);
1.2 raeburn 3353: }
1.1 raeburn 3354: }
3355:
1.56 raeburn 3356: sub bulkaction_javascript {
3357: my ($formname,$caller) = @_;
3358: my $docstart = 'document';
3359: if ($caller eq 'popup') {
3360: $docstart = 'opener.document';
3361: }
3362: my %lt = &Apache::lonlocal::texthash(
3363: acwi => 'Access will be set to start immediately',
3364: asyo => 'as you did not select an end date in the pop-up window',
3365: accw => 'Access will be set to continue indefinitely',
3366: asyd => 'as you did not select an end date in the pop-up window',
3367: sewi => "Sections will be switched to 'No section'",
3368: ayes => "as you either selected the 'No section' option",
3369: oryo => 'or you did not select a section in the pop-up window',
3370: arol => 'A role with no section will be added',
3371: swbs => 'Sections will be switched to:',
3372: rwba => 'Roles will be added for section(s):',
3373: );
3374: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
3375: my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
3376: my $singconfirm = &mt(' for a single user?');
3377: my $multconfirm = &mt(' for multiple users?');
1.170 damieng 3378: &js_escape(\$alert);
3379: &js_escape(\$noaction);
3380: &js_escape(\$singconfirm);
3381: &js_escape(\$multconfirm);
1.56 raeburn 3382: my $output = <<"ENDJS";
3383: function verify_action (field) {
3384: var numchecked = 0;
3385: var singconf = '$singconfirm';
3386: var multconf = '$multconfirm';
3387: if ($docstart.$formname.elements[field].length > 0) {
3388: for (i=0; i<$docstart.$formname.elements[field].length; i++) {
3389: if ($docstart.$formname.elements[field][i].checked == true) {
3390: numchecked ++;
3391: }
3392: }
3393: } else {
3394: if ($docstart.$formname.elements[field].checked == true) {
3395: numchecked ++;
3396: }
3397: }
3398: if (numchecked == 0) {
3399: alert("$alert");
3400: return;
3401: } else {
3402: var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
3403: var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
3404: if (choice == '') {
3405: alert("$noaction");
3406: return;
3407: } else {
3408: if (numchecked == 1) {
3409: message += singconf;
3410: } else {
3411: message += multconf;
3412: }
3413: ENDJS
3414: if ($caller ne 'popup') {
3415: $output .= <<"NEWWIN";
3416: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
3417: opendatebrowser(document.$formname,'$formname','go');
3418: return;
3419:
3420: } else {
3421: if (confirm(message)) {
3422: document.$formname.phase.value = 'bulkchange';
3423: document.$formname.submit();
3424: return;
3425: }
3426: }
3427: NEWWIN
3428: } else {
3429: $output .= <<"POPUP";
3430: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
3431: var datemsg = '';
3432: if (($docstart.$formname.startdate_month.value == '') &&
3433: ($docstart.$formname.startdate_day.value == '') &&
3434: ($docstart.$formname.startdate_year.value == '')) {
3435: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
3436: }
3437: if (($docstart.$formname.enddate_month.value == '') &&
3438: ($docstart.$formname.enddate_day.value == '') &&
3439: ($docstart.$formname.enddate_year.value == '')) {
3440: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
3441: }
3442: if (datemsg != '') {
3443: message += "\\n"+datemsg;
3444: }
3445: }
3446: if (choice == 'chgsec') {
3447: var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
3448: var retained = $docstart.$formname.retainsec.value;
3449: var secshow = $docstart.$formname.newsecs.value;
3450: if (secshow == '') {
3451: if (rolefilter == 'st' || retained == 0 || retained == "") {
3452: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3453: } else {
3454: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
3455: }
3456: } else {
3457: if (rolefilter == 'st' || retained == 0 || retained == "") {
3458: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
3459: } else {
3460: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
3461: }
3462: }
3463: }
3464: if (confirm(message)) {
3465: $docstart.$formname.phase.value = 'bulkchange';
3466: $docstart.$formname.submit();
3467: window.close();
3468: }
3469: POPUP
3470: }
3471: $output .= '
3472: }
3473: }
3474: }
3475: ';
3476: return $output;
3477: }
3478:
1.10 raeburn 3479: sub print_username_link {
1.48 raeburn 3480: my ($mode,$in) = @_;
1.10 raeburn 3481: my $output;
1.16 raeburn 3482: if ($mode eq 'autoenroll') {
3483: $output = $in->{'username'};
1.10 raeburn 3484: } else {
3485: $output = '<a href="javascript:username_display_launch('.
1.112 bisitz 3486: "'$in->{'username'}','$in->{'domain'}'".')">'.
1.10 raeburn 3487: $in->{'username'}.'</a>';
3488: }
3489: return $output;
3490: }
3491:
1.2 raeburn 3492: sub role_type_names {
3493: my %lt = &Apache::lonlocal::texthash (
1.13 raeburn 3494: 'domain' => 'Domain Roles',
3495: 'author' => 'Co-Author Roles',
3496: 'course' => 'Course Roles',
1.101 raeburn 3497: 'community' => 'Community Roles',
1.2 raeburn 3498: );
3499: return %lt;
3500: }
3501:
1.11 raeburn 3502: sub select_actions {
1.55 raeburn 3503: my ($context,$setting,$statusmode,$formname) = @_;
1.11 raeburn 3504: my %lt = &Apache::lonlocal::texthash(
3505: revoke => "Revoke user roles",
3506: delete => "Delete user roles",
3507: reenable => "Re-enable expired user roles",
3508: activate => "Make future user roles active now",
3509: chgdates => "Change starting/ending dates",
3510: chgsec => "Change section associated with user roles",
3511: );
1.150 raeburn 3512: # FIXME Add an option to change credits for student roles.
1.11 raeburn 3513: my ($output,$options,%choices);
1.23 raeburn 3514: # FIXME Disable actions for now for roletype=course in domain context
3515: if ($context eq 'domain' && $setting eq 'course') {
3516: return;
3517: }
1.26 raeburn 3518: if ($context eq 'course') {
3519: if ($env{'form.showrole'} ne 'Any') {
1.141 raeburn 3520: my $showactions;
3521: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
3522: $env{'request.course.id'})) {
3523: $showactions = 1;
3524: } elsif ($env{'request.course.sec'} ne '') {
3525: if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
3526: $showactions = 1;
3527: }
3528: }
3529: unless ($showactions) {
3530: unless (&is_courseowner($env{'request.course.id'},
3531: $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
3532: return;
3533: }
1.26 raeburn 3534: }
3535: }
3536: }
1.11 raeburn 3537: if ($statusmode eq 'Any') {
3538: $options .= '
3539: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
3540: $choices{'dates'} = 1;
3541: } else {
3542: if ($statusmode eq 'Future') {
3543: $options .= '
3544: <option value="activate">'.$lt{'activate'}.'</option>';
3545: $choices{'dates'} = 1;
3546: } elsif ($statusmode eq 'Expired') {
3547: $options .= '
3548: <option value="reenable">'.$lt{'reenable'}.'</option>';
3549: $choices{'dates'} = 1;
3550: }
1.13 raeburn 3551: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
3552: $options .= '
3553: <option value="chgdates">'.$lt{'chgdates'}.'</option>
3554: <option value="revoke">'.$lt{'revoke'}.'</option>';
3555: $choices{'dates'} = 1;
3556: }
1.11 raeburn 3557: }
3558: if ($context eq 'domain') {
3559: $options .= '
3560: <option value="delete">'.$lt{'delete'}.'</option>';
3561: }
3562: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26 raeburn 3563: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11 raeburn 3564: $options .= '
3565: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
3566: $choices{'sections'} = 1;
3567: }
3568: }
3569: if ($options) {
1.56 raeburn 3570: $output = '<select name="bulkaction">'."\n".
1.11 raeburn 3571: '<option value="" selected="selected">'.
3572: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
3573: if ($choices{'dates'}) {
3574: $output .=
3575: '<input type="hidden" name="startdate_month" value="" />'."\n".
3576: '<input type="hidden" name="startdate_day" value="" />'."\n".
3577: '<input type="hidden" name="startdate_year" value="" />'."\n".
3578: '<input type="hidden" name="startdate_hour" value="" />'."\n".
3579: '<input type="hidden" name="startdate_minute" value="" />'."\n".
3580: '<input type="hidden" name="startdate_second" value="" />'."\n".
3581: '<input type="hidden" name="enddate_month" value="" />'."\n".
3582: '<input type="hidden" name="enddate_day" value="" />'."\n".
3583: '<input type="hidden" name="enddate_year" value="" />'."\n".
3584: '<input type="hidden" name="enddate_hour" value="" />'."\n".
3585: '<input type="hidden" name="enddate_minute" value="" />'."\n".
1.56 raeburn 3586: '<input type="hidden" name="enddate_second" value="" />'."\n".
3587: '<input type="hidden" name="no_end_date" value="" />'."\n";
1.11 raeburn 3588: if ($context eq 'course') {
3589: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
3590: }
3591: }
3592: if ($choices{'sections'}) {
1.91 bisitz 3593: $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
3594: '<input type="hidden" name="newsecs" value="" />'."\n";
1.11 raeburn 3595: }
3596: }
3597: return $output;
3598: }
3599:
3600: sub date_section_javascript {
3601: my ($context,$setting) = @_;
1.49 raeburn 3602: my $title = 'Date_And_Section_Selector';
1.41 raeburn 3603: my %nopopup = &Apache::lonlocal::texthash (
3604: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
3605: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
3606: none => "Choose an action to take for selected users",
3607: );
1.96 bisitz 3608: my $output = <<"ENDONE";
3609: <script type="text/javascript">
3610: // <![CDATA[
1.41 raeburn 3611: function opendatebrowser(callingform,formname,calledby) {
1.11 raeburn 3612: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
3613: var url = '/adm/createuser?';
3614: var type = '';
3615: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
3616: ENDONE
3617: if ($context eq 'domain') {
3618: $output .= '
3619: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
3620: ';
3621: }
3622: my $width= '700';
3623: my $height = '400';
3624: $output .= <<"ENDTWO";
3625: url += 'action=dateselect&callingform=' + formname +
3626: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
3627: var title = '$title';
3628: var options = 'scrollbars=1,resizable=1,menubar=0';
3629: options += ',width=$width,height=$height';
3630: stdeditbrowser = open(url,title,options,'1');
3631: stdeditbrowser.focus();
3632: }
1.96 bisitz 3633: // ]]>
1.11 raeburn 3634: </script>
3635: ENDTWO
3636: return $output;
3637: }
3638:
3639: sub date_section_selector {
1.150 raeburn 3640: my ($context,$permission,$crstype,$showcredits) = @_;
1.11 raeburn 3641: my $callingform = $env{'form.callingform'};
3642: my $formname = 'dateselect';
3643: my $groupslist = &get_groupslist();
1.150 raeburn 3644: my $sec_js =
3645: &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
3646: $showcredits);
1.11 raeburn 3647: my $output = <<"END";
3648: <script type="text/javascript">
1.96 bisitz 3649: // <![CDATA[
1.11 raeburn 3650:
3651: $sec_js
3652:
3653: function saveselections(formname) {
3654:
3655: END
3656: if ($env{'form.bulkaction'} eq 'chgsec') {
3657: $output .= <<"END";
1.40 raeburn 3658: if (formname.retainsec.length > 1) {
3659: for (var i=0; i<formname.retainsec.length; i++) {
3660: if (formname.retainsec[i].checked == true) {
3661: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
3662: }
3663: }
3664: } else {
3665: opener.document.$callingform.retainsec.value = formname.retainsec.value;
3666: }
1.103 raeburn 3667: setSections(formname,'$crstype');
1.11 raeburn 3668: if (seccheck == 'ok') {
3669: opener.document.$callingform.newsecs.value = formname.sections.value;
3670: }
3671: END
3672: } else {
3673: if ($context eq 'course') {
3674: if (($env{'form.bulkaction'} eq 'reenable') ||
3675: ($env{'form.bulkaction'} eq 'activate') ||
3676: ($env{'form.bulkaction'} eq 'chgdates')) {
1.26 raeburn 3677: if ($env{'request.course.sec'} eq '') {
3678: $output .= <<"END";
1.11 raeburn 3679:
3680: if (formname.makedatesdefault.checked == true) {
3681: opener.document.$callingform.makedatesdefault.value = 1;
3682: }
3683: else {
3684: opener.document.$callingform.makedatesdefault.value = 0;
3685: }
3686:
3687: END
1.26 raeburn 3688: }
1.11 raeburn 3689: }
3690: }
3691: $output .= <<"END";
3692: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
3693: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
3694: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
3695: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
3696: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
3697: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
3698: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
3699: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
3700: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
3701: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
3702: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
3703: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
1.56 raeburn 3704: if (formname.no_end_date.checked) {
3705: opener.document.$callingform.no_end_date.value = '1';
3706: } else {
3707: opener.document.$callingform.no_end_date.value = '0';
3708: }
1.11 raeburn 3709: END
3710: }
1.56 raeburn 3711: my $verify_action_js = &bulkaction_javascript($callingform,'popup');
3712: $output .= <<"ENDJS";
3713: verify_action('actionlist');
1.11 raeburn 3714: }
1.56 raeburn 3715:
3716: $verify_action_js
3717:
1.96 bisitz 3718: // ]]>
1.11 raeburn 3719: </script>
1.56 raeburn 3720: ENDJS
1.11 raeburn 3721: my %lt = &Apache::lonlocal::texthash (
3722: chac => 'Access dates to apply for selected users',
3723: chse => 'Changes in section affiliation to apply to selected users',
1.118 raeburn 3724: 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.',
3725: forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
3726: reta => "Retain each user's current section affiliations?",
1.103 raeburn 3727: dnap => '(Does not apply to student roles).',
1.11 raeburn 3728: );
3729: my ($date_items,$headertext);
3730: if ($env{'form.bulkaction'} eq 'chgsec') {
3731: $headertext = $lt{'chse'};
3732: } else {
3733: $headertext = $lt{'chac'};
3734: my $starttime;
3735: if (($env{'form.bulkaction'} eq 'activate') ||
3736: ($env{'form.bulkaction'} eq 'reenable')) {
3737: $starttime = time;
3738: }
3739: $date_items = &date_setting_table($starttime,undef,$context,
1.21 raeburn 3740: $env{'form.bulkaction'},$formname,
1.101 raeburn 3741: $permission,$crstype);
1.11 raeburn 3742: }
3743: $output .= '<h3>'.$headertext.'</h3>'.
1.118 raeburn 3744: '<form name="'.$formname.'" method="post" action="">'."\n".
1.11 raeburn 3745: $date_items;
3746: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17 raeburn 3747: my ($cnum,$cdom) = &get_course_identity();
1.103 raeburn 3748: if ($crstype eq 'Community') {
1.118 raeburn 3749: $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.');
3750: $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 3751: $lt{'dnap'} = &mt('(Does not apply to member roles).');
3752: }
1.11 raeburn 3753: my $info;
3754: if ($env{'form.showrole'} eq 'st') {
3755: $output .= '<p>'.$lt{'fors'}.'</p>';
1.26 raeburn 3756: } elsif ($env{'form.showrole'} eq 'Any') {
1.11 raeburn 3757: $output .= '<p>'.$lt{'fors'}.'</p>'.
3758: '<p>'.$lt{'forn'}.' ';
3759: $info = $lt{'reta'};
3760: } else {
3761: $output .= '<p>'.$lt{'forn'}.' ';
3762: $info = $lt{'reta'};
3763: }
3764: if ($info) {
3765: $info .= '<span class="LC_nobreak">'.
3766: '<label><input type="radio" name="retainsec" value="1" '.
3767: 'checked="checked" />'.&mt('Yes').'</label> '.
3768: '<label><input type="radio" name="retainsec" value="0" />'.
3769: &mt('No').'</label></span>';
3770: if ($env{'form.showrole'} eq 'Any') {
3771: $info .= '<br />'.$lt{'dnap'};
3772: }
3773: $info .= '</p>';
3774: } else {
3775: $info = '<input type="hidden" name="retainsec" value="0" />';
3776: }
1.21 raeburn 3777: my $rowtitle = &mt('New section to assign');
1.150 raeburn 3778: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,
3779: $permission,$context,'chgsec',$crstype);
1.11 raeburn 3780: $output .= $info.$secbox;
3781: }
3782: $output .= '<p>'.
1.81 schafran 3783: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
1.11 raeburn 3784: '</form>';
3785: return $output;
3786: }
3787:
1.17 raeburn 3788: sub section_picker {
1.150 raeburn 3789: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype,
3790: $showcredits,$credits) = @_;
1.17 raeburn 3791: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3792: my $sections_select .= &course_sections(\%sections_count,$role);
1.118 raeburn 3793: my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
1.17 raeburn 3794: if ($mode eq 'upload') {
3795: my ($options,$cb_script,$coursepick) =
1.150 raeburn 3796: &default_role_selector($context,1,$crstype,$showcredits);
1.59 bisitz 3797: $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
1.17 raeburn 3798: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
3799: }
3800: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
3801: if ($env{'request.course.sec'} eq '') {
3802: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
3803: '<td align="center">'.&mt('Existing sections')."\n".
3804: '<br />'.$sections_select.'</td><td align="center">'.
3805: &mt('New section').'<br />'."\n".
1.118 raeburn 3806: '<input type="text" name="newsec" size="15" value="" />'."\n".
1.17 raeburn 3807: '<input type="hidden" name="sections" value="" />'."\n".
3808: '</td></tr></table>'."\n";
3809: } else {
1.149 raeburn 3810: $secbox .= '<input type="hidden" name="sections" value="'.
1.17 raeburn 3811: $env{'request.course.sec'}.'" />'.
3812: $env{'request.course.sec'};
3813: }
1.150 raeburn 3814: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n";
3815: unless ($mode eq 'chgsec') {
3816: if ($showcredits) {
3817: $secbox .=
3818: &Apache::lonhtmlcommon::row_title(&mt('credits (students)'),
3819: 'LC_evenrow_value')."\n".
3820: '<input type="text" name="credits" size="3" value="'.$credits.'" />'."\n".
3821: &Apache::lonhtmlcommon::row_closure(1)."\n";
3822: }
3823: }
3824: $secbox .= &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.17 raeburn 3825: return $secbox;
3826: }
3827:
1.2 raeburn 3828: sub results_header_row {
1.102 raeburn 3829: my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
1.5 raeburn 3830: my ($description,$showfilter);
3831: if ($rolefilter ne 'Any') {
3832: $showfilter = $rolefilter;
3833: }
1.2 raeburn 3834: if ($context eq 'course') {
1.24 raeburn 3835: if ($mode eq 'csv' || $mode eq 'excel') {
1.102 raeburn 3836: if ($crstype eq 'Community') {
3837: $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
3838: } else {
3839: $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
3840: }
1.24 raeburn 3841: }
1.2 raeburn 3842: if ($statusmode eq 'Expired') {
1.102 raeburn 3843: if ($crstype eq 'Community') {
3844: $description .= &mt('Users in community with expired [_1] roles',$showfilter);
3845: } else {
3846: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
3847: }
1.11 raeburn 3848: } elsif ($statusmode eq 'Future') {
1.102 raeburn 3849: if ($crstype eq 'Community') {
3850: $description .= &mt('Users in community with future [_1] roles',$showfilter);
3851: } else {
3852: $description .= &mt('Users in course with future [_1] roles',$showfilter);
3853: }
1.2 raeburn 3854: } elsif ($statusmode eq 'Active') {
1.102 raeburn 3855: if ($crstype eq 'Community') {
3856: $description .= &mt('Users in community with active [_1] roles',$showfilter);
3857: } else {
3858: $description .= &mt('Users in course with active [_1] roles',$showfilter);
3859: }
1.2 raeburn 3860: } else {
3861: if ($rolefilter eq 'Any') {
1.102 raeburn 3862: if ($crstype eq 'Community') {
3863: $description .= &mt('All users in community');
3864: } else {
3865: $description .= &mt('All users in course');
3866: }
1.2 raeburn 3867: } else {
1.102 raeburn 3868: if ($crstype eq 'Community') {
3869: $description .= &mt('All users in community with [_1] roles',$rolefilter);
3870: } else {
3871: $description .= &mt('All users in course with [_1] roles',$rolefilter);
3872: }
1.2 raeburn 3873: }
3874: }
1.33 raeburn 3875: my $constraint;
1.26 raeburn 3876: my $viewablesec = &viewable_section($permission);
3877: if ($viewablesec ne '') {
1.15 raeburn 3878: if ($env{'form.showrole'} eq 'st') {
1.33 raeburn 3879: $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.103 raeburn 3880: } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
1.33 raeburn 3881: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
3882: }
3883: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
3884: if ($env{'form.grpfilter'} eq 'none') {
3885: $constraint .= &mt(' and not in any group');
3886: } else {
3887: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
3888: }
3889: }
3890: } else {
3891: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
3892: if ($env{'form.secfilter'} eq 'none') {
3893: $constraint = &mt('only users affiliated with no section');
3894: } else {
3895: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
3896: }
3897: }
3898: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
3899: if ($env{'form.grpfilter'} eq 'none') {
3900: if ($constraint eq '') {
3901: $constraint = &mt('only users not in any group');
3902: } else {
3903: $constraint .= &mt(' and also not in any group');
3904: }
3905: } else {
3906: if ($constraint eq '') {
3907: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
3908: } else {
3909: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
3910: }
3911: }
1.15 raeburn 3912: }
3913: }
1.33 raeburn 3914: if ($constraint ne '') {
3915: $description .= ' ('.$constraint.')';
3916: }
1.13 raeburn 3917: } elsif ($context eq 'author') {
1.14 raeburn 3918: $description =
1.73 bisitz 3919: &mt('Author space for [_1]'
3920: ,'<span class="LC_cusr_emph">'
3921: .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})
3922: .'</span>')
3923: .': ';
1.2 raeburn 3924: if ($statusmode eq 'Expired') {
1.5 raeburn 3925: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 3926: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3927: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 3928: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3929: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 3930: } else {
3931: if ($rolefilter eq 'Any') {
1.5 raeburn 3932: $description .= &mt('All co-authors');
1.2 raeburn 3933: } else {
3934: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
3935: }
3936: }
3937: } elsif ($context eq 'domain') {
3938: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.73 bisitz 3939: $description = &mt('Domain - [_1]:',$domdesc).' ';
1.2 raeburn 3940: if ($env{'form.roletype'} eq 'domain') {
3941: if ($statusmode eq 'Expired') {
1.5 raeburn 3942: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 3943: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3944: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 3945: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3946: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 3947: } else {
3948: if ($rolefilter eq 'Any') {
1.5 raeburn 3949: $description .= &mt('All users in domain');
1.2 raeburn 3950: } else {
3951: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
3952: }
3953: }
1.13 raeburn 3954: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3955: if ($statusmode eq 'Expired') {
1.5 raeburn 3956: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 3957: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3958: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 3959: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3960: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 3961: } else {
3962: if ($rolefilter eq 'Any') {
1.5 raeburn 3963: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 3964: } else {
1.116 bisitz 3965: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
1.2 raeburn 3966: }
3967: }
1.102 raeburn 3968: } elsif (($env{'form.roletype'} eq 'course') ||
3969: ($env{'form.roletype'} eq 'community')) {
1.2 raeburn 3970: my $coursefilter = $env{'form.coursepick'};
1.102 raeburn 3971: if ($env{'form.roletype'} eq 'course') {
3972: if ($coursefilter eq 'category') {
3973: my $instcode = &instcode_from_coursefilter();
3974: if ($instcode eq '.') {
3975: $description .= &mt('All courses in domain').' - ';
3976: } else {
3977: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
3978: }
3979: } elsif ($coursefilter eq 'selected') {
3980: $description .= &mt('Selected courses in domain').' - ';
3981: } elsif ($coursefilter eq 'all') {
1.2 raeburn 3982: $description .= &mt('All courses in domain').' - ';
3983: }
1.102 raeburn 3984: } elsif ($env{'form.roletype'} eq 'community') {
3985: if ($coursefilter eq 'selected') {
3986: $description .= &mt('Selected communities in domain').' - ';
3987: } elsif ($coursefilter eq 'all') {
3988: $description .= &mt('All communities in domain').' - ';
3989: }
1.2 raeburn 3990: }
3991: if ($statusmode eq 'Expired') {
1.5 raeburn 3992: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 3993: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3994: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 3995: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3996: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 3997: } else {
3998: if ($rolefilter eq 'Any') {
3999: $description .= &mt('all users');
4000: } else {
4001: $description .= &mt('users with [_1] roles',$rolefilter);
4002: }
4003: }
4004: }
4005: }
4006: return $description;
4007: }
1.22 raeburn 4008:
4009: sub viewable_section {
4010: my ($permission) = @_;
4011: my $viewablesec;
4012: if (ref($permission) eq 'HASH') {
4013: if (exists($permission->{'view_section'})) {
4014: $viewablesec = $permission->{'view_section'};
4015: } elsif (exists($permission->{'cusr_section'})) {
4016: $viewablesec = $permission->{'cusr_section'};
4017: }
4018: }
4019: return $viewablesec;
4020: }
4021:
1.2 raeburn 4022:
1.1 raeburn 4023: #################################################
4024: #################################################
4025: sub show_drop_list {
1.101 raeburn 4026: my ($r,$classlist,$nosort,$permission,$crstype) = @_;
1.29 raeburn 4027: my $cid = $env{'request.course.id'};
1.17 raeburn 4028: my ($cnum,$cdom) = &get_course_identity($cid);
1.1 raeburn 4029: if (! exists($env{'form.sortby'})) {
4030: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4031: ['sortby']);
4032: }
4033: my $sortby = $env{'form.sortby'};
4034: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
4035: $sortby = 'username';
4036: }
4037: my $action = "drop";
1.17 raeburn 4038: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1 raeburn 4039: $r->print(<<END);
4040: <input type="hidden" name="sortby" value="$sortby" />
4041: <input type="hidden" name="action" value="$action" />
4042: <input type="hidden" name="state" value="done" />
1.17 raeburn 4043: <script type="text/javascript" language="Javascript">
1.96 bisitz 4044: // <![CDATA[
1.17 raeburn 4045: $check_uncheck_js
1.96 bisitz 4046: // ]]>
1.1 raeburn 4047: </script>
1.86 bisitz 4048: <input type="hidden" name="phase" value="four" />
1.1 raeburn 4049: END
1.30 raeburn 4050: my ($indexhash,$keylist) = &make_keylist_array();
4051: my $studentcount = 0;
4052: if (ref($classlist) eq 'HASH') {
4053: foreach my $student (keys(%{$classlist})) {
4054: my $sdata = $classlist->{$student};
4055: my $status = $sdata->[$indexhash->{'status'}];
4056: my $section = $sdata->[$indexhash->{'section'}];
4057: if ($status ne 'Active') {
4058: delete($classlist->{$student});
4059: next;
4060: }
4061: if ($env{'request.course.sec'} ne '') {
4062: if ($section ne $env{'request.course.sec'}) {
4063: delete($classlist->{$student});
4064: next;
4065: }
4066: }
4067: $studentcount ++;
4068: }
4069: }
4070: if (!$studentcount) {
1.143 bisitz 4071: my $msg = '';
1.101 raeburn 4072: if ($crstype eq 'Community') {
1.143 bisitz 4073: $msg = &mt('There are no members to drop.');
1.101 raeburn 4074: } else {
1.143 bisitz 4075: $msg = &mt('There are no students to drop.');
1.101 raeburn 4076: }
1.143 bisitz 4077: $r->print('<p class="LC_info">'.$msg.'</p>');
1.30 raeburn 4078: return;
4079: }
4080: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
4081: $classlist,$keylist,$cdom,$cnum);
4082: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
4083: 'dom' => "domain",
1.162 bisitz 4084: 'id' => "ID",
1.30 raeburn 4085: 'sn' => "student name",
1.101 raeburn 4086: 'mn' => "member name",
1.30 raeburn 4087: 'sec' => "section",
4088: 'start' => "start date",
4089: 'end' => "end date",
4090: 'groups' => "active groups",
4091: );
1.101 raeburn 4092: my $nametitle = $lt{'sn'};
4093: if ($crstype eq 'Community') {
4094: $nametitle = $lt{'mn'};
4095: }
1.1 raeburn 4096: if ($nosort) {
1.17 raeburn 4097: $r->print(&Apache::loncommon::start_data_table().
4098: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4099: $r->print(<<END);
4100: <th> </th>
4101: <th>$lt{'usrn'}</th>
4102: <th>$lt{'dom'}</th>
1.162 bisitz 4103: <th>$lt{'id'}</th>
1.101 raeburn 4104: <th>$nametitle</th>
1.1 raeburn 4105: <th>$lt{'sec'}</th>
4106: <th>$lt{'start'}</th>
4107: <th>$lt{'end'}</th>
4108: <th>$lt{'groups'}</th>
4109: END
1.17 raeburn 4110: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4111: } else {
1.17 raeburn 4112: $r->print(&Apache::loncommon::start_data_table().
4113: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 4114: $r->print(<<END);
1.17 raeburn 4115: <th> </th>
1.1 raeburn 4116: <th>
1.162 bisitz 4117: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1 raeburn 4118: </th><th>
1.162 bisitz 4119: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1 raeburn 4120: </th><th>
1.162 bisitz 4121: <a href="/adm/createuser?action=$action&sortby=id">$lt{'id'}</a>
1.1 raeburn 4122: </th><th>
1.162 bisitz 4123: <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
1.1 raeburn 4124: </th><th>
1.162 bisitz 4125: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1 raeburn 4126: </th><th>
1.162 bisitz 4127: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1 raeburn 4128: </th><th>
1.162 bisitz 4129: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1 raeburn 4130: </th><th>
1.162 bisitz 4131: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1 raeburn 4132: </th>
4133: END
1.17 raeburn 4134: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 4135: }
4136: #
4137: # Sort the students
1.30 raeburn 4138: my $index = $indexhash->{$sortby};
4139: my $second = $indexhash->{'username'};
4140: my $third = $indexhash->{'domain'};
1.1 raeburn 4141: my @Sorted_Students = sort {
4142: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
4143: ||
4144: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
4145: ||
4146: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30 raeburn 4147: } (keys(%{$classlist}));
1.1 raeburn 4148: foreach my $student (@Sorted_Students) {
4149: my $error;
4150: my $sdata = $classlist->{$student};
1.30 raeburn 4151: my $username = $sdata->[$indexhash->{'username'}];
4152: my $domain = $sdata->[$indexhash->{'domain'}];
4153: my $section = $sdata->[$indexhash->{'section'}];
4154: my $name = $sdata->[$indexhash->{'fullname'}];
4155: my $id = $sdata->[$indexhash->{'id'}];
4156: my $start = $sdata->[$indexhash->{'start'}];
4157: my $end = $sdata->[$indexhash->{'end'}];
1.1 raeburn 4158: my $groups = $classgroups->{$student};
4159: my $active_groups;
4160: if (ref($groups->{active}) eq 'HASH') {
4161: $active_groups = join(', ',keys(%{$groups->{'active'}}));
4162: }
4163: if (! defined($start) || $start == 0) {
4164: $start = &mt('none');
4165: } else {
4166: $start = &Apache::lonlocal::locallocaltime($start);
4167: }
4168: if (! defined($end) || $end == 0) {
4169: $end = &mt('none');
4170: } else {
4171: $end = &Apache::lonlocal::locallocaltime($end);
4172: }
1.17 raeburn 4173: my $studentkey = $student.':'.$section;
1.30 raeburn 4174: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1 raeburn 4175: #
4176: $r->print(&Apache::loncommon::start_data_table_row());
4177: $r->print(<<"END");
1.86 bisitz 4178: <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
1.1 raeburn 4179: <td>$username</td>
4180: <td>$domain</td>
4181: <td>$id</td>
4182: <td>$name</td>
4183: <td>$section</td>
1.29 raeburn 4184: <td>$start $startitem</td>
1.1 raeburn 4185: <td>$end</td>
4186: <td>$active_groups</td>
4187: END
4188: $r->print(&Apache::loncommon::end_data_table_row());
4189: }
4190: $r->print(&Apache::loncommon::end_data_table().'<br />');
4191: %lt=&Apache::lonlocal::texthash(
1.29 raeburn 4192: 'dp' => "Drop Students",
1.101 raeburn 4193: 'dm' => "Drop Members",
1.1 raeburn 4194: 'ca' => "check all",
4195: 'ua' => "uncheck all",
4196: );
1.101 raeburn 4197: my $btn = $lt{'dp'};
4198: if ($crstype eq 'Community') {
4199: $btn = $lt{'dm'};
4200: }
1.1 raeburn 4201: $r->print(<<"END");
1.89 bisitz 4202: <p>
1.86 bisitz 4203: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" />
4204: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
1.89 bisitz 4205: </p>
4206: <p>
1.101 raeburn 4207: <input type="submit" value="$btn" />
1.89 bisitz 4208: </p>
1.1 raeburn 4209: END
4210: return;
4211: }
4212:
4213: #
4214: # Print out the initial form to get the file containing a list of users
4215: #
4216: sub print_first_users_upload_form {
4217: my ($r,$context) = @_;
4218: my $str;
1.86 bisitz 4219: $str = '<input type="hidden" name="phase" value="two" />';
1.1 raeburn 4220: $str .= '<input type="hidden" name="action" value="upload" />';
1.101 raeburn 4221: $str .= '<input type="hidden" name="state" value="got_file" />';
1.95 bisitz 4222:
1.147 bisitz 4223: $str .= &Apache::grades::checkforfile_js();
4224:
1.85 bisitz 4225: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
1.95 bisitz 4226:
4227: # Excel and CSV Help
1.147 bisitz 4228: $str .= '<div class="LC_columnSection">'
1.95 bisitz 4229: .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
4230: &mt("How do I create a users list from a spreadsheet"))
1.147 bisitz 4231: .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.95 bisitz 4232: &mt("How do I create a CSV file from a spreadsheet"))
1.147 bisitz 4233: ."</div>\n";
1.95 bisitz 4234: $str .= &Apache::lonhtmlcommon::start_pick_box()
1.103 raeburn 4235: .&Apache::lonhtmlcommon::row_title(&mt('File'));
4236: if (&Apache::lonlocal::current_language() ne 'en') {
4237: if ($context eq 'course') {
4238: $str .= '<p class="LC_info">'."\n"
4239: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
4240: .'</p>'."\n";
4241: }
4242: }
4243: $str .= &Apache::loncommon::upfile_select_html()
1.95 bisitz 4244: .&Apache::lonhtmlcommon::row_closure()
4245: .&Apache::lonhtmlcommon::row_title(
4246: '<label for="noFirstLine">'
4247: .&mt('Ignore First Line')
4248: .'</label>')
4249: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
4250: .&Apache::lonhtmlcommon::row_closure(1)
4251: .&Apache::lonhtmlcommon::end_pick_box();
4252:
4253: $str .= '<p>'
1.147 bisitz 4254: .'<input type="submit" name="fileupload" value="'.&mt('Next').'"'
4255: .' onclick="javascript:checkUpload(this.form);" />'
1.95 bisitz 4256: .'</p>';
4257:
1.1 raeburn 4258: $r->print($str);
4259: return;
4260: }
4261:
4262: # ================================================= Drop/Add from uploaded file
4263: sub upfile_drop_add {
1.150 raeburn 4264: my ($r,$context,$permission,$showcredits) = @_;
1.189 raeburn 4265: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4266: if ($datatoken ne '') {
4267: &Apache::loncommon::load_tmp_file($r,$datatoken);
4268: }
1.1 raeburn 4269: my @userdata=&Apache::loncommon::upfile_record_sep();
4270: if($env{'form.noFirstLine'}){shift(@userdata);}
4271: my @keyfields = split(/\,/,$env{'form.keyfields'});
4272: my %fields=();
4273: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4274: if ($env{'form.upfile_associate'} eq 'reverse') {
4275: if ($env{'form.f'.$i} ne 'none') {
4276: $fields{$keyfields[$i]}=$env{'form.f'.$i};
4277: }
4278: } else {
4279: $fields{$env{'form.f'.$i}}=$keyfields[$i];
4280: }
4281: }
4282: #
4283: # Store the field choices away
1.150 raeburn 4284: my @storefields = qw/username names fname mname lname gen id
4285: sec ipwd email role domain inststatus/;
4286: if ($showcredits) {
4287: push (@storefields,'credits');
4288: }
4289: my %fieldstype;
4290: foreach my $field (@storefields) {
1.1 raeburn 4291: $env{'form.'.$field.'_choice'}=$fields{$field};
1.150 raeburn 4292: $fieldstype{$field.'_choice'} = 'scalar';
1.1 raeburn 4293: }
1.150 raeburn 4294: &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
1.185 raeburn 4295: my ($cid,$crstype,$setting,$crsdom);
1.101 raeburn 4296: if ($context eq 'domain') {
4297: $setting = $env{'form.roleaction'};
4298: }
4299: if ($env{'request.course.id'} ne '') {
4300: $cid = $env{'request.course.id'};
4301: $crstype = &Apache::loncommon::course_type();
1.185 raeburn 4302: $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.101 raeburn 4303: } elsif ($setting eq 'course') {
4304: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
4305: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
4306: $crstype = &Apache::loncommon::course_type($cid);
1.185 raeburn 4307: $crsdom = $env{'form.dcdomain'};
1.101 raeburn 4308: }
4309: }
1.1 raeburn 4310: my ($startdate,$enddate) = &get_dates_from_form();
4311: if ($env{'form.makedatesdefault'}) {
1.101 raeburn 4312: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 4313: }
4314: # Determine domain and desired host (home server)
1.57 raeburn 4315: my $defdom=$env{'request.role.domain'};
4316: my $domain;
4317: if ($env{'form.defaultdomain'} ne '') {
1.185 raeburn 4318: if (($context eq 'course') || ($setting eq 'course')) {
1.190 raeburn 4319: if ($env{'form.defaultdomain'} eq $crsdom) {
4320: $domain = $env{'form.defaultdomain'};
4321: } else {
1.185 raeburn 4322: if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
4323: $domain = $env{'form.defaultdomain'};
4324: } else {
1.192 raeburn 4325: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4326: &mt('Enrollment of users not permitted for specified default domain: [_1].',
4327: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4328: return 'untrusted';
1.185 raeburn 4329: }
4330: }
4331: } elsif ($context eq 'author') {
1.190 raeburn 4332: if ($env{'form.defaultdomain'} eq $defdom) {
4333: $domain = $env{'form.defaultdomain'};
4334: } else {
1.185 raeburn 4335: if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
1.186 raeburn 4336: (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
1.185 raeburn 4337: $domain = $env{'form.defaultdomain'};
4338: } else {
1.192 raeburn 4339: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4340: &mt('Addition of users not permitted for specified default domain: [_1].',
4341: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4342: return 'untrusted';
1.185 raeburn 4343: }
4344: }
4345: } elsif (($context eq 'domain') && ($setting eq 'domain')) {
1.190 raeburn 4346: if ($env{'form.defaultdomain'} eq $defdom) {
4347: $domain = $env{'form.defaultdomain'};
4348: } else {
1.185 raeburn 4349: if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
4350: $domain = $env{'form.defaultdomain'};
4351: } else {
1.192 raeburn 4352: $r->print('<span class="LC_error">'.&mt('Error').': '.
1.185 raeburn 4353: &mt('Addition of users not permitted for specified default domain: [_1].',
4354: &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
1.193 raeburn 4355: return 'untrusted';
1.185 raeburn 4356: }
4357: }
4358: }
1.57 raeburn 4359: } else {
4360: $domain = $defdom;
4361: }
1.1 raeburn 4362: my $desiredhost = $env{'form.lcserver'};
4363: if (lc($desiredhost) eq 'default') {
4364: $desiredhost = undef;
4365: } else {
1.57 raeburn 4366: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1 raeburn 4367: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 4368: $r->print('<p class="LC_error">'.&mt('Error').': '.
4369: &mt('Invalid home server specified').'</p>');
4370: return 'invalidhome';
1.1 raeburn 4371: }
4372: }
4373: # Determine authentication mechanism
4374: my $changeauth;
4375: if ($context eq 'domain') {
4376: $changeauth = $env{'form.changeauth'};
4377: }
4378: my $amode = '';
4379: my $genpwd = '';
4380: if ($env{'form.login'} eq 'krb') {
4381: $amode='krb';
4382: $amode.=$env{'form.krbver'};
4383: $genpwd=$env{'form.krbarg'};
4384: } elsif ($env{'form.login'} eq 'int') {
4385: $amode='internal';
4386: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
4387: $genpwd=$env{'form.intarg'};
4388: }
4389: } elsif ($env{'form.login'} eq 'loc') {
4390: $amode='localauth';
4391: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
4392: $genpwd=$env{'form.locarg'};
4393: }
1.194 raeburn 4394: } elsif ($env{'form.login'} eq 'lti') {
4395: $amode='lti';
1.1 raeburn 4396: }
4397: if ($amode =~ /^krb/) {
4398: if (! defined($genpwd) || $genpwd eq '') {
1.193 raeburn 4399: $r->print('<span class="Error">'.
1.1 raeburn 4400: &mt('Unable to enroll users').' '.
4401: &mt('No Kerberos domain was specified.').'</span></p>');
4402: $amode = ''; # This causes the loop below to be skipped
4403: }
4404: }
1.150 raeburn 4405: my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
1.1 raeburn 4406: if ($context eq 'domain') {
4407: if ($setting eq 'domain') {
4408: $defaultrole = $env{'form.defaultrole'};
4409: } elsif ($setting eq 'course') {
4410: $defaultrole = $env{'form.courserole'};
1.27 raeburn 4411: $defaultsec = $env{'form.sections'};
1.150 raeburn 4412: if ($showcredits) {
4413: $commoncredits = $env{'form.credits'};
4414: if ($crstype ne 'Community') {
4415: my %coursehash=&Apache::lonnet::coursedescription($cid);
4416: $defaultcredits = $coursehash{'internal.defaultcredits'};
4417: }
4418: }
1.149 raeburn 4419: }
1.13 raeburn 4420: } elsif ($context eq 'author') {
1.1 raeburn 4421: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 4422: } elsif ($context eq 'course') {
4423: $defaultrole = $env{'form.defaultrole'};
4424: $defaultsec = $env{'form.sections'};
1.150 raeburn 4425: if ($showcredits) {
4426: $commoncredits = $env{'form.credits'};
4427: $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
4428: }
1.1 raeburn 4429: }
1.27 raeburn 4430: # Check to see if user information can be changed
4431: my @userinfo = ('firstname','middlename','lastname','generation',
4432: 'permanentemail','id');
4433: my %canmodify;
4434: if (&Apache::lonnet::allowed('mau',$domain)) {
1.84 raeburn 4435: push(@userinfo,'inststatus');
1.27 raeburn 4436: foreach my $field (@userinfo) {
4437: $canmodify{$field} = 1;
4438: }
4439: }
4440: my (%userlist,%modifiable_fields,@poss_roles);
4441: my $secidx = &Apache::loncoursedata::CL_SECTION();
1.102 raeburn 4442: my @courseroles = &roles_by_context('course',1,$crstype);
1.27 raeburn 4443: if (!&Apache::lonnet::allowed('mau',$domain)) {
4444: if ($context eq 'course' || $context eq 'author') {
1.101 raeburn 4445: @poss_roles = &curr_role_permissions($context,'','',$crstype);
1.27 raeburn 4446: my @statuses = ('active','future');
4447: my ($indexhash,$keylist) = &make_keylist_array();
4448: my %info;
4449: foreach my $role (@poss_roles) {
4450: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
4451: \@userinfo,[$role]);
4452: }
4453: if ($context eq 'course') {
4454: my ($cnum,$cdom) = &get_course_identity();
4455: my $roster = &Apache::loncoursedata::get_classlist();
1.66 raeburn 4456: if (ref($roster) eq 'HASH') {
4457: %userlist = %{$roster};
4458: }
1.27 raeburn 4459: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
4460: \@statuses,\@poss_roles);
4461: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4462: \%advrolehash,$permission);
4463: } elsif ($context eq 'author') {
4464: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
4465: \@statuses,\@poss_roles);
4466: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
4467: \%cstr_roles,$permission);
4468:
4469: }
4470: }
1.1 raeburn 4471: }
1.193 raeburn 4472: if ($datatoken eq '') {
4473: $r->print('<p class="LC_error">'.&mt('Error').': '.
4474: &mt('Invalid datatoken').'</p>');
4475: return 'missingdata';
4476: }
1.1 raeburn 4477: if ( $domain eq &LONCAPA::clean_domain($domain)
4478: && ($amode ne '')) {
4479: #######################################
4480: ## Add/Modify Users ##
4481: #######################################
4482: if ($context eq 'course') {
4483: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 4484: } elsif ($context eq 'author') {
1.1 raeburn 4485: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
4486: } else {
4487: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
4488: }
1.87 bisitz 4489: $r->rflush;
4490:
1.1 raeburn 4491: my %counts = (
4492: user => 0,
4493: auth => 0,
4494: role => 0,
4495: );
4496: my $flushc=0;
4497: my %student=();
1.42 raeburn 4498: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 4499: my %userchg;
1.27 raeburn 4500: if ($context eq 'course' || $setting eq 'course') {
4501: if ($context eq 'course') {
4502: # Get information about course groups
4503: %curr_groups = &Apache::longroup::coursegroups();
4504: } elsif ($setting eq 'course') {
4505: if ($cid) {
4506: %curr_groups =
4507: &Apache::longroup::coursegroups($env{'form.dcdomain'},
4508: $env{'form.dccourse'});
4509: }
4510: }
4511: # determine section number
4512: if ($defaultsec =~ /,/) {
4513: push(@sections,split(/,/,$defaultsec));
4514: } else {
4515: push(@sections,$defaultsec);
4516: }
4517: # remove non alphanumeric values from section
4518: foreach my $item (@sections) {
4519: $item =~ s/\W//g;
4520: if ($item eq "none" || $item eq 'all') {
4521: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
4522: } elsif ($item ne '' && exists($curr_groups{$item})) {
4523: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
4524: } elsif ($item ne '') {
4525: push(@cleansec,$item);
4526: }
4527: }
4528: if ($defaultwarn) {
4529: $r->print($defaultwarn.'<br />');
4530: }
4531: if ($groupwarn) {
4532: $r->print($groupwarn.'<br />');
4533: }
1.1 raeburn 4534: }
1.124 raeburn 4535: my (%curr_rules,%got_rules,%alerts,%cancreate);
1.104 raeburn 4536: my %customroles = &my_custom_roles($crstype);
1.101 raeburn 4537: my @permitted_roles =
1.124 raeburn 4538: &roles_on_upload($context,$setting,$crstype,%customroles);
4539: my %longtypes = &Apache::lonlocal::texthash(
4540: official => 'Institutional',
4541: unofficial => 'Non-institutional',
4542: );
1.135 raeburn 4543: my $newuserdom = $env{'request.role.domain'};
4544: map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
1.1 raeburn 4545: # Get new users list
1.172 raeburn 4546: my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname);
1.171 raeburn 4547: my $counter = -1;
1.185 raeburn 4548: my (%willtrust,%trustchecked);
1.27 raeburn 4549: foreach my $line (@userdata) {
1.171 raeburn 4550: $counter ++;
1.42 raeburn 4551: my @secs;
1.27 raeburn 4552: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 4553: # Determine user name
1.128 raeburn 4554: $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 4555: unless (($entries{$fields{'username'}} eq '') ||
4556: (!defined($entries{$fields{'username'}}))) {
4557: my ($fname, $mname, $lname,$gen) = ('','','','');
4558: if (defined($fields{'names'})) {
4559: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
4560: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
4561: } else {
4562: if (defined($fields{'fname'})) {
4563: $fname=$entries{$fields{'fname'}};
4564: }
4565: if (defined($fields{'mname'})) {
4566: $mname=$entries{$fields{'mname'}};
4567: }
4568: if (defined($fields{'lname'})) {
4569: $lname=$entries{$fields{'lname'}};
4570: }
4571: if (defined($fields{'gen'})) {
4572: $gen=$entries{$fields{'gen'}};
4573: }
4574: }
1.128 raeburn 4575:
1.1 raeburn 4576: if ($entries{$fields{'username'}}
4577: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
1.128 raeburn 4578: my $nowhitespace;
4579: if ($entries{$fields{'username'}} =~ /\s/) {
4580: $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
4581: }
1.171 raeburn 4582: $disallow{$counter} =
1.157 bisitz 4583: &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 4584: '"<b>'.$entries{$fields{'username'}}.'</b>"',
4585: $fname,$mname,$lname,$gen).$nowhitespace;
1.27 raeburn 4586: next;
1.1 raeburn 4587: } else {
1.129 raeburn 4588: $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
1.71 droeschl 4589: if ($entries{$fields{'domain'}}
1.57 raeburn 4590: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
1.171 raeburn 4591: $disallow{$counter} =
1.157 bisitz 4592: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
1.171 raeburn 4593: '"<b>'.$entries{$fields{'domain'}}.'</b>"',
4594: $fname,$mname,$lname,$gen);
4595: next;
1.185 raeburn 4596: } elsif ($entries{$fields{'domain'}} ne $domain) {
4597: my $possdom = $entries{$fields{'domain'}};
4598: if ($context eq 'course' || $setting eq 'course') {
4599: unless ($trustchecked{$possdom}) {
4600: $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
4601: $trustchecked{$possdom} = 1;
4602: }
4603: } elsif ($context eq 'author') {
4604: unless ($trustchecked{$possdom}) {
4605: $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
4606: }
4607: if ($willtrust{$possdom}) {
4608: $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
4609: }
4610: }
4611: unless ($willtrust{$possdom}) {
4612: $disallow{$counter} =
4613: &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
4614: '"<b>'.$possdom.'</b>"',
4615: $fname,$mname,$lname,$gen);
4616: next;
4617: }
1.57 raeburn 4618: }
1.5 raeburn 4619: my $username = $entries{$fields{'username'}};
1.57 raeburn 4620: my $userdomain = $entries{$fields{'domain'}};
4621: if ($userdomain eq '') {
4622: $userdomain = $domain;
4623: }
1.27 raeburn 4624: if (defined($fields{'sec'})) {
4625: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 4626: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 4627: my $item = $entries{$fields{'sec'}};
4628: if ($item eq "none" || $item eq 'all') {
1.171 raeburn 4629: $disallow{$counter} =
4630: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
4631: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item);
1.27 raeburn 4632: next;
4633: } elsif (exists($curr_groups{$item})) {
1.171 raeburn 4634: $disallow{$counter} =
4635: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
4636: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.
4637: &mt('Section names and group names must be distinct.');
1.27 raeburn 4638: next;
4639: } else {
4640: push(@secs,$item);
4641: }
4642: }
4643: }
4644: if ($env{'request.course.sec'} ne '') {
4645: @secs = ($env{'request.course.sec'});
1.57 raeburn 4646: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
4647: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27 raeburn 4648: if ($currsec ne $env{'request.course.sec'}) {
1.171 raeburn 4649: $disallow{$counter} =
4650: &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
4651: '<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]);
1.27 raeburn 4652: if ($currsec eq '') {
1.171 raeburn 4653: $disallow{$counter} .=
4654: &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
1.27 raeburn 4655:
4656: } else {
1.171 raeburn 4657: $disallow{$counter} .=
4658: &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
1.27 raeburn 4659: }
1.171 raeburn 4660: $disallow{$counter} .=
4661: '<br />'.
4662: &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.',
4663: $secs[0]);
1.27 raeburn 4664: next;
1.1 raeburn 4665: }
4666: }
1.27 raeburn 4667: } elsif ($context eq 'course' || $setting eq 'course') {
4668: if (@secs == 0) {
4669: @secs = @cleansec;
1.1 raeburn 4670: }
4671: }
4672: # determine id number
4673: my $id='';
4674: if (defined($fields{'id'})) {
4675: if (defined($entries{$fields{'id'}})) {
4676: $id=$entries{$fields{'id'}};
4677: }
4678: $id=~tr/A-Z/a-z/;
4679: }
4680: # determine email address
4681: my $email='';
4682: if (defined($fields{'email'})) {
1.129 raeburn 4683: $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
1.1 raeburn 4684: if (defined($entries{$fields{'email'}})) {
4685: $email=$entries{$fields{'email'}};
1.84 raeburn 4686: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
4687: }
4688: }
4689: # determine affiliation
4690: my $inststatus='';
4691: if (defined($fields{'inststatus'})) {
4692: if (defined($entries{$fields{'inststatus'}})) {
4693: $inststatus=$entries{$fields{'inststatus'}};
4694: }
1.1 raeburn 4695: }
4696: # determine user password
4697: my $password = $genpwd;
4698: if (defined($fields{'ipwd'})) {
4699: if ($entries{$fields{'ipwd'}}) {
4700: $password=$entries{$fields{'ipwd'}};
4701: }
4702: }
4703: # determine user role
4704: my $role = '';
4705: if (defined($fields{'role'})) {
4706: if ($entries{$fields{'role'}}) {
1.42 raeburn 4707: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
4708: if ($entries{$fields{'role'}} ne '') {
4709: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
4710: $role = $entries{$fields{'role'}};
1.27 raeburn 4711: }
4712: }
4713: if ($role eq '') {
4714: my $rolestr = join(', ',@permitted_roles);
1.171 raeburn 4715: $disallow{$counter} =
4716: &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
4717: ,'<b>'.$entries{$fields{'username'}}.'</b>'
4718: ,$entries{$fields{'role'}})
4719: .'<br />'
4720: .&mt('Allowable role(s) is/are: [_1].',$rolestr);
1.1 raeburn 4721: next;
4722: }
4723: }
4724: }
4725: if ($role eq '') {
4726: $role = $defaultrole;
4727: }
4728: # Clean up whitespace
1.129 raeburn 4729: foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
1.1 raeburn 4730: $$_ =~ s/(\s+$|^\s+)//g;
4731: }
1.150 raeburn 4732: my $credits;
4733: if ($showcredits) {
4734: if (($role eq 'st') && ($crstype ne 'Community')) {
4735: $credits = $entries{$fields{'credits'}};
4736: if ($credits ne '') {
4737: $credits =~ s/[^\d\.]//g;
4738: }
4739: if ($credits eq '') {
4740: $credits = $commoncredits;
4741: }
4742: if ($credits eq $defaultcredits) {
4743: undef($credits);
4744: }
4745: }
4746: }
1.5 raeburn 4747: # check against rules
4748: my $checkid = 0;
4749: my $newuser = 0;
1.57 raeburn 4750: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5 raeburn 4751: if ($uhome eq 'no_host') {
1.135 raeburn 4752: if ($userdomain ne $newuserdom) {
4753: if ($context eq 'course') {
1.171 raeburn 4754: $disallow{$counter} =
4755: &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
4756: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 4757: } elsif ($context eq 'author') {
1.171 raeburn 4758: $disallow{$counter} =
4759: &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
4760: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 4761: } else {
1.171 raeburn 4762: $disallow{$counter} =
4763: &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
4764: '<b>'.$username.'</b>',$userdomain);
1.135 raeburn 4765: }
1.171 raeburn 4766: $disallow{$counter} .=
4767: &mt('The user does not already exist, and you may not create a new user in a different domain.');
1.124 raeburn 4768: next;
1.171 raeburn 4769: } else {
1.194 raeburn 4770: unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
1.171 raeburn 4771: $disallow{$counter} =
4772: &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
4773: '<b>'.$username.'</b>');
4774: next;
4775: }
1.124 raeburn 4776: }
1.5 raeburn 4777: $checkid = 1;
4778: $newuser = 1;
1.172 raeburn 4779: $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
1.13 raeburn 4780: } else {
1.27 raeburn 4781: if ($context eq 'course' || $context eq 'author') {
1.57 raeburn 4782: if ($userdomain eq $domain ) {
4783: if ($role eq '') {
4784: my @checkroles;
4785: foreach my $role (@poss_roles) {
4786: my $endkey;
4787: if ($role ne 'st') {
4788: $endkey = ':'.$role;
4789: }
4790: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
4791: if (!grep(/^\Q$role\E$/,@checkroles)) {
4792: push(@checkroles,$role);
4793: }
4794: }
1.27 raeburn 4795: }
1.57 raeburn 4796: if (@checkroles > 0) {
4797: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27 raeburn 4798: }
1.57 raeburn 4799: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
4800: %canmodify = %{$modifiable_fields{$role}};
1.27 raeburn 4801: }
4802: }
1.57 raeburn 4803: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84 raeburn 4804: for (my $i=0; $i<@newinfo; $i++) {
1.57 raeburn 4805: if (${$newinfo[$i]} ne '') {
4806: if (!$canmodify{$userinfo[$i]}) {
4807: ${$newinfo[$i]} = '';
4808: }
1.27 raeburn 4809: }
4810: }
4811: }
1.171 raeburn 4812: if ($id) {
4813: $existinguser{$userdomain}{$username} = $id;
4814: }
1.5 raeburn 4815: }
1.171 raeburn 4816: $userinfo{$counter} = {
4817: username => $username,
4818: domain => $userdomain,
4819: fname => $fname,
4820: mname => $mname,
4821: lname => $lname,
4822: gen => $gen,
4823: email => $email,
4824: id => $id,
4825: password => $password,
4826: inststatus => $inststatus,
4827: role => $role,
4828: sections => \@secs,
4829: credits => $credits,
4830: newuser => $newuser,
4831: checkid => $checkid,
4832: };
4833: }
4834: }
4835: } # end of foreach (@userdata)
4836: if ($counter > -1) {
4837: my $total = $counter + 1;
4838: my %checkids;
1.172 raeburn 4839: if ((keys(%existinguser)) || (keys(%checkuname))) {
4840: $r->print(&mt('Please be patient -- checking for institutional data ...'));
4841: $r->rflush();
4842: if (keys(%existinguser)) {
4843: foreach my $dom (keys(%existinguser)) {
4844: if (ref($existinguser{$dom}) eq 'HASH') {
4845: my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
4846: foreach my $username (keys(%{$existinguser{$dom}})) {
4847: if ($idhash{$username} ne $existinguser{$dom}{$username}) {
4848: $checkids{$username.':'.$dom} = {
4849: 'id' => $existinguser{$dom}{$username},
4850: };
4851: }
4852: }
4853: if (keys(%checkids)) {
4854: &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
4855: \%alerts,\%rulematch,
4856: \%inst_results,\%curr_rules,
4857: \%got_rules);
1.171 raeburn 4858: }
4859: }
4860: }
4861: }
1.172 raeburn 4862: if (keys(%checkuname)) {
4863: &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
4864: \%alerts,\%rulematch,\%inst_results,
4865: \%curr_rules,\%got_rules);
4866: }
4867: $r->print(' '.&mt('done').'<br /><br />');
4868: $r->rflush();
1.171 raeburn 4869: }
1.172 raeburn 4870: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
1.171 raeburn 4871: $r->print('<ul>');
4872: for (my $i=0; $i<=$counter; $i++) {
4873: if ($disallow{$i}) {
4874: $r->print('<li>'.$disallow{$i}.'</li>');
4875: } elsif (ref($userinfo{$i}) eq 'HASH') {
4876: my $password = $userinfo{$i}{'password'};
4877: my $newuser = $userinfo{$i}{'newuser'};
4878: my $checkid = $userinfo{$i}{'checkid'};
4879: my $id = $userinfo{$i}{'id'};
4880: my $role = $userinfo{$i}{'role'};
4881: my @secs;
4882: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
4883: @secs = @{$userinfo{$i}{'sections'}};
4884: }
4885: my $fname = $userinfo{$i}{'fname'};
4886: my $mname = $userinfo{$i}{'mname'};
4887: my $lname = $userinfo{$i}{'lname'};
4888: my $gen = $userinfo{$i}{'gen'};
4889: my $email = $userinfo{$i}{'email'};
4890: my $inststatus = $userinfo{$i}{'inststatus'};
4891: my $credits = $userinfo{$i}{'credits'};
4892: my $username = $userinfo{$i}{'username'};
4893: my $userdomain = $userinfo{$i}{'domain'};
4894: my $user = $username.':'.$userdomain;
4895: if ($newuser) {
4896: if (ref($alerts{'username'}) eq 'HASH') {
4897: if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
4898: if ($alerts{'username'}{$userdomain}{$username}) {
4899: $r->print('<li>'.
4900: &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
4901: &mt('Consequently, the user was not created.').'</li>');
4902: next;
4903: }
4904: }
4905: }
1.172 raeburn 4906: if (ref($inst_results{$user}) eq 'HASH') {
4907: if ($inst_results{$user}{'firstname'} ne '') {
4908: $fname = $inst_results{$user}{'firstname'};
4909: }
4910: if ($inst_results{$user}{'middlename'} ne '') {
4911: $mname = $inst_results{$user}{'middlename'};
4912: }
4913: if ($inst_results{$user}{'lasttname'} ne '') {
4914: $lname = $inst_results{$user}{'lastname'};
4915: }
4916: if ($inst_results{$user}{'permanentemail'} ne '') {
4917: $email = $inst_results{$user}{'permanentemail'};
4918: }
4919: if ($inst_results{$user}{'id'} ne '') {
4920: $id = $inst_results{$user}{'id'};
4921: $checkid = 0;
4922: }
4923: if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
4924: $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
4925: }
4926: }
4927: if (($checkid) && ($id ne '')) {
4928: if (ref($alerts{'id'}) eq 'HASH') {
4929: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
4930: if ($alerts{'id'}{$userdomain}{$username}) {
4931: $r->print('<li>'.
4932: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
4933: '<b>'.$username.'</b>').'<br />'.
4934: &mt('Consequently, the user was not created.').'</li>');
4935: next;
4936: }
4937: }
4938: }
4939: }
1.171 raeburn 4940: my $usertype = 'unofficial';
4941: if (ref($rulematch{$user}) eq 'HASH') {
4942: if ($rulematch{$user}{'username'}) {
4943: $usertype = 'official';
1.5 raeburn 4944: }
4945: }
1.171 raeburn 4946: unless ($cancreate{$usertype}) {
4947: my $showtype = $longtypes{$usertype};
4948: $r->print('<li>'.
4949: &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
4950: next;
4951: }
1.172 raeburn 4952: } elsif ($id ne '') {
1.171 raeburn 4953: if (exists($checkids{$user})) {
4954: $checkid = 1;
1.5 raeburn 4955: if (ref($alerts{'id'}) eq 'HASH') {
1.57 raeburn 4956: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
1.172 raeburn 4957: if ($alerts{'id'}{$userdomain}{$username}) {
1.171 raeburn 4958: $r->print('<li>'.
1.172 raeburn 4959: &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
1.124 raeburn 4960: '<b>'.$username.'</b>').'<br />'.
1.172 raeburn 4961: &mt('Consequently, the ID was not changed.').'</li>');
4962: $id = '';
1.124 raeburn 4963: }
1.5 raeburn 4964: }
4965: }
4966: }
4967: }
1.171 raeburn 4968: my $multiple = 0;
4969: my ($userresult,$authresult,$roleresult,$idresult);
4970: my (%userres,%authres,%roleres,%idres);
4971: my $singlesec = '';
4972: if ($role eq 'st') {
4973: my $sec;
4974: if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
1.42 raeburn 4975: if (@secs > 0) {
4976: $sec = $secs[0];
1.27 raeburn 4977: }
1.171 raeburn 4978: }
4979: &modifystudent($userdomain,$username,$cid,$sec,
4980: $desiredhost,$context);
4981: $roleresult =
4982: &Apache::lonnet::modifystudent
4983: ($userdomain,$username,$id,$amode,$password,
4984: $fname,$mname,$lname,$gen,$sec,$enddate,
4985: $startdate,$env{'form.forceid'},
4986: $desiredhost,$email,'manual','',$cid,
4987: '',$context,$inststatus,$credits);
4988: $userresult = $roleresult;
4989: } else {
4990: if ($role ne '') {
4991: if ($context eq 'course' || $setting eq 'course') {
4992: if ($customroles{$role}) {
4993: $role = 'cr_'.$env{'user.domain'}.'_'.
4994: $env{'user.name'}.'_'.$role;
4995: }
4996: if (($role ne 'cc') && ($role ne 'co')) {
4997: if (@secs > 1) {
4998: $multiple = 1;
4999: foreach my $sec (@secs) {
5000: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
5001: &modifyuserrole($context,$setting,
5002: $changeauth,$cid,$userdomain,$username,
5003: $id,$amode,$password,$fname,
5004: $mname,$lname,$gen,$sec,
5005: $env{'form.forceid'},$desiredhost,
5006: $email,$role,$enddate,
5007: $startdate,$checkid,$inststatus);
1.42 raeburn 5008: }
1.171 raeburn 5009: } elsif (@secs > 0) {
5010: $singlesec = $secs[0];
1.27 raeburn 5011: }
5012: }
5013: }
5014: if (!$multiple) {
1.28 raeburn 5015: ($userresult,$authresult,$roleresult,$idresult) =
1.27 raeburn 5016: &modifyuserrole($context,$setting,
1.57 raeburn 5017: $changeauth,$cid,$userdomain,$username,
1.42 raeburn 5018: $id,$amode,$password,$fname,
5019: $mname,$lname,$gen,$singlesec,
5020: $env{'form.forceid'},$desiredhost,
1.84 raeburn 5021: $email,$role,$enddate,$startdate,
5022: $checkid,$inststatus);
1.27 raeburn 5023: }
5024: }
1.171 raeburn 5025: }
5026: if ($multiple) {
5027: foreach my $sec (sort(keys(%userres))) {
5028: $flushc =
1.27 raeburn 5029: &user_change_result($r,$userres{$sec},$authres{$sec},
5030: $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57 raeburn 5031: $username,$userdomain,\%userchg);
1.27 raeburn 5032:
1.1 raeburn 5033: }
5034: } else {
1.171 raeburn 5035: $flushc =
5036: &user_change_result($r,$userresult,$authresult,
5037: $roleresult,$idresult,\%counts,$flushc,
5038: $username,$userdomain,\%userchg);
1.1 raeburn 5039: }
5040: }
1.172 raeburn 5041: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
1.171 raeburn 5042: } # end of loop
1.172 raeburn 5043: $r->print('</ul>');
1.171 raeburn 5044: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
5045: }
1.1 raeburn 5046: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 5047: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.29 raeburn 5048: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 5049: "</p>\n");
5050: if ($counts{'role'} > 0) {
5051: $r->print("<p>\n".
1.192 raeburn 5052: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
5053: &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.').
5054: "</p>\n");
1.29 raeburn 5055: } else {
5056: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 5057: }
5058: if ($counts{'auth'} > 0) {
5059: $r->print("<p>\n".
5060: &mt('Authentication changed for [_1] existing users.',
5061: $counts{'auth'})."</p>\n");
5062: }
1.13 raeburn 5063: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.1 raeburn 5064: #####################################
1.29 raeburn 5065: # Display list of students to drop #
1.1 raeburn 5066: #####################################
5067: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 5068: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 5069: # Get current classlist
1.30 raeburn 5070: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5071: if (! defined($classlist)) {
1.192 raeburn 5072: $r->print('<p class="LC_info">'.
5073: &mt('There are no students with current/future access to the course.').
5074: '</p>'."\n");
1.66 raeburn 5075: } elsif (ref($classlist) eq 'HASH') {
1.1 raeburn 5076: # Remove the students we just added from the list of students.
1.30 raeburn 5077: foreach my $line (@userdata) {
5078: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 5079: unless (($entries{$fields{'username'}} eq '') ||
5080: (!defined($entries{$fields{'username'}}))) {
5081: delete($classlist->{$entries{$fields{'username'}}.
5082: ':'.$domain});
5083: }
5084: }
5085: # Print out list of dropped students.
1.30 raeburn 5086: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 5087: }
5088: }
5089: } # end of unless
1.193 raeburn 5090: return 'ok';
1.1 raeburn 5091: }
5092:
1.13 raeburn 5093: sub print_namespacing_alerts {
5094: my ($domain,$alerts,$curr_rules) = @_;
5095: my $output;
5096: if (ref($alerts) eq 'HASH') {
5097: if (keys(%{$alerts}) > 0) {
5098: if (ref($alerts->{'username'}) eq 'HASH') {
5099: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
5100: my $count;
5101: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
5102: $count = keys(%{$alerts->{'username'}{$dom}});
5103: }
5104: my $domdesc = &Apache::lonnet::domain($domain,'description');
5105: if (ref($curr_rules->{$dom}) eq 'HASH') {
5106: $output .= &Apache::loncommon::instrule_disallow_msg(
5107: 'username',$domdesc,$count,'upload');
5108: }
5109: $output .= &Apache::loncommon::user_rule_formats($dom,
5110: $domdesc,$curr_rules->{$dom}{'username'},
5111: 'username');
5112: }
5113: }
5114: if (ref($alerts->{'id'}) eq 'HASH') {
5115: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
5116: my $count;
5117: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
5118: $count = keys(%{$alerts->{'id'}{$dom}});
5119: }
5120: my $domdesc = &Apache::lonnet::domain($domain,'description');
5121: if (ref($curr_rules->{$dom}) eq 'HASH') {
5122: $output .= &Apache::loncommon::instrule_disallow_msg(
5123: 'id',$domdesc,$count,'upload');
5124: }
5125: $output .= &Apache::loncommon::user_rule_formats($dom,
5126: $domdesc,$curr_rules->{$dom}{'id'},'id');
5127: }
5128: }
5129: }
5130: }
5131: }
5132:
1.1 raeburn 5133: sub user_change_result {
1.29 raeburn 5134: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57 raeburn 5135: $username,$userdomain,$userchg) = @_;
1.1 raeburn 5136: my $okresult = 0;
1.171 raeburn 5137: my @status;
1.1 raeburn 5138: if ($userresult ne 'ok') {
5139: if ($userresult =~ /^error:(.+)$/) {
5140: my $error = $1;
1.171 raeburn 5141: push(@status,
5142: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5143: }
5144: } else {
5145: $counts->{'user'} ++;
5146: $okresult = 1;
5147: }
5148: if ($authresult ne 'ok') {
5149: if ($authresult =~ /^error:(.+)$/) {
5150: my $error = $1;
1.171 raeburn 5151: push(@status,
5152: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5153: }
5154: } else {
5155: $counts->{'auth'} ++;
5156: $okresult = 1;
5157: }
5158: if ($roleresult ne 'ok') {
5159: if ($roleresult =~ /^error:(.+)$/) {
5160: my $error = $1;
1.171 raeburn 5161: push(@status,
5162: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 5163: }
5164: } else {
5165: $counts->{'role'} ++;
5166: $okresult = 1;
5167: }
5168: if ($okresult) {
5169: $flushc++;
1.57 raeburn 5170: $userchg->{$username.':'.$userdomain}=1;
1.1 raeburn 5171: if ($flushc>15) {
5172: $r->rflush;
5173: $flushc=0;
5174: }
5175: }
1.29 raeburn 5176: if ($idresult) {
1.171 raeburn 5177: push(@status,$idresult);
5178: }
5179: if (@status) {
5180: $r->print('<li>'.join('<br />',@status).'</li>');
1.29 raeburn 5181: }
1.1 raeburn 5182: return $flushc;
5183: }
5184:
5185: # ========================================================= Menu Phase Two Drop
1.17 raeburn 5186: sub print_drop_menu {
1.101 raeburn 5187: my ($r,$context,$permission,$crstype) = @_;
5188: my $heading;
5189: if ($crstype eq 'Community') {
5190: $heading = &mt("Drop Members");
5191: } else {
5192: $heading = &mt("Drop Students");
5193: }
5194: $r->print('<h3>'.$heading.'</h3>'."\n".
1.153 bisitz 5195: '<form name="studentform" method="post" action="">'."\n");
1.30 raeburn 5196: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 5197: if (! defined($classlist)) {
1.143 bisitz 5198: my $msg = '';
1.101 raeburn 5199: if ($crstype eq 'Community') {
1.143 bisitz 5200: $msg = &mt('There are no members currently enrolled.');
1.101 raeburn 5201: } else {
1.143 bisitz 5202: $msg = &mt('There are no students currently enrolled.');
1.101 raeburn 5203: }
1.143 bisitz 5204: $r->print('<p class="LC_info">'.$msg."</p>\n");
1.30 raeburn 5205: } else {
1.101 raeburn 5206: &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
1.1 raeburn 5207: }
1.162 bisitz 5208: $r->print('</form>');
1.1 raeburn 5209: return;
5210: }
5211:
5212: # ================================================================== Phase four
5213:
1.11 raeburn 5214: sub update_user_list {
1.118 raeburn 5215: my ($r,$context,$setting,$choice,$crstype) = @_;
1.11 raeburn 5216: my $now = time;
1.1 raeburn 5217: my $count=0;
1.101 raeburn 5218: if ($context eq 'course') {
5219: $crstype = &Apache::loncommon::course_type();
5220: }
1.11 raeburn 5221: my @changelist;
1.29 raeburn 5222: if ($choice eq 'drop') {
5223: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
5224: } else {
1.11 raeburn 5225: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
5226: }
5227: my %result_text = ( ok => { 'revoke' => 'Revoked',
5228: 'delete' => 'Deleted',
5229: 'reenable' => 'Re-enabled',
1.17 raeburn 5230: 'activate' => 'Activated',
5231: 'chgdates' => 'Changed Access Dates for',
1.118 raeburn 5232: 'chgsec' => 'Changed section(s) for',
1.17 raeburn 5233: 'drop' => 'Dropped',
1.11 raeburn 5234: },
5235: error => {'revoke' => 'revoking',
5236: 'delete' => 'deleting',
5237: 'reenable' => 're-enabling',
5238: 'activate' => 'activating',
1.17 raeburn 5239: 'chgdates' => 'changing access dates for',
5240: 'chgsec' => 'changing section for',
5241: 'drop' => 'dropping',
1.11 raeburn 5242: },
5243: );
5244: my ($startdate,$enddate);
5245: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
5246: ($startdate,$enddate) = &get_dates_from_form();
5247: }
5248: foreach my $item (@changelist) {
1.118 raeburn 5249: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
5250: @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
1.174 raeburn 5251: $nothingtodo,$keepnosection,$credits,$instsec);
1.17 raeburn 5252: if ($choice eq 'drop') {
5253: ($uname,$udom,$sec) = split(/:/,$item,-1);
5254: $role = 'st';
5255: $cid = $env{'request.course.id'};
5256: $scopestem = '/'.$cid;
5257: $scopestem =~s/\_/\//g;
5258: if ($sec eq '') {
5259: $scope = $scopestem;
5260: } else {
5261: $scope = $scopestem.'/'.$sec;
5262: }
5263: } elsif ($context eq 'course') {
1.174 raeburn 5264: ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
5265: split(/\:/,$item,8);
5266: $instsec = &unescape($instsec);
1.11 raeburn 5267: $cid = $env{'request.course.id'};
5268: $scopestem = '/'.$cid;
5269: $scopestem =~s/\_/\//g;
5270: if ($sec eq '') {
5271: $scope = $scopestem;
5272: } else {
5273: $scope = $scopestem.'/'.$sec;
5274: }
1.13 raeburn 5275: } elsif ($context eq 'author') {
1.11 raeburn 5276: ($uname,$udom,$role) = split(/\:/,$item,-1);
5277: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
5278: } elsif ($context eq 'domain') {
5279: if ($setting eq 'domain') {
5280: ($role,$uname,$udom) = split(/\:/,$item,-1);
5281: $scope = '/'.$env{'request.role.domain'}.'/';
1.13 raeburn 5282: } elsif ($setting eq 'author') {
1.11 raeburn 5283: ($uname,$udom,$role,$scope) = split(/\:/,$item);
5284: } elsif ($setting eq 'course') {
1.174 raeburn 5285: ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
5286: split(/\:/,$item,9);
5287: $instsec = &unescape($instsec);
1.11 raeburn 5288: $scope = '/'.$cid;
5289: $scope =~s/\_/\//g;
5290: if ($sec ne '') {
5291: $scope .= '/'.$sec;
5292: }
5293: }
5294: }
1.101 raeburn 5295: my $plrole = &Apache::lonnet::plaintext($role,$crstype);
1.11 raeburn 5296: my $start = $env{'form.'.$item.'_start'};
5297: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 5298: if ($choice eq 'drop') {
5299: # drop students
5300: $end = $now;
5301: $type = 'manual';
5302: $result =
1.52 raeburn 5303: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 5304: } elsif ($choice eq 'revoke') {
5305: # revoke or delete user role
1.11 raeburn 5306: $end = $now;
5307: if ($role eq 'st') {
5308: $result =
1.174 raeburn 5309: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5310: } else {
5311: $result =
1.52 raeburn 5312: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
5313: '','',$context);
1.11 raeburn 5314: }
5315: } elsif ($choice eq 'delete') {
5316: if ($role eq 'st') {
1.174 raeburn 5317: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.29 raeburn 5318: }
5319: $result =
5320: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 5321: $start,1,'',$context);
1.11 raeburn 5322: } else {
5323: #reenable, activate, change access dates or change section
5324: if ($choice ne 'chgsec') {
5325: $start = $startdate;
5326: $end = $enddate;
5327: }
5328: if ($choice eq 'reenable') {
5329: if ($role eq 'st') {
1.174 raeburn 5330: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5331: } else {
5332: $result =
5333: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5334: $now,'','',$context);
1.11 raeburn 5335: }
5336: } elsif ($choice eq 'activate') {
5337: if ($role eq 'st') {
1.174 raeburn 5338: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5339: } else {
5340: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5341: $now,'','',$context);
1.11 raeburn 5342: }
5343: } elsif ($choice eq 'chgdates') {
5344: if ($role eq 'st') {
1.174 raeburn 5345: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.11 raeburn 5346: } else {
5347: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 5348: $start,'','',$context);
1.11 raeburn 5349: }
5350: } elsif ($choice eq 'chgsec') {
5351: my (@newsecs,$revresult,$nochg,@retained);
1.103 raeburn 5352: if (($role ne 'cc') && ($role ne 'co')) {
1.117 raeburn 5353: my @secs = sort(split(/,/,$env{'form.newsecs'}));
5354: if (@secs) {
5355: my %curr_groups = &Apache::longroup::coursegroups();
5356: foreach my $sec (@secs) {
5357: next if (($sec =~ /\W/) || ($sec eq 'none') ||
5358: (exists($curr_groups{$sec})));
5359: push(@newsecs,$sec);
5360: }
5361: }
1.11 raeburn 5362: }
5363: # remove existing section if not to be retained.
1.118 raeburn 5364: if (!$env{'form.retainsec'} || ($role eq 'st')) {
1.11 raeburn 5365: if ($sec eq '') {
5366: if (@newsecs == 0) {
1.118 raeburn 5367: $result = 'ok';
1.11 raeburn 5368: $nochg = 1;
1.118 raeburn 5369: $nothingtodo = 1;
1.40 raeburn 5370: } else {
5371: $revresult =
5372: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 5373: $scope,$role,
5374: '','',$context);
1.40 raeburn 5375: }
1.11 raeburn 5376: } else {
1.28 raeburn 5377: if (@newsecs > 0) {
5378: if (grep(/^\Q$sec\E$/,@newsecs)) {
5379: push(@retained,$sec);
5380: } else {
5381: $revresult =
5382: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 5383: $scope,$role,
5384: '','',$context);
1.28 raeburn 5385: }
5386: } else {
1.11 raeburn 5387: $revresult =
1.28 raeburn 5388: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 5389: $scope,$role,
5390: '','',$context);
1.11 raeburn 5391: }
5392: }
5393: } else {
1.28 raeburn 5394: if ($sec eq '') {
5395: $nochg = 1;
1.118 raeburn 5396: $keepnosection = 1;
5397: } else {
1.28 raeburn 5398: push(@retained,$sec);
5399: }
1.11 raeburn 5400: }
5401: # add new sections
1.118 raeburn 5402: my (@diffs,@shownew);
5403: if (@retained) {
5404: @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
5405: } else {
5406: @diffs = @newsecs;
5407: }
1.11 raeburn 5408: if (@newsecs == 0) {
1.118 raeburn 5409: if ($nochg) {
5410: $result = 'ok';
5411: $nothingtodo = 1;
5412: } else {
1.28 raeburn 5413: if ($role eq 'st') {
5414: $result =
1.174 raeburn 5415: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.28 raeburn 5416: } else {
5417: my $newscope = $scopestem;
1.52 raeburn 5418: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 5419: }
5420: }
1.118 raeburn 5421: $showsecs = &mt('No section');
5422: } elsif (@diffs == 0) {
5423: $result = 'ok';
5424: $nothingtodo = 1;
1.11 raeburn 5425: } else {
1.118 raeburn 5426: foreach my $newsec (@newsecs) {
1.11 raeburn 5427: if (!grep(/^\Q$newsec\E$/,@retained)) {
5428: if ($role eq 'st') {
1.174 raeburn 5429: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
1.118 raeburn 5430: if (@newsecs > 1) {
5431: my $showsingle;
5432: if ($newsec eq '') {
5433: $showsingle = &mt('No section');
5434: } else {
5435: $showsingle = $newsec;
5436: }
5437: if ($crstype eq 'Community') {
5438: $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>');
5439: } else {
5440: $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>');
5441: }
5442: $showsecs = $showsingle;
5443: last;
5444: } else {
5445: if ($newsec eq '') {
5446: $showsecs = &mt('No section');
5447: } else {
5448: $showsecs = $newsec;
5449: }
5450: }
1.11 raeburn 5451: } else {
5452: my $newscope = $scopestem;
5453: if ($newsec ne '') {
5454: $newscope .= '/'.$newsec;
1.118 raeburn 5455: push(@shownew,$newsec);
1.11 raeburn 5456: }
5457: $result = &Apache::lonnet::assignrole($udom,$uname,
5458: $newscope,$role,$end,$start);
1.118 raeburn 5459:
1.11 raeburn 5460: }
5461: }
5462: }
5463: }
1.118 raeburn 5464: unless ($role eq 'st') {
5465: unless ($showsecs) {
5466: my @tolist = sort(@shownew,@retained);
5467: if ($keepnosection) {
5468: push(@tolist,&mt('No section'));
5469: }
5470: $showsecs = join(', ',@tolist);
5471: }
5472: }
1.11 raeburn 5473: }
5474: }
1.17 raeburn 5475: my $extent = $scope;
5476: if ($choice eq 'drop' || $context eq 'course') {
5477: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
5478: if ($cdesc) {
5479: $extent = $cdesc;
5480: }
5481: }
1.1 raeburn 5482: if ($result eq 'ok' || $result eq 'ok:') {
1.118 raeburn 5483: my $dates;
5484: if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
5485: $dates = &dates_feedback($start,$end,$now);
5486: }
5487: if ($choice eq 'chgsec') {
5488: if ($nothingtodo) {
5489: $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
5490: &Apache::loncommon::plainname($uname,$udom).
5491: '</i>').' ');
5492: if ($sec eq '') {
5493: $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
5494: } else {
5495: $r->print(&mt('Section(s): [_1] - [_2]',
5496: '<b>'.$showsecs.'</b>',$dates));
5497: }
5498: $r->print('<br />');
5499: } else {
5500: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
5501: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
5502: '<b>'.$showsecs.'</b>',$dates).'<br />');
5503: $count ++;
5504: }
5505: if ($warn_singlesec) {
5506: $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
5507: }
5508: } elsif ($choice eq 'chgdates') {
5509: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
1.121 raeburn 5510: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 5511: $dates).'<br />');
5512: $count ++;
5513: } else {
5514: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
1.121 raeburn 5515: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
1.118 raeburn 5516: '<br />');
5517: $count ++;
5518: }
1.1 raeburn 5519: } else {
5520: $r->print(
1.118 raeburn 5521: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
5522: $plrole,$extent,
1.121 raeburn 5523: '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
1.118 raeburn 5524: $result).'<br />');
1.11 raeburn 5525: }
5526: }
1.32 raeburn 5527: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 5528: if ($choice eq 'drop') {
5529: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
5530: '<input type="hidden" name="Status" value="Active" />'."\n".
5531: '<input type="hidden" name="showrole" value="st" />'."\n");
5532: } else {
5533: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
5534: if ($env{'form.'.$item} ne '') {
5535: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
5536: '" />'."\n");
5537: }
1.32 raeburn 5538: }
5539: }
1.144 bisitz 5540: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
1.11 raeburn 5541: if ($count > 0) {
1.17 raeburn 5542: if ($choice eq 'revoke' || $choice eq 'drop') {
1.74 bisitz 5543: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11 raeburn 5544: }
5545: # Flush the course logs so reverse user roles immediately updated
1.126 raeburn 5546: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.11 raeburn 5547: }
5548: if ($env{'form.makedatesdefault'}) {
5549: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.101 raeburn 5550: $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1 raeburn 5551: }
5552: }
1.33 raeburn 5553: my $linktext = &mt('Display User Lists');
5554: if ($choice eq 'drop') {
5555: $linktext = &mt('Display current class roster');
5556: }
1.144 bisitz 5557: $r->print(
5558: &Apache::lonhtmlcommon::actionbox(
5559: ['<a href="javascript:document.studentform.submit()">'.$linktext.'</a>'])
5560: .'</form>'."\n");
1.1 raeburn 5561: }
5562:
1.118 raeburn 5563: sub dates_feedback {
5564: my ($start,$end,$now) = @_;
5565: my $dates;
5566: if ($start < $now) {
5567: if ($end == 0) {
1.147 bisitz 5568: $dates = &mt('role(s) active now; no end date');
1.118 raeburn 5569: } elsif ($end > $now) {
5570: $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
5571: } else {
5572: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
5573: }
5574: } else {
5575: if ($end == 0 || $end > $now) {
5576: $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
5577: } else {
5578: $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
5579: }
5580: }
5581: return $dates;
5582: }
5583:
1.8 raeburn 5584: sub classlist_drop {
1.29 raeburn 5585: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 5586: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 5587: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8 raeburn 5588: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63 raeburn 5589: my %user;
5590: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8 raeburn 5591: return &mt('Drop from classlist: [_1]',
5592: '<b>'.$result.'</b>').'<br />';
5593: }
5594: }
5595: }
5596:
5597: sub active_student_roles {
5598: my ($cnum,$cdom,$uname,$udom) = @_;
5599: my %roles =
5600: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
5601: ['future','active'],['st']);
5602: return exists($roles{"$cnum:$cdom:st"});
5603: }
5604:
1.1 raeburn 5605: sub section_check_js {
1.8 raeburn 5606: my $groupslist= &get_groupslist();
1.170 damieng 5607: my %js_lt = &Apache::lonlocal::texthash(
5608: mayn => 'may not be used as the name for a section, as it is a reserved word.',
5609: plch => 'Please choose a different section name.',
5610: mnot => 'may not be used as a section name, as it is the name of a course group.',
5611: secn => 'Section names and group names must be distinct. Please choose a different section name.',
5612: );
5613: &js_escape(\%js_lt);
1.1 raeburn 5614: return <<"END";
5615: function validate(caller) {
1.9 raeburn 5616: var groups = new Array($groupslist);
1.1 raeburn 5617: var secname = caller.value;
5618: if ((secname == 'all') || (secname == 'none')) {
1.170 damieng 5619: alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
1.1 raeburn 5620: return 'error';
5621: }
5622: if (secname != '') {
5623: for (var k=0; k<groups.length; k++) {
5624: if (secname == groups[k]) {
1.170 damieng 5625: alert("'"+secname+"' $js_lt{'mnot'}\\n$js_lt{'secn'}");
1.1 raeburn 5626: return 'error';
5627: }
5628: }
5629: }
5630: return 'ok';
5631: }
5632: END
5633: }
5634:
5635: sub set_login {
1.194 raeburn 5636: my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
1.1 raeburn 5637: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5638: my $response;
5639: my ($authnum,%can_assign) =
5640: &Apache::loncommon::get_assignable_auth($dom);
5641: if ($authnum) {
5642: $response = &Apache::loncommon::start_data_table();
5643: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
5644: $response .= &Apache::loncommon::start_data_table_row().
5645: '<td>'.$authformkrb.'</td>'.
5646: &Apache::loncommon::end_data_table_row()."\n";
5647: }
5648: if ($can_assign{'int'}) {
5649: $response .= &Apache::loncommon::start_data_table_row().
5650: '<td>'.$authformint.'</td>'.
5651: &Apache::loncommon::end_data_table_row()."\n"
5652: }
5653: if ($can_assign{'loc'}) {
5654: $response .= &Apache::loncommon::start_data_table_row().
5655: '<td>'.$authformloc.'</td>'.
5656: &Apache::loncommon::end_data_table_row()."\n";
5657: }
1.194 raeburn 5658: if ($can_assign{'lti'}) {
5659: $response .= &Apache::loncommon::start_data_table_row().
5660: '<td>'.$authformlti.'</td>'.
5661: &Apache::loncommon::end_data_table_row()."\n";
5662: }
1.1 raeburn 5663: $response .= &Apache::loncommon::end_data_table();
5664: }
5665: return $response;
5666: }
5667:
1.8 raeburn 5668: sub course_sections {
1.178 raeburn 5669: my ($sections_count,$role,$current_sec,$disabled) = @_;
1.8 raeburn 5670: my $output = '';
1.169 raeburn 5671: my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
1.29 raeburn 5672: my $numsec = scalar(@sections);
1.92 bisitz 5673: my $is_selected = ' selected="selected"';
1.29 raeburn 5674: if ($numsec <= 1) {
1.178 raeburn 5675: $output = '<select name="currsec_'.$role.'"'.$disabled.'>'."\n".
1.51 raeburn 5676: ' <option value="">'.&mt('Select').'</option>'."\n";
5677: if ($current_sec eq 'none') {
5678: $output .=
5679: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
5680: } else {
5681: $output .=
1.29 raeburn 5682: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 5683: }
1.29 raeburn 5684: if ($numsec == 1) {
1.51 raeburn 5685: if ($current_sec eq $sections[0]) {
5686: $output .=
5687: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
5688: } else {
5689: $output .=
1.8 raeburn 5690: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 5691: }
1.29 raeburn 5692: }
1.8 raeburn 5693: } else {
5694: $output = '<select name="currsec_'.$role.'" ';
5695: my $multiple = 4;
5696: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 5697: if ($role eq 'st') {
1.178 raeburn 5698: $output .= $disabled.'>'."\n".
1.51 raeburn 5699: ' <option value="">'.&mt('Select').'</option>'."\n";
5700: if ($current_sec eq 'none') {
5701: $output .=
5702: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
5703: } else {
5704: $output .=
1.29 raeburn 5705: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 5706: }
1.29 raeburn 5707: } else {
1.178 raeburn 5708: $output .= 'multiple="multiple" size="'.$multiple.'"'.$disabled.'>'."\n";
1.29 raeburn 5709: }
1.8 raeburn 5710: foreach my $sec (@sections) {
1.51 raeburn 5711: if ($current_sec eq $sec) {
5712: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
5713: } else {
5714: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
5715: }
1.8 raeburn 5716: }
5717: }
5718: $output .= '</select>';
5719: return $output;
5720: }
5721:
5722: sub get_groupslist {
5723: my $groupslist;
5724: my %curr_groups = &Apache::longroup::coursegroups();
5725: if (%curr_groups) {
5726: $groupslist = join('","',sort(keys(%curr_groups)));
5727: $groupslist = '"'.$groupslist.'"';
5728: }
1.11 raeburn 5729: return $groupslist;
1.8 raeburn 5730: }
5731:
5732: sub setsections_javascript {
1.150 raeburn 5733: my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
1.28 raeburn 5734: my ($checkincluded,$finish,$rolecode,$setsection_js);
5735: if ($mode eq 'upload') {
5736: $checkincluded = 'formname.name == "'.$formname.'"';
5737: $finish = "return 'ok';";
5738: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
5739: } elsif ($formname eq 'cu') {
1.150 raeburn 5740: if (($crstype eq 'Course') && ($showcredits)) {
5741: $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
5742: } else {
5743: $checkincluded = 'formname.elements[i-1].checked == true';
5744: }
1.37 raeburn 5745: if ($checkauth) {
5746: $finish = "var authcheck = auth_check();\n".
5747: " if (authcheck == 'ok') {\n".
5748: " formname.submit();\n".
5749: " }\n";
5750: } else {
5751: $finish = 'formname.submit()';
5752: }
1.28 raeburn 5753: $rolecode = "var match = str.split('_');
5754: var role = match[3];\n";
1.165 raeburn 5755: } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
1.28 raeburn 5756: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 5757: if ($checkauth) {
5758: $finish = "var authcheck = auth_check();\n".
5759: " if (authcheck == 'ok') {\n".
5760: " formname.submit();\n".
5761: " }\n";
5762: } else {
5763: $finish = 'formname.submit()';
5764: }
1.28 raeburn 5765: $rolecode = "var match = str.split('_');
5766: var role = match[1];\n";
1.8 raeburn 5767: } else {
1.28 raeburn 5768: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 5769: $finish = "seccheck = 'ok';";
1.28 raeburn 5770: $rolecode = "var match = str.split('_');
5771: var role = match[1];\n";
1.11 raeburn 5772: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 5773: }
5774: my %alerts = &Apache::lonlocal::texthash(
5775: secd => 'Section designations do not apply to Course Coordinator roles.',
1.103 raeburn 5776: sedn => 'Section designations do not apply to Coordinator roles.',
1.8 raeburn 5777: accr => 'A course coordinator role will be added with access to all sections.',
1.103 raeburn 5778: acor => 'A coordinator role will be added with access to all sections',
1.8 raeburn 5779: inea => 'In each course, each user may only have one student role at a time.',
1.125 raeburn 5780: inco => 'In each community, each user may only have one member role at a time.',
1.145 raeburn 5781: youh => 'You had selected',
1.8 raeburn 5782: secs => 'sections.',
5783: plmo => 'Please modify your selections so they include no more than one section.',
5784: mayn => 'may not be used as the name for a section, as it is a reserved word.',
5785: plch => 'Please choose a different section name.',
5786: mnot => 'may not be used as a section name, as it is the name of a course group.',
5787: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.113 raeburn 5788: nonw => 'Section names may only contain letters or numbers.',
1.170 damieng 5789: );
5790: &js_escape(\%alerts);
1.8 raeburn 5791: $setsection_js .= <<"ENDSECCODE";
5792:
1.103 raeburn 5793: function setSections(formname,crstype) {
1.8 raeburn 5794: var re1 = /^currsec_/;
1.113 raeburn 5795: var re2 =/\\W/;
1.115 raeburn 5796: var trimleading = /^\\s+/;
5797: var trimtrailing = /\\s+\$/;
1.8 raeburn 5798: var groups = new Array($groupslist);
5799: for (var i=0;i<formname.elements.length;i++) {
5800: var str = formname.elements[i].name;
1.168 raeburn 5801: if (typeof(str) === "undefined") {
5802: continue;
5803: }
1.8 raeburn 5804: var checkcurr = str.match(re1);
5805: if (checkcurr != null) {
1.115 raeburn 5806: var num = i;
1.150 raeburn 5807: $rolecode
1.8 raeburn 5808: if ($checkincluded) {
1.103 raeburn 5809: if (role == 'cc' || role == 'co') {
5810: if (role == 'cc') {
5811: alert("$alerts{'secd'}\\n$alerts{'accr'}");
5812: } else {
5813: alert("$alerts{'sedn'}\\n$alerts{'acor'}");
5814: }
5815: } else {
1.8 raeburn 5816: var sections = '';
5817: var numsec = 0;
1.115 raeburn 5818: var fromexisting = new Array();
5819: for (var j=0; j<formname.elements[num].length; j++) {
5820: if (formname.elements[num].options[j].selected == true ) {
5821: var addsec = formname.elements[num].options[j].value;
1.119 raeburn 5822: if ((addsec != "") && (addsec != null)) {
1.115 raeburn 5823: fromexisting.push(addsec);
1.8 raeburn 5824: if (numsec == 0) {
1.115 raeburn 5825: sections = addsec;
5826: } else {
5827: sections = sections + "," + addsec;
1.8 raeburn 5828: }
1.115 raeburn 5829: numsec ++;
1.8 raeburn 5830: }
5831: }
5832: }
1.115 raeburn 5833: var newsecs = formname.elements[num+1].value;
1.113 raeburn 5834: var validsecs = new Array();
1.115 raeburn 5835: var validsecstr = '';
1.113 raeburn 5836: var badsecs = new Array();
1.8 raeburn 5837: if (newsecs != null && newsecs != "") {
1.115 raeburn 5838: var numsplit;
5839: if (newsecs.indexOf(',') == -1) {
5840: numsplit = new Array(newsecs);
5841: } else {
5842: numsplit = newsecs.split(/,/g);
5843: }
1.117 raeburn 5844: for (var m=0; m<numsplit.length; m++) {
5845: var newsec = numsplit[m];
1.115 raeburn 5846: newsec = newsec.replace(trimleading,'');
5847: newsec = newsec.replace(trimtrailing,'');
5848: if (re2.test(newsec) == true) {
5849: badsecs.push(newsec);
1.113 raeburn 5850: } else {
1.115 raeburn 5851: if (newsec != '') {
5852: var isnew = 1;
5853: if (fromexisting != null) {
1.117 raeburn 5854: for (var n=0; n<fromexisting.length; n++) {
5855: if (newsec == fromexisting[n]) {
1.115 raeburn 5856: isnew = 0;
5857: }
5858: }
5859: }
5860: if (isnew == 1) {
5861: validsecs.push(newsec);
5862: }
5863: }
1.113 raeburn 5864: }
5865: }
5866: if (badsecs.length > 0) {
5867: alert("$alerts{'nonw'}\\n$alerts{'plch'}");
5868: return;
5869: }
5870: numsec = numsec + validsecs.length;
1.8 raeburn 5871: }
5872: if ((role == 'st') && (numsec > 1)) {
1.103 raeburn 5873: if (crstype == 'Community') {
5874: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
5875: } else {
5876: alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
5877: }
1.8 raeburn 5878: return;
1.115 raeburn 5879: } else {
5880: if (validsecs != null) {
5881: for (var j=0; j<validsecs.length; j++) {
5882: if (validsecstr == '' || validsecstr == null) {
5883: validsecstr = validsecs[j];
5884: } else {
5885: validsecstr += ','+validsecs[j];
5886: }
5887: if ((validsecs[j] == 'all') ||
5888: (validsecs[j] == 'none')) {
5889: alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
1.8 raeburn 5890: return;
5891: }
5892: for (var k=0; k<groups.length; k++) {
1.115 raeburn 5893: if (validsecs[j] == groups[k]) {
5894: alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
1.8 raeburn 5895: return;
5896: }
5897: }
5898: }
5899: }
5900: }
1.115 raeburn 5901: if ((validsecstr != '') && (validsecstr != null)) {
1.117 raeburn 5902: if ((sections == '') || (sections == null)) {
5903: sections = validsecstr;
5904: } else {
1.115 raeburn 5905: sections = sections + "," + validsecstr;
5906: }
5907: }
5908: formname.elements[num+2].value = sections;
1.8 raeburn 5909: }
5910: }
5911: }
5912: }
5913: $finish
5914: }
5915: ENDSECCODE
1.11 raeburn 5916: return $setsection_js;
1.8 raeburn 5917: }
5918:
1.15 raeburn 5919: sub can_create_user {
5920: my ($dom,$context,$usertype) = @_;
5921: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5922: my $cancreate = 1;
1.28 raeburn 5923: if (&Apache::lonnet::allowed('mau',$dom)) {
5924: return $cancreate;
1.178 raeburn 5925: } elsif ($context eq 'domain') {
5926: $cancreate = 0;
5927: return $cancreate;
1.28 raeburn 5928: }
1.15 raeburn 5929: if (ref($domconf{'usercreation'}) eq 'HASH') {
5930: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
1.100 raeburn 5931: if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
1.15 raeburn 5932: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
5933: if ($creation eq 'none') {
5934: $cancreate = 0;
5935: } elsif ($creation ne 'any') {
5936: if (defined($usertype)) {
5937: if ($creation ne $usertype) {
5938: $cancreate = 0;
5939: }
5940: }
5941: }
5942: }
5943: }
5944: }
5945: return $cancreate;
5946: }
5947:
1.20 raeburn 5948: sub can_modify_userinfo {
5949: my ($context,$dom,$fields,$userroles) = @_;
5950: my %domconfig =
5951: &Apache::lonnet::get_dom('configuration',['usermodification'],
5952: $dom);
5953: my %canmodify;
5954: if (ref($fields) eq 'ARRAY') {
5955: foreach my $field (@{$fields}) {
5956: $canmodify{$field} = 0;
5957: if (&Apache::lonnet::allowed('mau',$dom)) {
5958: $canmodify{$field} = 1;
5959: } else {
5960: if (ref($domconfig{'usermodification'}) eq 'HASH') {
5961: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
5962: if (ref($userroles) eq 'ARRAY') {
5963: foreach my $role (@{$userroles}) {
5964: my $testrole;
1.60 raeburn 5965: if ($context eq 'selfcreate') {
5966: $testrole = $role;
1.20 raeburn 5967: } else {
1.60 raeburn 5968: if ($role =~ /^cr\//) {
5969: $testrole = 'cr';
5970: } else {
5971: $testrole = $role;
5972: }
1.20 raeburn 5973: }
5974: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
5975: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
5976: $canmodify{$field} = 1;
5977: last;
5978: }
5979: }
5980: }
5981: } else {
5982: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
5983: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
5984: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
5985: $canmodify{$field} = 1;
5986: last;
5987: }
5988: }
5989: }
5990: }
5991: }
5992: } elsif ($context eq 'course') {
5993: if (ref($userroles) eq 'ARRAY') {
5994: if (grep(/^st$/,@{$userroles})) {
5995: $canmodify{$field} = 1;
5996: }
5997: } else {
5998: $canmodify{$field} = 1;
5999: }
6000: }
6001: }
6002: }
6003: }
6004: return %canmodify;
6005: }
6006:
1.195 raeburn 6007: sub can_change_internalpass {
6008: my ($uname,$udom,$crstype,$permission) = @_;
6009: my $canchange;
6010: if (&Apache::lonnet::allowed('mau',$udom)) {
6011: $canchange = 1;
6012: } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
6013: ($udom eq $env{'request.role.domain'})) {
6014: unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
6015: my ($cnum,$cdom) = &get_course_identity();
6016: if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
6017: my $noupdate;
6018: my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
6019: $env{'user.name'}.':'.$env{'user.domain'},
6020: undef,undef,undef,'.');
6021: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
6022: ['active','future']);
6023: foreach my $key (keys(%roleshash)) {
6024: my ($name,$domain,$role) = split(/:/,$key);
6025: if ($role eq 'st') {
6026: next if (($name eq $cnum) && ($domain eq $cdom));
6027: if ($owned{$domain.'_'.$name}) {
6028: if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
6029: if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
6030: $noupdate = 1;
6031: last;
6032: }
6033: }
6034: } else {
6035: $noupdate = 1;
6036: last;
6037: }
6038: } else {
6039: $noupdate = 1;
6040: last;
6041: }
6042: }
6043: unless ($noupdate) {
6044: $canchange = 1;
6045: }
6046: }
6047: }
6048: }
6049: return $canchange;
6050: }
6051:
1.18 raeburn 6052: sub check_usertype {
1.134 raeburn 6053: my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
1.18 raeburn 6054: my $usertype;
1.134 raeburn 6055: if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
6056: if (!$got_rules->{$dom}) {
6057: my %domconfig = &Apache::lonnet::get_dom('configuration',
6058: ['usercreation'],$dom);
6059: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6060: foreach my $item ('username','id') {
6061: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6062: $curr_rules->{$dom}{$item} =
6063: $domconfig{'usercreation'}{$item.'_rule'};
6064: }
6065: }
6066: }
6067: $got_rules->{$dom} = 1;
6068: }
6069: if (ref($rules) eq 'HASH') {
6070: my @user_rules;
6071: if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
6072: foreach my $rule (keys(%{$rules})) {
6073: if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
6074: push(@user_rules,$rule);
6075: }
6076: }
6077: }
6078: if (@user_rules > 0) {
6079: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
6080: if (keys(%rule_check) > 0) {
6081: $usertype = 'unofficial';
6082: foreach my $item (keys(%rule_check)) {
6083: if ($rule_check{$item}) {
6084: $usertype = 'official';
6085: last;
6086: }
1.18 raeburn 6087: }
6088: }
6089: }
6090: }
6091: }
6092: return $usertype;
6093: }
6094:
1.17 raeburn 6095: sub roles_by_context {
1.101 raeburn 6096: my ($context,$custom,$crstype) = @_;
1.17 raeburn 6097: my @allroles;
6098: if ($context eq 'course') {
1.99 raeburn 6099: @allroles = ('st');
6100: if ($env{'request.role'} =~ m{^dc\./}) {
6101: push(@allroles,'ad');
6102: }
1.101 raeburn 6103: push(@allroles,('ta','ep','in'));
6104: if ($crstype eq 'Community') {
6105: push(@allroles,'co');
6106: } else {
6107: push(@allroles,'cc');
6108: }
1.17 raeburn 6109: if ($custom) {
6110: push(@allroles,'cr');
6111: }
6112: } elsif ($context eq 'author') {
6113: @allroles = ('ca','aa');
6114: } elsif ($context eq 'domain') {
1.182 raeburn 6115: @allroles = ('li','ad','dg','dh','da','sc','au','dc');
1.17 raeburn 6116: }
6117: return @allroles;
6118: }
6119:
1.16 raeburn 6120: sub get_permission {
1.101 raeburn 6121: my ($context,$crstype) = @_;
1.16 raeburn 6122: my %permission;
6123: if ($context eq 'course') {
1.17 raeburn 6124: my $custom = 1;
1.101 raeburn 6125: my @allroles = &roles_by_context($context,$custom,$crstype);
1.17 raeburn 6126: foreach my $role (@allroles) {
6127: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
6128: $permission{'cusr'} = 1;
6129: last;
6130: }
1.16 raeburn 6131: }
6132: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
6133: $permission{'custom'} = 1;
6134: }
6135: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
6136: $permission{'view'} = 1;
6137: }
6138: if (!$permission{'view'}) {
6139: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6140: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
6141: if ($permission{'view'}) {
6142: $permission{'view_section'} = $env{'request.course.sec'};
6143: }
6144: }
1.17 raeburn 6145: if (!$permission{'cusr'}) {
6146: if ($env{'request.course.sec'} ne '') {
6147: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
6148: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
6149: if ($permission{'cusr'}) {
6150: $permission{'cusr_section'} = $env{'request.course.sec'};
6151: }
6152: }
6153: }
1.16 raeburn 6154: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
6155: $permission{'grp_manage'} = 1;
6156: }
1.165 raeburn 6157: if ($permission{'cusr'}) {
6158: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6159: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6160: my %coursehash = (
6161: 'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
6162: 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
6163: 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
6164: 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
6165: );
6166: my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
6167: if (ref($managed_by_cc) eq 'ARRAY') {
6168: if (@{$managed_by_cc}) {
6169: $permission{'selfenrolladmin'} = 1;
6170: }
6171: }
6172: }
1.180 raeburn 6173: if ($env{'request.course.id'}) {
1.195 raeburn 6174: my $user;
6175: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
6176: $user = $env{'user.name'}.':'.$env{'user.domain'};
6177: }
1.180 raeburn 6178: if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
6179: $user)) {
6180: $permission{'owner'} = 1;
1.195 raeburn 6181: if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
6182: $permission{'mip'} = 1;
6183: }
1.180 raeburn 6184: } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
6185: if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
6186: $permission{'co-owner'} = 1;
6187: }
6188: }
6189: }
1.16 raeburn 6190: } elsif ($context eq 'author') {
6191: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
6192: $permission{'view'} = $permission{'cusr'};
6193: } else {
1.17 raeburn 6194: my @allroles = &roles_by_context($context);
6195: foreach my $role (@allroles) {
1.28 raeburn 6196: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
6197: $permission{'cusr'} = 1;
1.17 raeburn 6198: last;
6199: }
6200: }
6201: if (!$permission{'cusr'}) {
6202: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
6203: $permission{'cusr'} = 1;
6204: }
1.16 raeburn 6205: }
6206: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
6207: $permission{'custom'} = 1;
6208: }
1.176 raeburn 6209: if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
6210: $permission{'activity'} = 1;
6211: }
1.178 raeburn 6212: if (&Apache::lonnet::allowed('vur',$env{'request.role.domain'})) {
6213: $permission{'view'} = 1;
6214: }
1.180 raeburn 6215: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
6216: $permission{'owner'} = 1;
6217: }
1.16 raeburn 6218: }
6219: my $allowed = 0;
6220: foreach my $perm (values(%permission)) {
6221: if ($perm) { $allowed=1; last; }
6222: }
6223: return (\%permission,$allowed);
6224: }
6225:
6226: # ==================================================== Figure out author access
6227:
6228: sub authorpriv {
6229: my ($auname,$audom)=@_;
6230: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
6231: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
6232: }
6233:
1.27 raeburn 6234: sub roles_on_upload {
1.101 raeburn 6235: my ($context,$setting,$crstype,%customroles) = @_;
1.27 raeburn 6236: my (@possible_roles,@permitted_roles);
1.101 raeburn 6237: @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
1.27 raeburn 6238: foreach my $role (@possible_roles) {
6239: if ($role eq 'cr') {
6240: push(@permitted_roles,keys(%customroles));
6241: } else {
6242: push(@permitted_roles,$role);
6243: }
6244: }
1.42 raeburn 6245: return @permitted_roles;
1.27 raeburn 6246: }
6247:
1.17 raeburn 6248: sub get_course_identity {
6249: my ($cid) = @_;
6250: my ($cnum,$cdom,$cdesc);
6251: if ($cid eq '') {
6252: $cid = $env{'request.course.id'}
6253: }
6254: if ($cid ne '') {
6255: $cnum = $env{'course.'.$cid.'.num'};
6256: $cdom = $env{'course.'.$cid.'.domain'};
6257: $cdesc = $env{'course.'.$cid.'.description'};
6258: if ($cnum eq '' || $cdom eq '') {
6259: my %coursehash =
6260: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
6261: $cdom = $coursehash{'domain'};
6262: $cnum = $coursehash{'num'};
6263: $cdesc = $coursehash{'description'};
6264: }
6265: }
6266: return ($cnum,$cdom,$cdesc);
6267: }
6268:
1.19 raeburn 6269: sub dc_setcourse_js {
1.196 raeburn 6270: my ($formname,$mode,$context,$showcredits,$domain) = @_;
1.37 raeburn 6271: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 6272: my $cctext = &Apache::lonnet::plaintext('cc');
1.103 raeburn 6273: my $cotext = &Apache::lonnet::plaintext('co');
1.19 raeburn 6274: my %alerts = §ioncheck_alerts();
6275: my $role = 'role';
6276: if ($mode eq 'upload') {
6277: $role = 'courserole';
1.37 raeburn 6278: } else {
1.196 raeburn 6279: $authen_check = &verify_authen($formname,$context,$domain);
1.19 raeburn 6280: }
6281: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 6282: $authen_check
6283:
1.19 raeburn 6284: function setCourse() {
6285: var course = document.$formname.dccourse.value;
6286: if (course != "") {
6287: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
6288: alert("$alerts{'curd'}");
6289: return;
6290: }
6291: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
6292: var section="";
6293: var numsections = 0;
6294: var newsecs = new Array();
6295: for (var i=0; i<document.$formname.currsec.length; i++) {
6296: if (document.$formname.currsec.options[i].selected == true ) {
6297: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
6298: if (numsections == 0) {
6299: section = document.$formname.currsec.options[i].value
6300: numsections = 1;
6301: }
6302: else {
6303: section = section + "," + document.$formname.currsec.options[i].value
6304: numsections ++;
6305: }
6306: }
6307: }
6308: }
6309: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
6310: if (numsections == 0) {
6311: section = document.$formname.newsec.value
6312: }
6313: else {
6314: section = section + "," + document.$formname.newsec.value
6315: }
6316: newsecs = document.$formname.newsec.value.split(/,/g);
6317: numsections = numsections + newsecs.length;
6318: }
6319: if ((userrole == 'st') && (numsections > 1)) {
1.103 raeburn 6320: if (document.$formname.crstype.value == 'Community') {
6321: alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
6322: } else {
6323: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
6324: }
1.19 raeburn 6325: return;
6326: }
6327: for (var j=0; j<newsecs.length; j++) {
6328: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
6329: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
6330: return;
6331: }
6332: if (document.$formname.groups.value != '') {
6333: var groups = document.$formname.groups.value.split(/,/g);
6334: for (var k=0; k<groups.length; k++) {
6335: if (newsecs[j] == groups[k]) {
1.103 raeburn 6336: if (document.$formname.crstype.value == 'Community') {
6337: alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
6338: } else {
6339: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
6340: }
1.19 raeburn 6341: return;
6342: }
6343: }
6344: }
6345: }
6346: if ((userrole == 'cc') && (numsections > 0)) {
6347: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
6348: section = "";
6349: }
1.103 raeburn 6350: if ((userrole == 'co') && (numsections > 0)) {
6351: alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
6352: section = "";
6353: }
1.19 raeburn 6354: SCRIPTTOP
6355: if ($mode ne 'upload') {
1.150 raeburn 6356: $dc_setcourse_code .= (<<"SCRIPTMID");
1.19 raeburn 6357: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
6358: var numcourse = getIndex(document.$formname.dccourse);
6359: if (numcourse == "-1") {
1.103 raeburn 6360: if (document.$formname.type == 'Community') {
6361: alert("$alerts{'thwc'}");
6362: } else {
6363: alert("$alerts{'thwa'}");
6364: }
1.19 raeburn 6365: return;
6366: }
6367: else {
6368: document.$formname.elements[numcourse].name = "act"+coursename;
6369: var numnewsec = getIndex(document.$formname.newsec);
6370: if (numnewsec != "-1") {
6371: document.$formname.elements[numnewsec].name = "sec"+coursename;
6372: document.$formname.elements[numnewsec].value = section;
6373: }
6374: var numstart = getIndex(document.$formname.start);
6375: if (numstart != "-1") {
6376: document.$formname.elements[numstart].name = "start"+coursename;
6377: }
6378: var numend = getIndex(document.$formname.end);
6379: if (numend != "-1") {
6380: document.$formname.elements[numend].name = "end"+coursename
6381: }
1.150 raeburn 6382: SCRIPTMID
6383: if ($showcredits) {
6384: $dc_setcourse_code .= <<ENDCRED;
6385: var numcredits = getIndex(document.$formname.credits);
6386: if (numcredits != "-1") {
6387: document.$formname.elements[numcredits].name = "credits"+coursename;
6388: }
6389: ENDCRED
6390: }
6391: $dc_setcourse_code .= <<ENDSCRIPT;
1.19 raeburn 6392: }
6393: }
1.37 raeburn 6394: var authcheck = auth_check();
6395: if (authcheck == 'ok') {
6396: document.$formname.submit();
6397: }
1.19 raeburn 6398: }
6399: ENDSCRIPT
6400: } else {
6401: $dc_setcourse_code .= "
6402: document.$formname.sections.value = section;
6403: }
6404: return 'ok';
6405: }
6406: ";
6407: }
6408: $dc_setcourse_code .= (<<"ENDSCRIPT");
6409:
6410: function getIndex(caller) {
6411: for (var i=0;i<document.$formname.elements.length;i++) {
6412: if (document.$formname.elements[i] == caller) {
6413: return i;
6414: }
6415: }
6416: return -1;
6417: }
6418: ENDSCRIPT
1.37 raeburn 6419: return $dc_setcourse_code;
6420: }
6421:
6422: sub verify_authen {
1.196 raeburn 6423: my ($formname,$context,$domain) = @_;
1.37 raeburn 6424: my %alerts = &authcheck_alerts();
6425: my $finish = "return 'ok';";
6426: if ($context eq 'author') {
6427: $finish = "document.$formname.submit();";
6428: }
1.196 raeburn 6429: my ($numrules,$intargjs) =
6430: &passwd_validation_js('argpicked',$domain);
1.37 raeburn 6431: my $outcome = <<"ENDSCRIPT";
6432:
6433: function auth_check() {
6434: var logintype;
6435: if (document.$formname.login.length) {
6436: if (document.$formname.login.length > 0) {
6437: var loginpicked = 0;
6438: for (var i=0; i<document.$formname.login.length; i++) {
6439: if (document.$formname.login[i].checked == true) {
6440: loginpicked = 1;
6441: logintype = document.$formname.login[i].value;
6442: }
6443: }
6444: if (loginpicked == 0) {
6445: alert("$alerts{'authen'}");
6446: return;
6447: }
6448: }
6449: } else {
6450: logintype = document.$formname.login.value;
6451: }
6452: if (logintype == 'nochange') {
6453: return 'ok';
6454: }
6455: var argpicked = document.$formname.elements[logintype+'arg'].value;
6456: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
6457: var alertmsg = '';
6458: switch (logintype) {
6459: case 'krb':
6460: alertmsg = '$alerts{'krb'}';
6461: break;
6462: case 'int':
6463: alertmsg = '$alerts{'ipass'}';
1.196 raeburn 6464: break;
1.37 raeburn 6465: case 'fsys':
6466: alertmsg = '$alerts{'ipass'}';
6467: break;
6468: case 'loc':
6469: alertmsg = '';
6470: break;
6471: default:
6472: alertmsg = '';
6473: }
6474: if (alertmsg != '') {
6475: alert(alertmsg);
6476: return;
6477: }
1.196 raeburn 6478: } else if (logintype == 'int') {
6479: var numrules = $numrules;
6480: if (numrules > 0) {
6481: $intargjs
6482: }
1.37 raeburn 6483: }
6484: $finish
6485: }
6486: ENDSCRIPT
1.19 raeburn 6487: }
6488:
6489: sub sectioncheck_alerts {
6490: my %alerts = &Apache::lonlocal::texthash(
1.103 raeburn 6491: curd => 'You must select a course or community in the current domain',
1.19 raeburn 6492: inea => 'In each course, each user may only have one student role at a time',
1.103 raeburn 6493: inco => 'In each community, each user may only have one member role at a time',
1.19 raeburn 6494: youh => 'You had selected',
6495: sect => 'sections',
6496: plsm => 'Please modify your selections so they include no more than one section',
6497: mayn => 'may not be used as the name for a section, as it is a reserved word',
6498: plsc => 'Please choose a different section name',
6499: mayt => 'may not be used as the name for a section, as it is the name of a course group',
1.103 raeburn 6500: mayc => 'may not be used as the name for a section, as it is the name of a community group',
1.19 raeburn 6501: secn => 'Section names and group names must be distinct',
6502: secd => 'Section designations do not apply to ',
6503: role => 'roles',
6504: accr => 'role will be added with access to all sections',
1.103 raeburn 6505: thwa => 'There was a problem with your course selection',
6506: thwc => 'There was a problem with your community selection',
1.19 raeburn 6507: );
1.170 damieng 6508: &js_escape(\%alerts);
1.19 raeburn 6509: return %alerts;
6510: }
1.17 raeburn 6511:
1.37 raeburn 6512: sub authcheck_alerts {
6513: my %alerts =
6514: &Apache::lonlocal::texthash(
6515: authen => 'You must choose an authentication type.',
6516: krb => 'You need to specify the Kerberos domain.',
6517: ipass => 'You need to specify the initial password.',
6518: );
1.170 damieng 6519: &js_escape(\%alerts);
1.37 raeburn 6520: return %alerts;
6521: }
6522:
1.141 raeburn 6523: sub is_courseowner {
6524: my ($thiscourse,$courseowner) = @_;
6525: if ($courseowner eq '') {
6526: if ($env{'request.course.id'} eq $thiscourse) {
6527: $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
6528: }
6529: }
6530: if ($courseowner ne '') {
6531: if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
6532: return 1;
6533: }
6534: }
6535: return;
6536: }
6537:
1.165 raeburn 6538: sub get_selfenroll_titles {
6539: my @row = ('types','registered','enroll_dates','access_dates','section',
6540: 'approval','limit');
6541: my %lt = &Apache::lonlocal::texthash (
6542: types => 'Users allowed to self-enroll',
6543: registered => 'Registration status (official courses)' ,
6544: enroll_dates => 'Dates self-enrollment available',
6545: access_dates => 'Access dates for self-enrolling users',
6546: section => "Self-enrolling users' section",
6547: approval => 'Processing of requests',
6548: limit => 'Enrollment limit',
6549: );
6550: return (\@row,\%lt);
6551: }
6552:
6553: sub selfenroll_default_descs {
6554: my %desc = (
6555: types => {
6556: dom => &mt('Course domain'),
6557: all => &mt('Any domain'),
6558: '' => &mt('None'),
6559: },
6560: limit => {
6561: none => &mt('No limit'),
6562: allstudents => &mt('Limit by total students'),
6563: selfenrolled => &mt('Limit by total self-enrolled'),
6564: },
6565: approval => {
6566: '0' => &mt('Processed automatically'),
6567: '1' => &mt('Queued for approval'),
6568: '2' => &mt('Queued, pending validation'),
6569: },
6570: registered => {
6571: 0 => 'No registration required',
6572: 1 => 'Registered students only',
6573: },
6574: );
6575: return %desc;
6576: }
6577:
6578: sub selfenroll_validation_types {
6579: my @items = ('url','fields','button','markup');
6580: my %names = &Apache::lonlocal::texthash (
6581: url => 'Web address of validation server/script',
6582: fields => 'Form fields to send to validator',
6583: button => 'Text for validation button',
6584: markup => 'Validation description (HTML)',
6585: );
1.167 raeburn 6586: my @fields = ('username','domain','uniquecode','course','coursetype','description');
1.165 raeburn 6587: return (\@items,\%names,\@fields);
6588: }
6589:
6590: sub get_extended_type {
6591: my ($cdom,$cnum,$crstype,$current) = @_;
6592: my $type = 'unofficial';
6593: my %settings;
6594: if (ref($current) eq 'HASH') {
6595: %settings = %{$current};
6596: } else {
6597: %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
6598: }
6599: if ($crstype eq 'Community') {
6600: $type = 'community';
1.173 raeburn 6601: } elsif ($crstype eq 'Placement') {
6602: $type = 'placement';
1.165 raeburn 6603: } elsif ($settings{'internal.coursecode'}) {
6604: $type = 'official';
6605: } elsif ($settings{'internal.textbook'}) {
6606: $type = 'textbook';
6607: }
6608: return $type;
6609: }
6610:
6611: sub selfenrollment_administration {
6612: my ($cdom,$cnum,$crstype,$coursehash) = @_;
6613: my %settings;
6614: if (ref($coursehash) eq 'HASH') {
6615: %settings = %{$coursehash};
6616: } else {
6617: %settings = &Apache::lonnet::get('environment',
6618: ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
6619: 'internal.coursecode','internal.textbook'],$cdom,$cnum);
6620: }
6621: my ($possconfigs) = &get_selfenroll_titles();
6622: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6623: my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
6624:
6625: my (@in_course,@in_domain);
6626: if ($settings{'internal.selfenrollmgrcc'} ne '') {
6627: @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
6628: my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
6629: unless (@diffs) {
6630: return (\@in_course,\@in_domain);
6631: }
6632: }
6633: if ($settings{'internal.selfenrollmgrdc'} ne '') {
6634: my @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
6635: my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
6636: unless (@diffs) {
6637: return (\@in_course,\@in_domain);
6638: }
6639: }
6640: my @combined = @in_course;
6641: push(@combined,@in_domain);
6642: my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
6643: unless (@diffs) {
6644: return (\@in_course,\@in_domain);
6645: }
6646: if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
6647: push(@in_course,@diffs);
6648: } else {
6649: my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
6650: foreach my $item (@diffs) {
6651: if (grep(/^\Q$item\E$/,@defaultdc)) {
6652: push(@in_domain,$item);
6653: } else {
6654: push(@in_course,$item);
6655: }
6656: }
6657: }
6658: return (\@in_course,\@in_domain);
6659: }
6660:
1.175 raeburn 6661: sub custom_role_header {
6662: my ($context,$crstype,$templaterolerefs,$prefix) = @_;
6663: my %lt = &Apache::lonlocal::texthash(
6664: sele => 'Select a Template',
6665: );
6666: my ($context_code,$button_code);
6667: if ($context eq 'domain') {
6668: $context_code = &custom_coursetype_switch($crstype,$prefix);
6669: }
6670: if (ref($templaterolerefs) eq 'ARRAY') {
6671: foreach my $role (@{$templaterolerefs}) {
6672: my $display = 'inline';
6673: if (($context eq 'domain') && ($role eq 'co')) {
6674: $display = 'none';
6675: }
6676: $button_code .= &make_button_code($role,$crstype,$display,$prefix).' ';
6677: }
6678: }
6679: return <<"END";
6680: <div class="LC_left_float">
6681: <fieldset>
6682: <legend>$lt{'sele'}</legend>
6683: $button_code
6684: </fieldset></div>
6685: $context_code
6686: <br clear="all" />
6687: END
6688: }
6689:
6690: sub custom_coursetype_switch {
6691: my ($crstype,$prefix) = @_;
6692: my ($checkedcourse,$checkedcommunity);
6693: if ($crstype eq 'Community') {
6694: $checkedcommunity = ' checked="checked"';
6695: } else {
6696: $checkedcourse = ' checked="checked"';
6697: }
6698: my %lt = &Apache::lonlocal::texthash(
6699: cont => 'Context',
6700: cour => 'Course',
6701: comm => 'Community',
6702: );
6703: return <<"END";
6704: <div class="LC_left_float">
6705: <fieldset>
6706: <legend>$lt{'cont'}</legend>
6707: <label>
6708: <input type="radio" name="${prefix}_custrolecrstype" value="Course"$checkedcourse onclick="javascript:customSwitchType('$prefix');" />
6709: $lt{'cour'}
6710: </label>
6711: <label>
6712: <input type="radio" name="${prefix}_custrolecrstype" value="Community"$checkedcommunity onclick="javascript:customSwitchType('$prefix');" />
6713: $lt{'comm'}
6714: </label>
6715: </fieldset>
6716: </div>
6717: END
6718: }
6719:
6720: sub custom_role_table {
1.180 raeburn 6721: my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
1.175 raeburn 6722: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
6723: (ref($levelscurrent) eq 'HASH'));
6724: my %lt=&Apache::lonlocal::texthash (
6725: 'prv' => "Privilege",
6726: 'crl' => "Course Level",
6727: 'dml' => "Domain Level",
6728: 'ssl' => "System Level");
6729: my %cr = (
6730: course => '_c',
6731: domain => '_d',
6732: system => '_s',
6733: );
6734:
1.180 raeburn 6735: my $output=&Apache::loncommon::start_data_table($add_class,$id).
1.175 raeburn 6736: &Apache::loncommon::start_data_table_header_row().
6737: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
6738: '</th><th>'.$lt{'ssl'}.'</th>'.
6739: &Apache::loncommon::end_data_table_header_row();
6740: foreach my $priv (sort(keys(%{$full}))) {
6741: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
6742: $output .= &Apache::loncommon::start_data_table_row().
6743: '<td><span id="'.$prefix.$priv.'">'.$privtext.'</span></td>';
6744: foreach my $type ('course','domain','system') {
6745: if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
6746: $output .= '<td> </td>';
6747: } else {
6748: $output .= '<td>'.
6749: ($levels->{$type}{$priv}?'<input type="checkbox" id="'.$prefix.$priv.$cr{$type}.'"'.
6750: ' name="'.$prefix.$priv.$cr{$type}.'"'.
6751: ($levelscurrent->{$type}{$priv}?' checked="checked"':'').' />':' ').
6752: '</td>';
6753: }
6754: }
6755: $output .= &Apache::loncommon::end_data_table_row();
6756: }
6757: $output .= &Apache::loncommon::end_data_table();
6758: return $output;
6759: }
6760:
6761: sub custom_role_privs {
6762: my ($privs,$full,$levels,$levelscurrent)= @_;
6763: return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
6764: (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
6765: my %cr = (
6766: course => 'cr:c',
6767: domain => 'cr:d',
6768: system => 'cr:s',
6769: );
6770: foreach my $type ('course','domain','system') {
6771: foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
6772: my ($priv,$restrict)=split(/\&/,$item);
6773: if (!$restrict) { $restrict='F'; }
6774: $levels->{$type}->{$priv}=$restrict;
6775: if ($privs->{$type}=~/\:$priv/) {
6776: $levelscurrent->{$type}->{$priv}=1;
6777: }
6778: $full->{$priv}=1;
6779: }
6780: }
6781: return;
6782: }
6783:
6784: sub custom_template_roles {
6785: my ($context,$crstype) = @_;
6786: my @template_roles = ("in","ta","ep");
6787: if (($context eq 'domain') || ($context eq 'domprefs')) {
6788: push(@template_roles,"ad");
6789: }
6790: push(@template_roles,"st");
6791: if ($context eq 'domain') {
6792: unshift(@template_roles,('co','cc'));
6793: } else {
6794: if ($crstype eq 'Community') {
6795: unshift(@template_roles,'co');
6796: } else {
6797: unshift(@template_roles,'cc');
6798: }
6799: }
6800: return @template_roles;
6801: }
6802:
6803: sub custom_roledefs_js {
6804: my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
6805: my $button_code = "\n";
6806: my $head_script = "\n";
6807: my (%roletitlestr,$rolenamestr);
6808: my %role_titles = (
6809: Course => [],
6810: Community => [],
6811: );
6812: $head_script .= '<script type="text/javascript">'."\n"
6813: .'// <![CDATA['."\n";
6814: if (ref($templaterolesref) eq 'ARRAY') {
6815: if ($context eq 'domain') {
6816: $rolenamestr = join("','",@{$templaterolesref});
6817: }
6818: foreach my $role (@{$templaterolesref}) {
6819: $head_script .= &make_script_template($role,$crstype,$formname);
6820: if ($context eq 'domain') {
6821: foreach my $type ('Course','Community') {
6822: push(@{$role_titles{$type}},&Apache::lonnet::plaintext($role,$type));
6823: }
6824: }
6825: }
6826: }
6827: if ($context eq 'domain') {
6828: foreach my $type ('Course','Community') {
6829: $roletitlestr{$type} = join("','",@{$role_titles{$type}});
6830: }
6831: my %pt = (
6832: Community => {
6833: cst => &mt('Grant/revoke role of Member'),
6834: mdc => &mt('Edit community contents'),
6835: pch => &mt('Post discussion on community resources'),
6836: pfo => &mt('Print for other users and entire community'),
6837: },
6838: Course => {
6839: cst => &mt('Grant/revoke role of Student'),
6840: mdc => &mt('Edit course contents'),
6841: pch => &mt('Post discussion on course resources'),
6842: pfo => &mt('Print for other users and entire course'),
6843: },
6844: );
6845: $head_script .= <<"ENDJS";
6846: function customSwitchType(prefix) {
6847: var privnames = new Array('cst','mdc','pch','pfo');
6848: var privtxtcrs = new Array('$pt{Course}{cst}','$pt{Course}{mdc}','$pt{Course}{pch}','$pt{Course}{pfo}');
6849: var privtxtcom = new Array('$pt{Community}{cst}','$pt{Community}{mdc}','$pt{Community}{pch}','$pt{Community}{pfo}');
6850: var rolenames = new Array('$rolenamestr');
6851: var rolescrs = new Array('$roletitlestr{Course}');
6852: var rolescom = new Array('$roletitlestr{Community}');
6853: var radio = prefix+'_custrolecrstype';
6854: if (document.$formname.elements[radio].length > 1) {
6855: for (var i=0; i<document.$formname.elements[radio].length; i++) {
6856: if (document.$formname.elements[radio][i].checked) {
6857: if ((document.getElementById(prefix+'bre_s')) && (document.getElementById(prefix+'bro_s'))) {
6858: if (document.$formname.elements[radio][i].value == 'Community') {
6859: if (document.getElementById(prefix+'bre_s').checked) {
6860: document.getElementById(prefix+'bro_s').checked = true;
6861: document.getElementById(prefix+'bre_s').checked = false;
6862:
6863: }
6864: document.getElementById(prefix+'bre_s').style.visibility = 'hidden';
6865: } else {
6866: document.getElementById(prefix+'bre_s').style.visibility = 'visible';
6867: if (document.getElementById(prefix+'bro_s').checked) {
6868: document.getElementById(prefix+'bre_s').checked = true;
6869: document.getElementById(prefix+'bro_s').checked = false;
6870: }
6871: }
6872: }
6873: for (var j=0; j<privnames.length; j++) {
6874: if (document.getElementById(prefix+privnames[j])) {
6875: if (document.getElementById(prefix+privnames[j])) {
6876: if (document.$formname.elements[radio][i].value == 'Course') {
6877: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcrs[j];
6878: } else {
6879: document.getElementById(prefix+privnames[j]).innerHTML = privtxtcom[j];
6880: }
6881: }
6882: }
6883: }
6884: for (var j=0; j<rolenames.length; j++) {
6885: if (document.getElementById(prefix+rolenames[j])) {
6886: if (document.getElementById(prefix+rolenames[j])) {
6887: if (document.$formname.elements[radio][i].value == 'Course') {
6888: document.getElementById(prefix+rolenames[j]).value = rolescrs[j];
6889: if (rolenames[j] == 'cc') {
6890: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
6891: }
6892: if (rolenames[j] == 'co') {
6893: document.getElementById(prefix+rolenames[j]).style.display = 'none';
6894: }
6895: } else {
6896: document.getElementById(prefix+rolenames[j]).value = rolescom[j];
6897: if (rolenames[j] == 'cc') {
6898: document.getElementById(prefix+rolenames[j]).style.display = 'none';
6899: }
6900: if (rolenames[j] == 'co') {
6901: document.getElementById(prefix+rolenames[j]).style.display = 'inline';
6902: }
6903: }
6904: }
6905: }
6906: }
6907: }
6908: }
6909: }
6910: return;
6911: }
6912: ENDJS
6913: }
6914: $head_script .= "\n".$jsback."\n"
6915: .'// ]]>'."\n"
6916: .'</script>'."\n";
6917: return $head_script;
6918: }
6919:
6920: # --------------------------------------------------------
6921: sub make_script_template {
6922: my ($role,$crstype,$formname) = @_;
6923: my $return_script = 'function set_'.$role.'(prefix) {'."\n";
6924: my (%full_by_level,%role_priv);
6925: foreach my $level ('c','d','s') {
6926: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
6927: next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
6928: my ($priv,$restrict)=split(/\&/,$item);
6929: $full_by_level{$level}{$priv}=1;
6930: }
6931: $role_priv{$level} = {};
6932: my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
6933: foreach my $priv (@temp) {
6934: my ($priv_item, $dummy) = split(/\&/,$priv);
6935: $role_priv{$level}{$priv_item} = 1;
6936: }
6937: }
6938: my %to_check = (
6939: c => ['c','d','s'],
6940: d => ['d','s'],
6941: s => ['s'],
6942: );
6943: foreach my $level ('c','d','s') {
6944: if (ref($full_by_level{$level}) eq 'HASH') {
6945: foreach my $priv (keys(%{$full_by_level{$level}})) {
6946: my $value = 'false';
6947: if (ref($to_check{$level}) eq 'ARRAY') {
6948: foreach my $lett (@{$to_check{$level}}) {
6949: if (exists($role_priv{$lett}{$priv})) {
6950: $value = 'true';
6951: last;
6952: }
6953: }
6954: $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
6955: }
6956: }
6957: }
6958: }
6959: $return_script .= '}'."\n";
6960: return ($return_script);
6961: }
6962: # ----------------------------------------------------------
6963: sub make_button_code {
6964: my ($role,$crstype,$display,$prefix) = @_;
6965: my $label = &Apache::lonnet::plaintext($role,$crstype);
6966: my $button_code = '<input type="button" onclick="set_'.$role."('$prefix'".')" '.
6967: 'id="'.$prefix.$role.'" value="'.$label.'" '.
6968: 'style="display:'.$display.'" />';
6969: return ($button_code);
6970: }
6971:
6972: sub custom_role_update {
6973: my ($rolename,$prefix) = @_;
6974: # ------------------------------------------------------- What can be assigned?
6975: my %privs = (
6976: c => '',
6977: d => '',
6978: s => '',
6979: );
6980: foreach my $level (keys(%privs)) {
6981: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
6982: my ($priv,$restrict)=split(/\&/,$item);
6983: if (!$restrict) { $restrict=''; }
6984: if ($env{'form.'.$prefix.$priv.'_'.$level}) {
6985: $privs{$level} .=':'.$item;
6986: }
6987: }
6988: }
6989: return %privs;
6990: }
6991:
1.180 raeburn 6992: sub adhoc_status_types {
6993: my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
6994: my $output = &Apache::loncommon::start_data_table();
6995: my $numinrow = 3;
6996: my $rem;
6997: if (ref($types) eq 'ARRAY') {
6998: for (my $i=0; $i<@{$types}; $i++) {
6999: if (defined($usertypes->{$types->[$i]})) {
7000: my $rem = $i%($numinrow);
7001: if ($rem == 0) {
7002: if ($i > 0) {
7003: $output .= &Apache::loncommon::end_data_table_row();
7004: }
7005: $output .= &Apache::loncommon::start_data_table_row();
7006: }
7007: my $check;
7008: if (ref($selectedref) eq 'ARRAY') {
7009: if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
7010: $check = ' checked="checked"';
7011: }
7012: }
7013: $output .= '<td>'.
7014: '<span class="LC_nobreak"><label>'.
7015: '<input type="checkbox" name="'.$context.$role.'_status" '.
7016: 'value="'.$types->[$i].'"'.$check.$disabled.' />'.
7017: $usertypes->{$types->[$i]}.'</label></span></td>';
7018: }
7019: }
7020: $rem = @{$types}%($numinrow);
7021: }
7022: my $colsleft = $numinrow - $rem;
7023: if (($rem == 0) && (@{$types} > 0)) {
7024: $output .= &Apache::loncommon::start_data_table_row();
7025: }
7026: if ($colsleft > 1) {
7027: $output .= '<td colspan="'.$colsleft.'">';
7028: } else {
7029: $output .= '<td>';
7030: }
7031: my $defcheck;
7032: if (ref($selectedref) eq 'ARRAY') {
7033: if (grep(/^default$/,@{$selectedref})) {
7034: $defcheck = ' checked="checked"';
7035: }
7036: }
7037: $output .= '<span class="LC_nobreak"><label>'.
7038: '<input type="checkbox" name="'.$context.$role.'_status"'.
7039: 'value="default"'.$defcheck.$disabled.' />'.
7040: $othertitle.'</label></span></td>'.
7041: &Apache::loncommon::end_data_table_row().
7042: &Apache::loncommon::end_data_table();
7043: return $output;
7044: }
7045:
7046: sub adhoc_staff {
7047: my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
7048: my $output;
7049: if (ref($adhocref) eq 'HASH') {
7050: my %by_fullname;
7051: my $numinrow = 4;
7052: my $rem;
7053: my @personnel = keys(%{$adhocref});
7054: if (@personnel) {
7055: foreach my $person (@personnel) {
7056: my ($uname,$udom) = split(/:/,$person);
7057: my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
7058: $by_fullname{$fullname} = $person;
7059: }
7060: my @sorted = sort(keys(%by_fullname));
7061: my $count = scalar(@sorted);
7062: $output = &Apache::loncommon::start_data_table();
7063: for (my $i=0; $i<$count; $i++) {
7064: my $rem = $i%($numinrow);
7065: if ($rem == 0) {
7066: if ($i > 0) {
7067: $output .= &Apache::loncommon::end_data_table_row();
7068: }
7069: $output .= &Apache::loncommon::start_data_table_row();
7070: }
7071: my $check;
7072: my $user = $by_fullname{$sorted[$i]};
7073: if (ref($selectedref) eq 'ARRAY') {
7074: if (grep(/^\Q$user\E$/,@{$selectedref})) {
7075: $check = ' checked="checked"';
7076: }
7077: }
7078: if ($i == $count-1) {
7079: my $colsleft = $numinrow - $rem;
7080: if ($colsleft > 1) {
7081: $output .= '<td colspan="'.$colsleft.'">';
7082: } else {
7083: $output .= '<td>';
7084: }
7085: } else {
7086: $output .= '<td>';
7087: }
7088: $output .= '<span class="LC_nobreak"><label>'.
7089: '<input type="checkbox" name="'.$context.$role.'_staff_'.$access.'" '.
7090: 'value="'.$user.'"'.$check.$disabled.' />'.$sorted[$i].
7091: '</label></span></td>';
7092: if ($i == $count-1) {
7093: $output .= &Apache::loncommon::end_data_table_row();
7094: }
7095: }
7096: $output .= &Apache::loncommon::end_data_table();
7097: }
7098: }
7099: return $output;
7100: }
7101:
7102:
1.1 raeburn 7103: 1;
7104:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>