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