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