Annotation of loncom/interface/loncoursequeueadmin.pm, revision 1.66
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.66 ! raeburn 4: # $Id: loncoursequeueadmin.pm,v 1.65 2022/12/03 00:34:38 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.57 raeburn 108: args => ["\n$contextdesc\n"],
1.1 raeburn 109: });
110: } elsif ($context eq 'domainmanagers') {
1.12 raeburn 111: $rawsubj = 'Course/Community requests reviewed';
1.1 raeburn 112: push(@rawmsg,{
1.57 raeburn 113: mt => 'Course/Community creation requests in the following domain: [_1] have been reviewed.',
114: args => ["\n$contextdesc\n"],
1.30 raeburn 115: });
116: if (ref($textstr) eq 'ARRAY') {
117: push(@rawmsg,@{$textstr});
118: }
119: } elsif ($context eq 'authormanagers') {
1.42 bisitz 120: $rawsubj = 'Authoring Space requests reviewed';
1.30 raeburn 121: push(@rawmsg,{
1.57 raeburn 122: mt => 'Authoring requests in the following domain: [_1] have been reviewed.',
123: args => ["\n$contextdesc\n"],
1.1 raeburn 124: });
125: if (ref($textstr) eq 'ARRAY') {
126: push(@rawmsg,@{$textstr});
127: }
1.43 raeburn 128: } elsif ($context eq 'usernamemanagers') {
129: $rawsubj = 'LON-CAPA account requests reviewed';
130: push(@rawmsg,{
1.57 raeburn 131: mt => 'Account requests in the following domain: [_1] have been reviewed.',
132: args => ["\n$contextdesc\n"],
1.43 raeburn 133: });
134: if (ref($textstr) eq 'ARRAY') {
135: push(@rawmsg,@{$textstr});
136: }
1.1 raeburn 137: } elsif ($context eq 'enroller') {
138: $rawsubj = 'Enrollment request';
1.12 raeburn 139: if ($crstype eq 'community') {
140: $msgtxt = 'Your request for enrollment in the following community: [_1]requested on [_2]has been reviewed by a Coordinator.'
141: } else {
142: $msgtxt = 'Your request for enrollment in the following course: [_1]requested on [_2]has been reviewed by a Course Coordinator.';
143: }
1.1 raeburn 144: push(@rawmsg,{
1.12 raeburn 145: mt => $msgtxt,
1.2 raeburn 146: args => ["\n ".$contextdesc.",\n",$timestamp.",\n"],
1.1 raeburn 147: });
148: if (ref($textstr) eq 'ARRAY') {
149: push(@rawmsg,@{$textstr});
150: }
151: } elsif ($context eq 'courserequestor') {
1.12 raeburn 152: if ($crstype eq 'Community') {
153: $rawsubj = 'Community request';
154: $msgtxt = 'Your request for creation of the following community: [_1]requested on [_2]has been reviewed by a Domain Coordinator.';
155: } else {
156: $rawsubj = 'Course request';
157: $msgtxt = 'Your request for creation of the following course: [_1]requested on [_2]has been reviewed by a Domain Coordinator.';
158: }
1.1 raeburn 159: push(@rawmsg,{
1.12 raeburn 160: mt => $msgtxt,
1.2 raeburn 161: args => ["\n".$contextdesc.",\n",$timestamp.",\n"],
1.1 raeburn 162:
163: });
164: if (ref($textstr) eq 'ARRAY') {
165: push(@rawmsg,@{$textstr});
166: }
1.26 raeburn 167: } elsif ($context eq 'pendingrequestor') {
168: if ($crstype eq 'Community') {
169: $rawsubj = 'Community request';
170: } else {
171: $rawsubj = 'Processed course request';
172: }
173: if (ref($textstr) eq 'ARRAY') {
174: push(@rawmsg,@{$textstr});
175: }
1.1 raeburn 176: } elsif ($context eq 'coursereq') {
1.12 raeburn 177: if ($crstype eq 'community') {
178: $rawsubj = 'Community request to review';
179: $msgtxt = 'Creation of the following community: [_1]was requested by [_2] on [_3].';
180: } else {
181: $rawsubj = 'Course request to review';
182: $msgtxt = 'Creation of the following course: [_1]was requested by [_2] on [_3].';
183: }
1.1 raeburn 184: push(@rawmsg,{
1.12 raeburn 185: mt => $msgtxt,
1.2 raeburn 186: args => ["\n $contextdesc\n",$textstr,$timestamp],
1.1 raeburn 187: },
188: {
1.12 raeburn 189: 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 190: args => ["\n","\n\n","\n\n"],
1.1 raeburn 191: });
192: } elsif ($context eq 'selfenrollreq') {
193: $rawsubj = 'Self-enrollment request';
1.12 raeburn 194: if ($crstype eq 'community') {
1.31 raeburn 195: $msgtxt = 'Enrollment in the following community: [_1]was requested by [_2] on [_3].'
1.12 raeburn 196: } else {
1.31 raeburn 197: $msgtxt = 'Enrollment in the following course: [_1]was requested by [_2] on [_3].'
1.12 raeburn 198: }
1.1 raeburn 199: push(@rawmsg,{
1.12 raeburn 200: mt => $msgtxt,
1.2 raeburn 201: args => ["\n $contextdesc\n",$textstr,$timestamp."\n"],
202: });
1.12 raeburn 203: my $directions;
204: if ($crstype eq 'community') {
205: $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 206: } else {
1.12 raeburn 207: $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.';
208: }
209: push(@rawmsg,
1.1 raeburn 210: {
1.12 raeburn 211: mt => $directions,
1.2 raeburn 212: args => [" \n\n","\n"],
1.1 raeburn 213: });
1.30 raeburn 214: } elsif ($context eq 'authorreq') {
1.42 bisitz 215: $rawsubj = 'Authoring Space request to review';
1.31 raeburn 216: $msgtxt = 'Assignment of an author role in the [_1] domain[_2]was requested by [_3] on [_4].';
1.30 raeburn 217: push(@rawmsg,{
218: mt => $msgtxt,
219: args => [$contextdesc,"\n",$textstr,$timestamp],
220: },
221: {
1.42 bisitz 222: 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 223: args => ["\n","\n\n ","\n\n"],
224: });
225: } elsif ($context eq 'requestauthor') {
1.42 bisitz 226: $rawsubj = 'Authoring Space request';
227: $msgtxt = 'Your request for an Authoring Space requested on [_1]has been reviewed by a Domain Coordinator.';
1.30 raeburn 228: push(@rawmsg,{
229: mt => $msgtxt,
230: args => [$timestamp."\n"],
231: });
232: if (ref($textstr) eq 'ARRAY') {
233: push(@rawmsg,@{$textstr});
234: }
1.43 raeburn 235: } elsif ($context eq 'usernamereq') {
236: $rawsubj = 'LON-CAPA account request';
237: $msgtxt = 'Creation of a LON-CAPA account in the [_1] domain[_2]was requested by [_3] on [_4].';
238: push(@rawmsg,{
239: mt => $msgtxt,
240: args => [$contextdesc,"\n",$textstr,$timestamp],
241: },
242: {
243: mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Create users or modify the roles and privileges of users
244: -> LON-CAPA account requests[_3]to display a list of pending requests, which you can either approve or reject.',
245: args => ["\n","\n\n ","\n\n"],
246: });
247: } elsif ($context eq 'requestusername') {
248: $rawsubj = 'LON-CAPA account request';
249: $msgtxt = 'Your request for a LON-CAPA account requested on [_1]has been reviewed by a Domain Coordinator.';
250: push(@rawmsg,{
251: mt => $msgtxt,
252: args => [$timestamp."\n"],
253: });
254: if (ref($textstr) eq 'ARRAY') {
255: push(@rawmsg,@{$textstr});
256: }
1.39 raeburn 257: } elsif ($context eq 'uniquecode') {
258: $rawsubj = 'Course Identifier';
259: if (ref($textstr) eq 'ARRAY') {
260: push(@rawmsg,@{$textstr});
261: }
1.41 raeburn 262: } elsif ($context eq 'queuedcrsreq') {
263: $rawsubj = 'Course Request Queued';
264: if (ref($textstr) eq 'ARRAY') {
265: push(@rawmsg,@{$textstr});
266: }
267: } elsif ($context eq 'createdcrsreq') {
268: $rawsubj = 'Course Creation Information';
269: if (ref($textstr) eq 'ARRAY') {
270: push(@rawmsg,@{$textstr});
271: }
1.63 raeburn 272: } elsif ($context eq 'othdomroleuser') {
273: my $linktext = 'Roles';
274: if (&Apache::loncommon::show_course()) {
275: $linktext = 'Courses';
276: }
277: $rawsubj = 'Role Assignment Approval';
278: push(@rawmsg,{
279: mt => 'A domain different to your own LON-CAPA domain ([_1]) wants to assign you a role in their domain.',
280: args => ["\n$contextdesc\n"],
281: },
282: {
283: mt =>"[_1]Click $linktext at top right, then click 'Manage Role Requests' in the gray Functions bar ".
284: "to display a list of pending role assignments in other domain(s), which you can either accept or reject.",
285: args => ["\n\n"],
286: });
287: } elsif ($context eq 'othdomroledc') {
288: $rawsubj = 'Role Assignment Authorization';
289: push(@rawmsg,{
290: mt => 'Another LON-CAPA domain wants to assign a role in their domain to a user from your domain.',
291: args => [],
292: },
293: {
294: mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Create users or modify the roles and privileges of users
295: -> Queued Role Assignments (this domain) [_3]to display a list of pending requests, which you can either approve or reject.',
296: args => ["\n","\n\n ","\n\n"],
297: });
1.64 raeburn 298: } elsif ($context eq 'othdombydc') {
299: $rawsubj = 'Status of Role Assignment Requests';
300: push(@rawmsg,{
301: mt =>'A Domain Coordinator in a domain different to your own LON-CAPA domain '.
302: 'has taken action on queued role assignment(s) in this domain for user(s) from that other domain ([_1])',
303: args => ["\n$contextdesc\n"],
304: });
1.1 raeburn 305: }
306: my @to_notify = split(/,/,$notifylist);
307: my $numsent = 0;
308: my @recusers;
309: my @recudoms;
310: foreach my $cc (@to_notify) {
311: my ($ccname,$ccdom) = split(/:/,$cc);
312: if (!exists($msgcc->{$ccname.':'.$ccdom})) {
313: push(@recusers,$ccname);
314: push(@recudoms,$ccdom);
315: $msgcc->{$ccname.':'.$ccdom}='';
316: $numsent ++;
317: }
318: }
319: my %reciphash = (
320: cc => $msgcc,
321: );
1.43 raeburn 322: my ($uname,$udom,$need_temp_env);
1.1 raeburn 323: if ($sender =~ /:/) {
324: ($uname,$udom) = split(/:/,$sender);
1.43 raeburn 325: if ($context eq 'usernamereq') {
326: unless ($env{'user.name'} && $env{'user.domain'}) {
327: $need_temp_env = 1;
328: }
329: }
1.2 raeburn 330: } elsif ($context eq 'course') {
1.1 raeburn 331: $uname = $sender;
332: my %courseinfo = &Apache::lonnet::coursedescription($cid);
333: $udom = $courseinfo{'num'};
334: }
335: my %sentmessage;
336: my $stamp = time;
337: my $msgcount = &Apache::lonmsg::get_uniq();
338: my $sender_lh = &Apache::loncommon::user_lang($uname,$udom,$cid);
1.59 raeburn 339: $subject = &mt_user($sender_lh,$rawsubj);
1.1 raeburn 340: $message = '';
341: foreach my $item (@rawmsg) {
342: if (ref($item) eq 'HASH') {
1.59 raeburn 343: $message .= &mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
1.1 raeburn 344: }
345: }
1.43 raeburn 346: &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,
347: \@recusers,\@recudoms,undef,undef,undef,undef,$senderuname,$senderudom);
1.1 raeburn 348: my ($recipid,$recipstatus) = &Apache::lonmsg::store_recipients($subject,$uname,$udom,\%reciphash);
349: my $status;
1.43 raeburn 350: if ($need_temp_env) {
351: $env{'user.name'} = $uname;
352: $env{'user.domain'} = $udom;
353: }
1.1 raeburn 354: foreach my $recip (sort(keys(%{$msgcc}))) {
355: my ($ccname,$ccdom) = split(/:/,$recip);
356: my $recip_lh = &Apache::loncommon::user_lang($ccname,$ccdom,$cid);
1.59 raeburn 357: my $subject = &mt_user($sender_lh,$rawsubj);
1.1 raeburn 358: my $message = '';
359: foreach my $item (@rawmsg) {
360: if (ref($item) eq 'HASH') {
1.59 raeburn 361: $message .= &mt_user($sender_lh,$item->{mt},
362: @{$item->{args}})."\n";
1.1 raeburn 363: }
364: }
1.10 raeburn 365: if ($context eq 'coursemanagers') {
1.1 raeburn 366: if ($approvedlist) {
1.59 raeburn 367: $message .= "\n\n".&mt_user($sender_lh,'Approved enrollments:')."\n".$approvedlist;
1.1 raeburn 368: }
369: if ($rejectedlist) {
1.59 raeburn 370: $message .= "\n\n".&mt_user($sender_lh,'Rejected enrollments:')."\n".$rejectedlist;
1.1 raeburn 371: }
372: } elsif ($context eq 'domainmanagers') {
373: if ($approvedlist) {
1.59 raeburn 374: $message .= "\n\n".&mt_user($sender_lh,'Approved course requests:')."\n".$approvedlist;
1.1 raeburn 375: }
376: if ($rejectedlist) {
1.59 raeburn 377: $message .= "\n\n".&mt_user($sender_lh,'Rejected course requests:')."\n".$rejectedlist;
1.1 raeburn 378: }
1.30 raeburn 379: } elsif ($context eq 'authormanagers') {
380: if ($approvedlist) {
1.59 raeburn 381: $message .= "\n\n".&mt_user($sender_lh,'Approved author role requests:')."\n".$approvedlist;
1.30 raeburn 382: }
383: if ($rejectedlist) {
1.59 raeburn 384: $message .= "\n\n".&mt_user($sender_lh,'Rejected author role requests:')."\n".$rejectedlist;
1.30 raeburn 385: }
1.43 raeburn 386: } elsif ($context eq 'usernamemanagers') {
387: if ($approvedlist) {
1.59 raeburn 388: $message .= "\n\n".&mt_user($sender_lh,'Approved LON-CAPA account requests:')."\n".$approvedlist;
1.43 raeburn 389: }
390: if ($rejectedlist) {
1.59 raeburn 391: $message .= "\n\n".&mt_user($sender_lh,'Rejected LON-CAPA account requests:')."\n".$rejectedlist;
1.43 raeburn 392: }
1.64 raeburn 393: } elsif ($context eq 'othdombydc') {
394: if ($approvedlist) {
395: $message .= "\n\n".&mt_user($sender_lh,'Approved LON-CAPA role assignments:')."\n".$approvedlist;
396: }
397: if ($rejectedlist) {
398: $message .= "\n\n".&mt_user($sender_lh,'Rejected LON-CAPA role assignments:')."\n".$rejectedlist;
399: }
1.1 raeburn 400: }
1.43 raeburn 401: $status .= &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,1,
402: \%sentmessage,undef,undef,undef,1,$recipid).',';
1.1 raeburn 403: }
404: $status =~ s/,$//;
1.43 raeburn 405: if ($need_temp_env) {
406: undef($env{'user.name'});
407: undef($env{'user.domain'});
408: }
1.1 raeburn 409: return ($recipstatus,$status);
410: }
411:
412: sub display_queued_requests {
1.63 raeburn 413: my ($context,$dom,$cnum,$secondary) = @_;
1.65 raeburn 414: my ($namespace,$formaction,$nextelement,%requesthash,%reqstatus);
1.1 raeburn 415: if ($context eq 'course') {
416: $formaction = '/adm/createuser';
417: $namespace = 'selfenrollrequests';
418: %requesthash = &Apache::lonnet::dump($namespace,$dom,$cnum);
1.2 raeburn 419: $nextelement = '<input type="hidden" name="state" value="done" />';
1.30 raeburn 420: } elsif ($context eq 'requestauthor') {
421: $formaction = '/adm/createuser';
422: $namespace = 'requestauthorqueue';
423: %requesthash = &Apache::lonnet::dump_dom($namespace,$dom);
424: $nextelement = '<input type="hidden" name="state" value="done" />';
1.43 raeburn 425: } elsif ($context eq 'requestusername') {
426: $formaction = '/adm/createuser';
427: $namespace = 'usernamequeue';
428: %requesthash = &Apache::lonnet::dump_dom($namespace,$dom);
429: $nextelement = '<input type="hidden" name="state" value="done" />';
1.63 raeburn 430: } elsif ($context eq 'othdomqueue') {
431: $formaction = '/adm/createuser';
1.64 raeburn 432: $namespace = 'nohist_othdomqueued';
1.63 raeburn 433: if ($secondary eq 'domain') {
434: %requesthash = &Apache::lonnet::dump_dom($namespace,$dom);
435: foreach my $key (keys(%requesthash)) {
436: delete($requesthash{$key}) if ($key =~ /:(ca|aa)$/);
437: }
438: } elsif ($secondary eq 'author') {
439: %requesthash = &Apache::lonnet::dump($namespace,$dom,$cnum);
440: if ($cnum eq &Apache::lonnet::get_domainconfiguser($dom)) {
441: foreach my $key (keys(%requesthash)) {
442: delete($requesthash{$key}) if ($key !~ /:(ca|aa)$/);
443: }
444: }
445: } else {
446: %requesthash = &Apache::lonnet::dump($namespace,$dom,$cnum);
447: }
448: } elsif ($context eq 'othdomaction') {
449: $formaction = '/adm/createuser';
1.64 raeburn 450: $namespace = 'nohist_queuedrolereqs';
1.63 raeburn 451: if ($secondary eq 'domain') {
452: my $confname = &Apache::lonnet::get_domainconfiguser($dom);
453: %requesthash = &Apache::lonnet::dump($namespace,$dom,$confname);
454: } else {
455: %requesthash = &Apache::lonnet::dump($namespace,$dom,$cnum);
456: }
457: $nextelement = '<input type="hidden" name="state" value="done" />';
1.1 raeburn 458: } else {
459: $formaction = '/adm/createcourse';
460: $namespace = 'courserequestqueue';
1.23 raeburn 461: my $disposition = 'approval';
1.24 raeburn 462: my $nextphase = 'requestchange';
1.23 raeburn 463: if ($context eq 'pending') {
464: $disposition = 'pending';
1.24 raeburn 465: $nextphase = 'requestvalidation';
1.56 raeburn 466: } elsif ($context eq 'displaypending') {
467: $disposition = 'pending';
1.23 raeburn 468: }
469: %requesthash = &Apache::lonnet::dump_dom($namespace,$dom,'_'.$disposition);
1.24 raeburn 470: $nextelement = '<input type="hidden" name="phase" value="'.$nextphase.'" />';
1.1 raeburn 471: }
1.23 raeburn 472: my ($output,%queue_by_date);
1.1 raeburn 473: if (keys(%requesthash) > 0) {
474: foreach my $item (keys(%requesthash)) {
1.23 raeburn 475: my ($timestamp,$entry,$pending);
1.1 raeburn 476: if ($context eq 'course') {
477: ($timestamp, my $usec) = split(/:/,$requesthash{$item});
478: $entry = $item.':'.$usec;
1.30 raeburn 479: } elsif ($context eq 'requestauthor') {
480: $timestamp = $requesthash{$item};
481: ($entry) = ($item =~ /^($match_username)_approval$/);
1.43 raeburn 482: } elsif ($context eq 'requestusername') {
483: $timestamp = $requesthash{$item};
484: ($entry) = (&unescape($item) =~ /^($match_username)_approval$/);
1.63 raeburn 485: } elsif ($context eq 'othdomqueue') {
486: if (ref($requesthash{$item}) eq 'HASH') {
487: my ($puname,$pudom,$prole,$psec) = split(/:/,$item);
488: $timestamp = $requesthash{$item}{'timestamp'};
489: my $adj = $requesthash{$item}{'adj'};
490: $entry = join(':',$puname,$pudom,$prole,$adj,
491: &escape($requesthash{$item}{'requester'}),
492: $psec);
1.65 raeburn 493: } elsif ($item =~ /^status&/) {
494: my ($dummy,$key) = split(/&/,$item,2);
495: $reqstatus{$key} = $requesthash{$item};
1.63 raeburn 496: }
497: } elsif ($context eq 'othdomaction') {
1.64 raeburn 498: next unless ($item =~ /^pending:/);
1.63 raeburn 499: if (ref($requesthash{$item}) eq 'HASH') {
500: $timestamp = $requesthash{$item}{'timestamp'};
501: $entry = &escape($item).':'.&escape($requesthash{$item}{'requester'});
502: }
1.1 raeburn 503: } else {
504: if (ref($requesthash{$item}) eq 'HASH') {
1.63 raeburn 505: $timestamp = $requesthash{$item}{'timestamp'};
1.2 raeburn 506: my ($cnum,$disposition) = split('_',$item);
507: $entry = $cnum.':'.$requesthash{$item}{'ownername'}.':'.
1.23 raeburn 508: $requesthash{$item}{'ownerdom'}.':';
1.56 raeburn 509: if (($context eq 'pending') || ($context eq 'displaypending')) {
1.23 raeburn 510: $entry .= $requesthash{$item}{'instcode'};
511: } else {
512: $entry .= $requesthash{$item}{'crstype'};
513: }
514: $entry .= ':'.$requesthash{$item}{'description'};
1.1 raeburn 515: }
516: }
517: if ($entry ne '') {
1.23 raeburn 518: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
519: push(@{$queue_by_date{$timestamp}},$entry);
1.1 raeburn 520: } else {
1.23 raeburn 521: $queue_by_date{$timestamp} = [$entry];
1.1 raeburn 522: }
523: }
524: }
1.64 raeburn 525: }
526: if (keys(%queue_by_date) > 0) {
527: $output = '<form method="post" name="changequeue" action="'.$formaction.'" />'."\n".
528: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
529: $nextelement."\n";
530: if ($context eq 'course') {
531: $output .= '<h3>'.&mt('Self-enrollment requests queued pending approval by a Coordinator').'</h3>';
532: } elsif (($context eq 'pending') || ($context eq 'displaypending')) {
533: $output .= '<h3>'.&mt('Requests for official courses queued pending validation').'</h3>'.
534: '<p>'.&mt('Requests are validated against institutional data to confirm that the requestor is an instructor of record.').'<br />'.
535: &mt('Validation is attempted when the request is submitted.').' '.
536: &mt('If unvalidated, the request will be held in a queue.').' '.
537: &mt('Validation of pending requests is automatically repeated daily.').'</p>';
538: } elsif ($context eq 'requestauthor') {
539: $output .= '<h3>'.&mt('Requests for Authoring Space queued pending approval by a Domain Coordinator').'</h3>';
540: } elsif ($context eq 'requestusername') {
541: $output .= '<h3>'.&mt('Requests for LON-CAPA accounts queued pending approval by a Domain Coordinator').'</h3>';
542: } elsif ($context eq 'othdomqueue') {
543: if ($secondary eq 'domain') {
1.65 raeburn 544: $output .= '<h3>'.&mt('Domain role assignments for users from another domain which were/are queued for approval').'</h3>';
1.64 raeburn 545: } elsif ($secondary eq 'author') {
1.65 raeburn 546: $output .= '<h3>'.&mt('Co-author role assignments for users from another domain which were/are queued for approval').'</h3>';
1.64 raeburn 547: } elsif ($secondary eq 'course') {
1.65 raeburn 548: $output .= '<h3>'.&mt('Course role assignments for users from another domain which were/are queued for approval').'</h3>';
1.64 raeburn 549: } elsif ($secondary eq 'community') {
1.65 raeburn 550: $output .= '<h3>'.&mt('Community role assignments for users from another domain which were/are queued for approval').'</h3>';
1.64 raeburn 551: }
552: } elsif ($context eq 'othdomaction') {
553: if ($secondary eq 'user') {
554: $output .= '<h3>'.&mt('Role assignments for you in other domains, queued pending your acceptance of the role.').'</h3>';
555: } elsif ($secondary eq 'domain') {
556: $output .= '<h3>'.&mt('Role assignments in other domains, queued pending domain coordinator approval in this domain.').'</h3>';
557: }
1.23 raeburn 558: } else {
1.64 raeburn 559: $output .= '<h3>'.&mt('Course/Community requests queued pending approval by a Domain Coordinator').'</h3>';
1.65 raeburn 560: }
561: if ($context eq 'othdomqueue') {
562: $output .= &queued_role_display($secondary,\%queue_by_date,\%reqstatus);
563: } else {
564: $output .= &build_queue_display($dom,$context,\%queue_by_date,$secondary).
565: '<input type="hidden" name="queue" value="approval" />';
566: }
1.23 raeburn 567: if ($context eq 'pending') {
1.24 raeburn 568: $output .= '<br /><input type="submit" name="validationcheck" value="'.
569: &mt('Validate').'" /><br />'."\n".
1.56 raeburn 570: '<p>'.&mt('Any course/community requests which are successfully validated will be created immediately.').' '.
571: &mt('Unvalidated requests will be listed for manual approval/rejection.').'</p>';
1.63 raeburn 572: } elsif (($context ne 'helpdesk') && ($context ne 'displaypending') && ($context ne 'othdomqueue')) {
1.23 raeburn 573: $output .= '<br /><input type="submit" name="processqueue" value="'.&mt('Save').'" />';
574: }
575: $output .= '</form>';
576: } else {
577: $output .= '<div class="LC_info">';
578: if ($context eq 'course') {
579: $output .= &mt('There are currently no enrollment requests awaiting approval.');
1.56 raeburn 580: } elsif (($context eq 'pending') || ($context eq 'displaypending')) {
1.23 raeburn 581: $output .= &mt('There are currently no requests for official courses awaiting validation.');
1.43 raeburn 582: } elsif ($context eq 'requestauthor') {
583: $output .= &mt('There are currently no requests for Authoring Space awaiting approval.');
584: } elsif ($context eq 'requestusername') {
585: $output .= &mt('There are currently no requests for LON-CAPA accounts awaiting approval.');
1.63 raeburn 586: } elsif ($context eq 'othdomqueue') {
587: if ($secondary eq 'domain') {
1.65 raeburn 588: $output .= &mt('There are currently no domain role assignment(s) for user(s) from another domain which were/are queued for approval');
1.63 raeburn 589: } elsif ($secondary eq 'author') {
1.65 raeburn 590: $output .= &mt('There are currently no co-author role assignment(s) for user(s) from another domain which were/are queued for approval');
1.63 raeburn 591: } elsif ($secondary eq 'course') {
1.65 raeburn 592: $output .= &mt('There are currently no course role assignment(s) for user(s) from another domain which were/are queued for approval');
1.63 raeburn 593: } elsif ($secondary eq 'community') {
1.65 raeburn 594: $output .= &mt('There are currently no community role assignment(s) for user(s) from another domain which were/are queued for approval');
1.63 raeburn 595: }
596: } elsif ($context eq 'othdomaction') {
597: if ($secondary eq 'user') {
598: $output .= &mt('There are currently no pending role assignments for you in other domains, queued pending your acceptance of the role.');
599: } elsif ($secondary eq 'domain') {
600: $output .= &mt('There are currently no pending role assignments in other domains, queued pending domain coordinator approval in this domain.');
601: }
1.23 raeburn 602: } else {
603: $output .= &mt('There are currently no course or community requests awaiting approval.');
604: }
605: $output .= '</div>';
606: }
607: return $output;
608: }
1.1 raeburn 609:
1.23 raeburn 610: sub build_queue_display {
1.63 raeburn 611: my ($dom,$context,$queue,$secondary) = @_;
1.23 raeburn 612: return unless (ref($queue) eq 'HASH');
1.64 raeburn 613: my (%crstypes,%roles_by_context,$output);
614: $output .= &Apache::loncommon::start_data_table().
615: &Apache::loncommon::start_data_table_header_row();
1.63 raeburn 616: unless (($context eq 'pending') || ($context eq 'displaypending') ||
1.65 raeburn 617: ($context eq 'helpdesk')) {
1.23 raeburn 618: $output .= '<th>'.&mt('Action').'</th>';
619: }
1.65 raeburn 620: unless (($context eq 'othdomaction') && ($secondary eq 'user')) {
1.63 raeburn 621: $output .= '<th>'.&mt('Requestor').'</th>';
622: }
1.23 raeburn 623: if ($context eq 'course') {
624: $output .= '<th>'.&mt('Section').'</th>'.
625: '<th>'.&mt('Date requested').'</th>';
1.30 raeburn 626: } elsif ($context eq 'requestauthor') {
627: $output .= '<th>'.&mt('Date requested').'</th>';
1.43 raeburn 628: } elsif ($context eq 'requestusername') {
629: $output .= '<th>'.&mt('Date requested').'</th>'.
630: '<th>'.&mt('Details').'</th>';
1.63 raeburn 631: } elsif ($context eq 'othdomaction') {
632: $output .= '<th>'.&mt('Date requested').'</th>'.
633: '<th>'.&mt('Role type').'</th>'.
634: '<th>'.&mt('Location').'</th>';
635: if ($secondary eq 'domain') {
636: $output .= '<th>'.&mt('Affected User').'</th>';
637: }
638: foreach my $type ('domain','course') {
639: my @possroles = &Apache::lonuserutils::roles_by_context($type);
640: $roles_by_context{$type} = \@possroles;
641: }
1.56 raeburn 642: } elsif ($context eq 'pending' || $context eq 'displaypending' || $context eq 'stillpending') {
1.23 raeburn 643: $output .= '<th>'.&mt('Institutional code').'</th>'.
644: '<th>'.&mt('Date requested').'</th>'.
645: '<th>'.&mt('Details').'</th>';
646: } else {
647: %crstypes = &Apache::lonlocal::texthash (
648: official => 'Official course',
649: unofficial => 'Unofficial course',
650: community => 'Community',
1.38 raeburn 651: textbook => 'Textbook course',
1.53 raeburn 652: placement => 'Placement test',
1.23 raeburn 653: );
654: $output .= '<th>'.&mt('Type').'</th>'.
655: '<th>'.&mt('Date requested').'</th>'.
656: '<th>'.&mt('Details').'</th>';
657: }
658: $output .= &Apache::loncommon::end_data_table_header_row();
659: my @sortedtimes = sort {$a <=> $b} (keys(%{$queue}));
660: my $count = 0;
661: foreach my $item (@sortedtimes) {
662: if (ref($queue->{$item}) eq 'ARRAY') {
663: foreach my $request (sort(@{$queue->{$item}})) {
664: my ($row,$approve,$reject,$showtime,$showsec,$namelink,
1.63 raeburn 665: $detailslink,$crstype,$instcode,$showrole,$adjudicator,
666: $location,$showrequester);
1.23 raeburn 667: $showtime = &Apache::lonlocal::locallocaltime($item);
668: if ($context eq 'course') {
669: my ($puname,$pudom,$pusec) = split(/:/,$request);
670: $approve = $count.':'.$puname.':'.$pudom.':'.$pusec;
671: $reject = $puname.':'.$pudom;
672: $showsec = $pusec;
673: if ($showsec eq '') {
674: $showsec = &mt('none');
675: }
676: $namelink = &Apache::loncommon::aboutmewrapper(
677: &Apache::loncommon::plainname($puname,$pudom),
678: $puname,$pudom);
1.30 raeburn 679: } elsif ($context eq 'requestauthor') {
680: if (&Apache::lonnet::homeserver($request,$dom) ne 'no_host') {
681: $approve = $count.':'.$request;
1.63 raeburn 682: $reject = $request;
1.30 raeburn 683: $namelink = &Apache::loncommon::aboutmewrapper(
684: &Apache::loncommon::plainname($request,$dom),
685: $request,$dom);
686: }
1.43 raeburn 687: } elsif ($context eq 'requestusername') {
688: if (&Apache::lonnet::homeserver($request,$dom) eq 'no_host') {
689: my $queued = 'approval';
690: $approve = $count.':'.$request;
691: $reject = $request;
692: $detailslink='<a href="javascript:openusernamereqdisplay('.
693: "'$dom','$request','$queued'".');">'.$request.'</a>';
694: $namelink = $request;
695: }
1.63 raeburn 696: } elsif ($context eq 'othdomaction') {
1.64 raeburn 697: my ($status,$extent,$role,$crstype);
1.63 raeburn 698: my ($info,$requester) = map { &unescape($_); } split(/:/,$request);
699: if ($secondary eq 'user') {
1.64 raeburn 700: ($status,$extent,$role) = split(/:/,$info);
1.63 raeburn 701: $approve = $count.':'.$extent.':'.$role;
702: $reject = $extent.':'.$role;
703: } elsif ($secondary eq 'domain') {
1.64 raeburn 704: ($status,my $uname,$extent,$role) = split(/:/,$info);
1.63 raeburn 705: $approve = $count.':'.$extent.':'.$role.':'.$uname.':'.$dom;
706: $reject = $extent.':'.$role.':'.$uname.':'.$dom;
707: unless (&Apache::lonnet::homeserver($uname,$dom) eq 'no_host') {
708: $namelink = &Apache::loncommon::plainname($uname,$dom);
709: unless ($namelink eq $uname.':'.$dom) {
710: $namelink .= ' ('.$uname.':'.$dom.')';
711: }
712: }
713: }
714: if (($role eq 'ca') || ($role eq 'aa')) {
715: my ($audom,$auname) = ($extent =~ m{^/($match_domain)/($match_username)$});
716: $location = &mt('Author').': '.&Apache::loncommon::plainname($auname,$audom);
717: } elsif ($role eq 'co') {
718: my ($cdom,$cnum) = ($extent =~ m{^/($match_domain)/($match_courseid)});
719: if (&Apache::lonnet::is_course($cdom,$cnum)) {
720: my %info = &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
721: $crstype = $info{'type'};
722: $location = &mt('Community').': '.$info{'description'};
723: $showrole = &Apache::lonnet::plaintext($role,'Community');
724: }
725: } elsif ($role =~ m{^cr/}) {
726: $showrole = &Apache::lonnet::plaintext($role,$crstype);
727: my ($cdom,$cnum,$csec) = ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$});
728: if (&Apache::lonnet::is_course($cdom,$cnum)) {
729: my %info = &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
730: $crstype = $info{'type'};
731: $location = &mt($crstype).': '.$info{'description'};
732: if ($csec ne '') {
1.64 raeburn 733: $location .= '<br />'.&mt('Section').': '.$csec;
1.63 raeburn 734: }
735: }
736: } else {
737: foreach my $type ('course','domain') {
738: if (grep(/^\Q$role\E$/,@{$roles_by_context{$type}})) {
739: if ($type eq 'course') {
740: my ($cdom,$cnum,$csec) = ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$});
741: if (&Apache::lonnet::is_course($cdom,$cnum)) {
742: my %info = &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
743: $crstype = $info{'type'};
744: $location = &mt($crstype).': '.$info{'description'};
745: if ($csec ne '') {
1.64 raeburn 746: $location .= '<br />'.&mt('Section').': '.$csec;
1.63 raeburn 747: }
748: }
749: } else {
750: my ($domain) = ($extent =~ m{^/($match_domain)/});
751: $location = &mt('Domain').': '.&Apache::lonnet::domain($domain,'description');
752: }
753: last;
754: }
755: }
756: }
757: if ($role =~ m{^cr/($match_domain)/($match_username)/(\w+)$}) {
758: my ($crudom,$cruname,$rolename) = ($1,$2,$3);
759: my $creator = &Apache::loncommon::plainname($cruname,$crudom);
760: unless ($creator eq $cruname.':'.$crudom) {
761: $creator .= ' ('.$cruname.':'.$crudom.')';
762: }
763: $showrole = &mt('Custom role').': '.$rolename.'<br />'.
764: &mt('Created by').' '.$creator;
765: } else {
766: $showrole = &Apache::lonnet::plaintext($role,$crstype);
767: }
768: my ($requname,$requdom) = split(/:/,$requester);
769: $showrequester = &Apache::loncommon::plainname($requname,$requdom);
770: unless ($showrequester eq $requname.':'.$requdom) {
771: $showrequester .= ' ('.$requname.':'.$requdom.')';
772: }
1.23 raeburn 773: } else {
774: my ($cnum,$ownername,$ownerdom,$type,$cdesc);
1.43 raeburn 775: my $queued = 'approval';
1.56 raeburn 776: if ($context eq 'pending' || $context eq 'displaypending' || $context eq 'stillpending') {
1.23 raeburn 777: ($cnum,$ownername,$ownerdom,$instcode,$cdesc)=split(/:/,$request,5);
1.43 raeburn 778: $queued = 'pending';
1.1 raeburn 779: } else {
1.23 raeburn 780: ($cnum,$ownername,$ownerdom,$type,$cdesc)=split(/:/,$request,5);
1.1 raeburn 781: $crstype = $type;
782: if (defined($crstypes{$type})) {
783: $crstype = $crstypes{$type};
784: }
785: }
1.23 raeburn 786: $detailslink='<a href="javascript:opencoursereqdisplay('.
1.43 raeburn 787: "'$dom','$cnum','$queued'".');">'.$cdesc.'</a>';
1.23 raeburn 788: $approve = $count.':'.$cnum;
789: $reject = $cnum;
790: $namelink = &Apache::loncommon::aboutmewrapper(
791: &Apache::loncommon::plainname($ownername,$ownerdom),
792: $ownername,$ownerdom);
793: }
1.63 raeburn 794: unless (($context eq 'pending') || ($context eq 'displaypending') ||
1.65 raeburn 795: ($context eq 'helpdesk')) {
1.1 raeburn 796: $row = '<td><span class="LC_nobreak"><label>'.
1.30 raeburn 797: '<input type="radio" value="'.$approve.'" name="'.$count.'radioreq" />'.&mt('Approve').'</label>'.
798: '<label>'.(' 'x2).
799: '<input type="radio" value="'.$reject.'" name="'.$count.'radioreq" />'.&mt('Reject').'</label>'.
800: '<label>'.(' 'x2).
1.29 golterma 801: '<input type="radio" value="'."later:".$reject.'" name="'.$count.'radioreq" checked />'.&mt('Decide Later').
802: '</label></span><br /></td>';
1.1 raeburn 803: }
1.65 raeburn 804: unless ($context eq 'othdomaction') {
1.63 raeburn 805: $row .= '<td>'.$namelink.'</td>'."\n";
806: }
1.23 raeburn 807: if ($context eq 'course') {
808: $row .= '<td>'.$showsec.'</td>'."\n".
809: '<td>'.$showtime.'</td>'."\n";
1.30 raeburn 810: } elsif ($context eq 'requestauthor') {
811: $row .= '<td>'.$showtime.'</td>'."\n";
1.43 raeburn 812: } elsif ($context eq 'requestusername') {
813: $row .= '<td>'.$showtime.'</td>'."\n".
814: '<td>'.$detailslink.'</td>'."\n";
1.63 raeburn 815: } elsif ($context eq 'othdomaction') {
816: if ($secondary eq 'domain') {
817: $row .= '<td>'.$showrequester.'</td>'."\n";
818: }
819: $row .= '<td>'.$showtime.'</td>'."\n".
820: '<td>'.$showrole.'</td>'."\n".
821: '<td>'.$location.'</td>'."\n";
822: if ($secondary eq 'domain') {
823: $row .= '<td>'.$namelink.'</td>'."\n";
824: }
825: } else {
1.56 raeburn 826: if ($context eq 'pending' || $context eq 'displaypending' || $context eq 'stillpending') {
1.23 raeburn 827: $row .= '<td>'.$instcode.'</td>'."\n";
828: } else {
829: $row .= '<td>'.$crstype.'</td>'."\n";
830: }
831: $row .= '<td>'.$showtime.'</td>'."\n".
832: '<td>'.$detailslink.'</td>'."\n";
833: }
834: $output .= &Apache::loncommon::start_data_table_row()."\n".
835: $row.
836: &Apache::loncommon::end_data_table_row()."\n";
837: $count ++;
1.1 raeburn 838: }
839: }
840: }
1.23 raeburn 841: $output .= &Apache::loncommon::end_data_table();
1.1 raeburn 842: return $output;
843: }
844:
1.65 raeburn 845: sub queued_role_display {
846: my ($context,$queue,$status) = @_;
847: return unless ((ref($queue) eq 'HASH') && (ref($status) eq 'HASH'));
848: my (%curr,$minshown,$maxshown,$more_records,$crstype,$viewablesec,$output);
849: my $formname = 'changequeue';
850: if ($context eq 'course') {
851: $crstype = &Apache::loncommon::course_type();
852: my ($permission,$allowed) =
853: &Apache::lonuserutils::get_permission($context,$crstype);
854: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
855: my %saveable_parameters = ('show' => 'scalar',);
856: &Apache::loncommon::store_course_settings('roles_req',
857: \%saveable_parameters);
858: &Apache::loncommon::restore_course_settings('roles_req',
859: \%saveable_parameters);
860: }
861:
862: # Create navigation javascript
863: my $jsnav = &queued_log_js($formname);
864:
865: $output = (<<ENDSCRIPT);
866: <script type="text/javascript">
867: // <![CDATA[
868: $jsnav
869: // ]]>
870: </script>
871: ENDSCRIPT
872:
873: my $now = time();
874: my $defstart = $now - (7*24*3600); #7 days ago
875: my %defaults = (
876: page => '1',
877: show => '10',
878: role => 'any',
879: chgstatus => 'any',
880: chgadj => 'any',
881: rolereq_start_date => $defstart,
882: rolereq_end_date => $now,
883: );
884: $more_records = 0;
885: my %lt = &othdomrole_contexts();
886:
887: foreach my $item ('show','page','role','chgstatus','chgadj') {
888: $curr{$item} = $env{'form.'.$item};
889: }
890: ($curr{'rolereq_start_date'},$curr{'rolereq_end_date'}) =
891: &Apache::lonuserutils::get_dates_from_form('rolereq_start_date','rolereq_end_date');
892: foreach my $key (keys(%defaults)) {
893: if ($curr{$key} eq '') {
894: $curr{$key} = $defaults{$key};
895: }
896: }
897: $minshown = 1;
898: my $count = 0;
899: if ($curr{'show'} =~ /\D/) {
900: $curr{'page'} = 1;
901: } else {
902: $maxshown = $curr{'page'} * $curr{'show'};
903: if ($curr{'page'} > 1) {
904: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
905: }
906: }
907: $output .= &print_filter_menu($context,'changequeue',\%curr,$crstype);
908:
909: my $showntableheader = 0;
910:
911: # Table Header
912: my $tableheader =
913: &Apache::loncommon::start_data_table().
914: &Apache::loncommon::start_data_table_header_row().
915: '<th>'.&mt('Date requested').'</th>'.
916: '<th>'.&mt('Role').'</th>';
917: if ($context eq 'course') {
918: $tableheader .= '<th>'.&mt('Section').'</th>';
919: }
920: $tableheader .= '<th>'.&mt('Requested for').'</th>'.
921: '<th>'.&mt('Request status').'</th>'.
922: '<th>'.&mt('Adjudicator').'</th>'.
923: &Apache::loncommon::end_data_table_header_row();
924:
925: my @sortedtimes = sort {$a <=> $b} (keys(%{$queue}));
926: my $count = 0;
927: foreach my $item (@sortedtimes) {
928: next if (($item < $curr{'rolereq_start_date'}) ||
929: ($item > $curr{'rolereq_end_date'}));
930: if (ref($queue->{$item}) eq 'ARRAY') {
931: foreach my $request (sort(@{$queue->{$item}})) {
932: if ($curr{'show'} !~ /\D/) {
933: if ($count >= $curr{'page'} * $curr{'show'}) {
934: $more_records = 1;
935: last;
936: }
937: }
938: my ($showtime,$showsec,$namelink,$showrole,$showadj,
939: $showstatus,$id);
940: $showtime = &Apache::lonlocal::locallocaltime($item);
941: my ($uname,$udom,$role,$adj,$requester,$sec) = split(/:/,$request);
942: $id = join(':',($uname,$udom,$role));
943: if ($context eq 'course') {
944: $id .= ':'.$sec;
945: }
946: if ($curr{'role'} ne 'any') {
947: if ($curr{'role'} eq 'cr') {
948: next unless ($role =~ m{^cr/});
949: } else {
950: next unless ($role eq $curr{'role'});
951: }
952: }
953: if ($curr{'chgstatus'} ne 'any') {
954: next if ($status->{$id} ne $curr{'chgstatus'});
955: }
956: if ($curr{'chgadj'} ne 'any') {
957: next if ($adj ne $curr{'chgadj'});
958: }
959: if (($context eq 'course') && ($viewablesec ne '')) {
960: next if ($sec ne $viewablesec);
961: }
962: $count ++;
963: next if ($count < $minshown);
964: unless ($showntableheader) {
965: $output .= $tableheader;
966: $showntableheader = 1;
967: }
968: $showrole = &Apache::lonnet::plaintext($role,$crstype);
969: $showstatus = $lt{$status->{$id}};
970: $showadj = $lt{$adj};
971: unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
972: $namelink = &Apache::loncommon::plainname($uname,$udom)." ($uname:$udom)";
973: }
974: if ($context eq 'course') {
975: $showsec = $sec;
976: if ($showsec eq '') {
977: $showsec = &mt('none');
978: }
979: }
980: $output .= &Apache::loncommon::start_data_table_row()."\n".
981: '<td>'.$showtime.'</td>'."\n".
982: '<td>'.$showrole.'</td>'."\n";
983: if ($context eq 'course') {
984: $output .= '<td>'.$showsec.'</td>'."\n";
985: }
986: $output .= '<td>'.$namelink.'</td>'."\n".
987: '<td>'.$showstatus.'</td>'."\n".
988: '<td>'.$showadj.'</td>'."\n".
989: &Apache::loncommon::end_data_table_row()."\n";
990: }
991: }
992: }
993:
994: if ($showntableheader) { # Table footer, if content displayed above
995: $output .= &Apache::loncommon::end_data_table().
996: &queued_role_navlinks(\%curr,$more_records);
997: } else { # No content displayed above
998: $output .= '<p class="LC_info">'.
999: &mt('There are no records to display.').
1000: '</p>';
1001: }
1002: $output .= '<input type="hidden" name="page" value="'.$curr{'page'}.'" />';
1003: return $output;
1004: }
1005:
1006: sub queued_log_js {
1007: my ($formname) = @_;
1008: return <<"ENDSCRIPT";
1009:
1010: function chgPage(caller) {
1011: if (caller == 'previous') {
1012: document.$formname.page.value --;
1013: }
1014: if (caller == 'next') {
1015: document.$formname.page.value ++;
1016: }
1017: document.$formname.submit();
1018: return;
1019: }
1020: ENDSCRIPT
1021: }
1022:
1023: sub queued_role_navlinks {
1024: my ($curr,$more_records) = @_;
1025: return unless(ref($curr) eq 'HASH');
1026: # Navigation Buttons
1027: my $nav_links;
1028: if (($curr->{'page'} > 1) || ($more_records)) {
1029: $nav_links = '<p>';
1030: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
1031: $nav_links .= '<input type="button"'
1032: .' onclick="javascript:chgPage('."'previous'".');"'
1033: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
1034: .'" /> ';
1035: }
1036: if ($more_records) {
1037: $nav_links .= '<input type="button"'
1038: .' onclick="javascript:chgPage('."'next'".');"'
1039: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
1040: .'" />';
1041: }
1042: $nav_links .= '</p>';
1043: }
1044: return $nav_links;
1045: }
1046:
1.64 raeburn 1047: sub print_filter_menu {
1.65 raeburn 1048: my ($context,$formname,$curr,$crstype) = @_;
1049:
1050: my $nolink = 1;
1051: my $output = '<table><tr><td valign="top">'.
1052: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.66 ! raeburn 1053: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.65 raeburn 1054: (&mt('all'),5,10,20,50,100,1000,10000)).
1055: '</td><td> </td>';
1056: my $startform =
1057: &Apache::lonhtmlcommon::date_setter($formname,'rolereq_start_date',
1058: $curr->{'rolereq_start_date'},undef,
1059: undef,undef,undef,undef,undef,undef,$nolink);
1060: my $endform =
1061: &Apache::lonhtmlcommon::date_setter($formname,'rolereq_end_date',
1062: $curr->{'rolereq_end_date'},undef,
1063: undef,undef,undef,undef,undef,undef,$nolink);
1064: my %lt = &othdomrole_contexts();
1065: $output .= '<td valign="top"><b>'.&mt('Time window in which role was requested').':</b><br />'.
1066: '<table><tr><td>'.&mt('After:').
1067: '</td><td>'.$startform.'</td></tr>'.
1068: '<tr><td>'.&mt('Before:').'</td>'.
1069: '<td>'.$endform.'</td></tr></table>'.
1070: '</td>'.
1071: '<td> </td>'.
1072: '<td valign="top"><b>'.&mt('Requested role').':</b><br />'.
1073: '<select name="role"><option value="any"';
1074: if ($curr->{'role'} eq 'any') {
1075: $output .= ' selected="selected"';
1076: }
1077: $output .= '>'.&mt('Any').'</option>'."\n";
1078: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1079: foreach my $role (@roles) {
1080: my $plrole;
1081: if ($role eq 'cr') {
1082: $plrole = &mt('Custom Role');
1083: } else {
1084: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1085: }
1086: my $selstr = '';
1087: if ($role eq $curr->{'role'}) {
1088: $selstr = ' selected="selected"';
1089: }
1090: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
1091: }
1092: $output .= '</select></td>'.
1093: '<td> </td>'.
1094: '<td valign="top"><b>'.
1095: &mt('Request status').':</b><br />'.
1096: '<select name="chgstatus">'.
1097: '<option value="any"';
1098: if ($curr->{'chgstatus'} eq 'any') {
1099: $output .= ' selected="selected"';
1100: }
1101: $output .= '>'.&mt('Any').'</option>'."\n";
1102: my @possstatus = ('pending','approved','rejected');
1103: foreach my $statustype (@possstatus) {
1104: my $selstr = '';
1105: if ($curr->{'chgstatus'} eq $statustype) {
1106: $selstr = ' selected="selected"';
1107: }
1108: $output .= '<option value="'.$statustype.'"'.$selstr.'>'.$lt{$statustype}.'</option>'."\n";
1109: }
1110: $output .= '</select></td>'.
1111: '<td> </td>'.
1112: '<td valign="top"><b>'.
1113: &mt('Adjudicator').':</b><br />'.
1114: '<select name="chgadj">'.
1115: '<option value="any"';
1116: if ($curr->{'adj'} eq 'any') {
1117: $output .= ' selected="selected"';
1118: }
1119: $output .= '>'.&mt('Any').'</option>'."\n";
1120: my @possadj = ('domain','user');
1121: foreach my $adjtype (@possadj) {
1122: my $selstr = '';
1123: if ($curr->{'chgadj'} eq $adjtype) {
1124: $selstr = ' selected="selected"';
1125: }
1126: $output .= '<option value="'.$adjtype.'"'.$selstr.'>'.$lt{$adjtype}.'</option>'."\n";
1127: }
1128: $output .= '</select></td>'
1129: .'</tr></table>';
1130:
1131: # Update Display button
1132: $output .= '<p>'.
1133: '<input type="submit" value="'.&mt('Update Display').'" />'.
1134: '</p>'.
1135: '<hr />';
1136: return $output;
1137: }
1138:
1139: sub othdomrole_contexts {
1140: my %lt = &Apache::lonlocal::texthash(
1141: pending => 'Queued',
1142: approved => 'Approved',
1143: rejected => 'Rejected',
1144: user => 'User who acquires role',
1145: );
1146: $lt{'domain'} = &mt("[_1] in user's domain",
1147: &Apache::lonnet::plaintext('dc'));
1148: return %lt;
1.64 raeburn 1149: }
1150:
1.1 raeburn 1151: sub update_request_queue {
1152: my ($context,$cdom,$cnum,$coursedesc) = @_;
1153: my ($output,$access_start,$access_end,$limit,$cap,$notifylist,$namespace,
1.26 raeburn 1154: $stucounts,$idx,$classlist,%requesthash,$cid,$domdesc,$now,
1155: $sender,$approvedmsg,$rejectedmsg,$beneficiary,
1.2 raeburn 1156: @existing,@missingreq,@invalidusers,@limitexceeded,@completed,
1.19 raeburn 1157: @processing_errors,@warn_approves,@warn_rejects,@approvals,@warn_dels,
1.30 raeburn 1158: @rejections,@rejectionerrors,@nopermissions,%courseroles,@toremove,
1159: %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype,$queue,
1.63 raeburn 1160: $firsturl,$uniquecode,%codes,%roles_by_context,%requesteractive,
1.64 raeburn 1161: %gotroles,$confname,%requestedby,@rejectedreqs,$dbname);
1.29 golterma 1162: my $count=0;
1.43 raeburn 1163: while (my $item = $env{'form.'.$count.'radioreq'}) {
1164: if ($item =~ /^\d+:/) {
1165: push(@approvals,$item);
1166: } elsif ($item !~ /^later:/) {
1167: push(@rejections,$item);
1.29 golterma 1168: }
1.43 raeburn 1169: $count ++;
1.29 golterma 1170: }
1.1 raeburn 1171: $now = time;
1172: $sender = $env{'user.name'}.':'.$env{'user.domain'};
1173: if ($context eq 'course') {
1174: $namespace = 'selfenrollrequests';
1175: $beneficiary = 'enroller';
1176: $cid = $env{'request.course.id'};
1.12 raeburn 1177: $crstype = lc(&Apache::loncommon::course_type());
1.54 raeburn 1178: $firsturl = &Apache::lonnet::course_portal_url($cnum,$cdom);
1.1 raeburn 1179: %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
1180: $access_start = $env{'course.'.$cid.'.internal.selfenroll_start_access'};
1181: $access_end = $env{'course.'.$cid.'.internal.selfenroll_end_access'};
1182: $limit = $env{'course.'.$cid.'.internal.selfenroll_limit'};
1183: $cap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
1184: $notifylist = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
1185: ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
1186: $approvedmsg = [{
1187: mt => 'Your request for enrollment has been approved.',
1188: },
1189: {
1.28 raeburn 1190: mt => 'Visit [_1] to log-in and access the course',
1.25 raeburn 1191: args => [$firsturl],
1.1 raeburn 1192: }];
1193: $rejectedmsg = [{
1194: mt => 'Your request for enrollment has not been approved.',
1195: }];
1.30 raeburn 1196: } elsif ($context eq 'requestauthor') {
1197: $namespace = 'requestauthorqueue';
1198: $beneficiary = 'requestauthor';
1199: %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom);
1200: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1201: if (ref($domdefs{'requestauthor'}) eq 'HASH') {
1202: if (ref($domdefs{'requestauthor'}{'notify'}) eq 'HASH') {
1203: $notifylist = $domdefs{'requestauthor'}{'notify'}{'approval'};
1204: }
1205: }
1206: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($cdom);
1.54 raeburn 1207: $firsturl = &Apache::lonnet::course_portal_url($domconfiguser,$cdom);
1.30 raeburn 1208: $approvedmsg = [{
1.42 bisitz 1209: mt => 'Your request for Authoring Space has been approved.',
1.30 raeburn 1210: },
1211: {
1212: mt => 'Visit [_1] to log-in and select your author role',
1213: args => [$firsturl],
1214: }];
1215: $rejectedmsg = [{
1.42 bisitz 1216: mt => 'Your request for Authoring Space has not been approved.',
1.30 raeburn 1217: }];
1218: $domdesc = &Apache::lonnet::domain($cdom);
1.43 raeburn 1219: } elsif ($context eq 'requestusername') {
1220: $namespace = 'usernamequeue';
1221: $beneficiary = 'requestusername';
1222: %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom);
1223: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$cdom);
1224: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1225: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
1226: if (ref($domconfig{'usercreation'}{'cancreate'}{'notify'}) eq 'HASH') {
1227: $notifylist = $domconfig{'usercreation'}{'cancreate'}{'notify'}{'approval'};
1228: }
1229: }
1230: }
1231: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($cdom);
1.54 raeburn 1232: $firsturl = &Apache::lonnet::course_portal_url($domconfiguser,$cdom);
1.43 raeburn 1233: $approvedmsg = [{
1234: mt => 'Your request for a LON-CAPA account has been approved.',
1235: },
1236: {
1237: mt => 'Visit [_1] to log-in.',
1238: args => [$firsturl],
1239: }];
1240: $rejectedmsg = [{
1241: mt => 'Your request for a LON-CAPA account has not been approved.',
1242: }];
1243: $domdesc = &Apache::lonnet::domain($cdom);
1.64 raeburn 1244: $dbname = 'nohist_requestedusernames';
1.63 raeburn 1245: } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
1.64 raeburn 1246: $namespace = 'nohist_queuedrolereqs';
1.63 raeburn 1247: foreach my $type ('domain','course') {
1248: my @possroles = &Apache::lonuserutils::roles_by_context($type);
1249: $roles_by_context{$type} = \@possroles;
1250: }
1251: if ($context eq 'othdombydc') {
1.64 raeburn 1252: $confname = &Apache::lonnet::get_domainconfiguser($cdom);
1.63 raeburn 1253: %requesthash = &Apache::lonnet::dump($namespace,$cdom,$confname);
1254: } else {
1255: %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
1256: }
1257: $domdesc = &Apache::lonnet::domain($cdom);
1.64 raeburn 1258: $dbname = 'nohist_othdomqueued';
1.1 raeburn 1259: } else {
1.2 raeburn 1260: $domdesc = &Apache::lonnet::domain($cdom);
1261: $namespace = 'courserequestqueue';
1262: $beneficiary = 'courserequestor';
1.23 raeburn 1263: $queue = 'approval';
1264: if ($env{'form.queue'} eq 'pending') {
1265: $queue = 'pending';
1266: }
1267: %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom,'_'.$queue);
1.2 raeburn 1268: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
1269: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
1270: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
1271: $notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
1272: }
1273: }
1.12 raeburn 1274: $approvalmsg{'course'} =
1275: [{
1.2 raeburn 1276: mt => 'Your course request has been approved.',
1277: },
1278: {
1.28 raeburn 1279: mt => 'Visit [_1] to log-in and access the course',
1280: args => [],
1.2 raeburn 1281: }];
1.12 raeburn 1282: $rejectionmsg{'course'} =
1283: [{
1.2 raeburn 1284: mt => 'Your course request has not been approved.',
1285: }];
1.12 raeburn 1286:
1287: $approvalmsg{'community'} =
1288: [{
1289: mt => 'Your community request has been approved.',
1290: },
1291: {
1.28 raeburn 1292: mt => 'Visit [_1] to log-in and access the community',
1293: args => [],
1.12 raeburn 1294: }];
1295:
1296: $rejectionmsg{'community'} =
1297: [{
1298: mt => 'Your community request has not been approved.',
1299: }];
1300:
1.2 raeburn 1301: %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1302: my @roles = &Apache::lonuserutils::roles_by_context('course');
1303: foreach my $role (@roles) {
1304: $courseroles{$role}=&Apache::lonnet::plaintext($role,'Course');
1305: }
1306: foreach my $role (@roles) {
1307: $communityroles{$role}=&Apache::lonnet::plaintext($role,'Community');
1308: }
1.1 raeburn 1309: }
1310: foreach my $item (sort {$a <=> $b} @approvals) {
1311: if ($context eq 'course') {
1312: my ($num,$uname,$udom,$usec) = split(/:/,$item);
1313: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
1314: if ($uhome ne 'no_host') {
1315: if (exists($requesthash{$uname.':'.$udom})) {
1316: if (exists($classlist->{$uname.':'.$udom})) {
1317: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
1318: if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
1319: ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
1320: push(@existing,$uname.':'.$udom);
1321: next;
1322: }
1323: }
1324: }
1325: } else {
1326: push(@missingreq,$uname.':'.$udom);
1327: next;
1328: }
1329: if (!grep(/^\Q$item\E$/,@rejections)) {
1330: if ($limit eq 'allstudents') {
1331: if ($stucounts->{$limit} >= $cap) {
1332: push(@limitexceeded,$uname.':'.$udom);
1333: last;
1334: }
1335: } elsif ($limit eq 'selfenrolled') {
1336: if ($stucounts->{$limit} >= $cap) {
1337: push(@limitexceeded,$uname.':'.$udom);
1338: last;
1339: }
1340: }
1341: my $result =
1342: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
1343: if ($result eq 'ok') {
1.2 raeburn 1344: push(@completed,$uname.':'.$udom);
1.1 raeburn 1345: $stucounts->{'allstudents'} ++;
1346: $stucounts->{'selfenrolled'} ++;
1347: &send_selfserve_notification($uname.':'.$udom,$approvedmsg,
1.26 raeburn 1348: $cid,$coursedesc,$now,$beneficiary,$sender,
1349: undef,undef,$crstype);
1.2 raeburn 1350: my %userrequest = (
1351: $cdom.'_'.$cnum => {
1352: timestamp => $now,
1353: section => $usec,
1354: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
1355: status => 'approved',
1356: }
1357: );
1.1 raeburn 1358: my $userresult =
1359: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
1360: if ($userresult ne 'ok') {
1361: push(@warn_approves,$uname.':'.$udom);
1362: }
1363: } else {
1.2 raeburn 1364: push(@processing_errors,$uname.':'.$udom);
1.1 raeburn 1365: }
1366: }
1367: } else {
1368: push(@invalidusers,$uname.':'.$udom);
1369: }
1.30 raeburn 1370: } elsif ($context eq 'requestauthor') {
1371: my ($num,$uname) = split(/:/,$item);
1372: my $uhome = &Apache::lonnet::homeserver($uname,$cdom);
1373: if ($uhome ne 'no_host') {
1374: my ($user_is_adv,$user_is_author) = &Apache::lonnet::is_advanced_user($cdom,$uname);
1375: if ($user_is_author) {
1376: push(@existing,$uname);
1377: } elsif (&Apache::lonnet::usertools_access($uname,$cdom,'requestauthor',
1378: undef,'requestauthor')) {
1379: if (&Apache::lonnet::allowed('cau',$cdom)) {
1380: if (&Apache::lonnet::assignrole($cdom,$uname,'/'.$cdom.'/','au',undef,time,undef,undef,'requestauthor') eq 'ok') {
1381: push(@completed,$uname);
1382: &send_selfserve_notification($uname.':'.$cdom,
1383: $approvedmsg,undef,undef,$now,
1384: $beneficiary,$sender);
1385: my %userrequest = (
1386: author => {
1387: timestamp => $now,
1388: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
1389: status => 'approved',
1390: },
1391: author_status => 'approved',
1392: );
1393: my $userresult =
1394: &Apache::lonnet::put('requestauthor',\%userrequest,$cdom,$uname);
1395: if ($userresult ne 'ok') {
1.43 raeburn 1396: push(@warn_approves,$uname.':'.$cdom);
1.30 raeburn 1397: }
1398: } else {
1399: push(@processing_errors,$uname);
1400: }
1401: } else {
1402: push(@nopermissions,$uname);
1403: }
1404: } else {
1405: push(@nopermissions,$uname);
1406: }
1407: } else {
1408: push(@invalidusers,$uname.':'.$cdom);
1409: }
1410: push(@toremove,(@invalidusers,@nopermissions));
1.43 raeburn 1411: } elsif ($context eq 'requestusername') {
1412: my ($num,$uname) = split(/:/,$item);
1413: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($cdom);
1414: my %curr = &Apache::lonnet::get($dbname,[$uname],$cdom,$domconfiguser);
1.58 raeburn 1415:
1.43 raeburn 1416: if (ref($curr{$uname}) eq 'HASH') {
1.58 raeburn 1417: my ($logtoken,$serverid,$encpass,$courseid,$id,$firstname,
1418: $middlename,$lastname,$generation,$inststatus,$email);
1.43 raeburn 1419: $curr{$uname}{'timestamp'} = $now;
1420: $curr{$uname}{'adjudicator'} = $env{'user.name'}.':'.$env{'user.domain'};
1421: $courseid = $curr{$uname}{'courseid'};
1422: $id = $curr{$uname}{'id'};
1423: $firstname = $curr{$uname}{'firstname'};
1424: $middlename = $curr{$uname}{'middlename'};
1425: $lastname = $curr{$uname}{'lastname'};
1426: $generation = $curr{$uname}{'generation'};
1.46 raeburn 1427: $inststatus = $curr{$uname}{'inststatus'};
1.43 raeburn 1428:
1.58 raeburn 1429: if ($curr{$uname}{'email'} ne '') {
1430: $email = $curr{$uname}{'email'};
1431: } elsif ($uname =~ /^[^\@]+\@[^\@]+$/) {
1432: $email = $uname;
1433: }
1434:
1435: my $upass;
1436: if ($curr{$uname}{'tmpinfo'}) {
1437: my ($key,$caller)=split(/&/,$curr{$uname}{'tmpinfo'});
1438: if ($caller eq 'createaccount') {
1439: if ($curr{$uname}{'upass'} eq '') {
1440: $upass = $curr{$uname}{'upass'};
1441: } else {
1442: $upass = &Apache::loncommon::des_decrypt($key,$curr{$uname}{'upass'});
1443: }
1444: } else {
1445: push(@processing_errors,$uname);
1446: }
1447: } else {
1448: $upass = $curr{$uname}{'upass'};
1449: }
1450: if ($upass eq '') {
1451: push(@processing_errors,$uname);
1452: } else {
1.43 raeburn 1453: undef($curr{$uname}{'upass'});
1454: my $result =
1455: &Apache::lonnet::modifyuser($cdom,$uname,$id,'internal',$upass,
1456: $firstname,$middlename,$lastname,
1.58 raeburn 1457: $generation,undef,undef,$email);
1.43 raeburn 1458: if ($result eq 'ok') {
1459: $curr{$uname}{'status'} = 'created';
1460: push(@completed,$uname);
1461: my $uhome = &Apache::lonnet::homeserver($uname,$cdom);
1462: if ($uhome eq 'no_host') {
1463: push(@warn_approves,$uname);
1464: } else {
1.44 raeburn 1465: unless (($inststatus eq 'default') || ($inststatus eq '')) {
1466: &Apache::lonnet::put('environment',{inststatus => $inststatus},$cdom,$uname);
1467: }
1.43 raeburn 1468: &send_selfserve_notification($uname.':'.$cdom,
1469: $approvedmsg,undef,undef,$now,
1470: $beneficiary,$sender);
1471: if (&Apache::lonnet::put($dbname,\%curr,$cdom,$domconfiguser) ne 'ok') {
1472: push(@warn_approves,$uname);
1473: }
1474: }
1475: } else {
1476: push(@processing_errors,$uname);
1477: }
1478: }
1479: } else {
1480: push(@invalidusers,$uname);
1481: }
1482: push(@toremove,@invalidusers);
1.63 raeburn 1483: } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
1484: if ($context eq 'othdombydc') {
1485: my ($num,$extent,$role,$uname,$udom) = split(/:/,$item);
1486: my ($logmsg,$result);
1487: if ($udom eq $cdom) {
1.64 raeburn 1488: my $key = 'pending:'.$uname.':'.$extent.':'.$role;
1.63 raeburn 1489: if (exists($requesthash{$key})) {
1490: if (ref($requesthash{$key}) eq 'HASH') {
1491: my $requester = $requesthash{$key}->{'requester'};
1492: my ($requname,$requdom) = split(/:/,$requester);
1493: my $start = $requesthash{$key}->{'start'};
1494: my $end = $requesthash{$key}->{'end'};
1495: my $credits = $requesthash{$key}->{'credits'};
1496: my $reqcontext = $requesthash{$key}->{'context'};
1497: if ((&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') &&
1498: (&Apache::lonnet::homeserver($requname,$requdom) ne 'no_host')) {
1499: if (($role eq 'ca') || ($role eq 'aa')) {
1500: my ($audom,$auname) = ($extent =~ m{^/($match_domain)/($match_username)$});
1501: if (&Apache::lonnet::homeserver($auname,$audom) ne 'no_host') {
1502: if ($requester eq $auname.':'.$audom) {
1503: unless ($gotroles{$requester}) {
1504: &requester_roles($auname,$audom,\%requesteractive);
1505: $gotroles{$requester} = 1;
1506: }
1507: if (ref($requesteractive{$requester}) eq 'HASH') {
1508: if ($requesteractive{$requester}{':'.$audom.':au'}) {
1509: $result = &Apache::lonnet::assignrole($udom,$uname,$extent,$role,
1510: $end,$start,'','',$reqcontext);
1511: }
1512: }
1513: }
1514: }
1515: } elsif (($role eq 'co') || ($role eq 'cc')) {
1516: my ($crsdom,$crsnum) = ($extent =~ m{^/($match_domain)/($match_courseid)});
1517: if (&Apache::lonnet::is_course($crsdom,$crsnum)) {
1518: my %info = &Apache::lonnet::coursedescription("$crsdom/$crsnum",{'one_time' => 1});
1519: if ((($role eq 'co') && ($info{'type'} eq 'Community')) ||
1520: (($role eq 'cc') && ($info{'type'} ne 'Community'))) {
1521: if ($info{'internal.courseowner'} eq $requester) {
1522: unless ($gotroles{$requester}) {
1523: &requester_roles($requname,$requdom,\%requesteractive);
1524: $gotroles{$requester} = 1;
1525: }
1526: if (ref($requesteractive{$requester}) eq 'HASH') {
1527: if ($requesteractive{$requester}{"$crsnum:$crsdom:$role"}) {
1.64 raeburn 1528: ($logmsg,$result) =
1.63 raeburn 1529: &Apache::loncommon::commit_standardrole($udom,$uname,$extent,$role,$start,
1530: $end,$crsdom,$crsnum,'',
1531: $reqcontext);
1532: }
1533: }
1534: }
1535: }
1536: }
1537: } elsif ($role =~ m{^(cr)/($match_domain)/($match_username)/(\w+)$}) {
1538: my ($mrole,$crudom,$cruname,$rolename) = ($1,$2,$3,$4);
1539: my ($crsdom,$crsnum,$csec) =
1540: ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$});
1541: if (&Apache::lonnet::is_course($crsdom,$crsnum)) {
1542: my ($rdummy,$roledef) =
1543: &Apache::lonnet::get('roles',["rolesdef_$rolename"],$crudom,$cruname);
1544: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1545: unless ($gotroles{$requester}) {
1546: &requester_roles($requname,$requdom,\%requesteractive);
1547: $gotroles{$requester} = 1;
1548: }
1549: if (ref($requesteractive{$requester}) eq 'HASH') {
1550: if (&requester_has_perm($crsdom,$crsnum,$mrole,$requesteractive{$requester})) {
1.64 raeburn 1551: ($logmsg,$result) =
1552: &Apache::loncommon::commit_customrole($udom,$uname,$extent,$crudom,$cruname,
1553: $rolename,$start,$end,$reqcontext);
1.63 raeburn 1554: }
1555: }
1556: }
1557: }
1558: } else {
1559: my $process;
1560: foreach my $type ('course','domain') {
1561: if (grep(/^\Q$role\E$/,@{$roles_by_context{$type}})) {
1562: if ($type eq 'course') {
1563: my ($crsdom,$crsnum,$csec) = ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$});
1564: if (&Apache::lonnet::is_course($crsdom,$crsnum)) {
1565: my $typeok;
1566: if ($role eq 'cc') {
1567: my %info = &Apache::lonnet::coursedescription("$crsdom/$crsnum",{'one_time' => 1});
1568: if ($info{'type'} eq 'Course') {
1569: $typeok = 1;
1570: }
1571: } else {
1572: $typeok = 1;
1573: }
1574: if ($typeok) {
1575: unless ($gotroles{$requester}) {
1576: &requester_roles($requname,$requdom,\%requesteractive);
1577: $gotroles{$requester} = 1;
1578: }
1579: if (ref($requesteractive{$requester}) eq 'HASH') {
1580: if (&requester_has_perm($crsdom,$crsnum,$role,$requesteractive{$requester})) {
1.64 raeburn 1581: ($logmsg,$result) =
1.63 raeburn 1582: &Apache::loncommon::commit_standardrole($udom,$uname,$extent,$role,$start,
1583: $end,$crsdom,$crsnum,$csec,
1584: $reqcontext,$credits);
1585: }
1586: }
1587: }
1588: }
1589: } else {
1.64 raeburn 1590: my ($domain) = ($extent =~ m{^/($match_domain)/});
1.63 raeburn 1591: if (&Apache::lonnet::domain($domain) ne '') {
1592: unless ($gotroles{$requester}) {
1593: &requester_roles($requname,$requdom,\%requesteractive);
1594: $gotroles{$requester} = 1;
1595: }
1596: if (&requester_has_perm($domain,'',$role,$requesteractive{$requester})) {
1597: $result = &Apache::lonnet::assignrole($udom,$uname,$extent,$role,
1598: $end,$start,'','',$reqcontext);
1599: }
1600: }
1601: }
1602: last;
1603: }
1604: }
1605: }
1606: }
1.64 raeburn 1607: if ($result eq 'ok') {
1608: $requestedby{$item} = $requester;
1609: my $statusres;
1610: my $id = $uname.':'.$udom.':'.$role;
1611: if (($role eq 'ca') || ($role eq 'aa')) {
1612: my ($audom,$auname) = ($extent =~ m{^/($match_domain)/($match_username)$});
1613: $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'approved'},$audom,$auname);
1614: } elsif ($extent =~ m{^/($match_domain)/$}) {
1615: my $domain = $1;
1616: my $configuser = &Apache::lonnet::get_domainconfiguser($domain);
1617: $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'approved'},$domain,$configuser);
1618: } else {
1619: my ($crsdom,$crsnum,$csec) = ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/([^/]+))$});
1620: $id .= ':'.$csec;
1621: $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'approved'},$crsdom,$crsnum);
1622: }
1623: if ($statusres eq 'ok') {
1624: my $newkey = 'approved:'.$uname.':'.$extent.':'.$role;
1625: $requesthash{$newkey} = $requesthash{$key};
1626: delete($requesthash{$key});
1627: push(@toremove,$key);
1628: push(@completed,$item);
1629: }
1630: }
1.63 raeburn 1631: }
1632: }
1633: }
1634: } else {
1635: my ($num,$extent,$role) = split(/:/,$item);
1636: if (exists($requesthash{$extent.':'.$role})) {
1637: if (ref($requesthash{$extent.':'.$role}) eq 'HASH') {
1638: #FIXME
1639: #check if extent is valid
1640: #check if role is valid
1641: #check requester privs
1642: }
1643: }
1644: }
1.1 raeburn 1645: } else {
1.2 raeburn 1646: my ($num,$cnum) = split(':',$item);
1.23 raeburn 1647: if (ref($requesthash{$cnum.'_'.$queue}) eq 'HASH') {
1.2 raeburn 1648: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
1.23 raeburn 1649: my $ownername = $requesthash{$cnum.'_'.$queue}{'ownername'};
1650: my $ownerdom = $requesthash{$cnum.'_'.$queue}{'ownerdom'};
1651: $crstype = $requesthash{$cnum.'_'.$queue}{'crstype'};
1652: my $coursedesc = $requesthash{$cnum.'_'.$queue}{'description'};
1.2 raeburn 1653: my $longroles = \%courseroles;
1654: if ($crstype eq 'community') {
1655: $longroles = \%communityroles;
1656: }
1.5 raeburn 1657: my $cancreate;
1658: if ($cdom eq $ownerdom) {
1659: if (&Apache::lonnet::usertools_access($ownername,$ownerdom,$crstype,
1660: undef,'requestcourses')) {
1661: $cancreate = 1;
1662: }
1663: } else {
1664: my %userenv = &Apache::lonnet::userenvironment($ownerdom,$ownername,'reqcrsotherdom.'.$crstype);
1665: if ($userenv{'reqcrsotherdom.'.$crstype}) {
1666: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
1667: if (grep(/^\Q$cdom\E:/,@doms)) {
1668: $cancreate = 1;
1669: }
1670: }
1671: }
1672: if ($cancreate) {
1.2 raeburn 1673: my $requestkey = $cdom.'_'.$cnum;
1674: my %history =
1675: &Apache::lonnet::restore($requestkey,'courserequests',
1676: $ownerdom,$ownername);
1677: if ((ref($history{'details'}) eq 'HASH') &&
1.23 raeburn 1678: ($history{'disposition'} eq $queue)) {
1.59 raeburn 1679: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,
1680: $keysmsg,$code,%customitems);
1681: my $clonemsg = [];
1.41 raeburn 1682: my $fullname = '';
1683: my $inprocess = &Apache::lonnet::auto_crsreq_update($cdom,$cnum,$crstype,'process',$ownername,
1684: $ownerdom,$fullname,$coursedesc);
1685: if (ref($inprocess) eq 'HASH') {
1686: foreach my $key (keys(%{$inprocess})) {
1687: if (exists($history{'details'}{$key})) {
1688: $customitems{$key} = $history{'details'}{$key};
1689: }
1690: }
1691: }
1.50 raeburn 1692: if ($history{'details'}{'clonecrs'}) {
1693: $customitems{'_LC_clonefrom'} = $history{'details'}{'clonedom'}.'_'.$history{'details'}{'clonecrs'};
1694: }
1.59 raeburn 1695: my ($result,$postprocess) = &course_creation($cdom,$cnum,$context,$history{'details'},
1696: \$logmsg,$clonemsg,\$newusermsg,\$addresult,\$enrollcount,
1.41 raeburn 1697: \$response,\$keysmsg,\%domdefs,$longroles,\$code,\%customitems);
1.2 raeburn 1698: if ($result eq 'created') {
1.12 raeburn 1699: if ($crstype eq 'community') {
1700: $approvedmsg = $approvalmsg{'community'};
1701: } else {
1702: $approvedmsg = $approvalmsg{'course'};
1703: }
1.54 raeburn 1704: my $firsturl = &Apache::lonnet::course_portal_url($cnum,$cdom);
1.28 raeburn 1705: if (ref($approvedmsg) eq 'ARRAY') {
1706: if (ref($approvedmsg->[1]) eq 'HASH') {
1707: $approvedmsg->[1]->{'args'} = [$firsturl];
1708: }
1.59 raeburn 1709: if ((ref($clonemsg) eq 'ARRAY') && (@{$clonemsg})) {
1710: push(@{$approvedmsg},@{$clonemsg});
1711: }
1.39 raeburn 1712: if ($code) {
1713: push(@{$approvedmsg},
1714: {
1715: mt => 'Students can automatically select your course by entering this code: [_1]',
1716: args => [$code],
1717: });
1718: $codes{$cnum} = $code;
1719: }
1.41 raeburn 1720: if (ref($postprocess) eq 'HASH') {
1721: if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
1722: foreach my $item (@{$postprocess->{'createdmsg'}}) {
1723: if (ref($item) eq 'HASH') {
1724: if ($item->{'mt'} ne '') {
1725: push(@{$approvedmsg},$item);
1726: }
1727: }
1728: }
1729: }
1730: }
1.28 raeburn 1731: }
1.2 raeburn 1732: push(@completed,$cnum);
1.19 raeburn 1733:
1.23 raeburn 1734: unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_'.$queue],$cdom) eq 'ok') {
1.19 raeburn 1735: push(@warn_dels,$cnum);
1736: }
1.26 raeburn 1737: &send_selfserve_notification($ownername.':'.$ownerdom,
1738: $approvedmsg,$cid,$coursedesc,$now,
1739: $beneficiary,$sender,undef,undef,$crstype);
1.2 raeburn 1740: my %reqhash = (
1741: reqtime => $history{'reqtime'},
1742: crstype => $history{'crstype'},
1743: details => $history{'details'},
1744: disposition => $history{'disposition'},
1745: status => 'created',
1746: adjudicator => $env{'user.name'}.':'.
1747: $env{'user.domain'},
1748: );
1749: my $userresult =
1750: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
1751: 'courserequests',$ownerdom,$ownername);
1752: if ($userresult eq 'ok') {
1753: my %status = (
1754: 'status:'.$cdom.':'.$cnum => 'created'
1755: );
1756: my $statusresult =
1757: &Apache::lonnet::put('courserequests',\%status,
1758: $ownerdom,$ownername);
1759: if ($statusresult ne 'ok') {
1760: push(@warn_approves,$cnum);
1761: }
1762: }
1763: if ($userresult ne 'ok') {
1764: push(@warn_approves,$cnum);
1765: }
1766: } else {
1767: push(@processing_errors,$cnum);
1768: }
1769: } else {
1770: push(@processing_errors,$cnum);
1771: }
1772: } else {
1.5 raeburn 1773: push(@nopermissions,$cnum);
1.2 raeburn 1774: }
1775: } else {
1776: push(@existing,$cnum);
1777: }
1778: } else {
1779: push(@missingreq,$cnum);
1780: }
1.1 raeburn 1781: }
1782: }
1.2 raeburn 1783: my @changes = (@completed,@rejections);
1784: if ($context eq 'domain') {
1.23 raeburn 1785: @changes = map {$_.'_'.$queue} (@changes);
1.30 raeburn 1786: } elsif ($context eq 'requestauthor') {
1787: @changes = map {$_.'_approval'} (@changes);
1.43 raeburn 1788: } elsif ($context eq 'requestusername') {
1789: @changes = map {&escape($_).'_approval'} (@changes);
1.2 raeburn 1790: }
1.1 raeburn 1791: if (@rejections) {
1.3 raeburn 1792: foreach my $item (@rejections) {
1.30 raeburn 1793: if (($context eq 'course') || ($context eq 'requestauthor')) {
1.43 raeburn 1794: my ($user,$uname,$udom,%userrequest,$key,$dbname);
1.30 raeburn 1795: if ($context eq 'requestauthor') {
1796: $uname = $item;
1797: $udom = $cdom;
1798: $user = $uname.':'.$udom;
1799: $key = 'author';
1.43 raeburn 1800: $dbname = 'requestauthor';
1.30 raeburn 1801: } else {
1802: $user = $item;
1803: ($uname,$udom) = split(/:/,$user);
1804: $key = $cdom.'_'.$cnum;
1.43 raeburn 1805: $dbname = $namespace;
1.30 raeburn 1806: }
1.2 raeburn 1807: &send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc,
1.26 raeburn 1808: $now,$beneficiary,$sender,undef,undef,
1809: $crstype);
1.30 raeburn 1810: %userrequest = (
1811: $key => {
1.1 raeburn 1812: timestamp => $now,
1813: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
1.30 raeburn 1814: status => 'rejection',
1.1 raeburn 1815: }
1816: );
1.30 raeburn 1817: if ($context eq 'requestauthor') {
1818: $userrequest{'author_status'} = 'rejection';
1819: }
1.1 raeburn 1820: my $userresult =
1.43 raeburn 1821: &Apache::lonnet::put($dbname,\%userrequest,$udom,$uname);
1.1 raeburn 1822: if ($userresult ne 'ok') {
1.30 raeburn 1823: push(@warn_rejects,$item);
1.1 raeburn 1824: }
1.43 raeburn 1825: } elsif ($context eq 'requestusername') {
1826: my ($uname,$udom,$dbname);
1827: $uname = $item;
1828: $udom = $cdom;
1829: $dbname = 'nohist_requestedusernames';
1830: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($cdom);
1831: my %curr = &Apache::lonnet::get($dbname,[$uname],$cdom,$domconfiguser);
1832: if (ref($curr{$uname}) eq 'HASH') {
1833: $curr{$uname}{'status'} = 'rejected';
1834: $curr{$uname}{'timestamp'} = $now;
1835: $curr{$uname}{'adjudicator'} = $env{'user.name'}.':'.$env{'user.domain'};
1836: undef($curr{$uname}{'tmpinfo'});
1837: undef($curr{$uname}{'upass'});
1838: }
1839: my $userresult =
1840: &Apache::lonnet::put($dbname,\%curr,$cdom,$domconfiguser);
1841: if ($userresult ne 'ok') {
1842: push(@warn_rejects,$uname);
1843: }
1.63 raeburn 1844: } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
1.64 raeburn 1845: if ($context eq 'othdombydc') {
1846: my ($extent,$role,$uname,$udom) = split(/:/,$item);
1847: my $oldkey = 'pending:'.$uname.':'.$extent.':'.$role;
1848: my $newkey = 'rejected:'.$uname.':'.$extent.':'.$role;
1849: my $dbname = 'nohist_othdomqueued';
1850: if (exists($requesthash{$oldkey})) {
1851: if (ref($requesthash{$oldkey}) eq 'HASH') {
1852: $requesthash{$newkey} = $requesthash{$oldkey};
1853: delete($requesthash{$oldkey});
1854: push(@toremove,$oldkey);
1855: $requesthash{$newkey}->{'timestamp'} = $now;
1856: $requesthash{$newkey}->{'adjudicator'} = $env{'user.name'}.':'.$env{'user.domain'};
1857: my $statusres;
1858: my $id = $uname.':'.$udom.':'.$role;
1859: if (($role eq 'ca') || ($role eq 'aa')) {
1860: my ($audom,$auname) = ($extent =~ m{^/($match_domain)/($match_username)$});
1861: $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'rejected'},$audom,$auname);
1862: } elsif ($extent =~ m{^/($match_domain)/$}) {
1863: my $domain = $1;
1864: my $configuser = &Apache::lonnet::get_domainconfiguser($domain);
1865: $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'rejected'},$domain,$configuser);
1866: } else {
1867: my ($crsdom,$crsnum,$csec) = ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/([^/]+))$});
1868: $id .= ':'.$csec;
1869: $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'rejected'},$crsdom,$crsnum);
1870: }
1871: if ($statusres eq 'ok') {
1872: $requestedby{$item} = $requesthash{$newkey}->{'requester'};
1873: push(@rejectedreqs,$item);
1874: }
1875: }
1876: }
1877: }
1.1 raeburn 1878: } else {
1.3 raeburn 1879: my $cnum = $item;
1.23 raeburn 1880: if (ref($requesthash{$cnum.'_'.$queue}) eq 'HASH') {
1.3 raeburn 1881: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
1882: my $requestkey = $cdom.'_'.$cnum;
1.23 raeburn 1883: my $ownername = $requesthash{$cnum.'_'.$queue}{'ownername'};
1884: my $ownerdom = $requesthash{$cnum.'_'.$queue}{'ownerdom'};
1885: my $coursedesc = $requesthash{$cnum.'_'.$queue}{'description'};
1886: $crstype = $requesthash{$cnum.'_'.$queue}{'crstype'};
1.12 raeburn 1887: if ($crstype eq 'community') {
1888: $rejectedmsg = $rejectionmsg{'community'};
1889: } else {
1890: $rejectedmsg = $rejectionmsg{'course'};
1891: }
1.2 raeburn 1892: &send_selfserve_notification($ownername.':'.$ownerdom,$rejectedmsg,
1893: $cid,$coursedesc,$now,$beneficiary,
1.12 raeburn 1894: $sender,undef,undef,$crstype);
1.2 raeburn 1895: my %history =
1.3 raeburn 1896: &Apache::lonnet::restore($requestkey,'courserequests',
1.2 raeburn 1897: $ownerdom,$ownername);
1898: if ((ref($history{'details'}) eq 'HASH') &&
1.23 raeburn 1899: ($history{'disposition'} eq $queue)) {
1.2 raeburn 1900: my %reqhash = (
1901: reqtime => $history{'reqtime'},
1902: crstype => $history{'crstype'},
1903: details => $history{'details'},
1904: disposition => $history{'disposition'},
1905: status => 'rejected',
1906: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
1907: );
1908: my $userresult =
1.3 raeburn 1909: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
1910: 'courserequests',$ownerdom,$ownername);
1911: if ($userresult eq 'ok') {
1912: my %status = (
1913: 'status:'.$cdom.':'.$cnum => 'rejected'
1914: );
1915: my $statusresult =
1916: &Apache::lonnet::put('courserequests',\%status,
1917: $ownerdom,$ownername);
1918: if ($statusresult ne 'ok') {
1919: push(@warn_rejects,$cnum);
1920: }
1921: } else {
1922: push(@warn_rejects,$cnum);
1.2 raeburn 1923: }
1.23 raeburn 1924: unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_'.$queue],$cdom) eq 'ok') {
1.19 raeburn 1925: push(@warn_dels,$cnum);
1926: }
1.3 raeburn 1927: } else {
1928: push(@warn_rejects,$cnum);
1.2 raeburn 1929: }
1.3 raeburn 1930: } else {
1931: push(@existing,$cnum);
1.2 raeburn 1932: }
1.3 raeburn 1933: } else {
1934: push(@rejectionerrors,$cnum);
1.2 raeburn 1935: }
1.1 raeburn 1936: }
1937: }
1938: }
1.30 raeburn 1939: if (@toremove) {
1.43 raeburn 1940: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($cdom);
1.30 raeburn 1941: foreach my $item (@toremove) {
1.43 raeburn 1942: if ($context eq 'requestauthor') {
1943: my %userrequest = (
1944: author => {
1945: timestamp => $now,
1946: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
1947: status => 'deleted',
1948: },
1949: author_status => 'deleted',
1950: );
1951: &Apache::lonnet::put('requestauthor',\%userrequest,$cdom,$item);
1952: } elsif ($context eq 'requestusername') {
1953: my $dbname = 'nohist_requestedusernames';
1954: my %curr = &Apache::lonnet::get($dbname,[$item],$cdom,$domconfiguser);
1955: if (ref($curr{$item}) eq 'HASH') {
1956: $curr{$item}{'status'} = 'deleted';
1957: $curr{$item}{'timestamp'} = $now;
1958: $curr{$item}{'adjudicator'} = $env{'user.name'}.':'.$env{'user.domain'};
1959: undef($curr{$item}{'upass'});
1960: undef($curr{$item}{'tmpinfo'});
1961: }
1962: }
1.30 raeburn 1963: }
1.64 raeburn 1964: unless ($context eq 'othdombydc') {
1965: @toremove = map {$_.'_approval'} (@toremove);
1966: }
1.30 raeburn 1967: my $delresult = &Apache::lonnet::del_dom($namespace,\@toremove,$cdom);
1.64 raeburn 1968: if (($delresult ne 'ok') && ($context eq 'othdombydc')) {
1969: push(@warn_dels,@toremove);
1970: }
1.30 raeburn 1971: }
1.1 raeburn 1972: if (@changes) {
1973: my $delresult;
1974: if ($context eq 'course') {
1975: $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
1.64 raeburn 1976: } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
1977: if ($context eq 'othdombydc') {
1978: $delresult = &Apache::lonnet::put($namespace,\%requesthash,$cdom,$confname);
1979: }
1.1 raeburn 1980: } else {
1981: $delresult = &Apache::lonnet::del_dom($namespace,\@changes,$cdom);
1982: }
1983: if ($delresult eq 'ok') {
1984: my $namelink =
1985: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
1986: my ($chgmsg,$approvedlist,$rejectedlist);
1987: if ($context eq 'course') {
1988: $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
1.2 raeburn 1989: if (@completed) {
1990: $approvedlist = join("\n",@completed);
1.12 raeburn 1991: if ($crstype eq 'community') {
1992: $output .= '<p>'.&mt('The following were enrolled in the community:').'<ul>';
1993: } else {
1994: $output .= '<p>'.&mt('The following were enrolled in the course:').'<ul>';
1995: }
1.2 raeburn 1996: foreach my $user (@completed) {
1.1 raeburn 1997: my ($uname,$udom) = split(/:/,$user);
1998: my $userlink =
1999: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
2000: $output .= '<li>'.$userlink.'</li>';
2001: }
2002: $output .= '</ul></p>';
2003: }
2004: if (@rejections) {
2005: $rejectedlist = join("\n",@rejections);
2006: $output .= '<p>'.&mt('The following enrollment requests were rejected:').'<ul>';
2007: foreach my $user (@rejections) {
2008: $output .= '<li>'.$user.'</li>';
2009: }
2010: $output .= '</ul></p>';
2011: }
1.2 raeburn 2012: if ($notifylist ne '') {
2013: &send_selfserve_notification($notifylist,$chgmsg,$cid,$coursedesc,
2014: $now,'coursemanagers',$sender,
1.12 raeburn 2015: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 2016: }
1.30 raeburn 2017: } elsif ($context eq 'requestauthor') {
1.42 bisitz 2018: $chgmsg = "'Action was taken on the following Authoring Space requests by [_1].',$namelink";
1.30 raeburn 2019: if (@completed) {
2020: $approvedlist = join("\n",@completed);
2021: $output .= '<p>'.&mt('The following requests were approved:').'<ul>';
2022: foreach my $uname (@completed) {
2023: my $userlink =
2024: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
2025: $output .= '<li>'.$userlink.'</li>';
2026: }
2027: $output .= '</ul></p>';
2028: }
2029: if (@rejections) {
2030: $rejectedlist = join("\n",@rejections);
2031: $output .= '<p>'.&mt('The following requests were rejected:').'<ul>';
2032: foreach my $uname (@rejections) {
2033: my $userlink =
2034: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
2035: $output .= '<li>'.$userlink.'</li>';
2036: }
2037: $output .= '</ul></p>';
2038: }
2039: if ($notifylist ne '') {
2040: &send_selfserve_notification($notifylist,$chgmsg,undef,$domdesc,
2041: $now,'authormanagers',$sender,
2042: $approvedlist,$rejectedlist);
2043: }
1.43 raeburn 2044: } elsif ($context eq 'requestusername') {
2045: $chgmsg = "'Action was taken on the following LON-CAPA account requests by [_1].',$namelink";
2046: if (@completed) {
2047: $approvedlist = join("\n",@completed);
2048: $output .= '<p>'.&mt('The following requests were approved:').'<ul>';
2049: foreach my $uname (@completed) {
2050: $output .= '<li>'.$uname.'</li>';
2051:
2052: }
2053: $output .= '</ul></p>';
2054: }
2055: if (@rejections) {
2056: $rejectedlist = join("\n",@rejections);
2057: $output .= '<p>'.&mt('The following requests were rejected:').'<ul>';
2058: foreach my $uname (@rejections) {
2059: $output .= '<li>'.$uname.'</li>';
2060: }
2061: $output .= '</ul></p>';
2062: }
2063: if ($notifylist ne '') {
2064: &send_selfserve_notification($notifylist,$chgmsg,undef,$domdesc,
2065: $now,'usernamemanagers',$sender,
2066: $approvedlist,$rejectedlist);
2067: }
1.63 raeburn 2068: } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
1.64 raeburn 2069: $chgmsg = "'Action was taken on the following role requests by [_1].',$namelink";
2070: my (%approvals_by_requester,%rejections_by_requester,%for_requester);
2071: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
2072: if (@completed) {
2073: $output .= '<p>'.&mt('The following roles in other domain(s) were assigned for user(s) in this domain:').'<ul>'.
2074: &get_othdombydc_results('approved',\@completed,\%approvals_by_requester,\%requestedby,\%for_requester).
2075: '</ul></p>';
2076: }
2077: if (@rejectedreqs) {
2078: $output .= '<p>'.&mt('The following role assignments in other domain(s) for user(s) in this domain were rejected:').'<ul>'.
2079: &get_othdombydc_results('rejected',\@rejectedreqs,\%rejections_by_requester,\%requestedby,\%for_requester).
2080: '</ul></p>';
2081: }
2082: foreach my $key (sort(keys(%for_requester))) {
2083: if (ref($approvals_by_requester{$key}) eq 'ARRAY') {
2084: if (@{$approvals_by_requester{$key}} > 0) {
2085: $approvedlist = join("\n\n",@{$approvals_by_requester{$key}});
2086: }
2087: }
2088: if (ref($rejections_by_requester{$key}) eq 'ARRAY') {
2089: if (@{$rejections_by_requester{$key}} > 0) {
2090: $rejectedlist = join("\n\n",@{$rejections_by_requester{$key}});
2091: }
2092: }
2093: if (($approvedlist ne '') || ($rejectedlist ne '')) {
2094: &send_selfserve_notification($key,$chgmsg,'',$domdesc,$now,
2095: $context,$sender,$approvedlist,
2096: $rejectedlist);
2097: }
2098: }
1.1 raeburn 2099: } else {
1.12 raeburn 2100: $chgmsg = "'Action was taken on the following course and community requests by [_1].',$namelink";
1.2 raeburn 2101: if (@completed) {
2102: $approvedlist = join("\n",@completed);
1.12 raeburn 2103: $output .= '<p>'.&mt('The following courses/communities were created:').'<ul>';
1.2 raeburn 2104: foreach my $cnum (@completed) {
2105: my $showcourse;
1.23 raeburn 2106: if (ref($requesthash{$cnum.'_'.$queue})) {
2107: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1.2 raeburn 2108: } else {
2109: $showcourse = $cnum;
2110: }
2111: my $syllabuslink =
2112: &Apache::loncommon::syllabuswrapper($showcourse,$cnum,$cdom);
1.40 raeburn 2113: if ($codes{$cnum}) {
1.49 raeburn 2114: $syllabuslink .= ' '.&mt('Unique code: [_1]',$codes{$cnum});
1.39 raeburn 2115: }
1.2 raeburn 2116: $output .= '<li>'.$syllabuslink.'</li>';
2117: }
2118: $output .= '</ul></p>';
2119: }
2120: if (@rejections) {
2121: $rejectedlist = join("\n",@rejections);
2122: $output .= '<p>'.&mt('The following requests were rejected:').'<ul>';
2123: foreach my $cnum (@rejections) {
2124: my $showcourse;
1.23 raeburn 2125: if (ref($requesthash{$cnum.'_'.$queue})) {
2126: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1.2 raeburn 2127: } else {
2128: $showcourse = $cnum;
2129: }
2130: $output .= '<li>'.$showcourse.'</li>';
2131: }
2132: $output .= '</ul></p>';
2133: }
2134: if ($notifylist ne '') {
2135: &send_selfserve_notification($notifylist,$chgmsg,$cid,$domdesc,
2136: $now,'domainmanagers',$sender,
1.12 raeburn 2137: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 2138: }
1.1 raeburn 2139: }
1.43 raeburn 2140: } else {
1.64 raeburn 2141: if (($context eq 'requestauthor') || ($context eq 'requestusername') || ($context eq 'othdombydc')) {
1.43 raeburn 2142: push(@warn_dels,@changes);
2143: }
1.1 raeburn 2144: }
2145: }
2146: if (@existing) {
2147: if ($context eq 'course') {
2148: $output .= '<p>'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'<ul>';
2149: foreach my $user (@existing) {
2150: $output .= '<li>'.$user.'</li>';
2151: }
2152: $output .= '</ul></p>';
1.30 raeburn 2153: } elsif ($context eq 'requestauthor') {
1.42 bisitz 2154: $output .= '<p>'.&mt('Authoring Space requests from the following users were deleted because one already exists:').'<ul>';
1.30 raeburn 2155: foreach my $uname (@existing) {
2156: my $userlink =
2157: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
2158: $output .= '<li>'.$userlink.'</li>';
2159: }
2160: $output .= '</ul></p>';
1.1 raeburn 2161: } else {
1.12 raeburn 2162: $output .= '<p>'.&mt('The following course/community creation requests were deleted because the course or community has already been created:').'<ul>';
1.2 raeburn 2163: foreach my $cnum (@existing) {
2164: my $showcourse;
2165: my %coursehash = &Apache::lonnet::coursedescription($cdom.'/'.$cnum);
2166: if ($coursehash{'description'} ne '') {
2167: $showcourse = $coursehash{'description'};
2168: } else {
2169: $showcourse = $cnum;
2170: }
2171: $output .= '<li>'.$showcourse.'</li>';
2172: }
2173: $output .= '</ul></p>';
1.1 raeburn 2174: }
2175: }
2176: if (@missingreq) {
2177: if ($context eq 'course') {
2178: $output .= '<p>'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'<ul>';
2179: foreach my $user (@missingreq) {
2180: $output .= '<li>'.$user.'</li>';
2181: }
2182: $output .= '</ul></p>';
1.30 raeburn 2183: } elsif ($context eq 'requestauthor') {
2184: $output .= '<p>'.&mt('The following requests were ignored because the request is no longer in the queue:').'<ul>';
2185: foreach my $uname (@missingreq) {
2186: my $userlink =
2187: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
2188: $output .= '<li>'.$userlink.'</li>';
2189: }
2190: $output .= '</ul></p>';
1.2 raeburn 2191: } else {
1.12 raeburn 2192: $output .= '<p>'.&mt('The following course/community creation requests were ignored because the request is no longer in the queue:').'<ul>';
1.2 raeburn 2193: foreach my $cnum (@missingreq) {
2194: $output .= '<li>'.$cnum.'</li>';
2195: }
2196: $output .= '</ul></p>';
1.1 raeburn 2197: }
2198: }
2199: if (@invalidusers) {
2200: if ($context eq 'course') {
2201: $output .= '<p>'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';
2202: foreach my $user (@invalidusers) {
2203: $output .= '<li>'.$user.'</li>';
2204: }
2205: $output .= '</ul></p>';
1.30 raeburn 2206: } elsif ($context eq 'requestauthor') {
1.42 bisitz 2207: $output .= '<p>'.&mt('The following Authoring Space requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';
1.30 raeburn 2208: foreach my $uname (@invalidusers) {
2209: my $userlink =
2210: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
2211: $output .= '<li>'.$userlink.'</li>';
2212: }
2213: $output .= '</ul></p>';
1.1 raeburn 2214: }
2215: }
2216: if (@limitexceeded) {
2217: if ($context eq 'course') {
2218: $output .= '<p>'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'<ul>';
2219: foreach my $user (@limitexceeded) {
2220: $output .= '<li>'.$user.'</li>';
2221: }
2222: $output .= '</ul></p>';
2223: }
2224: }
1.5 raeburn 2225: if (@nopermissions) {
1.30 raeburn 2226: if ($context eq 'course') {
2227: $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>';
2228: foreach my $cnum (@nopermissions) {
2229: my $showcourse;
2230: if (ref($requesthash{$cnum.'_'.$queue})) {
2231: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
2232: } else {
2233: $showcourse = $cnum;
2234: }
2235: $output .= '<li>'.$showcourse.'</li>';
2236: }
2237: $output .= '</ul></p>';
2238: } elsif ($context eq 'requestauthor') {
1.42 bisitz 2239: $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 2240: foreach my $uname (@nopermissions) {
2241: my $userlink =
2242: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
2243: $output .= '<li>'.$userlink.'</li>';
1.5 raeburn 2244: }
1.30 raeburn 2245: $output .= '</ul></p>';
1.5 raeburn 2246: }
2247: }
1.2 raeburn 2248: if (@processing_errors) {
1.1 raeburn 2249: if ($context eq 'course') {
2250: $output .= '<p>'.&mt('The following enrollment requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 2251: foreach my $user (@processing_errors) {
1.1 raeburn 2252: $output .= '<li>'.$user.'</li>';
2253: }
2254: $output .= '</ul></p>';
1.30 raeburn 2255: } elsif ($context eq 'requestauthor') {
2256: $output .= '<p>'.&mt('The following requests could not be processed because an error occurred:').'<ul>';
2257: foreach my $uname (@processing_errors) {
2258: my $userlink =
2259: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
2260: $output .= '<li>'.$userlink.'</li>';
2261: }
2262: $output .= '</ul></p>';
1.43 raeburn 2263: } elsif ($context eq 'requestusername') {
2264: $output .= '<p>'.&mt('The following requests could not be processed because an error occurred:').'<ul>';
2265: foreach my $uname (@processing_errors) {
2266: $output .= '<li>'.$uname.'</li>';
2267: }
2268: $output .= '</ul></p>';
1.1 raeburn 2269: } else {
1.12 raeburn 2270: $output .= '<p>'.&mt('The following course/community creation requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 2271: foreach my $cnum (@processing_errors) {
2272: my $showcourse;
1.23 raeburn 2273: if (ref($requesthash{$cnum.'_'.$queue})) {
2274: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1.2 raeburn 2275: } else {
2276: $showcourse = $cnum;
2277: }
2278: $output .= '<li>'.$showcourse.'</li>';
2279: }
2280: $output .= '</ul></p>';
1.1 raeburn 2281: }
2282: }
1.3 raeburn 2283: if (@rejectionerrors) {
1.12 raeburn 2284: $output .= '<p>'.&mt('The following course/community creation request rejections could not be fully processed because an error occurred:').'<ul>';
1.3 raeburn 2285: foreach my $cnum (@rejectionerrors) {
2286: my $showcourse;
1.23 raeburn 2287: if (ref($requesthash{$cnum.'_'.$queue})) {
2288: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1.3 raeburn 2289: } else {
2290: $showcourse = $cnum;
2291: }
2292: $output .= '<li>'.$showcourse.'</li>';
2293: }
2294: $output .= '</ul></p>';
2295: }
1.2 raeburn 2296: if (@warn_approves || @warn_rejects) {
1.1 raeburn 2297: if ($context eq 'course') {
2298: $output .= '<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>';
2299: foreach my $user (@warn_approves) {
2300: $output .= '<li>'.$user.'</li>';
2301: }
2302: $output .= '</ul></p>';
1.30 raeburn 2303: } elsif ($context eq 'requestauthor') {
2304: $output .= '<p>'.&mt("For the following users, an error occurred when updating the user's own author request record:").'<ul>';
2305: foreach my $uname (@warn_approves,@warn_rejects) {
2306: my $userlink =
2307: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
2308: $output .= '<li>'.$userlink.'</li>';
2309: }
2310: $output .= '</ul></p>';
1.43 raeburn 2311: } elsif ($context eq 'requestusername') {
2312: $output .= '<p>'.&mt("For the following users, an error occurred when updating the account request record for the user:").'<ul>';
2313: foreach my $uname (@warn_approves,@warn_rejects) {
2314: $output .= '<li>'.$uname.'</li>';
2315: }
2316: $output .= '</ul></p>';
1.64 raeburn 2317: } elsif ($context eq 'othdombydc') {
2318:
1.1 raeburn 2319: } else {
1.12 raeburn 2320: $output .= '<p>'.&mt("For the following course/community requests an error occurred when updating the requestor's own requests record:").'<ul>';
1.2 raeburn 2321: foreach my $cnum (@warn_approves,@warn_rejects) {
2322: my $showcourse;
1.23 raeburn 2323: if (ref($requesthash{$cnum.'_'.$queue})) {
2324: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
1.2 raeburn 2325: } else {
2326: $showcourse = $cnum;
2327: }
2328: $output .= '<li>'.$showcourse.'</li>';
1.1 raeburn 2329: }
2330: $output .= '</ul></p>';
2331: }
2332: }
1.19 raeburn 2333: if (@warn_dels) {
1.30 raeburn 2334: if ($context eq 'requestauthor') {
2335: $output .= '<p>'.&mt("For the following requests an error occurred when removing the request from the queue:").'<ul>';
2336: foreach my $uname (@warn_dels) {
2337: my $userlink =
2338: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
2339: $output .= '<li>'.$userlink.'</li>';
2340: }
2341: $output .= '</ul></p>';
1.43 raeburn 2342: } elsif ($context eq 'requestusername') {
2343: $output .= '<p>'.&mt("For the following requests an error occurred when removing the request from the queue:").'<ul>';
2344: foreach my $item (@warn_dels) {
2345: my ($escuname) = split(/_/,$item);
2346: $output .= '<li>'.&unescape($escuname).'</li>';
2347: }
1.64 raeburn 2348: $output .= '</ul></p>';
2349: } elsif ($context eq 'othdombydc') {
2350: $output .= '<p>'.
2351: &mt("For the following queued role assignments an error occurred when removing the item from the queue:").
2352: '<ul>'.&get_othdombydc_results('dequeue_error',\@warn_dels).'</ul>'.
2353: '</p>';
1.30 raeburn 2354: } else {
1.36 bisitz 2355: $output .= '<p>'.&mt("For the following course/community requests an error occurred when removing requests from the pending queue:").'<ul>';
1.30 raeburn 2356: foreach my $cnum (@warn_dels) {
2357: my $showcourse;
2358: if (ref($requesthash{$cnum.'_'.$queue})) {
2359: $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
2360: } else {
2361: $showcourse = $cnum;
2362: }
2363: $output .= '<li>'.$showcourse.'</li>';
1.19 raeburn 2364: }
1.30 raeburn 2365: $output .= '</ul></p>';
1.19 raeburn 2366: }
2367: }
1.1 raeburn 2368: return $output;
2369: }
2370:
1.64 raeburn 2371: sub get_othdombydc_results {
2372: my ($action,$items,$results,$requestedby,$for_requester) = @_;
2373: return unless (ref($items) eq 'ARRAY');
2374: unless ($action eq 'dequeue_error') {
2375: return unless ((ref($results) eq 'HASH') && (ref($requestedby) eq 'HASH') &&
2376: (ref($for_requester) eq 'HASH'));
2377: }
2378: my $output;
2379: foreach my $item (@{$items}) {
2380: my ($extent,$role,$uname,$udom);
2381: if ($action eq 'approved') {
2382: (my $num,$extent,$role,$uname,$udom) = split(/:/,$item);
2383: } elsif ($action eq 'rejected') {
2384: ($extent,$role,$uname,$udom) = split(/:/,$item);
2385: } elsif ($action eq 'dequeue_error') {
2386: (my $oldstatus,$uname,$extent,$role) = split(/:/,$item);
2387: $udom = $env{'request.role.domain'};
2388: }
2389: my @text = (&mt('User: [_1]',$uname));
2390: if (($role eq 'ca') || ($role eq 'aa')) {
2391: my $plainrole = &Apache::lonnet::plaintext($role);
2392: my ($audom,$auname) = ($extent =~ m{^/($match_domain)/($match_username)$});
2393: my $title = &Apache::loncommon::plainname($auname,$audom);
2394: push(@text,(&mt('Role: [_1]',$plainrole),
2395: &mt('Domain: [_1]',&Apache::lonnet::domain($audom)),
2396: &mt('Authoring Space belonging to: [_1]',$title)));
2397: } elsif ($extent =~ m{^/($match_domain)/$}) {
2398: my $domain = $1;
2399: my $plainrole = &Apache::lonnet::plaintext($role);
2400: if (&Apache::lonnet::domain($domain) ne '') {
2401: push(@text,(&mt('Role: [_1]',$plainrole),
2402: &mt('Domain: [_1]',&Apache::lonnet::domain($domain))));
2403: }
2404: } else {
2405: my ($crsdom,$crsnum,$csec) = ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/([^/]+)$)});
2406: if (($crsdom ne '') && ($crsnum ne '')) {
2407: my %info = &Apache::lonnet::coursedescription("$crsdom/$crsnum");
2408: my $plainrole = &Apache::lonnet::plaintext($role,$info{'type'});
2409: push(@text,(&mt('Role: [_1]',$plainrole),
2410: &mt('Domain: [_1]',&Apache::lonnet::domain($crsdom)),
2411: &mt("$info{'type'}: [_1]",$info{'description'})));
2412: if ($csec ne '') {
2413: push(@text,&mt('Section: [_1]',$csec));
2414: }
2415: }
2416: }
2417: $output .= '<li><ul><li>'.join('</li><li>',@text).'</li></ul></li>';
2418: unless ($action eq 'dequeue_error') {
2419: push(@{$results->{$requestedby->{$item}}},join("\n",@text));
2420: $for_requester->{$requestedby->{$item}} = 1;
2421: }
2422: }
2423: return $output;
2424: }
2425:
1.63 raeburn 2426: sub requester_roles {
2427: my ($requname,$requdom,$activeroles) = @_;
2428: if (ref($activeroles) eq 'HASH') {
2429: my %roleshash = &Apache::lonnet::get_my_roles($requname,$requdom,'userroles');
2430: $activeroles->{$requname.':'.$requdom} = \%roleshash;
2431: }
2432: return;
2433: }
2434:
2435: sub requester_has_perm {
2436: my ($crsdom,$crsnum,$mrole,$requesterroles) = @_;
2437: return unless (ref($requesterroles) eq 'HASH');
2438: my $has_perm;
2439: foreach my $key (keys(%{$requesterroles})) {
2440: if ($crsnum eq '') {
2441: next unless ($key =~ /^\Q:$crsdom:\E/);
2442: } else {
2443: next unless (($key =~ /^\Q$crsnum:$crsdom:\E/) || ($key =~ /^\Q:$crsdom:\E/));
2444: }
2445: my ($keycrs,$keydom,$keyrole) = split(/:/,$key);
2446: if (($keycrs ne '') && ($crsnum ne '')) {
2447: if ($keycrs eq $crsnum) {
2448: if ($Apache::lonnet::pr{$keyrole.':c'} =~ /(^|:)c\Q$mrole\E(&|:)/) {
2449: $has_perm = 1;
2450: last;
2451: }
2452: }
2453: } else {
2454: if ($Apache::lonnet::pr{$keyrole.':d'} =~ /(^|:)c\Q$mrole\E(&|:)/) {
2455: $has_perm = 1;
2456: last;
2457: }
2458: }
2459: }
2460: return $has_perm;
2461: }
2462:
1.1 raeburn 2463: sub get_student_counts {
2464: my ($cdom,$cnum) = @_;
2465: my (%idx,%stucounts);
2466: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
2467: $idx{'type'} = &Apache::loncoursedata::CL_TYPE();
2468: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
2469: while (my ($student,$data) = each(%$classlist)) {
2470: if (($data->[$idx{'status'}] eq 'Active') ||
2471: ($data->[$idx{'status'}] eq 'Future')) {
2472: if ($data->[$idx{'type'}] eq 'selfenroll') {
2473: $stucounts{'selfenroll'} ++;
2474: }
2475: $stucounts{'allstudents'} ++;
2476: }
2477: }
2478: return (\%stucounts,\%idx,$classlist);
2479: }
2480:
1.2 raeburn 2481: sub course_creation {
1.59 raeburn 2482: my ($dom,$cnum,$context,$details,$logmsg,$clonemsg,$newusermsg,$addresult,
2483: $enrollcount,$output,$keysmsg,$domdefs,$longroles,$coderef,$customhash,
2484: $callercontext,$user_lh) = @_;
1.2 raeburn 2485: unless ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH') &&
2486: (ref($longroles) eq 'HASH')) {
1.53 raeburn 2487: return ('error: Invalid request');
1.2 raeburn 2488: }
2489: my ($result,$ownername,$ownerdom);
2490: my $crstype = $details->{'crstype'};
1.41 raeburn 2491: my $coursedesc = $details->{'cdescr'};
1.47 raeburn 2492: my $accessstart = $details->{'accessstart'};
2493: my $accessend = $details->{'accessend'};
2494: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.40 raeburn 2495: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2496: if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
2497: if ($domconfig{'requestcourses'}{'uniquecode'}{$crstype}) {
2498: $details->{'uniquecode'} = 1;
2499: }
2500: }
2501: }
1.2 raeburn 2502: if ($context eq 'domain') {
2503: $ownername = $details->{'owner'};
2504: $ownerdom = $details->{'domain'};
2505: } else {
2506: $ownername = $env{'user.name'};
2507: $ownerdom = $env{'user.domain'};
2508: }
1.41 raeburn 2509: my $fullname = &Apache::loncommon::plainname($ownername,$ownerdom);
1.2 raeburn 2510: my $owneremail;
2511: my %emails = &Apache::loncommon::getemails($ownername,$ownerdom);
2512: foreach my $email ('permanentemail','critnotification','notification') {
2513: $owneremail = $emails{$email};
2514: last if ($owneremail ne '');
2515: }
1.61 raeburn 2516: my %reqdetails = &build_batchcreatehash($dom,$cnum,$context,$details,$owneremail,$domdefs);
1.2 raeburn 2517: my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',
1.59 raeburn 2518: \%reqdetails,$longroles,$logmsg,$clonemsg,$newusermsg,$addresult,
2519: $enrollcount,$output,$keysmsg,$ownerdom,$ownername,$cnum,$crstype,
2520: $coderef,$callercontext,$user_lh);
1.41 raeburn 2521: my $postprocess;
1.2 raeburn 2522: if ($cid eq "/$dom/$cnum") {
2523: $result = 'created';
1.41 raeburn 2524: my $code;
2525: if (ref($coderef)) {
2526: $code = $$coderef;
2527: }
2528: $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,$result,$ownername,
1.47 raeburn 2529: $ownerdom,$fullname,$coursedesc,$code,
2530: $accessstart,$accessend,$customhash);
1.2 raeburn 2531: } else {
2532: $result = 'error: '.$cid;
2533: }
1.41 raeburn 2534: return ($result,$postprocess);
1.2 raeburn 2535: }
2536:
2537: sub build_batchcreatehash {
1.61 raeburn 2538: my ($dom,$cnum,$context,$details,$owneremail,$domdefs) = @_;
1.2 raeburn 2539: my %batchhash;
1.60 raeburn 2540: my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift tinyurls enrollstart enrollend accessstart accessend sections users uniquecode};
1.2 raeburn 2541: if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
1.17 raeburn 2542: my $emailenc = &escape($owneremail);
1.2 raeburn 2543: my $owner = $details->{'owner'}.':'.$details->{'domain'};
2544: foreach my $item (@items) {
2545: $batchhash{$item} = $details->{$item};
2546: }
1.60 raeburn 2547: if (ref($details->{'crosslists'}) eq 'HASH') {
2548: foreach my $key (keys(%{$details->{'crosslists'}})) {
2549: if (ref($details->{'crosslists'}->{$key}) eq 'HASH') {
1.61 raeburn 2550: my $instsec = $details->{crosslists}->{$key}->{instsec};
2551: $batchhash{'crosslists'}{$key}{'inst'} = $details->{crosslists}->{$key}->{instcode};
2552: my $crskey = $cnum.':'.$batchhash{'crosslists'}{$key}{'inst'};
2553: my %formatted = &Apache::lonnet::auto_instsec_reformat($dom,'clutter',
2554: {$crskey => [$instsec]});
2555: if (ref($formatted{$crskey}) eq 'ARRAY') {
2556: $batchhash{'crosslists'}{$key}{'inst'} .= $formatted{$crskey}->[0];
2557: }
1.60 raeburn 2558: $batchhash{'crosslists'}{$key}{'loncapa'} = $details->{crosslists}->{$key}->{loncapa};
2559: }
2560: }
2561: }
1.2 raeburn 2562: $batchhash{'title'} = $details->{'cdescr'};
2563: $batchhash{'coursecode'} = $details->{'instcode'};
1.35 raeburn 2564: if ($domdefs->{'officialcredits'} || $domdefs->{'unofficialcredits'}) {
2565: $batchhash{'defaultcredits'} = $details->{'defaultcredits'};
2566: }
1.2 raeburn 2567: $batchhash{'emailenc'} = $emailenc;
2568: $batchhash{'adds'} = $details->{'autoadds'};
2569: $batchhash{'drops'} = $details->{'autodrops'};
2570: $batchhash{'authtype'} = $domdefs->{'auth_def'};
2571: $batchhash{'authparam'} = $domdefs->{'auth_arg_def'};
2572: if ($details->{'crstype'} eq 'community') {
2573: $batchhash{'crstype'} = 'Community';
1.53 raeburn 2574: } elsif ($details->{'crstype'} eq 'placement') {
2575: $batchhash{'crstype'} = 'Placement';
1.2 raeburn 2576: } else {
1.41 raeburn 2577: if ($details->{'crstype'} eq 'textbook') {
2578: if ($details->{'clonecrs'} && $details->{'clonedom'}) {
2579: my %clonedfrom = &Apache::lonnet::coursedescription($details->{'clonedom'}.'_'.$details->{'clonecrs'});
2580: $batchhash{'textbook'} = $clonedfrom{'description'};
2581: }
1.62 raeburn 2582: } elsif ($details->{'crstype'} eq 'lti') {
2583: $batchhash{'lti'} = 1;
1.41 raeburn 2584: }
1.2 raeburn 2585: $batchhash{'crstype'} = 'Course';
2586: }
1.8 raeburn 2587: my ($owner_firstname,$owner_lastname);
2588: if ($context eq 'domain') {
2589: my %userenv = &Apache::lonnet::userenvironment($details->{'domain'},
2590: $details->{'owner'},
2591: 'firstname','lastname');
2592: $owner_firstname = $userenv{'firstname'};
2593: $owner_lastname = $userenv{'lastname'};
2594: } else {
2595: $owner_firstname = $env{'environment.firstname'};
2596: $owner_lastname = $env{'environment.lastname'};
2597: }
2598: if (ref($details->{'personnel'}) eq 'HASH') {
2599: %{$batchhash{'users'}} = %{$details->{'personnel'}};
2600: if (ref($batchhash{'users'}) eq 'HASH') {
2601: foreach my $userkey (keys(%{$batchhash{'users'}})) {
2602: if (ref($batchhash{'users'}{$userkey}) eq 'HASH') {
2603: if (ref($batchhash{'users'}{$userkey}{'roles'}) eq 'ARRAY') {
2604: foreach my $role (@{$batchhash{'users'}{$userkey}{'roles'}}) {
2605: my $start = '';
2606: my $end = '';
2607: if ($role eq 'st') {
2608: $start = $details->{'accessstart'};
2609: $end = $details->{'accessend'};
2610: }
2611: $batchhash{'users'}{$userkey}{$role}{'start'} = $start;
2612: $batchhash{'users'}{$userkey}{$role}{'end'} = $end;
2613: }
2614: }
2615: }
2616: }
2617: }
2618: }
2619: $batchhash{'users'}{$owner}{firstname} = $owner_firstname;
2620: $batchhash{'users'}{$owner}{lastname} = $owner_lastname;
2621: $batchhash{'users'}{$owner}{emailenc} = $emailenc;
2622: $batchhash{'users'}{$owner}{owneremail} = $owneremail;
1.55 raeburn 2623: $batchhash{'setcomment'} = 1;
1.2 raeburn 2624: }
2625: return %batchhash;
2626: }
2627:
1.4 raeburn 2628: sub can_clone_course {
1.51 raeburn 2629: my ($uname,$udom,$clonecrs,$clonedom,$crstype,$dom,$instcode) = @_;
1.4 raeburn 2630: my $canclone;
1.11 raeburn 2631: my $ccrole = 'cc';
1.12 raeburn 2632: if ($crstype eq 'community') {
1.11 raeburn 2633: $ccrole = 'co';
2634: }
1.4 raeburn 2635: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',['active'],
1.11 raeburn 2636: [$ccrole],[$clonedom]);
2637: if (exists($roleshash{$clonecrs.':'.$clonedom.':'.$ccrole})) {
1.4 raeburn 2638: $canclone = 1;
2639: } else {
1.51 raeburn 2640: my %courseenv = &Apache::lonnet::userenvironment($clonedom,$clonecrs,
2641: ('cloners','internal.coursecode'));
1.4 raeburn 2642: my $cloners = $courseenv{'cloners'};
1.51 raeburn 2643: my $clonefromcode = $courseenv{'internal.coursecode'};
1.4 raeburn 2644: if ($cloners ne '') {
2645: my @cloneable = split(',',$cloners);
2646: if (grep(/^\*$/,@cloneable)) {
2647: $canclone = 1;
1.51 raeburn 2648: } elsif (grep(/^\*:\Q$udom\E$/,@cloneable)) {
2649: $canclone = 1;
2650: } elsif (grep(/^\Q$uname\E:\Q$udom\E$/,@cloneable)) {
2651: $canclone = 1;
1.4 raeburn 2652: }
1.51 raeburn 2653: unless ($canclone) {
2654: if (($clonefromcode) && ($instcode) && ($clonedom eq $dom)) {
2655: my (%gotdomdefaults,%gotcodedefaults);
2656: foreach my $cloner (@cloneable) {
2657: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
2658: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
2659: if ($cloner =~ /\=/) {
2660: my (%codedefaults,@code_order);
2661: if (ref($gotcodedefaults{$clonedom}) eq 'HASH') {
2662: if (ref($gotcodedefaults{$clonedom}{'defaults'}) eq 'HASH') {
2663: %codedefaults = %{$gotcodedefaults{$clonedom}{'defaults'}};
2664: }
2665: if (ref($gotcodedefaults{$clonedom}{'order'}) eq 'ARRAY') {
2666: @code_order = @{$gotcodedefaults{$dom}{'order'}};
2667: }
2668: } else {
2669: &Apache::lonnet::auto_instcode_defaults($clonedom,
2670: \%codedefaults,
2671: \@code_order);
2672: $gotcodedefaults{$clonedom}{'defaults'} = \%codedefaults;
2673: $gotcodedefaults{$clonedom}{'order'} = \@code_order;
2674: }
2675: if (@code_order > 0) {
2676: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
2677: $cloner,$clonefromcode,$instcode)) {
2678: $canclone = 1;
2679: last;
2680: }
2681: }
2682: }
2683: }
2684: }
2685: }
1.4 raeburn 2686: }
1.51 raeburn 2687: } else {
2688: my %domdefs = &Apache::lonnet::get_domain_defaults($clonedom);
2689: if ($domdefs{'canclone'}) {
2690: unless ($domdefs{'canclone'} eq 'none') {
2691: if ($domdefs{'canclone'} eq 'domain') {
2692: if ($udom eq $clonedom) {
2693: $canclone = 1;
2694: }
2695: } elsif (($clonefromcode) && ($instcode) &&
2696: ($clonedom eq $dom)) {
2697: if (&Apache::lonnet::default_instcode_cloning($clonedom,$domdefs{'canclone'},
2698: $clonefromcode,$instcode)) {
2699: $canclone = 1;
2700: }
2701: }
2702: }
1.4 raeburn 2703: }
2704: }
1.18 raeburn 2705: unless ($canclone) {
2706: if (&Apache::lonnet::is_course_owner($clonedom,$clonecrs,$uname,$udom)) {
1.20 bisitz 2707: $canclone = 1;
1.18 raeburn 2708: }
2709: }
1.4 raeburn 2710: }
2711: return $canclone;
2712: }
2713:
1.13 raeburn 2714: sub get_processtype {
1.30 raeburn 2715: my ($context,$uname,$udom,$isadv,$dom,$crstype,$inststatuses,$domconfig) = @_;
1.13 raeburn 2716: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
2717: if ($uname eq '' || $udom eq '') {
2718: $uname = $env{'user.name'};
2719: $udom = $env{'user.domain'};
2720: $isadv = $env{'user.adv'};
2721: }
1.30 raeburn 2722: my (%userenv,%settings,$val,@options,$envkey);
2723: if ($context eq 'course') {
2724: @options = ('autolimit','validate','approval');
2725: $envkey = 'requestcourses.'.$crstype;
2726: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
2727: if (ref($domconfig->{'requestcourses'}->{$crstype}) eq 'HASH') {
2728: %settings = %{$domconfig->{'requestcourses'}->{$crstype}};
2729: }
2730: }
2731: } else {
2732: @options = ('automatic','approval');
2733: $envkey = 'requestauthor';
2734: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
2735: %settings = %{$domconfig->{'requestauthor'}};
2736: }
2737: }
2738: if (($dom eq $udom) || ($context eq 'requestauthor')) {
1.13 raeburn 2739: %userenv =
1.30 raeburn 2740: &Apache::lonnet::userenvironment($udom,$uname,$envkey,'inststatus');
2741: if ($userenv{$envkey}) {
2742: $val = $userenv{$envkey};
1.13 raeburn 2743: @{$inststatuses} = ('_custom_');
2744: } else {
1.30 raeburn 2745: my %alltasks;
2746: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
1.33 raeburn 2747: $val = $settings{'_LC_adv'};
1.30 raeburn 2748: @{$inststatuses} = ('_LC_adv_');
2749: } else {
2750: if ($userenv{'inststatus'} ne '') {
2751: @{$inststatuses} = split(',',$userenv{'inststatus'});
2752: } else {
2753: @{$inststatuses} = ('default');
2754: }
2755: foreach my $status (@{$inststatuses}) {
2756: if (exists($settings{$status})) {
2757: my $value = $settings{$status};
2758: next unless ($value);
2759: unless (exists($alltasks{$value})) {
2760: if (ref($alltasks{$value}) eq 'ARRAY') {
2761: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
2762: push(@{$alltasks{$value}},$status);
1.13 raeburn 2763: }
1.30 raeburn 2764: } else {
2765: @{$alltasks{$value}} = ($status);
1.13 raeburn 2766: }
2767: }
1.30 raeburn 2768: }
2769: }
2770: my $maxlimit = 0;
2771: if ($context eq 'course') {
2772: foreach my $key (sort(keys(%alltasks))) {
2773: if ($key =~ /^autolimit=(\d*)$/) {
2774: if ($1 eq '') {
2775: $val ='autolimit=';
2776: last;
2777: } elsif ($1 > $maxlimit) {
2778: $maxlimit = $1;
1.13 raeburn 2779: }
2780: }
1.30 raeburn 2781: }
2782: }
2783: if (($context eq 'requestauthor') || (!$val)) {
2784: if ($context eq 'course' && $maxlimit) {
2785: $val = 'autolimit='.$maxlimit;
2786: } else {
2787: foreach my $option (@options) {
2788: if ($alltasks{$option}) {
2789: $val = $option;
2790: last;
1.13 raeburn 2791: }
2792: }
2793: }
2794: }
2795: }
2796: }
2797: } else {
2798: %userenv = &Apache::lonnet::userenvironment($udom,$uname,'reqcrsotherdom.'.$crstype);
2799: if ($userenv{'reqcrsotherdom.'.$crstype}) {
2800: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
2801: my $optregex = join('|',@options);
2802: foreach my $item (@doms) {
2803: my ($extdom,$extopt) = split(':',$item);
2804: if ($extdom eq $dom) {
2805: if ($extopt =~ /^($optregex)(=?\d*)$/) {
2806: $val = $1.$2;
2807: }
2808: last;
2809: }
2810: }
2811: @{$inststatuses} = ('_external_');
2812: }
2813: }
2814: return $val;
2815: }
2816:
1.14 raeburn 2817: sub queued_selfenrollment {
2818: my ($notitle) = @_;
2819: my $output;
2820: my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests');
2821: my %reqs_by_date;
2822: foreach my $item (keys(%selfenrollrequests)) {
2823: if (ref($selfenrollrequests{$item}) eq 'HASH') {
2824: if ($selfenrollrequests{$item}{'status'} eq 'request') {
2825: if ($selfenrollrequests{$item}{'timestamp'}) {
2826: push(@{$reqs_by_date{$selfenrollrequests{$item}{'timestamp'}}},$item);
2827: }
2828: }
2829: }
2830: }
2831: if (keys(%reqs_by_date)) {
2832: unless ($notitle) {
1.32 raeburn 2833: $output .= '<br /><b>'.&mt('Enrollment requests pending Course Coordinator approval').'</b><br />';
1.14 raeburn 2834: }
2835: $output .= &Apache::loncommon::start_data_table().
2836: &Apache::loncommon::start_data_table_header_row().
2837: '<th>'.&mt('Date requested').'</th><th>'.&mt('Course title').'</th>'.
2838: '<th>'.&mt('User role').'</th><th>'.&mt('Section').'</th>'.
2839: &Apache::loncommon::end_data_table_header_row();
2840: my @sorted = sort { $a <=> $b } (keys(%reqs_by_date));
2841: foreach my $item (@sorted) {
2842: if (ref($reqs_by_date{$item}) eq 'ARRAY') {
2843: foreach my $crs (@{$reqs_by_date{$item}}) {
2844: my %courseinfo = &Apache::lonnet::coursedescription($crs);
2845: my $usec = $selfenrollrequests{$crs}{'section'};
1.16 raeburn 2846: my $rolename = &Apache::lonnet::plaintext('st',$courseinfo{'type'},$crs);
1.14 raeburn 2847: if ($usec eq '') {
2848: $usec = &mt('No section');
2849: }
2850: $output .= &Apache::loncommon::start_data_table_row().
2851: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
2852: '<td>'.$courseinfo{'description'}.'</td>'.
2853: '<td>'.$rolename.'</td><td>'.$usec.'</td>'.
2854: &Apache::loncommon::end_data_table_row();
2855: }
2856: }
2857: }
2858: $output .= &Apache::loncommon::end_data_table();
2859: }
2860: return $output;
2861: }
2862:
1.19 raeburn 2863: sub update_coursereq_status {
1.26 raeburn 2864: my ($reqhash,$dom,$cnum,$reqstatus,$context,$udom,$uname) = @_;
1.19 raeburn 2865: my ($storeresult,$statusresult,$output);
2866: my $requestkey = $dom.'_'.$cnum;
2867: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2868: $storeresult = &Apache::lonnet::store_userdata($reqhash,$requestkey,
1.26 raeburn 2869: 'courserequests',$udom,$uname);
1.19 raeburn 2870: if ($storeresult eq 'ok') {
2871: my %status = (
2872: 'status:'.$dom.':'.$cnum => $reqstatus,
2873: );
1.26 raeburn 2874: $statusresult = &Apache::lonnet::put('courserequests',\%status,$udom,$uname);
1.19 raeburn 2875: }
2876: } else {
2877: $storeresult = 'error: invalid requestkey format';
2878: }
2879: if ($storeresult ne 'ok') {
2880: $output = &mt('An error occurred saving a record of the details of your request: [_1].',$storeresult);
2881: if ($context eq 'domain') {
2882: $output .= "\n";
2883: } else {
2884: $output = '<span class="LC_warning">'.$output.'</span><br />';
2885: }
1.26 raeburn 2886: &Apache::lonnet::logthis("Error saving course request - $requestkey for $uname:$udom - $storeresult");
1.19 raeburn 2887: } elsif ($statusresult ne 'ok') {
2888: $output = &mt('An error occurred saving a record of the status of your request: [_1].',$statusresult);
2889: if ($context eq 'domain') {
2890: $output .= "\n";
2891: } else {
2892: $output = '<span class="LC_warning">'.$output.'</span><br />';
2893: }
1.26 raeburn 2894: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $uname:$udom) - $statusresult");
1.19 raeburn 2895: }
2896: return ($storeresult,$output);
2897: }
2898:
1.23 raeburn 2899: sub process_official_reqs {
1.26 raeburn 2900: my ($context,$dom,$dcname,$dcdom) = @_;
1.23 raeburn 2901: my $reqsnamespace = 'courserequestqueue';
2902: my %requesthash =
1.24 raeburn 2903: &Apache::lonnet::dump_dom($reqsnamespace,$dom,'_pending');
1.23 raeburn 2904: my (%newcids,%longroles,%stillpending);
2905: my @courseroles = ('cc','in','ta','ep','ad','st');
2906: foreach my $role (@courseroles) {
2907: $longroles{$role}=&Apache::lonnet::plaintext($role);
2908: }
2909: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1.59 raeburn 2910: my ($output,$linefeed,$user_lh);
1.23 raeburn 2911: if ($context eq 'auto') {
2912: $linefeed = "\n";
1.59 raeburn 2913: $user_lh = &Apache::loncommon::user_lang($dcname,$dcdom);
1.23 raeburn 2914: } else {
2915: $linefeed = '<br />'."\n";
2916: }
2917: foreach my $key (keys(%requesthash)) {
2918: my ($cnum,$status) = split('_',$key);
2919: next if (&Apache::lonnet::homeserver($cnum,$dom) ne 'no_host');
2920: if (ref($requesthash{$key}) eq 'HASH') {
2921: my $ownername = $requesthash{$key}{'ownername'};
2922: my $ownerdom = $requesthash{$key}{'ownerdom'};
2923: next if (&Apache::lonnet::homeserver($ownername,$ownerdom) eq 'no_host');
2924: my $inststatus;
2925: my %userenv =
2926: &Apache::lonnet::get('environment',['inststatus'],
2927: $ownerdom,$ownername);
2928: my ($tmp) = keys(%userenv);
2929: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
2930: $inststatus = $userenv{'inststatus'};
2931: } else {
2932: undef(%userenv);
2933: }
2934: my $reqkey = $dom.'_'.$cnum;
2935: my %history = &Apache::lonnet::restore($reqkey,'courserequests',
2936: $ownerdom,$ownername);
2937: if (ref($history{'details'}) eq 'HASH') {
2938: my $instcode = $history{'details'}{'instcode'};
2939: my $crstype = $history{'details'}{'crstype'};
2940: my $reqtime = $history{'details'}{'reqtime'};
2941: my $cdescr = $history{'details'}{'cdescr'};
2942: my @currsec;
2943: my $sections = $history{'details'}{'sections'};
2944: if (ref($sections) eq 'HASH') {
2945: foreach my $i (sort(keys(%{$sections}))) {
2946: if (ref($sections->{$i}) eq 'HASH') {
2947: my $sec = $sections->{$i}{'inst'};
2948: if (!grep(/^\Q$sec\E$/,@currsec)) {
2949: push(@currsec,$sec);
2950: }
2951: }
2952: }
2953: }
2954: my $instseclist = join(',',@currsec);
2955: my ($validationchk,$disposition,$reqstatus,$message,
2956: $validation,$validationerror);
2957: $validationchk =
2958: &Apache::lonnet::auto_courserequest_validation($dom,
2959: $ownername.':'.$ownerdom,$crstype,$inststatus,
2960: $instcode,$instseclist);
2961: if ($validationchk =~ /:/) {
2962: ($validation,$message) = split(':',$validationchk);
2963: } else {
2964: $validation = $validationchk;
2965: }
2966: if ($validation =~ /^error(.*)$/) {
2967: $disposition = 'approval';
2968: $validationerror = $1;
2969: } else {
2970: $disposition = $validation;
2971: }
2972: $reqstatus = $disposition;
2973: if ($disposition eq 'process') {
1.39 raeburn 2974: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,$code);
1.59 raeburn 2975: my $clonemsg = [];
1.41 raeburn 2976: my %customitems;
2977: my $fullname = &Apache::loncommon::plainname($ownername,$ownerdom);
2978: my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$ownername,
2979: $ownerdom,$fullname,$cdescr);
2980: if (ref($inprocess) eq 'HASH') {
2981: foreach my $key (keys(%{$inprocess})) {
2982: if (exists($history{'details'}{$key})) {
2983: $customitems{$key} = $history{'details'}{$key};
2984: }
2985: }
2986: }
1.50 raeburn 2987: if ($history{'details'}{'clonecrs'}) {
2988: $customitems{'_LC_clonefrom'} = $history{'details'}{'clonedom'}.'_'.$history{'details'}{'clonecrs'};
2989: }
1.41 raeburn 2990: my ($result,$postprocess) =
1.59 raeburn 2991: &course_creation($dom,$cnum,'domain',$history{'details'},\$logmsg,$clonemsg,\$newusermsg,
2992: \$addresult,\$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,
2993: \$code,\%customitems,$context,$user_lh);
1.23 raeburn 2994: if ($result eq 'created') {
2995: $disposition = 'created';
2996: $reqstatus = 'created';
1.26 raeburn 2997: my $cid = $dom.'_'.$cnum;
2998: push(@{$newcids{$instcode}},$cid);
2999: if ($dcname && $dcdom) {
1.54 raeburn 3000: my $firsturl = &Apache::lonnet::course_portal_url($cnum,$dom);
1.26 raeburn 3001: my $beneficiary = 'pendingrequestor';
3002: my $now = time;
3003: my $owner = $ownername.':'.$ownerdom;
3004: my $approvedmsg =
3005: [{
1.27 raeburn 3006: mt => 'Your requested course: [_1], (queued pending validation) has now been created.',
3007: args => [$cdescr],
1.59 raeburn 3008: }];
3009: if ((ref($clonemsg) eq 'ARRAY') && (@{$clonemsg})) {
3010: push(@{$approvedmsg},@{$clonemsg});
3011: }
3012: push(@{$approvedmsg},
1.26 raeburn 3013: {
1.28 raeburn 3014: mt => 'Visit [_1] to log-in and access the course.',
1.26 raeburn 3015: args => [$firsturl],
1.27 raeburn 3016: },
3017: {
1.59 raeburn 3018: mt => 'If currently logged-in to LON-CAPA, log-out and log-in again to select your new course role.',
3019: args => [],
3020: }
3021: );
1.26 raeburn 3022: my $sender = $dcname.':'.$dcdom;
1.41 raeburn 3023: if (ref($postprocess) eq 'HASH') {
3024: if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
3025: foreach my $item (@{$postprocess->{'createdmsg'}}) {
3026: if (ref($item) eq 'HASH') {
3027: if ($item->{'mt'} ne '') {
3028: push(@{$approvedmsg},$item);
3029: }
3030: }
3031: }
3032: }
1.48 raeburn 3033: if (ref($postprocess->{'createdactions'}) eq 'HASH') {
3034: if (ref($postprocess->{'createdactions'}{'environment'}) eq 'HASH') {
3035: &postprocess_crsenv($dom,$cnum,$postprocess->{'createdactions'}{'environment'});
3036: }
3037: }
1.41 raeburn 3038: }
1.26 raeburn 3039: &send_selfserve_notification($owner,$approvedmsg,
3040: $cid,$cdescr,$now,
3041: $beneficiary,$sender,
3042: undef,undef,$crstype);
3043: }
1.23 raeburn 3044: }
3045: } elsif ($disposition eq 'rejected') {
3046: $output .= &mt('Queued course request for [_1] submitted by [_2] with status [_3] rejected when validating.',$instcode,$ownername.':'.$ownerdom,$inststatus).$linefeed;
3047: } elsif ($disposition eq 'approval') {
3048: $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;
3049:
3050: my $requestid = $cnum.'_'.$disposition;
3051: my $request = {
3052: $requestid => {
3053: timestamp => $reqtime,
3054: crstype => $crstype,
3055: ownername => $ownername,
3056: ownerdom => $ownerdom,
3057: description => $cdescr,
3058: },
3059: };
3060: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,$dom);
3061: unless ($putresult eq 'ok') {
3062: $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;
3063: }
3064: } elsif ($disposition eq 'pending') {
3065: my $instcode = $requesthash{$key}{'instcode'};
3066: my $description = $requesthash{$key}{'description'};
3067: my $timestamp = $requesthash{$key}{'timestamp'};
3068: my $entry = $cnum.':'.$ownername.':'.$ownerdom.':'.
3069: $instcode.':'.$description;
3070: if (ref($stillpending{$timestamp}) eq 'ARRAY') {
3071: push(@{$stillpending{$timestamp}},$entry);
3072: } else {
3073: $stillpending{$timestamp} = [$entry];
3074: }
3075: }
3076: unless ($disposition eq 'pending') {
3077: my ($statusresult,$output) =
3078: &update_coursereq_status(\%requesthash,$dom,$cnum,
1.26 raeburn 3079: $reqstatus,'domain',$ownerdom,
3080: $ownername);
1.23 raeburn 3081: unless (&Apache::lonnet::del_dom($reqsnamespace,[$cnum.'_pending'],$dom) eq 'ok') {
3082: $output .= &mt('An error occurred when removing the request for [_1] submitted by [_2] from the pending queue.',$instcode,$ownername.':'.$ownerdom).$linefeed;
3083: }
3084: }
3085: }
3086: }
3087: }
3088: foreach my $key (sort(keys(%newcids))) {
3089: if (ref($newcids{$key}) eq 'ARRAY') {
3090: $output .= "created course from queued request: $key - ".join(', ',@{$newcids{$key}}).$linefeed;
3091: my $newcourse = &LONCAPA::escape($key.':'.$newcids{$key});
3092: }
3093: }
3094: unless ($context eq 'auto') {
3095: if (keys(%stillpending) > 0) {
3096: $output .= '<form method="post" name="changequeue" action="/adm/createcourse" />'."\n".
3097: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
3098: '<input type="hidden" name="phase" value="requestchange" />'.
3099: '<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>'.
3100: &build_queue_display($dom,'stillpending',\%stillpending).
3101: '<br /><input type="hidden" name="queue" value="pending" />'."\n".
3102: '<input type="submit" name="processqueue" value="'.&mt('Save').'" />'.
3103: '</form>';
3104: }
3105: }
3106: return $output;
3107: }
3108:
1.48 raeburn 3109: sub postprocess_crsenv {
3110: my ($dom,$cnum,$postprocessenv) = @_;
3111: if (ref($postprocessenv) eq 'HASH') {
3112: my $cid = $dom.'_'.$cnum;
3113: my %settablecrsenv = (
3114: 'internal.selfenroll_types' => 1,
3115: 'internal.selfenroll_registered' => 1,
3116: 'internal.selfenroll_section' => 1,
3117: 'internal.selfenroll_start_access' => 1,
3118: 'internal.selfenroll_end_access' => 1,
3119: 'internal.selfenroll_limit' => 1,
3120: 'internal.selfenroll_cap' => 1,
3121: 'internal.selfenroll_approval' => 1,
3122: 'internal.selfenroll_notifylist' => 1,
3123: );
3124: my %needcrsidput = (
3125: 'internal.selfenroll_types' => 1,
3126: 'internal.selfenroll_start_date' => 1,
3127: 'internal. selfenroll_end_date' => 1,
3128: );
3129: my (@needupdate,%newcrsenv);
3130: foreach my $key (keys(%{$postprocessenv})) {
3131: if ($settablecrsenv{$key}) {
3132: $newcrsenv{$key} = $postprocessenv->{$key};
3133: if ($needcrsidput{$key}) {
3134: push(@needupdate,$key);
3135: }
3136: }
3137: if (keys(%newcrsenv)) {
3138: my $putresult = &Apache::lonnet::put('environment',\%newcrsenv,$dom,$cnum);
3139: if ($putresult eq 'ok') {
3140: if (@needupdate) {
3141: my %crsinfo =
3142: &Apache::lonnet::courseiddump($dom,'.',1,'.','.',$cnum,undef,undef,'.');
3143: if (ref($crsinfo{$cid}) eq 'HASH') {
3144: foreach my $key (@needupdate) {
3145: $crsinfo{$cid}{$key} = $newcrsenv{$key};
3146: }
3147: my $chome = &Apache::lonnet::homeserver($cnum,$dom);
3148: &Apache::lonnet::courseidput($dom,\%crsinfo,$chome,'notime');
3149: }
3150: }
3151: }
3152: }
3153: }
3154: }
3155: return;
3156: }
3157:
3158:
1.45 raeburn 3159: sub requestcourses_validation_types {
3160: my @items = ('url','fields','button','markup');
3161: my %names = &Apache::lonlocal::texthash (
3162: url => 'Web address of validation server/script',
3163: fields => 'Form fields to send to validator',
3164: button => 'Text for validation button',
3165: markup => 'Validation description (HTML)',
3166: );
3167: my @fields = ('owner','course','coursetype','description');
3168: return (\@items,\%names,\@fields);
3169: }
3170:
1.31 raeburn 3171: sub is_active_author {
3172: if ($env{'user.role.au./'.$env{'user.domain'}.'/'} =~ /^(\d*)\.(\d*)$/) {
3173: if ((!$1 || $1 < time) &&
3174: (!$2 || $2 > time)) {
3175: return 1;
3176: }
3177: }
3178: }
3179:
3180: sub author_prompt {
3181: my ($is_active_author,$offer_author);
3182: if ($env{'environment.canrequest.author'}) {
3183: unless (&is_active_author()) {
1.32 raeburn 3184: unless (&reqauthor_check() =~ /^approval:\d+$/) {
3185: $offer_author = 1;
1.31 raeburn 3186: }
3187: }
3188: }
3189: return $offer_author;
3190: }
3191:
3192: sub reqauthor_check {
3193: my $queued = $env{'environment.requestauthorqueued'};
3194: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
3195: $env{'user.domain'},$env{'user.name'});
3196: my $reqstatus = $reqauthor{'author_status'};
3197: if (($reqstatus eq '' && $queued ne '') ||
3198: ($env{'environment.requestauthorqueued'} !~ /^\Q$reqstatus\E/)) {
3199: if (ref($reqauthor{'author'}) eq 'HASH') {
3200: $queued = $reqstatus.':'.$reqauthor{'author'}{'timestamp'};
3201: } else {
3202: undef($queued);
3203: }
3204: &Apache::lonnet::appenv({'environment.requestauthorqueued' => $queued});
3205: }
3206: return $queued;
3207: }
3208:
3209: sub process_reqauthor {
3210: my ($dispositionref,$updateref) = @_;
3211: if (&is_active_author()) {
3212: return '<span class="LC_warning">'.
1.42 bisitz 3213: &mt('An Authoring Space has already been assigned to you.').'<br />'.
1.31 raeburn 3214: &mt('Please select the Author role from your [_1]roles page[_2].','<a href="/adm/roles">',
3215: '</a>').'</span>';
3216: }
3217: unless ($env{'environment.canrequest.author'}) {
3218: return '<span class="LC_warning">'.
1.42 bisitz 3219: &mt('You do not currently have rights to request an Authoring Space.').'<br />'.
1.37 raeburn 3220: &mt('Please contact the [_1]helpdesk[_2] for assistance.','<a href="/adm/helpdesk">',
1.31 raeburn 3221: '</a>').'</span>';
3222: }
3223: my $queued = &reqauthor_check();
3224: if ($queued =~ /^approval:(\d+)$/) {
3225: my $timestamp = $1;
3226: return '<span class="LC_info">'.
1.42 bisitz 3227: &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
1.31 raeburn 3228: &Apache::lonlocal::locallocaltime($timestamp)).
3229: '</span>';
3230: } elsif ($queued =~ /^approved:(\d+)$/) {
3231: my $timestamp = $1;
3232: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
3233: ['active'],['au'],[$env{'user.domain'}]);
3234: if (keys(%roleshash) > 0) {
3235: return '<span class="LC_info">'.
1.42 bisitz 3236: &mt('A request for Authoring Space submitted on [_1] has been approved.',
1.31 raeburn 3237: &Apache::lonlocal::locallocaltime($timestamp)).
3238: '</span>';
3239: }
3240: }
3241: my ($output,@inststatuses,%domconfig);
3242: %domconfig = &Apache::lonnet::get_dom('configuration',['requestauthor'],
3243: $env{'user.domain'});
3244: my $val = &get_processtype('requestauthor',$env{'user.name'},$env{'user.domain'},
3245: $env{'user.adv'},$env{'user.domain'},undef,
3246: \@inststatuses,\%domconfig);
3247: my $now = time;
3248: if ($val eq 'automatic') {
3249: my $start = $now-1;
3250: if (&Apache::lonnet::assignrole($env{'user.domain'},$env{'user.name'},'/'.$env{'user.domain'}.'/',
3251: 'au',undef,$start,undef,undef,'requestauthor') eq 'ok') {
3252: $output = '<span class="LC_info">'.
1.42 bisitz 3253: &mt('Access to Authoring Space has been activated').'</span><br />';
1.31 raeburn 3254: &Apache::lonroles::update_session_roles();
3255: &Apache::lonnet::appenv({'user.update.time' => $now});
3256: if (ref($updateref)) {
3257: $$updateref = $now;
3258: }
3259: if (ref($dispositionref)) {
3260: $$dispositionref = 'created';
3261: }
3262: } else {
3263: $output = '<span class="LC_info">'.
1.42 bisitz 3264: &mt('An error occurred while activating your access to Authoring Space');
1.31 raeburn 3265: }
3266: } elsif ($val eq 'approval') {
3267: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($env{'user.domain'});
3268: if (&Apache::lonnet::put('requestauthorqueue',{ $env{'user.name'}.'_'.$val => $now },
3269: $env{'user.domain'},$domconfiguser) eq 'ok') {
3270: my %userrequest = (
3271: author => {
3272: timestamp => $now,
3273: status => $val,
3274: },
3275: author_status => $val,
3276: );
3277: my $req_notifylist;
3278: if (ref($domconfig{'requestauthor'}) eq 'HASH') {
3279: if (ref($domconfig{'requestauthor'}{'notify'}) eq 'HASH') {
3280: my $req_notifylist = $domconfig{'requestauthor'}{'notify'}{'approval'};
3281: if ($req_notifylist) {
3282: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3283: $env{'user.domain'});
3284: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
3285: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
3286: &send_selfserve_notification($req_notifylist,
3287: "$fullname ($env{'user.name'}:$env{'user.domain'})",
3288: undef,$domdesc,$now,'authorreq',$sender);
3289: }
3290: }
3291: }
3292: my $userresult =
3293: &Apache::lonnet::put('requestauthor',\%userrequest,$env{'user.domain'},$env{'user.name'});
3294: $output = '<span class="LC_info">'.
1.42 bisitz 3295: &mt('Your request for Authoring Space has been submitted for approval.').
1.31 raeburn 3296: '</span>';
3297: &Apache::lonnet::appenv({'environment.requestauthorqueued' => $val.':'.$now});
3298: } else {
3299: $output = '<span class="LC_info">'.
1.42 bisitz 3300: &mt('An error occurred saving your request for Authoring Space.').
1.31 raeburn 3301: '</span>';
3302: }
3303: }
3304: return $output;
3305: }
3306:
1.1 raeburn 3307: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>