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