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