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