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