Annotation of loncom/interface/loncoursequeueadmin.pm, revision 1.46
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.46 ! raeburn 4: # $Id: loncoursequeueadmin.pm,v 1.45 2014/04/16 13:32: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.40 raeburn 1608: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestauthor'],$dom);
1609: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
1610: if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
1611: if ($domconfig{'requestcourses'}{'uniquecode'}{$crstype}) {
1612: $details->{'uniquecode'} = 1;
1613: }
1614: }
1615: }
1.2 raeburn 1616: if ($context eq 'domain') {
1617: $ownername = $details->{'owner'};
1618: $ownerdom = $details->{'domain'};
1619: } else {
1620: $ownername = $env{'user.name'};
1621: $ownerdom = $env{'user.domain'};
1622: }
1.41 raeburn 1623: my $fullname = &Apache::loncommon::plainname($ownername,$ownerdom);
1.2 raeburn 1624: my $owneremail;
1625: my %emails = &Apache::loncommon::getemails($ownername,$ownerdom);
1626: foreach my $email ('permanentemail','critnotification','notification') {
1627: $owneremail = $emails{$email};
1628: last if ($owneremail ne '');
1629: }
1.8 raeburn 1630: my %reqdetails = &build_batchcreatehash($dom,$context,$details,$owneremail,$domdefs);
1.2 raeburn 1631: my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',
1.22 raeburn 1632: \%reqdetails,$longroles,$logmsg,$newusermsg,$addresult,
1.39 raeburn 1633: $enrollcount,$output,$keysmsg,$ownerdom,$ownername,$cnum,$crstype,$coderef);
1.41 raeburn 1634: my $postprocess;
1.2 raeburn 1635: if ($cid eq "/$dom/$cnum") {
1636: $result = 'created';
1.41 raeburn 1637: my $code;
1638: if (ref($coderef)) {
1639: $code = $$coderef;
1640: }
1641: $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,$result,$ownername,
1642: $ownerdom,$fullname,$coursedesc,$code,$customhash);
1.2 raeburn 1643: } else {
1644: $result = 'error: '.$cid;
1645: }
1.41 raeburn 1646: return ($result,$postprocess);
1.2 raeburn 1647: }
1648:
1649: sub build_batchcreatehash {
1.8 raeburn 1650: my ($dom,$context,$details,$owneremail,$domdefs) = @_;
1.2 raeburn 1651: my %batchhash;
1.39 raeburn 1652: my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users uniquecode};
1.2 raeburn 1653: if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
1.17 raeburn 1654: my $emailenc = &escape($owneremail);
1.2 raeburn 1655: my $owner = $details->{'owner'}.':'.$details->{'domain'};
1656: foreach my $item (@items) {
1657: $batchhash{$item} = $details->{$item};
1658: }
1659: $batchhash{'title'} = $details->{'cdescr'};
1660: $batchhash{'coursecode'} = $details->{'instcode'};
1.35 raeburn 1661: if ($domdefs->{'officialcredits'} || $domdefs->{'unofficialcredits'}) {
1662: $batchhash{'defaultcredits'} = $details->{'defaultcredits'};
1663: }
1.2 raeburn 1664: $batchhash{'emailenc'} = $emailenc;
1665: $batchhash{'adds'} = $details->{'autoadds'};
1666: $batchhash{'drops'} = $details->{'autodrops'};
1667: $batchhash{'authtype'} = $domdefs->{'auth_def'};
1668: $batchhash{'authparam'} = $domdefs->{'auth_arg_def'};
1669: if ($details->{'crstype'} eq 'community') {
1670: $batchhash{'crstype'} = 'Community';
1671: } else {
1.41 raeburn 1672: if ($details->{'crstype'} eq 'textbook') {
1673: if ($details->{'clonecrs'} && $details->{'clonedom'}) {
1674: my %clonedfrom = &Apache::lonnet::coursedescription($details->{'clonedom'}.'_'.$details->{'clonecrs'});
1675: $batchhash{'textbook'} = $clonedfrom{'description'};
1676: }
1677: }
1.2 raeburn 1678: $batchhash{'crstype'} = 'Course';
1679: }
1.8 raeburn 1680: my ($owner_firstname,$owner_lastname);
1681: if ($context eq 'domain') {
1682: my %userenv = &Apache::lonnet::userenvironment($details->{'domain'},
1683: $details->{'owner'},
1684: 'firstname','lastname');
1685: $owner_firstname = $userenv{'firstname'};
1686: $owner_lastname = $userenv{'lastname'};
1687: } else {
1688: $owner_firstname = $env{'environment.firstname'};
1689: $owner_lastname = $env{'environment.lastname'};
1690: }
1691: if (ref($details->{'personnel'}) eq 'HASH') {
1692: %{$batchhash{'users'}} = %{$details->{'personnel'}};
1693: if (ref($batchhash{'users'}) eq 'HASH') {
1694: foreach my $userkey (keys(%{$batchhash{'users'}})) {
1695: if (ref($batchhash{'users'}{$userkey}) eq 'HASH') {
1696: if (ref($batchhash{'users'}{$userkey}{'roles'}) eq 'ARRAY') {
1697: foreach my $role (@{$batchhash{'users'}{$userkey}{'roles'}}) {
1698: my $start = '';
1699: my $end = '';
1700: if ($role eq 'st') {
1701: $start = $details->{'accessstart'};
1702: $end = $details->{'accessend'};
1703: }
1704: $batchhash{'users'}{$userkey}{$role}{'start'} = $start;
1705: $batchhash{'users'}{$userkey}{$role}{'end'} = $end;
1706: }
1707: }
1708: }
1709: }
1710: }
1711: }
1712: $batchhash{'users'}{$owner}{firstname} = $owner_firstname;
1713: $batchhash{'users'}{$owner}{lastname} = $owner_lastname;
1714: $batchhash{'users'}{$owner}{emailenc} = $emailenc;
1715: $batchhash{'users'}{$owner}{owneremail} = $owneremail;
1.2 raeburn 1716: }
1717: return %batchhash;
1718: }
1719:
1.4 raeburn 1720: sub can_clone_course {
1.11 raeburn 1721: my ($uname,$udom,$clonecrs,$clonedom,$crstype) = @_;
1.4 raeburn 1722: my $canclone;
1.11 raeburn 1723: my $ccrole = 'cc';
1.12 raeburn 1724: if ($crstype eq 'community') {
1.11 raeburn 1725: $ccrole = 'co';
1726: }
1.4 raeburn 1727: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',['active'],
1.11 raeburn 1728: [$ccrole],[$clonedom]);
1729: if (exists($roleshash{$clonecrs.':'.$clonedom.':'.$ccrole})) {
1.4 raeburn 1730: $canclone = 1;
1731: } else {
1732: my %courseenv = &Apache::lonnet::userenvironment($clonedom,$clonecrs,('cloners'));
1733: my $cloners = $courseenv{'cloners'};
1734: if ($cloners ne '') {
1735: my @cloneable = split(',',$cloners);
1736: if (grep(/^\*$/,@cloneable)) {
1737: $canclone = 1;
1738: }
1739: if (grep(/^\*:\Q$udom\E$/,@cloneable)) {
1740: $canclone = 1;
1741: }
1742: if (grep(/^\Q$uname\E:\Q$udom\E$/,@cloneable)) {
1743: $canclone = 1;
1744: }
1745: }
1.18 raeburn 1746: unless ($canclone) {
1747: if (&Apache::lonnet::is_course_owner($clonedom,$clonecrs,$uname,$udom)) {
1.20 bisitz 1748: $canclone = 1;
1.18 raeburn 1749: }
1750: }
1.4 raeburn 1751: }
1752: return $canclone;
1753: }
1754:
1.13 raeburn 1755: sub get_processtype {
1.30 raeburn 1756: my ($context,$uname,$udom,$isadv,$dom,$crstype,$inststatuses,$domconfig) = @_;
1.13 raeburn 1757: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1758: if ($uname eq '' || $udom eq '') {
1759: $uname = $env{'user.name'};
1760: $udom = $env{'user.domain'};
1761: $isadv = $env{'user.adv'};
1762: }
1.30 raeburn 1763: my (%userenv,%settings,$val,@options,$envkey);
1764: if ($context eq 'course') {
1765: @options = ('autolimit','validate','approval');
1766: $envkey = 'requestcourses.'.$crstype;
1767: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
1768: if (ref($domconfig->{'requestcourses'}->{$crstype}) eq 'HASH') {
1769: %settings = %{$domconfig->{'requestcourses'}->{$crstype}};
1770: }
1771: }
1772: } else {
1773: @options = ('automatic','approval');
1774: $envkey = 'requestauthor';
1775: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
1776: %settings = %{$domconfig->{'requestauthor'}};
1777: }
1778: }
1779: if (($dom eq $udom) || ($context eq 'requestauthor')) {
1.13 raeburn 1780: %userenv =
1.30 raeburn 1781: &Apache::lonnet::userenvironment($udom,$uname,$envkey,'inststatus');
1782: if ($userenv{$envkey}) {
1783: $val = $userenv{$envkey};
1.13 raeburn 1784: @{$inststatuses} = ('_custom_');
1785: } else {
1.30 raeburn 1786: my %alltasks;
1787: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
1.33 raeburn 1788: $val = $settings{'_LC_adv'};
1.30 raeburn 1789: @{$inststatuses} = ('_LC_adv_');
1790: } else {
1791: if ($userenv{'inststatus'} ne '') {
1792: @{$inststatuses} = split(',',$userenv{'inststatus'});
1793: } else {
1794: @{$inststatuses} = ('default');
1795: }
1796: foreach my $status (@{$inststatuses}) {
1797: if (exists($settings{$status})) {
1798: my $value = $settings{$status};
1799: next unless ($value);
1800: unless (exists($alltasks{$value})) {
1801: if (ref($alltasks{$value}) eq 'ARRAY') {
1802: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
1803: push(@{$alltasks{$value}},$status);
1.13 raeburn 1804: }
1.30 raeburn 1805: } else {
1806: @{$alltasks{$value}} = ($status);
1.13 raeburn 1807: }
1808: }
1.30 raeburn 1809: }
1810: }
1811: my $maxlimit = 0;
1812: if ($context eq 'course') {
1813: foreach my $key (sort(keys(%alltasks))) {
1814: if ($key =~ /^autolimit=(\d*)$/) {
1815: if ($1 eq '') {
1816: $val ='autolimit=';
1817: last;
1818: } elsif ($1 > $maxlimit) {
1819: $maxlimit = $1;
1.13 raeburn 1820: }
1821: }
1.30 raeburn 1822: }
1823: }
1824: if (($context eq 'requestauthor') || (!$val)) {
1825: if ($context eq 'course' && $maxlimit) {
1826: $val = 'autolimit='.$maxlimit;
1827: } else {
1828: foreach my $option (@options) {
1829: if ($alltasks{$option}) {
1830: $val = $option;
1831: last;
1.13 raeburn 1832: }
1833: }
1834: }
1835: }
1836: }
1837: }
1838: } else {
1839: %userenv = &Apache::lonnet::userenvironment($udom,$uname,'reqcrsotherdom.'.$crstype);
1840: if ($userenv{'reqcrsotherdom.'.$crstype}) {
1841: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
1842: my $optregex = join('|',@options);
1843: foreach my $item (@doms) {
1844: my ($extdom,$extopt) = split(':',$item);
1845: if ($extdom eq $dom) {
1846: if ($extopt =~ /^($optregex)(=?\d*)$/) {
1847: $val = $1.$2;
1848: }
1849: last;
1850: }
1851: }
1852: @{$inststatuses} = ('_external_');
1853: }
1854: }
1855: return $val;
1856: }
1857:
1.14 raeburn 1858: sub queued_selfenrollment {
1859: my ($notitle) = @_;
1860: my $output;
1861: my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests');
1862: my %reqs_by_date;
1863: foreach my $item (keys(%selfenrollrequests)) {
1864: if (ref($selfenrollrequests{$item}) eq 'HASH') {
1865: if ($selfenrollrequests{$item}{'status'} eq 'request') {
1866: if ($selfenrollrequests{$item}{'timestamp'}) {
1867: push(@{$reqs_by_date{$selfenrollrequests{$item}{'timestamp'}}},$item);
1868: }
1869: }
1870: }
1871: }
1872: if (keys(%reqs_by_date)) {
1873: unless ($notitle) {
1.32 raeburn 1874: $output .= '<br /><b>'.&mt('Enrollment requests pending Course Coordinator approval').'</b><br />';
1.14 raeburn 1875: }
1876: $output .= &Apache::loncommon::start_data_table().
1877: &Apache::loncommon::start_data_table_header_row().
1878: '<th>'.&mt('Date requested').'</th><th>'.&mt('Course title').'</th>'.
1879: '<th>'.&mt('User role').'</th><th>'.&mt('Section').'</th>'.
1880: &Apache::loncommon::end_data_table_header_row();
1881: my @sorted = sort { $a <=> $b } (keys(%reqs_by_date));
1882: foreach my $item (@sorted) {
1883: if (ref($reqs_by_date{$item}) eq 'ARRAY') {
1884: foreach my $crs (@{$reqs_by_date{$item}}) {
1885: my %courseinfo = &Apache::lonnet::coursedescription($crs);
1886: my $usec = $selfenrollrequests{$crs}{'section'};
1.16 raeburn 1887: my $rolename = &Apache::lonnet::plaintext('st',$courseinfo{'type'},$crs);
1.14 raeburn 1888: if ($usec eq '') {
1889: $usec = &mt('No section');
1890: }
1891: $output .= &Apache::loncommon::start_data_table_row().
1892: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
1893: '<td>'.$courseinfo{'description'}.'</td>'.
1894: '<td>'.$rolename.'</td><td>'.$usec.'</td>'.
1895: &Apache::loncommon::end_data_table_row();
1896: }
1897: }
1898: }
1899: $output .= &Apache::loncommon::end_data_table();
1900: }
1901: return $output;
1902: }
1903:
1.19 raeburn 1904: sub update_coursereq_status {
1.26 raeburn 1905: my ($reqhash,$dom,$cnum,$reqstatus,$context,$udom,$uname) = @_;
1.19 raeburn 1906: my ($storeresult,$statusresult,$output);
1907: my $requestkey = $dom.'_'.$cnum;
1908: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1909: $storeresult = &Apache::lonnet::store_userdata($reqhash,$requestkey,
1.26 raeburn 1910: 'courserequests',$udom,$uname);
1.19 raeburn 1911: if ($storeresult eq 'ok') {
1912: my %status = (
1913: 'status:'.$dom.':'.$cnum => $reqstatus,
1914: );
1.26 raeburn 1915: $statusresult = &Apache::lonnet::put('courserequests',\%status,$udom,$uname);
1.19 raeburn 1916: }
1917: } else {
1918: $storeresult = 'error: invalid requestkey format';
1919: }
1920: if ($storeresult ne 'ok') {
1921: $output = &mt('An error occurred saving a record of the details of your request: [_1].',$storeresult);
1922: if ($context eq 'domain') {
1923: $output .= "\n";
1924: } else {
1925: $output = '<span class="LC_warning">'.$output.'</span><br />';
1926: }
1.26 raeburn 1927: &Apache::lonnet::logthis("Error saving course request - $requestkey for $uname:$udom - $storeresult");
1.19 raeburn 1928: } elsif ($statusresult ne 'ok') {
1929: $output = &mt('An error occurred saving a record of the status of your request: [_1].',$statusresult);
1930: if ($context eq 'domain') {
1931: $output .= "\n";
1932: } else {
1933: $output = '<span class="LC_warning">'.$output.'</span><br />';
1934: }
1.26 raeburn 1935: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $uname:$udom) - $statusresult");
1.19 raeburn 1936: }
1937: return ($storeresult,$output);
1938: }
1939:
1.23 raeburn 1940: sub process_official_reqs {
1.26 raeburn 1941: my ($context,$dom,$dcname,$dcdom) = @_;
1.23 raeburn 1942: my $reqsnamespace = 'courserequestqueue';
1943: my %requesthash =
1.24 raeburn 1944: &Apache::lonnet::dump_dom($reqsnamespace,$dom,'_pending');
1.23 raeburn 1945: my (%newcids,%longroles,%stillpending);
1946: my @courseroles = ('cc','in','ta','ep','ad','st');
1947: foreach my $role (@courseroles) {
1948: $longroles{$role}=&Apache::lonnet::plaintext($role);
1949: }
1950: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1951: my ($output,$linefeed);
1952: if ($context eq 'auto') {
1953: $linefeed = "\n";
1954: } else {
1955: $linefeed = '<br />'."\n";
1956: }
1957: foreach my $key (keys(%requesthash)) {
1958: my ($cnum,$status) = split('_',$key);
1959: next if (&Apache::lonnet::homeserver($cnum,$dom) ne 'no_host');
1960: if (ref($requesthash{$key}) eq 'HASH') {
1961: my $ownername = $requesthash{$key}{'ownername'};
1962: my $ownerdom = $requesthash{$key}{'ownerdom'};
1963: next if (&Apache::lonnet::homeserver($ownername,$ownerdom) eq 'no_host');
1964: my $inststatus;
1965: my %userenv =
1966: &Apache::lonnet::get('environment',['inststatus'],
1967: $ownerdom,$ownername);
1968: my ($tmp) = keys(%userenv);
1969: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
1970: $inststatus = $userenv{'inststatus'};
1971: } else {
1972: undef(%userenv);
1973: }
1974: my $reqkey = $dom.'_'.$cnum;
1975: my %history = &Apache::lonnet::restore($reqkey,'courserequests',
1976: $ownerdom,$ownername);
1977: if (ref($history{'details'}) eq 'HASH') {
1978: my $instcode = $history{'details'}{'instcode'};
1979: my $crstype = $history{'details'}{'crstype'};
1980: my $reqtime = $history{'details'}{'reqtime'};
1981: my $cdescr = $history{'details'}{'cdescr'};
1982: my @currsec;
1983: my $sections = $history{'details'}{'sections'};
1984: if (ref($sections) eq 'HASH') {
1985: foreach my $i (sort(keys(%{$sections}))) {
1986: if (ref($sections->{$i}) eq 'HASH') {
1987: my $sec = $sections->{$i}{'inst'};
1988: if (!grep(/^\Q$sec\E$/,@currsec)) {
1989: push(@currsec,$sec);
1990: }
1991: }
1992: }
1993: }
1994: my $instseclist = join(',',@currsec);
1995: my ($validationchk,$disposition,$reqstatus,$message,
1996: $validation,$validationerror);
1997: $validationchk =
1998: &Apache::lonnet::auto_courserequest_validation($dom,
1999: $ownername.':'.$ownerdom,$crstype,$inststatus,
2000: $instcode,$instseclist);
2001: if ($validationchk =~ /:/) {
2002: ($validation,$message) = split(':',$validationchk);
2003: } else {
2004: $validation = $validationchk;
2005: }
2006: if ($validation =~ /^error(.*)$/) {
2007: $disposition = 'approval';
2008: $validationerror = $1;
2009: } else {
2010: $disposition = $validation;
2011: }
2012: $reqstatus = $disposition;
2013: if ($disposition eq 'process') {
1.39 raeburn 2014: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,$code);
1.41 raeburn 2015: my %customitems;
2016: my $fullname = &Apache::loncommon::plainname($ownername,$ownerdom);
2017: my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$ownername,
2018: $ownerdom,$fullname,$cdescr);
2019: if (ref($inprocess) eq 'HASH') {
2020: foreach my $key (keys(%{$inprocess})) {
2021: if (exists($history{'details'}{$key})) {
2022: $customitems{$key} = $history{'details'}{$key};
2023: }
2024: }
2025: }
2026: my ($result,$postprocess) =
2027: &course_creation($dom,$cnum,'domain',$history{'details'},\$logmsg,\$newusermsg,\$addresult,
2028: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,\$code,\%customitems);
1.23 raeburn 2029: if ($result eq 'created') {
2030: $disposition = 'created';
2031: $reqstatus = 'created';
1.26 raeburn 2032: my $cid = $dom.'_'.$cnum;
2033: push(@{$newcids{$instcode}},$cid);
2034: if ($dcname && $dcdom) {
2035: my $firsturl = &course_portal_url($cnum,$dom);
2036: my $beneficiary = 'pendingrequestor';
2037: my $now = time;
2038: my $owner = $ownername.':'.$ownerdom;
2039: my $approvedmsg =
2040: [{
1.27 raeburn 2041: mt => 'Your requested course: [_1], (queued pending validation) has now been created.',
2042: args => [$cdescr],
1.26 raeburn 2043: },
2044: {
1.28 raeburn 2045: mt => 'Visit [_1] to log-in and access the course.',
1.26 raeburn 2046: args => [$firsturl],
1.27 raeburn 2047: },
2048: {
2049: mt => 'If currently logged-in to LON-CAPA, log-out and log-in again to select your new course role.'
1.26 raeburn 2050: }];
2051: my $sender = $dcname.':'.$dcdom;
1.41 raeburn 2052: if (ref($postprocess) eq 'HASH') {
2053: if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
2054: foreach my $item (@{$postprocess->{'createdmsg'}}) {
2055: if (ref($item) eq 'HASH') {
2056: if ($item->{'mt'} ne '') {
2057: push(@{$approvedmsg},$item);
2058: }
2059: }
2060: }
2061: }
2062: }
1.26 raeburn 2063: &send_selfserve_notification($owner,$approvedmsg,
2064: $cid,$cdescr,$now,
2065: $beneficiary,$sender,
2066: undef,undef,$crstype);
2067: }
1.23 raeburn 2068: }
2069: } elsif ($disposition eq 'rejected') {
2070: $output .= &mt('Queued course request for [_1] submitted by [_2] with status [_3] rejected when validating.',$instcode,$ownername.':'.$ownerdom,$inststatus).$linefeed;
2071: } elsif ($disposition eq 'approval') {
2072: $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;
2073:
2074: my $requestid = $cnum.'_'.$disposition;
2075: my $request = {
2076: $requestid => {
2077: timestamp => $reqtime,
2078: crstype => $crstype,
2079: ownername => $ownername,
2080: ownerdom => $ownerdom,
2081: description => $cdescr,
2082: },
2083: };
2084: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,$dom);
2085: unless ($putresult eq 'ok') {
2086: $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;
2087: }
2088: } elsif ($disposition eq 'pending') {
2089: my $instcode = $requesthash{$key}{'instcode'};
2090: my $description = $requesthash{$key}{'description'};
2091: my $timestamp = $requesthash{$key}{'timestamp'};
2092: my $entry = $cnum.':'.$ownername.':'.$ownerdom.':'.
2093: $instcode.':'.$description;
2094: if (ref($stillpending{$timestamp}) eq 'ARRAY') {
2095: push(@{$stillpending{$timestamp}},$entry);
2096: } else {
2097: $stillpending{$timestamp} = [$entry];
2098: }
2099: }
2100: unless ($disposition eq 'pending') {
2101: my ($statusresult,$output) =
2102: &update_coursereq_status(\%requesthash,$dom,$cnum,
1.26 raeburn 2103: $reqstatus,'domain',$ownerdom,
2104: $ownername);
1.23 raeburn 2105: unless (&Apache::lonnet::del_dom($reqsnamespace,[$cnum.'_pending'],$dom) eq 'ok') {
2106: $output .= &mt('An error occurred when removing the request for [_1] submitted by [_2] from the pending queue.',$instcode,$ownername.':'.$ownerdom).$linefeed;
2107: }
2108: }
2109: }
2110: }
2111: }
2112: foreach my $key (sort(keys(%newcids))) {
2113: if (ref($newcids{$key}) eq 'ARRAY') {
2114: $output .= "created course from queued request: $key - ".join(', ',@{$newcids{$key}}).$linefeed;
2115: my $newcourse = &LONCAPA::escape($key.':'.$newcids{$key});
2116: }
2117: }
2118: unless ($context eq 'auto') {
2119: if (keys(%stillpending) > 0) {
2120: $output .= '<form method="post" name="changequeue" action="/adm/createcourse" />'."\n".
2121: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
2122: '<input type="hidden" name="phase" value="requestchange" />'.
2123: '<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>'.
2124: &build_queue_display($dom,'stillpending',\%stillpending).
2125: '<br /><input type="hidden" name="queue" value="pending" />'."\n".
2126: '<input type="submit" name="processqueue" value="'.&mt('Save').'" />'.
2127: '</form>';
2128: }
2129: }
2130: return $output;
2131: }
2132:
1.45 raeburn 2133: sub requestcourses_validation_types {
2134: my @items = ('url','fields','button','markup');
2135: my %names = &Apache::lonlocal::texthash (
2136: url => 'Web address of validation server/script',
2137: fields => 'Form fields to send to validator',
2138: button => 'Text for validation button',
2139: markup => 'Validation description (HTML)',
2140: );
2141: my @fields = ('owner','course','coursetype','description');
2142: return (\@items,\%names,\@fields);
2143: }
2144:
1.31 raeburn 2145: sub is_active_author {
2146: if ($env{'user.role.au./'.$env{'user.domain'}.'/'} =~ /^(\d*)\.(\d*)$/) {
2147: if ((!$1 || $1 < time) &&
2148: (!$2 || $2 > time)) {
2149: return 1;
2150: }
2151: }
2152: }
2153:
2154: sub author_prompt {
2155: my ($is_active_author,$offer_author);
2156: if ($env{'environment.canrequest.author'}) {
2157: unless (&is_active_author()) {
1.32 raeburn 2158: unless (&reqauthor_check() =~ /^approval:\d+$/) {
2159: $offer_author = 1;
1.31 raeburn 2160: }
2161: }
2162: }
2163: return $offer_author;
2164: }
2165:
2166: sub reqauthor_check {
2167: my $queued = $env{'environment.requestauthorqueued'};
2168: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
2169: $env{'user.domain'},$env{'user.name'});
2170: my $reqstatus = $reqauthor{'author_status'};
2171: if (($reqstatus eq '' && $queued ne '') ||
2172: ($env{'environment.requestauthorqueued'} !~ /^\Q$reqstatus\E/)) {
2173: if (ref($reqauthor{'author'}) eq 'HASH') {
2174: $queued = $reqstatus.':'.$reqauthor{'author'}{'timestamp'};
2175: } else {
2176: undef($queued);
2177: }
2178: &Apache::lonnet::appenv({'environment.requestauthorqueued' => $queued});
2179: }
2180: return $queued;
2181: }
2182:
2183: sub process_reqauthor {
2184: my ($dispositionref,$updateref) = @_;
2185: if (&is_active_author()) {
2186: return '<span class="LC_warning">'.
1.42 bisitz 2187: &mt('An Authoring Space has already been assigned to you.').'<br />'.
1.31 raeburn 2188: &mt('Please select the Author role from your [_1]roles page[_2].','<a href="/adm/roles">',
2189: '</a>').'</span>';
2190: }
2191: unless ($env{'environment.canrequest.author'}) {
2192: return '<span class="LC_warning">'.
1.42 bisitz 2193: &mt('You do not currently have rights to request an Authoring Space.').'<br />'.
1.37 raeburn 2194: &mt('Please contact the [_1]helpdesk[_2] for assistance.','<a href="/adm/helpdesk">',
1.31 raeburn 2195: '</a>').'</span>';
2196: }
2197: my $queued = &reqauthor_check();
2198: if ($queued =~ /^approval:(\d+)$/) {
2199: my $timestamp = $1;
2200: return '<span class="LC_info">'.
1.42 bisitz 2201: &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
1.31 raeburn 2202: &Apache::lonlocal::locallocaltime($timestamp)).
2203: '</span>';
2204: } elsif ($queued =~ /^approved:(\d+)$/) {
2205: my $timestamp = $1;
2206: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
2207: ['active'],['au'],[$env{'user.domain'}]);
2208: if (keys(%roleshash) > 0) {
2209: return '<span class="LC_info">'.
1.42 bisitz 2210: &mt('A request for Authoring Space submitted on [_1] has been approved.',
1.31 raeburn 2211: &Apache::lonlocal::locallocaltime($timestamp)).
2212: '</span>';
2213: }
2214: }
2215: my ($output,@inststatuses,%domconfig);
2216: %domconfig = &Apache::lonnet::get_dom('configuration',['requestauthor'],
2217: $env{'user.domain'});
2218: my $val = &get_processtype('requestauthor',$env{'user.name'},$env{'user.domain'},
2219: $env{'user.adv'},$env{'user.domain'},undef,
2220: \@inststatuses,\%domconfig);
2221: my $now = time;
2222: if ($val eq 'automatic') {
2223: my $start = $now-1;
2224: if (&Apache::lonnet::assignrole($env{'user.domain'},$env{'user.name'},'/'.$env{'user.domain'}.'/',
2225: 'au',undef,$start,undef,undef,'requestauthor') eq 'ok') {
2226: $output = '<span class="LC_info">'.
1.42 bisitz 2227: &mt('Access to Authoring Space has been activated').'</span><br />';
1.31 raeburn 2228: &Apache::lonroles::update_session_roles();
2229: &Apache::lonnet::appenv({'user.update.time' => $now});
2230: if (ref($updateref)) {
2231: $$updateref = $now;
2232: }
2233: if (ref($dispositionref)) {
2234: $$dispositionref = 'created';
2235: }
2236: } else {
2237: $output = '<span class="LC_info">'.
1.42 bisitz 2238: &mt('An error occurred while activating your access to Authoring Space');
1.31 raeburn 2239: }
2240: } elsif ($val eq 'approval') {
2241: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($env{'user.domain'});
2242: if (&Apache::lonnet::put('requestauthorqueue',{ $env{'user.name'}.'_'.$val => $now },
2243: $env{'user.domain'},$domconfiguser) eq 'ok') {
2244: my %userrequest = (
2245: author => {
2246: timestamp => $now,
2247: status => $val,
2248: },
2249: author_status => $val,
2250: );
2251: my $req_notifylist;
2252: if (ref($domconfig{'requestauthor'}) eq 'HASH') {
2253: if (ref($domconfig{'requestauthor'}{'notify'}) eq 'HASH') {
2254: my $req_notifylist = $domconfig{'requestauthor'}{'notify'}{'approval'};
2255: if ($req_notifylist) {
2256: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
2257: $env{'user.domain'});
2258: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
2259: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
2260: &send_selfserve_notification($req_notifylist,
2261: "$fullname ($env{'user.name'}:$env{'user.domain'})",
2262: undef,$domdesc,$now,'authorreq',$sender);
2263: }
2264: }
2265: }
2266: my $userresult =
2267: &Apache::lonnet::put('requestauthor',\%userrequest,$env{'user.domain'},$env{'user.name'});
2268: $output = '<span class="LC_info">'.
1.42 bisitz 2269: &mt('Your request for Authoring Space has been submitted for approval.').
1.31 raeburn 2270: '</span>';
2271: &Apache::lonnet::appenv({'environment.requestauthorqueued' => $val.':'.$now});
2272: } else {
2273: $output = '<span class="LC_info">'.
1.42 bisitz 2274: &mt('An error occurred saving your request for Authoring Space.').
1.31 raeburn 2275: '</span>';
2276: }
2277: }
2278: return $output;
2279: }
2280:
1.1 raeburn 2281: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>