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