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