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