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