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