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