Annotation of loncom/interface/loncoursequeueadmin.pm, revision 1.20
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.20 ! bisitz 4: # $Id: loncoursequeueadmin.pm,v 1.19 2010/02/21 23:38:51 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:
30: =head1 NAME
31:
32: Apache::loncoursequeueadmin.pm
33:
34: =head1 SYNOPSIS
35:
1.14 raeburn 36: Utilities used by domain coordinators to administer queued course creation requests,
37: and by course coordinators for queued self-enrollment requests, and by general
38: users to display their queued self-enrollment requests.
1.1 raeburn 39:
40: This is part of the LearningOnline Network with CAPA project
41: described at http://www.lon-capa.org.
42:
43: =head1 SUBROUTINES
44:
45: =over
46:
47: =item send_selfserve_notification()
48:
49: =item display_queued_requests()
50:
51: =item update_request_queue()
52:
53: =item get_student_counts()
54:
1.13 raeburn 55: =item course_creation()
56:
57: =item build_batchcreatehash()
58:
59: =item can_clone_course()
60:
61: =item get_processtype()
62:
1.14 raeburn 63: =item queued_selfenrollment()
64:
1.1 raeburn 65: =back
66:
67: =cut
68:
69: package Apache::loncoursequeueadmin;
70:
71: use strict;
72: use Apache::lonnet;
73: use Apache::loncommon;
74: use Apache::lonmsg;
75: use Apache::lonlocal;
1.2 raeburn 76: use Apache::lonuserutils;
1.19 raeburn 77: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 78:
79: sub send_selfserve_notification {
1.2 raeburn 80: my ($notifylist,$textstr,$cid,$contextdesc,$timestamp,$context,$sender,
1.12 raeburn 81: $approvedlist,$rejectedlist,$crstype) = @_;
1.1 raeburn 82: # FIXME locallocaltime needs to be able to take $sender_lh as an argument
83: # so this can be localized to the recipients date display format/time zone
84: $timestamp =&Apache::lonlocal::locallocaltime($timestamp);
85: my $msgcc;
1.12 raeburn 86: my ($rawsubj,@rawmsg,$subject,$message,$reviewer,$msgtxt);
1.1 raeburn 87: if ($context eq 'coursemanagers') {
88: $rawsubj = 'Self-enrollment requests processed';
89: push(@rawmsg,{
1.10 raeburn 90: mt => 'Enrollment requests in the following course: [_1] have been processed.',
1.3 raeburn 91: args => ["\n $contextdesc"],
1.1 raeburn 92: });
93: } elsif ($context eq 'domainmanagers') {
1.12 raeburn 94: $rawsubj = 'Course/Community requests reviewed';
1.1 raeburn 95: push(@rawmsg,{
1.12 raeburn 96: mt => 'Course/Community creation requests in the following domain: [_1] have been reviewed.',
1.3 raeburn 97: args => ["\n $contextdesc"],
1.1 raeburn 98: });
99: if (ref($textstr) eq 'ARRAY') {
100: push(@rawmsg,@{$textstr});
101: }
102: } elsif ($context eq 'enroller') {
103: $rawsubj = 'Enrollment request';
1.12 raeburn 104: if ($crstype eq 'community') {
105: $msgtxt = 'Your request for enrollment in the following community: [_1]requested on [_2]has been reviewed by a Coordinator.'
106: } else {
107: $msgtxt = 'Your request for enrollment in the following course: [_1]requested on [_2]has been reviewed by a Course Coordinator.';
108: }
1.1 raeburn 109: push(@rawmsg,{
1.12 raeburn 110: mt => $msgtxt,
1.2 raeburn 111: args => ["\n ".$contextdesc.",\n",$timestamp.",\n"],
1.1 raeburn 112:
113: });
114: if (ref($textstr) eq 'ARRAY') {
115: push(@rawmsg,@{$textstr});
116: }
117: } elsif ($context eq 'courserequestor') {
1.12 raeburn 118: if ($crstype eq 'Community') {
119: $rawsubj = 'Community request';
120: $msgtxt = 'Your request for creation of the following community: [_1]requested on [_2]has been reviewed by a Domain Coordinator.';
121: } else {
122: $rawsubj = 'Course request';
123: $msgtxt = 'Your request for creation of the following course: [_1]requested on [_2]has been reviewed by a Domain Coordinator.';
124: }
1.1 raeburn 125: push(@rawmsg,{
1.12 raeburn 126: mt => $msgtxt,
1.2 raeburn 127: args => ["\n".$contextdesc.",\n",$timestamp.",\n"],
1.1 raeburn 128:
129: });
130: if (ref($textstr) eq 'ARRAY') {
131: push(@rawmsg,@{$textstr});
132: }
133: } elsif ($context eq 'coursereq') {
1.12 raeburn 134: if ($crstype eq 'community') {
135: $rawsubj = 'Community request to review';
136: $msgtxt = 'Creation of the following community: [_1]was requested by [_2] on [_3].';
137: } else {
138: $rawsubj = 'Course request to review';
139: $msgtxt = 'Creation of the following course: [_1]was requested by [_2] on [_3].';
140: }
1.1 raeburn 141: push(@rawmsg,{
1.12 raeburn 142: mt => $msgtxt,
1.2 raeburn 143: args => ["\n $contextdesc\n",$textstr,$timestamp],
1.1 raeburn 144: },
145: {
1.12 raeburn 146: 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.2 raeburn 147: args => ["\n","\n\n ","\n\n"],
1.1 raeburn 148: });
149: } elsif ($context eq 'selfenrollreq') {
150: $rawsubj = 'Self-enrollment request';
1.12 raeburn 151: if ($crstype eq 'community') {
152: $msgtxt = 'Enrollment in the following community: [_1] was requested by [_2] on [_3].'
153: } else {
154: $msgtxt = 'Enrollment in the following course: [_1] was requested by [_2] on [_3].'
155: }
1.1 raeburn 156: push(@rawmsg,{
1.12 raeburn 157: mt => $msgtxt,
1.2 raeburn 158: args => ["\n $contextdesc\n",$textstr,$timestamp."\n"],
159: });
1.12 raeburn 160: my $directions;
161: if ($crstype eq 'community') {
162: $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 163: } else {
1.12 raeburn 164: $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.';
165: }
166: push(@rawmsg,
1.1 raeburn 167: {
1.12 raeburn 168: mt => $directions,
1.2 raeburn 169: args => [" \n\n","\n"],
1.1 raeburn 170: });
1.2 raeburn 171:
1.1 raeburn 172: }
173: my @to_notify = split(/,/,$notifylist);
174: my $numsent = 0;
175: my @recusers;
176: my @recudoms;
177: foreach my $cc (@to_notify) {
178: my ($ccname,$ccdom) = split(/:/,$cc);
179: if (!exists($msgcc->{$ccname.':'.$ccdom})) {
180: push(@recusers,$ccname);
181: push(@recudoms,$ccdom);
182: $msgcc->{$ccname.':'.$ccdom}='';
183: $numsent ++;
184: }
185: }
186: my %reciphash = (
187: cc => $msgcc,
188: );
189: my ($uname,$udom);
190: if ($sender =~ /:/) {
191: ($uname,$udom) = split(/:/,$sender);
1.2 raeburn 192: } elsif ($context eq 'course') {
1.1 raeburn 193: $uname = $sender;
194: my %courseinfo = &Apache::lonnet::coursedescription($cid);
195: $udom = $courseinfo{'num'};
196: }
197: my %sentmessage;
198: my $stamp = time;
199: my $msgcount = &Apache::lonmsg::get_uniq();
200: my $sender_lh = &Apache::loncommon::user_lang($uname,$udom,$cid);
201: $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj);
202: $message = '';
203: foreach my $item (@rawmsg) {
204: if (ref($item) eq 'HASH') {
205: $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
206: }
207: }
208: &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,\@recusers,\@recudoms);
209: my ($recipid,$recipstatus) = &Apache::lonmsg::store_recipients($subject,$uname,$udom,\%reciphash);
210: my $status;
211: foreach my $recip (sort(keys(%{$msgcc}))) {
212: my ($ccname,$ccdom) = split(/:/,$recip);
213: my $recip_lh = &Apache::loncommon::user_lang($ccname,$ccdom,$cid);
214: my $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj);
215: my $message = '';
216: foreach my $item (@rawmsg) {
217: if (ref($item) eq 'HASH') {
218: $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},
219: @{$item->{args}})."\n";
220: }
221: }
1.10 raeburn 222: if ($context eq 'coursemanagers') {
1.1 raeburn 223: if ($approvedlist) {
224: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved enrollments:')."\n".$approvedlist;
225: }
226: if ($rejectedlist) {
227: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected enrollments:')."\n".$rejectedlist;
228: }
229: } elsif ($context eq 'domainmanagers') {
230: if ($approvedlist) {
231: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved course requests:')."\n".$approvedlist;
232: }
233: if ($rejectedlist) {
234: $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected course requests:')."\n".$rejectedlist;
235: }
236: }
237: $status .= &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,1,\%sentmessage,undef,undef,undef,1,$recipid).',';
238: }
239: $status =~ s/,$//;
240: return ($recipstatus,$status);
241: }
242:
243: sub display_queued_requests {
244: my ($context,$dom,$cnum) = @_;
1.2 raeburn 245: my ($namespace,$formaction,$nextelement,%requesthash);
1.1 raeburn 246: if ($context eq 'course') {
247: $formaction = '/adm/createuser';
248: $namespace = 'selfenrollrequests';
249: %requesthash = &Apache::lonnet::dump($namespace,$dom,$cnum);
1.2 raeburn 250: $nextelement = '<input type="hidden" name="state" value="done" />';
1.1 raeburn 251: } else {
252: $formaction = '/adm/createcourse';
253: $namespace = 'courserequestqueue';
1.6 raeburn 254: %requesthash = &Apache::lonnet::dump_dom($namespace,$dom,'_approval');
1.2 raeburn 255: $nextelement = '<input type="hidden" name="phase" value="requestchange" />';
1.1 raeburn 256: }
257: my ($output,%queue_by_date,%crstypes);
258: if (keys(%requesthash) > 0) {
1.2 raeburn 259: $output = '<form method="post" name="changequeue" action="'.$formaction.'" />'."\n".
260: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
261: $nextelement."\n".
1.1 raeburn 262: &Apache::loncommon::start_data_table().
263: &Apache::loncommon::start_data_table_header_row().
264: '<th>'.&mt('Action').'</th>'.
265: '<th>'.&mt('Requestor').'</th>';
266: if ($context eq 'course') {
267: $output .= '<th>'.&mt('Section').'</th>'.
268: '<th>'.&mt('Date requested').'</th>';
1.12 raeburn 269: } else {
1.1 raeburn 270: %crstypes = &Apache::lonlocal::texthash (
271: official => 'Official course',
272: unofficial => 'Unofficial course',
273: community => 'Community',
274: );
275: $output .= '<th>'.&mt('Type').'</th>'.
276: '<th>'.&mt('Date requested').'</th>'.
277: '<th>'.&mt('Details').'</th>';
278: }
279: $output .= &Apache::loncommon::end_data_table_header_row();
280: foreach my $item (keys(%requesthash)) {
281: my ($timestamp,$entry);
282: if ($context eq 'course') {
283: ($timestamp, my $usec) = split(/:/,$requesthash{$item});
284: $entry = $item.':'.$usec;
285: } else {
286: $timestamp = $requesthash{$item}{'timestamp'};
287: if (ref($requesthash{$item}) eq 'HASH') {
1.2 raeburn 288: my ($cnum,$disposition) = split('_',$item);
289: $entry = $cnum.':'.$requesthash{$item}{'ownername'}.':'.
1.1 raeburn 290: $requesthash{$item}{'ownerdom'}.':'.
291: $requesthash{$item}{'crstype'}.':'.
292: $requesthash{$item}{'description'};
293: }
294: }
295: if ($entry ne '') {
296: if (exists($queue_by_date{$timestamp})) {
297: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
298: push(@{$queue_by_date{$timestamp}},$entry);
299: }
300: } else {
301: @{$queue_by_date{$timestamp}} = ($entry);
302: }
303: }
304: }
305: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
306: my $count = 0;
307: foreach my $item (@sortedtimes) {
308: if (ref($queue_by_date{$item}) eq 'ARRAY') {
309: foreach my $request (sort(@{$queue_by_date{$item}})) {
310: my ($row,$approve,$reject,$showtime,$showsec,$namelink,
311: $detailslink,$crstype);
312: $showtime = &Apache::lonlocal::locallocaltime($item);
313: if ($context eq 'course') {
314: my ($puname,$pudom,$pusec) = split(/:/,$request);
315: $approve = $count.':'.$puname.':'.$pudom.':'.$pusec;
316: $reject = $puname.':'.$pudom;
317: $showsec = $pusec;
318: if ($showsec eq '') {
319: $showsec = &mt('none');
320: }
321: $namelink = &Apache::loncommon::aboutmewrapper(
322: &Apache::loncommon::plainname($puname,$pudom),
323: $puname,$pudom);
324:
325: } else {
1.2 raeburn 326: my ($cnum,$ownername,$ownerdom,$type,$cdesc)=split(/:/,$request,5);
1.7 raeburn 327: $detailslink='<a href="javascript:opencoursereqdisplay('.
328: "'$dom','$cnum'".');">'.$cdesc.'</a>';
1.1 raeburn 329: $crstype = $type;
330: if (defined($crstypes{$type})) {
331: $crstype = $crstypes{$type};
332: }
333: $approve = $count.':'.$cnum;
334: $reject = $cnum;
335: $namelink = &Apache::loncommon::aboutmewrapper(
336: &Apache::loncommon::plainname($ownername,$ownerdom),
337: $ownername,$ownerdom);
338: }
339: $row = '<td><span class="LC_nobreak"><label>'.
340: '<input type="checkbox" value="'.$approve.'" name="approvereq" />'.&mt('Approve').'</label></span><br />'.
341: '<span class="LC_nobreak"><label>'.
342: '<input type="checkbox" value="'.$reject.'" name="rejectreq" />'.&mt('Reject').'</label></span><br /></td>'.
343: '<td>'.$namelink.'</td>'."\n";
344: if ($context eq 'course') {
345: $row .= '<td>'.$showsec.'</td>'."\n".
346: '<td>'.$showtime.'</td>'."\n";
347: } else {
348: $row .= '<td>'.$crstype.'</td>'."\n".
349: '<td>'.$showtime.'</td>'."\n".
350: '<td>'.$detailslink.'</td>'."\n";
351: }
352: $output .= &Apache::loncommon::start_data_table_row()."\n".
353: $row.
354: &Apache::loncommon::end_data_table_row()."\n";
355: $count ++;
356: }
357: }
358: }
359: $output .= &Apache::loncommon::end_data_table().
360: '<input type="submit" name="processqueue" value="'.&mt('Save').
361: '" /></form>';
362: } else {
363: if ($context eq 'course') {
364: $output .= &mt('There are currently no enrollment requests.');
365: } else {
1.12 raeburn 366: $output .= &mt('There are currently no course or community requests awaiting approval.');
1.1 raeburn 367: }
368: }
369: return $output;
370: }
371:
372: sub update_request_queue {
373: my ($context,$cdom,$cnum,$coursedesc) = @_;
374: my ($output,$access_start,$access_end,$limit,$cap,$notifylist,$namespace,
1.2 raeburn 375: $stucounts,$idx,$classlist,%requesthash,$cid,$hostname,$protocol,
376: $domdesc,$now,$sender,$approvedmsg,$rejectedmsg,$beneficiary,
377: @existing,@missingreq,@invalidusers,@limitexceeded,@completed,
1.19 raeburn 378: @processing_errors,@warn_approves,@warn_rejects,@approvals,@warn_dels,
1.5 raeburn 379: @rejections,@rejectionerrors,@nopermissions,%courseroles,
1.12 raeburn 380: %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype);
1.1 raeburn 381: @approvals = &Apache::loncommon::get_env_multiple('form.approvereq');
382: @rejections = &Apache::loncommon::get_env_multiple('form.rejectreq');
383: $now = time;
384: $sender = $env{'user.name'}.':'.$env{'user.domain'};
385: if ($context eq 'course') {
386: $namespace = 'selfenrollrequests';
387: $beneficiary = 'enroller';
388: $cid = $env{'request.course.id'};
1.12 raeburn 389: $crstype = lc(&Apache::loncommon::course_type());
1.1 raeburn 390: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
391: $hostname = &Apache::lonnet::hostname($chome);
392: $protocol = $Apache::lonnet::protocol{$chome};
393: $protocol = 'http' if ($protocol ne 'https');
394: %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
395: $access_start = $env{'course.'.$cid.'.internal.selfenroll_start_access'};
396: $access_end = $env{'course.'.$cid.'.internal.selfenroll_end_access'};
397: $limit = $env{'course.'.$cid.'.internal.selfenroll_limit'};
398: $cap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
399: $notifylist = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
400: ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
401: $approvedmsg = [{
402: mt => 'Your request for enrollment has been approved.',
403: },
404: {
405: mt => 'Visit [_1], to log-in and access the course',
406: args => [$protocol.'://'.$hostname],
407: }];
408: $rejectedmsg = [{
409: mt => 'Your request for enrollment has not been approved.',
410: }];
411: } else {
1.2 raeburn 412: $domdesc = &Apache::lonnet::domain($cdom);
413: $namespace = 'courserequestqueue';
414: $beneficiary = 'courserequestor';
1.6 raeburn 415: %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom,'_approval');
1.2 raeburn 416: my $chome = &Apache::lonnet::domain($cdom,'primary');
417: $hostname = &Apache::lonnet::hostname($chome);
418: $protocol = $Apache::lonnet::protocol{$chome};
419: $protocol = 'http' if ($protocol ne 'https');
420: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
421: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
422: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
423: $notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
424: }
425: }
1.12 raeburn 426: $approvalmsg{'course'} =
427: [{
1.2 raeburn 428: mt => 'Your course request has been approved.',
429: },
430: {
431: mt => 'Visit [_1], to log-in and access the course',
432: args => [$protocol.'://'.$hostname],
433: }];
1.12 raeburn 434: $rejectionmsg{'course'} =
435: [{
1.2 raeburn 436: mt => 'Your course request has not been approved.',
437: }];
1.12 raeburn 438:
439: $approvalmsg{'community'} =
440: [{
441: mt => 'Your community request has been approved.',
442: },
443: {
444: mt => 'Visit [_1], to log-in and access the community',
445: args => [$protocol.'://'.$hostname],
446: }];
447:
448: $rejectionmsg{'community'} =
449: [{
450: mt => 'Your community request has not been approved.',
451: }];
452:
1.2 raeburn 453: %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
454: my @roles = &Apache::lonuserutils::roles_by_context('course');
455: foreach my $role (@roles) {
456: $courseroles{$role}=&Apache::lonnet::plaintext($role,'Course');
457: }
458: foreach my $role (@roles) {
459: $communityroles{$role}=&Apache::lonnet::plaintext($role,'Community');
460: }
461:
1.1 raeburn 462: }
463: foreach my $item (sort {$a <=> $b} @approvals) {
464: if ($context eq 'course') {
465: my ($num,$uname,$udom,$usec) = split(/:/,$item);
466: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
467: if ($uhome ne 'no_host') {
468: if (exists($requesthash{$uname.':'.$udom})) {
469: if (exists($classlist->{$uname.':'.$udom})) {
470: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
471: if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
472: ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
473: push(@existing,$uname.':'.$udom);
474: next;
475: }
476: }
477: }
478: } else {
479: push(@missingreq,$uname.':'.$udom);
480: next;
481: }
482: if (!grep(/^\Q$item\E$/,@rejections)) {
483: if ($limit eq 'allstudents') {
484: if ($stucounts->{$limit} >= $cap) {
485: push(@limitexceeded,$uname.':'.$udom);
486: last;
487: }
488: } elsif ($limit eq 'selfenrolled') {
489: if ($stucounts->{$limit} >= $cap) {
490: push(@limitexceeded,$uname.':'.$udom);
491: last;
492: }
493: }
494: my $result =
495: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
496: if ($result eq 'ok') {
1.2 raeburn 497: push(@completed,$uname.':'.$udom);
1.1 raeburn 498: $stucounts->{'allstudents'} ++;
499: $stucounts->{'selfenrolled'} ++;
500: &send_selfserve_notification($uname.':'.$udom,$approvedmsg,
1.12 raeburn 501: $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
1.2 raeburn 502: my %userrequest = (
503: $cdom.'_'.$cnum => {
504: timestamp => $now,
505: section => $usec,
506: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
507: status => 'approved',
508: }
509: );
1.1 raeburn 510: my $userresult =
511: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
512: if ($userresult ne 'ok') {
513: push(@warn_approves,$uname.':'.$udom);
514: }
515: } else {
1.2 raeburn 516: push(@processing_errors,$uname.':'.$udom);
1.1 raeburn 517: }
518: }
519: } else {
520: push(@invalidusers,$uname.':'.$udom);
521: }
522: } else {
1.2 raeburn 523: my ($num,$cnum) = split(':',$item);
524: if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
525: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
526: my $ownername = $requesthash{$cnum.'_approval'}{'ownername'};
527: my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'};
1.12 raeburn 528: $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
1.2 raeburn 529: my $coursedesc = $requesthash{$cnum.'_approval'}{'description'};
530: my $longroles = \%courseroles;
531: if ($crstype eq 'community') {
532: $longroles = \%communityroles;
533: }
1.5 raeburn 534: my $cancreate;
535: if ($cdom eq $ownerdom) {
536: if (&Apache::lonnet::usertools_access($ownername,$ownerdom,$crstype,
537: undef,'requestcourses')) {
538: $cancreate = 1;
539: }
540: } else {
541: my %userenv = &Apache::lonnet::userenvironment($ownerdom,$ownername,'reqcrsotherdom.'.$crstype);
542: if ($userenv{'reqcrsotherdom.'.$crstype}) {
543: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
544: if (grep(/^\Q$cdom\E:/,@doms)) {
545: $cancreate = 1;
546: }
547: }
548: }
549: if ($cancreate) {
1.2 raeburn 550: my $requestkey = $cdom.'_'.$cnum;
551: my %history =
552: &Apache::lonnet::restore($requestkey,'courserequests',
553: $ownerdom,$ownername);
554: if ((ref($history{'details'}) eq 'HASH') &&
555: ($history{'disposition'} eq 'approval')) {
556: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);
557: my $result = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg,
558: \$newusermsg,\$addresult,\$enrollcount,
559: \$response,\$keysmsg,\%domdefs,$longroles);
560: if ($result eq 'created') {
1.12 raeburn 561: if ($crstype eq 'community') {
562: $approvedmsg = $approvalmsg{'community'};
563: } else {
564: $approvedmsg = $approvalmsg{'course'};
565: }
1.2 raeburn 566: push(@completed,$cnum);
1.19 raeburn 567:
568: unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_approval'],$cdom) eq 'ok') {
569: push(@warn_dels,$cnum);
570: }
1.2 raeburn 571: &send_selfserve_notification($ownername.':'.$ownerdom,$approvedmsg,
1.12 raeburn 572: $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
1.2 raeburn 573: my %reqhash = (
574: reqtime => $history{'reqtime'},
575: crstype => $history{'crstype'},
576: details => $history{'details'},
577: disposition => $history{'disposition'},
578: status => 'created',
579: adjudicator => $env{'user.name'}.':'.
580: $env{'user.domain'},
581: );
582: my $userresult =
583: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
584: 'courserequests',$ownerdom,$ownername);
585: if ($userresult eq 'ok') {
586: my %status = (
587: 'status:'.$cdom.':'.$cnum => 'created'
588: );
589: my $statusresult =
590: &Apache::lonnet::put('courserequests',\%status,
591: $ownerdom,$ownername);
592: if ($statusresult ne 'ok') {
593: push(@warn_approves,$cnum);
594: }
595: }
596: if ($userresult ne 'ok') {
597: push(@warn_approves,$cnum);
598: }
599: } else {
600: push(@processing_errors,$cnum);
601: }
602: } else {
603: push(@processing_errors,$cnum);
604: }
605: } else {
1.5 raeburn 606: push(@nopermissions,$cnum);
1.2 raeburn 607: }
608: } else {
609: push(@existing,$cnum);
610: }
611: } else {
612: push(@missingreq,$cnum);
613: }
1.1 raeburn 614: }
615: }
1.2 raeburn 616: my @changes = (@completed,@rejections);
617: if ($context eq 'domain') {
618: @changes = map {$_.'_approval'} (@changes);
619: }
1.1 raeburn 620: if (@rejections) {
1.3 raeburn 621: foreach my $item (@rejections) {
1.1 raeburn 622: if ($context eq 'course') {
1.3 raeburn 623: my $user = $item;
1.2 raeburn 624: &send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc,
1.12 raeburn 625: $now,$beneficiary,$sender,undef,undef,$crstype);
1.1 raeburn 626: my ($uname,$udom) = split(/:/,$user);
627: my %userrequest = (
628: $cdom.'_'.$cnum => {
629: timestamp => $now,
630: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
631: status => 'rejected',
632: }
633: );
634: my $userresult =
635: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
636: if ($userresult ne 'ok') {
637: push(@warn_rejects,$user);
638: }
639: } else {
1.3 raeburn 640: my $cnum = $item;
641: if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
642: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
643: my $requestkey = $cdom.'_'.$cnum;
1.2 raeburn 644: my $ownername = $requesthash{$cnum.'_approval'}{'ownername'};
645: my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'};
646: my $coursedesc = $requesthash{$cnum.'_approval'}{'description'};
1.12 raeburn 647: $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
648: if ($crstype eq 'community') {
649: $rejectedmsg = $rejectionmsg{'community'};
650: } else {
651: $rejectedmsg = $rejectionmsg{'course'};
652: }
1.2 raeburn 653: &send_selfserve_notification($ownername.':'.$ownerdom,$rejectedmsg,
654: $cid,$coursedesc,$now,$beneficiary,
1.12 raeburn 655: $sender,undef,undef,$crstype);
1.2 raeburn 656: my %history =
1.3 raeburn 657: &Apache::lonnet::restore($requestkey,'courserequests',
1.2 raeburn 658: $ownerdom,$ownername);
659: if ((ref($history{'details'}) eq 'HASH') &&
660: ($history{'disposition'} eq 'approval')) {
661: my %reqhash = (
662: reqtime => $history{'reqtime'},
663: crstype => $history{'crstype'},
664: details => $history{'details'},
665: disposition => $history{'disposition'},
666: status => 'rejected',
667: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
668: );
669: my $userresult =
1.3 raeburn 670: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
671: 'courserequests',$ownerdom,$ownername);
672: if ($userresult eq 'ok') {
673: my %status = (
674: 'status:'.$cdom.':'.$cnum => 'rejected'
675: );
676: my $statusresult =
677: &Apache::lonnet::put('courserequests',\%status,
678: $ownerdom,$ownername);
679: if ($statusresult ne 'ok') {
680: push(@warn_rejects,$cnum);
681: }
682: } else {
683: push(@warn_rejects,$cnum);
1.2 raeburn 684: }
1.19 raeburn 685: unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_approval'],$cdom) eq 'ok') {
686: push(@warn_dels,$cnum);
687: }
1.3 raeburn 688: } else {
689: push(@warn_rejects,$cnum);
1.2 raeburn 690: }
1.3 raeburn 691: } else {
692: push(@existing,$cnum);
1.2 raeburn 693: }
1.3 raeburn 694: } else {
695: push(@rejectionerrors,$cnum);
1.2 raeburn 696: }
1.1 raeburn 697: }
698: }
699: }
700: if (@changes) {
701: my $delresult;
702: if ($context eq 'course') {
703: $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
704: } else {
705: $delresult = &Apache::lonnet::del_dom($namespace,\@changes,$cdom);
706: }
707: if ($delresult eq 'ok') {
708: my $namelink =
709: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
710: my ($chgmsg,$approvedlist,$rejectedlist);
711: if ($context eq 'course') {
712: $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
1.2 raeburn 713: if (@completed) {
714: $approvedlist = join("\n",@completed);
1.12 raeburn 715: if ($crstype eq 'community') {
716: $output .= '<p>'.&mt('The following were enrolled in the community:').'<ul>';
717: } else {
718: $output .= '<p>'.&mt('The following were enrolled in the course:').'<ul>';
719: }
1.2 raeburn 720: foreach my $user (@completed) {
1.1 raeburn 721: my ($uname,$udom) = split(/:/,$user);
722: my $userlink =
723: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
724: $output .= '<li>'.$userlink.'</li>';
725: }
726: $output .= '</ul></p>';
727: }
728: if (@rejections) {
729: $rejectedlist = join("\n",@rejections);
730: $output .= '<p>'.&mt('The following enrollment requests were rejected:').'<ul>';
731: foreach my $user (@rejections) {
732: $output .= '<li>'.$user.'</li>';
733: }
734: $output .= '</ul></p>';
735: }
1.2 raeburn 736: if ($notifylist ne '') {
737: &send_selfserve_notification($notifylist,$chgmsg,$cid,$coursedesc,
738: $now,'coursemanagers',$sender,
1.12 raeburn 739: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 740: }
1.1 raeburn 741: } else {
1.12 raeburn 742: $chgmsg = "'Action was taken on the following course and community requests by [_1].',$namelink";
1.2 raeburn 743: if (@completed) {
744: $approvedlist = join("\n",@completed);
1.12 raeburn 745: $output .= '<p>'.&mt('The following courses/communities were created:').'<ul>';
1.2 raeburn 746: foreach my $cnum (@completed) {
747: my $showcourse;
748: if (ref($requesthash{$cnum.'_approval'})) {
749: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
750: } else {
751: $showcourse = $cnum;
752: }
753: my $syllabuslink =
754: &Apache::loncommon::syllabuswrapper($showcourse,$cnum,$cdom);
755: $output .= '<li>'.$syllabuslink.'</li>';
756: }
757: $output .= '</ul></p>';
758: }
759: if (@rejections) {
760: $rejectedlist = join("\n",@rejections);
761: $output .= '<p>'.&mt('The following requests were rejected:').'<ul>';
762: foreach my $cnum (@rejections) {
763: my $showcourse;
764: if (ref($requesthash{$cnum.'_approval'})) {
765: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
766: } else {
767: $showcourse = $cnum;
768: }
769: $output .= '<li>'.$showcourse.'</li>';
770: }
771: $output .= '</ul></p>';
772: }
773: if ($notifylist ne '') {
774: &send_selfserve_notification($notifylist,$chgmsg,$cid,$domdesc,
775: $now,'domainmanagers',$sender,
1.12 raeburn 776: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 777: }
1.1 raeburn 778: }
779: }
780: }
781: if (@existing) {
782: if ($context eq 'course') {
783: $output .= '<p>'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'<ul>';
784: foreach my $user (@existing) {
785: $output .= '<li>'.$user.'</li>';
786: }
787: $output .= '</ul></p>';
788: } else {
1.12 raeburn 789: $output .= '<p>'.&mt('The following course/community creation requests were deleted because the course or community has already been created:').'<ul>';
1.2 raeburn 790: foreach my $cnum (@existing) {
791: my $showcourse;
792: my %coursehash = &Apache::lonnet::coursedescription($cdom.'/'.$cnum);
793: if ($coursehash{'description'} ne '') {
794: $showcourse = $coursehash{'description'};
795: } else {
796: $showcourse = $cnum;
797: }
798: $output .= '<li>'.$showcourse.'</li>';
799: }
800: $output .= '</ul></p>';
1.1 raeburn 801: }
802: }
803: if (@missingreq) {
804: if ($context eq 'course') {
805: $output .= '<p>'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'<ul>';
806: foreach my $user (@missingreq) {
807: $output .= '<li>'.$user.'</li>';
808: }
809: $output .= '</ul></p>';
1.2 raeburn 810: } else {
1.12 raeburn 811: $output .= '<p>'.&mt('The following course/community creation requests were ignored because the request is no longer in the queue:').'<ul>';
1.2 raeburn 812: foreach my $cnum (@missingreq) {
813: $output .= '<li>'.$cnum.'</li>';
814: }
815: $output .= '</ul></p>';
816:
1.1 raeburn 817: }
818: }
819: if (@invalidusers) {
820: if ($context eq 'course') {
821: $output .= '<p>'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';
822: foreach my $user (@invalidusers) {
823: $output .= '<li>'.$user.'</li>';
824: }
825: $output .= '</ul></p>';
826: }
827: }
828: if (@limitexceeded) {
829: if ($context eq 'course') {
830: $output .= '<p>'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'<ul>';
831: foreach my $user (@limitexceeded) {
832: $output .= '<li>'.$user.'</li>';
833: }
834: $output .= '</ul></p>';
835: }
836: }
1.5 raeburn 837: if (@nopermissions) {
1.12 raeburn 838: $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>';
1.5 raeburn 839: foreach my $cnum (@nopermissions) {
840: my $showcourse;
841: if (ref($requesthash{$cnum.'_approval'})) {
842: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
843: } else {
844: $showcourse = $cnum;
845: }
846: $output .= '<li>'.$showcourse.'</li>';
847: }
848: $output .= '</ul></p>';
849: }
1.2 raeburn 850: if (@processing_errors) {
1.1 raeburn 851: if ($context eq 'course') {
852: $output .= '<p>'.&mt('The following enrollment requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 853: foreach my $user (@processing_errors) {
1.1 raeburn 854: $output .= '<li>'.$user.'</li>';
855: }
856: $output .= '</ul></p>';
857: } else {
1.12 raeburn 858: $output .= '<p>'.&mt('The following course/community creation requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 859: foreach my $cnum (@processing_errors) {
860: my $showcourse;
861: if (ref($requesthash{$cnum.'_approval'})) {
862: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
863: } else {
864: $showcourse = $cnum;
865: }
866: $output .= '<li>'.$showcourse.'</li>';
867: }
868: $output .= '</ul></p>';
1.1 raeburn 869: }
870: }
1.3 raeburn 871: if (@rejectionerrors) {
1.12 raeburn 872: $output .= '<p>'.&mt('The following course/community creation request rejections could not be fully processed because an error occurred:').'<ul>';
1.3 raeburn 873: foreach my $cnum (@rejectionerrors) {
874: my $showcourse;
875: if (ref($requesthash{$cnum.'_approval'})) {
876: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
877: } else {
878: $showcourse = $cnum;
879: }
880: $output .= '<li>'.$showcourse.'</li>';
881: }
882: $output .= '</ul></p>';
883: }
1.2 raeburn 884: if (@warn_approves || @warn_rejects) {
1.1 raeburn 885: if ($context eq 'course') {
886: $output .= '<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>';
887: foreach my $user (@warn_approves) {
888: $output .= '<li>'.$user.'</li>';
889: }
890: $output .= '</ul></p>';
891: } else {
1.12 raeburn 892: $output .= '<p>'.&mt("For the following course/community requests an error occurred when updating the requestor's own requests record:").'<ul>';
1.2 raeburn 893: foreach my $cnum (@warn_approves,@warn_rejects) {
894: my $showcourse;
895: if (ref($requesthash{$cnum.'_approval'})) {
896: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
897: } else {
898: $showcourse = $cnum;
899: }
900: $output .= '<li>'.$showcourse.'</li>';
1.1 raeburn 901: }
902: $output .= '</ul></p>';
903: }
904: }
1.19 raeburn 905: if (@warn_dels) {
906: $output .= '<p>'.&mt("For the following course/community requests an error occurred when removing requests for the following from the pending queue:").'<ul>';
907: foreach my $cnum (@warn_dels) {
908: my $showcourse;
909: if (ref($requesthash{$cnum.'_approval'})) {
910: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
911: } else {
912: $showcourse = $cnum;
913: }
914: $output .= '<li>'.$showcourse.'</li>';
915: }
916: $output .= '</ul></p>';
917: }
1.1 raeburn 918: return $output;
919: }
920:
921: sub get_student_counts {
922: my ($cdom,$cnum) = @_;
923: my (%idx,%stucounts);
924: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
925: $idx{'type'} = &Apache::loncoursedata::CL_TYPE();
926: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
927: while (my ($student,$data) = each(%$classlist)) {
928: if (($data->[$idx{'status'}] eq 'Active') ||
929: ($data->[$idx{'status'}] eq 'Future')) {
930: if ($data->[$idx{'type'}] eq 'selfenroll') {
931: $stucounts{'selfenroll'} ++;
932: }
933: $stucounts{'allstudents'} ++;
934: }
935: }
936: return (\%stucounts,\%idx,$classlist);
937: }
938:
1.2 raeburn 939: sub course_creation {
940: my ($dom,$cnum,$context,$details,$logmsg,$newusermsg,$addresult,$enrollcount,$output,
941: $keysmsg,$domdefs,$longroles) = @_;
942: unless ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH') &&
943: (ref($longroles) eq 'HASH')) {
944: return 'error: Invalid request';
945: }
946: my ($result,$ownername,$ownerdom);
947: my $crstype = $details->{'crstype'};
948: if ($context eq 'domain') {
949: $ownername = $details->{'owner'};
950: $ownerdom = $details->{'domain'};
951: } else {
952: $ownername = $env{'user.name'};
953: $ownerdom = $env{'user.domain'};
954: }
955: my $owneremail;
956: my %emails = &Apache::loncommon::getemails($ownername,$ownerdom);
957: foreach my $email ('permanentemail','critnotification','notification') {
958: $owneremail = $emails{$email};
959: last if ($owneremail ne '');
960: }
1.8 raeburn 961: my %reqdetails = &build_batchcreatehash($dom,$context,$details,$owneremail,$domdefs);
1.2 raeburn 962: my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',
963: \%reqdetails,$longroles,\$logmsg,\$newusermsg,\$addresult,
964: \$enrollcount,\$output,\$keysmsg,$ownerdom,$ownername,$cnum,$crstype);
965: if ($cid eq "/$dom/$cnum") {
966: $result = 'created';
967: } else {
968: $result = 'error: '.$cid;
969: }
970: return $result;
971: }
972:
973: sub build_batchcreatehash {
1.8 raeburn 974: my ($dom,$context,$details,$owneremail,$domdefs) = @_;
1.2 raeburn 975: my %batchhash;
976: my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users};
977: if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
1.17 raeburn 978: my $emailenc = &escape($owneremail);
1.2 raeburn 979: my $owner = $details->{'owner'}.':'.$details->{'domain'};
980: foreach my $item (@items) {
981: $batchhash{$item} = $details->{$item};
982: }
983: $batchhash{'title'} = $details->{'cdescr'};
984: $batchhash{'coursecode'} = $details->{'instcode'};
985: $batchhash{'emailenc'} = $emailenc;
986: $batchhash{'adds'} = $details->{'autoadds'};
987: $batchhash{'drops'} = $details->{'autodrops'};
988: $batchhash{'authtype'} = $domdefs->{'auth_def'};
989: $batchhash{'authparam'} = $domdefs->{'auth_arg_def'};
990: if ($details->{'crstype'} eq 'community') {
991: $batchhash{'crstype'} = 'Community';
992: } else {
993: $batchhash{'crstype'} = 'Course';
994: }
1.8 raeburn 995: my ($owner_firstname,$owner_lastname);
996: if ($context eq 'domain') {
997: my %userenv = &Apache::lonnet::userenvironment($details->{'domain'},
998: $details->{'owner'},
999: 'firstname','lastname');
1000: $owner_firstname = $userenv{'firstname'};
1001: $owner_lastname = $userenv{'lastname'};
1002: } else {
1003: $owner_firstname = $env{'environment.firstname'};
1004: $owner_lastname = $env{'environment.lastname'};
1005: }
1006: if (ref($details->{'personnel'}) eq 'HASH') {
1007: %{$batchhash{'users'}} = %{$details->{'personnel'}};
1008: if (ref($batchhash{'users'}) eq 'HASH') {
1009: foreach my $userkey (keys(%{$batchhash{'users'}})) {
1010: if (ref($batchhash{'users'}{$userkey}) eq 'HASH') {
1011: if (ref($batchhash{'users'}{$userkey}{'roles'}) eq 'ARRAY') {
1012: foreach my $role (@{$batchhash{'users'}{$userkey}{'roles'}}) {
1013: my $start = '';
1014: my $end = '';
1015: if ($role eq 'st') {
1016: $start = $details->{'accessstart'};
1017: $end = $details->{'accessend'};
1018: }
1019: $batchhash{'users'}{$userkey}{$role}{'start'} = $start;
1020: $batchhash{'users'}{$userkey}{$role}{'end'} = $end;
1021: }
1022: }
1023: }
1024: }
1025: }
1026: }
1027: $batchhash{'users'}{$owner}{firstname} = $owner_firstname;
1028: $batchhash{'users'}{$owner}{lastname} = $owner_lastname;
1029: $batchhash{'users'}{$owner}{emailenc} = $emailenc;
1030: $batchhash{'users'}{$owner}{owneremail} = $owneremail;
1.2 raeburn 1031: }
1032: return %batchhash;
1033: }
1034:
1.4 raeburn 1035: sub can_clone_course {
1.11 raeburn 1036: my ($uname,$udom,$clonecrs,$clonedom,$crstype) = @_;
1.4 raeburn 1037: my $canclone;
1.11 raeburn 1038: my $ccrole = 'cc';
1.12 raeburn 1039: if ($crstype eq 'community') {
1.11 raeburn 1040: $ccrole = 'co';
1041: }
1.4 raeburn 1042: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',['active'],
1.11 raeburn 1043: [$ccrole],[$clonedom]);
1044: if (exists($roleshash{$clonecrs.':'.$clonedom.':'.$ccrole})) {
1.4 raeburn 1045: $canclone = 1;
1046: } else {
1047: my %courseenv = &Apache::lonnet::userenvironment($clonedom,$clonecrs,('cloners'));
1048: my $cloners = $courseenv{'cloners'};
1049: if ($cloners ne '') {
1050: my @cloneable = split(',',$cloners);
1051: if (grep(/^\*$/,@cloneable)) {
1052: $canclone = 1;
1053: }
1054: if (grep(/^\*:\Q$udom\E$/,@cloneable)) {
1055: $canclone = 1;
1056: }
1057: if (grep(/^\Q$uname\E:\Q$udom\E$/,@cloneable)) {
1058: $canclone = 1;
1059: }
1060: }
1.18 raeburn 1061: unless ($canclone) {
1062: if (&Apache::lonnet::is_course_owner($clonedom,$clonecrs,$uname,$udom)) {
1.20 ! bisitz 1063: $canclone = 1;
1.18 raeburn 1064: }
1065: }
1.4 raeburn 1066: }
1067: return $canclone;
1068: }
1069:
1.13 raeburn 1070: sub get_processtype {
1071: my ($uname,$udom,$isadv,$dom,$crstype,$inststatuses,$domconfig) = @_;
1072: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1073: if ($uname eq '' || $udom eq '') {
1074: $uname = $env{'user.name'};
1075: $udom = $env{'user.domain'};
1076: $isadv = $env{'user.adv'};
1077: }
1078: my (%userenv,%settings,$val);
1079: my @options = ('autolimit','validate','approval');
1080: if ($dom eq $udom) {
1081: %userenv =
1082: &Apache::lonnet::userenvironment($udom,$uname,'requestcourses.'.$crstype,'inststatus');
1083: if ($userenv{'requestcourses.'.$crstype}) {
1084: $val = $userenv{'requestcourses.'.$crstype};
1085: @{$inststatuses} = ('_custom_');
1086: } else {
1087: my ($task,%alltasks);
1088: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
1089: %settings = %{$domconfig->{'requestcourses'}};
1090: if (ref($settings{$crstype}) eq 'HASH') {
1091: if (($isadv) && ($settings{$crstype}{'_LC_adv'} ne '')) {
1092: $val = $settings{$crstype}{'_LC_adv'};
1093: @{$inststatuses} = ('_LC_adv_');
1094: } else {
1095: if ($userenv{'inststatus'} ne '') {
1096: @{$inststatuses} = split(',',$userenv{'inststatus'});
1097: } else {
1098: @{$inststatuses} = ('default');
1099: }
1100: foreach my $status (@{$inststatuses}) {
1101: if (exists($settings{$crstype}{$status})) {
1102: my $value = $settings{$crstype}{$status};
1103: next unless ($value);
1104: unless (exists($alltasks{$value})) {
1105: if (ref($alltasks{$value}) eq 'ARRAY') {
1106: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
1107: push(@{$alltasks{$value}},$status);
1108: }
1109: } else {
1110: @{$alltasks{$value}} = ($status);
1111: }
1112: }
1113: }
1114: }
1115: my $maxlimit = 0;
1116:
1117: foreach my $key (sort(keys(%alltasks))) {
1118: if ($key =~ /^autolimit=(\d*)$/) {
1119: if ($1 eq '') {
1120: $val ='autolimit=';
1121: last;
1122: } elsif ($1 > $maxlimit) {
1123: $maxlimit = $1;
1124: }
1125: }
1126: }
1127: if ($maxlimit) {
1128: $val = 'autolimit='.$maxlimit;
1129: } else {
1130: foreach my $option (@options) {
1131: if ($alltasks{$option}) {
1132: $val = $option;
1133: last;
1134: }
1135: }
1136: }
1137: }
1138: }
1139: }
1140: }
1141: } else {
1142: %userenv = &Apache::lonnet::userenvironment($udom,$uname,'reqcrsotherdom.'.$crstype);
1143: if ($userenv{'reqcrsotherdom.'.$crstype}) {
1144: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
1145: my $optregex = join('|',@options);
1146: foreach my $item (@doms) {
1147: my ($extdom,$extopt) = split(':',$item);
1148: if ($extdom eq $dom) {
1149: if ($extopt =~ /^($optregex)(=?\d*)$/) {
1150: $val = $1.$2;
1151: }
1152: last;
1153: }
1154: }
1155: @{$inststatuses} = ('_external_');
1156: }
1157: }
1158: return $val;
1159: }
1160:
1.14 raeburn 1161: sub queued_selfenrollment {
1162: my ($notitle) = @_;
1163: my $output;
1164: my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests');
1165: my %reqs_by_date;
1166: foreach my $item (keys(%selfenrollrequests)) {
1167: if (ref($selfenrollrequests{$item}) eq 'HASH') {
1168: if ($selfenrollrequests{$item}{'status'} eq 'request') {
1169: if ($selfenrollrequests{$item}{'timestamp'}) {
1170: push(@{$reqs_by_date{$selfenrollrequests{$item}{'timestamp'}}},$item);
1171: }
1172: }
1173: }
1174: }
1175: if (keys(%reqs_by_date)) {
1176: unless ($notitle) {
1177: $output .= '<b>'.&mt('Enrollment requests pending Course Coordinator approval').'</b><br />';
1178: }
1179: $output .= &Apache::loncommon::start_data_table().
1180: &Apache::loncommon::start_data_table_header_row().
1181: '<th>'.&mt('Date requested').'</th><th>'.&mt('Course title').'</th>'.
1182: '<th>'.&mt('User role').'</th><th>'.&mt('Section').'</th>'.
1183: &Apache::loncommon::end_data_table_header_row();
1184: my @sorted = sort { $a <=> $b } (keys(%reqs_by_date));
1185: foreach my $item (@sorted) {
1186: if (ref($reqs_by_date{$item}) eq 'ARRAY') {
1187: foreach my $crs (@{$reqs_by_date{$item}}) {
1188: my %courseinfo = &Apache::lonnet::coursedescription($crs);
1189: my $usec = $selfenrollrequests{$crs}{'section'};
1.16 raeburn 1190: my $rolename = &Apache::lonnet::plaintext('st',$courseinfo{'type'},$crs);
1.14 raeburn 1191: if ($usec eq '') {
1192: $usec = &mt('No section');
1193: }
1194: $output .= &Apache::loncommon::start_data_table_row().
1195: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
1196: '<td>'.$courseinfo{'description'}.'</td>'.
1197: '<td>'.$rolename.'</td><td>'.$usec.'</td>'.
1198: &Apache::loncommon::end_data_table_row();
1199: }
1200: }
1201: }
1202: $output .= &Apache::loncommon::end_data_table();
1203: }
1204: return $output;
1205: }
1206:
1.19 raeburn 1207: sub update_coursereq_status {
1208: my ($reqhash,$dom,$cnum,$reqstatus,$context) = @_;
1209: my ($storeresult,$statusresult,$output);
1210: my $requestkey = $dom.'_'.$cnum;
1211: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1212: $storeresult = &Apache::lonnet::store_userdata($reqhash,$requestkey,
1213: 'courserequests');
1214: if ($storeresult eq 'ok') {
1215: my %status = (
1216: 'status:'.$dom.':'.$cnum => $reqstatus,
1217: );
1218: $statusresult = &Apache::lonnet::put('courserequests',\%status);
1219: }
1220: } else {
1221: $storeresult = 'error: invalid requestkey format';
1222: }
1223: if ($storeresult ne 'ok') {
1224: $output = &mt('An error occurred saving a record of the details of your request: [_1].',$storeresult);
1225: if ($context eq 'domain') {
1226: $output .= "\n";
1227: } else {
1228: $output = '<span class="LC_warning">'.$output.'</span><br />';
1229: }
1230: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1231: } elsif ($statusresult ne 'ok') {
1232: $output = &mt('An error occurred saving a record of the status of your request: [_1].',$statusresult);
1233: if ($context eq 'domain') {
1234: $output .= "\n";
1235: } else {
1236: $output = '<span class="LC_warning">'.$output.'</span><br />';
1237: }
1238: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
1239: }
1240: return ($storeresult,$output);
1241: }
1242:
1.1 raeburn 1243: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>