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