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