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