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