Annotation of loncom/interface/loncoursequeueadmin.pm, revision 1.38
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.38 ! raeburn 4: # $Id: loncoursequeueadmin.pm,v 1.37 2013/08/17 00:34:29 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.31 raeburn 73: =item is_active_author()
74:
75: =item author_prompt()
76:
77: =item reqauthor_check()
78:
79: =item process_reqauthor()
80:
1.1 raeburn 81: =back
82:
83: =cut
84:
85: package Apache::loncoursequeueadmin;
86:
87: use strict;
88: use Apache::lonnet;
89: use Apache::loncommon;
90: use Apache::lonmsg;
91: use Apache::lonlocal;
1.2 raeburn 92: use Apache::lonuserutils;
1.19 raeburn 93: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 94:
95: sub send_selfserve_notification {
1.2 raeburn 96: my ($notifylist,$textstr,$cid,$contextdesc,$timestamp,$context,$sender,
1.12 raeburn 97: $approvedlist,$rejectedlist,$crstype) = @_;
1.1 raeburn 98: # FIXME locallocaltime needs to be able to take $sender_lh as an argument
99: # so this can be localized to the recipients date display format/time zone
100: $timestamp =&Apache::lonlocal::locallocaltime($timestamp);
1.26 raeburn 101: my ($msgcc,$rawsubj,@rawmsg,$subject,$message,$reviewer,$msgtxt);
102: my ($senderuname,$senderudom) = split(':',$sender);
1.1 raeburn 103: if ($context eq 'coursemanagers') {
104: $rawsubj = 'Self-enrollment requests processed';
105: push(@rawmsg,{
1.10 raeburn 106: mt => 'Enrollment requests in the following course: [_1] have been processed.',
1.30 raeburn 107: args => ["\n$contextdesc"],
1.1 raeburn 108: });
109: } elsif ($context eq 'domainmanagers') {
1.12 raeburn 110: $rawsubj = 'Course/Community requests reviewed';
1.1 raeburn 111: push(@rawmsg,{
1.31 raeburn 112: mt => 'Course/Community creation requests in the following domain: "[_1]" have been reviewed.',
1.30 raeburn 113: args => ["\n$contextdesc"],
114: });
115: if (ref($textstr) eq 'ARRAY') {
116: push(@rawmsg,@{$textstr});
117: }
118: } elsif ($context eq 'authormanagers') {
119: $rawsubj = 'Authoring space requests reviewed';
120: push(@rawmsg,{
1.31 raeburn 121: mt => 'Authoring requests in the following domain: "[_1]" have been reviewed.',
1.30 raeburn 122: args => ["\n$contextdesc"],
1.1 raeburn 123: });
124: if (ref($textstr) eq 'ARRAY') {
125: push(@rawmsg,@{$textstr});
126: }
127: } elsif ($context eq 'enroller') {
128: $rawsubj = 'Enrollment request';
1.12 raeburn 129: if ($crstype eq 'community') {
130: $msgtxt = 'Your request for enrollment in the following community: [_1]requested on [_2]has been reviewed by a Coordinator.'
131: } else {
132: $msgtxt = 'Your request for enrollment in the following course: [_1]requested on [_2]has been reviewed by a Course Coordinator.';
133: }
1.1 raeburn 134: push(@rawmsg,{
1.12 raeburn 135: mt => $msgtxt,
1.2 raeburn 136: args => ["\n ".$contextdesc.",\n",$timestamp.",\n"],
1.1 raeburn 137:
138: });
139: if (ref($textstr) eq 'ARRAY') {
140: push(@rawmsg,@{$textstr});
141: }
142: } elsif ($context eq 'courserequestor') {
1.12 raeburn 143: if ($crstype eq 'Community') {
144: $rawsubj = 'Community request';
145: $msgtxt = 'Your request for creation of the following community: [_1]requested on [_2]has been reviewed by a Domain Coordinator.';
146: } else {
147: $rawsubj = 'Course request';
148: $msgtxt = 'Your request for creation of the following course: [_1]requested on [_2]has been reviewed by a Domain Coordinator.';
149: }
1.1 raeburn 150: push(@rawmsg,{
1.12 raeburn 151: mt => $msgtxt,
1.2 raeburn 152: args => ["\n".$contextdesc.",\n",$timestamp.",\n"],
1.1 raeburn 153:
154: });
155: if (ref($textstr) eq 'ARRAY') {
156: push(@rawmsg,@{$textstr});
157: }
1.26 raeburn 158: } elsif ($context eq 'pendingrequestor') {
159: if ($crstype eq 'Community') {
160: $rawsubj = 'Community request';
161: } else {
162: $rawsubj = 'Processed course request';
163: }
164: if (ref($textstr) eq 'ARRAY') {
165: push(@rawmsg,@{$textstr});
166: }
1.1 raeburn 167: } elsif ($context eq 'coursereq') {
1.12 raeburn 168: if ($crstype eq 'community') {
169: $rawsubj = 'Community request to review';
170: $msgtxt = 'Creation of the following community: [_1]was requested by [_2] on [_3].';
171: } else {
172: $rawsubj = 'Course request to review';
173: $msgtxt = 'Creation of the following course: [_1]was requested by [_2] on [_3].';
174: }
1.1 raeburn 175: push(@rawmsg,{
1.12 raeburn 176: mt => $msgtxt,
1.2 raeburn 177: args => ["\n $contextdesc\n",$textstr,$timestamp],
1.1 raeburn 178: },
179: {
1.12 raeburn 180: 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.31 raeburn 181: args => ["\n","\n\n","\n\n"],
1.1 raeburn 182: });
183: } elsif ($context eq 'selfenrollreq') {
184: $rawsubj = 'Self-enrollment request';
1.12 raeburn 185: if ($crstype eq 'community') {
1.31 raeburn 186: $msgtxt = 'Enrollment in the following community: [_1]was requested by [_2] on [_3].'
1.12 raeburn 187: } else {
1.31 raeburn 188: $msgtxt = 'Enrollment in the following course: [_1]was requested by [_2] on [_3].'
1.12 raeburn 189: }
1.1 raeburn 190: push(@rawmsg,{
1.12 raeburn 191: mt => $msgtxt,
1.2 raeburn 192: args => ["\n $contextdesc\n",$textstr,$timestamp."\n"],
193: });
1.12 raeburn 194: my $directions;
195: if ($crstype eq 'community') {
196: $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 197: } else {
1.12 raeburn 198: $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.';
199: }
200: push(@rawmsg,
1.1 raeburn 201: {
1.12 raeburn 202: mt => $directions,
1.2 raeburn 203: args => [" \n\n","\n"],
1.1 raeburn 204: });
1.30 raeburn 205: } elsif ($context eq 'authorreq') {
206: $rawsubj = 'Authoring space request to review';
1.31 raeburn 207: $msgtxt = 'Assignment of an author role in the [_1] domain[_2]was requested by [_3] on [_4].';
1.30 raeburn 208: push(@rawmsg,{
209: mt => $msgtxt,
210: args => [$contextdesc,"\n",$textstr,$timestamp],
211: },
212: {
213: mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Create users or modify the roles and privileges of users -> Authoring space reqests[_3]to display a list of pending requests, which you can either approve or reject.',
214: args => ["\n","\n\n ","\n\n"],
215: });
1.2 raeburn 216:
1.30 raeburn 217: } elsif ($context eq 'requestauthor') {
218: $rawsubj = 'Authoring space request';
219: $msgtxt = 'Your request for an authoring space requested on [_1]has been reviewed by a Domain Coordinator.';
220: push(@rawmsg,{
221: mt => $msgtxt,
222: args => [$timestamp."\n"],
223: });
224: if (ref($textstr) eq 'ARRAY') {
225: push(@rawmsg,@{$textstr});
226: }
1.1 raeburn 227: }
228: my @to_notify = split(/,/,$notifylist);
229: my $numsent = 0;
230: my @recusers;
231: my @recudoms;
232: foreach my $cc (@to_notify) {
233: my ($ccname,$ccdom) = split(/:/,$cc);
234: if (!exists($msgcc->{$ccname.':'.$ccdom})) {
235: push(@recusers,$ccname);
236: push(@recudoms,$ccdom);
237: $msgcc->{$ccname.':'.$ccdom}='';
238: $numsent ++;
239: }
240: }
241: my %reciphash = (
242: cc => $msgcc,
243: );
244: my ($uname,$udom);
245: if ($sender =~ /:/) {
246: ($uname,$udom) = split(/:/,$sender);
1.2 raeburn 247: } elsif ($context eq 'course') {
1.1 raeburn 248: $uname = $sender;
249: my %courseinfo = &Apache::lonnet::coursedescription($cid);
250: $udom = $courseinfo{'num'};
251: }
252: my %sentmessage;
253: my $stamp = time;
254: my $msgcount = &Apache::lonmsg::get_uniq();
255: my $sender_lh = &Apache::loncommon::user_lang($uname,$udom,$cid);
256: $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj);
257: $message = '';
258: foreach my $item (@rawmsg) {
259: if (ref($item) eq 'HASH') {
260: $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
261: }
262: }
1.26 raeburn 263: &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,\@recusers,\@recudoms,undef,undef,undef,undef,$senderuname,$senderudom);
1.1 raeburn 264: my ($recipid,$recipstatus) = &Apache::lonmsg::store_recipients($subject,$uname,$udom,\%reciphash);
265: my $status;
266: foreach my $recip (sort(keys(%{$msgcc}))) {
267: my ($ccname,$ccdom) = split(/:/,$recip);
268: my $recip_lh = &Apache::loncommon::user_lang($ccname,$ccdom,$cid);
269: my $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj);
270: my $message = '';
271: foreach my $item (@rawmsg) {
272: if (ref($item) eq 'HASH') {
273: $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},
274: @{$item->{args}})."\n";
275: }
276: }
1.10 raeburn 277: if ($context eq 'coursemanagers') {
1.1 raeburn 278: if ($approvedlist) {
279: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved enrollments:')."\n".$approvedlist;
280: }
281: if ($rejectedlist) {
282: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected enrollments:')."\n".$rejectedlist;
283: }
284: } elsif ($context eq 'domainmanagers') {
285: if ($approvedlist) {
286: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved course requests:')."\n".$approvedlist;
287: }
288: if ($rejectedlist) {
289: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected course requests:')."\n".$rejectedlist;
290: }
1.30 raeburn 291: } elsif ($context eq 'authormanagers') {
292: if ($approvedlist) {
293: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved author role requests:')."\n".$approvedlist;
294: }
295: if ($rejectedlist) {
296: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected author role requests:')."\n".$rejectedlist;
297: }
1.1 raeburn 298: }
299: $status .= &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,1,\%sentmessage,undef,undef,undef,1,$recipid).',';
300: }
301: $status =~ s/,$//;
302: return ($recipstatus,$status);
303: }
304:
305: sub display_queued_requests {
306: my ($context,$dom,$cnum) = @_;
1.2 raeburn 307: my ($namespace,$formaction,$nextelement,%requesthash);
1.1 raeburn 308: if ($context eq 'course') {
309: $formaction = '/adm/createuser';
310: $namespace = 'selfenrollrequests';
311: %requesthash = &Apache::lonnet::dump($namespace,$dom,$cnum);
1.2 raeburn 312: $nextelement = '<input type="hidden" name="state" value="done" />';
1.30 raeburn 313: } elsif ($context eq 'requestauthor') {
314: $formaction = '/adm/createuser';
315: $namespace = 'requestauthorqueue';
316: %requesthash = &Apache::lonnet::dump_dom($namespace,$dom);
317: $nextelement = '<input type="hidden" name="state" value="done" />';
1.1 raeburn 318: } else {
319: $formaction = '/adm/createcourse';
320: $namespace = 'courserequestqueue';
1.23 raeburn 321: my $disposition = 'approval';
1.24 raeburn 322: my $nextphase = 'requestchange';
1.23 raeburn 323: if ($context eq 'pending') {
324: $disposition = 'pending';
1.24 raeburn 325: $nextphase = 'requestvalidation';
1.23 raeburn 326: }
327: %requesthash = &Apache::lonnet::dump_dom($namespace,$dom,'_'.$disposition);
1.24 raeburn 328: $nextelement = '<input type="hidden" name="phase" value="'.$nextphase.'" />';
1.1 raeburn 329: }
1.23 raeburn 330: my ($output,%queue_by_date);
1.1 raeburn 331: if (keys(%requesthash) > 0) {
1.2 raeburn 332: $output = '<form method="post" name="changequeue" action="'.$formaction.'" />'."\n".
333: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.23 raeburn 334: $nextelement."\n";
1.1 raeburn 335: foreach my $item (keys(%requesthash)) {
1.23 raeburn 336: my ($timestamp,$entry,$pending);
1.1 raeburn 337: if ($context eq 'course') {
338: ($timestamp, my $usec) = split(/:/,$requesthash{$item});
339: $entry = $item.':'.$usec;
1.30 raeburn 340: } elsif ($context eq 'requestauthor') {
341: $timestamp = $requesthash{$item};
342: ($entry) = ($item =~ /^($match_username)_approval$/);
1.1 raeburn 343: } else {
344: $timestamp = $requesthash{$item}{'timestamp'};
345: if (ref($requesthash{$item}) eq 'HASH') {
1.2 raeburn 346: my ($cnum,$disposition) = split('_',$item);
347: $entry = $cnum.':'.$requesthash{$item}{'ownername'}.':'.
1.23 raeburn 348: $requesthash{$item}{'ownerdom'}.':';
349: if ($context eq 'pending') {
350: $entry .= $requesthash{$item}{'instcode'};
351: } else {
352: $entry .= $requesthash{$item}{'crstype'};
353: }
354: $entry .= ':'.$requesthash{$item}{'description'};
1.1 raeburn 355: }
356: }
357: if ($entry ne '') {
1.23 raeburn 358: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
359: push(@{$queue_by_date{$timestamp}},$entry);
1.1 raeburn 360: } else {
1.23 raeburn 361: $queue_by_date{$timestamp} = [$entry];
1.1 raeburn 362: }
363: }
364: }
1.23 raeburn 365: if (keys(%queue_by_date) > 0) {
366: if ($context eq 'course') {
367: $output .= '<h3>'.&mt('Self-enrollment requests queued pending approval by a Coordinator').'</h3>';
368: } elsif ($context eq 'pending') {
369: $output .= '<h3>'.&mt('Requests for official courses queued pending validation').'</h3>'.
370: '<p>'.&mt('Requests are validated against institutional data to confirm that the requestor is an instructor of record.').'<br />'.
371: &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>';
1.30 raeburn 372: } elsif ($context eq 'requestauthor') {
373: $output .= '<h3>'.&mt('Requests for authoring space queued pending approval by a Domain Coordinator').'</h3>';
1.23 raeburn 374: } else {
1.30 raeburn 375: $output .= '<h3>'.&mt('Course/Community requests queued pending approval by a Domain Coordinator').'</h3>';
1.23 raeburn 376: }
377: $output .= &build_queue_display($dom,$context,\%queue_by_date).
378: '<input type="hidden" name="queue" value="approval" />';
379: } else {
380: $output .= '<div class="LC_info">';
381: if ($context eq 'course') {
382: $output .= &mt('There are currently no enrollment requests awaiting approval.');
383: } elsif ($context eq 'pending') {
384: $output .= &mt('There are currently no requests for official courses awaiting validation.');
1.30 raeburn 385: } elsif ($context eq 'requestauthor') {
386: $output .= &mt('There are currently no requests for authoring space awaiting approval.');
1.23 raeburn 387: } elsif ($context eq 'domain') {
388: $output .= &mt('There are currently no course or community requests awaiting approval.');
389: }
390: $output .= '</div>';
391: }
392: if ($context eq 'pending') {
1.24 raeburn 393: $output .= '<br /><input type="submit" name="validationcheck" value="'.
394: &mt('Validate').'" /><br />'."\n".
1.23 raeburn 395: '<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>';
396: } else {
397: $output .= '<br /><input type="submit" name="processqueue" value="'.&mt('Save').'" />';
398: }
399: $output .= '</form>';
400: } else {
401: $output .= '<div class="LC_info">';
402: if ($context eq 'course') {
403: $output .= &mt('There are currently no enrollment requests awaiting approval.');
404: } elsif ($context eq 'pending') {
405: $output .= &mt('There are currently no requests for official courses awaiting validation.');
406: } else {
407: $output .= &mt('There are currently no course or community requests awaiting approval.');
408: }
409: $output .= '</div>';
410: }
411: return $output;
412: }
1.1 raeburn 413:
1.23 raeburn 414: sub build_queue_display {
415: my ($dom,$context,$queue) = @_;
416: return unless (ref($queue) eq 'HASH');
417: my %crstypes;
418: my $output = &Apache::loncommon::start_data_table().
419: &Apache::loncommon::start_data_table_header_row();
420: unless ($context eq 'pending') {
421: $output .= '<th>'.&mt('Action').'</th>';
422: }
423: $output .= '<th>'.&mt('Requestor').'</th>';
424: if ($context eq 'course') {
425: $output .= '<th>'.&mt('Section').'</th>'.
426: '<th>'.&mt('Date requested').'</th>';
1.30 raeburn 427: } elsif ($context eq 'requestauthor') {
428: $output .= '<th>'.&mt('Date requested').'</th>';
1.23 raeburn 429: } elsif ($context eq 'pending' || $context eq 'stillpending') {
430: $output .= '<th>'.&mt('Institutional code').'</th>'.
431: '<th>'.&mt('Date requested').'</th>'.
432: '<th>'.&mt('Details').'</th>';
433: } else {
434: %crstypes = &Apache::lonlocal::texthash (
435: official => 'Official course',
436: unofficial => 'Unofficial course',
437: community => 'Community',
1.38 ! raeburn 438: textbook => 'Textbook course',
1.23 raeburn 439: );
440: $output .= '<th>'.&mt('Type').'</th>'.
441: '<th>'.&mt('Date requested').'</th>'.
442: '<th>'.&mt('Details').'</th>';
443: }
444: $output .= &Apache::loncommon::end_data_table_header_row();
445: my @sortedtimes = sort {$a <=> $b} (keys(%{$queue}));
446: my $count = 0;
447: foreach my $item (@sortedtimes) {
448: if (ref($queue->{$item}) eq 'ARRAY') {
449: foreach my $request (sort(@{$queue->{$item}})) {
450: my ($row,$approve,$reject,$showtime,$showsec,$namelink,
451: $detailslink,$crstype,$instcode);
452: $showtime = &Apache::lonlocal::locallocaltime($item);
453: if ($context eq 'course') {
454: my ($puname,$pudom,$pusec) = split(/:/,$request);
455: $approve = $count.':'.$puname.':'.$pudom.':'.$pusec;
456: $reject = $puname.':'.$pudom;
457: $showsec = $pusec;
458: if ($showsec eq '') {
459: $showsec = &mt('none');
460: }
461: $namelink = &Apache::loncommon::aboutmewrapper(
462: &Apache::loncommon::plainname($puname,$pudom),
463: $puname,$pudom);
1.30 raeburn 464: } elsif ($context eq 'requestauthor') {
465: if (&Apache::lonnet::homeserver($request,$dom) ne 'no_host') {
466: $approve = $count.':'.$request;
467: $reject = $request;
468: $namelink = &Apache::loncommon::aboutmewrapper(
469: &Apache::loncommon::plainname($request,$dom),
470: $request,$dom);
471: }
1.23 raeburn 472: } else {
473: my ($cnum,$ownername,$ownerdom,$type,$cdesc);
474: my $queue = 'approval';
475: if ($context eq 'pending' || $context eq 'stillpending') {
476: ($cnum,$ownername,$ownerdom,$instcode,$cdesc)=split(/:/,$request,5);
477: $queue = 'pending';
1.1 raeburn 478: } else {
1.23 raeburn 479: ($cnum,$ownername,$ownerdom,$type,$cdesc)=split(/:/,$request,5);
1.1 raeburn 480: $crstype = $type;
481: if (defined($crstypes{$type})) {
482: $crstype = $crstypes{$type};
483: }
484: }
1.23 raeburn 485: $detailslink='<a href="javascript:opencoursereqdisplay('.
486: "'$dom','$cnum','$queue'".');">'.$cdesc.'</a>';
487: $approve = $count.':'.$cnum;
488: $reject = $cnum;
489: $namelink = &Apache::loncommon::aboutmewrapper(
490: &Apache::loncommon::plainname($ownername,$ownerdom),
491: $ownername,$ownerdom);
492: }
493: unless ($context eq 'pending') {
1.1 raeburn 494: $row = '<td><span class="LC_nobreak"><label>'.
1.30 raeburn 495: '<input type="radio" value="'.$approve.'" name="'.$count.'radioreq" />'.&mt('Approve').'</label>'.
496: '<label>'.(' 'x2).
497: '<input type="radio" value="'.$reject.'" name="'.$count.'radioreq" />'.&mt('Reject').'</label>'.
498: '<label>'.(' 'x2).
1.29 golterma 499: '<input type="radio" value="'."later:".$reject.'" name="'.$count.'radioreq" checked />'.&mt('Decide Later').
500: '</label></span><br /></td>';
1.1 raeburn 501: }
1.23 raeburn 502: $row .= '<td>'.$namelink.'</td>'."\n";
503: if ($context eq 'course') {
504: $row .= '<td>'.$showsec.'</td>'."\n".
505: '<td>'.$showtime.'</td>'."\n";
1.30 raeburn 506: } elsif ($context eq 'requestauthor') {
507: $row .= '<td>'.$showtime.'</td>'."\n";
1.23 raeburn 508: } else {
509: if ($context eq 'pending' || $context eq 'stillpending') {
510: $row .= '<td>'.$instcode.'</td>'."\n";
511: } else {
512: $row .= '<td>'.$crstype.'</td>'."\n";
513: }
514: $row .= '<td>'.$showtime.'</td>'."\n".
515: '<td>'.$detailslink.'</td>'."\n";
516: }
517: $output .= &Apache::loncommon::start_data_table_row()."\n".
518: $row.
519: &Apache::loncommon::end_data_table_row()."\n";
520: $count ++;
1.1 raeburn 521: }
522: }
523: }
1.23 raeburn 524: $output .= &Apache::loncommon::end_data_table();
1.1 raeburn 525: return $output;
526: }
527:
528: sub update_request_queue {
529: my ($context,$cdom,$cnum,$coursedesc) = @_;
530: my ($output,$access_start,$access_end,$limit,$cap,$notifylist,$namespace,
1.26 raeburn 531: $stucounts,$idx,$classlist,%requesthash,$cid,$domdesc,$now,
532: $sender,$approvedmsg,$rejectedmsg,$beneficiary,
1.2 raeburn 533: @existing,@missingreq,@invalidusers,@limitexceeded,@completed,
1.19 raeburn 534: @processing_errors,@warn_approves,@warn_rejects,@approvals,@warn_dels,
1.30 raeburn 535: @rejections,@rejectionerrors,@nopermissions,%courseroles,@toremove,
536: %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype,$queue,
537: $firsturl);
1.29 golterma 538: my $count=0;
539: while (my @course = &Apache::loncommon::get_env_multiple('form.'.$count.'radioreq')) {
1.34 raeburn 540: if ($course[0] =~ /^\d+:.*/) {
541: push(@approvals,$course[0]);
542: } elsif ($course[0] =~ /^later:.*/) {
1.29 golterma 543: #decide later
544: } else {
1.34 raeburn 545: push(@rejections,$course[0]);
1.29 golterma 546: }
547: $count+=1;
548: }
549:
1.1 raeburn 550: $now = time;
551: $sender = $env{'user.name'}.':'.$env{'user.domain'};
552: if ($context eq 'course') {
553: $namespace = 'selfenrollrequests';
554: $beneficiary = 'enroller';
555: $cid = $env{'request.course.id'};
1.12 raeburn 556: $crstype = lc(&Apache::loncommon::course_type());
1.26 raeburn 557: $firsturl = &course_portal_url($cnum,$cdom);
1.1 raeburn 558: %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
559: $access_start = $env{'course.'.$cid.'.internal.selfenroll_start_access'};
560: $access_end = $env{'course.'.$cid.'.internal.selfenroll_end_access'};
561: $limit = $env{'course.'.$cid.'.internal.selfenroll_limit'};
562: $cap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
563: $notifylist = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
564: ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
565: $approvedmsg = [{
566: mt => 'Your request for enrollment has been approved.',
567: },
568: {
1.28 raeburn 569: mt => 'Visit [_1] to log-in and access the course',
1.25 raeburn 570: args => [$firsturl],
1.1 raeburn 571: }];
572: $rejectedmsg = [{
573: mt => 'Your request for enrollment has not been approved.',
574: }];
1.30 raeburn 575: } elsif ($context eq 'requestauthor') {
576: $namespace = 'requestauthorqueue';
577: $beneficiary = 'requestauthor';
578: %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom);
579: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
580: if (ref($domdefs{'requestauthor'}) eq 'HASH') {
581: if (ref($domdefs{'requestauthor'}{'notify'}) eq 'HASH') {
582: $notifylist = $domdefs{'requestauthor'}{'notify'}{'approval'};
583: }
584: }
585: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($cdom);
586: $firsturl = &course_portal_url($domconfiguser,$cdom);
587: $approvedmsg = [{
588: mt => 'Your request for authoring space has been approved.',
589: },
590: {
591: mt => 'Visit [_1] to log-in and select your author role',
592: args => [$firsturl],
593: }];
594: $rejectedmsg = [{
595: mt => 'Your request for authoring space has not been approved.',
596: }];
597: $domdesc = &Apache::lonnet::domain($cdom);
1.1 raeburn 598: } else {
1.2 raeburn 599: $domdesc = &Apache::lonnet::domain($cdom);
600: $namespace = 'courserequestqueue';
601: $beneficiary = 'courserequestor';
1.23 raeburn 602: $queue = 'approval';
603: if ($env{'form.queue'} eq 'pending') {
604: $queue = 'pending';
605: }
606: %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom,'_'.$queue);
1.2 raeburn 607: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
608: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
609: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
610: $notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
611: }
612: }
1.12 raeburn 613: $approvalmsg{'course'} =
614: [{
1.2 raeburn 615: mt => 'Your course request has been approved.',
616: },
617: {
1.28 raeburn 618: mt => 'Visit [_1] to log-in and access the course',
619: args => [],
1.2 raeburn 620: }];
1.12 raeburn 621: $rejectionmsg{'course'} =
622: [{
1.2 raeburn 623: mt => 'Your course request has not been approved.',
624: }];
1.12 raeburn 625:
626: $approvalmsg{'community'} =
627: [{
628: mt => 'Your community request has been approved.',
629: },
630: {
1.28 raeburn 631: mt => 'Visit [_1] to log-in and access the community',
632: args => [],
1.12 raeburn 633: }];
634:
635: $rejectionmsg{'community'} =
636: [{
637: mt => 'Your community request has not been approved.',
638: }];
639:
1.2 raeburn 640: %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
641: my @roles = &Apache::lonuserutils::roles_by_context('course');
642: foreach my $role (@roles) {
643: $courseroles{$role}=&Apache::lonnet::plaintext($role,'Course');
644: }
645: foreach my $role (@roles) {
646: $communityroles{$role}=&Apache::lonnet::plaintext($role,'Community');
647: }
1.1 raeburn 648: }
649: foreach my $item (sort {$a <=> $b} @approvals) {
650: if ($context eq 'course') {
651: my ($num,$uname,$udom,$usec) = split(/:/,$item);
652: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
653: if ($uhome ne 'no_host') {
654: if (exists($requesthash{$uname.':'.$udom})) {
655: if (exists($classlist->{$uname.':'.$udom})) {
656: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
657: if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
658: ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
659: push(@existing,$uname.':'.$udom);
660: next;
661: }
662: }
663: }
664: } else {
665: push(@missingreq,$uname.':'.$udom);
666: next;
667: }
668: if (!grep(/^\Q$item\E$/,@rejections)) {
669: if ($limit eq 'allstudents') {
670: if ($stucounts->{$limit} >= $cap) {
671: push(@limitexceeded,$uname.':'.$udom);
672: last;
673: }
674: } elsif ($limit eq 'selfenrolled') {
675: if ($stucounts->{$limit} >= $cap) {
676: push(@limitexceeded,$uname.':'.$udom);
677: last;
678: }
679: }
680: my $result =
681: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
682: if ($result eq 'ok') {
1.2 raeburn 683: push(@completed,$uname.':'.$udom);
1.1 raeburn 684: $stucounts->{'allstudents'} ++;
685: $stucounts->{'selfenrolled'} ++;
686: &send_selfserve_notification($uname.':'.$udom,$approvedmsg,
1.26 raeburn 687: $cid,$coursedesc,$now,$beneficiary,$sender,
688: undef,undef,$crstype);
1.2 raeburn 689: my %userrequest = (
690: $cdom.'_'.$cnum => {
691: timestamp => $now,
692: section => $usec,
693: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
694: status => 'approved',
695: }
696: );
1.1 raeburn 697: my $userresult =
698: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
699: if ($userresult ne 'ok') {
700: push(@warn_approves,$uname.':'.$udom);
701: }
702: } else {
1.2 raeburn 703: push(@processing_errors,$uname.':'.$udom);
1.1 raeburn 704: }
705: }
706: } else {
707: push(@invalidusers,$uname.':'.$udom);
708: }
1.30 raeburn 709: } elsif ($context eq 'requestauthor') {
710: my ($num,$uname) = split(/:/,$item);
711: my $uhome = &Apache::lonnet::homeserver($uname,$cdom);
712: if ($uhome ne 'no_host') {
713: my ($user_is_adv,$user_is_author) = &Apache::lonnet::is_advanced_user($cdom,$uname);
714: if ($user_is_author) {
715: push(@existing,$uname);
716: } elsif (&Apache::lonnet::usertools_access($uname,$cdom,'requestauthor',
717: undef,'requestauthor')) {
718: if (&Apache::lonnet::allowed('cau',$cdom)) {
719: if (&Apache::lonnet::assignrole($cdom,$uname,'/'.$cdom.'/','au',undef,time,undef,undef,'requestauthor') eq 'ok') {
720: push(@completed,$uname);
721: unless (&Apache::lonnet::del_dom($namespace,[$uname.'_approval'],$cdom) eq 'ok') {
722: push(@warn_dels,$uname);
723: }
724: &send_selfserve_notification($uname.':'.$cdom,
725: $approvedmsg,undef,undef,$now,
726: $beneficiary,$sender);
727: my %userrequest = (
728: author => {
729: timestamp => $now,
730: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
731: status => 'approved',
732: },
733: author_status => 'approved',
734: );
735: my $userresult =
736: &Apache::lonnet::put('requestauthor',\%userrequest,$cdom,$uname);
737: if ($userresult ne 'ok') {
738: push(@warn_approves,$item);
739: }
740: } else {
741: push(@processing_errors,$uname);
742: }
743: } else {
744: push(@nopermissions,$uname);
745: }
746: } else {
747: push(@nopermissions,$uname);
748: }
749: } else {
750: push(@invalidusers,$uname.':'.$cdom);
751: }
752: push(@toremove,(@invalidusers,@nopermissions));
1.1 raeburn 753: } else {
1.2 raeburn 754: my ($num,$cnum) = split(':',$item);
1.23 raeburn 755: if (ref($requesthash{$cnum.'_'.$queue}) eq 'HASH') {
1.2 raeburn 756: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
1.23 raeburn 757: my $ownername = $requesthash{$cnum.'_'.$queue}{'ownername'};
758: my $ownerdom = $requesthash{$cnum.'_'.$queue}{'ownerdom'};
759: $crstype = $requesthash{$cnum.'_'.$queue}{'crstype'};
760: my $coursedesc = $requesthash{$cnum.'_'.$queue}{'description'};
1.2 raeburn 761: my $longroles = \%courseroles;
762: if ($crstype eq 'community') {
763: $longroles = \%communityroles;
764: }
1.5 raeburn 765: my $cancreate;
766: if ($cdom eq $ownerdom) {
767: if (&Apache::lonnet::usertools_access($ownername,$ownerdom,$crstype,
768: undef,'requestcourses')) {
769: $cancreate = 1;
770: }
771: } else {
772: my %userenv = &Apache::lonnet::userenvironment($ownerdom,$ownername,'reqcrsotherdom.'.$crstype);
773: if ($userenv{'reqcrsotherdom.'.$crstype}) {
774: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
775: if (grep(/^\Q$cdom\E:/,@doms)) {
776: $cancreate = 1;
777: }
778: }
779: }
780: if ($cancreate) {
1.2 raeburn 781: my $requestkey = $cdom.'_'.$cnum;
782: my %history =
783: &Apache::lonnet::restore($requestkey,'courserequests',
784: $ownerdom,$ownername);
785: if ((ref($history{'details'}) eq 'HASH') &&
1.23 raeburn 786: ($history{'disposition'} eq $queue)) {
1.2 raeburn 787: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);
788: my $result = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg,
789: \$newusermsg,\$addresult,\$enrollcount,
790: \$response,\$keysmsg,\%domdefs,$longroles);
791: if ($result eq 'created') {
1.12 raeburn 792: if ($crstype eq 'community') {
793: $approvedmsg = $approvalmsg{'community'};
794: } else {
795: $approvedmsg = $approvalmsg{'course'};
796: }
1.28 raeburn 797: my $firsturl = &course_portal_url($cnum,$cdom);
798: if (ref($approvedmsg) eq 'ARRAY') {
799: if (ref($approvedmsg->[1]) eq 'HASH') {
800: $approvedmsg->[1]->{'args'} = [$firsturl];
801: }
802: }
1.2 raeburn 803: push(@completed,$cnum);
1.19 raeburn 804:
1.23 raeburn 805: unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_'.$queue],$cdom) eq 'ok') {
1.19 raeburn 806: push(@warn_dels,$cnum);
807: }
1.26 raeburn 808: &send_selfserve_notification($ownername.':'.$ownerdom,
809: $approvedmsg,$cid,$coursedesc,$now,
810: $beneficiary,$sender,undef,undef,$crstype);
1.2 raeburn 811: my %reqhash = (
812: reqtime => $history{'reqtime'},
813: crstype => $history{'crstype'},
814: details => $history{'details'},
815: disposition => $history{'disposition'},
816: status => 'created',
817: adjudicator => $env{'user.name'}.':'.
818: $env{'user.domain'},
819: );
820: my $userresult =
821: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
822: 'courserequests',$ownerdom,$ownername);
823: if ($userresult eq 'ok') {
824: my %status = (
825: 'status:'.$cdom.':'.$cnum => 'created'
826: );
827: my $statusresult =
828: &Apache::lonnet::put('courserequests',\%status,
829: $ownerdom,$ownername);
830: if ($statusresult ne 'ok') {
831: push(@warn_approves,$cnum);
832: }
833: }
834: if ($userresult ne 'ok') {
835: push(@warn_approves,$cnum);
836: }
837: } else {
838: push(@processing_errors,$cnum);
839: }
840: } else {
841: push(@processing_errors,$cnum);
842: }
843: } else {
1.5 raeburn 844: push(@nopermissions,$cnum);
1.2 raeburn 845: }
846: } else {
847: push(@existing,$cnum);
848: }
849: } else {
850: push(@missingreq,$cnum);
851: }
1.1 raeburn 852: }
853: }
1.2 raeburn 854: my @changes = (@completed,@rejections);
855: if ($context eq 'domain') {
1.23 raeburn 856: @changes = map {$_.'_'.$queue} (@changes);
1.30 raeburn 857: } elsif ($context eq 'requestauthor') {
858: @changes = map {$_.'_approval'} (@changes);
1.2 raeburn 859: }
1.1 raeburn 860: if (@rejections) {
1.3 raeburn 861: foreach my $item (@rejections) {
1.30 raeburn 862: if (($context eq 'course') || ($context eq 'requestauthor')) {
863: my ($user,$uname,$udom,%userrequest,$key);
864: if ($context eq 'requestauthor') {
865: $uname = $item;
866: $udom = $cdom;
867: $user = $uname.':'.$udom;
868: $key = 'author';
869: } else {
870: $user = $item;
871: ($uname,$udom) = split(/:/,$user);
872: $key = $cdom.'_'.$cnum;
873: }
1.2 raeburn 874: &send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc,
1.26 raeburn 875: $now,$beneficiary,$sender,undef,undef,
876: $crstype);
1.30 raeburn 877: %userrequest = (
878: $key => {
1.1 raeburn 879: timestamp => $now,
880: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
1.30 raeburn 881: status => 'rejection',
1.1 raeburn 882: }
883: );
1.30 raeburn 884: if ($context eq 'requestauthor') {
885: $userrequest{'author_status'} = 'rejection';
886: }
1.1 raeburn 887: my $userresult =
1.30 raeburn 888: &Apache::lonnet::put('requestauthor',\%userrequest,$udom,$uname);
1.1 raeburn 889: if ($userresult ne 'ok') {
1.30 raeburn 890: push(@warn_rejects,$item);
1.1 raeburn 891: }
892: } else {
1.3 raeburn 893: my $cnum = $item;
1.23 raeburn 894: if (ref($requesthash{$cnum.'_'.$queue}) eq 'HASH') {
1.3 raeburn 895: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
896: my $requestkey = $cdom.'_'.$cnum;
1.23 raeburn 897: my $ownername = $requesthash{$cnum.'_'.$queue}{'ownername'};
898: my $ownerdom = $requesthash{$cnum.'_'.$queue}{'ownerdom'};
899: my $coursedesc = $requesthash{$cnum.'_'.$queue}{'description'};
900: $crstype = $requesthash{$cnum.'_'.$queue}{'crstype'};
1.12 raeburn 901: if ($crstype eq 'community') {
902: $rejectedmsg = $rejectionmsg{'community'};
903: } else {
904: $rejectedmsg = $rejectionmsg{'course'};
905: }
1.2 raeburn 906: &send_selfserve_notification($ownername.':'.$ownerdom,$rejectedmsg,
907: $cid,$coursedesc,$now,$beneficiary,
1.12 raeburn 908: $sender,undef,undef,$crstype);
1.2 raeburn 909: my %history =
1.3 raeburn 910: &Apache::lonnet::restore($requestkey,'courserequests',
1.2 raeburn 911: $ownerdom,$ownername);
912: if ((ref($history{'details'}) eq 'HASH') &&
1.23 raeburn 913: ($history{'disposition'} eq $queue)) {
1.2 raeburn 914: my %reqhash = (
915: reqtime => $history{'reqtime'},
916: crstype => $history{'crstype'},
917: details => $history{'details'},
918: disposition => $history{'disposition'},
919: status => 'rejected',
920: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
921: );
922: my $userresult =
1.3 raeburn 923: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
924: 'courserequests',$ownerdom,$ownername);
925: if ($userresult eq 'ok') {
926: my %status = (
927: 'status:'.$cdom.':'.$cnum => 'rejected'
928: );
929: my $statusresult =
930: &Apache::lonnet::put('courserequests',\%status,
931: $ownerdom,$ownername);
932: if ($statusresult ne 'ok') {
933: push(@warn_rejects,$cnum);
934: }
935: } else {
936: push(@warn_rejects,$cnum);
1.2 raeburn 937: }
1.23 raeburn 938: unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_'.$queue],$cdom) eq 'ok') {
1.19 raeburn 939: push(@warn_dels,$cnum);
940: }
1.3 raeburn 941: } else {
942: push(@warn_rejects,$cnum);
1.2 raeburn 943: }
1.3 raeburn 944: } else {
945: push(@existing,$cnum);
1.2 raeburn 946: }
1.3 raeburn 947: } else {
948: push(@rejectionerrors,$cnum);
1.2 raeburn 949: }
1.1 raeburn 950: }
951: }
952: }
1.30 raeburn 953: if (@toremove) {
954: foreach my $item (@toremove) {
955: my %userrequest = (
956: author => {
957: timestamp => $now,
958: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
959: status => 'deleted',
960: },
961: author_status => 'deleted',
962: );
963: &Apache::lonnet::put('requestauthor',\%userrequest,$cdom,$item);
964: }
965: @toremove = map {$_.'_approval'} (@toremove);
966: my $delresult = &Apache::lonnet::del_dom($namespace,\@toremove,$cdom);
967: }
1.1 raeburn 968: if (@changes) {
969: my $delresult;
970: if ($context eq 'course') {
971: $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
972: } else {
973: $delresult = &Apache::lonnet::del_dom($namespace,\@changes,$cdom);
974: }
975: if ($delresult eq 'ok') {
976: my $namelink =
977: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
978: my ($chgmsg,$approvedlist,$rejectedlist);
979: if ($context eq 'course') {
980: $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
1.2 raeburn 981: if (@completed) {
982: $approvedlist = join("\n",@completed);
1.12 raeburn 983: if ($crstype eq 'community') {
984: $output .= '<p>'.&mt('The following were enrolled in the community:').'<ul>';
985: } else {
986: $output .= '<p>'.&mt('The following were enrolled in the course:').'<ul>';
987: }
1.2 raeburn 988: foreach my $user (@completed) {
1.1 raeburn 989: my ($uname,$udom) = split(/:/,$user);
990: my $userlink =
991: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
992: $output .= '<li>'.$userlink.'</li>';
993: }
994: $output .= '</ul></p>';
995: }
996: if (@rejections) {
997: $rejectedlist = join("\n",@rejections);
998: $output .= '<p>'.&mt('The following enrollment requests were rejected:').'<ul>';
999: foreach my $user (@rejections) {
1000: $output .= '<li>'.$user.'</li>';
1001: }
1002: $output .= '</ul></p>';
1003: }
1.2 raeburn 1004: if ($notifylist ne '') {
1005: &send_selfserve_notification($notifylist,$chgmsg,$cid,$coursedesc,
1006: $now,'coursemanagers',$sender,
1.12 raeburn 1007: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 1008: }
1.30 raeburn 1009: } elsif ($context eq 'requestauthor') {
1010: $chgmsg = "'Action was taken on the following authoring space requests by [_1].',$namelink";
1011: if (@completed) {
1012: $approvedlist = join("\n",@completed);
1013: $output .= '<p>'.&mt('The following requests were approved:').'<ul>';
1014: foreach my $uname (@completed) {
1015: my $userlink =
1016: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
1017: $output .= '<li>'.$userlink.'</li>';
1018:
1019: }
1020: $output .= '</ul></p>';
1021: }
1022: if (@rejections) {
1023: $rejectedlist = join("\n",@rejections);
1024: $output .= '<p>'.&mt('The following requests were rejected:').'<ul>';
1025: foreach my $uname (@rejections) {
1026: my $userlink =
1027: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
1028: $output .= '<li>'.$userlink.'</li>';
1029: }
1030: $output .= '</ul></p>';
1031: }
1032: if ($notifylist ne '') {
1033: &send_selfserve_notification($notifylist,$chgmsg,undef,$domdesc,
1034: $now,'authormanagers',$sender,
1035: $approvedlist,$rejectedlist);
1036: }
1.1 raeburn 1037: } else {
1.12 raeburn 1038: $chgmsg = "'Action was taken on the following course and community requests by [_1].',$namelink";
1.2 raeburn 1039: if (@completed) {
1040: $approvedlist = join("\n",@completed);
1.12 raeburn 1041: $output .= '<p>'.&mt('The following courses/communities were created:').'<ul>';
1.2 raeburn 1042: foreach my $cnum (@completed) {
1043: my $showcourse;
1.23 raeburn 1044: if (ref($requesthash{$cnum.'_'.$queue})) {
1045: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1.2 raeburn 1046: } else {
1047: $showcourse = $cnum;
1048: }
1049: my $syllabuslink =
1050: &Apache::loncommon::syllabuswrapper($showcourse,$cnum,$cdom);
1051: $output .= '<li>'.$syllabuslink.'</li>';
1052: }
1053: $output .= '</ul></p>';
1054: }
1055: if (@rejections) {
1056: $rejectedlist = join("\n",@rejections);
1057: $output .= '<p>'.&mt('The following requests were rejected:').'<ul>';
1058: foreach my $cnum (@rejections) {
1059: my $showcourse;
1.23 raeburn 1060: if (ref($requesthash{$cnum.'_'.$queue})) {
1061: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1.2 raeburn 1062: } else {
1063: $showcourse = $cnum;
1064: }
1065: $output .= '<li>'.$showcourse.'</li>';
1066: }
1067: $output .= '</ul></p>';
1068: }
1069: if ($notifylist ne '') {
1070: &send_selfserve_notification($notifylist,$chgmsg,$cid,$domdesc,
1071: $now,'domainmanagers',$sender,
1.12 raeburn 1072: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 1073: }
1.1 raeburn 1074: }
1075: }
1076: }
1077: if (@existing) {
1078: if ($context eq 'course') {
1079: $output .= '<p>'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'<ul>';
1080: foreach my $user (@existing) {
1081: $output .= '<li>'.$user.'</li>';
1082: }
1083: $output .= '</ul></p>';
1.30 raeburn 1084: } elsif ($context eq 'requestauthor') {
1085: $output .= '<p>'.&mt('Authoring space requests from the following users were deleted because one already exists:').'<ul>';
1086: foreach my $uname (@existing) {
1087: my $userlink =
1088: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
1089: $output .= '<li>'.$userlink.'</li>';
1090: }
1091: $output .= '</ul></p>';
1.1 raeburn 1092: } else {
1.12 raeburn 1093: $output .= '<p>'.&mt('The following course/community creation requests were deleted because the course or community has already been created:').'<ul>';
1.2 raeburn 1094: foreach my $cnum (@existing) {
1095: my $showcourse;
1096: my %coursehash = &Apache::lonnet::coursedescription($cdom.'/'.$cnum);
1097: if ($coursehash{'description'} ne '') {
1098: $showcourse = $coursehash{'description'};
1099: } else {
1100: $showcourse = $cnum;
1101: }
1102: $output .= '<li>'.$showcourse.'</li>';
1103: }
1104: $output .= '</ul></p>';
1.1 raeburn 1105: }
1106: }
1107: if (@missingreq) {
1108: if ($context eq 'course') {
1109: $output .= '<p>'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'<ul>';
1110: foreach my $user (@missingreq) {
1111: $output .= '<li>'.$user.'</li>';
1112: }
1113: $output .= '</ul></p>';
1.30 raeburn 1114: } elsif ($context eq 'requestauthor') {
1115: $output .= '<p>'.&mt('The following requests were ignored because the request is no longer in the queue:').'<ul>';
1116: foreach my $uname (@missingreq) {
1117: my $userlink =
1118: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
1119: $output .= '<li>'.$userlink.'</li>';
1120: }
1121: $output .= '</ul></p>';
1.2 raeburn 1122: } else {
1.12 raeburn 1123: $output .= '<p>'.&mt('The following course/community creation requests were ignored because the request is no longer in the queue:').'<ul>';
1.2 raeburn 1124: foreach my $cnum (@missingreq) {
1125: $output .= '<li>'.$cnum.'</li>';
1126: }
1127: $output .= '</ul></p>';
1.1 raeburn 1128: }
1129: }
1130: if (@invalidusers) {
1131: if ($context eq 'course') {
1132: $output .= '<p>'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';
1133: foreach my $user (@invalidusers) {
1134: $output .= '<li>'.$user.'</li>';
1135: }
1136: $output .= '</ul></p>';
1.30 raeburn 1137: } elsif ($context eq 'requestauthor') {
1138: $output .= '<p>'.&mt('The following authoring space requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';
1139: foreach my $uname (@invalidusers) {
1140: my $userlink =
1141: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
1142: $output .= '<li>'.$userlink.'</li>';
1143: }
1144: $output .= '</ul></p>';
1.1 raeburn 1145: }
1146: }
1147: if (@limitexceeded) {
1148: if ($context eq 'course') {
1149: $output .= '<p>'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'<ul>';
1150: foreach my $user (@limitexceeded) {
1151: $output .= '<li>'.$user.'</li>';
1152: }
1153: $output .= '</ul></p>';
1154: }
1155: }
1.5 raeburn 1156: if (@nopermissions) {
1.30 raeburn 1157: if ($context eq 'course') {
1158: $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>';
1159: foreach my $cnum (@nopermissions) {
1160: my $showcourse;
1161: if (ref($requesthash{$cnum.'_'.$queue})) {
1162: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1163: } else {
1164: $showcourse = $cnum;
1165: }
1166: $output .= '<li>'.$showcourse.'</li>';
1167: }
1168: $output .= '</ul></p>';
1169: } elsif ($context eq 'requestauthor') {
1170: $output .= '<p>'.&mt('The following requests could not be processed because the requestor does not have rights to request an authoring space:').'<ul>';
1171: foreach my $uname (@nopermissions) {
1172: my $userlink =
1173: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
1174: $output .= '<li>'.$userlink.'</li>';
1.5 raeburn 1175: }
1.30 raeburn 1176: $output .= '</ul></p>';
1.5 raeburn 1177: }
1178: }
1.2 raeburn 1179: if (@processing_errors) {
1.1 raeburn 1180: if ($context eq 'course') {
1181: $output .= '<p>'.&mt('The following enrollment requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 1182: foreach my $user (@processing_errors) {
1.1 raeburn 1183: $output .= '<li>'.$user.'</li>';
1184: }
1185: $output .= '</ul></p>';
1.30 raeburn 1186: } elsif ($context eq 'requestauthor') {
1187: $output .= '<p>'.&mt('The following requests could not be processed because an error occurred:').'<ul>';
1188: foreach my $uname (@processing_errors) {
1189: my $userlink =
1190: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
1191: $output .= '<li>'.$userlink.'</li>';
1192: }
1193: $output .= '</ul></p>';
1.1 raeburn 1194: } else {
1.12 raeburn 1195: $output .= '<p>'.&mt('The following course/community creation requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 1196: foreach my $cnum (@processing_errors) {
1197: my $showcourse;
1.23 raeburn 1198: if (ref($requesthash{$cnum.'_'.$queue})) {
1199: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1.2 raeburn 1200: } else {
1201: $showcourse = $cnum;
1202: }
1203: $output .= '<li>'.$showcourse.'</li>';
1204: }
1205: $output .= '</ul></p>';
1.1 raeburn 1206: }
1207: }
1.3 raeburn 1208: if (@rejectionerrors) {
1.12 raeburn 1209: $output .= '<p>'.&mt('The following course/community creation request rejections could not be fully processed because an error occurred:').'<ul>';
1.3 raeburn 1210: foreach my $cnum (@rejectionerrors) {
1211: my $showcourse;
1.23 raeburn 1212: if (ref($requesthash{$cnum.'_'.$queue})) {
1213: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1.3 raeburn 1214: } else {
1215: $showcourse = $cnum;
1216: }
1217: $output .= '<li>'.$showcourse.'</li>';
1218: }
1219: $output .= '</ul></p>';
1220: }
1.2 raeburn 1221: if (@warn_approves || @warn_rejects) {
1.1 raeburn 1222: if ($context eq 'course') {
1223: $output .= '<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>';
1224: foreach my $user (@warn_approves) {
1225: $output .= '<li>'.$user.'</li>';
1226: }
1227: $output .= '</ul></p>';
1.30 raeburn 1228: } elsif ($context eq 'requestauthor') {
1229: $output .= '<p>'.&mt("For the following users, an error occurred when updating the user's own author request record:").'<ul>';
1230: foreach my $uname (@warn_approves,@warn_rejects) {
1231: my $userlink =
1232: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
1233: $output .= '<li>'.$userlink.'</li>';
1234: }
1235: $output .= '</ul></p>';
1.1 raeburn 1236: } else {
1.12 raeburn 1237: $output .= '<p>'.&mt("For the following course/community requests an error occurred when updating the requestor's own requests record:").'<ul>';
1.2 raeburn 1238: foreach my $cnum (@warn_approves,@warn_rejects) {
1239: my $showcourse;
1.23 raeburn 1240: if (ref($requesthash{$cnum.'_'.$queue})) {
1241: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1.2 raeburn 1242: } else {
1243: $showcourse = $cnum;
1244: }
1245: $output .= '<li>'.$showcourse.'</li>';
1.1 raeburn 1246: }
1247: $output .= '</ul></p>';
1248: }
1249: }
1.19 raeburn 1250: if (@warn_dels) {
1.30 raeburn 1251: if ($context eq 'requestauthor') {
1252: $output .= '<p>'.&mt("For the following requests an error occurred when removing the request from the queue:").'<ul>';
1253: foreach my $uname (@warn_dels) {
1254: my $userlink =
1255: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
1256: $output .= '<li>'.$userlink.'</li>';
1257: }
1258: $output .= '</ul></p>';
1259: } else {
1.36 bisitz 1260: $output .= '<p>'.&mt("For the following course/community requests an error occurred when removing requests from the pending queue:").'<ul>';
1.30 raeburn 1261: foreach my $cnum (@warn_dels) {
1262: my $showcourse;
1263: if (ref($requesthash{$cnum.'_'.$queue})) {
1264: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1265: } else {
1266: $showcourse = $cnum;
1267: }
1268: $output .= '<li>'.$showcourse.'</li>';
1.19 raeburn 1269: }
1.30 raeburn 1270: $output .= '</ul></p>';
1.19 raeburn 1271: }
1272: }
1.1 raeburn 1273: return $output;
1274: }
1275:
1.26 raeburn 1276: sub course_portal_url {
1277: my ($cnum,$cdom) = @_;
1278: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1279: my $hostname = &Apache::lonnet::hostname($chome);
1280: my $protocol = $Apache::lonnet::protocol{$chome};
1281: $protocol = 'http' if ($protocol ne 'https');
1282: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
1283: my $firsturl;
1284: if ($domdefaults{'portal_def'}) {
1285: $firsturl = $domdefaults{'portal_def'};
1286: } else {
1287: $firsturl = $protocol.'://'.$hostname;
1288: }
1289: return $firsturl;
1290: }
1291:
1.1 raeburn 1292: sub get_student_counts {
1293: my ($cdom,$cnum) = @_;
1294: my (%idx,%stucounts);
1295: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1296: $idx{'type'} = &Apache::loncoursedata::CL_TYPE();
1297: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
1298: while (my ($student,$data) = each(%$classlist)) {
1299: if (($data->[$idx{'status'}] eq 'Active') ||
1300: ($data->[$idx{'status'}] eq 'Future')) {
1301: if ($data->[$idx{'type'}] eq 'selfenroll') {
1302: $stucounts{'selfenroll'} ++;
1303: }
1304: $stucounts{'allstudents'} ++;
1305: }
1306: }
1307: return (\%stucounts,\%idx,$classlist);
1308: }
1309:
1.2 raeburn 1310: sub course_creation {
1311: my ($dom,$cnum,$context,$details,$logmsg,$newusermsg,$addresult,$enrollcount,$output,
1312: $keysmsg,$domdefs,$longroles) = @_;
1313: unless ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH') &&
1314: (ref($longroles) eq 'HASH')) {
1315: return 'error: Invalid request';
1316: }
1317: my ($result,$ownername,$ownerdom);
1318: my $crstype = $details->{'crstype'};
1319: if ($context eq 'domain') {
1320: $ownername = $details->{'owner'};
1321: $ownerdom = $details->{'domain'};
1322: } else {
1323: $ownername = $env{'user.name'};
1324: $ownerdom = $env{'user.domain'};
1325: }
1326: my $owneremail;
1327: my %emails = &Apache::loncommon::getemails($ownername,$ownerdom);
1328: foreach my $email ('permanentemail','critnotification','notification') {
1329: $owneremail = $emails{$email};
1330: last if ($owneremail ne '');
1331: }
1.8 raeburn 1332: my %reqdetails = &build_batchcreatehash($dom,$context,$details,$owneremail,$domdefs);
1.2 raeburn 1333: my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',
1.22 raeburn 1334: \%reqdetails,$longroles,$logmsg,$newusermsg,$addresult,
1335: $enrollcount,$output,$keysmsg,$ownerdom,$ownername,$cnum,$crstype);
1.2 raeburn 1336: if ($cid eq "/$dom/$cnum") {
1337: $result = 'created';
1338: } else {
1339: $result = 'error: '.$cid;
1340: }
1341: return $result;
1342: }
1343:
1344: sub build_batchcreatehash {
1.8 raeburn 1345: my ($dom,$context,$details,$owneremail,$domdefs) = @_;
1.2 raeburn 1346: my %batchhash;
1347: my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users};
1348: if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
1.17 raeburn 1349: my $emailenc = &escape($owneremail);
1.2 raeburn 1350: my $owner = $details->{'owner'}.':'.$details->{'domain'};
1351: foreach my $item (@items) {
1352: $batchhash{$item} = $details->{$item};
1353: }
1354: $batchhash{'title'} = $details->{'cdescr'};
1355: $batchhash{'coursecode'} = $details->{'instcode'};
1.35 raeburn 1356: if ($domdefs->{'officialcredits'} || $domdefs->{'unofficialcredits'}) {
1357: $batchhash{'defaultcredits'} = $details->{'defaultcredits'};
1358: }
1.2 raeburn 1359: $batchhash{'emailenc'} = $emailenc;
1360: $batchhash{'adds'} = $details->{'autoadds'};
1361: $batchhash{'drops'} = $details->{'autodrops'};
1362: $batchhash{'authtype'} = $domdefs->{'auth_def'};
1363: $batchhash{'authparam'} = $domdefs->{'auth_arg_def'};
1364: if ($details->{'crstype'} eq 'community') {
1365: $batchhash{'crstype'} = 'Community';
1366: } else {
1367: $batchhash{'crstype'} = 'Course';
1368: }
1.8 raeburn 1369: my ($owner_firstname,$owner_lastname);
1370: if ($context eq 'domain') {
1371: my %userenv = &Apache::lonnet::userenvironment($details->{'domain'},
1372: $details->{'owner'},
1373: 'firstname','lastname');
1374: $owner_firstname = $userenv{'firstname'};
1375: $owner_lastname = $userenv{'lastname'};
1376: } else {
1377: $owner_firstname = $env{'environment.firstname'};
1378: $owner_lastname = $env{'environment.lastname'};
1379: }
1380: if (ref($details->{'personnel'}) eq 'HASH') {
1381: %{$batchhash{'users'}} = %{$details->{'personnel'}};
1382: if (ref($batchhash{'users'}) eq 'HASH') {
1383: foreach my $userkey (keys(%{$batchhash{'users'}})) {
1384: if (ref($batchhash{'users'}{$userkey}) eq 'HASH') {
1385: if (ref($batchhash{'users'}{$userkey}{'roles'}) eq 'ARRAY') {
1386: foreach my $role (@{$batchhash{'users'}{$userkey}{'roles'}}) {
1387: my $start = '';
1388: my $end = '';
1389: if ($role eq 'st') {
1390: $start = $details->{'accessstart'};
1391: $end = $details->{'accessend'};
1392: }
1393: $batchhash{'users'}{$userkey}{$role}{'start'} = $start;
1394: $batchhash{'users'}{$userkey}{$role}{'end'} = $end;
1395: }
1396: }
1397: }
1398: }
1399: }
1400: }
1401: $batchhash{'users'}{$owner}{firstname} = $owner_firstname;
1402: $batchhash{'users'}{$owner}{lastname} = $owner_lastname;
1403: $batchhash{'users'}{$owner}{emailenc} = $emailenc;
1404: $batchhash{'users'}{$owner}{owneremail} = $owneremail;
1.2 raeburn 1405: }
1406: return %batchhash;
1407: }
1408:
1.4 raeburn 1409: sub can_clone_course {
1.11 raeburn 1410: my ($uname,$udom,$clonecrs,$clonedom,$crstype) = @_;
1.4 raeburn 1411: my $canclone;
1.11 raeburn 1412: my $ccrole = 'cc';
1.12 raeburn 1413: if ($crstype eq 'community') {
1.11 raeburn 1414: $ccrole = 'co';
1415: }
1.4 raeburn 1416: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',['active'],
1.11 raeburn 1417: [$ccrole],[$clonedom]);
1418: if (exists($roleshash{$clonecrs.':'.$clonedom.':'.$ccrole})) {
1.4 raeburn 1419: $canclone = 1;
1420: } else {
1421: my %courseenv = &Apache::lonnet::userenvironment($clonedom,$clonecrs,('cloners'));
1422: my $cloners = $courseenv{'cloners'};
1423: if ($cloners ne '') {
1424: my @cloneable = split(',',$cloners);
1425: if (grep(/^\*$/,@cloneable)) {
1426: $canclone = 1;
1427: }
1428: if (grep(/^\*:\Q$udom\E$/,@cloneable)) {
1429: $canclone = 1;
1430: }
1431: if (grep(/^\Q$uname\E:\Q$udom\E$/,@cloneable)) {
1432: $canclone = 1;
1433: }
1434: }
1.18 raeburn 1435: unless ($canclone) {
1436: if (&Apache::lonnet::is_course_owner($clonedom,$clonecrs,$uname,$udom)) {
1.20 bisitz 1437: $canclone = 1;
1.18 raeburn 1438: }
1439: }
1.4 raeburn 1440: }
1441: return $canclone;
1442: }
1443:
1.13 raeburn 1444: sub get_processtype {
1.30 raeburn 1445: my ($context,$uname,$udom,$isadv,$dom,$crstype,$inststatuses,$domconfig) = @_;
1.13 raeburn 1446: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1447: if ($uname eq '' || $udom eq '') {
1448: $uname = $env{'user.name'};
1449: $udom = $env{'user.domain'};
1450: $isadv = $env{'user.adv'};
1451: }
1.30 raeburn 1452: my (%userenv,%settings,$val,@options,$envkey);
1453: if ($context eq 'course') {
1454: @options = ('autolimit','validate','approval');
1455: $envkey = 'requestcourses.'.$crstype;
1456: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
1457: if (ref($domconfig->{'requestcourses'}->{$crstype}) eq 'HASH') {
1458: %settings = %{$domconfig->{'requestcourses'}->{$crstype}};
1459: }
1460: }
1461: } else {
1462: @options = ('automatic','approval');
1463: $envkey = 'requestauthor';
1464: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
1465: %settings = %{$domconfig->{'requestauthor'}};
1466: }
1467: }
1468: if (($dom eq $udom) || ($context eq 'requestauthor')) {
1.13 raeburn 1469: %userenv =
1.30 raeburn 1470: &Apache::lonnet::userenvironment($udom,$uname,$envkey,'inststatus');
1471: if ($userenv{$envkey}) {
1472: $val = $userenv{$envkey};
1.13 raeburn 1473: @{$inststatuses} = ('_custom_');
1474: } else {
1.30 raeburn 1475: my %alltasks;
1476: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
1.33 raeburn 1477: $val = $settings{'_LC_adv'};
1.30 raeburn 1478: @{$inststatuses} = ('_LC_adv_');
1479: } else {
1480: if ($userenv{'inststatus'} ne '') {
1481: @{$inststatuses} = split(',',$userenv{'inststatus'});
1482: } else {
1483: @{$inststatuses} = ('default');
1484: }
1485: foreach my $status (@{$inststatuses}) {
1486: if (exists($settings{$status})) {
1487: my $value = $settings{$status};
1488: next unless ($value);
1489: unless (exists($alltasks{$value})) {
1490: if (ref($alltasks{$value}) eq 'ARRAY') {
1491: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
1492: push(@{$alltasks{$value}},$status);
1.13 raeburn 1493: }
1.30 raeburn 1494: } else {
1495: @{$alltasks{$value}} = ($status);
1.13 raeburn 1496: }
1497: }
1.30 raeburn 1498: }
1499: }
1500: my $maxlimit = 0;
1501: if ($context eq 'course') {
1502: foreach my $key (sort(keys(%alltasks))) {
1503: if ($key =~ /^autolimit=(\d*)$/) {
1504: if ($1 eq '') {
1505: $val ='autolimit=';
1506: last;
1507: } elsif ($1 > $maxlimit) {
1508: $maxlimit = $1;
1.13 raeburn 1509: }
1510: }
1.30 raeburn 1511: }
1512: }
1513: if (($context eq 'requestauthor') || (!$val)) {
1514: if ($context eq 'course' && $maxlimit) {
1515: $val = 'autolimit='.$maxlimit;
1516: } else {
1517: foreach my $option (@options) {
1518: if ($alltasks{$option}) {
1519: $val = $option;
1520: last;
1.13 raeburn 1521: }
1522: }
1523: }
1524: }
1525: }
1526: }
1527: } else {
1528: %userenv = &Apache::lonnet::userenvironment($udom,$uname,'reqcrsotherdom.'.$crstype);
1529: if ($userenv{'reqcrsotherdom.'.$crstype}) {
1530: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
1531: my $optregex = join('|',@options);
1532: foreach my $item (@doms) {
1533: my ($extdom,$extopt) = split(':',$item);
1534: if ($extdom eq $dom) {
1535: if ($extopt =~ /^($optregex)(=?\d*)$/) {
1536: $val = $1.$2;
1537: }
1538: last;
1539: }
1540: }
1541: @{$inststatuses} = ('_external_');
1542: }
1543: }
1544: return $val;
1545: }
1546:
1.14 raeburn 1547: sub queued_selfenrollment {
1548: my ($notitle) = @_;
1549: my $output;
1550: my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests');
1551: my %reqs_by_date;
1552: foreach my $item (keys(%selfenrollrequests)) {
1553: if (ref($selfenrollrequests{$item}) eq 'HASH') {
1554: if ($selfenrollrequests{$item}{'status'} eq 'request') {
1555: if ($selfenrollrequests{$item}{'timestamp'}) {
1556: push(@{$reqs_by_date{$selfenrollrequests{$item}{'timestamp'}}},$item);
1557: }
1558: }
1559: }
1560: }
1561: if (keys(%reqs_by_date)) {
1562: unless ($notitle) {
1.32 raeburn 1563: $output .= '<br /><b>'.&mt('Enrollment requests pending Course Coordinator approval').'</b><br />';
1.14 raeburn 1564: }
1565: $output .= &Apache::loncommon::start_data_table().
1566: &Apache::loncommon::start_data_table_header_row().
1567: '<th>'.&mt('Date requested').'</th><th>'.&mt('Course title').'</th>'.
1568: '<th>'.&mt('User role').'</th><th>'.&mt('Section').'</th>'.
1569: &Apache::loncommon::end_data_table_header_row();
1570: my @sorted = sort { $a <=> $b } (keys(%reqs_by_date));
1571: foreach my $item (@sorted) {
1572: if (ref($reqs_by_date{$item}) eq 'ARRAY') {
1573: foreach my $crs (@{$reqs_by_date{$item}}) {
1574: my %courseinfo = &Apache::lonnet::coursedescription($crs);
1575: my $usec = $selfenrollrequests{$crs}{'section'};
1.16 raeburn 1576: my $rolename = &Apache::lonnet::plaintext('st',$courseinfo{'type'},$crs);
1.14 raeburn 1577: if ($usec eq '') {
1578: $usec = &mt('No section');
1579: }
1580: $output .= &Apache::loncommon::start_data_table_row().
1581: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
1582: '<td>'.$courseinfo{'description'}.'</td>'.
1583: '<td>'.$rolename.'</td><td>'.$usec.'</td>'.
1584: &Apache::loncommon::end_data_table_row();
1585: }
1586: }
1587: }
1588: $output .= &Apache::loncommon::end_data_table();
1589: }
1590: return $output;
1591: }
1592:
1.19 raeburn 1593: sub update_coursereq_status {
1.26 raeburn 1594: my ($reqhash,$dom,$cnum,$reqstatus,$context,$udom,$uname) = @_;
1.19 raeburn 1595: my ($storeresult,$statusresult,$output);
1596: my $requestkey = $dom.'_'.$cnum;
1597: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1598: $storeresult = &Apache::lonnet::store_userdata($reqhash,$requestkey,
1.26 raeburn 1599: 'courserequests',$udom,$uname);
1.19 raeburn 1600: if ($storeresult eq 'ok') {
1601: my %status = (
1602: 'status:'.$dom.':'.$cnum => $reqstatus,
1603: );
1.26 raeburn 1604: $statusresult = &Apache::lonnet::put('courserequests',\%status,$udom,$uname);
1.19 raeburn 1605: }
1606: } else {
1607: $storeresult = 'error: invalid requestkey format';
1608: }
1609: if ($storeresult ne 'ok') {
1610: $output = &mt('An error occurred saving a record of the details of your request: [_1].',$storeresult);
1611: if ($context eq 'domain') {
1612: $output .= "\n";
1613: } else {
1614: $output = '<span class="LC_warning">'.$output.'</span><br />';
1615: }
1.26 raeburn 1616: &Apache::lonnet::logthis("Error saving course request - $requestkey for $uname:$udom - $storeresult");
1.19 raeburn 1617: } elsif ($statusresult ne 'ok') {
1618: $output = &mt('An error occurred saving a record of the status of your request: [_1].',$statusresult);
1619: if ($context eq 'domain') {
1620: $output .= "\n";
1621: } else {
1622: $output = '<span class="LC_warning">'.$output.'</span><br />';
1623: }
1.26 raeburn 1624: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $uname:$udom) - $statusresult");
1.19 raeburn 1625: }
1626: return ($storeresult,$output);
1627: }
1628:
1.23 raeburn 1629: sub process_official_reqs {
1.26 raeburn 1630: my ($context,$dom,$dcname,$dcdom) = @_;
1.23 raeburn 1631: my $reqsnamespace = 'courserequestqueue';
1632: my %requesthash =
1.24 raeburn 1633: &Apache::lonnet::dump_dom($reqsnamespace,$dom,'_pending');
1.23 raeburn 1634: my (%newcids,%longroles,%stillpending);
1635: my @courseroles = ('cc','in','ta','ep','ad','st');
1636: foreach my $role (@courseroles) {
1637: $longroles{$role}=&Apache::lonnet::plaintext($role);
1638: }
1639: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1640: my ($output,$linefeed);
1641: if ($context eq 'auto') {
1642: $linefeed = "\n";
1643: } else {
1644: $linefeed = '<br />'."\n";
1645: }
1646: foreach my $key (keys(%requesthash)) {
1647: my ($cnum,$status) = split('_',$key);
1648: next if (&Apache::lonnet::homeserver($cnum,$dom) ne 'no_host');
1649: if (ref($requesthash{$key}) eq 'HASH') {
1650: my $ownername = $requesthash{$key}{'ownername'};
1651: my $ownerdom = $requesthash{$key}{'ownerdom'};
1652: next if (&Apache::lonnet::homeserver($ownername,$ownerdom) eq 'no_host');
1653: my $inststatus;
1654: my %userenv =
1655: &Apache::lonnet::get('environment',['inststatus'],
1656: $ownerdom,$ownername);
1657: my ($tmp) = keys(%userenv);
1658: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
1659: $inststatus = $userenv{'inststatus'};
1660: } else {
1661: undef(%userenv);
1662: }
1663: my $reqkey = $dom.'_'.$cnum;
1664: my %history = &Apache::lonnet::restore($reqkey,'courserequests',
1665: $ownerdom,$ownername);
1666: if (ref($history{'details'}) eq 'HASH') {
1667: my $instcode = $history{'details'}{'instcode'};
1668: my $crstype = $history{'details'}{'crstype'};
1669: my $reqtime = $history{'details'}{'reqtime'};
1670: my $cdescr = $history{'details'}{'cdescr'};
1671: my @currsec;
1672: my $sections = $history{'details'}{'sections'};
1673: if (ref($sections) eq 'HASH') {
1674: foreach my $i (sort(keys(%{$sections}))) {
1675: if (ref($sections->{$i}) eq 'HASH') {
1676: my $sec = $sections->{$i}{'inst'};
1677: if (!grep(/^\Q$sec\E$/,@currsec)) {
1678: push(@currsec,$sec);
1679: }
1680: }
1681: }
1682: }
1683: my $instseclist = join(',',@currsec);
1684: my ($validationchk,$disposition,$reqstatus,$message,
1685: $validation,$validationerror);
1686: $validationchk =
1687: &Apache::lonnet::auto_courserequest_validation($dom,
1688: $ownername.':'.$ownerdom,$crstype,$inststatus,
1689: $instcode,$instseclist);
1690: if ($validationchk =~ /:/) {
1691: ($validation,$message) = split(':',$validationchk);
1692: } else {
1693: $validation = $validationchk;
1694: }
1695: if ($validation =~ /^error(.*)$/) {
1696: $disposition = 'approval';
1697: $validationerror = $1;
1698: } else {
1699: $disposition = $validation;
1700: }
1701: $reqstatus = $disposition;
1702: if ($disposition eq 'process') {
1703: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);
1704: my $result = &course_creation($dom,$cnum,'domain',$history{'details'},\$logmsg,\$newusermsg,\$addresult,\$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
1705: if ($result eq 'created') {
1706: $disposition = 'created';
1707: $reqstatus = 'created';
1.26 raeburn 1708: my $cid = $dom.'_'.$cnum;
1709: push(@{$newcids{$instcode}},$cid);
1710: if ($dcname && $dcdom) {
1711: my $firsturl = &course_portal_url($cnum,$dom);
1712: my $beneficiary = 'pendingrequestor';
1713: my $now = time;
1714: my $owner = $ownername.':'.$ownerdom;
1715: my $approvedmsg =
1716: [{
1.27 raeburn 1717: mt => 'Your requested course: [_1], (queued pending validation) has now been created.',
1718: args => [$cdescr],
1.26 raeburn 1719: },
1720: {
1.28 raeburn 1721: mt => 'Visit [_1] to log-in and access the course.',
1.26 raeburn 1722: args => [$firsturl],
1.27 raeburn 1723: },
1724: {
1725: mt => 'If currently logged-in to LON-CAPA, log-out and log-in again to select your new course role.'
1.26 raeburn 1726: }];
1727: my $sender = $dcname.':'.$dcdom;
1728: &send_selfserve_notification($owner,$approvedmsg,
1729: $cid,$cdescr,$now,
1730: $beneficiary,$sender,
1731: undef,undef,$crstype);
1732: }
1.23 raeburn 1733: }
1734: } elsif ($disposition eq 'rejected') {
1735: $output .= &mt('Queued course request for [_1] submitted by [_2] with status [_3] rejected when validating.',$instcode,$ownername.':'.$ownerdom,$inststatus).$linefeed;
1736: } elsif ($disposition eq 'approval') {
1737: $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;
1738:
1739: my $requestid = $cnum.'_'.$disposition;
1740: my $request = {
1741: $requestid => {
1742: timestamp => $reqtime,
1743: crstype => $crstype,
1744: ownername => $ownername,
1745: ownerdom => $ownerdom,
1746: description => $cdescr,
1747: },
1748: };
1749: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,$dom);
1750: unless ($putresult eq 'ok') {
1751: $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;
1752: }
1753: } elsif ($disposition eq 'pending') {
1754: my $instcode = $requesthash{$key}{'instcode'};
1755: my $description = $requesthash{$key}{'description'};
1756: my $timestamp = $requesthash{$key}{'timestamp'};
1757: my $entry = $cnum.':'.$ownername.':'.$ownerdom.':'.
1758: $instcode.':'.$description;
1759: if (ref($stillpending{$timestamp}) eq 'ARRAY') {
1760: push(@{$stillpending{$timestamp}},$entry);
1761: } else {
1762: $stillpending{$timestamp} = [$entry];
1763: }
1764: }
1765: unless ($disposition eq 'pending') {
1766: my ($statusresult,$output) =
1767: &update_coursereq_status(\%requesthash,$dom,$cnum,
1.26 raeburn 1768: $reqstatus,'domain',$ownerdom,
1769: $ownername);
1.23 raeburn 1770: unless (&Apache::lonnet::del_dom($reqsnamespace,[$cnum.'_pending'],$dom) eq 'ok') {
1771: $output .= &mt('An error occurred when removing the request for [_1] submitted by [_2] from the pending queue.',$instcode,$ownername.':'.$ownerdom).$linefeed;
1772: }
1773: }
1774: }
1775: }
1776: }
1777: foreach my $key (sort(keys(%newcids))) {
1778: if (ref($newcids{$key}) eq 'ARRAY') {
1779: $output .= "created course from queued request: $key - ".join(', ',@{$newcids{$key}}).$linefeed;
1780: my $newcourse = &LONCAPA::escape($key.':'.$newcids{$key});
1781: }
1782: }
1783: unless ($context eq 'auto') {
1784: if (keys(%stillpending) > 0) {
1785: $output .= '<form method="post" name="changequeue" action="/adm/createcourse" />'."\n".
1786: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1787: '<input type="hidden" name="phase" value="requestchange" />'.
1788: '<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>'.
1789: &build_queue_display($dom,'stillpending',\%stillpending).
1790: '<br /><input type="hidden" name="queue" value="pending" />'."\n".
1791: '<input type="submit" name="processqueue" value="'.&mt('Save').'" />'.
1792: '</form>';
1793: }
1794: }
1795: return $output;
1796: }
1797:
1.31 raeburn 1798: sub is_active_author {
1799: if ($env{'user.role.au./'.$env{'user.domain'}.'/'} =~ /^(\d*)\.(\d*)$/) {
1800: if ((!$1 || $1 < time) &&
1801: (!$2 || $2 > time)) {
1802: return 1;
1803: }
1804: }
1805: }
1806:
1807: sub author_prompt {
1808: my ($is_active_author,$offer_author);
1809: if ($env{'environment.canrequest.author'}) {
1810: unless (&is_active_author()) {
1.32 raeburn 1811: unless (&reqauthor_check() =~ /^approval:\d+$/) {
1812: $offer_author = 1;
1.31 raeburn 1813: }
1814: }
1815: }
1816: return $offer_author;
1817: }
1818:
1819: sub reqauthor_check {
1820: my $queued = $env{'environment.requestauthorqueued'};
1821: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
1822: $env{'user.domain'},$env{'user.name'});
1823: my $reqstatus = $reqauthor{'author_status'};
1824: if (($reqstatus eq '' && $queued ne '') ||
1825: ($env{'environment.requestauthorqueued'} !~ /^\Q$reqstatus\E/)) {
1826: if (ref($reqauthor{'author'}) eq 'HASH') {
1827: $queued = $reqstatus.':'.$reqauthor{'author'}{'timestamp'};
1828: } else {
1829: undef($queued);
1830: }
1831: &Apache::lonnet::appenv({'environment.requestauthorqueued' => $queued});
1832: }
1833: return $queued;
1834: }
1835:
1836: sub process_reqauthor {
1837: my ($dispositionref,$updateref) = @_;
1838: if (&is_active_author()) {
1839: return '<span class="LC_warning">'.
1840: &mt('An authoring space has already been assigned to you.').'<br />'.
1841: &mt('Please select the Author role from your [_1]roles page[_2].','<a href="/adm/roles">',
1842: '</a>').'</span>';
1843: }
1844: unless ($env{'environment.canrequest.author'}) {
1845: return '<span class="LC_warning">'.
1846: &mt('You do not currently have rights to request an authoring space.').'<br />'.
1.37 raeburn 1847: &mt('Please contact the [_1]helpdesk[_2] for assistance.','<a href="/adm/helpdesk">',
1.31 raeburn 1848: '</a>').'</span>';
1849: }
1850: my $queued = &reqauthor_check();
1851: if ($queued =~ /^approval:(\d+)$/) {
1852: my $timestamp = $1;
1853: return '<span class="LC_info">'.
1854: &mt('A request for authoring space submitted on [_1] is awaiting approval',
1855: &Apache::lonlocal::locallocaltime($timestamp)).
1856: '</span>';
1857: } elsif ($queued =~ /^approved:(\d+)$/) {
1858: my $timestamp = $1;
1859: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
1860: ['active'],['au'],[$env{'user.domain'}]);
1861: if (keys(%roleshash) > 0) {
1862: return '<span class="LC_info">'.
1863: &mt('A request for authoring space submitted on [_1] has been approved.',
1864: &Apache::lonlocal::locallocaltime($timestamp)).
1865: '</span>';
1866: }
1867: }
1868: my ($output,@inststatuses,%domconfig);
1869: %domconfig = &Apache::lonnet::get_dom('configuration',['requestauthor'],
1870: $env{'user.domain'});
1871: my $val = &get_processtype('requestauthor',$env{'user.name'},$env{'user.domain'},
1872: $env{'user.adv'},$env{'user.domain'},undef,
1873: \@inststatuses,\%domconfig);
1874: my $now = time;
1875: if ($val eq 'automatic') {
1876: my $start = $now-1;
1877: if (&Apache::lonnet::assignrole($env{'user.domain'},$env{'user.name'},'/'.$env{'user.domain'}.'/',
1878: 'au',undef,$start,undef,undef,'requestauthor') eq 'ok') {
1879: $output = '<span class="LC_info">'.
1880: &mt('Access to authoring space has been activated').'</span><br />';
1881: &Apache::lonroles::update_session_roles();
1882: &Apache::lonnet::appenv({'user.update.time' => $now});
1883: if (ref($updateref)) {
1884: $$updateref = $now;
1885: }
1886: if (ref($dispositionref)) {
1887: $$dispositionref = 'created';
1888: }
1889: } else {
1890: $output = '<span class="LC_info">'.
1891: &mt('An error occurred while activating your access to authoring space');
1892: }
1893: } elsif ($val eq 'approval') {
1894: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($env{'user.domain'});
1895: if (&Apache::lonnet::put('requestauthorqueue',{ $env{'user.name'}.'_'.$val => $now },
1896: $env{'user.domain'},$domconfiguser) eq 'ok') {
1897: my %userrequest = (
1898: author => {
1899: timestamp => $now,
1900: status => $val,
1901: },
1902: author_status => $val,
1903: );
1904: my $req_notifylist;
1905: if (ref($domconfig{'requestauthor'}) eq 'HASH') {
1906: if (ref($domconfig{'requestauthor'}{'notify'}) eq 'HASH') {
1907: my $req_notifylist = $domconfig{'requestauthor'}{'notify'}{'approval'};
1908: if ($req_notifylist) {
1909: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
1910: $env{'user.domain'});
1911: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
1912: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1913: &send_selfserve_notification($req_notifylist,
1914: "$fullname ($env{'user.name'}:$env{'user.domain'})",
1915: undef,$domdesc,$now,'authorreq',$sender);
1916: }
1917: }
1918: }
1919: my $userresult =
1920: &Apache::lonnet::put('requestauthor',\%userrequest,$env{'user.domain'},$env{'user.name'});
1921: $output = '<span class="LC_info">'.
1922: &mt('Your request for authoring space has been submitted for approval.').
1923: '</span>';
1924: &Apache::lonnet::appenv({'environment.requestauthorqueued' => $val.':'.$now});
1925: } else {
1926: $output = '<span class="LC_info">'.
1927: &mt('An error occurred saving your request for authoring space.').
1928: '</span>';
1929: }
1930: }
1931: return $output;
1932: }
1933:
1.1 raeburn 1934: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>