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