Annotation of loncom/interface/loncoursequeueadmin.pm, revision 1.12.2.7
1.1 raeburn 1: # The LearningOnline Network
2: # Utilities to administer domain course requests and course self-enroll requests
3: #
1.12.2.7! raeburn 4: # $Id: loncoursequeueadmin.pm,v 1.12.2.6 2010/01/15 15:38:10 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.4 raeburn 469: my $enresult = &enable_gci_submission($udom,$uname,
470: $access_end,$access_start);
1.12.2.2 raeburn 471: }
1.1 raeburn 472: if (exists($classlist->{$uname.':'.$udom})) {
473: if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
474: if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
475: ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
476: push(@existing,$uname.':'.$udom);
477: next;
478: }
479: }
480: }
481: } else {
482: push(@missingreq,$uname.':'.$udom);
483: next;
484: }
485: if (!grep(/^\Q$item\E$/,@rejections)) {
486: if ($limit eq 'allstudents') {
487: if ($stucounts->{$limit} >= $cap) {
488: push(@limitexceeded,$uname.':'.$udom);
489: last;
490: }
491: } elsif ($limit eq 'selfenrolled') {
492: if ($stucounts->{$limit} >= $cap) {
493: push(@limitexceeded,$uname.':'.$udom);
494: last;
495: }
496: }
497: my $result =
498: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
499: if ($result eq 'ok') {
1.2 raeburn 500: push(@completed,$uname.':'.$udom);
1.1 raeburn 501: $stucounts->{'allstudents'} ++;
502: $stucounts->{'selfenrolled'} ++;
503: &send_selfserve_notification($uname.':'.$udom,$approvedmsg,
1.12 raeburn 504: $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
1.2 raeburn 505: my %userrequest = (
506: $cdom.'_'.$cnum => {
507: timestamp => $now,
508: section => $usec,
509: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
510: status => 'approved',
511: }
512: );
1.1 raeburn 513: my $userresult =
514: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
515: if ($userresult ne 'ok') {
516: push(@warn_approves,$uname.':'.$udom);
1.12.2.1 raeburn 517: } elsif ($udom eq 'gci') {
518: my %changehash = (
519: 'reqcrsotherdom.unofficial' => 'gcitest:autolimit=',
520: );
521: my $reqresult = &Apache::lonnet::put('environment',\%changehash,
522: $udom,$uname);
523: if ($reqresult ne 'ok') {
524: push(@warn_coursereqs,$uname.':'.$udom);
525: }
1.1 raeburn 526: }
527: } else {
1.2 raeburn 528: push(@processing_errors,$uname.':'.$udom);
1.1 raeburn 529: }
530: }
531: } else {
532: push(@invalidusers,$uname.':'.$udom);
533: }
534: } else {
1.2 raeburn 535: my ($num,$cnum) = split(':',$item);
536: if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
537: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
538: my $ownername = $requesthash{$cnum.'_approval'}{'ownername'};
539: my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'};
1.12 raeburn 540: $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
1.2 raeburn 541: my $coursedesc = $requesthash{$cnum.'_approval'}{'description'};
542: my $longroles = \%courseroles;
543: if ($crstype eq 'community') {
544: $longroles = \%communityroles;
545: }
1.5 raeburn 546: my $cancreate;
547: if ($cdom eq $ownerdom) {
548: if (&Apache::lonnet::usertools_access($ownername,$ownerdom,$crstype,
549: undef,'requestcourses')) {
550: $cancreate = 1;
551: }
552: } else {
553: my %userenv = &Apache::lonnet::userenvironment($ownerdom,$ownername,'reqcrsotherdom.'.$crstype);
554: if ($userenv{'reqcrsotherdom.'.$crstype}) {
555: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
556: if (grep(/^\Q$cdom\E:/,@doms)) {
557: $cancreate = 1;
558: }
559: }
560: }
561: if ($cancreate) {
1.2 raeburn 562: my $requestkey = $cdom.'_'.$cnum;
563: my %history =
564: &Apache::lonnet::restore($requestkey,'courserequests',
565: $ownerdom,$ownername);
566: if ((ref($history{'details'}) eq 'HASH') &&
567: ($history{'disposition'} eq 'approval')) {
568: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);
569: my $result = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg,
570: \$newusermsg,\$addresult,\$enrollcount,
571: \$response,\$keysmsg,\%domdefs,$longroles);
572: if ($result eq 'created') {
1.12 raeburn 573: if ($crstype eq 'community') {
574: $approvedmsg = $approvalmsg{'community'};
575: } else {
576: $approvedmsg = $approvalmsg{'course'};
577: }
1.2 raeburn 578: push(@completed,$cnum);
579: &send_selfserve_notification($ownername.':'.$ownerdom,$approvedmsg,
1.12 raeburn 580: $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
1.2 raeburn 581: my %reqhash = (
582: reqtime => $history{'reqtime'},
583: crstype => $history{'crstype'},
584: details => $history{'details'},
585: disposition => $history{'disposition'},
586: status => 'created',
587: adjudicator => $env{'user.name'}.':'.
588: $env{'user.domain'},
589: );
590: my $userresult =
591: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
592: 'courserequests',$ownerdom,$ownername);
593: if ($userresult eq 'ok') {
594: my %status = (
595: 'status:'.$cdom.':'.$cnum => 'created'
596: );
597: my $statusresult =
598: &Apache::lonnet::put('courserequests',\%status,
599: $ownerdom,$ownername);
600: if ($statusresult ne 'ok') {
601: push(@warn_approves,$cnum);
602: }
603: }
604: if ($userresult ne 'ok') {
605: push(@warn_approves,$cnum);
606: }
607: } else {
608: push(@processing_errors,$cnum);
609: }
610: } else {
611: push(@processing_errors,$cnum);
612: }
613: } else {
1.5 raeburn 614: push(@nopermissions,$cnum);
1.2 raeburn 615: }
616: } else {
617: push(@existing,$cnum);
618: }
619: } else {
620: push(@missingreq,$cnum);
621: }
1.1 raeburn 622: }
623: }
1.2 raeburn 624: my @changes = (@completed,@rejections);
625: if ($context eq 'domain') {
626: @changes = map {$_.'_approval'} (@changes);
627: }
1.1 raeburn 628: if (@rejections) {
1.3 raeburn 629: foreach my $item (@rejections) {
1.1 raeburn 630: if ($context eq 'course') {
1.3 raeburn 631: my $user = $item;
1.2 raeburn 632: &send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc,
1.12 raeburn 633: $now,$beneficiary,$sender,undef,undef,$crstype);
1.1 raeburn 634: my ($uname,$udom) = split(/:/,$user);
635: my %userrequest = (
636: $cdom.'_'.$cnum => {
637: timestamp => $now,
638: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
639: status => 'rejected',
640: }
641: );
642: my $userresult =
643: &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
644: if ($userresult ne 'ok') {
645: push(@warn_rejects,$user);
646: }
647: } else {
1.3 raeburn 648: my $cnum = $item;
649: if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
650: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
651: my $requestkey = $cdom.'_'.$cnum;
1.2 raeburn 652: my $ownername = $requesthash{$cnum.'_approval'}{'ownername'};
653: my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'};
654: my $coursedesc = $requesthash{$cnum.'_approval'}{'description'};
1.12 raeburn 655: $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
656: if ($crstype eq 'community') {
657: $rejectedmsg = $rejectionmsg{'community'};
658: } else {
659: $rejectedmsg = $rejectionmsg{'course'};
660: }
1.2 raeburn 661: &send_selfserve_notification($ownername.':'.$ownerdom,$rejectedmsg,
662: $cid,$coursedesc,$now,$beneficiary,
1.12 raeburn 663: $sender,undef,undef,$crstype);
1.2 raeburn 664: my %history =
1.3 raeburn 665: &Apache::lonnet::restore($requestkey,'courserequests',
1.2 raeburn 666: $ownerdom,$ownername);
667: if ((ref($history{'details'}) eq 'HASH') &&
668: ($history{'disposition'} eq 'approval')) {
669: my %reqhash = (
670: reqtime => $history{'reqtime'},
671: crstype => $history{'crstype'},
672: details => $history{'details'},
673: disposition => $history{'disposition'},
674: status => 'rejected',
675: adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
676: );
677: my $userresult =
1.3 raeburn 678: &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
679: 'courserequests',$ownerdom,$ownername);
680: if ($userresult eq 'ok') {
681: my %status = (
682: 'status:'.$cdom.':'.$cnum => 'rejected'
683: );
684: my $statusresult =
685: &Apache::lonnet::put('courserequests',\%status,
686: $ownerdom,$ownername);
687: if ($statusresult ne 'ok') {
688: push(@warn_rejects,$cnum);
689: }
690: } else {
691: push(@warn_rejects,$cnum);
1.2 raeburn 692: }
1.3 raeburn 693: } else {
694: push(@warn_rejects,$cnum);
1.2 raeburn 695: }
1.3 raeburn 696: } else {
697: push(@existing,$cnum);
1.2 raeburn 698: }
1.3 raeburn 699: } else {
700: push(@rejectionerrors,$cnum);
1.2 raeburn 701: }
1.1 raeburn 702: }
703: }
704: }
705: if (@changes) {
706: my $delresult;
707: if ($context eq 'course') {
708: $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
709: } else {
710: $delresult = &Apache::lonnet::del_dom($namespace,\@changes,$cdom);
711: }
712: if ($delresult eq 'ok') {
713: my $namelink =
714: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
715: my ($chgmsg,$approvedlist,$rejectedlist);
716: if ($context eq 'course') {
717: $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
1.2 raeburn 718: if (@completed) {
719: $approvedlist = join("\n",@completed);
1.12 raeburn 720: if ($crstype eq 'community') {
721: $output .= '<p>'.&mt('The following were enrolled in the community:').'<ul>';
722: } else {
723: $output .= '<p>'.&mt('The following were enrolled in the course:').'<ul>';
724: }
1.2 raeburn 725: foreach my $user (@completed) {
1.1 raeburn 726: my ($uname,$udom) = split(/:/,$user);
727: my $userlink =
728: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
729: $output .= '<li>'.$userlink.'</li>';
730: }
731: $output .= '</ul></p>';
732: }
733: if (@rejections) {
734: $rejectedlist = join("\n",@rejections);
735: $output .= '<p>'.&mt('The following enrollment requests were rejected:').'<ul>';
736: foreach my $user (@rejections) {
737: $output .= '<li>'.$user.'</li>';
738: }
739: $output .= '</ul></p>';
740: }
1.2 raeburn 741: if ($notifylist ne '') {
742: &send_selfserve_notification($notifylist,$chgmsg,$cid,$coursedesc,
743: $now,'coursemanagers',$sender,
1.12 raeburn 744: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 745: }
1.1 raeburn 746: } else {
1.12 raeburn 747: $chgmsg = "'Action was taken on the following course and community requests by [_1].',$namelink";
1.2 raeburn 748: if (@completed) {
749: $approvedlist = join("\n",@completed);
1.12 raeburn 750: $output .= '<p>'.&mt('The following courses/communities were created:').'<ul>';
1.2 raeburn 751: foreach my $cnum (@completed) {
752: my $showcourse;
753: if (ref($requesthash{$cnum.'_approval'})) {
754: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
755: } else {
756: $showcourse = $cnum;
757: }
758: my $syllabuslink =
759: &Apache::loncommon::syllabuswrapper($showcourse,$cnum,$cdom);
760: $output .= '<li>'.$syllabuslink.'</li>';
761: }
762: $output .= '</ul></p>';
763: }
764: if (@rejections) {
765: $rejectedlist = join("\n",@rejections);
766: $output .= '<p>'.&mt('The following requests were rejected:').'<ul>';
767: foreach my $cnum (@rejections) {
768: my $showcourse;
769: if (ref($requesthash{$cnum.'_approval'})) {
770: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
771: } else {
772: $showcourse = $cnum;
773: }
774: $output .= '<li>'.$showcourse.'</li>';
775: }
776: $output .= '</ul></p>';
777: }
778: if ($notifylist ne '') {
779: &send_selfserve_notification($notifylist,$chgmsg,$cid,$domdesc,
780: $now,'domainmanagers',$sender,
1.12 raeburn 781: $approvedlist,$rejectedlist,$crstype);
1.2 raeburn 782: }
1.1 raeburn 783: }
784: }
785: }
786: if (@existing) {
787: if ($context eq 'course') {
788: $output .= '<p>'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'<ul>';
789: foreach my $user (@existing) {
790: $output .= '<li>'.$user.'</li>';
791: }
792: $output .= '</ul></p>';
793: } else {
1.12 raeburn 794: $output .= '<p>'.&mt('The following course/community creation requests were deleted because the course or community has already been created:').'<ul>';
1.2 raeburn 795: foreach my $cnum (@existing) {
796: my $showcourse;
797: my %coursehash = &Apache::lonnet::coursedescription($cdom.'/'.$cnum);
798: if ($coursehash{'description'} ne '') {
799: $showcourse = $coursehash{'description'};
800: } else {
801: $showcourse = $cnum;
802: }
803: $output .= '<li>'.$showcourse.'</li>';
804: }
805: $output .= '</ul></p>';
1.1 raeburn 806: }
807: }
808: if (@missingreq) {
809: if ($context eq 'course') {
810: $output .= '<p>'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'<ul>';
811: foreach my $user (@missingreq) {
812: $output .= '<li>'.$user.'</li>';
813: }
814: $output .= '</ul></p>';
1.2 raeburn 815: } else {
1.12 raeburn 816: $output .= '<p>'.&mt('The following course/community creation requests were ignored because the request is no longer in the queue:').'<ul>';
1.2 raeburn 817: foreach my $cnum (@missingreq) {
818: $output .= '<li>'.$cnum.'</li>';
819: }
820: $output .= '</ul></p>';
821:
1.1 raeburn 822: }
823: }
824: if (@invalidusers) {
825: if ($context eq 'course') {
826: $output .= '<p>'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';
827: foreach my $user (@invalidusers) {
828: $output .= '<li>'.$user.'</li>';
829: }
830: $output .= '</ul></p>';
831: }
832: }
833: if (@limitexceeded) {
834: if ($context eq 'course') {
835: $output .= '<p>'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'<ul>';
836: foreach my $user (@limitexceeded) {
837: $output .= '<li>'.$user.'</li>';
838: }
839: $output .= '</ul></p>';
840: }
841: }
1.5 raeburn 842: if (@nopermissions) {
1.12 raeburn 843: $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 844: foreach my $cnum (@nopermissions) {
845: my $showcourse;
846: if (ref($requesthash{$cnum.'_approval'})) {
847: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
848: } else {
849: $showcourse = $cnum;
850: }
851: $output .= '<li>'.$showcourse.'</li>';
852: }
853: $output .= '</ul></p>';
854: }
1.2 raeburn 855: if (@processing_errors) {
1.1 raeburn 856: if ($context eq 'course') {
857: $output .= '<p>'.&mt('The following enrollment requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 858: foreach my $user (@processing_errors) {
1.1 raeburn 859: $output .= '<li>'.$user.'</li>';
860: }
861: $output .= '</ul></p>';
862: } else {
1.12 raeburn 863: $output .= '<p>'.&mt('The following course/community creation requests could not be processed because an error occurred:').'<ul>';
1.2 raeburn 864: foreach my $cnum (@processing_errors) {
865: my $showcourse;
866: if (ref($requesthash{$cnum.'_approval'})) {
867: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
868: } else {
869: $showcourse = $cnum;
870: }
871: $output .= '<li>'.$showcourse.'</li>';
872: }
873: $output .= '</ul></p>';
1.1 raeburn 874: }
875: }
1.3 raeburn 876: if (@rejectionerrors) {
1.12 raeburn 877: $output .= '<p>'.&mt('The following course/community creation request rejections could not be fully processed because an error occurred:').'<ul>';
1.3 raeburn 878: foreach my $cnum (@rejectionerrors) {
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>';
888: }
1.2 raeburn 889: if (@warn_approves || @warn_rejects) {
1.1 raeburn 890: if ($context eq 'course') {
891: $output .= '<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>';
892: foreach my $user (@warn_approves) {
893: $output .= '<li>'.$user.'</li>';
894: }
895: $output .= '</ul></p>';
896: } else {
1.12 raeburn 897: $output .= '<p>'.&mt("For the following course/community requests an error occurred when updating the requestor's own requests record:").'<ul>';
1.2 raeburn 898: foreach my $cnum (@warn_approves,@warn_rejects) {
899: my $showcourse;
900: if (ref($requesthash{$cnum.'_approval'})) {
901: $showcourse = $requesthash{$cnum.'_approval'}{'description'};
902: } else {
903: $showcourse = $cnum;
904: }
905: $output .= '<li>'.$showcourse.'</li>';
1.1 raeburn 906: }
907: $output .= '</ul></p>';
908: }
909: }
1.12.2.1 raeburn 910: if (@warn_coursereqs) {
911: $output .= '<p>'..&mt("For the following users, an error occurred when setting rights to request creation of Concept Test courses:").'<ul>';
912: foreach my $user (@warn_coursereqs) {
913: $output .= '<li>'.$user.'</li>';
914: }
915: $output .= '</ul></p>';
916: }
1.1 raeburn 917: return $output;
918: }
919:
1.12.2.2 raeburn 920: sub enable_gci_submission {
921: my ($udom,$uname,$access_end,$access_start) = @_;
922: my $cdom = 'gci';
923: my $cnum = '1H96711d710194bfegcil1';
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',
979: \%reqdetails,$longroles,\$logmsg,\$newusermsg,\$addresult,
980: \$enrollcount,\$output,\$keysmsg,$ownerdom,$ownername,$cnum,$crstype);
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;
992: my @items = qw{owner domain coursehome clonecrs clonedom 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')) {
997: my $emailenc = &Apache::lonnet::escape($owneremail);
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: }
1080: }
1081: return $canclone;
1082: }
1083:
1.12.2.5 raeburn 1084: sub queued_selfenrollment {
1085: my ($notitle) = @_;
1086: my $output;
1087: my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests');
1088: my %reqs_by_date;
1089: foreach my $item (keys(%selfenrollrequests)) {
1090: if (ref($selfenrollrequests{$item}) eq 'HASH') {
1091: if ($selfenrollrequests{$item}{'status'} eq 'request') {
1092: if ($selfenrollrequests{$item}{'timestamp'}) {
1093: push(@{$reqs_by_date{$selfenrollrequests{$item}{'timestamp'}}},$item);
1094: }
1095: }
1096: }
1097: }
1098: if (keys(%reqs_by_date)) {
1099: unless ($notitle) {
1100: $output .= '<b>'.&mt('Enrollment requests pending Course Coordinator approval').'</b><br />';
1101: }
1102: $output .= &Apache::loncommon::start_data_table().
1103: &Apache::loncommon::start_data_table_header_row().
1104: '<th>'.&mt('Date requested').'</th><th>'.&mt('Course title').'</th>'.
1105: '<th>'.&mt('User role').'</th><th>'.&mt('Section').'</th>'.
1106: &Apache::loncommon::end_data_table_header_row();
1107: my @sorted = sort { $a <=> $b } (keys(%reqs_by_date));
1108: foreach my $item (@sorted) {
1109: if (ref($reqs_by_date{$item}) eq 'ARRAY') {
1110: foreach my $crs (@{$reqs_by_date{$item}}) {
1111: my %courseinfo = &Apache::lonnet::coursedescription($crs);
1112: my $usec = $selfenrollrequests{$crs}{'section'};
1.12.2.7! raeburn 1113: my $rolename = &Apache::lonnet::plaintext('st',$courseinfo{'type'},$crs);
1.12.2.5 raeburn 1114: if ($usec eq '') {
1115: $usec = &mt('No section');
1116: }
1117: $output .= &Apache::loncommon::start_data_table_row().
1118: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
1119: '<td>'.$courseinfo{'description'}.'</td>'.
1120: '<td>'.$rolename.'</td><td>'.$usec.'</td>'.
1121: &Apache::loncommon::end_data_table_row();
1122: }
1123: }
1124: }
1125: $output .= &Apache::loncommon::end_data_table();
1126: }
1127: return $output;
1128: }
1129:
1.1 raeburn 1130: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>