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