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