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