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