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