Annotation of loncom/interface/loncoursequeueadmin.pm, revision 1.13
1.1 raeburn 1: # The LearningOnline Network
2: # Utilities to administer domain course requests and course self-enroll requests
3: #
1.13 ! raeburn 4: # $Id: loncoursequeueadmin.pm,v 1.12 2009/11/18 19:15:45 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: =head1 NAME
31:
32: Apache::loncoursequeueadmin.pm
33:
34: =head1 SYNOPSIS
35:
1.13 ! raeburn 36: Administration utilities used by domain coordinators for queued course creation requests, and by course coordinators for queued self-enrollment requests.
1.1 raeburn 37:
38: This is part of the LearningOnline Network with CAPA project
39: described at http://www.lon-capa.org.
40:
41: =head1 SUBROUTINES
42:
43: =over
44:
45: =item send_selfserve_notification()
46:
47: =item display_queued_requests()
48:
49: =item update_request_queue()
50:
51: =item get_student_counts()
52:
1.13 ! raeburn 53: =item course_creation()
! 54:
! 55: =item build_batchcreatehash()
! 56:
! 57: =item can_clone_course()
! 58:
! 59: =item get_processtype()
! 60:
1.1 raeburn 61: =back
62:
63: =cut
64:
65: package Apache::loncoursequeueadmin;
66:
67: use strict;
68: use Apache::Constants qw(:common :http);
69: use Apache::lonnet;
70: use Apache::loncommon;
71: use Apache::lonmsg;
72: use Apache::lonlocal;
1.2 raeburn 73: use Apache::lonuserutils;
1.1 raeburn 74: use LONCAPA;
75:
76: sub send_selfserve_notification {
1.2 raeburn 77: my ($notifylist,$textstr,$cid,$contextdesc,$timestamp,$context,$sender,
1.12 raeburn 78: $approvedlist,$rejectedlist,$crstype) = @_;
1.1 raeburn 79: # FIXME locallocaltime needs to be able to take $sender_lh as an argument
80: # so this can be localized to the recipients date display format/time zone
81: $timestamp =&Apache::lonlocal::locallocaltime($timestamp);
82: my $msgcc;
1.12 raeburn 83: my ($rawsubj,@rawmsg,$subject,$message,$reviewer,$msgtxt);
1.1 raeburn 84: if ($context eq 'coursemanagers') {
85: $rawsubj = 'Self-enrollment requests processed';
86: push(@rawmsg,{
1.10 raeburn 87: mt => 'Enrollment requests in the following course: [_1] have been processed.',
1.3 raeburn 88: args => ["\n $contextdesc"],
1.1 raeburn 89: });
90: } elsif ($context eq 'domainmanagers') {
1.12 raeburn 91: $rawsubj = 'Course/Community requests reviewed';
1.1 raeburn 92: push(@rawmsg,{
1.12 raeburn 93: mt => 'Course/Community creation requests in the following domain: [_1] have been reviewed.',
1.3 raeburn 94: args => ["\n $contextdesc"],
1.1 raeburn 95: });
96: if (ref($textstr) eq 'ARRAY') {
97: push(@rawmsg,@{$textstr});
98: }
99: } elsif ($context eq 'enroller') {
100: $rawsubj = 'Enrollment request';
1.12 raeburn 101: if ($crstype eq 'community') {
102: $msgtxt = 'Your request for enrollment in the following community: [_1]requested on [_2]has been reviewed by a Coordinator.'
103: } else {
104: $msgtxt = 'Your request for enrollment in the following course: [_1]requested on [_2]has been reviewed by a Course Coordinator.';
105: }
1.1 raeburn 106: push(@rawmsg,{
1.12 raeburn 107: mt => $msgtxt,
1.2 raeburn 108: args => ["\n ".$contextdesc.",\n",$timestamp.",\n"],
1.1 raeburn 109:
110: });
111: if (ref($textstr) eq 'ARRAY') {
112: push(@rawmsg,@{$textstr});
113: }
114: } elsif ($context eq 'courserequestor') {
1.12 raeburn 115: if ($crstype eq 'Community') {
116: $rawsubj = 'Community request';
117: $msgtxt = 'Your request for creation of the following community: [_1]requested on [_2]has been reviewed by a Domain Coordinator.';
118: } else {
119: $rawsubj = 'Course request';
120: $msgtxt = 'Your request for creation of the following course: [_1]requested on [_2]has been reviewed by a Domain Coordinator.';
121: }
1.1 raeburn 122: push(@rawmsg,{
1.12 raeburn 123: mt => $msgtxt,
1.2 raeburn 124: args => ["\n".$contextdesc.",\n",$timestamp.",\n"],
1.1 raeburn 125:
126: });
127: if (ref($textstr) eq 'ARRAY') {
128: push(@rawmsg,@{$textstr});
129: }
130: } elsif ($context eq 'coursereq') {
1.12 raeburn 131: if ($crstype eq 'community') {
132: $rawsubj = 'Community request to review';
133: $msgtxt = 'Creation of the following community: [_1]was requested by [_2] on [_3].';
134: } else {
135: $rawsubj = 'Course request to review';
136: $msgtxt = 'Creation of the following course: [_1]was requested by [_2] on [_3].';
137: }
1.1 raeburn 138: push(@rawmsg,{
1.12 raeburn 139: mt => $msgtxt,
1.2 raeburn 140: args => ["\n $contextdesc\n",$textstr,$timestamp],
1.1 raeburn 141: },
142: {
1.12 raeburn 143: mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Course and community creation -> Approve or reject requests[_3]to display a list of pending requests, which you can either approve or reject.',
1.2 raeburn 144: args => ["\n","\n\n ","\n\n"],
1.1 raeburn 145: });
146: } elsif ($context eq 'selfenrollreq') {
147: $rawsubj = 'Self-enrollment request';
1.12 raeburn 148: if ($crstype eq 'community') {
149: $msgtxt = 'Enrollment in the following community: [_1] was requested by [_2] on [_3].'
150: } else {
151: $msgtxt = 'Enrollment in the following course: [_1] was requested by [_2] on [_3].'
152: }
1.1 raeburn 153: push(@rawmsg,{
1.12 raeburn 154: mt => $msgtxt,
1.2 raeburn 155: args => ["\n $contextdesc\n",$textstr,$timestamp."\n"],
156: });
1.12 raeburn 157: my $directions;
158: if ($crstype eq 'community') {
159: $directions = 'As Coordinator, use: [_1]Main Menu -> Manage Community Users -> Enrollment Requests[_2]to display a list of pending enrollment requests, which you can either approve or reject.';
1.2 raeburn 160: } else {
1.12 raeburn 161: $directions = 'As Course Coordinator, use: [_1]Main Menu -> Manage Course Users -> Enrollment Requests[_2]to display a list of pending enrollment requests, which you can either approve or reject.';
162: }
163: push(@rawmsg,
1.1 raeburn 164: {
1.12 raeburn 165: mt => $directions,
1.2 raeburn 166: args => [" \n\n","\n"],
1.1 raeburn 167: });
1.2 raeburn 168:
1.1 raeburn 169: }
170: my @to_notify = split(/,/,$notifylist);
171: my $numsent = 0;
172: my @recusers;
173: my @recudoms;
174: foreach my $cc (@to_notify) {
175: my ($ccname,$ccdom) = split(/:/,$cc);
176: if (!exists($msgcc->{$ccname.':'.$ccdom})) {
177: push(@recusers,$ccname);
178: push(@recudoms,$ccdom);
179: $msgcc->{$ccname.':'.$ccdom}='';
180: $numsent ++;
181: }
182: }
183: my %reciphash = (
184: cc => $msgcc,
185: );
186: my ($uname,$udom);
187: if ($sender =~ /:/) {
188: ($uname,$udom) = split(/:/,$sender);
1.2 raeburn 189: } elsif ($context eq 'course') {
1.1 raeburn 190: $uname = $sender;
191: my %courseinfo = &Apache::lonnet::coursedescription($cid);
192: $udom = $courseinfo{'num'};
193: }
194: my %sentmessage;
195: my $stamp = time;
196: my $msgcount = &Apache::lonmsg::get_uniq();
197: my $sender_lh = &Apache::loncommon::user_lang($uname,$udom,$cid);
198: $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj);
199: $message = '';
200: foreach my $item (@rawmsg) {
201: if (ref($item) eq 'HASH') {
202: $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
203: }
204: }
205: &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,\@recusers,\@recudoms);
206: my ($recipid,$recipstatus) = &Apache::lonmsg::store_recipients($subject,$uname,$udom,\%reciphash);
207: my $status;
208: foreach my $recip (sort(keys(%{$msgcc}))) {
209: my ($ccname,$ccdom) = split(/:/,$recip);
210: my $recip_lh = &Apache::loncommon::user_lang($ccname,$ccdom,$cid);
211: my $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj);
212: my $message = '';
213: foreach my $item (@rawmsg) {
214: if (ref($item) eq 'HASH') {
215: $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},
216: @{$item->{args}})."\n";
217: }
218: }
1.10 raeburn 219: if ($context eq 'coursemanagers') {
1.1 raeburn 220: if ($approvedlist) {
221: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved enrollments:')."\n".$approvedlist;
222: }
223: if ($rejectedlist) {
224: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected enrollments:')."\n".$rejectedlist;
225: }
226: } elsif ($context eq 'domainmanagers') {
227: if ($approvedlist) {
228: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved course requests:')."\n".$approvedlist;
229: }
230: if ($rejectedlist) {
231: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected course requests:')."\n".$rejectedlist;
232: }
233: }
234: $status .= &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,1,\%sentmessage,undef,undef,undef,1,$recipid).',';
235: }
236: $status =~ s/,$//;
237: return ($recipstatus,$status);
238: }
239:
240: sub display_queued_requests {
241: my ($context,$dom,$cnum) = @_;
1.2 raeburn 242: my ($namespace,$formaction,$nextelement,%requesthash);
1.1 raeburn 243: if ($context eq 'course') {
244: $formaction = '/adm/createuser';
245: $namespace = 'selfenrollrequests';
246: %requesthash = &Apache::lonnet::dump($namespace,$dom,$cnum);
1.2 raeburn 247: $nextelement = '<input type="hidden" name="state" value="done" />';
1.1 raeburn 248: } else {
249: $formaction = '/adm/createcourse';
250: $namespace = 'courserequestqueue';
1.6 raeburn 251: %requesthash = &Apache::lonnet::dump_dom($namespace,$dom,'_approval');
1.2 raeburn 252: $nextelement = '<input type="hidden" name="phase" value="requestchange" />';
1.1 raeburn 253: }
254: my ($output,%queue_by_date,%crstypes);
255: if (keys(%requesthash) > 0) {
1.2 raeburn 256: $output = '<form method="post" name="changequeue" action="'.$formaction.'" />'."\n".
257: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
258: $nextelement."\n".
1.1 raeburn 259: &Apache::loncommon::start_data_table().
260: &Apache::loncommon::start_data_table_header_row().
261: '<th>'.&mt('Action').'</th>'.
262: '<th>'.&mt('Requestor').'</th>';
263: if ($context eq 'course') {
264: $output .= '<th>'.&mt('Section').'</th>'.
265: '<th>'.&mt('Date requested').'</th>';
1.12 raeburn 266: } else {
1.1 raeburn 267: %crstypes = &Apache::lonlocal::texthash (
268: official => 'Official course',
269: unofficial => 'Unofficial course',
270: community => 'Community',
271: );
272: $output .= '<th>'.&mt('Type').'</th>'.
273: '<th>'.&mt('Date requested').'</th>'.
274: '<th>'.&mt('Details').'</th>';
275: }
276: $output .= &Apache::loncommon::end_data_table_header_row();
277: foreach my $item (keys(%requesthash)) {
278: my ($timestamp,$entry);
279: if ($context eq 'course') {
280: ($timestamp, my $usec) = split(/:/,$requesthash{$item});
281: $entry = $item.':'.$usec;
282: } else {
283: $timestamp = $requesthash{$item}{'timestamp'};
284: if (ref($requesthash{$item}) eq 'HASH') {
1.2 raeburn 285: my ($cnum,$disposition) = split('_',$item);
286: $entry = $cnum.':'.$requesthash{$item}{'ownername'}.':'.
1.1 raeburn 287: $requesthash{$item}{'ownerdom'}.':'.
288: $requesthash{$item}{'crstype'}.':'.
289: $requesthash{$item}{'description'};
290: }
291: }
292: if ($entry ne '') {
293: if (exists($queue_by_date{$timestamp})) {
294: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
295: push(@{$queue_by_date{$timestamp}},$entry);
296: }
297: } else {
298: @{$queue_by_date{$timestamp}} = ($entry);
299: }
300: }
301: }
302: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
303: my $count = 0;
304: foreach my $item (@sortedtimes) {
305: if (ref($queue_by_date{$item}) eq 'ARRAY') {
306: foreach my $request (sort(@{$queue_by_date{$item}})) {
307: my ($row,$approve,$reject,$showtime,$showsec,$namelink,
308: $detailslink,$crstype);
309: $showtime = &Apache::lonlocal::locallocaltime($item);
310: if ($context eq 'course') {
311: my ($puname,$pudom,$pusec) = split(/:/,$request);
312: $approve = $count.':'.$puname.':'.$pudom.':'.$pusec;
313: $reject = $puname.':'.$pudom;
314: $showsec = $pusec;
315: if ($showsec eq '') {
316: $showsec = &mt('none');
317: }
318: $namelink = &Apache::loncommon::aboutmewrapper(
319: &Apache::loncommon::plainname($puname,$pudom),
320: $puname,$pudom);
321:
322: } else {
1.2 raeburn 323: my ($cnum,$ownername,$ownerdom,$type,$cdesc)=split(/:/,$request,5);
1.7 raeburn 324: $detailslink='<a href="javascript:opencoursereqdisplay('.
325: "'$dom','$cnum'".');">'.$cdesc.'</a>';
1.1 raeburn 326: $crstype = $type;
327: if (defined($crstypes{$type})) {
328: $crstype = $crstypes{$type};
329: }
330: $approve = $count.':'.$cnum;
331: $reject = $cnum;
332: $namelink = &Apache::loncommon::aboutmewrapper(
333: &Apache::loncommon::plainname($ownername,$ownerdom),
334: $ownername,$ownerdom);
335: }
336: $row = '<td><span class="LC_nobreak"><label>'.
337: '<input type="checkbox" value="'.$approve.'" name="approvereq" />'.&mt('Approve').'</label></span><br />'.
338: '<span class="LC_nobreak"><label>'.
339: '<input type="checkbox" value="'.$reject.'" name="rejectreq" />'.&mt('Reject').'</label></span><br /></td>'.
340: '<td>'.$namelink.'</td>'."\n";
341: if ($context eq 'course') {
342: $row .= '<td>'.$showsec.'</td>'."\n".
343: '<td>'.$showtime.'</td>'."\n";
344: } else {
345: $row .= '<td>'.$crstype.'</td>'."\n".
346: '<td>'.$showtime.'</td>'."\n".
347: '<td>'.$detailslink.'</td>'."\n";
348: }
349: $output .= &Apache::loncommon::start_data_table_row()."\n".
350: $row.
351: &Apache::loncommon::end_data_table_row()."\n";
352: $count ++;
353: }
354: }
355: }
356: $output .= &Apache::loncommon::end_data_table().
357: '<input type="submit" name="processqueue" value="'.&mt('Save').
358: '" /></form>';
359: } else {
360: if ($context eq 'course') {
361: $output .= &mt('There are currently no enrollment requests.');
362: } else {
1.12 raeburn 363: $output .= &mt('There are currently no course or community requests awaiting approval.');
1.1 raeburn 364: }
365: }
366: return $output;
367: }
368:
369: sub update_request_queue {
370: my ($context,$cdom,$cnum,$coursedesc) = @_;
371: my ($output,$access_start,$access_end,$limit,$cap,$notifylist,$namespace,
1.2 raeburn 372: $stucounts,$idx,$classlist,%requesthash,$cid,$hostname,$protocol,
373: $domdesc,$now,$sender,$approvedmsg,$rejectedmsg,$beneficiary,
374: @existing,@missingreq,@invalidusers,@limitexceeded,@completed,
375: @processing_errors,@warn_approves,@warn_rejects,@approvals,
1.5 raeburn 376: @rejections,@rejectionerrors,@nopermissions,%courseroles,
1.12 raeburn 377: %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype);
1.1 raeburn 378: @approvals = &Apache::loncommon::get_env_multiple('form.approvereq');
379: @rejections = &Apache::loncommon::get_env_multiple('form.rejectreq');
380: $now = time;
381: $sender = $env{'user.name'}.':'.$env{'user.domain'};
382: if ($context eq 'course') {
383: $namespace = 'selfenrollrequests';
384: $beneficiary = 'enroller';
385: $cid = $env{'request.course.id'};
1.12 raeburn 386: $crstype = lc(&Apache::loncommon::course_type());
1.1 raeburn 387: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
388: $hostname = &Apache::lonnet::hostname($chome);
389: $protocol = $Apache::lonnet::protocol{$chome};
390: $protocol = 'http' if ($protocol ne 'https');
391: %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
392: $access_start = $env{'course.'.$cid.'.internal.selfenroll_start_access'};
393: $access_end = $env{'course.'.$cid.'.internal.selfenroll_end_access'};
394: $limit = $env{'course.'.$cid.'.internal.selfenroll_limit'};
395: $cap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
396: $notifylist = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
397: ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
398: $approvedmsg = [{
399: mt => 'Your request for enrollment has been approved.',
400: },
401: {
402: mt => 'Visit [_1], to log-in and access the course',
403: args => [$protocol.'://'.$hostname],
404: }];
405: $rejectedmsg = [{
406: mt => 'Your request for enrollment has not been approved.',
407: }];
408: } else {
1.2 raeburn 409: $domdesc = &Apache::lonnet::domain($cdom);
410: $namespace = 'courserequestqueue';
411: $beneficiary = 'courserequestor';
1.6 raeburn 412: %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom,'_approval');
1.2 raeburn 413: my $chome = &Apache::lonnet::domain($cdom,'primary');
414: $hostname = &Apache::lonnet::hostname($chome);
415: $protocol = $Apache::lonnet::protocol{$chome};
416: $protocol = 'http' if ($protocol ne 'https');
417: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
418: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
419: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
420: $notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
421: }
422: }
1.12 raeburn 423: $approvalmsg{'course'} =
424: [{
1.2 raeburn 425: mt => 'Your course request has been approved.',
426: },
427: {
428: mt => 'Visit [_1], to log-in and access the course',
429: args => [$protocol.'://'.$hostname],
430: }];
1.12 raeburn 431: $rejectionmsg{'course'} =
432: [{
1.2 raeburn 433: mt => 'Your course request has not been approved.',
434: }];
1.12 raeburn 435:
436: $approvalmsg{'community'} =
437: [{
438: mt => 'Your community request has been approved.',
439: },
440: {
441: mt => 'Visit [_1], to log-in and access the community',
442: args => [$protocol.'://'.$hostname],
443: }];
444:
445: $rejectionmsg{'community'} =
446: [{
447: mt => 'Your community request has not been approved.',
448: }];
449:
1.2 raeburn 450: %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
451: my @roles = &Apache::lonuserutils::roles_by_context('course');
452: foreach my $role (@roles) {
453: $courseroles{$role}=&Apache::lonnet::plaintext($role,'Course');
454: }
455: foreach my $role (@roles) {
456: $communityroles{$role}=&Apache::lonnet::plaintext($role,'Community');
457: }
458:
1.1 raeburn 459: }
460: foreach my $item (sort {$a <=> $b} @approvals) {
461: if ($context eq 'course') {
462: my ($num,$uname,$udom,$usec) = split(/:/,$item);
463: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
464: if ($uhome ne 'no_host') {
465: if (exists($requesthash{$uname.':'.$udom})) {
466:
467: if (exists($classlist->{$uname.':'.$udom})) {
468: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
469: if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
470: ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
471: push(@existing,$uname.':'.$udom);
472: next;
473: }
474: }
475: }
476: } else {
477: push(@missingreq,$uname.':'.$udom);
478: next;
479: }
480: if (!grep(/^\Q$item\E$/,@rejections)) {
481: if ($limit eq 'allstudents') {
482: if ($stucounts->{$limit} >= $cap) {
483: push(@limitexceeded,$uname.':'.$udom);
484: last;
485: }
486: } elsif ($limit eq 'selfenrolled') {
487: if ($stucounts->{$limit} >= $cap) {
488: push(@limitexceeded,$uname.':'.$udom);
489: last;
490: }
491: }
492: my $result =
493: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
494: if ($result eq 'ok') {
1.2 raeburn 495: push(@completed,$uname.':'.$udom);
1.1 raeburn 496: $stucounts->{'allstudents'} ++;
497: $stucounts->{'selfenrolled'} ++;
498: &send_selfserve_notification($uname.':'.$udom,$approvedmsg,
1.12 raeburn 499: $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
1.2 raeburn 500: my %userrequest = (
501: $cdom.'_'.$cnum => {
502: timestamp => $now,
503: section => $usec,
504: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
505: status => 'approved',
506: }
507: );
1.1 raeburn 508: my $userresult =
509: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
510: if ($userresult ne 'ok') {
511: push(@warn_approves,$uname.':'.$udom);
512: }
513: } else {
1.2 raeburn 514: push(@processing_errors,$uname.':'.$udom);
1.1 raeburn 515: }
516: }
517: } else {
518: push(@invalidusers,$uname.':'.$udom);
519: }
520: } else {
1.2 raeburn 521: my ($num,$cnum) = split(':',$item);
522: if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
523: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
524: my $ownername = $requesthash{$cnum.'_approval'}{'ownername'};
525: my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'};
1.12 raeburn 526: $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
1.2 raeburn 527: my $coursedesc = $requesthash{$cnum.'_approval'}{'description'};
528: my $longroles = \%courseroles;
529: if ($crstype eq 'community') {
530: $longroles = \%communityroles;
531: }
1.5 raeburn 532: my $cancreate;
533: if ($cdom eq $ownerdom) {
534: if (&Apache::lonnet::usertools_access($ownername,$ownerdom,$crstype,
535: undef,'requestcourses')) {
536: $cancreate = 1;
537: }
538: } else {
539: my %userenv = &Apache::lonnet::userenvironment($ownerdom,$ownername,'reqcrsotherdom.'.$crstype);
540: if ($userenv{'reqcrsotherdom.'.$crstype}) {
541: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
542: if (grep(/^\Q$cdom\E:/,@doms)) {
543: $cancreate = 1;
544: }
545: }
546: }
547: if ($cancreate) {
1.2 raeburn 548: my $requestkey = $cdom.'_'.$cnum;
549: my %history =
550: &Apache::lonnet::restore($requestkey,'courserequests',
551: $ownerdom,$ownername);
552: if ((ref($history{'details'}) eq 'HASH') &&
553: ($history{'disposition'} eq 'approval')) {
554: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);
555: my $result = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg,
556: \$newusermsg,\$addresult,\$enrollcount,
557: \$response,\$keysmsg,\%domdefs,$longroles);
558: if ($result eq 'created') {
1.12 raeburn 559: if ($crstype eq 'community') {
560: $approvedmsg = $approvalmsg{'community'};
561: } else {
562: $approvedmsg = $approvalmsg{'course'};
563: }
1.2 raeburn 564: push(@completed,$cnum);
565: &send_selfserve_notification($ownername.':'.$ownerdom,$approvedmsg,
1.12 raeburn 566: $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
1.2 raeburn 567: my %reqhash = (
568: reqtime => $history{'reqtime'},
569: crstype => $history{'crstype'},
570: details => $history{'details'},
571: disposition => $history{'disposition'},
572: status => 'created',
573: adjudicator => $env{'user.name'}.':'.
574: $env{'user.domain'},
575: );
576: my $userresult =
577: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
578: 'courserequests',$ownerdom,$ownername);
579: if ($userresult eq 'ok') {
580: my %status = (
581: 'status:'.$cdom.':'.$cnum => 'created'
582: );
583: my $statusresult =
584: &Apache::lonnet::put('courserequests',\%status,
585: $ownerdom,$ownername);
586: if ($statusresult ne 'ok') {
587: push(@warn_approves,$cnum);
588: }
589: }
590: if ($userresult ne 'ok') {
591: push(@warn_approves,$cnum);
592: }
593: } else {
594: push(@processing_errors,$cnum);
595: }
596: } else {
597: push(@processing_errors,$cnum);
598: }
599: } else {
1.5 raeburn 600: push(@nopermissions,$cnum);
1.2 raeburn 601: }
602: } else {
603: push(@existing,$cnum);
604: }
605: } else {
606: push(@missingreq,$cnum);
607: }
1.1 raeburn 608: }
609: }
1.2 raeburn 610: my @changes = (@completed,@rejections);
611: if ($context eq 'domain') {
612: @changes = map {$_.'_approval'} (@changes);
613: }
1.1 raeburn 614: if (@rejections) {
1.3 raeburn 615: foreach my $item (@rejections) {
1.1 raeburn 616: if ($context eq 'course') {
1.3 raeburn 617: my $user = $item;
1.2 raeburn 618: &send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc,
1.12 raeburn 619: $now,$beneficiary,$sender,undef,undef,$crstype);
1.1 raeburn 620: my ($uname,$udom) = split(/:/,$user);
621: my %userrequest = (
622: $cdom.'_'.$cnum => {
623: timestamp => $now,
624: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
625: status => 'rejected',
626: }
627: );
628: my $userresult =
629: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
630: if ($userresult ne 'ok') {
631: push(@warn_rejects,$user);
632: }
633: } else {
1.3 raeburn 634: my $cnum = $item;
635: if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
636: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
637: my $requestkey = $cdom.'_'.$cnum;
1.2 raeburn 638: my $ownername = $requesthash{$cnum.'_approval'}{'ownername'};
639: my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'};
640: my $coursedesc = $requesthash{$cnum.'_approval'}{'description'};
1.12 raeburn 641: $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
642: if ($crstype eq 'community') {
643: $rejectedmsg = $rejectionmsg{'community'};
644: } else {
645: $rejectedmsg = $rejectionmsg{'course'};
646: }
1.2 raeburn 647: &send_selfserve_notification($ownername.':'.$ownerdom,$rejectedmsg,
648: $cid,$coursedesc,$now,$beneficiary,
1.12 raeburn 649: $sender,undef,undef,$crstype);
1.2 raeburn 650: my %history =
1.3 raeburn 651: &Apache::lonnet::restore($requestkey,'courserequests',
1.2 raeburn 652: $ownerdom,$ownername);
653: if ((ref($history{'details'}) eq 'HASH') &&
654: ($history{'disposition'} eq 'approval')) {
655: my %reqhash = (
656: reqtime => $history{'reqtime'},
657: crstype => $history{'crstype'},
658: details => $history{'details'},
659: disposition => $history{'disposition'},
660: status => 'rejected',
661: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
662: );
663: my $userresult =
1.3 raeburn 664: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
665: 'courserequests',$ownerdom,$ownername);
666: if ($userresult eq 'ok') {
667: my %status = (
668: 'status:'.$cdom.':'.$cnum => 'rejected'
669: );
670: my $statusresult =
671: &Apache::lonnet::put('courserequests',\%status,
672: $ownerdom,$ownername);
673: if ($statusresult ne 'ok') {
674: push(@warn_rejects,$cnum);
675: }
676: } else {
677: push(@warn_rejects,$cnum);
1.2 raeburn 678: }
1.3 raeburn 679: } else {
680: push(@warn_rejects,$cnum);
1.2 raeburn 681: }
1.3 raeburn 682: } else {
683: push(@existing,$cnum);
1.2 raeburn 684: }
1.3 raeburn 685: } else {
686: push(@rejectionerrors,$cnum);
1.2 raeburn 687: }
1.1 raeburn 688: }
689: }
690: }
691: if (@changes) {
692: my $delresult;
693: if ($context eq 'course') {
694: $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
695: } else {
696: $delresult = &Apache::lonnet::del_dom($namespace,\@changes,$cdom);
697: }
698: if ($delresult eq 'ok') {
699: my $namelink =
700: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
701: my ($chgmsg,$approvedlist,$rejectedlist);
702: if ($context eq 'course') {
703: $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
1.2 raeburn 704: if (@completed) {
705: $approvedlist = join("\n",@completed);
1.12 raeburn 706: if ($crstype eq 'community') {
707: $output .= '<p>'.&mt('The following were enrolled in the community:').'<ul>';
708: } else {
709: $output .= '<p>'.&mt('The following were enrolled in the course:').'<ul>';
710: }
1.2 raeburn 711: foreach my $user (@completed) {
1.1 raeburn 712: my ($uname,$udom) = split(/:/,$user);
713: my $userlink =
714: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
715: $output .= '<li>'.$userlink.'</li>';
716: }
717: $output .= '</ul></p>';
718: }
719: if (@rejections) {
720: $rejectedlist = join("\n",@rejections);
721: $output .= '<p>'.&mt('The following enrollment requests were rejected:').'<ul>';
722: foreach my $user (@rejections) {
723: $output .= '<li>'.$user.'</li>';
724: }
725: $output .= '</ul></p>';
726: }
1.2 raeburn 727: if ($notifylist ne '') {
728: &send_selfserve_notification($notifylist,$chgmsg,$cid,$coursedesc,
729: $now,'coursemanagers',$sender,
1.12 raeburn 730: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 731: }
1.1 raeburn 732: } else {
1.12 raeburn 733: $chgmsg = "'Action was taken on the following course and community requests by [_1].',$namelink";
1.2 raeburn 734: if (@completed) {
735: $approvedlist = join("\n",@completed);
1.12 raeburn 736: $output .= '<p>'.&mt('The following courses/communities were created:').'<ul>';
1.2 raeburn 737: foreach my $cnum (@completed) {
738: my $showcourse;
739: if (ref($requesthash{$cnum.'_approval'})) {
740: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
741: } else {
742: $showcourse = $cnum;
743: }
744: my $syllabuslink =
745: &Apache::loncommon::syllabuswrapper($showcourse,$cnum,$cdom);
746: $output .= '<li>'.$syllabuslink.'</li>';
747: }
748: $output .= '</ul></p>';
749: }
750: if (@rejections) {
751: $rejectedlist = join("\n",@rejections);
752: $output .= '<p>'.&mt('The following requests were rejected:').'<ul>';
753: foreach my $cnum (@rejections) {
754: my $showcourse;
755: if (ref($requesthash{$cnum.'_approval'})) {
756: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
757: } else {
758: $showcourse = $cnum;
759: }
760: $output .= '<li>'.$showcourse.'</li>';
761: }
762: $output .= '</ul></p>';
763: }
764: if ($notifylist ne '') {
765: &send_selfserve_notification($notifylist,$chgmsg,$cid,$domdesc,
766: $now,'domainmanagers',$sender,
1.12 raeburn 767: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 768: }
1.1 raeburn 769: }
770: }
771: }
772: if (@existing) {
773: if ($context eq 'course') {
774: $output .= '<p>'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'<ul>';
775: foreach my $user (@existing) {
776: $output .= '<li>'.$user.'</li>';
777: }
778: $output .= '</ul></p>';
779: } else {
1.12 raeburn 780: $output .= '<p>'.&mt('The following course/community creation requests were deleted because the course or community has already been created:').'<ul>';
1.2 raeburn 781: foreach my $cnum (@existing) {
782: my $showcourse;
783: my %coursehash = &Apache::lonnet::coursedescription($cdom.'/'.$cnum);
784: if ($coursehash{'description'} ne '') {
785: $showcourse = $coursehash{'description'};
786: } else {
787: $showcourse = $cnum;
788: }
789: $output .= '<li>'.$showcourse.'</li>';
790: }
791: $output .= '</ul></p>';
1.1 raeburn 792: }
793: }
794: if (@missingreq) {
795: if ($context eq 'course') {
796: $output .= '<p>'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'<ul>';
797: foreach my $user (@missingreq) {
798: $output .= '<li>'.$user.'</li>';
799: }
800: $output .= '</ul></p>';
1.2 raeburn 801: } else {
1.12 raeburn 802: $output .= '<p>'.&mt('The following course/community creation requests were ignored because the request is no longer in the queue:').'<ul>';
1.2 raeburn 803: foreach my $cnum (@missingreq) {
804: $output .= '<li>'.$cnum.'</li>';
805: }
806: $output .= '</ul></p>';
807:
1.1 raeburn 808: }
809: }
810: if (@invalidusers) {
811: if ($context eq 'course') {
812: $output .= '<p>'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';
813: foreach my $user (@invalidusers) {
814: $output .= '<li>'.$user.'</li>';
815: }
816: $output .= '</ul></p>';
817: }
818: }
819: if (@limitexceeded) {
820: if ($context eq 'course') {
821: $output .= '<p>'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'<ul>';
822: foreach my $user (@limitexceeded) {
823: $output .= '<li>'.$user.'</li>';
824: }
825: $output .= '</ul></p>';
826: }
827: }
1.5 raeburn 828: if (@nopermissions) {
1.12 raeburn 829: $output .= '<p>'.&mt('The following course/community creation requests could not be processed because the owner does not have rights to create this type of course:').'<ul>';
1.5 raeburn 830: foreach my $cnum (@nopermissions) {
831: my $showcourse;
832: if (ref($requesthash{$cnum.'_approval'})) {
833: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
834: } else {
835: $showcourse = $cnum;
836: }
837: $output .= '<li>'.$showcourse.'</li>';
838: }
839: $output .= '</ul></p>';
840: }
1.2 raeburn 841: if (@processing_errors) {
1.1 raeburn 842: if ($context eq 'course') {
843: $output .= '<p>'.&mt('The following enrollment requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 844: foreach my $user (@processing_errors) {
1.1 raeburn 845: $output .= '<li>'.$user.'</li>';
846: }
847: $output .= '</ul></p>';
848: } else {
1.12 raeburn 849: $output .= '<p>'.&mt('The following course/community creation requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 850: foreach my $cnum (@processing_errors) {
851: my $showcourse;
852: if (ref($requesthash{$cnum.'_approval'})) {
853: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
854: } else {
855: $showcourse = $cnum;
856: }
857: $output .= '<li>'.$showcourse.'</li>';
858: }
859: $output .= '</ul></p>';
1.1 raeburn 860: }
861: }
1.3 raeburn 862: if (@rejectionerrors) {
1.12 raeburn 863: $output .= '<p>'.&mt('The following course/community creation request rejections could not be fully processed because an error occurred:').'<ul>';
1.3 raeburn 864: foreach my $cnum (@rejectionerrors) {
865: my $showcourse;
866: if (ref($requesthash{$cnum.'_approval'})) {
867: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
868: } else {
869: $showcourse = $cnum;
870: }
871: $output .= '<li>'.$showcourse.'</li>';
872: }
873: $output .= '</ul></p>';
874: }
1.2 raeburn 875: if (@warn_approves || @warn_rejects) {
1.1 raeburn 876: if ($context eq 'course') {
877: $output .= '<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>';
878: foreach my $user (@warn_approves) {
879: $output .= '<li>'.$user.'</li>';
880: }
881: $output .= '</ul></p>';
882: } else {
1.12 raeburn 883: $output .= '<p>'.&mt("For the following course/community requests an error occurred when updating the requestor's own requests record:").'<ul>';
1.2 raeburn 884: foreach my $cnum (@warn_approves,@warn_rejects) {
885: my $showcourse;
886: if (ref($requesthash{$cnum.'_approval'})) {
887: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
888: } else {
889: $showcourse = $cnum;
890: }
891: $output .= '<li>'.$showcourse.'</li>';
1.1 raeburn 892: }
893: $output .= '</ul></p>';
894: }
895: }
896: return $output;
897: }
898:
899: sub get_student_counts {
900: my ($cdom,$cnum) = @_;
901: my (%idx,%stucounts);
902: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
903: $idx{'type'} = &Apache::loncoursedata::CL_TYPE();
904: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
905: while (my ($student,$data) = each(%$classlist)) {
906: if (($data->[$idx{'status'}] eq 'Active') ||
907: ($data->[$idx{'status'}] eq 'Future')) {
908: if ($data->[$idx{'type'}] eq 'selfenroll') {
909: $stucounts{'selfenroll'} ++;
910: }
911: $stucounts{'allstudents'} ++;
912: }
913: }
914: return (\%stucounts,\%idx,$classlist);
915: }
916:
1.2 raeburn 917: sub course_creation {
918: my ($dom,$cnum,$context,$details,$logmsg,$newusermsg,$addresult,$enrollcount,$output,
919: $keysmsg,$domdefs,$longroles) = @_;
920: unless ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH') &&
921: (ref($longroles) eq 'HASH')) {
922: return 'error: Invalid request';
923: }
924: my ($result,$ownername,$ownerdom);
925: my $crstype = $details->{'crstype'};
926: if ($context eq 'domain') {
927: $ownername = $details->{'owner'};
928: $ownerdom = $details->{'domain'};
929: } else {
930: $ownername = $env{'user.name'};
931: $ownerdom = $env{'user.domain'};
932: }
933: my $owneremail;
934: my %emails = &Apache::loncommon::getemails($ownername,$ownerdom);
935: foreach my $email ('permanentemail','critnotification','notification') {
936: $owneremail = $emails{$email};
937: last if ($owneremail ne '');
938: }
1.8 raeburn 939: my %reqdetails = &build_batchcreatehash($dom,$context,$details,$owneremail,$domdefs);
1.2 raeburn 940: my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',
941: \%reqdetails,$longroles,\$logmsg,\$newusermsg,\$addresult,
942: \$enrollcount,\$output,\$keysmsg,$ownerdom,$ownername,$cnum,$crstype);
943: if ($cid eq "/$dom/$cnum") {
944: $result = 'created';
945: } else {
946: $result = 'error: '.$cid;
947: }
948: return $result;
949: }
950:
951: sub build_batchcreatehash {
1.8 raeburn 952: my ($dom,$context,$details,$owneremail,$domdefs) = @_;
1.2 raeburn 953: my %batchhash;
954: my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users};
955: if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
956: my $emailenc = &Apache::lonnet::escape($owneremail);
957: my $owner = $details->{'owner'}.':'.$details->{'domain'};
958: foreach my $item (@items) {
959: $batchhash{$item} = $details->{$item};
960: }
961: $batchhash{'title'} = $details->{'cdescr'};
962: $batchhash{'coursecode'} = $details->{'instcode'};
963: $batchhash{'emailenc'} = $emailenc;
964: $batchhash{'adds'} = $details->{'autoadds'};
965: $batchhash{'drops'} = $details->{'autodrops'};
966: $batchhash{'authtype'} = $domdefs->{'auth_def'};
967: $batchhash{'authparam'} = $domdefs->{'auth_arg_def'};
968: if ($details->{'crstype'} eq 'community') {
969: $batchhash{'crstype'} = 'Community';
970: } else {
971: $batchhash{'crstype'} = 'Course';
972: }
1.8 raeburn 973: my ($owner_firstname,$owner_lastname);
974: if ($context eq 'domain') {
975: my %userenv = &Apache::lonnet::userenvironment($details->{'domain'},
976: $details->{'owner'},
977: 'firstname','lastname');
978: $owner_firstname = $userenv{'firstname'};
979: $owner_lastname = $userenv{'lastname'};
980: } else {
981: $owner_firstname = $env{'environment.firstname'};
982: $owner_lastname = $env{'environment.lastname'};
983: }
984: if (ref($details->{'personnel'}) eq 'HASH') {
985: %{$batchhash{'users'}} = %{$details->{'personnel'}};
986: if (ref($batchhash{'users'}) eq 'HASH') {
987: foreach my $userkey (keys(%{$batchhash{'users'}})) {
988: if (ref($batchhash{'users'}{$userkey}) eq 'HASH') {
989: if (ref($batchhash{'users'}{$userkey}{'roles'}) eq 'ARRAY') {
990: foreach my $role (@{$batchhash{'users'}{$userkey}{'roles'}}) {
991: my $start = '';
992: my $end = '';
993: if ($role eq 'st') {
994: $start = $details->{'accessstart'};
995: $end = $details->{'accessend'};
996: }
997: $batchhash{'users'}{$userkey}{$role}{'start'} = $start;
998: $batchhash{'users'}{$userkey}{$role}{'end'} = $end;
999: }
1000: }
1001: }
1002: }
1003: }
1004: }
1005: $batchhash{'users'}{$owner}{firstname} = $owner_firstname;
1006: $batchhash{'users'}{$owner}{lastname} = $owner_lastname;
1007: $batchhash{'users'}{$owner}{emailenc} = $emailenc;
1008: $batchhash{'users'}{$owner}{owneremail} = $owneremail;
1.2 raeburn 1009: }
1010: return %batchhash;
1011: }
1012:
1.4 raeburn 1013: sub can_clone_course {
1.11 raeburn 1014: my ($uname,$udom,$clonecrs,$clonedom,$crstype) = @_;
1.4 raeburn 1015: my $canclone;
1.11 raeburn 1016: my $ccrole = 'cc';
1.12 raeburn 1017: if ($crstype eq 'community') {
1.11 raeburn 1018: $ccrole = 'co';
1019: }
1.4 raeburn 1020: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',['active'],
1.11 raeburn 1021: [$ccrole],[$clonedom]);
1022: if (exists($roleshash{$clonecrs.':'.$clonedom.':'.$ccrole})) {
1.4 raeburn 1023: $canclone = 1;
1024: } else {
1025: my %courseenv = &Apache::lonnet::userenvironment($clonedom,$clonecrs,('cloners'));
1026: my $cloners = $courseenv{'cloners'};
1027: if ($cloners ne '') {
1028: my @cloneable = split(',',$cloners);
1029: if (grep(/^\*$/,@cloneable)) {
1030: $canclone = 1;
1031: }
1032: if (grep(/^\*:\Q$udom\E$/,@cloneable)) {
1033: $canclone = 1;
1034: }
1035: if (grep(/^\Q$uname\E:\Q$udom\E$/,@cloneable)) {
1036: $canclone = 1;
1037: }
1038: }
1039: }
1040: return $canclone;
1041: }
1042:
1.13 ! raeburn 1043: sub get_processtype {
! 1044: my ($uname,$udom,$isadv,$dom,$crstype,$inststatuses,$domconfig) = @_;
! 1045: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
! 1046: if ($uname eq '' || $udom eq '') {
! 1047: $uname = $env{'user.name'};
! 1048: $udom = $env{'user.domain'};
! 1049: $isadv = $env{'user.adv'};
! 1050: }
! 1051: my (%userenv,%settings,$val);
! 1052: my @options = ('autolimit','validate','approval');
! 1053: if ($dom eq $udom) {
! 1054: %userenv =
! 1055: &Apache::lonnet::userenvironment($udom,$uname,'requestcourses.'.$crstype,'inststatus');
! 1056: if ($userenv{'requestcourses.'.$crstype}) {
! 1057: $val = $userenv{'requestcourses.'.$crstype};
! 1058: @{$inststatuses} = ('_custom_');
! 1059: } else {
! 1060: my ($task,%alltasks);
! 1061: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
! 1062: %settings = %{$domconfig->{'requestcourses'}};
! 1063: if (ref($settings{$crstype}) eq 'HASH') {
! 1064: if (($isadv) && ($settings{$crstype}{'_LC_adv'} ne '')) {
! 1065: $val = $settings{$crstype}{'_LC_adv'};
! 1066: @{$inststatuses} = ('_LC_adv_');
! 1067: } else {
! 1068: if ($userenv{'inststatus'} ne '') {
! 1069: @{$inststatuses} = split(',',$userenv{'inststatus'});
! 1070: } else {
! 1071: @{$inststatuses} = ('default');
! 1072: }
! 1073: foreach my $status (@{$inststatuses}) {
! 1074: if (exists($settings{$crstype}{$status})) {
! 1075: my $value = $settings{$crstype}{$status};
! 1076: next unless ($value);
! 1077: unless (exists($alltasks{$value})) {
! 1078: if (ref($alltasks{$value}) eq 'ARRAY') {
! 1079: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
! 1080: push(@{$alltasks{$value}},$status);
! 1081: }
! 1082: } else {
! 1083: @{$alltasks{$value}} = ($status);
! 1084: }
! 1085: }
! 1086: }
! 1087: }
! 1088: my $maxlimit = 0;
! 1089:
! 1090: foreach my $key (sort(keys(%alltasks))) {
! 1091: if ($key =~ /^autolimit=(\d*)$/) {
! 1092: if ($1 eq '') {
! 1093: $val ='autolimit=';
! 1094: last;
! 1095: } elsif ($1 > $maxlimit) {
! 1096: $maxlimit = $1;
! 1097: }
! 1098: }
! 1099: }
! 1100: if ($maxlimit) {
! 1101: $val = 'autolimit='.$maxlimit;
! 1102: } else {
! 1103: foreach my $option (@options) {
! 1104: if ($alltasks{$option}) {
! 1105: $val = $option;
! 1106: last;
! 1107: }
! 1108: }
! 1109: }
! 1110: }
! 1111: }
! 1112: }
! 1113: }
! 1114: } else {
! 1115: %userenv = &Apache::lonnet::userenvironment($udom,$uname,'reqcrsotherdom.'.$crstype);
! 1116: if ($userenv{'reqcrsotherdom.'.$crstype}) {
! 1117: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
! 1118: my $optregex = join('|',@options);
! 1119: foreach my $item (@doms) {
! 1120: my ($extdom,$extopt) = split(':',$item);
! 1121: if ($extdom eq $dom) {
! 1122: if ($extopt =~ /^($optregex)(=?\d*)$/) {
! 1123: $val = $1.$2;
! 1124: }
! 1125: last;
! 1126: }
! 1127: }
! 1128: @{$inststatuses} = ('_external_');
! 1129: }
! 1130: }
! 1131: return $val;
! 1132: }
! 1133:
1.1 raeburn 1134: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>