File:
[LON-CAPA] /
loncom /
interface /
lonrequestcourse.pm
Revision
1.49:
download - view:
text,
annotated -
select for diffs
Tue Mar 30 15:01:17 2010 UTC (14 years, 4 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Default for cloning radiobutton to "No".
- Fix args in call to &header() when displaying warning message when displaying
existing request.
- Change args passed to &sorted_request_history()
- replace third and fourth args with a single arg (ref to Hash of current filters (status, before, after, crstype).
- Check for form.queue (either approval or pending) to allow manual approval/rejection official courses pendng validation of instructor of record.
1: # The LearningOnline Network
2: # Request a course
3: #
4: # $Id: lonrequestcourse.pm,v 1.49 2010/03/30 15:01:17 raeburn Exp $
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::lonrequestcourse.pm
33:
34: =head1 SYNOPSIS
35:
36: Allows users to request creation of new courses.
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 handler()
46:
47: =item get_breadcrumbs()
48:
49: =item header()
50:
51: =item form_elements()
52:
53: =item onload_action()
54:
55: =item print_main_menu()
56:
57: =item request_administration()
58:
59: =item close_popup_form()
60:
61: =item get_instcode()
62:
63: =item print_request_form()
64:
65: =item print_enrollment_menu()
66:
67: =item show_invalid_crosslists()
68:
69: =item inst_section_selector()
70:
71: =item date_setting_table()
72:
73: =item print_personnel_menu()
74:
75: =item print_request_status()
76:
77: =item print_request_logs()
78:
79: =item print_review()
80:
81: =item dates_from_form()
82:
83: =item courseinfo_form()
84:
85: =item clone_form()
86:
87: =item clone_text()
88:
89: =item coursecode_form()
90:
91: =item get_course_dom()
92:
93: =item display_navbuttons()
94:
95: =item print_request_outcome()
96:
97: =item check_autolimit()
98:
99: =item retrieve_settings()
100:
101: =item get_request_settings()
102:
103: =item extract_instcode()
104:
105: =item generate_date_items()
106:
107: =back
108:
109: =cut
110:
111: package Apache::lonrequestcourse;
112:
113: use strict;
114: use Apache::Constants qw(:common :http);
115: use Apache::lonnet;
116: use Apache::loncommon;
117: use Apache::lonlocal;
118: use Apache::loncoursequeueadmin;
119: use Apache::lonuserutils;
120: use LONCAPA qw(:DEFAULT :match);
121:
122: sub handler {
123: my ($r) = @_;
124: &Apache::loncommon::content_type($r,'text/html');
125: $r->send_http_header;
126: if ($r->header_only) {
127: return OK;
128: }
129:
130: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
131: ['action','showdom','cnum','state','crstype','queue']);
132: &Apache::lonhtmlcommon::clear_breadcrumbs();
133: my $dom = &get_course_dom();
134: my $action = $env{'form.action'};
135: my $state = $env{'form.state'};
136: my (%states,%stored);
137: my ($jscript,$uname,$udom,$result,$warning);
138:
139: $states{'display'} = ['details'];
140: $states{'view'} = ['pick_request','details','cancel','removal'];
141: $states{'log'} = ['display'];
142: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
143:
144: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
145: unless ($env{'form.state'} eq 'crstype') {
146: unshift(@{$states{'new'}},'codepick');
147: }
148: }
149:
150: foreach my $key (keys(%states)) {
151: if (ref($states{$key}) eq 'ARRAY') {
152: unshift (@{$states{$key}},'crstype');
153: }
154: }
155:
156: my @invalidcrosslist;
157: my %trail = (
158: crstype => 'Request Action',
159: codepick => 'Category',
160: courseinfo => 'Description',
161: enrollment => 'Access Dates',
162: personnel => 'Personnel',
163: review => 'Review',
164: process => 'Result',
165: pick_request => 'Display Summary',
166: details => 'Request Details',
167: cancel => 'Cancel Request',
168: removal => 'Outcome',
169: display => 'Request Logs',
170: );
171:
172: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
173: $trail{'enrollment'} = 'Enrollment';
174: }
175:
176: my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) =
177: &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
178: if ($action eq 'display') {
179: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
180: if ($env{'form.cnum'} ne '') {
181: my $cnum = $env{'form.cnum'};
182: my $queue = $env{'form.queue'};
183: my $reqkey = $cnum.'_'.$queue;
184: my $namespace = 'courserequestqueue';
185: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
186: my %queued =
187: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
188: if (ref($queued{$reqkey}) eq 'HASH') {
189: $uname = $queued{$reqkey}{'ownername'};
190: $udom = $queued{$reqkey}{'ownerdom'};
191: if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
192: $result = &retrieve_settings($dom,$cnum,$udom,$uname);
193: } else {
194: if ($env{'form.crstype'} eq 'community') {
195: $warning = &mt('Invalid username or domain for community requestor');
196: } else {
197: $warning = &mt('Invalid username or domain for course requestor');
198: }
199: }
200: } else {
201: if ($env{'form.crstype'} eq 'community') {
202: $warning = &mt('No information was found for this community request.');
203: } else {
204: $warning = &mt('No information was found for this course request.');
205: }
206: }
207: } else {
208: $warning = &mt('No course request ID provided.');
209: }
210: } else {
211: if ($env{'form.crstype'} eq 'any') {
212: $warning = &mt('You do not have rights to view course or community request information.');
213: } elsif ($env{'form.crstype'} eq 'community') {
214: $warning = &mt('You do not have rights to view community request information.');
215: } else {
216: $warning = &mt('You do not have rights to view course request information.');
217: }
218: }
219: } elsif ((defined($state)) && (defined($action))) {
220: if (($action eq 'view') && ($state eq 'details')) {
221: if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
222: my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
223: }
224: } elsif ($env{'form.crstype'} eq 'official') {
225: if (&Apache::lonnet::auto_run('',$dom)) {
226: if (($action eq 'new') && (($state eq 'enrollment') ||
227: ($state eq 'personnel'))) {
228: my $checkcrosslist = 0;
229: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
230: if ($env{'form.crosslist_'.$i}) {
231: $checkcrosslist ++;
232: }
233: }
234: if ($checkcrosslist) {
235: my %codechk;
236: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
237: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
238: \%cat_titles,
239: \%cat_order,
240: \@code_order);
241: my $numtitles = scalar(@codetitles);
242: if ($numtitles) {
243: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
244: if ($env{'form.crosslist_'.$i}) {
245: my $codecheck;
246: my $crosslistcode = '';
247: foreach my $item (@code_order) {
248: $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item};
249: }
250: if ($crosslistcode ne '') {
251: ($codechk{$i}, my $rest) =
252: &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
253: }
254: unless ($codechk{$i} eq 'valid') {
255: $env{'form.crosslist_'.$i} = '';
256: push(@invalidcrosslist,$crosslistcode);
257: }
258: }
259: }
260: }
261: }
262: }
263: }
264: }
265: my %elements = &form_elements($dom);
266: my $elementsref = {};
267: if (ref($elements{$action}) eq 'HASH') {
268: if (ref($elements{$action}{$state}) eq 'HASH') {
269: $elementsref = $elements{$action}{$state};
270: }
271: }
272: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
273: $env{'form.clonedom'} = $dom;
274: }
275: if ($state eq 'crstype') {
276: $jscript = &mainmenu_javascript();
277: } else {
278: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
279: if ($state eq 'courseinfo') {
280: $jscript .= &cloning_javascript();
281: }
282: }
283: }
284:
285: if ($state eq 'personnel') {
286: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
287: }
288:
289: my $loaditems = &onload_action($action,$state);
290:
291: my (%can_request,%request_domains);
292: my $canreq =
293: &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains);
294: if ($action eq 'new') {
295: if ($canreq) {
296: if ($state eq 'crstype') {
297: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
298: $crumb,\%request_domains);
299: } else {
300: &request_administration($r,$action,$state,$page,\%states,$dom,
301: $jscript,$loaditems,$crumb,$newinstcode,
302: $codechk,$checkedcode,$description,
303: \@invalidcrosslist);
304: }
305: } else {
306: $r->print(&header('Course/Community Requests').$crumb.
307: '<div class="LC_warning">'.
308: &mt('You do not have privileges to request creation of courses or communities.').
309: '</div>'.&Apache::loncommon::end_page());
310: }
311: } elsif ($action eq 'view') {
312: if ($state eq 'crstype') {
313: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains);
314: } else {
315: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
316: $loaditems,$crumb);
317: }
318: } elsif ($action eq 'display') {
319: if ($warning ne '') {
320: my $args = { only_body => 1 };
321: $r->print(&header('Course/Community Requests','','' ,'',$args).$crumb.
322: '<h3>'.&mt('Course/Community Request Details').'</h3>'.
323: '<div class="LC_warning">'.$warning.'</div>'.
324: &close_popup_form());
325: } else {
326: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
327: $loaditems,$crumb,'','','','','',$uname,$udom);
328: }
329: } elsif ($action eq 'log') {
330: if ($state eq 'crstype') {
331: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
332: } else {
333: $jscript .= <<ENDJS;
334:
335: function backPage(formname,prevstate) {
336: formname.state.value = prevstate;
337: formname.submit();
338: }
339:
340: function setPage(formname) {
341: formname.page.value = '1';
342: return;
343: }
344:
345: ENDJS
346: &print_request_logs($r,$dom,$jscript,$loaditems,$crumb);
347: }
348: } else {
349: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
350: }
351: return OK;
352: }
353:
354: sub mainmenu_javascript {
355: return <<"END";
356: function setType(courseForm) {
357: for (var i=0; i<courseForm.crstype.length; i++) {
358: if (courseForm.crstype.options[i].value == "$env{'form.crstype'}") {
359: courseForm.crstype.options[i].selected = true;
360: } else {
361: courseForm.crstype.options[i].selected = false;
362: }
363: }
364: }
365:
366: function setAction(courseForm) {
367: for (var i=0; i<courseForm.action.length; i++) {
368: if (courseForm.action.options[i].value == "$env{'form.action'}") {
369: courseForm.action.options[i].selected = true;
370: } else {
371: courseForm.action.options[i].selected = false;
372: }
373: }
374: }
375: END
376: }
377:
378: sub cloning_javascript {
379: return <<"END";
380: function setCloneDisplay(courseForm) {
381: if (courseForm.cloning.length > 1) {
382: for (var i=0; i<courseForm.cloning.length; i++) {
383: if (courseForm.cloning[i].checked) {
384: if (courseForm.cloning[i].value == 1) {
385: document.getElementById('cloneoptions').style.display="block";;
386: }
387: }
388: }
389: }
390: }
391: END
392: }
393:
394: sub get_breadcrumbs {
395: my ($dom,$action,$state,$states,$trail) = @_;
396: my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
397: my $page = 0;
398: if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
399: if (defined($action)) {
400: my $done = 0;
401: my $i=0;
402: if (ref($states->{$action}) eq 'ARRAY') {
403: while ($i<@{$states->{$action}} && !$done) {
404: if ($states->{$action}[$i] eq $$state) {
405: $page = $i;
406: $done = 1;
407: }
408: $i++;
409: }
410: }
411: if ($env{'form.crstype'} eq 'official') {
412: if ($page > 1) {
413: if ($states->{$action}[$page-1] eq 'codepick') {
414: if ($env{'form.instcode'} eq '') {
415: ($newinstcode,$numtitles) = &get_instcode($dom);
416: if ($numtitles) {
417: if ($newinstcode eq '') {
418: $$state = 'codepick';
419: $page --;
420: } else {
421: ($codechk,$description) =
422: &Apache::lonnet::auto_validate_instcode('',
423: $dom,$newinstcode);
424: if ($codechk ne 'valid') {
425: $$state = 'codepick';
426: $page --;
427: }
428: $checkedcode = 1;
429: }
430: }
431: }
432: }
433: }
434: }
435: for (my $i=0; $i<@{$states->{$action}}; $i++) {
436: if ($$state eq $states->{$action}[$i]) {
437: &Apache::lonhtmlcommon::add_breadcrumb(
438: {text=>"$trail->{$$state}"});
439: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
440: last;
441: } else {
442: if (($$state eq 'process') || ($$state eq 'removal')) {
443: &Apache::lonhtmlcommon::add_breadcrumb(
444: { href => '/adm/requestcourse',
445: text => "$trail->{$states->{$action}[$i]}",
446: }
447: );
448: } else {
449: &Apache::lonhtmlcommon::add_breadcrumb(
450: { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')",
451: text => "$trail->{$states->{$action}[$i]}", }
452: );
453: }
454: }
455: }
456: } else {
457: &Apache::lonhtmlcommon::add_breadcrumb(
458: {text=>'Pick Action'});
459: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
460: }
461: } else {
462: &Apache::lonhtmlcommon::add_breadcrumb(
463: {text=>'Pick Action'});
464: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
465: }
466: return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
467: }
468:
469: sub header {
470: my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
471: if ($jscript) {
472: $jscript = '<script type="text/javascript">'."\n".
473: '// <![CDATA['."\n".
474: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
475: }
476: if ($loaditems) {
477: if (ref($args) eq 'HASH') {
478: my %loadhash = (
479: 'add_entries' => $loaditems,
480: );
481: my %arghash = (%loadhash,%{$args});
482: $args = \%arghash;
483: } else {
484: $args = {'add_entries' => $loaditems,};
485: }
486: }
487: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
488: }
489:
490: sub form_elements {
491: my ($dom) = @_;
492: my %elements =
493: (
494: new => {
495: crstype => {
496: crstype => 'selectbox',
497: action => 'selectbox',
498: origcnum => 'hidden',
499: },
500: courseinfo => {
501: cdescr => 'text',
502: cloning => 'radio',
503: clonecrs => 'text',
504: clonedom => 'selectbox',
505: datemode => 'radio',
506: dateshift => 'text',
507: },
508: enrollment => {
509: accessstart_month => 'selectbox',
510: accessstart_hour => 'selectbox',
511: accessend_month => 'selectbox',
512: accessend_hour => 'selectbox',
513: accessstart_day => 'text',
514: accessstart_year => 'text',
515: accessstart_minute => 'text',
516: accessstart_second => 'text',
517: accessend_day => 'text',
518: accessend_year => 'text',
519: accessend_minute => 'text',
520: accessend_second => 'text',
521: no_end_date => 'checkbox',
522: },
523: personnel => {
524: addperson => 'checkbox',
525: },
526: review => {
527: cnum => 'hidden',
528: },
529: },
530: view => {
531: crstype => {
532: crstype => 'selectbox',
533: action => 'selectbox',
534: },
535: },
536: );
537: my %servers = &Apache::lonnet::get_servers($dom,'library');
538: my $numlib = keys(%servers);
539: if ($numlib > 1) {
540: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
541: } else {
542: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
543: }
544: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
545: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
546: \%cat_order,\@code_order);
547: my $numtitles = scalar(@codetitles);
548: if ($numtitles) {
549: my %extras;
550: $lastitem = pop(@codetitles);
551: $extras{'instcode_'.$lastitem} = 'text';
552: foreach my $item (@codetitles) {
553: $extras{'instcode_'.$item} = 'selectbox';
554: }
555: $elements{'new'}{'codepick'} = \%extras;
556: }
557: if (&Apache::lonnet::auto_run('',$dom)) {
558: my %extras = (
559: sectotal => 'hidden',
560: enrollstart_month => 'selectbox',
561: enrollstart_hour => 'selectbox',
562: enrollend_month => 'selectbox',
563: enrollend_hour => 'selectbox',
564: enrollstart_day => 'text',
565: enrollstart_year => 'text',
566: enrollstart_minute => 'text',
567: enrollstart_second => 'text',
568: enrollend_day => 'text',
569: enrollend_year => 'text',
570: enrollend_minute => 'text',
571: enrollend_second => 'text',
572: addcrosslist => 'checkbox',
573: autoadds => 'radio',
574: autodrops => 'radio',
575: );
576: if ($env{'form.sectotal'} > 0) {
577: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
578: $extras{'sec_'.$i} = 'radio';
579: $extras{'secnum_'.$i} = 'text';
580: $extras{'loncapasec_'.$i} = 'text';
581: }
582: }
583: my $crosslisttotal = $env{'form.crosslisttotal'};
584: if ($env{'form.addcrosslist'}) {
585: $crosslisttotal ++;
586: }
587: if (!$crosslisttotal) {
588: $crosslisttotal = 1;
589: }
590:
591: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
592: if ($numtitles) {
593: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
594: }
595: if (@codetitles > 0) {
596: foreach my $item (@codetitles) {
597: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
598: }
599: }
600: $extras{'crosslist_'.$i} = 'checkbox';
601: $extras{'crosslist_'.$i.'_instsec'} = 'text',
602: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
603: }
604: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
605: %{$elements{'new'}{'enrollment'}} = %mergedhash;
606: }
607: my %people;
608: my $persontotal = $env{'form.persontotal'};
609: if ($env{'form.addperson'}) {
610: $persontotal ++;
611: }
612: if ((!defined($persontotal)) || (!$persontotal)) {
613: $persontotal = 1;
614: }
615: for (my $i=0; $i<$persontotal; $i++) {
616: $people{'person_'.$i.'_uname'} = 'text',
617: $people{'person_'.$i.'_dom'} = 'selectbox',
618: $people{'person_'.$i.'_hidedom'} = 'hidden',
619: $people{'person_'.$i.'_firstname'} = 'text',
620: $people{'person_'.$i.'_lastname'} = 'text',
621: $people{'person_'.$i.'_emailaddr'} = 'text',
622: $people{'person_'.$i.'_role'} = 'selectbox',
623: $people{'person_'.$i.'_sec'} = 'selectbox',
624: $people{'person_'.$i.'_newsec'} = 'text',
625: }
626: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
627: %{$elements{'new'}{'personnel'}} = %personnelhash;
628: return %elements;
629: }
630:
631: sub onload_action {
632: my ($action,$state) = @_;
633: my %loaditems;
634: if (($action eq 'new') || ($action eq 'view')) {
635: if ($state eq 'crstype') {
636: $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
637: } else {
638: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
639: }
640: if ($state eq 'courseinfo') {
641: $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);';
642: }
643: }
644: return \%loaditems;
645: }
646:
647: sub print_main_menu {
648: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_;
649: my ($types,$typename) = &Apache::loncommon::course_types();
650: my $onchange;
651: unless ($env{'form.interface'} eq 'textual') {
652: $onchange = 'this.form.submit()';
653: }
654:
655: my $nextstate_setter = "\n";
656: if (ref($states) eq 'HASH') {
657: foreach my $key (keys(%{$states})) {
658: if (ref($states->{$key}) eq 'ARRAY') {
659: $nextstate_setter .=
660: " if (actionchoice == '$key') {
661: nextstate = '".$states->{$key}[1]."';
662: }
663: ";
664: }
665: }
666: }
667:
668: my $js = <<"END";
669:
670: function nextPage(formname) {
671: var crschoice = document.mainmenu_coursetype.crstype.value;
672: var actionchoice = document.mainmenu_action.action.value;
673: if (check_can_request(crschoice,actionchoice) == true) {
674: if ((actionchoice == 'new') && (crschoice == 'official')) {
675: nextstate = 'codepick';
676: } else {
677: $nextstate_setter
678: }
679: formname.crstype.value = crschoice;
680: formname.action.value = actionchoice;
681: formname.state.value= nextstate;
682: formname.submit();
683: }
684: return;
685: }
686:
687: function check_can_request(crschoice,actionchoice) {
688: var official = '';
689: var unofficial = '';
690: var community = '';
691: END
692: if (ref($can_request) eq 'HASH') {
693: foreach my $item (keys(%{$can_request})) {
694: $js .= "
695: $item = 1;
696: ";
697: }
698: }
699: my %lt = &Apache::lonlocal::texthash(
700: official => 'You are not permitted to request creation of an official course in this domain.',
701: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
702: community => 'You are not permitted to request creation of a community this domain.',
703: all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
704: );
705: $js .= <<END;
706: if (crschoice == 'official') {
707: if (official != 1) {
708: alert("$lt{'official'}");
709: return false;
710: }
711: } else {
712: if (crschoice == 'unofficial') {
713: if (unofficial != 1) {
714: alert("$lt{'unofficial'}");
715: return false;
716: }
717: } else {
718: if (crschoice == 'community') {
719: if (community != 1) {
720: alert("$lt{'community'}");
721: return false;
722: }
723: } else {
724: if (actionchoice == 'new') {
725: alert("$lt{'all'}");
726: return false;
727: }
728: }
729: }
730: }
731: return true;
732: }
733: END
734: my ($pagetitle,$pageinfo,$domaintitle);
735: if (ref($can_request) eq 'HASH') {
736: if (($can_request->{'official'}) || ($can_request->{'unofficial'})) {
737: if ($can_request->{'community'}) {
738: $pagetitle = 'Course/Community Requests';
739: $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
740: $domaintitle = &mt('Course/Community Domain');
741: } else {
742: $pagetitle = 'Course Requests';
743: $pageinfo = &mt('Request creation of a new course, or review your pending course requests.');
744: $domaintitle = &mt('Course Domain');
745: }
746: } elsif ($can_request->{'community'}) {
747: $pagetitle = 'Community Requests';
748: $pageinfo = &mt('Request creation of a new course, or review your pending requests.');
749: $domaintitle = &mt('Community Domain');
750: } else {
751: $pagetitle = 'Course/Community Requests';
752: $pageinfo = &mt('You do not have rights to request creation of courses in this domain; please choose a different domain.');
753: $domaintitle = &mt('Course/Community Domain');
754: }
755: }
756: my @incdoms;
757: if (ref($request_domains) eq 'HASH') {
758: foreach my $item (keys(%{$request_domains})) {
759: if (ref($request_domains->{$item}) eq 'ARRAY') {
760: foreach my $possdom (@{$request_domains->{$item}}) {
761: unless(grep(/^\Q$possdom\E$/,@incdoms)) {
762: push(@incdoms,$possdom);
763: }
764: }
765: }
766: }
767: }
768: $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
769: '<p>'.$pageinfo.'</p>'.
770: '<div>'.
771: &Apache::lonhtmlcommon::start_pick_box().
772: &Apache::lonhtmlcommon::row_title($domaintitle).
773: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
774: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,\@incdoms));
775: if (!$onchange) {
776: $r->print(' <input type="submit" name="godom" value="'.
777: &mt('Change').'" />');
778: }
779: unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) {
780: $r->print(&Apache::lonhtmlcommon::row_closure(1)."\n".
781: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
782: &Apache::loncommon::end_page());
783: return;
784: }
785: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
786: my $formname = 'requestcrs';
787: my $nexttext = &mt('Next');
788: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
789: <form name="mainmenu_action" method="post" action="">
790: <select size="1" name="action" >
791: <option value="new">'.&mt('New request').'</option>
792: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
793: <option value="log">'.&mt('View request history').'</option>
794: </select></form>'.
795: &Apache::lonhtmlcommon::row_closure().
796: &Apache::lonhtmlcommon::row_title(&mt('Type')).'
797: <form name="mainmenu_coursetype" method="post" action="">
798: <select size="1" name="crstype">');
799: if (ref($can_request) eq 'HASH') {
800: if (keys(%{$can_request}) > 1) {
801: $r->print(' <option value="any">'.&mt('All types').'</option>');
802: }
803: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
804: foreach my $type (@{$types}) {
805: next unless($can_request->{$type});
806: my $selected = '';
807: if ($env{'form.crstype'} eq '') {
808: if ($type eq 'official') {
809: $selected = ' selected="selected"';
810: }
811: } else {
812: if ($type eq $env{'form.crstype'}) {
813: $selected = ' selected="selected"';
814: }
815: }
816: $r->print('<option value="'.$type.'"'.$selected.'>'.&mt($typename->{$type}).
817: '</option>'."\n");
818: }
819: }
820: }
821: $r->print('</select></form>'."\n".
822: &Apache::lonhtmlcommon::row_closure(1)."\n".
823: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
824: '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n".
825: '<input type="hidden" name="state" value="crstype" />'."\n".
826: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
827: '<input type="hidden" name="crstype" value="" />'."\n".
828: '<input type="hidden" name="action" value="" />'."\n".
829: '<input type="button" name="next" value="'.$nexttext.
830: '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
831: '</form></div>');
832: $r->print(&Apache::loncommon::end_page());
833: return;
834: }
835:
836: sub request_administration {
837: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
838: $newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist,
839: $uname,$udom) = @_;
840: my $js;
841: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
842: $js = <<END;
843:
844: function nextPage(formname,nextstate) {
845: formname.state.value= nextstate;
846: formname.submit();
847: }
848:
849: END
850: }
851: if (($action eq 'new') || ($action eq 'view')) {
852: $js .= <<END;
853:
854: function backPage(formname,prevstate) {
855: formname.state.value = prevstate;
856: formname.submit();
857: }
858:
859: END
860: }
861: if ($action eq 'new') {
862: my $jsextra;
863: if ($state eq 'courseinfo') {
864: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
865: } elsif ($state eq 'enrollment') {
866: if (($env{'form.crstype'} eq 'official') &&
867: (&Apache::lonnet::auto_run('',$dom))) {
868: $js .= "\n".§ion_check_javascript()."\n".&enrollment_lcsec_js();
869: }
870: } elsif ($state eq 'personnel') {
871: $js .= "\n".§ion_check_javascript()."\n".&personnel_lcsec_js();
872: }
873: my $title;
874: if ($env{'form.crstype'} eq 'community') {
875: $title = 'Request a community';
876: } else {
877: $title = 'Request a course';
878: }
879: $r->print(&header($title,$js.$jscript,$loaditems,$jsextra).$crumb);
880: &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
881: $codechk,$checkedcode,$description,$invalidcrosslist);
882: } elsif ($action eq 'view') {
883: my $jsextra;
884: my $formname = 'requestcrs';
885: my $prev = $states->{$action}[$page-1];
886: my $next = $states->{$action}[$page+1];
887: if ($state eq 'pick_request') {
888: $next = $states->{$action}[$page+1];
889: $jsextra = &viewrequest_javascript($formname,$next);
890: } elsif ($state eq 'details') {
891: $jsextra = &viewdetails_javascript($formname);
892:
893: } elsif ($state eq 'cancel') {
894: $jsextra = &viewcancel_javascript($formname);
895: }
896: my $title;
897: if ($env{'form.crstype'} eq 'community') {
898: $title = 'Manage community requests';
899: } else {
900: $title = 'Manage course requests';
901: }
902: $r->print(&header($title,$js.$jscript.$jsextra,$loaditems).$crumb);
903: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
904: if ($state eq 'pick_request') {
905: my $title;
906: if ($env{'form.crstype'} eq 'community') {
907: $title = &mt('Pending community requests');
908: } elsif ($env{'form.crstype'} eq 'official') {
909: $title = &mt('Pending requests for official courses');
910: } elsif ($env{'form.crstype'} eq 'unofficial') {
911: $title = &mt('Pending requests for unofficial courses');
912: } else {
913: $title = &mt('Pending course/community requests');
914: }
915: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
916: &print_request_status($dom,$action).'</form></div>');
917: } elsif ($state eq 'details') {
918: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
919: my $origcnum = $env{'form.cnum'};
920: if ($origcnum eq '') {
921: $origcnum = $env{'form.origcnum'};
922: }
923: if ($env{'form.crstype'} eq 'official') {
924: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
925: \%cat_order,\@code_order);
926: }
927: my $title;
928: if ($env{'form.crstype'} eq 'community') {
929: $title = &mt('Community Request Details');
930: } else {
931: $title = &mt('Course Request Details');
932: }
933: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
934: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
935: \@code_order)."\n".
936: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
937: my @excluded = &get_excluded_elements($dom,$states,'new','review');
938: push(@excluded,'origcnum');
939: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
940: my $other = 'modify';
941: my %navtxt = &Apache::lonlocal::texthash (
942: prev => 'Back',
943: other => 'Modify Request',
944: next => 'Cancel Request',
945: );
946: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
947: $navtxt{'next'},$state,$other,$navtxt{'other'});
948: $r->print('</form>');
949: } elsif ($state eq 'cancel') {
950: my $title;
951: if ($env{'form.crstype'} eq 'community') {
952: $title = &mt('Cancel community request');
953: } else {
954: $title = &mt('Cancel course request');
955: }
956: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
957: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
958: $output);
959: my @excluded = &get_excluded_elements($dom,$states,'view','cancel');
960: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
961: my %navtxt = &Apache::lonlocal::texthash (
962: prev => 'Back',
963: next => 'Confirm Cancellation',
964: );
965: if ($result eq 'ok') {
966: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
967: $navtxt{'next'},$state);
968: } else {
969: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
970: '',$state);
971: }
972: $r->print('</form>');
973: } elsif ($state eq 'removal') {
974: my $cnum = $env{'form.origcnum'};
975: my $statuskey = 'status:'.$dom.':'.$cnum;
976: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
977: $env{'user.domain'},$env{'user.name'});
978: my $currstatus = $userreqhash{$statuskey};
979: my ($result,$error);
980: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
981: my %status = (
982: $statuskey => 'cancelled',
983: );
984: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
985: if ($statusresult eq 'ok') {
986: my $delresult =
987: &Apache::lonnet::del_dom('courserequestqueue',
988: [$cnum.'_'.$currstatus],$dom);
989: if ($delresult eq 'ok') {
990: $result = 'ok';
991: } else {
992: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
993: }
994: } else {
995: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
996: }
997: } else {
998: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
999: }
1000: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
1001: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
1002: '<input type="hidden" name="action" value="'.$action.'" />'."\n".
1003: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
1004: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
1005: if ($result eq 'ok') {
1006: if ($env{'form.crstype'} eq 'community') {
1007: $r->print(&mt('Your community request has been cancelled.'));
1008: } else {
1009: $r->print(&mt('Your course request has been cancelled.'));
1010: }
1011: } else {
1012: $r->print('<div class="LC_error">'.
1013: &mt('The request cancellation process was not complete.').
1014: '<br />'.$error.'</div>');
1015: }
1016: $r->print('</form>');
1017: }
1018: } elsif ($action eq 'display') {
1019: my $formname = 'requestcrs';
1020: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1021: if ($env{'form.crstype'} eq 'official') {
1022: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1023: \%cat_order,\@code_order);
1024: }
1025: my ($title,$header);
1026: if ($env{'form.crstype'} eq 'community') {
1027: $title = 'Community Request';
1028: $header = &mt('Community Request');
1029: } else {
1030: $title = 'Course Request';
1031: $header = &mt('Course Request');
1032: }
1033: $r->print(&header($title,'','','',{ 'only_body' => 1}).
1034: $crumb."\n".'<h3>'.$header.'</h3>'.
1035: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1036: \@code_order,$uname,$udom)."\n".'</div>'.
1037: &close_popup_form());
1038: }
1039: $r->print(&Apache::loncommon::end_page());
1040: return;
1041: }
1042:
1043: sub enrollment_lcsec_js {
1044: my %alerts = §ion_check_alerts();
1045: my $secname = $alerts{'badsec'};
1046: my $secnone = $alerts{'reserved'};
1047: my $output = '
1048: function validateEnrollSections(formname,nextstate) {
1049: var badsectotal = 0;
1050: var reservedtotal = 0;
1051: var secTest = "";
1052: ';
1053: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1054: $output .= "
1055: var selSec = 0;
1056: for (var j=0; j<document.requestcrs.sec_".$i.".length; j++) {
1057: if (document.requestcrs.sec_".$i."[j].checked) {
1058: selSec = document.requestcrs.sec_".$i."[j].value;
1059: }
1060: if (selSec == 1) {
1061: secTest = validsection(document.requestcrs.loncapasec_".$i.");
1062: if (secTest == 'badsec') {
1063: badsectotal++;
1064: }
1065: if (secTest == 'reserved') {
1066: reservedtotal++;
1067: }
1068: }
1069: }
1070: ";
1071: }
1072: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1073: $output .= "
1074: if (document.requestcrs.crosslist_".$i.".checked) {
1075: secTest = validsection(document.requestcrs.crosslist_".$i."_lcsec);
1076: if (secTest == 'badsec') {
1077: badsectotal++;
1078: }
1079: if (secTest == 'reserved') {
1080: reservedtotal++;
1081: }
1082: }
1083: ";
1084: }
1085: $output .= "
1086: if (badsectotal>0) {
1087: alert('$secname');
1088: return false;
1089: }
1090: if (reservedtotal>0) {
1091: alert('$secnone');
1092: return false;
1093: }
1094: formname.state.value= nextstate;
1095: formname.submit();
1096: return;
1097: }
1098: ";
1099: return $output;
1100: }
1101:
1102: sub personnel_lcsec_js {
1103: my %alerts = §ion_check_alerts();
1104: my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'};
1105: my $secnone = $alerts{'reserved'};
1106: my $output = '
1107: function validatePersonnelSections(formname,nextstate) {
1108: var badsectotal = 0;
1109: var reservedtotal = 0;
1110: var secTest = "";
1111: ';
1112: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1113: $output .= "
1114: if (document.requestcrs.person_".$i."_uname.value != '') {
1115: secTest = validsection(document.requestcrs.person_".$i."_newsec,'1');
1116: if (secTest == 'badsec') {
1117: badsectotal++;
1118: }
1119: if (secTest == 'reserved') {
1120: reservedtotal++;
1121: }
1122: }
1123: ";
1124: }
1125: $output .= "
1126: if (badsectotal > 0) {
1127: alert('$secname');
1128: return false;
1129: } else {
1130: if (reservedtotal > 0) {
1131: alert('$secnone');
1132: return false;
1133: }
1134: }
1135: formname.state.value = nextstate;
1136: formname.submit();
1137: return;
1138: }
1139: ";
1140: return $output;
1141: }
1142:
1143: sub section_check_alerts {
1144: my %lt =
1145: &Apache::lonlocal::texthash(
1146: reserved => "You need to change one or more LON-CAPA section names - none is a reserved word in the system, and may not be used.",
1147: badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
1148: separate => 'Separate multiple sections with a comma.'
1149: );
1150: return %lt;
1151: }
1152:
1153: sub section_check_javascript {
1154: return <<"END";
1155: function validsection(field,mult) {
1156: var str = field.value;
1157: var badsec=0;
1158: var reserved=0;
1159: if (window.RegExp) {
1160: var badsecnum=0;
1161: var reservednum=0;
1162: var pattern=/[^a-zA-Z0-9]/;
1163: str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
1164: str = str.replace(/[ ]{2,}/gi," ");
1165: if (mult == '1') {
1166: var sections = new Array();
1167: sections = str.split(/\\s*[\\s,;:]\\s*/);
1168: var i;
1169: for (i=0; i<sections.length; i++) {
1170: if ((sections[i] != '') && (sections[i] != undefined) && (sections[i] != null)) {
1171: if (pattern.test(sections[i])) {
1172: badsecnum++;
1173: } else {
1174: if (sections[i] == 'none') {
1175: reservednum++;
1176: }
1177: }
1178: }
1179: }
1180: } else {
1181: if ((str != '') && (str != undefined) && (str != null)) {
1182: if (pattern.test(str)) {
1183: badsecnum++;
1184: } else {
1185: if (str == 'none') {
1186: reservednum++;
1187: }
1188: }
1189: }
1190: }
1191: if (badsecnum > 0) {
1192: return 'badsec';
1193: }
1194: if (reservednum > 0) {
1195: return 'reserved';
1196: }
1197: }
1198: return;
1199: }
1200: END
1201: }
1202:
1203: sub close_popup_form {
1204: my $close= &mt('Close Window');
1205: return << "END";
1206: <p><form name="displayreq" action="" method="post">
1207: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
1208: </form></p>
1209: END
1210: }
1211:
1212: sub get_instcode {
1213: my ($dom) = @_;
1214: my ($instcode,$numtitles);
1215: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1216: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1217: \%cat_order,\@code_order);
1218: $numtitles = scalar(@codetitles);
1219: if (@code_order > 0) {
1220: my $message;
1221: foreach my $item (@code_order) {
1222: $instcode .= $env{'form.instcode_'.$item};
1223: }
1224: }
1225: return ($instcode,$numtitles);
1226: }
1227:
1228: sub print_request_form {
1229: my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1230: $description,$invalidcrosslist) = @_;
1231: my $formname = 'requestcrs';
1232: my ($next,$prev,$message,$output,$codepicker,$crstype);
1233: $prev = $states->{$action}[$page-1];
1234: $next = $states->{$action}[$page+1];
1235: my %navtxt = &Apache::lonlocal::texthash (
1236: prev => 'Back',
1237: next => 'Next',
1238: );
1239: $crstype = $env{'form.crstype'};
1240: $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1241: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
1242: @disallowed);
1243: if ($crstype eq 'official') {
1244: if ($env{'form.instcode'} ne '') {
1245: $instcode = $env{'form.instcode'};
1246: } elsif ($newinstcode ne '') {
1247: $instcode = $newinstcode;
1248: }
1249: if ($checkedcode) {
1250: if ($codechk eq 'valid') {
1251: $message = '<div class="LC_info">'.
1252: &mt('The chosen course category [_1] is valid.','<b>'.
1253: $instcode.'</b>').
1254: '<input type="hidden" name="instcode" value="'.
1255: $instcode.'" /></div>';
1256: } else {
1257: $message = '<div class="LC_warning">'.
1258: &mt('No course was found matching your choice of institutional course category.');
1259: if ($codechk ne '') {
1260: $message .= '<br />'.$codechk;
1261: }
1262: $message .= '</div>';
1263: $prev = 'crstype';
1264: }
1265: $r->print($message);
1266: }
1267: }
1268: if ($prev eq 'crstype') {
1269: if ($crstype eq 'official') {
1270: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1271: \%cat_order,\@code_order);
1272: }
1273: if (@code_order > 0) {
1274: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
1275: \%cat_titles,\%cat_order);
1276: if ($codepicker) {
1277: $r->print(&mt('Specify the course to be created.').
1278: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1279: $codepicker.
1280: &Apache::lonhtmlcommon::end_pick_box().'</div>');
1281: } else {
1282: $next = $states->{$action}[$page+2];
1283: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1284: }
1285: } else {
1286: if ($crstype eq 'official') {
1287: $next = $states->{$action}[$page+2];
1288: }
1289: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1290: }
1291: } elsif ($prev eq 'codepick') {
1292: if ($instcode eq '') {
1293: $prev = $states->{$action}[$page-2];
1294: }
1295: $r->print(&courseinfo_form($dom,$formname,$crstype,$next,$description));
1296: } elsif ($state eq 'enrollment') {
1297: if ($crstype eq 'official') {
1298: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1299: \%cat_order,\@code_order);
1300: }
1301: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
1302: \%cat_titles,\%cat_order,\@code_order,
1303: $invalidcrosslist));
1304: } elsif ($state eq 'personnel') {
1305: $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
1306: } elsif ($state eq 'review') {
1307: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
1308: my $now = time;
1309: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1310: my $personname = $env{'form.person_'.$i.'_uname'};
1311: my $persondom = $env{'form.person_'.$i.'_dom'};
1312: if (($personname =~ /^$match_username$/) &&
1313: ($persondom =~ /^$match_domain$/)) {
1314: if (&Apache::lonnet::domain($persondom)) {
1315: my $personhome =
1316: &Apache::lonnet::homeserver($personname,$persondom);
1317: if ($personhome eq 'no_host') {
1318: if ($persondom ne $dom) {
1319: my $skipuser = 1;
1320: if ($env{'user.role.dc./'.$persondom.'/'}) {
1321: my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
1322: if (((!$start) || ($start < $now)) &&
1323: ((!$end) || ($end > $now))) {
1324: $skipuser = 0;
1325: }
1326: }
1327: if ($skipuser) {
1328: push(@disallowed,$i);
1329: $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
1330: next;
1331: }
1332: }
1333: if (&get_cancreate_status($persondom,$personname,$dom)) {
1334: my ($allowed,$msg) =
1335: &check_newuser_rules($persondom,$personname,
1336: \%alerts,\%rulematch,\%inst_results,
1337: \%curr_rules,\%got_rules);
1338: if ($allowed) {
1339: if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
1340: if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
1341: $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
1342: }
1343: if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
1344: $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
1345: }
1346: if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
1347: $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
1348: }
1349: }
1350: } else {
1351: push(@disallowed,$i);
1352: $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1353: }
1354: } else {
1355: push(@disallowed,$i);
1356: $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1357: }
1358: } else {
1359: my %userenv =
1360: &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
1361: if ($env{'form.person_'.$i.'_lastname'} eq '') {
1362: $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
1363: }
1364: if ($env{'form.person_'.$i.'_firstname'} eq '') {
1365: $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
1366: }
1367: if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
1368: $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
1369: }
1370: }
1371: } elsif ($personname ne '') {
1372: push(@disallowed,$i);
1373: $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
1374: }
1375: } elsif ($personname ne '') {
1376: push(@disallowed,$i);
1377: $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
1378: }
1379: }
1380: my $cnum;
1381: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
1382: $cnum = $env{'form.origcnum'};
1383: } else {
1384: my $gentype = 'Course';
1385: if ($crstype eq 'community') {
1386: $gentype = 'Community';
1387: }
1388: $cnum = &Apache::lonnet::generate_coursenum($dom,$gentype);
1389: }
1390: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1391: \%cat_order,\@code_order);
1392: if ($crstype eq 'community') {
1393: $r->print('<h3>'.&mt('Review community request details before submission').'</h3>');
1394: } else {
1395: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>');
1396: }
1397: $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg).
1398: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1399: if ($crstype eq 'community') {
1400: $navtxt{'next'} = &mt('Submit community request');
1401: } else {
1402: $navtxt{'next'} = &mt('Submit course request');
1403: }
1404: } elsif ($state eq 'process') {
1405: if ($crstype eq 'official') {
1406: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1407: \%cat_order,\@code_order);
1408: }
1409: my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles,
1410: \@code_order);
1411: $r->print($result);
1412: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1413: $r->print('<p>');
1414: if ($storeresult eq 'ok') {
1415: $r->print('<a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1416: &mt('Modify this request').'</a>'.(' 'x4));
1417: }
1418: $r->print('<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1419: return;
1420: }
1421: }
1422: my @excluded = &get_excluded_elements($dom,$states,$action,$state);
1423: if ($state eq 'personnel') {
1424: push(@excluded,'persontotal');
1425: }
1426: if ($state eq 'review') {
1427: if (@disallowed > 0) {
1428: my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
1429: my @currsecs = ¤t_lc_sections();
1430: if (@currsecs) {
1431: push(@items,'sec');
1432: }
1433: my $count = 0;
1434: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1435: unless ($env{'form.person_'.$i.'_uname'} eq '') {
1436: if (grep(/^$i$/,@disallowed)) {
1437: foreach my $item (@items) {
1438: $env{'form.person_'.$i.'_'.$item} = '';
1439: }
1440: } else {
1441: foreach my $item (@items) {
1442: $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
1443: }
1444: }
1445: }
1446: $count ++;
1447: }
1448: $env{'form.persontotal'} = $count;
1449:
1450: }
1451: }
1452: if ($state eq 'enrollment') {
1453: push(@excluded,'crosslisttotal');
1454: }
1455: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1456: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1457: $navtxt{'next'},$state);
1458: return;
1459: }
1460:
1461: sub get_cancreate_status {
1462: my ($persondom,$personname,$dom) = @_;
1463: my ($rules,$ruleorder) =
1464: &Apache::lonnet::inst_userrules($persondom,'username');
1465: my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1466: $rules);
1467: return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype);
1468: }
1469:
1470: sub check_newuser_rules {
1471: my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
1472: $got_rules) = @_;
1473: my $allowed = 1;
1474: my $newuser = 1;
1475: my ($checkhash,$userchkmsg);
1476: my $checks = { 'username' => 1 };
1477: $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
1478: &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
1479: $inst_results,$curr_rules,$got_rules);
1480: if (ref($alerts->{'username'}) eq 'HASH') {
1481: if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
1482: my $domdesc =
1483: &Apache::lonnet::domain($persondom,'description');
1484: if ($alerts->{'username'}{$persondom}{$personname}) {
1485: if (ref($curr_rules->{$persondom}) eq 'HASH') {
1486: $userchkmsg =
1487: &Apache::loncommon::instrule_disallow_msg('username',
1488: $domdesc,1).
1489: &Apache::loncommon::user_rule_formats($persondom,
1490: $domdesc,$curr_rules->{$persondom}{'username'},
1491: 'username');
1492: }
1493: $allowed = 0;
1494: }
1495: }
1496: }
1497: return ($allowed,$userchkmsg);
1498: }
1499:
1500: sub get_excluded_elements {
1501: my ($dom,$states,$action,$state) = @_;
1502: my @excluded = ('counter');
1503: my %elements = &form_elements($dom);
1504: if (ref($states) eq 'HASH') {
1505: if (ref($states->{$action}) eq 'ARRAY') {
1506: my @items = @{$states->{$action}};
1507: my $numitems = scalar(@items);
1508: if ($numitems) {
1509: for (my $i=$numitems-1; $i>=0; $i--) {
1510: if (ref($elements{$action}) eq 'HASH') {
1511: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1512: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1513: push(@excluded,$key);
1514: }
1515: }
1516: }
1517: last if ($items[$i] eq $state);
1518: }
1519: }
1520: }
1521: }
1522: if (grep(/^instcode_/,@excluded)) {
1523: push(@excluded,'instcode');
1524: }
1525: return @excluded;
1526: }
1527:
1528: sub print_enrollment_menu {
1529: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1530: $invalidcrosslist) =@_;
1531: my ($sections,$autoenroll,$access_dates,$output,$hasauto);
1532: my $starttime = time;
1533: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1534:
1535: my %accesstitles = (
1536: 'start' => 'Default start access',
1537: 'end' => 'Default end access',
1538: );
1539: my %enrolltitles = (
1540: 'start' => 'Start auto-enrollment',
1541: 'end' => 'End auto-enrollment',
1542: );
1543: if ($env{'form.crstype'} eq 'official') {
1544: if (&Apache::lonnet::auto_run('',$dom)) {
1545: $output = &show_invalid_crosslists($invalidcrosslist);
1546: my ($section_form,$crosslist_form);
1547: $section_form = &inst_section_selector($dom,$instcode);
1548: if ($section_form) {
1549: $sections = &Apache::lonhtmlcommon::row_headline().
1550: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
1551: ' '.&mt('Sections for auto-enrollment').'</h3>'.
1552: &Apache::lonhtmlcommon::row_closure(1).
1553: $section_form;
1554: }
1555: my $crosslisttotal = $env{'form.crosslisttotal'};
1556: if (!$crosslisttotal) {
1557: $crosslisttotal = 1;
1558: }
1559: if ($env{'form.addcrosslist'}) {
1560: $crosslisttotal ++;
1561: }
1562: for (my $i=0; $i<$crosslisttotal; $i++) {
1563: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1564: $cat_titles,$cat_order,$i);
1565: }
1566: if ($crosslist_form) {
1567: $crosslist_form .=
1568: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1569: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1570: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1571: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1572: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1573: $sections .= &Apache::lonhtmlcommon::row_headline.
1574: '<h3>'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1575: &Apache::lonhtmlcommon::row_closure(1).
1576: $crosslist_form;
1577: }
1578: $hasauto = 1;
1579: $autoenroll =
1580: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')).
1581: '<span class="LC_nobreak"><label>'.
1582: '<input type="radio" name="autoadds" value="1">'.
1583: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1584: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1585: &mt('No').'</label></span>'.
1586: &Apache::lonhtmlcommon::row_closure(1).
1587: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')).
1588: '<span class="LC_nobreak"><label>'.
1589: '<input type="radio" name="autodrops" value="1">'.
1590: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1591: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1592: &mt('No').'</label></span>'.
1593: &Apache::lonhtmlcommon::row_closure(1).
1594: &date_setting_table($starttime,$endtime,$formname,'enroll',
1595: $hasauto,%enrolltitles);
1596: }
1597: }
1598: my $access_dates =
1599: &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
1600: %accesstitles);
1601: $output .= &Apache::lonhtmlcommon::start_pick_box();
1602: if ($sections) {
1603: $output .= $sections;
1604: }
1605: if ($autoenroll) {
1606: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1607: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1608: &Apache::lonhtmlcommon::row_closure(1).
1609: $autoenroll;
1610: }
1611: if ($access_dates) {
1612: my $header = &mt('Access dates for students');
1613: if ($env{'form.crstype'} eq 'community') {
1614: $header = &mt('Access dates for community members');
1615: }
1616: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1617: '<h3>'.$header.'</h3>'.
1618: &Apache::lonhtmlcommon::row_closure(1).
1619: $access_dates
1620: }
1621: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1622: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1623: }
1624:
1625: sub show_invalid_crosslists {
1626: my ($invalidcrosslist) = @_;
1627: my $output;
1628: if (ref($invalidcrosslist) eq 'ARRAY') {
1629: if (@{$invalidcrosslist} > 0) {
1630: $output = '<div class="LC_warning">'.
1631: &mt('The following crosslisted courses were invalid:').'<ul>';
1632: foreach my $item (@{$invalidcrosslist}) {
1633: $output .= '<li>'.$item.'</li>';
1634: }
1635: $output .= '</ul></div><br />';
1636: }
1637: }
1638: return $output;
1639: }
1640:
1641:
1642: sub inst_section_selector {
1643: my ($dom,$instcode) = @_;
1644: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1645: my $sectotal = scalar(@sections);
1646: my $output;
1647: if ($sectotal) {
1648: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1649: &Apache::loncommon::start_data_table().
1650: &Apache::loncommon::start_data_table_row().
1651: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1652: 'value="'.$sectotal.'" /></th>'.
1653: '<th>'.&mt('Institutional Section').'</th>'.
1654: '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
1655: ' '.&mt('LON-CAPA section').'</th>'.
1656: &Apache::loncommon::end_data_table_row();
1657: for (my $i=0; $i<@sections; $i++) {
1658: my $colflag = $i%2;
1659: my $secon = ' checked="checked"';
1660: my $secoff = '';
1661: if ($env{'form.origcnum'}) {
1662: $secoff = $secon;
1663: $secon='';
1664: }
1665: $output .= &Apache::loncommon::start_data_table_row().
1666: '<td><label><input type="radio" name="sec_'.$i.
1667: '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
1668: (' 'x2).'<label><input type="radio" name="sec_'.$i.
1669: '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
1670: '<td align="center">'.$sections[$i].
1671: '<input type="hidden" name="secnum_'.$i.'" value="'.
1672: $sections[$i].'" /></td>'.
1673: '<td><input type="text" size="10" name="loncapasec_'.$i.
1674: '" value="'.$sections[$i].'" /></td>'.
1675: &Apache::loncommon::end_data_table_row();
1676: }
1677: $output .= &Apache::loncommon::end_data_table().
1678: &Apache::lonhtmlcommon::row_closure();
1679: }
1680: return $output;
1681: }
1682:
1683: sub date_setting_table {
1684: my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_;
1685: my ($perpetual,$table);
1686: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1687: $starttime,'','','',1,'','','',1);
1688: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1689: $endtime,'','','',1,'','','',1);
1690: my $closure = '';
1691: if ($prefix eq 'access') {
1692: $perpetual = ' <span class="LC_nobreak"><label>'.
1693: '<input type="checkbox" name="no_end_date" />'.
1694: &mt('No end date').'</label></span>';
1695: $closure = '1';
1696: }
1697:
1698: my %help_item = (
1699: access => {
1700: start => 'Course_Request_Access_Start',
1701: end => 'Course_Request_Access_End',
1702: },
1703: enroll => {
1704: start => 'Course_Request_Enroll_Start',
1705: end => 'Course_Request_Enroll_End',
1706: },
1707: );
1708: if ($hasauto) {
1709: $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
1710: $help_item{'access'}{'end'} = 'Course_Request_RegAccess_End';
1711: }
1712:
1713: $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
1714: ' '.&mt($datetitles{'start'})).$startform.
1715: &Apache::lonhtmlcommon::row_closure(1).
1716: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
1717: ' '.&mt($datetitles{'end'})).$endform.$perpetual.
1718: &Apache::lonhtmlcommon::row_closure($closure);
1719: return $table;
1720: }
1721:
1722: sub print_personnel_menu {
1723: my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
1724: my $output;
1725: if ($crstype eq 'official') {
1726: if (&Apache::lonnet::auto_run('',$dom)) {
1727: $output .= &show_invalid_crosslists($invalidcrosslist);
1728: }
1729: }
1730: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1731: my $persontotal = $env{'form.persontotal'};
1732: if ((!defined($persontotal)) || (!$persontotal)) {
1733: $persontotal = 1;
1734: }
1735: if ($env{'form.addperson'}) {
1736: $persontotal ++;
1737: }
1738: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1739:
1740: my $type = 'Course';
1741: if ($crstype eq 'community') {
1742: $type = 'Community';
1743: }
1744: my $roleoptions;
1745: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1746: foreach my $role (@roles) {
1747: my $plrole = &Apache::lonnet::plaintext($role,$type);
1748: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1749: }
1750: my %customroles=&Apache::lonuserutils::my_custom_roles();
1751: if (keys(%customroles) > 0) {
1752: foreach my $cust (sort(keys(%customroles))) {
1753: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1754: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1755: }
1756: }
1757:
1758: my @currsecs = ¤t_lc_sections();
1759:
1760: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1761: if (@currsecs) {
1762: my $existsize = scalar(@currsecs);
1763: if ($existsize > 3) {
1764: $existsize = 3;
1765: }
1766: if ($existsize > 1) {
1767: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1768: }
1769: @currsecs = sort { $a <=> $b } (@currsecs);
1770: $existtitle = &mt('Official').': ';
1771: $existops = '<option value="">'.&mt('None').'</option>';
1772: foreach my $sec (@currsecs) {
1773: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1774: }
1775: $seccolspan = ' colspan="2"';
1776: $newtitle = &mt('Other').': ';
1777: }
1778:
1779: if ($persontotal) {
1780: my %lt = &Apache::lonlocal::texthash(
1781: community => 'Requestor is automatically assigned Coordinator role.',
1782: official => 'Requestor is automatically assigned Course Coordinator role.',
1783: );
1784: $lt{'unofficial'} = $lt{'official'};
1785: $output .= &Apache::lonhtmlcommon::row_headline().
1786: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
1787: }
1788: for (my $i=0; $i<$persontotal; $i++) {
1789: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1790: my $linkargstr = join("','",@linkargs);
1791: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1792: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1793: "'person_".$i."_hidedom','person_".$i."_uname'".');';
1794: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1795: 1,$onchange).
1796: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1797: my %form_elems;
1798: foreach my $item (@items) {
1799: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1800: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1801: 'value="" readonly="readonly" />';
1802: }
1803: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1804: $roleoptions.'</select>';
1805: my $sectionselector;
1806: if (@currsecs) {
1807: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1808: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1809: }
1810: $sectionselector .= $newtitle.
1811: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1812: my $usersrchlinktxt = &mt('Search for user');
1813: my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1814: $usersrchlinktxt);
1815: my $userchklinktxt = &mt('Check username');
1816: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1817: $userchklinktxt,'checkusername');
1818: $output .=
1819: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
1820: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
1821: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
1822: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
1823: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
1824: '</tr>'."\n".'<tr>'.
1825: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1826: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1827: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1828: '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
1829: '<td'.$seccolspan.' align="center" valign="top">'.
1830: &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1831: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
1832: }
1833: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1834: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
1835: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1836: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1837: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1838: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1839: if ($crstype eq 'community') {
1840: $output .= '<p>'.&mt('You may also add users later, once the community has been created, by using the "Manage community users" link, accessible from the "Main Menu".').'</p>';
1841: } else {
1842: $output .= '<p>'.&mt('You may also add users later, once the course has been created, by using the "Manage course users" link, accessible from the "Main Menu".').'</p>';
1843: }
1844: return $output;
1845: }
1846:
1847: sub current_lc_sections {
1848: my @currsecs;
1849: if ($env{'form.sectotal'}) {
1850: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1851: if ($env{'form.sec_'.$i}) {
1852: if (defined($env{'form.loncapasec_'.$i})) {
1853: my $lcsec = $env{'form.loncapasec_'.$i};
1854: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
1855: push(@currsecs,$lcsec);
1856: }
1857: }
1858: }
1859: }
1860: }
1861: return @currsecs;
1862: }
1863:
1864: sub sorted_request_history {
1865: my ($dom,$action,$curr_req) = @_;
1866: my ($after,$before,$statusfilter,$crstypefilter);
1867: if ($env{'form.status'} ne '') {
1868: $statusfilter = $env{'form.status'};
1869: }
1870: if ($env{'form.crstype'} ne '') {
1871: $crstypefilter = $env{'form.crstype'};
1872: }
1873: if (ref($curr_req) eq 'HASH') {
1874: $after = $curr_req->{'requested_after_date'},
1875: $before = $curr_req->{'requested_before_date'};
1876: $statusfilter = $curr_req->{'status'};
1877: $crstypefilter = $curr_req->{'crstype'};
1878: }
1879: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
1880: $env{'user.name'},'^status:'.$dom);
1881: my %queue_by_date;
1882: my ($types,$typenames) = &Apache::loncommon::course_types();
1883: foreach my $key (keys(%statusinfo)) {
1884: if ($action eq 'view') {
1885: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
1886: } else {
1887: next unless (($statusfilter eq 'any') ||
1888: ($statusfilter eq $statusinfo{$key}));
1889: }
1890: (undef,my($cdom,$cnum)) = split(':',$key);
1891: next if ($cdom ne $dom);
1892: my $requestkey = $cdom.'_'.$cnum;
1893: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1894: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1895: $env{'user.domain'},$env{'user.name'});
1896: my $entry;
1897: my $reqtime = $history{'reqtime'};
1898: my $lastupdate = $history{'timestamp'};
1899: my $crstype = $history{'crstype'};
1900: my $disposition = $history{'disposition'};
1901: my $status = $history{'status'};
1902: if ($action eq 'view') {
1903: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1904: } else {
1905: next if (($reqtime < $after) || ($reqtime > $before));
1906: }
1907: next unless (($crstypefilter eq 'any') ||
1908: ($crstypefilter eq $crstype));
1909: if ($action eq 'view') {
1910: next unless (($disposition eq 'approval') ||
1911: ($disposition eq 'pending'));
1912: }
1913: if (ref($history{'details'}) eq 'HASH') {
1914: $entry = $requestkey.':'.$crstype.':'.
1915: &escape($history{'details'}{'cdescr'});
1916: if ($action eq 'log') {
1917: $entry .= ':'.$lastupdate.':';
1918: if ($statusinfo{$key} ne '') {
1919: $entry .= $statusinfo{$key};
1920: } elsif ($status ne '') {
1921: $entry .= $status;
1922: } else {
1923: $entry .= $disposition;
1924: }
1925: }
1926: if ($crstype eq 'official') {
1927: $entry .= ':'.&escape($history{'details'}{'instcode'});
1928: }
1929: }
1930: if ($entry ne '') {
1931: if (exists($queue_by_date{$reqtime})) {
1932: if (ref($queue_by_date{$reqtime}) eq 'ARRAY') {
1933: push(@{$queue_by_date{$reqtime}},$entry);
1934: }
1935: } else {
1936: @{$queue_by_date{$reqtime}} = ($entry);
1937: }
1938: }
1939: }
1940: }
1941: return %queue_by_date;
1942: }
1943:
1944: sub print_request_status {
1945: my ($dom,$action) = @_;
1946: my %queue_by_date = &sorted_request_history($dom,$action);
1947: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1948: my $formname = 'requestcrs';
1949: my ($types,$typenames) = &Apache::loncommon::course_types();
1950: my $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1951:
1952: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1953: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
1954: '<input type="hidden" name="showdom" value="" />'."\n".
1955: '<input type="hidden" name="cnum" value="" />'."\n";
1956: if (@sortedtimes > 0) {
1957: my $desctitle;
1958: if ($env{'form.crstype'} eq 'any') {
1959: $desctitle = &mt('Course/Community Description')
1960: } elsif ($env{'form.crstype'} eq 'community') {
1961: $desctitle = &mt('Community Description')
1962: } else {
1963: $desctitle = &mt('Course Description');
1964: }
1965: $output .= &Apache::loncommon::start_data_table().
1966: &Apache::loncommon::start_data_table_header_row().
1967: '<th>'.&mt('Action').'</th>'.
1968: '<th>'.$desctitle.'</th>'.
1969: '<th>'.&mt('Domain').'</th>';
1970: if ($env{'form.crstype'} eq 'any') {
1971: $output .= '<th>'.&mt('Type').'</th>';
1972: }
1973: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1974: $output .= '<th>'.&mt('Institutional Code').'</th>';
1975: }
1976: $output .= '<th>'.&mt('Date requested').'</th>'.
1977: &Apache::loncommon::end_data_table_header_row();
1978: my $count = 0;
1979: foreach my $item (@sortedtimes) {
1980: my $showtime = &Apache::lonlocal::locallocaltime($item);
1981: if (ref($queue_by_date{$item}) eq 'ARRAY') {
1982: foreach my $request (sort(@{$queue_by_date{$item}})) {
1983: my ($key,$type,$desc,$instcode) = split(':',$request);
1984: my ($cdom,$cnum) = split('_',$key);
1985: $output .= &Apache::loncommon::start_data_table_row().
1986: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1987: '<td>'.&unescape($desc).'</td>'.
1988: '<td>'.$cdom.'</td>';
1989: if ($env{'form.crstype'} eq 'any') {
1990: my $typename;
1991: if (ref($typenames) eq 'HASH') {
1992: $typename = &mt($typenames->{$type});
1993: }
1994: if ($typename eq '') {
1995: $typename = &mt('Unknown type');
1996: }
1997: $output .= '<td>'.$typename.'</td>';
1998: }
1999: if (($env{'form.crstype'} eq 'any') ||
2000: ($env{'form.crstype'} eq 'official')) {
2001: my $showinstcode;
2002: if ($type eq 'official') {
2003: $showinstcode = &unescape($instcode);
2004: } else {
2005: $showinstcode = &mt('Not applicable');
2006: }
2007: $output .= '<td>'.$showinstcode.'</td>';
2008: }
2009: $output .= '<td>'.$showtime.'</td>'.
2010: &Apache::loncommon::end_data_table_row();
2011: }
2012: }
2013: }
2014: $output .= &Apache::loncommon::end_data_table();
2015: } else {
2016: if ($env{'form.crstype'} eq 'any') {
2017: $output .= '<div>'.&mt('You have no matching course or community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'</div>';
2018: } elsif ($env{'form.crstype'} eq 'community') {
2019: $output .= '<div>'.&mt('You have no matching community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'</div>';
2020: } else {
2021: $output .= '<div>'.&mt('You have no matching course requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'</div>';
2022: }
2023: }
2024: $output .= '
2025: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
2026: return $output;
2027: }
2028:
2029: sub print_cancel_request {
2030: my ($dom,$cnum) = @_;
2031: my $requestkey = $dom.'_'.$cnum;
2032: my ($result,$output);
2033: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2034: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2035: $env{'user.domain'},$env{'user.name'});
2036: my $timestamp = $history{'reqtime'};
2037: my $crstype = $history{'crstype'};
2038: my $status = $history{'status'};
2039: if (($status eq 'cancelled') || ($status eq 'created')) {
2040: if ($status eq 'cancelled') {
2041: $output = &mt('This request has already been cancelled.');
2042: } elsif ($status eq 'created') {
2043: $output = &mt('This request has already been processed, and a course created.');
2044: }
2045: $output = &mt('No further action will be taken');
2046: } elsif (ref($history{'details'}) eq 'HASH') {
2047: my ($types,$typename) = &Apache::loncommon::course_types();
2048: my $showtype = $crstype;
2049: if (defined($typename->{$crstype})) {
2050: $showtype = $typename->{$crstype};
2051: }
2052: $output = '<p>'.&Apache::loncommon::start_data_table().
2053: &Apache::loncommon::start_data_table_header_row().
2054: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
2055: '<th>'.&mt('Type').'</th>'.
2056: &Apache::loncommon::end_data_table_header_row().
2057: &Apache::loncommon::start_data_table_row().
2058: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
2059: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
2060: '<td>'.$showtype.'</td>'.
2061: &Apache::loncommon::end_data_table_row().
2062: &Apache::loncommon::end_data_table().
2063: '<br /><div class="LC_warning">';
2064: if ($crstype eq 'community') {
2065: $output .= &mt('Cancelling the request will remove it from the queue of pending community requests').'</div>';
2066: } else {
2067: $output .= &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
2068: }
2069: $result = 'ok';
2070: } else {
2071: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
2072: }
2073: } else {
2074: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
2075: }
2076: return ($result,$output);
2077: }
2078:
2079: sub viewrequest_javascript {
2080: my ($formname,$next) = @_;
2081: return <<"ENDJS";
2082:
2083: function chooseRequest(cdom,cnum) {
2084: document.$formname.showdom.value = cdom;
2085: document.$formname.cnum.value = cnum;
2086: nextPage(document.$formname,'$next');
2087: }
2088:
2089: ENDJS
2090: }
2091:
2092: sub viewdetails_javascript {
2093: my ($formname) = @_;
2094: return << "ENDJS";
2095:
2096: function nextPage(formname,nextstate) {
2097: if (nextstate == "modify") {
2098: formname.state.value = "personnel";
2099: formname.action.value = "new";
2100: } else {
2101: formname.state.value = nextstate;
2102: }
2103: formname.submit();
2104: }
2105:
2106: function backPage(formname,prevstate) {
2107: formname.state.value = prevstate;
2108: formname.submit();
2109: }
2110:
2111: ENDJS
2112: }
2113:
2114: sub viewcancel_javascript {
2115: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
2116: 'Your request will be removed.');
2117: return << "ENDJS";
2118: function nextPage(formname,nextstate) {
2119: if (confirm('$alert')) {
2120: formname.state.value = nextstate;
2121: formname.submit();
2122: }
2123: return;
2124: }
2125:
2126: ENDJS
2127: }
2128:
2129: sub print_request_logs {
2130: my ($r,$dom,$jscript,$loaditems,$crumb) = @_;
2131: my $title;
2132: if ($env{'form.crstype'} eq 'community') {
2133: $title = 'Community Request Logs';
2134: } elsif ($env{'form.crstype'} eq 'any') {
2135: $title = 'Course/Community Request Logs';
2136: } else {
2137: $title = 'Course Request Logs';
2138: }
2139: $r->print(&header($title,$jscript,$loaditems).$crumb);
2140: my $formname = 'requestcrs';
2141: $r->print('<form action="/adm/requestcourse" method="post" name="'.$formname.'" onsubmit="javascript:setPage(this);">'."\n".
2142: '<input type="hidden" name="action" value="log" />'."\n".
2143: '<input type="hidden" name="state" value="display" />'."\n");
2144: # set defaults
2145: my $now = time();
2146: my $defstart = $now - (7*24*3600); #7 days ago
2147: my %defaults = (
2148: page => '1',
2149: show => '10',
2150: crstype => 'any',
2151: status => 'any',
2152: requested_before_date => $now,
2153: requested_after_date => $defstart,
2154: );
2155: my ($types,$typenames) = &Apache::loncommon::course_types();
2156: my $more_records = 0;
2157: my %curr;
2158: foreach my $item ('show','page','crstype','status') {
2159: $curr{$item} = $env{'form.'.$item};
2160: }
2161: $curr{'requested_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_after_date');
2162: $curr{'requested_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_before_date');
2163: foreach my $key (keys(%defaults)) {
2164: if ($curr{$key} eq '') {
2165: $curr{$key} = $defaults{$key};
2166: }
2167: }
2168: my ($statuses,$statusnames) = &reqstatus_names($curr{'crstype'});
2169: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
2170: &requestlog_display_filter($formname,\%curr));
2171: my %queue_by_date = &sorted_request_history($dom,$env{'form.action'},\%curr);
2172: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
2173: my $showntablehdr = 0;
2174: my $tablehdr = &Apache::loncommon::start_data_table().
2175: &Apache::loncommon::start_data_table_header_row().
2176: '<th> </th><th>'.&mt('Request Date').'</th>'.
2177: '<th>'.&mt('Description').'</th>';
2178: if ($curr{'crstype'} eq 'any') {
2179: $tablehdr .= '<th>'.&mt('Course Type').'</th>';
2180: }
2181: if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) {
2182: $tablehdr .= '<th>'.&mt('Institutional Code').'</th>';
2183: }
2184: if ($curr{'status'} eq 'any') {
2185: $tablehdr .= '<th>'.&mt('Status').'</th>';
2186: } elsif ($curr{'status'} eq 'created') {
2187: $tablehdr .= '<th>'.&mt('Creation Date').'</th>';
2188: } elsif ($curr{'status'} eq 'cancelled') {
2189: $tablehdr .= '<th>'.&mt('Cancellation Date').'</th>';
2190: } elsif ($curr{'status'} eq 'rejected') {
2191: $tablehdr .= '<th>'.&mt('Rejection Date').'</th>';
2192: }
2193: $tablehdr .= &Apache::loncommon::end_data_table_header_row();
2194: my ($minshown,$maxshown);
2195: $minshown = 1;
2196: my $count = 0;
2197: if ($curr{'show'} ne &mt('all')) {
2198: $maxshown = $curr{'page'} * $curr{'show'};
2199: if ($curr{'page'} > 1) {
2200: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
2201: }
2202: }
2203: my $norecords;
2204: if (@sortedtimes > 0) {
2205: foreach my $item (@sortedtimes) {
2206: if ($curr{'show'} ne &mt('all')) {
2207: if ($count >= $curr{'page'} * $curr{'show'}) {
2208: $more_records = 1;
2209: last;
2210: }
2211: }
2212: $count ++;
2213: next if ($count < $minshown);
2214: if (!$showntablehdr) {
2215: $r->print($tablehdr);
2216: $showntablehdr = 1;
2217: }
2218: my $showtime = &Apache::lonlocal::locallocaltime($item);
2219: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2220: foreach my $request (sort(@{$queue_by_date{$item}})) {
2221: my ($key,$crstype,$desc,$timestamp,$status,$instcode) = split(':',$request);
2222: my ($cdom,$cnum) = split('_',$key);
2223: my $output = &Apache::loncommon::start_data_table_row().
2224: '<td>'.$count.'</td>'.
2225: '<td>'.$showtime.'</td>'.
2226: '<td>'.&unescape($desc).'</td>';
2227: if ($curr{'crstype'} eq 'any') {
2228: my $typename;
2229: if (ref($typenames) eq 'HASH') {
2230: $typename = &mt($typenames->{$crstype});
2231: }
2232: if ($typename eq '') {
2233: $typename = &mt('Unknown type');
2234: }
2235: $output .= '<td>'.$typename.'</td>';
2236: }
2237: if (($curr{'crstype'} eq 'any') ||
2238: ($curr{'crstype'} eq 'official')) {
2239: my $showinstcode;
2240: if ($crstype eq 'official') {
2241: $showinstcode = &unescape($instcode);
2242: } else {
2243: $showinstcode = &mt('Not applicable');
2244: }
2245: $output .= '<td>'.$showinstcode.'</td>';
2246: }
2247: if ($curr{'status'} eq 'any') {
2248: my $statusname = &mt('Unknown status');
2249: if (ref($statusnames) eq 'HASH') {
2250: if ($statusnames->{$status} ne '') {
2251: $statusname = $statusnames->{$status};
2252: }
2253: }
2254: if (($status eq 'created') || ($status eq 'cancelled') ||
2255: ($status eq 'rejected')) {
2256: $statusname .= ' '.&Apache::lonlocal::locallocaltime($timestamp);
2257: }
2258: $output .= '<td>'.$statusname.'</td>';
2259: } elsif (($status eq 'created') || ($status eq 'cancelled') ||
2260: ($status eq 'rejected')) {
2261: $output .= '<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>';
2262: }
2263: $output .= &Apache::loncommon::end_data_table_row();
2264: $r->print($output);
2265: }
2266: }
2267: }
2268: if ($showntablehdr) {
2269: $r->print(&Apache::loncommon::end_data_table());
2270: if (($curr{'page'} > 1) || ($more_records)) {
2271: $r->print('<table><tr>');
2272: if ($curr{'page'} > 1) {
2273: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
2274: }
2275: if ($more_records) {
2276: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
2277: }
2278: $r->print('</tr></table>');
2279: $r->print(<<"ENDSCRIPT");
2280: <script type="text/javascript">
2281: // <![CDATA[
2282: function chgPage(caller) {
2283: if (caller == 'previous') {
2284: document.$formname.page.value --;
2285: }
2286: if (caller == 'next') {
2287: document.$formname.page.value ++;
2288: }
2289: document.$formname.submit();
2290: return;
2291: }
2292: // ]]>
2293: </script>
2294: ENDSCRIPT
2295: }
2296: } else {
2297: $norecords = 1;
2298: }
2299: } else {
2300: $norecords = 1;
2301: }
2302: if ($norecords) {
2303: $r->print('<p class="LC_info">'.
2304: &mt('There are no records to display').
2305: '</p>');
2306: }
2307: $r->print('</form>'.
2308: &Apache::loncommon::end_page());
2309: return;
2310: }
2311:
2312: sub reqstatus_names {
2313: my ($crstype) = @_;
2314: my @statuses = qw(created approval pending rejected cancelled);
2315: my %statusnames =
2316: &Apache::lonlocal::texthash (
2317: created => 'Course/Community created',
2318: approval => 'Queued pending approval',
2319: pending => 'Queued pending validation',
2320: rejected => 'Request rejected',
2321: cancelled => 'Request cancelled',
2322: );
2323: if (($crstype eq 'official') || ($crstype eq 'unofficial')) {
2324: $statusnames{'created'} = &mt('Course created');
2325: } elsif ($crstype eq 'community') {
2326: $statusnames{'created'} = &mt('Community created');
2327: }
2328: return (\@statuses,\%statusnames);
2329: }
2330:
2331: sub requestlog_display_filter {
2332: my ($formname,$curr) = @_;
2333: my $nolink = 1;
2334: my $output = '<table><tr><td valign="top">'.
2335: '<span class="LC_nobreak"><b>'.&mt('Records/page:').'</b></span><br />'.
2336: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
2337: (&mt('all'),5,10,20,50,100,1000,10000)).
2338: '</td><td> </td>';
2339: my $startform =
2340: &Apache::lonhtmlcommon::date_setter($formname,'requested_after_date',
2341: $curr->{'requested_after_date'},undef,
2342: undef,undef,undef,undef,undef,undef,$nolink);
2343: my $endform =
2344: &Apache::lonhtmlcommon::date_setter($formname,'requested_before_date',
2345: $curr->{'requested_before_date'},undef,
2346: undef,undef,undef,undef,undef,undef,$nolink);
2347: $output .= '<td valign="top"><b>'.&mt('Window during which course/community was requested:').'</b><br />'.
2348: '<table><tr><td>'.&mt('After:').
2349: '</td><td>'.$startform.'</td></tr>'.
2350: '<tr><td>'.&mt('Before:').'</td>'.
2351: '<td>'.$endform.'</td></tr></table>'.
2352: '</td>'.
2353: '<td> </td>';
2354: my ($types,$typenames) = &Apache::loncommon::course_types();
2355: if (ref($types) eq 'ARRAY') {
2356: if (@{$types} > 1) {
2357: $output .= '<td valign="top"><b>'.
2358: &mt('Course Type:').'</b><br /><select name="crstype">';
2359: my $selstr = '';
2360: if ($curr->{'crstype'} eq 'any') {
2361: $selstr = ' selected="selected"';
2362: }
2363: $output .= '<option value="any"'.$selstr.'>'.&mt('All types').'</option>'."\n";
2364: foreach my $crstype (@{$types}) {
2365: my $selstr = '';
2366: if ($curr->{'crstype'} eq $crstype) {
2367: $selstr = ' selected="selected"';
2368: }
2369: my $typename = $crstype;
2370: if (ref($typenames) eq 'HASH') {
2371: if ($typenames->{$crstype} ne '') {
2372: $typename = $typenames->{$crstype};
2373: }
2374: }
2375: $output .= '<option value="'.$crstype.'"'.$selstr.'>'.$typename.'</option>'."\n";
2376: }
2377: $output .= '</select></td>';
2378: }
2379: }
2380: my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'});
2381: if (ref($statuses) eq 'ARRAY') {
2382: if (@{$statuses} > 1) {
2383: $output .= '<td valign="top"><b>'.
2384: &mt('Request Status:').'</b><br /><select name="status">';
2385: my $selstr = '';
2386: if ($curr->{'status'} eq 'any') {
2387: $selstr = ' selected="selected"';
2388: }
2389: $output .= '<option value="any"'.$selstr.'>'.&mt('Any status').'</option>'."\n";
2390: foreach my $status (@{$statuses}) {
2391: my $selstr = '';
2392: if ($curr->{'status'} eq $status) {
2393: $selstr = ' selected="selected"';
2394: }
2395: my $statusname = $status;
2396: if (ref($statusnames) eq 'HASH') {
2397: if ($statusnames->{$status} ne '') {
2398: $statusname = $statusnames->{$status};
2399: }
2400: }
2401: $output .= '<option value="'.$status.'"'.$selstr.'>'.$statusname.'</option>'."\n";
2402: }
2403: $output .= '</select></td>';
2404: }
2405: }
2406: $output .= '</tr></table>';
2407:
2408: # Update Display button
2409: $output .= '<p>'.
2410: '<input type="submit" value="'.&mt('Update Display').'" />'.
2411: '</p><hr />';
2412: return $output;
2413: }
2414:
2415: sub print_review {
2416: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
2417: $disallowed,$disallowmsg) = @_;
2418: my ($types,$typename) = &Apache::loncommon::course_types();
2419: my ($owner,$ownername,$owneremail);
2420: if ($uname eq '' || $udom eq '') {
2421: $uname = $env{'user.name'};
2422: $udom = $env{'user.domain'};
2423: }
2424: $owner = $uname.':'.$udom;
2425: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
2426: my %emails = &Apache::loncommon::getemails($uname,$udom);
2427: foreach my $email ('permanentemail','critnotification','notification') {
2428: $owneremail = $emails{$email};
2429: last if ($owneremail ne '');
2430: }
2431: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
2432: $section_headers,$section_values,$personnel_headers,$personnel_values);
2433:
2434: $crstypename = $env{'form.crstype'};
2435: if (ref($typename) eq 'HASH') {
2436: unless ($typename->{$env{'form.crstype'}} eq '') {
2437: $crstypename = &mt($typename->{$env{'form.crstype'}});
2438: }
2439: }
2440: my $category = 'Course';
2441: if ($env{'form.crstype'} eq 'community') {
2442: $category = 'Community';
2443: }
2444:
2445: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
2446: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
2447:
2448: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
2449: '('.&Apache::lonnet::plaintext('st',$category).')';
2450: if ($env{'form.crstype'} eq 'official') {
2451: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
2452: foreach my $title (@{$codetitles}) {
2453: if ($env{'form.instcode_'.$title} ne '') {
2454: $inst_headers .= '<th>'.$title.'</th>';
2455: my $longitem = $env{'form.instcode_'.$title};
2456: if (ref($cat_titles->{$title}) eq 'HASH') {
2457: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
2458: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
2459: }
2460: }
2461: $inst_values .= '<td>'.$longitem.'</td>';
2462: }
2463: }
2464: }
2465: if (&Apache::lonnet::auto_run('',$dom)) {
2466: $enrollrow_title = &mt('Enrollment');
2467: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
2468: '<th>'.&mt('Automatic Drops').'</th>'.
2469: '<th>'.&mt('Enrollment Starts').'</th>'.
2470: '<th>'.&mt('Enrollment Ends').'</th>';
2471: $section_headers = '<th>'.&mt('Sections').'</th>'.
2472: '<th>'.&mt('Crosslistings').'</th>';
2473:
2474: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
2475: my @autoroster = (&mt('No'),&mt('Yes'));
2476: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
2477: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
2478: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
2479: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
2480: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
2481: &mt('Institutional section').'</th>'.
2482: '<th>'.&mt('LON-CAPA section').'</th></tr>';
2483: my $secinfo;
2484: if ($env{'form.sectotal'} > 0) {
2485: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2486: if ($env{'form.sec_'.$i}) {
2487: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
2488: if ($env{'form.loncapasec_'.$i} ne '') {
2489: $secinfo .= $env{'form.loncapasec_'.$i};
2490: } else {
2491: $secinfo .= &mt('None');
2492: }
2493: $secinfo .= '</td></tr>';
2494: }
2495: }
2496: }
2497: if ($secinfo eq '') {
2498: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
2499: }
2500: $section_values .= $secinfo.'</table></td><td>'.
2501: '<table class="LC_innerpickbox"><tr><th>'.
2502: &mt('Institutional course/section').'</th>'.
2503: '<th>'.&mt('LON-CAPA section').'</th></tr>';
2504: my $xlistinfo;
2505: my $crosslisttotal = $env{'form.crosslisttotal'};
2506: if (!$crosslisttotal) {
2507: $crosslisttotal = 1;
2508: }
2509: for (my $i=0; $i<$crosslisttotal; $i++) {
2510: if ($env{'form.crosslist_'.$i}) {
2511: $xlistinfo .= '<tr><td>';
2512: if (ref($code_order) eq 'ARRAY') {
2513: if (@{$code_order} > 0) {
2514: foreach my $item (@{$code_order}) {
2515: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
2516: }
2517: }
2518: }
2519: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
2520: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
2521: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
2522: } else {
2523: $xlistinfo .= &mt('None');
2524: }
2525: $xlistinfo .= '</td></tr>';
2526: }
2527: }
2528: if ($xlistinfo eq '') {
2529: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
2530: }
2531: $section_values .= $xlistinfo;
2532: }
2533: $section_values .= '</table></td>';
2534: }
2535:
2536: my %ctxt = &clone_text();
2537: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
2538: if (($env{'form.cloning'}) &&
2539: ($env{'form.clonecrs'} =~ /^$match_name$/) &&
2540: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
2541: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
2542: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
2543: $env{'form.crstype'});
2544: if ($canclone) {
2545: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
2546: $env{'form.clonecrs'},('description','internal.coursecode'));
2547: if (keys(%courseenv) > 0) {
2548: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
2549: $inst_values .= '<td>'.$courseenv{'description'}.' ';
2550: my $cloneinst = $courseenv{'internal.coursecode'};
2551: if ($cloneinst ne '') {
2552: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
2553: } else {
2554: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
2555: }
2556: $inst_values .= '</td><td>';
2557: if ($env{'form.datemode'} eq 'preserve') {
2558: $inst_values .= $ctxt{'prd'};
2559: } elsif ($env{'form.datemode'} eq 'shift') {
2560: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
2561: } else {
2562: $inst_values .= $ctxt{'ncd'};
2563: }
2564: $inst_values .= '</td>';
2565: } else {
2566: $inst_values .= '<td>'.&mt('Unknown').'</td>';
2567: }
2568: } else {
2569: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
2570: }
2571: } else {
2572: $inst_values .= '<td>'.&mt('None').'</td>';
2573: }
2574: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
2575: '<th>'.&mt('Access Ends').'</th>';
2576: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2577: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
2578: if ($accessend == 0) {
2579: $enroll_values .= '<td>'.&mt('No end date').'</td>';
2580: } else {
2581: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
2582: }
2583:
2584: my $container = 'Course';
2585: my $ccrole = 'cc';
2586: if ($env{'form.crstype'} eq 'community') {
2587: $container = 'Community';
2588: $ccrole = 'co';
2589: }
2590:
2591: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
2592: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
2593: '</th>';
2594:
2595: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
2596: '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
2597: '<td>'.&mt('None').'</td></tr>';
2598: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2599: if ($env{'form.person_'.$i.'_uname'} ne '') {
2600: if (ref($disallowed) eq 'ARRAY') {
2601: next if (grep(/^$i$/,@{$disallowed}));
2602: }
2603: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2604: my @allsecs;
2605: foreach my $sec (@officialsecs) {
2606: next unless ($sec =~ /\w/);
2607: next if ($sec =~ /\W/);
2608: next if ($sec eq 'none');
2609: push(@allsecs,$sec);
2610: }
2611: my $newsec = $env{'form.person_'.$i.'_newsec'};
2612: $newsec =~ s/^\s+//;
2613: $newsec =~s/\s+$//;
2614: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
2615: foreach my $sec (@newsecs) {
2616: next unless ($sec =~ /\w/);
2617: next if ($sec =~ /\W/);
2618: next if ($sec eq 'none');
2619: if ($sec ne '') {
2620: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2621: push(@allsecs,$sec);
2622: }
2623: }
2624: }
2625: my $showsec;
2626: if (@allsecs) {
2627: $showsec = join(', ',@allsecs);
2628: }
2629: if ($showsec eq '') {
2630: $showsec = &mt('None');
2631: }
2632: if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
2633: $showsec = &mt('None');
2634: }
2635: my $role = $env{'form.person_'.$i.'_role'};
2636: $personnel_values .=
2637: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
2638: $env{'form.person_'.$i.'_lastname'}.'</td>'.
2639: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
2640: $env{'form.person_'.$i.'_dom'}.'</td>'.
2641: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
2642: '<td>'.$showsec.'</td></tr>';
2643: }
2644: }
2645: my $output;
2646: if (ref($disallowed) eq 'ARRAY') {
2647: if (@{$disallowed} > 0) {
2648: if (ref($disallowmsg) eq 'HASH') {
2649: $output = '<p class="LC_warning">'.
2650: &mt('Not all requested personnel could be included.').'<ul>';
2651: foreach my $item (@{$disallowed}) {
2652: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
2653: }
2654: $output .= '</ul></p>';
2655: }
2656: }
2657: }
2658: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
2659: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
2660: '<table class="LC_innerpickbox"><tr>'.
2661: '<th>'.&mt('Name').'</th>'.
2662: '<th>'.&mt('Username:Domain').'</th>'.
2663: '<th>'.&mt('E-mail address').'</th>'.
2664: '</tr><tr>'."\n".
2665: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
2666: '<td>'.$owneremail.'</td>'.
2667: '</tr></table>'."\n".
2668: &Apache::lonhtmlcommon::row_closure().
2669: &Apache::lonhtmlcommon::row_title(&mt('Description')).
2670: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
2671: '<tr>'.$inst_values.'</tr></table>'."\n".
2672: &Apache::lonhtmlcommon::row_closure().
2673: &Apache::lonhtmlcommon::row_title($enrollrow_title).
2674: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
2675: '<tr>'.$enroll_values.'</tr></table>'."\n".
2676: &Apache::lonhtmlcommon::row_closure();
2677: if ($section_headers ne '') {
2678: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
2679: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
2680: '<tr>'.$section_values.'</tr></table>'."\n".
2681: &Apache::lonhtmlcommon::row_closure();
2682: }
2683: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
2684: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
2685: $personnel_values.'</table>'."\n".
2686: &Apache::lonhtmlcommon::row_closure(1).
2687: &Apache::lonhtmlcommon::end_pick_box().'</div>';
2688: return $output;
2689: }
2690:
2691: sub dates_from_form {
2692: my ($startname,$endname) = @_;
2693: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
2694: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
2695: if ($endname eq 'accessend') {
2696: if (exists($env{'form.no_end_date'}) ) {
2697: $enddate = 0;
2698: }
2699: }
2700: return ($startdate,$enddate);
2701: }
2702:
2703: sub courseinfo_form {
2704: my ($dom,$formname,$crstype,$next,$description) = @_;
2705: my %lt = &Apache::lonlocal::texthash(
2706: official => 'You must provide a (brief) course description.',
2707: community => 'You must provide a (brief) community description.'
2708: );
2709: $lt{'unofficial'} = $lt{'official'};
2710: my $js_validate = <<"ENDJS";
2711: <script type="text/javascript">
2712: // <![CDATA['
2713:
2714: function validateForm() {
2715: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
2716: alert('$lt{$crstype}');
2717: return;
2718: }
2719: nextPage(document.$formname,'$next');
2720: }
2721:
2722: function toggleCloning() {
2723: var willclone;
2724: if (document.$formname.cloning.length > 1) {
2725: for (var i=0; i<document.$formname.cloning.length; i++) {
2726: if (document.$formname.cloning[i].checked) {
2727: willclone = document.$formname.cloning[i].value;
2728: }
2729: }
2730: }
2731: if (willclone == 1) {
2732: document.getElementById('cloneoptions').style.display="block";
2733: } else {
2734: document.getElementById('cloneoptions').style.display="none";
2735: document.$formname.clonecrs.value = '';
2736: }
2737: }
2738:
2739: // ]]
2740: </script>
2741:
2742: ENDJS
2743: my $title = &mt('Brief Course Description');
2744: my $clonetitle = &mt('Clone content and settings from an existing course?');
2745: if ($crstype eq 'community') {
2746: $title = &mt('Brief Community Description');
2747: $clonetitle = &mt('Clone content and settings from an existing community?');
2748: }
2749: my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box().
2750: &Apache::lonhtmlcommon::row_headline().
2751: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'.
2752: &Apache::lonhtmlcommon::row_closure(1).
2753: &Apache::lonhtmlcommon::row_title(&mt('Description')).
2754: '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
2755: my ($home_server_pick,$numlib) =
2756: &Apache::loncommon::home_server_form_item($dom,'chome',
2757: 'default','hide');
2758: if ($numlib > 1) {
2759: $output .= &Apache::lonhtmlcommon::row_closure().
2760: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
2761: }
2762: $output .= $home_server_pick.
2763: &Apache::lonhtmlcommon::row_closure().
2764: &Apache::lonhtmlcommon::row_headline().
2765: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.
2766: &Apache::lonhtmlcommon::row_closure(1).
2767: &Apache::lonhtmlcommon::row_title(&mt('Clone?')).
2768: '<label><input type="radio" name="cloning" value="1" '.
2769: 'onclick="javascript:toggleCloning()" />'.
2770: &mt('Yes').(' 'x2).'</label><label>'.
2771: '<input type="radio" name="cloning" value="0" checked="checked" '.
2772: 'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'.
2773: '</h3>'.
2774: &Apache::lonhtmlcommon::row_closure(1).
2775: &Apache::lonhtmlcommon::row_headline().
2776: '<div id="cloneoptions" style="display: none" >'.
2777: &Apache::lonhtmlcommon::start_pick_box().
2778: &clone_form($dom,$formname,$crstype).
2779: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
2780: &Apache::lonhtmlcommon::end_pick_box()."\n";
2781: return $output;
2782: }
2783:
2784: sub clone_form {
2785: my ($dom,$formname,$crstype) = @_;
2786: my $type = 'Course';
2787: if ($crstype eq 'community') {
2788: $type = 'Community';
2789: }
2790: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').' '.
2791: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
2792: my %lt = &clone_text();
2793: my $output .=
2794: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
2795: '<input type="text" size="25" name="clonecrs" value="" />'.
2796: '</label>'.&Apache::lonhtmlcommon::row_closure(1).
2797: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
2798: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
2799: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
2800: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
2801: '</label><br /><label>'.
2802: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
2803: '</label><br /><label>'.
2804: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
2805: $lt{'shd'}.'</label>'.
2806: '<input type="text" size="5" name="dateshift" value="365" />'.
2807: &Apache::lonhtmlcommon::row_closure(1);
2808: return $output;
2809: }
2810:
2811: sub clone_text {
2812: return &Apache::lonlocal::texthash(
2813: 'cid' => 'Course ID',
2814: 'dmn' => 'Domain',
2815: 'dsh' => 'Date Shift',
2816: 'ncd' => 'Do not clone date parameters',
2817: 'prd' => 'Clone date parameters as-is',
2818: 'shd' => 'Shift date parameters by number of days',
2819: );
2820: }
2821:
2822: sub coursecode_form {
2823: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
2824: my $output;
2825: my %rowtitle = &Apache::lonlocal::texthash (
2826: instcode => 'Course Category',
2827: crosslist => 'Cross Listed Course',
2828: );
2829: my %helpitem = (
2830: instcode => 'Course_Request_Category',
2831: crosslist => 'Course_Request_Crosslist',
2832: );
2833: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
2834: (ref($cat_order))) {
2835: my ($sel,$instsec,$lcsec);
2836: $sel = $context;
2837: if ($context eq 'crosslist') {
2838: $sel .= '_'.$num;
2839: $instsec = &mt('Institutional section').'<br />'.
2840: '<input type="text" size="10" name="'.$sel.'_instsec" />';
2841: $lcsec = &mt('LON-CAPA section').'<br />'.
2842: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
2843: }
2844: if (@{$codetitles} > 0) {
2845: my $lastitem = pop(@{$codetitles});
2846: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
2847: if (@{$codetitles} > 0) {
2848: $output = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($helpitem{$context}).' '.$rowtitle{$context}).
2849: '<table><tr>';
2850: if ($context eq 'crosslist') {
2851: $output .= '<td>'.&mt('Include?').'<br />'.
2852: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
2853: }
2854: foreach my $title (@{$codetitles}) {
2855: if (ref($cat_order->{$title}) eq 'ARRAY') {
2856: if (@{$cat_order->{$title}} > 0) {
2857: $output .= '<td align="center">'.$title.'<br />'."\n".
2858: '<select name="'.$sel.'_'.$title.'">'."\n".
2859: ' <option value="" selected="selected">'.
2860: &mt('Select').'</option>'."\n";
2861: foreach my $item (@{$cat_order->{$title}}) {
2862: my $longitem = $item;
2863: if (ref($cat_titles->{$title}) eq 'HASH') {
2864: if ($cat_titles->{$title}{$item} ne '') {
2865: $longitem = $cat_titles->{$title}{$item};
2866: }
2867: }
2868: $output .= '<option value="'.$item.'">'.$longitem.
2869: '</option>'."\n";
2870: }
2871: }
2872: $output .= '</select></td>'."\n";
2873: }
2874: }
2875: if ($context eq 'crosslist') {
2876: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
2877: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
2878: '<td align="center">'.$lcsec.'</td></tr></table>';
2879: } else {
2880: $output .= '</tr></table>'.
2881: &Apache::lonhtmlcommon::row_closure().
2882: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2883: $lastinput;
2884: }
2885: } else {
2886: if ($context eq 'crosslist') {
2887: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
2888: '<table><tr>'.
2889: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
2890: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
2891: '</tr></table>';
2892: } else {
2893: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2894: $lastinput;
2895: }
2896: }
2897: $output .= &Apache::lonhtmlcommon::row_closure(1);
2898: push(@$codetitles,$lastitem);
2899: } elsif ($context eq 'crosslist') {
2900: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
2901: '<table><tr><td align="center">'.
2902: '<span class="LC_nobreak">'.&mt('Include?').
2903: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
2904: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
2905: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
2906: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
2907: &Apache::lonhtmlcommon::row_closure(1);
2908: }
2909: }
2910: return $output;
2911: }
2912:
2913: sub get_course_dom {
2914: my $codedom = &Apache::lonnet::default_login_domain();
2915: if ($env{'form.showdom'} ne '') {
2916: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
2917: return $env{'form.showdom'};
2918: }
2919: }
2920: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
2921: my ($types,$typename) = &Apache::loncommon::course_types();
2922: if (ref($types) eq 'ARRAY') {
2923: foreach my $type (@{$types}) {
2924: if (&Apache::lonnet::usertools_access($env{'user.name'},
2925: $env{'user.domain'},$type,
2926: undef,'requestcourses')) {
2927: return $env{'user.domain'};
2928: }
2929: }
2930: my @possible_doms;
2931: foreach my $type (@{$types}) {
2932: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
2933: if ($dom_str ne '') {
2934: my @domains = split(',',$dom_str);
2935: foreach my $entry (@domains) {
2936: my ($extdom,$extopt) = split(':',$entry);
2937: if ($extdom eq $env{'request.role.domain'}) {
2938: return $extdom;
2939: }
2940: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
2941: push(@possible_doms,$extdom);
2942: }
2943: }
2944: }
2945: }
2946: if (@possible_doms) {
2947: @possible_doms = sort(@possible_doms);
2948: return $possible_doms[0];
2949: }
2950: }
2951: $codedom = $env{'user.domain'};
2952: if ($env{'request.role.domain'} ne '') {
2953: $codedom = $env{'request.role.domain'};
2954: }
2955: }
2956: return $codedom;
2957: }
2958:
2959: sub display_navbuttons {
2960: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
2961: $r->print('<div class="LC_navbuttons">');
2962: if ($prev) {
2963: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2964: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
2965: (' 'x3));
2966: } elsif ($prevtext) {
2967: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2968: 'onclick="javascript:history.back()"/>'.(' 'x3));
2969: }
2970: if ($state eq 'details') {
2971: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
2972: 'onclick="javascript:nextPage('."document.$formname,'$other'".
2973: ')" />');
2974: }
2975: my $gotnext;
2976: if ($state eq 'courseinfo') {
2977: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2978: 'onclick="javascript:validateForm();" />');
2979: $gotnext = 1;
2980: } elsif ($state eq 'enrollment') {
2981: if (($env{'form.crstype'} eq 'official') &&
2982: (&Apache::lonnet::auto_run('',$dom))) {
2983: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2984: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
2985: $gotnext = 1;
2986: }
2987: } elsif ($state eq 'personnel') {
2988: if ($env{'form.persontotal'} > 0) {
2989: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2990: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
2991: $gotnext = 1;
2992: }
2993: }
2994: unless ($gotnext) {
2995: if ($next) {
2996: $r->print('
2997: <input type="button" name="next" value="'.$nexttext.'" '.
2998: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
2999: }
3000: }
3001: $r->print('</div>');
3002: }
3003:
3004: sub print_request_outcome {
3005: my ($dom,$codetitles,$code_order) = @_;
3006: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
3007: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
3008: my $sectotal = $env{'form.sectotal'};
3009: my $crosslisttotal = 0;
3010: $cnum = $env{'form.cnum'};
3011: unless ($cnum =~ /^$match_courseid$/) {
3012: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
3013: return $output;
3014: }
3015:
3016: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
3017: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
3018: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
3019: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
3020: }
3021: }
3022: $now = time;
3023: $crstype = $env{'form.crstype'};
3024: my $ccrole = 'cc';
3025: if ($crstype eq 'community') {
3026: $ccrole = 'co';
3027: }
3028: my @instsections;
3029: if ($crstype eq 'official') {
3030: if (&Apache::lonnet::auto_run('',$dom)) {
3031: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
3032: }
3033: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
3034: if ($env{'form.sec_'.$i}) {
3035: if ($env{'form.secnum_'.$i} ne '') {
3036: my $sec = $env{'form.secnum_'.$i};
3037: $sections{$i}{'inst'} = $sec;
3038: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
3039: push(@instsections,$sec);
3040: }
3041: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
3042: }
3043: }
3044: }
3045: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
3046: if ($env{'form.crosslist_'.$i}) {
3047: my $xlistinfo = '';
3048: if (ref($code_order) eq 'ARRAY') {
3049: if (@{$code_order} > 0) {
3050: foreach my $item (@{$code_order}) {
3051: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
3052: }
3053: }
3054: }
3055: $crosslistings{$i}{'instcode'} = $xlistinfo;
3056: if ($xlistinfo ne '') {
3057: $crosslisttotal ++;
3058: }
3059: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
3060: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
3061: }
3062: }
3063: } else {
3064: $enrollstart = '';
3065: $enrollend = '';
3066: }
3067: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
3068: my $uname = $env{'form.person_'.$i.'_uname'};
3069: my $udom = $env{'form.person_'.$i.'_dom'};
3070: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
3071: if (&Apache::lonnet::domain($udom) ne '') {
3072: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
3073: $personnel{$uname.':'.$udom} = {
3074: firstname => $env{'form.person_'.$i.'_firstname'},
3075: lastname => $env{'form.person_'.$i.'_lastname'},
3076: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
3077: };
3078: }
3079: my $role = $env{'form.person_'.$i.'_role'};
3080: unless ($role eq '') {
3081: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
3082: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
3083: unless (grep(/^\Q$role\E$/,@curr_roles)) {
3084: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
3085: }
3086: } else {
3087: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
3088: }
3089: if ($role eq $ccrole) {
3090: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
3091: } else {
3092: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
3093: my @allsecs;
3094: foreach my $sec (@currsec) {
3095: next unless ($sec =~ /\w/);
3096: next if ($sec =~ /\W/);
3097: next if ($sec eq 'none');
3098: push(@allsecs,$sec);
3099: }
3100: my $newsec = $env{'form.person_'.$i.'_newsec'};
3101: $newsec =~ s/^\s+//;
3102: $newsec =~s/\s+$//;
3103: my @newsecs = split(/[\s,;]+/,$newsec);
3104: foreach my $sec (@newsecs) {
3105: next if ($sec =~ /\W/);
3106: next if ($sec eq 'none');
3107: if ($sec ne '') {
3108: unless (grep(/^\Q$sec\E$/,@allsecs)) {
3109: push(@allsecs,$sec);
3110: }
3111: }
3112: }
3113: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
3114: }
3115: }
3116: } else {
3117: push(@missingdom,$uname.':'.$udom);
3118: }
3119: } else {
3120: push(@baduname,$uname.':'.$udom);
3121: }
3122: }
3123: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
3124: my $autodrops = 0;
3125: if ($env{'form.autodrops'}) {
3126: $autodrops = $env{'form.autodrops'};
3127: }
3128: my $autoadds = 0;
3129: if ($env{'form.autoadds'}) {
3130: $autodrops = $env{'form.autoadds'};
3131: }
3132: if ($env{'form.autoadds'}) {
3133: $autodrops = $env{'form.autoadds'};
3134: }
3135: my $instcode = '';
3136: if (exists($env{'form.instcode'})) {
3137: $instcode = $env{'form.instcode'};
3138: }
3139: my $clonecrs = '';
3140: my $clonedom = '';
3141: if (($env{'form.cloning'}) &&
3142: ($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
3143: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
3144: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
3145: $env{'form.clonedom'});
3146: if ($clonehome ne 'no_host') {
3147: my $canclone =
3148: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
3149: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
3150: $crstype);
3151: if ($canclone) {
3152: $clonecrs = $env{'form.clonecrs'};
3153: $clonedom = $env{'form.clonedom'};
3154: }
3155: }
3156: }
3157: my $details = {
3158: owner => $env{'user.name'},
3159: domain => $env{'user.domain'},
3160: cdom => $dom,
3161: cnum => $cnum,
3162: coursehome => $env{'form.chome'},
3163: cdescr => $env{'form.cdescr'},
3164: crstype => $env{'form.crstype'},
3165: instcode => $instcode,
3166: clonedom => $clonedom,
3167: clonecrs => $clonecrs,
3168: datemode => $env{'form.datemode'},
3169: dateshift => $env{'form.dateshift'},
3170: sectotal => $sectotal,
3171: sections => \%sections,
3172: crosslisttotal => $crosslisttotal,
3173: crosslists => \%crosslistings,
3174: autoadds => $autoadds,
3175: autodrops => $autodrops,
3176: enrollstart => $enrollstart,
3177: enrollend => $enrollend,
3178: accessstart => $accessstart,
3179: accessend => $accessend,
3180: personnel => \%personnel,
3181: };
3182: my (@inststatuses,$storeresult,$creationresult);
3183: my $val =
3184: &Apache::loncoursequeueadmin::get_processtype($env{'user.name'},$env{'user.domain'},
3185: $env{'user.adv'},$dom,$crstype,\@inststatuses,\%domconfig);
3186: if ($val eq '') {
3187: if ($crstype eq 'official') {
3188: $output = &mt('You are not permitted to request creation of official courses.');
3189: } elsif ($crstype eq 'unofficial') {
3190: $output = &mt('You are not permitted to request creation of unofficial courses.');
3191: } elsif ($crstype eq 'community') {
3192: $output = &mt('You are not permitted to request creation of communities');
3193: } else {
3194: $output = &mt('Unrecognized course type: [_1]',$crstype);
3195: }
3196: $storeresult = 'notpermitted';
3197: } else {
3198: my ($disposition,$message,$reqstatus);
3199: my %reqhash = (
3200: reqtime => $now,
3201: crstype => $crstype,
3202: details => $details,
3203: );
3204: my $requestkey = $dom.'_'.$cnum;
3205: my $validationerror;
3206: if ($val eq 'autolimit=') {
3207: $disposition = 'process';
3208: } elsif ($val =~ /^autolimit=(\d+)$/) {
3209: my $limit = $1;
3210: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
3211: $dom,$crstype,$limit,\$message);
3212: } elsif ($val eq 'validate') {
3213: my ($inststatuslist,$validationchk,$validation);
3214: if (@inststatuses > 0) {
3215: $inststatuslist = join(',',@inststatuses);
3216: }
3217: my $instseclist;
3218: if (@instsections > 0) {
3219: $instseclist = join(',',@instsections);
3220: }
3221: $validationchk =
3222: &Apache::lonnet::auto_courserequest_validation($dom,
3223: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
3224: $inststatuslist,$instcode,$instseclist);
3225: if ($validationchk =~ /:/) {
3226: ($validation,$message) = split(':',$validationchk);
3227: } else {
3228: $validation = $validationchk;
3229: }
3230: if ($validation =~ /^error(.*)$/) {
3231: $disposition = 'approval';
3232: $validationerror = $1;
3233: } else {
3234: $disposition = $validation;
3235: }
3236: } else {
3237: $disposition = 'approval';
3238: }
3239: $reqhash{'disposition'} = $disposition;
3240: $reqstatus = $disposition;
3241: my ($modified,$queued);
3242: if ($disposition eq 'rejected') {
3243: if ($crstype eq 'community') {
3244: $output = &mt('Your community request was rejected.');
3245: } else {
3246: $output = &mt('Your course request was rejected.');
3247: }
3248: if ($message) {
3249: $output .= '<div class="LC_warning">'.$message.'</div>';
3250: }
3251: $storeresult = 'rejected';
3252: } elsif ($disposition eq 'process') {
3253: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
3254: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
3255: my $type = 'Course';
3256: if ($crstype eq 'community') {
3257: $type = 'Community';
3258: }
3259: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
3260: foreach my $role (@roles) {
3261: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
3262: }
3263: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
3264: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
3265: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
3266: if ($result eq 'created') {
3267: $disposition = 'created';
3268: $reqstatus = 'created';
3269: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
3270: \%longroles);
3271: if ($crstype eq 'community') {
3272: $output = '<p>'.&mt('Your community request has been processed and the community has been created.');
3273: } else {
3274: $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
3275: }
3276: $output .= '<br />'.$role_result.'</p>';
3277: $creationresult = 'created';
3278: } else {
3279: $output = '<span class="LC_error">';
3280: if ($crstype eq 'community') {
3281: $output .= &mt('An error occurred when processing your community request.');
3282: } else {
3283: $output .= &mt('An error occurred when processing your course request.');
3284: }
3285: $output .= '<br />'.
3286: &mt('You may want to review the request details and submit the request again.').
3287: '</span>';
3288: $creationresult = 'error';
3289: }
3290: } else {
3291: my $requestid = $cnum.'_'.$disposition;
3292: my $request = {
3293: $requestid => {
3294: timestamp => $now,
3295: crstype => $crstype,
3296: ownername => $env{'user.name'},
3297: ownerdom => $env{'user.domain'},
3298: description => $env{'form.cdescr'},
3299: },
3300: };
3301: if ($crstype eq 'official') {
3302: $request->{$requestid}->{'instcode'} = $instcode;
3303: }
3304: my $statuskey = 'status:'.$dom.':'.$cnum;
3305: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
3306: $env{'user.domain'},$env{'user.name'});
3307: if ($userreqhash{$statuskey} ne '') {
3308: $modified = 1;
3309: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
3310: my %queuehash = &Apache::lonnet::get('courserequestqueue',
3311: [$cnum.'_approval',
3312: $cnum.'_pending'],$dom,$uname);
3313: if (($queuehash{$cnum.'_approval'} ne '') ||
3314: ($queuehash{$cnum.'_pending'} ne '')) {
3315: $queued = 1;
3316: }
3317: }
3318: unless ($queued) {
3319: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
3320: $dom);
3321: if ($putresult eq 'ok') {
3322: if ($crstype eq 'community') {
3323: $output .= &mt('Your community request has been recorded.');
3324: } else {
3325: $output .= &mt('Your course request has been recorded.')
3326: }
3327: $output .= '<br />'.
3328: ¬ification_information($disposition,$req_notifylist,
3329: $cnum,$now);
3330: } else {
3331: $reqstatus = 'domainerror';
3332: $reqhash{'disposition'} = $disposition;
3333: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
3334: $output = '<span class"LC_warning">'.$warning.'</span><br />';
3335: }
3336: }
3337: }
3338: ($storeresult,my $updateresult) =
3339: &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
3340: $cnum,$reqstatus,'request');
3341: if ($modified && $queued && $storeresult eq 'ok') {
3342: if ($crstype eq 'community') {
3343: $output .= '<p>'.&mt('Your community request has been updated').'</p>';
3344: } else {
3345: $output .= '<p>'.&mt('Your course request has been updated').'</p>';
3346: }
3347: $output .= ¬ification_information($disposition,$req_notifylist,$cnum,$now);
3348: }
3349: if ($validationerror ne '') {
3350: $output .= '<p class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
3351: }
3352: if ($updateresult) {
3353: $output .= $updateresult;
3354: }
3355: }
3356: if ($creationresult ne '') {
3357: return ($creationresult,$output);
3358: } else {
3359: return ($storeresult,$output);
3360: }
3361: }
3362:
3363: sub update_requestors_roles {
3364: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
3365: my $now = time;
3366: my ($active,$future,$numactive,$numfuture,$output);
3367: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
3368: if (ref($details) eq 'HASH') {
3369: if (ref($details->{'personnel'}) eq 'HASH') {
3370: my $ccrole = 'cc';
3371: if ($crstype eq 'community') {
3372: $ccrole = 'co';
3373: }
3374: unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
3375: $details->{'personnel'}{$owner} = {
3376: 'roles' => [$ccrole],
3377: $ccrole => { 'usec' => [] },
3378: };
3379: }
3380: my @roles;
3381: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
3382: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
3383: unless (grep(/^\Q$ccrole\E$/,@roles)) {
3384: push(@roles,$ccrole);
3385: }
3386: } else {
3387: @roles = ($ccrole);
3388: }
3389: foreach my $role (@roles) {
3390: my $refresh=$env{'user.refresh.time'};
3391: if ($refresh eq '') {
3392: $refresh = $env{'user.login.time'};
3393: }
3394: if ($refresh eq '') {
3395: $refresh = $now;
3396: }
3397: my $start = $refresh-1;
3398: my $end = '0';
3399: if ($role eq 'st') {
3400: if ($details->{'accessstart'} ne '') {
3401: $start = $details->{'accessstart'};
3402: }
3403: if ($details->{'accessend'} ne '') {
3404: $end = $details->{'accessend'};
3405: }
3406: }
3407: my @usecs;
3408: if ($role ne $ccrole) {
3409: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
3410: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
3411: }
3412: }
3413: if ($role eq 'st') {
3414: if (@usecs > 1) {
3415: my $firstsec = $usecs[0];
3416: @usecs = ($firstsec);
3417: }
3418: }
3419: if (@usecs == 0) {
3420: push(@usecs,'');
3421: }
3422: foreach my $usec (@usecs) {
3423: my (%userroles,%newrole,%newgroups,$spec,$area);
3424: my $area = '/'.$dom.'/'.$cnum;
3425: my $spec = $role.'.'.$area;
3426: if ($usec ne '') {
3427: $spec .= '/'.$usec;
3428: $area .= '/'.$usec;
3429: }
3430: if ($role =~ /^cr\//) {
3431: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
3432: $cnum,$spec,$area);
3433: } else {
3434: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
3435: $spec,$cnum,$area);
3436: }
3437: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
3438: \%newgroups);
3439: $userroles{'user.role.'.$spec} = $start.'.'.$end;
3440: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
3441: if (($end == 0) || ($end > $now)) {
3442: my $showrole = $role;
3443: if ($role =~ /^cr\//) {
3444: $showrole = &Apache::lonnet::plaintext($role,$crstype);
3445: } elsif (ref($longroles) eq 'HASH') {
3446: if ($longroles->{$role} ne '') {
3447: $showrole = $longroles->{$role};
3448: }
3449: }
3450: if ($start <= $now) {
3451: $active .= '<li><a href="/adm/roles?selectrole=1&'.
3452: $spec.'=1">'.$showrole;
3453: if ($usec ne '') {
3454: $active .= ' - '.&mt('section:').' '.$usec;
3455: }
3456: $active .= '</a></li>';
3457: $numactive ++;
3458: } else {
3459: $future .= '<li>'.$showrole;
3460: if ($usec ne '') {
3461: $future .= ' - '.&mt('section:').' '.$usec;
3462: }
3463: $future .= '</li>';
3464: $numfuture ++;
3465: }
3466: }
3467: }
3468: }
3469: }
3470: }
3471: if ($active) {
3472: if ($numactive == 1) {
3473: if ($crstype eq 'Community') {
3474: $output = &mt('Use the following link to enter the community:');
3475: } else {
3476: $output = &mt('Use the following link to enter the course:');
3477: }
3478: } else {
3479: if ($crstype eq 'Community') {
3480: $output = &mt('Use the following links to your new roles to enter the community:');
3481: } else {
3482: $output = &mt('Use the following links to your new roles to enter the course:');
3483: }
3484: }
3485: $output .= ' <ul>'.$active.'</ul><br />';
3486: }
3487: if ($future) {
3488: if ($crstype eq 'Community') {
3489: $output .= &mt('The following community [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'}))
3490: } else {
3491: $output .= &mt('The following course [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'}));
3492: }
3493: $output .= ' <ul>'.$future.'</ul>';
3494: }
3495: return $output;
3496: }
3497:
3498: sub notification_information {
3499: my ($disposition,$req_notifylist,$cnum,$now) = @_;
3500: my %emails = &Apache::loncommon::getemails();
3501: my $address;
3502: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
3503: $address = $emails{'permanentemail'};
3504: if ($address eq '') {
3505: $address = $emails{'notification'};
3506: }
3507: }
3508: my $output;
3509: if ($disposition eq 'approval') {
3510: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
3511: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
3512: if ($address ne '') {
3513: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
3514: }
3515: if ($req_notifylist) {
3516: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3517: $env{'user.domain'});
3518: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
3519: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
3520: }
3521: } elsif ($disposition eq 'pending') {
3522: $output .= '<div class="LC_info">'.
3523: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
3524: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
3525: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
3526: '</div>';
3527: } else {
3528: $output .= '<div class="LC_warning">'.
3529: &mt('Your request status is: [_1].',$disposition).
3530: '</div>';
3531: }
3532: return $output;
3533: }
3534:
3535: sub check_autolimit {
3536: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
3537: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
3538: 'userroles',['active','future'],['cc','co'],[$dom]);
3539: my ($types,$typename) = &Apache::loncommon::course_types();
3540: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
3541: my $count = 0;
3542: foreach my $key (keys(%requests)) {
3543: my ($cdom,$cnum) = split('_',$key);
3544: if (ref($requests{$key}) eq 'HASH') {
3545: next if ($requests{$key}{'crstype'} ne $crstype);
3546: if (($crstype eq 'community') &&
3547: (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
3548: $count ++;
3549: } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
3550: (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
3551: $count ++;
3552: }
3553: }
3554: }
3555: if ($count < $limit) {
3556: return 'process';
3557: } else {
3558: if (ref($typename) eq 'HASH') {
3559: if ($crstype eq 'community') {
3560: $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
3561: '<br />'.&mt("Your limit is [_1].",$limit);
3562: } else {
3563: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
3564: '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
3565: }
3566: }
3567: return 'rejected';
3568: }
3569: return;
3570: }
3571:
3572: sub retrieve_settings {
3573: my ($dom,$cnum,$udom,$uname) = @_;
3574: if ($udom eq '' || $uname eq '') {
3575: $udom = $env{'user.domain'};
3576: $uname = $env{'user.name'};
3577: }
3578: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
3579: if ($result eq 'ok') {
3580: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
3581: $env{'form.chome'} = $reqinfo{'coursehome'};
3582: $env{'form.cdescr'} = $reqinfo{'cdescr'};
3583: $env{'form.crstype'} = $reqinfo{'crstype'};
3584: &generate_date_items($reqinfo{'accessstart'},'accessstart');
3585: &generate_date_items($reqinfo{'accessend'},'accessend');
3586: if ($reqinfo{'accessend'} == 0) {
3587: $env{'form.no_end_date'} = 1;
3588: }
3589: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
3590: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
3591: &generate_date_items($reqinfo{'enrollend'},'enrollend');
3592: }
3593: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
3594: $env{'form.clonedom'} = $reqinfo{'clonedom'};
3595: $env{'form.datemode'} = $reqinfo{'datemode'};
3596: $env{'form.dateshift'} = $reqinfo{'dateshift'};
3597: if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
3598: $env{'form.sectotal'} = $reqinfo{'sectotal'};
3599: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
3600: $env{'form.autoadds'} = $reqinfo{'autoadds'};
3601: $env{'form.autdrops'} = $reqinfo{'autodrops'};
3602: $env{'form.instcode'} = $reqinfo{'instcode'};
3603: my $crscode = {
3604: $cnum => $reqinfo{'instcode'},
3605: };
3606: &extract_instcode($dom,'instcode',$crscode,$cnum);
3607: }
3608: my @currsec;
3609: if (ref($reqinfo{'sections'}) eq 'HASH') {
3610: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
3611: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
3612: my $sec = $reqinfo{'sections'}{$i}{'inst'};
3613: $env{'form.secnum_'.$i} = $sec;
3614: $env{'form.sec_'.$i} = '1';
3615: if (!grep(/^\Q$sec\E$/,@currsec)) {
3616: push(@currsec,$sec);
3617: }
3618: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
3619: }
3620: }
3621: }
3622: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
3623: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
3624: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
3625: $env{'form.crosslist_'.$i} = '1';
3626: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
3627: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
3628: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
3629: my $key = $cnum.$i;
3630: my $crscode = {
3631: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
3632: };
3633: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
3634: }
3635: }
3636: }
3637: }
3638: if (ref($reqinfo{'personnel'}) eq 'HASH') {
3639: my $i = 0;
3640: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
3641: my ($uname,$udom) = split(':',$user);
3642: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
3643: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
3644: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
3645: $env{'form.person_'.$i.'_role'} = $role;
3646: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
3647: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
3648: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
3649: $env{'form.person_'.$i.'_uname'} = $uname;
3650: $env{'form.person_'.$i.'_dom'} = $udom;
3651: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
3652: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
3653: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
3654: my @newsecs;
3655: if (@usecs > 0) {
3656: foreach my $sec (@usecs) {
3657: if (grep(/^\Q$sec\E/,@currsec)) {
3658: $env{'form.person_'.$i.'_sec'} = $sec;
3659: } else {
3660: push(@newsecs,$sec);
3661: }
3662: }
3663: }
3664: if (@newsecs > 0) {
3665: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
3666: }
3667: }
3668: }
3669: $i ++;
3670: }
3671: }
3672: }
3673: }
3674: $env{'form.persontotal'} = $i;
3675: }
3676: }
3677: }
3678: return $result;
3679: }
3680:
3681: sub get_request_settings {
3682: my ($dom,$cnum,$udom,$uname) = @_;
3683: my $requestkey = $dom.'_'.$cnum;
3684: my ($result,%reqinfo);
3685: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
3686: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
3687: my $disposition = $history{'disposition'};
3688: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
3689: if (ref($history{'details'}) eq 'HASH') {
3690: %reqinfo = %{$history{'details'}};
3691: $result = 'ok';
3692: } else {
3693: $result = 'nothash';
3694: }
3695: } else {
3696: $result = 'notqueued';
3697: }
3698: } else {
3699: $result = 'invalid';
3700: }
3701: return ($result,%reqinfo);
3702: }
3703:
3704: sub extract_instcode {
3705: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
3706: my (%codes,@codetitles,%cat_titles,%cat_order);
3707: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
3708: \@codetitles,\%cat_titles,
3709: \%cat_order) eq 'ok') {
3710: if (ref($codes{$crskey}) eq 'HASH') {
3711: if (@codetitles > 0) {
3712: my $sel = $element;
3713: if ($element eq 'crosslist') {
3714: $sel .= '_'.$counter;
3715: }
3716: foreach my $title (@codetitles) {
3717: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
3718: }
3719: }
3720: }
3721: }
3722: return;
3723: }
3724:
3725: sub generate_date_items {
3726: my ($currentval,$item) = @_;
3727: if ($currentval =~ /\d+/) {
3728: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
3729: &Apache::lonhtmlcommon::get_timedates($currentval);
3730: $env{'form.'.$item.'_day'} = $mday;
3731: $env{'form.'.$item.'_month'} = $month+1;
3732: $env{'form.'.$item.'_year'} = $year;
3733: }
3734: return;
3735: }
3736:
3737: 1;
3738:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>