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