Annotation of loncom/interface/loncoursequeueadmin.pm, revision 1.12.2.10
1.1 raeburn 1: # The LearningOnline Network
2: # Utilities to administer domain course requests and course self-enroll requests
3: #
1.12.2.10! raeburn 4: # $Id: loncoursequeueadmin.pm,v 1.12.2.9 2010/09/03 19:20:47 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,
379: @warn_coursereqs);
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');
393: %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
394: $access_start = $env{'course.'.$cid.'.internal.selfenroll_start_access'};
395: $access_end = $env{'course.'.$cid.'.internal.selfenroll_end_access'};
396: $limit = $env{'course.'.$cid.'.internal.selfenroll_limit'};
397: $cap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
398: $notifylist = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
399: ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
400: $approvedmsg = [{
401: mt => 'Your request for enrollment has been approved.',
402: },
403: {
404: mt => 'Visit [_1], to log-in and access the course',
405: args => [$protocol.'://'.$hostname],
406: }];
407: $rejectedmsg = [{
408: mt => 'Your request for enrollment has not been approved.',
409: }];
410: } else {
1.2 raeburn 411: $domdesc = &Apache::lonnet::domain($cdom);
412: $namespace = 'courserequestqueue';
413: $beneficiary = 'courserequestor';
1.6 raeburn 414: %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom,'_approval');
1.2 raeburn 415: my $chome = &Apache::lonnet::domain($cdom,'primary');
416: $hostname = &Apache::lonnet::hostname($chome);
417: $protocol = $Apache::lonnet::protocol{$chome};
418: $protocol = 'http' if ($protocol ne 'https');
419: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
420: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
421: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
422: $notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
423: }
424: }
1.12 raeburn 425: $approvalmsg{'course'} =
426: [{
1.2 raeburn 427: mt => 'Your course request has been approved.',
428: },
429: {
430: mt => 'Visit [_1], to log-in and access the course',
431: args => [$protocol.'://'.$hostname],
432: }];
1.12 raeburn 433: $rejectionmsg{'course'} =
434: [{
1.2 raeburn 435: mt => 'Your course request has not been approved.',
436: }];
1.12 raeburn 437:
438: $approvalmsg{'community'} =
439: [{
440: mt => 'Your community request has been approved.',
441: },
442: {
443: mt => 'Visit [_1], to log-in and access the community',
444: args => [$protocol.'://'.$hostname],
445: }];
446:
447: $rejectionmsg{'community'} =
448: [{
449: mt => 'Your community request has not been approved.',
450: }];
451:
1.2 raeburn 452: %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
453: my @roles = &Apache::lonuserutils::roles_by_context('course');
454: foreach my $role (@roles) {
455: $courseroles{$role}=&Apache::lonnet::plaintext($role,'Course');
456: }
457: foreach my $role (@roles) {
458: $communityroles{$role}=&Apache::lonnet::plaintext($role,'Community');
459: }
460:
1.1 raeburn 461: }
1.12.2.10! raeburn 462: my %allnums = &Apache::loncommon::get_faculty_cnums();
1.1 raeburn 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})) {
1.12.2.10! raeburn 469: if ($cdom ne '' && ref($allnums{$cdom} eq 'HASH') {
! 470: my ($addothers,@others);
! 471: foreach my $key (%{$allnums{$cdom}}) {
! 472: if ($key eq $cnum) {
! 473: $addothers = 1;
! 474: } else {
! 475: push(@others,$key);
! 476: }
! 477: }
! 478: if ($addothers) {
! 479: foreach my $crs (@others) {
! 480: my $enresult =
! 481: &enable_additional_roles($cdom,$crs,$udom,$uname,
! 482: $access_end,$access_start);
! 483: }
1.12.2.9 raeburn 484: }
1.12.2.2 raeburn 485: }
1.1 raeburn 486: if (exists($classlist->{$uname.':'.$udom})) {
487: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
488: if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
489: ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
490: push(@existing,$uname.':'.$udom);
491: next;
492: }
493: }
494: }
495: } else {
496: push(@missingreq,$uname.':'.$udom);
497: next;
498: }
499: if (!grep(/^\Q$item\E$/,@rejections)) {
500: if ($limit eq 'allstudents') {
501: if ($stucounts->{$limit} >= $cap) {
502: push(@limitexceeded,$uname.':'.$udom);
503: last;
504: }
505: } elsif ($limit eq 'selfenrolled') {
506: if ($stucounts->{$limit} >= $cap) {
507: push(@limitexceeded,$uname.':'.$udom);
508: last;
509: }
510: }
511: my $result =
512: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
513: if ($result eq 'ok') {
1.2 raeburn 514: push(@completed,$uname.':'.$udom);
1.1 raeburn 515: $stucounts->{'allstudents'} ++;
516: $stucounts->{'selfenrolled'} ++;
517: &send_selfserve_notification($uname.':'.$udom,$approvedmsg,
1.12 raeburn 518: $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
1.2 raeburn 519: my %userrequest = (
520: $cdom.'_'.$cnum => {
521: timestamp => $now,
522: section => $usec,
523: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
524: status => 'approved',
525: }
526: );
1.1 raeburn 527: my $userresult =
528: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
529: if ($userresult ne 'ok') {
530: push(@warn_approves,$uname.':'.$udom);
1.12.2.10! raeburn 531: } elsif (ref($allnums{$udom}) eq 'HASH') {
1.12.2.1 raeburn 532: my %changehash = (
1.12.2.10! raeburn 533: 'reqcrsotherdom.unofficial' => $udom.'test:autolimit=',
1.12.2.1 raeburn 534: );
535: my $reqresult = &Apache::lonnet::put('environment',\%changehash,
536: $udom,$uname);
537: if ($reqresult ne 'ok') {
538: push(@warn_coursereqs,$uname.':'.$udom);
539: }
1.1 raeburn 540: }
541: } else {
1.2 raeburn 542: push(@processing_errors,$uname.':'.$udom);
1.1 raeburn 543: }
544: }
545: } else {
546: push(@invalidusers,$uname.':'.$udom);
547: }
548: } else {
1.2 raeburn 549: my ($num,$cnum) = split(':',$item);
550: if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
551: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
552: my $ownername = $requesthash{$cnum.'_approval'}{'ownername'};
553: my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'};
1.12 raeburn 554: $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
1.2 raeburn 555: my $coursedesc = $requesthash{$cnum.'_approval'}{'description'};
556: my $longroles = \%courseroles;
557: if ($crstype eq 'community') {
558: $longroles = \%communityroles;
559: }
1.5 raeburn 560: my $cancreate;
561: if ($cdom eq $ownerdom) {
562: if (&Apache::lonnet::usertools_access($ownername,$ownerdom,$crstype,
563: undef,'requestcourses')) {
564: $cancreate = 1;
565: }
566: } else {
567: my %userenv = &Apache::lonnet::userenvironment($ownerdom,$ownername,'reqcrsotherdom.'.$crstype);
568: if ($userenv{'reqcrsotherdom.'.$crstype}) {
569: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
570: if (grep(/^\Q$cdom\E:/,@doms)) {
571: $cancreate = 1;
572: }
573: }
574: }
575: if ($cancreate) {
1.2 raeburn 576: my $requestkey = $cdom.'_'.$cnum;
577: my %history =
578: &Apache::lonnet::restore($requestkey,'courserequests',
579: $ownerdom,$ownername);
580: if ((ref($history{'details'}) eq 'HASH') &&
581: ($history{'disposition'} eq 'approval')) {
582: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);
583: my $result = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg,
584: \$newusermsg,\$addresult,\$enrollcount,
585: \$response,\$keysmsg,\%domdefs,$longroles);
586: if ($result eq 'created') {
1.12 raeburn 587: if ($crstype eq 'community') {
588: $approvedmsg = $approvalmsg{'community'};
589: } else {
590: $approvedmsg = $approvalmsg{'course'};
591: }
1.2 raeburn 592: push(@completed,$cnum);
593: &send_selfserve_notification($ownername.':'.$ownerdom,$approvedmsg,
1.12 raeburn 594: $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
1.2 raeburn 595: my %reqhash = (
596: reqtime => $history{'reqtime'},
597: crstype => $history{'crstype'},
598: details => $history{'details'},
599: disposition => $history{'disposition'},
600: status => 'created',
601: adjudicator => $env{'user.name'}.':'.
602: $env{'user.domain'},
603: );
604: my $userresult =
605: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
606: 'courserequests',$ownerdom,$ownername);
607: if ($userresult eq 'ok') {
608: my %status = (
609: 'status:'.$cdom.':'.$cnum => 'created'
610: );
611: my $statusresult =
612: &Apache::lonnet::put('courserequests',\%status,
613: $ownerdom,$ownername);
614: if ($statusresult ne 'ok') {
615: push(@warn_approves,$cnum);
616: }
617: }
618: if ($userresult ne 'ok') {
619: push(@warn_approves,$cnum);
620: }
621: } else {
622: push(@processing_errors,$cnum);
623: }
624: } else {
625: push(@processing_errors,$cnum);
626: }
627: } else {
1.5 raeburn 628: push(@nopermissions,$cnum);
1.2 raeburn 629: }
630: } else {
631: push(@existing,$cnum);
632: }
633: } else {
634: push(@missingreq,$cnum);
635: }
1.1 raeburn 636: }
637: }
1.2 raeburn 638: my @changes = (@completed,@rejections);
639: if ($context eq 'domain') {
640: @changes = map {$_.'_approval'} (@changes);
641: }
1.1 raeburn 642: if (@rejections) {
1.3 raeburn 643: foreach my $item (@rejections) {
1.1 raeburn 644: if ($context eq 'course') {
1.3 raeburn 645: my $user = $item;
1.2 raeburn 646: &send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc,
1.12 raeburn 647: $now,$beneficiary,$sender,undef,undef,$crstype);
1.1 raeburn 648: my ($uname,$udom) = split(/:/,$user);
649: my %userrequest = (
650: $cdom.'_'.$cnum => {
651: timestamp => $now,
652: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
653: status => 'rejected',
654: }
655: );
656: my $userresult =
657: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
658: if ($userresult ne 'ok') {
659: push(@warn_rejects,$user);
660: }
661: } else {
1.3 raeburn 662: my $cnum = $item;
663: if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
664: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
665: my $requestkey = $cdom.'_'.$cnum;
1.2 raeburn 666: my $ownername = $requesthash{$cnum.'_approval'}{'ownername'};
667: my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'};
668: my $coursedesc = $requesthash{$cnum.'_approval'}{'description'};
1.12 raeburn 669: $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
670: if ($crstype eq 'community') {
671: $rejectedmsg = $rejectionmsg{'community'};
672: } else {
673: $rejectedmsg = $rejectionmsg{'course'};
674: }
1.2 raeburn 675: &send_selfserve_notification($ownername.':'.$ownerdom,$rejectedmsg,
676: $cid,$coursedesc,$now,$beneficiary,
1.12 raeburn 677: $sender,undef,undef,$crstype);
1.2 raeburn 678: my %history =
1.3 raeburn 679: &Apache::lonnet::restore($requestkey,'courserequests',
1.2 raeburn 680: $ownerdom,$ownername);
681: if ((ref($history{'details'}) eq 'HASH') &&
682: ($history{'disposition'} eq 'approval')) {
683: my %reqhash = (
684: reqtime => $history{'reqtime'},
685: crstype => $history{'crstype'},
686: details => $history{'details'},
687: disposition => $history{'disposition'},
688: status => 'rejected',
689: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
690: );
691: my $userresult =
1.3 raeburn 692: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
693: 'courserequests',$ownerdom,$ownername);
694: if ($userresult eq 'ok') {
695: my %status = (
696: 'status:'.$cdom.':'.$cnum => 'rejected'
697: );
698: my $statusresult =
699: &Apache::lonnet::put('courserequests',\%status,
700: $ownerdom,$ownername);
701: if ($statusresult ne 'ok') {
702: push(@warn_rejects,$cnum);
703: }
704: } else {
705: push(@warn_rejects,$cnum);
1.2 raeburn 706: }
1.3 raeburn 707: } else {
708: push(@warn_rejects,$cnum);
1.2 raeburn 709: }
1.3 raeburn 710: } else {
711: push(@existing,$cnum);
1.2 raeburn 712: }
1.3 raeburn 713: } else {
714: push(@rejectionerrors,$cnum);
1.2 raeburn 715: }
1.1 raeburn 716: }
717: }
718: }
719: if (@changes) {
720: my $delresult;
721: if ($context eq 'course') {
722: $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
723: } else {
724: $delresult = &Apache::lonnet::del_dom($namespace,\@changes,$cdom);
725: }
726: if ($delresult eq 'ok') {
727: my $namelink =
728: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
729: my ($chgmsg,$approvedlist,$rejectedlist);
730: if ($context eq 'course') {
731: $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
1.2 raeburn 732: if (@completed) {
733: $approvedlist = join("\n",@completed);
1.12 raeburn 734: if ($crstype eq 'community') {
735: $output .= '<p>'.&mt('The following were enrolled in the community:').'<ul>';
736: } else {
737: $output .= '<p>'.&mt('The following were enrolled in the course:').'<ul>';
738: }
1.2 raeburn 739: foreach my $user (@completed) {
1.1 raeburn 740: my ($uname,$udom) = split(/:/,$user);
741: my $userlink =
742: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
743: $output .= '<li>'.$userlink.'</li>';
744: }
745: $output .= '</ul></p>';
746: }
747: if (@rejections) {
748: $rejectedlist = join("\n",@rejections);
749: $output .= '<p>'.&mt('The following enrollment requests were rejected:').'<ul>';
750: foreach my $user (@rejections) {
751: $output .= '<li>'.$user.'</li>';
752: }
753: $output .= '</ul></p>';
754: }
1.2 raeburn 755: if ($notifylist ne '') {
756: &send_selfserve_notification($notifylist,$chgmsg,$cid,$coursedesc,
757: $now,'coursemanagers',$sender,
1.12 raeburn 758: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 759: }
1.1 raeburn 760: } else {
1.12 raeburn 761: $chgmsg = "'Action was taken on the following course and community requests by [_1].',$namelink";
1.2 raeburn 762: if (@completed) {
763: $approvedlist = join("\n",@completed);
1.12 raeburn 764: $output .= '<p>'.&mt('The following courses/communities were created:').'<ul>';
1.2 raeburn 765: foreach my $cnum (@completed) {
766: my $showcourse;
767: if (ref($requesthash{$cnum.'_approval'})) {
768: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
769: } else {
770: $showcourse = $cnum;
771: }
772: my $syllabuslink =
773: &Apache::loncommon::syllabuswrapper($showcourse,$cnum,$cdom);
774: $output .= '<li>'.$syllabuslink.'</li>';
775: }
776: $output .= '</ul></p>';
777: }
778: if (@rejections) {
779: $rejectedlist = join("\n",@rejections);
780: $output .= '<p>'.&mt('The following requests were rejected:').'<ul>';
781: foreach my $cnum (@rejections) {
782: my $showcourse;
783: if (ref($requesthash{$cnum.'_approval'})) {
784: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
785: } else {
786: $showcourse = $cnum;
787: }
788: $output .= '<li>'.$showcourse.'</li>';
789: }
790: $output .= '</ul></p>';
791: }
792: if ($notifylist ne '') {
793: &send_selfserve_notification($notifylist,$chgmsg,$cid,$domdesc,
794: $now,'domainmanagers',$sender,
1.12 raeburn 795: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 796: }
1.1 raeburn 797: }
798: }
799: }
800: if (@existing) {
801: if ($context eq 'course') {
802: $output .= '<p>'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'<ul>';
803: foreach my $user (@existing) {
804: $output .= '<li>'.$user.'</li>';
805: }
806: $output .= '</ul></p>';
807: } else {
1.12 raeburn 808: $output .= '<p>'.&mt('The following course/community creation requests were deleted because the course or community has already been created:').'<ul>';
1.2 raeburn 809: foreach my $cnum (@existing) {
810: my $showcourse;
811: my %coursehash = &Apache::lonnet::coursedescription($cdom.'/'.$cnum);
812: if ($coursehash{'description'} ne '') {
813: $showcourse = $coursehash{'description'};
814: } else {
815: $showcourse = $cnum;
816: }
817: $output .= '<li>'.$showcourse.'</li>';
818: }
819: $output .= '</ul></p>';
1.1 raeburn 820: }
821: }
822: if (@missingreq) {
823: if ($context eq 'course') {
824: $output .= '<p>'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'<ul>';
825: foreach my $user (@missingreq) {
826: $output .= '<li>'.$user.'</li>';
827: }
828: $output .= '</ul></p>';
1.2 raeburn 829: } else {
1.12 raeburn 830: $output .= '<p>'.&mt('The following course/community creation requests were ignored because the request is no longer in the queue:').'<ul>';
1.2 raeburn 831: foreach my $cnum (@missingreq) {
832: $output .= '<li>'.$cnum.'</li>';
833: }
834: $output .= '</ul></p>';
835:
1.1 raeburn 836: }
837: }
838: if (@invalidusers) {
839: if ($context eq 'course') {
840: $output .= '<p>'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';
841: foreach my $user (@invalidusers) {
842: $output .= '<li>'.$user.'</li>';
843: }
844: $output .= '</ul></p>';
845: }
846: }
847: if (@limitexceeded) {
848: if ($context eq 'course') {
849: $output .= '<p>'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'<ul>';
850: foreach my $user (@limitexceeded) {
851: $output .= '<li>'.$user.'</li>';
852: }
853: $output .= '</ul></p>';
854: }
855: }
1.5 raeburn 856: if (@nopermissions) {
1.12 raeburn 857: $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 858: foreach my $cnum (@nopermissions) {
859: my $showcourse;
860: if (ref($requesthash{$cnum.'_approval'})) {
861: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
862: } else {
863: $showcourse = $cnum;
864: }
865: $output .= '<li>'.$showcourse.'</li>';
866: }
867: $output .= '</ul></p>';
868: }
1.2 raeburn 869: if (@processing_errors) {
1.1 raeburn 870: if ($context eq 'course') {
871: $output .= '<p>'.&mt('The following enrollment requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 872: foreach my $user (@processing_errors) {
1.1 raeburn 873: $output .= '<li>'.$user.'</li>';
874: }
875: $output .= '</ul></p>';
876: } else {
1.12 raeburn 877: $output .= '<p>'.&mt('The following course/community creation requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 878: foreach my $cnum (@processing_errors) {
879: my $showcourse;
880: if (ref($requesthash{$cnum.'_approval'})) {
881: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
882: } else {
883: $showcourse = $cnum;
884: }
885: $output .= '<li>'.$showcourse.'</li>';
886: }
887: $output .= '</ul></p>';
1.1 raeburn 888: }
889: }
1.3 raeburn 890: if (@rejectionerrors) {
1.12 raeburn 891: $output .= '<p>'.&mt('The following course/community creation request rejections could not be fully processed because an error occurred:').'<ul>';
1.3 raeburn 892: foreach my $cnum (@rejectionerrors) {
893: my $showcourse;
894: if (ref($requesthash{$cnum.'_approval'})) {
895: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
896: } else {
897: $showcourse = $cnum;
898: }
899: $output .= '<li>'.$showcourse.'</li>';
900: }
901: $output .= '</ul></p>';
902: }
1.2 raeburn 903: if (@warn_approves || @warn_rejects) {
1.1 raeburn 904: if ($context eq 'course') {
905: $output .= '<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>';
906: foreach my $user (@warn_approves) {
907: $output .= '<li>'.$user.'</li>';
908: }
909: $output .= '</ul></p>';
910: } else {
1.12 raeburn 911: $output .= '<p>'.&mt("For the following course/community requests an error occurred when updating the requestor's own requests record:").'<ul>';
1.2 raeburn 912: foreach my $cnum (@warn_approves,@warn_rejects) {
913: my $showcourse;
914: if (ref($requesthash{$cnum.'_approval'})) {
915: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
916: } else {
917: $showcourse = $cnum;
918: }
919: $output .= '<li>'.$showcourse.'</li>';
1.1 raeburn 920: }
921: $output .= '</ul></p>';
922: }
923: }
1.12.2.1 raeburn 924: if (@warn_coursereqs) {
925: $output .= '<p>'..&mt("For the following users, an error occurred when setting rights to request creation of Concept Test courses:").'<ul>';
926: foreach my $user (@warn_coursereqs) {
927: $output .= '<li>'.$user.'</li>';
928: }
929: $output .= '</ul></p>';
930: }
1.1 raeburn 931: return $output;
932: }
933:
1.12.2.9 raeburn 934: sub enable_additional_roles {
935: my ($cdom,$cnum,$udom,$uname,$access_end,$access_start) = @_;
1.12.2.2 raeburn 936: my ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
937: if (exists($classlist->{$uname.':'.$udom})) {
938: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
939: if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
940: ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
941: return;
942: }
943: }
944: }
945: return
946: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
947: }
948:
1.1 raeburn 949: sub get_student_counts {
950: my ($cdom,$cnum) = @_;
951: my (%idx,%stucounts);
952: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
953: $idx{'type'} = &Apache::loncoursedata::CL_TYPE();
954: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
955: while (my ($student,$data) = each(%$classlist)) {
956: if (($data->[$idx{'status'}] eq 'Active') ||
957: ($data->[$idx{'status'}] eq 'Future')) {
958: if ($data->[$idx{'type'}] eq 'selfenroll') {
959: $stucounts{'selfenroll'} ++;
960: }
961: $stucounts{'allstudents'} ++;
962: }
963: }
964: return (\%stucounts,\%idx,$classlist);
965: }
966:
1.2 raeburn 967: sub course_creation {
968: my ($dom,$cnum,$context,$details,$logmsg,$newusermsg,$addresult,$enrollcount,$output,
969: $keysmsg,$domdefs,$longroles) = @_;
970: unless ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH') &&
971: (ref($longroles) eq 'HASH')) {
972: return 'error: Invalid request';
973: }
974: my ($result,$ownername,$ownerdom);
975: my $crstype = $details->{'crstype'};
976: if ($context eq 'domain') {
977: $ownername = $details->{'owner'};
978: $ownerdom = $details->{'domain'};
979: } else {
980: $ownername = $env{'user.name'};
981: $ownerdom = $env{'user.domain'};
982: }
983: my $owneremail;
984: my %emails = &Apache::loncommon::getemails($ownername,$ownerdom);
985: foreach my $email ('permanentemail','critnotification','notification') {
986: $owneremail = $emails{$email};
987: last if ($owneremail ne '');
988: }
1.8 raeburn 989: my %reqdetails = &build_batchcreatehash($dom,$context,$details,$owneremail,$domdefs);
1.2 raeburn 990: my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',
1.12.2.8 raeburn 991: \%reqdetails,$longroles,$logmsg,$newusermsg,$addresult,
992: $enrollcount,$output,$keysmsg,$ownerdom,$ownername,$cnum,$crstype);
1.2 raeburn 993: if ($cid eq "/$dom/$cnum") {
994: $result = 'created';
995: } else {
996: $result = 'error: '.$cid;
997: }
998: return $result;
999: }
1000:
1001: sub build_batchcreatehash {
1.8 raeburn 1002: my ($dom,$context,$details,$owneremail,$domdefs) = @_;
1.2 raeburn 1003: my %batchhash;
1.12.2.8 raeburn 1004: my @items = qw{owner domain coursehome clonecrs clonedom cloneroster datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users};
1.12.2.10! raeburn 1005: if ($dom =~ /^\w+citest$/) {
1.12.2.3 raeburn 1006: push(@items,'firstres');
1007: }
1.2 raeburn 1008: if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
1.12.2.8 raeburn 1009: my $emailenc = &escape($owneremail);
1.2 raeburn 1010: my $owner = $details->{'owner'}.':'.$details->{'domain'};
1011: foreach my $item (@items) {
1012: $batchhash{$item} = $details->{$item};
1013: }
1014: $batchhash{'title'} = $details->{'cdescr'};
1015: $batchhash{'coursecode'} = $details->{'instcode'};
1016: $batchhash{'emailenc'} = $emailenc;
1017: $batchhash{'adds'} = $details->{'autoadds'};
1018: $batchhash{'drops'} = $details->{'autodrops'};
1019: $batchhash{'authtype'} = $domdefs->{'auth_def'};
1020: $batchhash{'authparam'} = $domdefs->{'auth_arg_def'};
1021: if ($details->{'crstype'} eq 'community') {
1022: $batchhash{'crstype'} = 'Community';
1023: } else {
1024: $batchhash{'crstype'} = 'Course';
1025: }
1.8 raeburn 1026: my ($owner_firstname,$owner_lastname);
1027: if ($context eq 'domain') {
1028: my %userenv = &Apache::lonnet::userenvironment($details->{'domain'},
1029: $details->{'owner'},
1030: 'firstname','lastname');
1031: $owner_firstname = $userenv{'firstname'};
1032: $owner_lastname = $userenv{'lastname'};
1033: } else {
1034: $owner_firstname = $env{'environment.firstname'};
1035: $owner_lastname = $env{'environment.lastname'};
1036: }
1037: if (ref($details->{'personnel'}) eq 'HASH') {
1038: %{$batchhash{'users'}} = %{$details->{'personnel'}};
1039: if (ref($batchhash{'users'}) eq 'HASH') {
1040: foreach my $userkey (keys(%{$batchhash{'users'}})) {
1041: if (ref($batchhash{'users'}{$userkey}) eq 'HASH') {
1042: if (ref($batchhash{'users'}{$userkey}{'roles'}) eq 'ARRAY') {
1043: foreach my $role (@{$batchhash{'users'}{$userkey}{'roles'}}) {
1044: my $start = '';
1045: my $end = '';
1046: if ($role eq 'st') {
1047: $start = $details->{'accessstart'};
1048: $end = $details->{'accessend'};
1049: }
1050: $batchhash{'users'}{$userkey}{$role}{'start'} = $start;
1051: $batchhash{'users'}{$userkey}{$role}{'end'} = $end;
1052: }
1053: }
1054: }
1055: }
1056: }
1057: }
1058: $batchhash{'users'}{$owner}{firstname} = $owner_firstname;
1059: $batchhash{'users'}{$owner}{lastname} = $owner_lastname;
1060: $batchhash{'users'}{$owner}{emailenc} = $emailenc;
1061: $batchhash{'users'}{$owner}{owneremail} = $owneremail;
1.2 raeburn 1062: }
1063: return %batchhash;
1064: }
1065:
1.4 raeburn 1066: sub can_clone_course {
1.11 raeburn 1067: my ($uname,$udom,$clonecrs,$clonedom,$crstype) = @_;
1.4 raeburn 1068: my $canclone;
1.11 raeburn 1069: my $ccrole = 'cc';
1.12 raeburn 1070: if ($crstype eq 'community') {
1.11 raeburn 1071: $ccrole = 'co';
1072: }
1.4 raeburn 1073: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',['active'],
1.11 raeburn 1074: [$ccrole],[$clonedom]);
1075: if (exists($roleshash{$clonecrs.':'.$clonedom.':'.$ccrole})) {
1.4 raeburn 1076: $canclone = 1;
1077: } else {
1078: my %courseenv = &Apache::lonnet::userenvironment($clonedom,$clonecrs,('cloners'));
1079: my $cloners = $courseenv{'cloners'};
1080: if ($cloners ne '') {
1081: my @cloneable = split(',',$cloners);
1082: if (grep(/^\*$/,@cloneable)) {
1083: $canclone = 1;
1084: }
1085: if (grep(/^\*:\Q$udom\E$/,@cloneable)) {
1086: $canclone = 1;
1087: }
1088: if (grep(/^\Q$uname\E:\Q$udom\E$/,@cloneable)) {
1089: $canclone = 1;
1090: }
1091: }
1.12.2.8 raeburn 1092: unless ($canclone) {
1093: if (&Apache::lonnet::is_course_owner($clonedom,$clonecrs,$uname,$udom)) {
1094: $canclone = 1;
1095: }
1096: }
1.4 raeburn 1097: }
1098: return $canclone;
1099: }
1100:
1.12.2.5 raeburn 1101: sub queued_selfenrollment {
1102: my ($notitle) = @_;
1103: my $output;
1104: my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests');
1105: my %reqs_by_date;
1106: foreach my $item (keys(%selfenrollrequests)) {
1107: if (ref($selfenrollrequests{$item}) eq 'HASH') {
1108: if ($selfenrollrequests{$item}{'status'} eq 'request') {
1109: if ($selfenrollrequests{$item}{'timestamp'}) {
1110: push(@{$reqs_by_date{$selfenrollrequests{$item}{'timestamp'}}},$item);
1111: }
1112: }
1113: }
1114: }
1115: if (keys(%reqs_by_date)) {
1116: unless ($notitle) {
1117: $output .= '<b>'.&mt('Enrollment requests pending Course Coordinator approval').'</b><br />';
1118: }
1119: $output .= &Apache::loncommon::start_data_table().
1120: &Apache::loncommon::start_data_table_header_row().
1121: '<th>'.&mt('Date requested').'</th><th>'.&mt('Course title').'</th>'.
1122: '<th>'.&mt('User role').'</th><th>'.&mt('Section').'</th>'.
1123: &Apache::loncommon::end_data_table_header_row();
1124: my @sorted = sort { $a <=> $b } (keys(%reqs_by_date));
1125: foreach my $item (@sorted) {
1126: if (ref($reqs_by_date{$item}) eq 'ARRAY') {
1127: foreach my $crs (@{$reqs_by_date{$item}}) {
1128: my %courseinfo = &Apache::lonnet::coursedescription($crs);
1129: my $usec = $selfenrollrequests{$crs}{'section'};
1.12.2.7 raeburn 1130: my $rolename = &Apache::lonnet::plaintext('st',$courseinfo{'type'},$crs);
1.12.2.5 raeburn 1131: if ($usec eq '') {
1132: $usec = &mt('No section');
1133: }
1134: $output .= &Apache::loncommon::start_data_table_row().
1135: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
1136: '<td>'.$courseinfo{'description'}.'</td>'.
1137: '<td>'.$rolename.'</td><td>'.$usec.'</td>'.
1138: &Apache::loncommon::end_data_table_row();
1139: }
1140: }
1141: }
1142: $output .= &Apache::loncommon::end_data_table();
1143: }
1144: return $output;
1145: }
1146:
1.1 raeburn 1147: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>