File:
[LON-CAPA] /
loncom /
interface /
lonrequestcourse.pm
Revision
1.27:
download - view:
text,
annotated -
select for diffs
Mon Aug 31 14:57:06 2009 UTC (14 years, 11 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- move breadcrumb generation to &get_breadcrumbs().
- breadcrumb links point to request main menu if course request submission was
processed without error, or if course request was removed via cancel action.
- move validation of institutional code to &get_breadcrumbs() so trail is correct,
if re-display of course code setting table is needed.
- validate institutional codes for crosslisted courses
- xhtml: use three separate forms on request main menu to satisfy valid tag nesting.
- Add row_headlines in pick_box tables and aggregate items on each page into a single
pick_box table.
- Replace "Back" button on request outcome screen with link to "Make another request",
(and if request is queued - link to "Modify this request".
1: # The LearningOnline Network
2: # Request a course
3: #
4: # $Id: lonrequestcourse.pm,v 1.27 2009/08/31 14:57:06 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 check_can_request()
56:
57: =item course_types()
58:
59: =item print_main_menu()
60:
61: =item request_administration()
62:
63: =item close_popup_form()
64:
65: =item get_instcode()
66:
67: =item print_request_form()
68:
69: =item print_enrollment_menu()
70:
71: =item show_invalid_crosslists()
72:
73: =item inst_section_selector()
74:
75: =item date_setting_table()
76:
77: =item print_personnel_menu()
78:
79: =item print_request_status()
80:
81: =item print_request_logs()
82:
83: =item print_review()
84:
85: =item dates_from_form()
86:
87: =item courseinfo_form()
88:
89: =item clone_form()
90:
91: =item clone_text()
92:
93: =item coursecode_form()
94:
95: =item get_course_dom()
96:
97: =item display_navbuttons()
98:
99: =item print_request_outcome()
100:
101: =item get_processtype()
102:
103: =item check_autolimit()
104:
105: =item build_batchcreatehash()
106:
107: =item retrieve_settings()
108:
109: =item get_request_settings()
110:
111: =item extract_instcode()
112:
113: =item generate_date_items()
114:
115: =back
116:
117: =cut
118:
119: package Apache::lonrequestcourse;
120:
121: use strict;
122: use Apache::Constants qw(:common :http);
123: use Apache::lonnet;
124: use Apache::loncommon;
125: use Apache::lonlocal;
126: use Apache::loncoursequeueadmin;
127: use LONCAPA qw(:DEFAULT :match);
128:
129: sub handler {
130: my ($r) = @_;
131: &Apache::loncommon::content_type($r,'text/html');
132: $r->send_http_header;
133: if ($r->header_only) {
134: return OK;
135: }
136:
137: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
138: ['action','showdom','cnum','state']);
139: &Apache::lonhtmlcommon::clear_breadcrumbs();
140: my $dom = &get_course_dom();
141: my $action = $env{'form.action'};
142: my $state = $env{'form.state'};
143: my (%states,%stored);
144: my ($jscript,$uname,$udom,$result,$warning);
145:
146: $states{'display'} = ['details'];
147: $states{'view'} = ['pick_request','details','cancel','removal'];
148: $states{'log'} = ['filter','display'];
149: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
150:
151: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
152: unless ($env{'form.state'} eq 'crstype') {
153: unshift(@{$states{'new'}},'codepick');
154: }
155: }
156:
157: foreach my $key (keys(%states)) {
158: if (ref($states{$key}) eq 'ARRAY') {
159: unshift (@{$states{$key}},'crstype');
160: }
161: }
162:
163: my @invalidcrosslist;
164: my %trail = (
165: crstype => 'Course Request Action',
166: codepick => 'Category',
167: courseinfo => 'Description',
168: enrollment => 'Access Dates',
169: personnel => 'Personnel',
170: review => 'Review',
171: process => 'Result',
172: pick_request => 'Display Summary',
173: details => 'Request Details',
174: cancel => 'Cancel Request',
175: removal => 'Outcome',
176: );
177:
178: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
179: $trail{'enrollment'} = 'Enrollment';
180: }
181:
182: my ($page,$crumb,$newinstcode,$codechk,$checkedcode) =
183: &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
184: if ($action eq 'display') {
185: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
186: my $namespace = 'courserequestqueue';
187: if ($env{'form.cnum'} ne '') {
188: my $cnum = $env{'form.cnum'};
189: my $reqkey = $cnum.'_approval';
190: my $namespace = 'courserequestqueue';
191: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
192: my %queued =
193: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
194: if (ref($queued{$reqkey}) eq 'HASH') {
195: $uname = $queued{$reqkey}{'ownername'};
196: $udom = $queued{$reqkey}{'ownerdom'};
197: if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
198: $result = &retrieve_settings($dom,$cnum,$udom,$uname);
199: } else {
200: $warning = &mt('Invalid username or domain for course requestor');
201: }
202: } else {
203: $warning = &mt('No information was found for this course request.');
204: }
205: } else {
206: $warning = &mt('No course request ID provided.');
207: }
208: } else {
209: $warning = &mt('You do not have rights to view course request information.');
210: }
211: } elsif ((defined($state)) && (defined($action))) {
212: if (($action eq 'view') && ($state eq 'details')) {
213: if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
214: my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
215: }
216: } elsif ($env{'form.crstype'} eq 'official') {
217: if (&Apache::lonnet::auto_run('',$dom)) {
218: if (($action eq 'new') && (($state eq 'enrollment') ||
219: ($state eq 'personnel'))) {
220: my $checkcrosslist = 0;
221: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
222: if ($env{'form.crosslist_'.$i}) {
223: $checkcrosslist ++;
224: }
225: }
226: if ($checkcrosslist) {
227: my %codechk;
228: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
229: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
230: \%cat_titles,
231: \%cat_order,
232: \@code_order);
233: my $numtitles = scalar(@codetitles);
234: if ($numtitles) {
235: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
236: if ($env{'form.crosslist_'.$i}) {
237: my $codecheck;
238: my $crosslistcode = '';
239: foreach my $item (@code_order) {
240: $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item};
241: }
242: if ($crosslistcode ne '') {
243: $codechk{$i} =
244: &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
245: }
246: unless ($codechk{$i} eq 'valid') {
247: $env{'form.crosslist_'.$i} = '';
248: push(@invalidcrosslist,$crosslistcode);
249: }
250: }
251: }
252: }
253: }
254: }
255: }
256: }
257: my %elements = &form_elements($dom);
258: my $elementsref = {};
259: if (ref($elements{$action}) eq 'HASH') {
260: if (ref($elements{$action}{$state}) eq 'HASH') {
261: $elementsref = $elements{$action}{$state};
262: }
263: }
264: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
265: $env{'form.clonedom'} = $dom;
266: }
267: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
268: }
269:
270: if ($state eq 'personnel') {
271: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
272: }
273:
274: my $loaditems = &onload_action($action,$state);
275:
276: my %can_request;
277: my $canreq = &check_can_request($dom,\%can_request);
278: if ($action eq 'new') {
279: if ($canreq) {
280: if ($state eq 'crstype') {
281: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
282: $crumb);
283: } else {
284: &request_administration($r,$action,$state,$page,\%states,$dom,
285: $jscript,$loaditems,$crumb,$newinstcode,
286: $codechk,$checkedcode,\@invalidcrosslist);
287: }
288: } else {
289: $r->print(&header('Course Requests').$crumb.
290: '<div class="LC_warning">'.
291: &mt('You do not have privileges to request creation of courses.').
292: '</div>'.&Apache::loncommon::end_page());
293: }
294: } elsif ($action eq 'view') {
295: if ($state eq 'crstype') {
296: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
297: } else {
298: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
299: $loaditems,$crumb);
300: }
301: } elsif ($action eq 'display') {
302: if ($warning ne '') {
303: my $args = { only_body => 1 };
304: $r->print(&header('Course Requests','','',$args).$crumb.
305: '<h3>'.&mt('Course Request Details').'</h3>'.
306: '<div class="LC_warning">'.$warning.'</div>'.
307: &close_popup_form());
308: } else {
309: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
310: $loaditems,$crumb,'','','','',$uname,$udom);
311: }
312: } elsif ($action eq 'log') {
313: &print_request_logs($jscript,$loaditems,$crumb);
314: } else {
315: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
316: }
317: return OK;
318: }
319:
320: sub get_breadcrumbs {
321: my ($dom,$action,$state,$states,$trail) = @_;
322: my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles);
323: my $page = 0;
324: if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
325: if (defined($action)) {
326: my $done = 0;
327: my $i=0;
328: if (ref($states->{$action}) eq 'ARRAY') {
329: while ($i<@{$states->{$action}} && !$done) {
330: if ($states->{$action}[$i] eq $$state) {
331: $page = $i;
332: $done = 1;
333: }
334: $i++;
335: }
336: }
337: if ($env{'form.crstype'} eq 'official') {
338: if ($page > 1) {
339: if ($states->{$action}[$page-1] eq 'codepick') {
340: if ($env{'form.instcode'} eq '') {
341: ($newinstcode,$numtitles) = &get_instcode($dom);
342: if ($numtitles) {
343: if ($newinstcode eq '') {
344: $$state = 'codepick';
345: $page --;
346: } else {
347: $codechk =
348: &Apache::lonnet::auto_validate_instcode('',
349: $dom,$newinstcode);
350: if ($codechk ne 'valid') {
351: $$state = 'codepick';
352: $page --;
353: }
354: $checkedcode = 1;
355: }
356: }
357: }
358: }
359: }
360: }
361: for (my $i=0; $i<@{$states->{$action}}; $i++) {
362: if ($$state eq $states->{$action}[$i]) {
363: &Apache::lonhtmlcommon::add_breadcrumb(
364: {text=>"$trail->{$$state}"});
365: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
366: last;
367: } else {
368: if (($$state eq 'process') || ($$state eq 'removal')) {
369: &Apache::lonhtmlcommon::add_breadcrumb(
370: { href => '/adm/requestcourse',
371: text => "$trail->{$states->{$action}[$i]}",
372: }
373: );
374: } else {
375: &Apache::lonhtmlcommon::add_breadcrumb(
376: { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')",
377: text => "$trail->{$states->{$action}[$i]}", }
378: );
379: }
380: }
381: }
382: } else {
383: &Apache::lonhtmlcommon::add_breadcrumb(
384: {text=>'Pick Action'});
385: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
386: }
387: } else {
388: &Apache::lonhtmlcommon::add_breadcrumb(
389: {text=>'Pick Action'});
390: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
391: }
392: return ($page,$crumb,$newinstcode,$codechk,$checkedcode);
393: }
394:
395: sub header {
396: my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
397: if ($jscript) {
398: $jscript = '<script type="text/javascript">'."\n".
399: '// <![CDATA['."\n".
400: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
401: }
402: if ($loaditems) {
403: if (ref($args) eq 'HASH') {
404: my %loadhash = (
405: 'add_entries' => $loaditems,
406: );
407: my %arghash = (%loadhash,%{$args});
408: $args = \%arghash;
409: } else {
410: $args = {'add_entries' => $loaditems,};
411: }
412: }
413: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
414: }
415:
416: sub form_elements {
417: my ($dom) = @_;
418: my %elements =
419: (
420: new => {
421: crstype => {
422: crstype => 'selectbox',
423: action => 'selectbox',
424: origcnum => 'hidden',
425: },
426: courseinfo => {
427: cdescr => 'text',
428: clonecrs => 'text',
429: clonedom => 'selectbox',
430: datemode => 'radio',
431: dateshift => 'text',
432: },
433: enrollment => {
434: accessstart_month => 'selectbox',
435: accessstart_hour => 'selectbox',
436: accessend_month => 'selectbox',
437: accessend_hour => 'selectbox',
438: accessstart_day => 'text',
439: accessstart_year => 'text',
440: accessstart_minute => 'text',
441: accessstart_second => 'text',
442: accessend_day => 'text',
443: accessend_year => 'text',
444: accessend_minute => 'text',
445: accessend_second => 'text',
446: no_end_date => 'checkbox',
447: },
448: personnel => {
449: addperson => 'checkbox',
450: },
451: review => {
452: cnum => 'hidden',
453: },
454: },
455: view => {
456: crstype => {
457: crstype => 'selectbox',
458: action => 'selectbox',
459: },
460: },
461: );
462: my %servers = &Apache::lonnet::get_servers($dom,'library');
463: my $numlib = keys(%servers);
464: if ($numlib > 1) {
465: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
466: } else {
467: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
468: }
469: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
470: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
471: \%cat_order,\@code_order);
472: my $numtitles = scalar(@codetitles);
473: if ($numtitles) {
474: my %extras;
475: $lastitem = pop(@codetitles);
476: $extras{'instcode_'.$lastitem} = 'text';
477: foreach my $item (@codetitles) {
478: $extras{'instcode_'.$item} = 'selectbox';
479: }
480: $elements{'new'}{'codepick'} = \%extras;
481: }
482: if (&Apache::lonnet::auto_run('',$dom)) {
483: my %extras = (
484: sectotal => 'hidden',
485: enrollstart_month => 'selectbox',
486: enrollstart_hour => 'selectbox',
487: enrollend_month => 'selectbox',
488: enrollend_hour => 'selectbox',
489: enrollstart_day => 'text',
490: enrollstart_year => 'text',
491: enrollstart_minute => 'text',
492: enrollstart_second => 'text',
493: enrollend_day => 'text',
494: enrollend_year => 'text',
495: enrollend_minute => 'text',
496: enrollend_second => 'text',
497: addcrosslist => 'checkbox',
498: autoadds => 'radio',
499: autodrops => 'radio',
500: );
501: if ($env{'form.sectotal'} > 0) {
502: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
503: $extras{'sec_'.$i} = 'checkbox',
504: $extras{'secnum_'.$i} = 'text',
505: $extras{'loncapasec_'.$i} = 'text',
506: }
507: }
508: my $crosslisttotal = $env{'form.crosslisttotal'};
509: if ($env{'form.addcrosslist'}) {
510: $crosslisttotal ++;
511: }
512: if (!$crosslisttotal) {
513: $crosslisttotal = 1;
514: }
515:
516: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
517: if ($numtitles) {
518: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
519: }
520: if (@codetitles > 0) {
521: foreach my $item (@codetitles) {
522: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
523: }
524: }
525: $extras{'crosslist_'.$i} = 'checkbox';
526: $extras{'crosslist_'.$i.'_instsec'} = 'text',
527: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
528: }
529: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
530: %{$elements{'new'}{'enrollment'}} = %mergedhash;
531: }
532: my %people;
533: my $persontotal = $env{'form.persontotal'};
534: if ($env{'form.addperson'}) {
535: $persontotal ++;
536: }
537: if ((!defined($persontotal)) || (!$persontotal)) {
538: $persontotal = 1;
539: }
540: for (my $i=0; $i<$persontotal; $i++) {
541: $people{'person_'.$i.'_uname'} = 'text',
542: $people{'person_'.$i.'_dom'} = 'selectbox',
543: $people{'person_'.$i.'_hidedom'} = 'hidden',
544: $people{'person_'.$i.'_firstname'} = 'text',
545: $people{'person_'.$i.'_lastname'} = 'text',
546: $people{'person_'.$i.'_emailaddr'} = 'text',
547: $people{'person_'.$i.'_role'} = 'selectbox',
548: $people{'person_'.$i.'_sec'} = 'selectbox',
549: $people{'person_'.$i.'_newsec'} = 'text',
550: }
551: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
552: %{$elements{'new'}{'personnel'}} = %personnelhash;
553: return %elements;
554: }
555:
556: sub onload_action {
557: my ($action,$state) = @_;
558: my %loaditems;
559: if (($action eq 'new') || ($action eq 'view')) {
560: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)';
561: }
562: return \%loaditems;
563: }
564:
565: sub check_can_request {
566: my ($dom,$can_request) = @_;
567: my $canreq = 0;
568: my ($types,$typename) = &course_types();
569: my @options = ('approval','validate','autolimit');
570: my $optregex = join('|',@options);
571: if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) {
572: foreach my $type (@{$types}) {
573: if (&Apache::lonnet::usertools_access($env{'user.name'},
574: $env{'user.domain'},
575: $type,undef,'requestcourses')) {
576: $canreq ++;
577: if ($dom eq $env{'user.domain'}) {
578: $can_request->{$type} = 1;
579: }
580: }
581: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
582: my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type});
583: if (@curr > 0) {
584: $canreq ++;
585: unless ($dom eq $env{'user.domain'}) {
586: if (grep(/^\Q$dom\E:($optregex)(=?\d*)$/,@curr)) {
587: $can_request->{$type} = 1;
588: }
589: }
590: }
591: }
592: }
593: }
594: return $canreq;
595: }
596:
597: sub course_types {
598: my @types = ('official','unofficial','community');
599: my %typename = (
600: official => 'Official course',
601: unofficial => 'Unofficial course',
602: community => 'Community',
603: );
604: return (\@types,\%typename);
605: }
606:
607:
608: sub print_main_menu {
609: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_;
610: my ($types,$typename) = &course_types();
611: my $onchange;
612: unless ($env{'form.interface'} eq 'textual') {
613: $onchange = 1;
614: }
615:
616: my $nextstate_setter = "\n";
617: if (ref($states) eq 'HASH') {
618: foreach my $key (keys(%{$states})) {
619: if (ref($states->{$key}) eq 'ARRAY') {
620: $nextstate_setter .=
621: " if (actionchoice == '$key') {
622: nextstate = '".$states->{$key}[1]."';
623: }
624: ";
625: }
626: }
627: }
628:
629: my $js = <<"END";
630:
631: function nextPage(formname) {
632: var crschoice = document.mainmenu_coursetype.crstype.value;
633: var actionchoice = document.mainmenu_action.action.value;
634: if (check_can_request(crschoice,actionchoice) == true) {
635: if ((actionchoice == 'new') && (crschoice == 'official')) {
636: nextstate = 'codepick';
637: } else {
638: $nextstate_setter
639: }
640: formname.crstype.value = crschoice;
641: formname.action.value = actionchoice;
642: formname.state.value= nextstate;
643: formname.submit();
644: }
645: return;
646: }
647:
648: function check_can_request(crschoice,actionchoice) {
649: var official = '';
650: var unofficial = '';
651: var community = '';
652: END
653:
654: foreach my $item (keys(%{$can_request})) {
655: $js .= "
656: $item = 1;
657: ";
658: }
659: my %lt = &Apache::lonlocal::texthash(
660: official => 'You are not permitted to request creation of an official course in this domain.',
661: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
662: community => 'You are not permitted to request creation of a community this domain.',
663: all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
664: );
665: $js .= <<END;
666: if (crschoice == 'official') {
667: if (official != 1) {
668: alert("$lt{'official'}");
669: return false;
670: }
671: } else {
672: if (crschoice == 'unofficial') {
673: if (unofficial != 1) {
674: alert("$lt{'unofficial'}");
675: return false;
676: }
677: } else {
678: if (crschoice == 'community') {
679: if (community != 1) {
680: alert("$lt{'community'}");
681: return false;
682: }
683: } else {
684: if (actionchoice == 'new') {
685: alert("$lt{'all'}");
686: return false;
687: }
688: }
689: }
690: }
691: return true;
692: }
693:
694: END
695:
696: $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.'<div>'.
697: &Apache::lonhtmlcommon::start_pick_box().
698: &Apache::lonhtmlcommon::row_title(&mt('Course Domain')).
699: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
700: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange));
701: if (!$onchange) {
702: $r->print(' <input type="submit" name="godom" value="'.
703: &mt('Change').'" />');
704: }
705: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
706:
707: my $formname = 'requestcrs';
708: my $nexttext = &mt('Next');
709: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
710: <form name="mainmenu_action" method="post" action="">
711: <select size="1" name="action" >
712: <option value="new">'.&mt('New request').'</option>
713: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
714: <option value="log">'.&mt('View request history').'</option>
715: </select></form>'.
716: &Apache::lonhtmlcommon::row_closure(1).
717: &Apache::lonhtmlcommon::row_title(&mt('Course Type')).'
718: <form name="mainmenu_coursetype" method="post" action="">
719: <select size="1" name="crstype">
720: <option value="any">'.&mt('All types').'</option>');
721: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
722: foreach my $type (@{$types}) {
723: my $selected = '';
724: if ($type eq 'official') {
725: $selected = ' selected="selected"';
726: }
727: $r->print('<option value="'.$type.'"'.$selected.'>'.$typename->{$type}.
728: '</option>'."\n");
729: }
730: }
731: $r->print('</select></form>'."\n".
732: &Apache::lonhtmlcommon::row_closure(1)."\n".
733: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
734: '<div><form name="'.$formname.'" method="post" action="">'."\n".
735: '<input type="hidden" name="state" value="crstype" />'."\n".
736: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
737: '<input type="hidden" name="crstype" value="" />'."\n".
738: '<input type="hidden" name="action" value="" />'."\n".
739: '<input type="button" name="next" value="'.$nexttext.
740: '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
741: '</form></div>');
742: $r->print(&Apache::loncommon::end_page());
743: return;
744: }
745:
746: sub request_administration {
747: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
748: $newinstcode,$codechk,$checkedcode,$invalidcrosslist,$uname,$udom) = @_;
749: my $js;
750: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
751: $js = <<END;
752:
753: function nextPage(formname,nextstate) {
754: formname.state.value= nextstate;
755: formname.submit();
756: }
757:
758: END
759: }
760: if (($action eq 'new') || ($action eq 'view')) {
761: $js .= <<END;
762:
763: function backPage(formname,prevstate) {
764: formname.state.value = prevstate;
765: formname.submit();
766: }
767:
768: END
769: }
770: if ($action eq 'new') {
771: my $jsextra;
772: unless (($state eq 'review') || ($state eq 'process')) {
773: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
774: }
775: $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb);
776: &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
777: $codechk,$checkedcode,$invalidcrosslist);
778: } elsif ($action eq 'view') {
779: my $jsextra;
780: my $formname = 'requestcrs';
781: my $prev = $states->{$action}[$page-1];
782: my $next = $states->{$action}[$page+1];
783: if ($state eq 'pick_request') {
784: $next = $states->{$action}[$page+1];
785: $jsextra = &viewrequest_javascript($formname,$next);
786: } elsif ($state eq 'details') {
787: $jsextra = &viewdetails_javascript($formname);
788:
789: } elsif ($state eq 'cancel') {
790: $jsextra = &viewcancel_javascript($formname);
791: }
792: $r->print(&header('Manage course requests',$js.$jscript.$jsextra,$loaditems).
793: $crumb);
794: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
795: if ($state eq 'pick_request') {
796: $r->print('<h3>'.&mt('Pending course requests').'</h3><div>'."\n".$form."\n".
797: &print_request_status($dom).'</form>');
798: } elsif ($state eq 'details') {
799: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
800: my $origcnum = $env{'form.cnum'};
801: if ($origcnum eq '') {
802: $origcnum = $env{'form.origcnum'};
803: }
804: if ($env{'form.crstype'} eq 'official') {
805: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
806: \%cat_order,\@code_order);
807: }
808: $r->print('<h3>'.&mt('Course Request Details').'</h3><div>'."\n".$form."\n".
809: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
810: \@code_order)."\n".
811: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
812: my @excluded = &get_excluded_elements($dom,$states,'new','review');
813: push(@excluded,'origcnum');
814: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
815: my $other = 'modify';
816: my %navtxt = &Apache::lonlocal::texthash (
817: prev => 'Back',
818: other => 'Modify Request',
819: next => 'Cancel Request',
820: );
821: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'},
822: $state,$other,$navtxt{'other'});
823: $r->print('</form>');
824: } elsif ($state eq 'cancel') {
825: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
826: $r->print('<h3>'.&mt('Cancel course request').'</h3><div>'."\n".$form."\n".
827: $output);
828: my @excluded = &get_excluded_elements($dom,$states,'view','cancel');
829: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
830: my %navtxt = &Apache::lonlocal::texthash (
831: prev => 'Back',
832: next => 'Confirm Cancellation',
833: );
834: if ($result eq 'ok') {
835: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,
836: $navtxt{'next'},$state);
837: } else {
838: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},undef,'',$state);
839: }
840: $r->print('</form>');
841: } elsif ($state eq 'removal') {
842: my $cnum = $env{'form.origcnum'};
843: my $statuskey = 'status:'.$dom.':'.$cnum;
844: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
845: $env{'user.domain'},$env{'user.name'});
846: my $currstatus = $userreqhash{$statuskey};
847: my ($result,$error);
848: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
849: my %status = (
850: $statuskey => 'cancelled',
851: );
852: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
853: if ($statusresult eq 'ok') {
854: my $delresult =
855: &Apache::lonnet::del_dom('courserequestqueue',
856: [$cnum.'_'.$currstatus],$dom);
857: if ($delresult eq 'ok') {
858: $result = 'ok';
859: } else {
860: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
861: }
862: } else {
863: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
864: }
865: } else {
866: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
867: }
868: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
869: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
870: '<input type="hidden" name="action" value="'.$action.'" />'."\n".
871: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
872: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
873: if ($result eq 'ok') {
874: $r->print(&mt('Your course request has been cancelled.'));
875: } else {
876: $r->print('<div class="LC_error">'.
877: &mt('The request cancellation process was not complete.').
878: '<br />'.$error.'</div>');
879: }
880: $r->print('</form>');
881: }
882: } elsif ($action eq 'display') {
883: my $formname = 'requestcrs';
884: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
885: if ($env{'form.crstype'} eq 'official') {
886: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
887: \%cat_order,\@code_order);
888: }
889: $r->print(&header('Course Request','','','',{ 'only_body' => 1}).
890: $crumb."\n".'<h3>'.&mt('Course Request Details').'</h3>'.
891: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
892: \@code_order,$uname,$udom)."\n".'</div>'.
893: &close_popup_form());
894: } elsif ($action eq 'log') {
895: $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
896: }
897: $r->print(&Apache::loncommon::end_page());
898: return;
899: }
900:
901: sub close_popup_form {
902: my $close= &mt('Close Window');
903: return << "END";
904: <p><form name="displayreq" action="" method="post">
905: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
906: </form></p>
907: END
908: }
909:
910: sub get_instcode {
911: my ($dom) = @_;
912: my ($instcode,$numtitles);
913: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
914: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
915: \%cat_order,\@code_order);
916: $numtitles = scalar(@codetitles);
917: if (@code_order > 0) {
918: my $message;
919: foreach my $item (@code_order) {
920: $instcode .= $env{'form.instcode_'.$item};
921: }
922: }
923: return ($instcode,$numtitles);
924: }
925:
926: sub print_request_form {
927: my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
928: $invalidcrosslist) = @_;
929: my $formname = 'requestcrs';
930: my ($next,$prev,$message,$output,$codepicker,$crstype);
931: $prev = $states->{$action}[$page-1];
932: $next = $states->{$action}[$page+1];
933: my %navtxt = &Apache::lonlocal::texthash (
934: prev => 'Back',
935: next => 'Next',
936: );
937: $crstype = $env{'form.crstype'};
938: $r->print('<form name="'.$formname.'" method="post" action="/adm/requestcourse">');
939: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
940: if ($crstype eq 'official') {
941: if ($env{'form.instcode'} ne '') {
942: $instcode = $env{'form.instcode'};
943: } elsif ($newinstcode ne '') {
944: $instcode = $newinstcode;
945: }
946: if ($checkedcode) {
947: if ($codechk eq 'valid') {
948: $message = '<div class="LC_info">'.
949: &mt('The chosen course category [_1] is valid.','<b>'.
950: $instcode.'</b>').
951: '<input type="hidden" name="instcode" value="'.
952: $instcode.'" /></div>';
953: } else {
954: $message = '<div class="LC_warning">'.
955: &mt('No course was found matching your choice of institutional course category.');
956: if ($codechk ne '') {
957: $message .= '<br />'.$codechk;
958: }
959: $message .= '</div>';
960: $prev = 'crstype';
961: }
962: $r->print($message);
963: }
964: }
965: if ($prev eq 'crstype') {
966: if ($crstype eq 'official') {
967: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
968: \%cat_order,\@code_order);
969: }
970: if (@code_order > 0) {
971: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
972: \%cat_titles,\%cat_order);
973: if ($codepicker) {
974: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box().$codepicker.
975: &Apache::lonhtmlcommon::end_pick_box().'</div>');
976: } else {
977: $next = $states->{$action}[$page+2];
978: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
979: }
980: } else {
981: if ($crstype eq 'official') {
982: $next = $states->{$action}[$page+2];
983: }
984: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
985: }
986: } elsif ($prev eq 'codepick') {
987: if ($instcode eq '') {
988: $prev = $states->{$action}[$page-2];
989: }
990: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
991: } elsif ($state eq 'enrollment') {
992: if ($crstype eq 'official') {
993: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
994: \%cat_order,\@code_order);
995: }
996: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
997: \%cat_titles,\%cat_order,\@code_order,
998: $invalidcrosslist));
999: } elsif ($state eq 'personnel') {
1000: $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
1001: } elsif ($state eq 'review') {
1002: my $cnum;
1003: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
1004: $cnum = $env{'form.origcnum'};
1005: } else {
1006: $cnum = &Apache::lonnet::generate_coursenum($dom);
1007: }
1008: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1009: \%cat_order,\@code_order);
1010: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>'.
1011: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order).
1012: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1013: $navtxt{'next'} = &mt('Submit course request');
1014: } elsif ($state eq 'process') {
1015: if ($crstype eq 'official') {
1016: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1017: \%cat_order,\@code_order);
1018: }
1019: my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles,
1020: \@code_order);
1021: $r->print($result);
1022: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1023: $r->print('<p>');
1024: if ($storeresult eq 'ok') {
1025: $r->print('<a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1026: &mt('Modify this request').'</a>'.(' 'x4));
1027: }
1028: $r->print('<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1029: return;
1030: }
1031: }
1032: my @excluded = &get_excluded_elements($dom,$states,$action,$state);
1033: if ($state eq 'personnel') {
1034: push(@excluded,'persontotal');
1035: }
1036: if ($state eq 'enrollment') {
1037: push(@excluded,'crosslisttotal');
1038: }
1039: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1040: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'},$state);
1041: return;
1042: }
1043:
1044: sub get_excluded_elements {
1045: my ($dom,$states,$action,$state) = @_;
1046: my @excluded = ('counter');
1047: my %elements = &form_elements($dom);
1048: if (ref($states) eq 'HASH') {
1049: if (ref($states->{$action}) eq 'ARRAY') {
1050: my @items = @{$states->{$action}};
1051: my $numitems = scalar(@items);
1052: if ($numitems) {
1053: for (my $i=$numitems-1; $i>=0; $i--) {
1054: if (ref($elements{$action}) eq 'HASH') {
1055: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1056: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1057: push(@excluded,$key);
1058: }
1059: }
1060: }
1061: last if ($items[$i] eq $state);
1062: }
1063: }
1064: }
1065: }
1066: if (grep(/^instcode_/,@excluded)) {
1067: push(@excluded,'instcode');
1068: }
1069: return @excluded;
1070: }
1071:
1072: sub print_enrollment_menu {
1073: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1074: $invalidcrosslist) =@_;
1075: my ($sections,$autoenroll,$access_dates,$output);
1076: my $starttime = time;
1077: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1078:
1079: my %accesstitles = (
1080: 'start' => 'Default start access',
1081: 'end' => 'Default end access',
1082: );
1083: my %enrolltitles = (
1084: 'start' => 'Start auto-enrollment',
1085: 'end' => 'End auto-enrollment',
1086: );
1087: if ($env{'form.crstype'} eq 'official') {
1088: if (&Apache::lonnet::auto_run('',$dom)) {
1089: $output = &show_invalid_crosslists($invalidcrosslist);
1090: my ($section_form,$crosslist_form);
1091: $section_form = &inst_section_selector($dom,$instcode);
1092: if ($section_form) {
1093: $sections = &Apache::lonhtmlcommon::row_headline().
1094: '<h3>'.&mt('Sections for auto-enrollment').'</h3>'.
1095: &Apache::lonhtmlcommon::row_closure(1).
1096: $section_form;
1097: }
1098: my $crosslisttotal = $env{'form.crosslisttotal'};
1099: if (!$crosslisttotal) {
1100: $crosslisttotal = 1;
1101: }
1102: if ($env{'form.addcrosslist'}) {
1103: $crosslisttotal ++;
1104: }
1105: for (my $i=0; $i<$crosslisttotal; $i++) {
1106: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1107: $cat_titles,$cat_order,$i);
1108: }
1109: if ($crosslist_form) {
1110: $crosslist_form .=
1111: &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
1112: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1113: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1114: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1115: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1116: $sections .= &Apache::lonhtmlcommon::row_headline.
1117: '<h3>'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1118: &Apache::lonhtmlcommon::row_closure(1).
1119: $crosslist_form;
1120: }
1121: $autoenroll =
1122: &Apache::lonhtmlcommon::row_title(&mt('Add registered students automatically')).
1123: '<span class="LC_nobreak"><label>'.
1124: '<input type="radio" name="autoadds" value="1">'.
1125: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1126: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1127: &mt('No').'</label></span>'.
1128: &Apache::lonhtmlcommon::row_closure(1).
1129: &Apache::lonhtmlcommon::row_title(&mt('Drop unregistered students automatically')).
1130: '<span class="LC_nobreak"><label>'.
1131: '<input type="radio" name="autodrops" value="1">'.
1132: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1133: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1134: &mt('No').'</label></span>'.
1135: &Apache::lonhtmlcommon::row_closure(1).
1136: &date_setting_table($starttime,$endtime,$formname,'enroll',%enrolltitles);
1137: }
1138: }
1139: my $access_dates =
1140: &date_setting_table($starttime,$endtime,$formname,'access',%accesstitles);
1141: $output .= &Apache::lonhtmlcommon::start_pick_box();
1142: if ($sections) {
1143: $output .= $sections;
1144: }
1145: if ($autoenroll) {
1146: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1147: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1148: &Apache::lonhtmlcommon::row_closure(1).
1149: $autoenroll;
1150: }
1151: if ($access_dates) {
1152: my $header = &mt('Access dates for students');
1153: if ($env{'form.crstype'} eq 'community') {
1154: $header = &mt('Access dates for community members');
1155: }
1156: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1157: '<h3>'.$header.'</h3>'.
1158: &Apache::lonhtmlcommon::row_closure(1).
1159: $access_dates
1160: }
1161: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1162: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1163: }
1164:
1165: sub show_invalid_crosslists {
1166: my ($invalidcrosslist) = @_;
1167: my $output;
1168: if (ref($invalidcrosslist) eq 'ARRAY') {
1169: if (@{$invalidcrosslist} > 0) {
1170: $output = '<div class="LC_warning">'.
1171: &mt('The following crosslisted courses were invalid:').'<ul>';
1172: foreach my $item (@{$invalidcrosslist}) {
1173: $output .= '<li>'.$item.'</li>';
1174: }
1175: $output .= '</ul></div><br />';
1176: }
1177: }
1178: return $output;
1179: }
1180:
1181:
1182: sub inst_section_selector {
1183: my ($dom,$instcode) = @_;
1184: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1185: my $sectotal = scalar(@sections);
1186: my $output;
1187: if ($sectotal) {
1188: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1189: &Apache::loncommon::start_data_table().
1190: &Apache::loncommon::start_data_table_row().
1191: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1192: 'value="'.$sectotal.'" /></th>'.
1193: '<th>'.&mt('Institutional Section').'</th>'.
1194: '<th>'.&mt('LON-CAPA section').'</th>'.
1195: &Apache::loncommon::end_data_table_row();
1196: for (my $i=0; $i<@sections; $i++) {
1197: my $colflag = $i%2;
1198: my $checked = ' checked="checked"';
1199: if ($env{'form.origcnum'}) {
1200: $checked='';
1201: }
1202: $output .= &Apache::loncommon::start_data_table_row().
1203: '<td><input type="checkbox" name="sec_'.$i.
1204: '"'.$checked.' value="1" /></td>'.
1205: '<td>'.$sections[$i].
1206: '<input type="hidden" name="secnum_'.$i.'" value="'.
1207: $sections[$i].'" /></td>'.
1208: '<td><input type="text" size="10" name="loncapasec_'.$i.
1209: '" value="'.$sections[$i].'" /></td>'.
1210: &Apache::loncommon::end_data_table_row();
1211: }
1212: $output .= &Apache::loncommon::end_data_table().
1213: &Apache::lonhtmlcommon::row_closure();
1214: }
1215: return $output;
1216: }
1217:
1218: sub date_setting_table {
1219: my ($starttime,$endtime,$formname,$prefix,%datetitles) = @_;
1220: my ($perpetual,$table);
1221: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1222: $starttime,'','','',1,'','','',1);
1223: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1224: $endtime,'','','',1,'','','',1);
1225: my $closure = '';
1226: if ($prefix eq 'access') {
1227: $perpetual = ' <span class="LC_nobreak"><label>'.
1228: '<input type="checkbox" name="no_end_date" />'.
1229: &mt('No end date').'</label></span>';
1230: $closure = '1';
1231: }
1232: $table = &Apache::lonhtmlcommon::row_title($datetitles{'start'}).
1233: $startform.
1234: &Apache::lonhtmlcommon::row_closure(1).
1235: &Apache::lonhtmlcommon::row_title($datetitles{'end'}).
1236: $endform.$perpetual.
1237: &Apache::lonhtmlcommon::row_closure($closure);
1238: return $table;
1239: }
1240:
1241: sub print_personnel_menu {
1242: my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
1243: my $output;
1244: if ($crstype eq 'official') {
1245: if (&Apache::lonnet::auto_run('',$dom)) {
1246: $output .= &show_invalid_crosslists($invalidcrosslist);
1247: }
1248: }
1249: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1250: my $persontotal = $env{'form.persontotal'};
1251: if ((!defined($persontotal)) || (!$persontotal)) {
1252: $persontotal = 1;
1253: }
1254: if ($env{'form.addperson'}) {
1255: $persontotal ++;
1256: }
1257: my $userlinktxt = &mt('Set User');
1258: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1259:
1260: my $roleoptions;
1261: my @roles = &Apache::lonuserutils::roles_by_context('course');
1262: my $type = 'Course';
1263: if ($crstype eq 'community') {
1264: $type = 'Community';
1265: }
1266: foreach my $role (@roles) {
1267: my $plrole=&Apache::lonnet::plaintext($role,$type);
1268: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1269: }
1270: my %customroles=&Apache::lonuserutils::my_custom_roles();
1271: if (keys(%customroles) > 0) {
1272: foreach my $cust (sort(keys(%customroles))) {
1273: my $custrole='cr_cr_'.$env{'user.domain'}.
1274: '_'.$env{'user.name'}.'_'.$cust;
1275: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1276: }
1277: }
1278:
1279: my @currsecs;
1280: if ($env{'form.sectotal'}) {
1281: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1282: if (defined($env{'form.loncapasec_'.$i})) {
1283: my $lcsec = $env{'form.loncapasec_'.$i};
1284: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
1285: push(@currsecs,$lcsec);
1286: }
1287: }
1288: }
1289: }
1290:
1291: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1292: if (@currsecs) {
1293: my $existsize = scalar(@currsecs);
1294: if ($existsize > 3) {
1295: $existsize = 3;
1296: }
1297: if ($existsize > 1) {
1298: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1299: }
1300: @currsecs = sort { $a <=> $b } (@currsecs);
1301: $existtitle = &mt('Official').': ';
1302: $existops = '<option value="">'.&mt('None').'</option>';
1303: foreach my $sec (@currsecs) {
1304: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1305: }
1306: $seccolspan = ' colspan="2"';
1307: $newtitle = &mt('Other').': ';
1308: }
1309:
1310: if ($persontotal) {
1311: $output .= &Apache::lonhtmlcommon::row_headline().
1312: '<h3>'.&mt('Requestor is automatically assigned Course Coordinator role.').' '.&mt('Include other personnel?').'</h3>';
1313: }
1314: for (my $i=0; $i<$persontotal; $i++) {
1315: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1316: my $linkargstr = join("','",@linkargs);
1317: my $userlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,$userlinktxt);
1318: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value=""'.
1319: ' onFocus="this.blur();'.
1320: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');" />';
1321: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1322: "'person_".$i."_hidedom'".');'.
1323: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');';
1324: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1325: 1,$onchange).
1326: '<input type="hidden" name="person_'.$i.'_hidedom" value="'.$dom.'" />';
1327: my %form_elems;
1328: foreach my $item (@items) {
1329: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1330: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1331: 'value="" readonly="readonly" />';
1332: }
1333: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1334: $roleoptions.'</select>';
1335: my $sectionselector;
1336: if (@currsecs) {
1337: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1338: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1339: }
1340: $sectionselector .= $newtitle.
1341: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1342: $output .=
1343: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel').'<br />'.
1344: '<span class="LC_nobreak">'.$userlink.
1345: '</span>').
1346: '<table><tr><td align="center" valign="top">'.&mt('Username').'<br />'.$uname_form.'</td>'."\n".
1347: '<td align="center" valign="top" colspan="2">'.&mt('Domain').'<br />'.$udom_form.'</td></tr><tr>'."\n".
1348: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1349: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1350: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1351: '<tr><td align="center" valign="top">'.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
1352: '<td'.$seccolspan.' align="center" valign="top">'.&mt('Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1353: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
1354: }
1355: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
1356: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
1357: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1358: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1359: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1360: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1361: return $output;
1362: }
1363:
1364: sub print_request_status {
1365: my ($dom) = @_;
1366: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
1367: $env{'user.name'},'^status:'.$dom);
1368: my ($output,$formname,%queue_by_date,%typenames);
1369: if ($env{'form.crstype'} eq 'any') {
1370: %typenames = &Apache::lonlocal::texthash (
1371: official => 'Official course',
1372: unofficial => 'Unofficial course',
1373: community => 'Community',
1374: );
1375: }
1376: foreach my $key (keys(%statusinfo)) {
1377: if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {
1378: (undef,my($cdom,$cnum)) = split(':',$key);
1379: next if ($cdom ne $dom);
1380: my $requestkey = $cdom.'_'.$cnum;
1381: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1382: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1383: $env{'user.domain'},$env{'user.name'});
1384: my $entry;
1385: my $timestamp = $history{'reqtime'};
1386: my $crstype = $history{'crstype'};
1387: my $disposition = $history{'disposition'};
1388: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1389: next unless (($env{'form.crstype'} eq 'any') ||
1390: ($env{'form.crstype'} eq $crstype));
1391: next unless (($disposition eq 'approval') ||
1392: ($disposition eq 'pending'));
1393: if (ref($history{'details'}) eq 'HASH') {
1394: $entry = $requestkey.':'.$crstype.':'.
1395: &escape($history{'details'}{'cdescr'});
1396: if ($crstype eq 'official') {
1397: $entry .= ':'.&escape($history{'details'}{'instcode'});
1398: }
1399: }
1400: if ($entry ne '') {
1401: if (exists($queue_by_date{$timestamp})) {
1402: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
1403: push(@{$queue_by_date{$timestamp}},$entry);
1404: }
1405: } else {
1406: @{$queue_by_date{$timestamp}} = ($entry);
1407: }
1408: }
1409: }
1410: }
1411: }
1412: $formname = 'requestcrs';
1413: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1414: $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1415:
1416: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1417: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
1418: '<input type="hidden" name="showdom" value="" />'."\n".
1419: '<input type="hidden" name="cnum" value="" />'."\n";
1420: if (@sortedtimes > 0) {
1421: $output .= &Apache::loncommon::start_data_table().
1422: &Apache::loncommon::start_data_table_header_row().
1423: '<th>'.&mt('Action').'</th>'.
1424: '<th>'.&mt('Course Description').'</th>'.
1425: '<th>'.&mt('Domain').'</th>';
1426: if ($env{'form.crstype'} eq 'any') {
1427: $output .= '<th>'.&mt('Type').'</th>';
1428: }
1429: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1430: $output .= '<th>'.&mt('Institutional Code').'</th>';
1431: }
1432: $output .= '<th>'.&mt('Date requested').'</th>'.
1433: &Apache::loncommon::end_data_table_header_row();
1434: my $count = 0;
1435: foreach my $item (@sortedtimes) {
1436: my $showtime = &Apache::lonlocal::locallocaltime($item);
1437: if (ref($queue_by_date{$item}) eq 'ARRAY') {
1438: foreach my $request (sort(@{$queue_by_date{$item}})) {
1439: my ($key,$type,$desc,$instcode) = split(':',$request);
1440: my ($cdom,$cnum) = split('_',$key);
1441: $output .= &Apache::loncommon::start_data_table_row().
1442: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1443: '<td>'.&unescape($desc).'</td>'.
1444: '<td>'.$cdom.'</td>';
1445: if ($env{'form.crstype'} eq 'any') {
1446: my $typename = $typenames{$type};
1447: if ($typename eq '') {
1448: $typename = &mt('Unknown type');
1449: }
1450: $output .= '<td>'.$typename.'</td>';
1451: }
1452: if (($env{'form.crstype'} eq 'any') ||
1453: ($env{'form.crstype'} eq 'official')) {
1454: my $showinstcode;
1455: if ($type eq 'official') {
1456: $showinstcode = &unescape($instcode);
1457: } else {
1458: $showinstcode = &mt('Not applicable');
1459: }
1460: $output .= '<td>'.$showinstcode.'</td>';
1461: }
1462: $output .= '<td>'.$showtime.'</td>'.
1463: &Apache::loncommon::end_data_table_row();
1464: }
1465: }
1466: }
1467: $output .= &Apache::loncommon::end_data_table();
1468: } else {
1469: $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>';
1470: }
1471: $output .= '
1472: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />
1473: </form></div>';
1474: return $output;
1475: }
1476:
1477: sub print_cancel_request {
1478: my ($dom,$cnum) = @_;
1479: my $requestkey = $dom.'_'.$cnum;
1480: my ($result,$output);
1481: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1482: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1483: $env{'user.domain'},$env{'user.name'});
1484: my $timestamp = $history{'reqtime'};
1485: my $crstype = $history{'crstype'};
1486: my $status = $history{'status'};
1487: if (($status eq 'cancelled') || ($status eq 'created')) {
1488: if ($status eq 'cancelled') {
1489: $output = &mt('This request has already been cancelled.');
1490: } elsif ($status eq 'created') {
1491: $output = &mt('This request has already been processed, and a course created.');
1492: }
1493: $output = &mt('No further action will be taken');
1494: } elsif (ref($history{'details'}) eq 'HASH') {
1495: my ($types,$typename) = &course_types();
1496: my $showtype = $crstype;
1497: if (defined($typename->{$crstype})) {
1498: $showtype = $typename->{$crstype};
1499: }
1500: $output = '<p>'.&Apache::loncommon::start_data_table().
1501: &Apache::loncommon::start_data_table_header_row().
1502: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
1503: '<th>'.&mt('Type').'</th>'.
1504: &Apache::loncommon::end_data_table_header_row().
1505: &Apache::loncommon::start_data_table_row().
1506: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
1507: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
1508: '<td>'.$showtype.'</td>'.
1509: &Apache::loncommon::end_data_table_row().
1510: &Apache::loncommon::end_data_table().
1511: '<br /><div class="LC_warning">'.
1512: &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
1513: $result = 'ok';
1514: } else {
1515: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
1516: }
1517: } else {
1518: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
1519: }
1520: return ($result,$output);
1521: }
1522:
1523: sub viewrequest_javascript {
1524: my ($formname,$next) = @_;
1525: return <<"ENDJS";
1526:
1527: function chooseRequest(cdom,cnum) {
1528: document.$formname.showdom.value = cdom;
1529: document.$formname.cnum.value = cnum;
1530: nextPage(document.$formname,'$next');
1531: }
1532:
1533: ENDJS
1534: }
1535:
1536: sub viewdetails_javascript {
1537: my ($formname) = @_;
1538: return << "ENDJS";
1539:
1540: function nextPage(formname,nextstate) {
1541: if (nextstate == "modify") {
1542: formname.state.value = "personnel";
1543: formname.action.value = "new";
1544: } else {
1545: formname.state.value = nextstate;
1546: }
1547: formname.submit();
1548: }
1549:
1550: function backPage(formname,prevstate) {
1551: formname.state.value = prevstate;
1552: formname.submit();
1553: }
1554:
1555: ENDJS
1556: }
1557:
1558: sub viewcancel_javascript {
1559: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
1560: 'Your request will be removed.');
1561: return << "ENDJS";
1562: function nextPage(formname,nextstate) {
1563: if (confirm('$alert')) {
1564: formname.state.value = nextstate;
1565: formname.submit();
1566: }
1567: return;
1568: }
1569:
1570: ENDJS
1571: }
1572:
1573: sub print_request_logs {
1574: my ($jscript,$loaditems,$crumb) = @_;
1575: return;
1576: }
1577:
1578: sub print_review {
1579: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom) = @_;
1580: my ($types,$typename) = &course_types();
1581: my ($owner,$ownername,$owneremail);
1582: if ($uname eq '' || $udom eq '') {
1583: $uname = $env{'user.name'};
1584: $udom = $env{'user.domain'};
1585: }
1586: $owner = $uname.':'.$udom;
1587: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
1588: my %emails = &Apache::loncommon::getemails($uname,$udom);
1589: foreach my $email ('permanentemail','critnotification','notification') {
1590: $owneremail = $emails{$email};
1591: last if ($owneremail ne '');
1592: }
1593: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
1594: $section_headers,$section_values,$personnel_headers,$personnel_values);
1595:
1596: $crstypename = $env{'form.crstype'};
1597: if (ref($typename) eq 'HASH') {
1598: unless ($typename->{$env{'form.crstype'}} eq '') {
1599: $crstypename = $typename->{$env{'form.crstype'}};
1600: }
1601: }
1602: my $category = 'Course';
1603: if ($env{'form.crstype'} eq 'community') {
1604: $category = 'Community';
1605: }
1606:
1607: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
1608: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
1609:
1610: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
1611: '('.&Apache::lonnet::plaintext('st',$category).')';
1612: if ($env{'form.crstype'} eq 'official') {
1613: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
1614: foreach my $title (@{$codetitles}) {
1615: if ($env{'form.instcode_'.$title} ne '') {
1616: $inst_headers .= '<th>'.$title.'</th>';
1617: my $longitem = $env{'form.instcode_'.$title};
1618: if (ref($cat_titles->{$title}) eq 'HASH') {
1619: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
1620: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
1621: }
1622: }
1623: $inst_values .= '<td>'.$longitem.'</td>';
1624: }
1625: }
1626: }
1627: if (&Apache::lonnet::auto_run('',$dom)) {
1628: $enrollrow_title = &mt('Enrollment');
1629: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
1630: '<th>'.&mt('Automatic Drops').'</th>'.
1631: '<th>'.&mt('Enrollment Starts').'</th>'.
1632: '<th>'.&mt('Enrollment Ends').'</th>';
1633: $section_headers = '<th>'.&mt('Sections').'</th>'.
1634: '<th>'.&mt('Crosslistings').'</th>';
1635:
1636: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1637: my @autoroster = (&mt('No'),&mt('Yes'));
1638: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
1639: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1640: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
1641: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1642: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
1643: &mt('Institutional section').'</th>'.
1644: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1645: my $secinfo;
1646: if ($env{'form.sectotal'} > 0) {
1647: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1648: if ($env{'form.sec_'.$i}) {
1649: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1650: if ($env{'form.loncapasec_'.$i} ne '') {
1651: $secinfo .= $env{'form.loncapasec_'.$i};
1652: } else {
1653: $secinfo .= &mt('None');
1654: }
1655: $secinfo .= '</td></tr>';
1656: }
1657: }
1658: }
1659: if ($secinfo eq '') {
1660: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1661: }
1662: $section_values .= $secinfo.'</table></td><td>'.
1663: '<table class="LC_innerpickbox"><tr><th>'.
1664: &mt('Institutional course/section').'</th>'.
1665: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1666: my $xlistinfo;
1667: my $crosslisttotal = $env{'form.crosslisttotal'};
1668: if (!$crosslisttotal) {
1669: $crosslisttotal = 1;
1670: }
1671: for (my $i=0; $i<$crosslisttotal; $i++) {
1672: if ($env{'form.crosslist_'.$i}) {
1673: $xlistinfo .= '<tr><td>';
1674: if (ref($code_order) eq 'ARRAY') {
1675: if (@{$code_order} > 0) {
1676: foreach my $item (@{$code_order}) {
1677: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1678: }
1679: }
1680: }
1681: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
1682: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
1683: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
1684: } else {
1685: $xlistinfo .= &mt('None');
1686: }
1687: $xlistinfo .= '</td></tr>';
1688: }
1689: }
1690: if ($xlistinfo eq '') {
1691: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1692: }
1693: $section_values .= $xlistinfo;
1694: }
1695: $section_values .= '</table></td>';
1696: }
1697:
1698: my %ctxt = &clone_text();
1699: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1700: if (($env{'form.clonecrs'} =~ /^$match_name$/) &&
1701: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1702: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1703: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
1704: if ($canclone) {
1705: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
1706: $env{'form.clonecrs'},('description','internal.coursecode'));
1707: if (keys(%courseenv) > 0) {
1708: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
1709: $inst_values .= '<td>'.$courseenv{'description'}.' ';
1710: my $cloneinst = $courseenv{'internal.coursecode'};
1711: if ($cloneinst ne '') {
1712: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1713: } else {
1714: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1715: }
1716: $inst_values .= '</td><td>';
1717: if ($env{'form.datemode'} eq 'preserve') {
1718: $inst_values .= $ctxt{'prd'};
1719: } elsif ($env{'form.datemode'} eq 'shift') {
1720: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
1721: } else {
1722: $inst_values .= $ctxt{'ncd'};
1723: }
1724: $inst_values .= '</td>';
1725: } else {
1726: $inst_values .= '<td>'.&mt('Unknown').'</td>';
1727: }
1728: } else {
1729: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
1730: }
1731: } else {
1732: $inst_values .= '<td>'.&mt('None').'</td>';
1733: }
1734: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
1735: '<th>'.&mt('Access Ends').'</th>';
1736: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1737: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
1738: if ($accessend == 0) {
1739: $enroll_values .= '<td>'.&mt('No end date').'</td>';
1740: } else {
1741: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1742: }
1743:
1744: my $container = 'Course';
1745: if ($env{'form.crstype'} eq 'community') {
1746: $container = 'Community';
1747: }
1748:
1749: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
1750: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
1751: '</th>';
1752: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1753: '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
1754: '<td>'.&mt('None').'</td></tr>';
1755: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1756: if ($env{'form.person_'.$i.'_uname'} ne '') {
1757: my @allsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1758: my $newsec = $env{'form.person_'.$i.'_newsec'};
1759: $newsec =~ s/^\s+//;
1760: $newsec =~s/\s+$//;
1761: my @newsecs = split(/[\s,;]+/,$newsec);
1762: foreach my $sec (@newsecs) {
1763: next if ($sec =~ /\W/);
1764: next if ($newsec eq 'none');
1765: if ($sec ne '') {
1766: unless (grep(/^\Q$sec\E$/,@allsecs)) {
1767: push(@allsecs,$sec);
1768: }
1769: }
1770: }
1771: my $showsec;
1772: if (@allsecs) {
1773: $showsec = join(', ',@allsecs);
1774: }
1775: if ($showsec eq '') {
1776: $showsec = &mt('None');
1777: }
1778: if ($env{'form.person_'.$i.'_role'} eq 'cc') {
1779: $showsec = &mt('None');
1780: }
1781: $personnel_values .=
1782: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
1783: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1784: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
1785: $env{'form.person_'.$i.'_dom'}.'</td>'.
1786: '<td>'.&Apache::lonnet::plaintext($env{'form.person_'.$i.'_role'},
1787: $container).'</td>'.
1788: '<td>'.$showsec.'</td></tr>';
1789: }
1790: }
1791: my $output =
1792: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1793: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1794: '<table class="LC_innerpickbox"><tr>'.
1795: '<th>'.&mt('Name').'</th>'.
1796: '<th>'.&mt('Username:Domain').'</th>'.
1797: '<th>'.&mt('E-mail address').'</th>'.
1798: '</tr><tr>'."\n".
1799: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
1800: '<td>'.$owneremail.'</td>'.
1801: '</tr></table>'."\n".
1802: &Apache::lonhtmlcommon::row_closure().
1803: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1804: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
1805: '<tr>'.$inst_values.'</tr></table>'."\n".
1806: &Apache::lonhtmlcommon::row_closure().
1807: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1808: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
1809: '<tr>'.$enroll_values.'</tr></table>'."\n".
1810: &Apache::lonhtmlcommon::row_closure();
1811: if ($section_headers ne '') {
1812: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
1813: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
1814: '<tr>'.$section_values.'</tr></table>'."\n".
1815: &Apache::lonhtmlcommon::row_closure();
1816: }
1817: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
1818: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
1819: $personnel_values.'</table>'."\n".
1820: &Apache::lonhtmlcommon::row_closure(1).
1821: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1822: return $output;
1823: }
1824:
1825: sub dates_from_form {
1826: my ($startname,$endname) = @_;
1827: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1828: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1829: if ($endname eq 'accessend') {
1830: if (exists($env{'form.no_end_date'}) ) {
1831: $enddate = 0;
1832: }
1833: }
1834: return ($startdate,$enddate);
1835: }
1836:
1837: sub courseinfo_form {
1838: my ($dom,$formname,$crstype,$next) = @_;
1839: my $nodescr = &mt('You must provide a (brief) course description.');
1840: my $js_validate = <<"ENDJS";
1841: <script type="text/javascript">
1842: // <![CDATA['
1843:
1844: function validateForm() {
1845: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1846: alert('$nodescr');
1847: return;
1848: }
1849: nextPage(document.$formname,'$next');
1850: }
1851: // ]]
1852: </script>
1853:
1854: ENDJS
1855: my $title = &mt('Brief Course Description');
1856: if ($crstype eq 'community') {
1857: $title = &mt('Brief Community Description');
1858: }
1859: my $output .= $js_validate."\n".'<div>'.&Apache::lonhtmlcommon::start_pick_box().
1860: &Apache::lonhtmlcommon::row_headline().
1861: '<h3>'.$title.'</h3>'.
1862: &Apache::lonhtmlcommon::row_closure(1).
1863: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1864: '<input type="text" size="40" name="cdescr" />';
1865: my ($home_server_pick,$numlib) =
1866: &Apache::loncommon::home_server_form_item($dom,'chome',
1867: 'default','hide');
1868: if ($numlib > 1) {
1869: $output .= &Apache::lonhtmlcommon::row_closure().
1870: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1871: }
1872: $output .= $home_server_pick.
1873: &Apache::lonhtmlcommon::row_closure().
1874: &Apache::lonhtmlcommon::row_headline().
1875: '<h3>'.&mt('Clone content and settings from an existing course?').'</h3>'.
1876: &Apache::lonhtmlcommon::row_closure(1).
1877: &clone_form($dom,$formname,$crstype).
1878: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
1879: return $output;
1880: }
1881:
1882: sub clone_form {
1883: my ($dom,$formname,$crstype) = @_;
1884: my $type = 'Course';
1885: if ($crstype eq 'community') {
1886: $type = 'Community';
1887: }
1888: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').
1889: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1890: my %lt = &clone_text();
1891: my $output .=
1892: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1893: '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();'.
1894: 'opencrsbrowser('."'$formname','clonecrs','clonedom','','','','$type'".');" />'.
1895: '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
1896: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
1897: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
1898: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
1899: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
1900: '</label><br /><label>'.
1901: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
1902: '</label><br /><label>'.
1903: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
1904: $lt{'shd'}.'</label>'.
1905: '<input type="text" size="5" name="dateshift" value="365" />'.
1906: &Apache::lonhtmlcommon::row_closure(1);
1907: return $output;
1908: }
1909:
1910: sub clone_text {
1911: return &Apache::lonlocal::texthash(
1912: 'cid' => 'Course ID',
1913: 'dmn' => 'Domain',
1914: 'dsh' => 'Date Shift',
1915: 'ncd' => 'Do not clone date parameters',
1916: 'prd' => 'Clone date parameters as-is',
1917: 'shd' => 'Shift date parameters by number of days',
1918: );
1919: }
1920:
1921: sub coursecode_form {
1922: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1923: my $output;
1924: my %rowtitle = (
1925: instcode => 'Course Category',
1926: crosslist => 'Cross Listed Course',
1927: );
1928: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
1929: (ref($cat_order))) {
1930: my ($sel,$instsec,$lcsec);
1931: $sel = $context;
1932: if ($context eq 'crosslist') {
1933: $sel .= '_'.$num;
1934: $instsec = &mt('Institutional section').'<br />'.
1935: '<input type="text" size="10" name="'.$sel.'_instsec" />';
1936: $lcsec = &mt('LON-CAPA section').'<br />'.
1937: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
1938: }
1939: if (@{$codetitles} > 0) {
1940: my $lastitem = pop(@{$codetitles});
1941: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1942: if (@{$codetitles} > 0) {
1943: $output = &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1944: '<table><tr>';
1945: if ($context eq 'crosslist') {
1946: $output .= '<td>'.&mt('Include?').'<br />'.
1947: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1948: }
1949: foreach my $title (@{$codetitles}) {
1950: if (ref($cat_order->{$title}) eq 'ARRAY') {
1951: if (@{$cat_order->{$title}} > 0) {
1952: $output .= '<td align="center">'.$title.'<br />'."\n".
1953: '<select name="'.$sel.'_'.$title.'">'."\n".
1954: ' <option value="" selected="selected">'.
1955: &mt('Select').'</option>'."\n";
1956: foreach my $item (@{$cat_order->{$title}}) {
1957: my $longitem = $item;
1958: if (ref($cat_titles->{$title}) eq 'HASH') {
1959: if ($cat_titles->{$title}{$item} ne '') {
1960: $longitem = $cat_titles->{$title}{$item};
1961: }
1962: }
1963: $output .= '<option value="'.$item.'">'.$longitem.
1964: '</option>'."\n";
1965: }
1966: }
1967: $output .= '</select></td>'."\n";
1968: }
1969: }
1970: if ($context eq 'crosslist') {
1971: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1972: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
1973: '<td align="center">'.$lcsec.'</td></tr></table>';
1974: } else {
1975: $output .= '</tr></table>'.
1976: &Apache::lonhtmlcommon::row_closure().
1977: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1978: $lastinput;
1979: }
1980: } else {
1981: if ($context eq 'crosslist') {
1982: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1983: '<table><tr>'.
1984: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
1985: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
1986: '</tr></table>';
1987: } else {
1988: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1989: $lastinput;
1990: }
1991: }
1992: $output .= &Apache::lonhtmlcommon::row_closure(1);
1993: push(@$codetitles,$lastitem);
1994: } elsif ($context eq 'crosslist') {
1995: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1996: '<table><tr><td align="center">'.
1997: '<span class="LC_nobreak">'.&mt('Include?').
1998: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
1999: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
2000: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
2001: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
2002: &Apache::lonhtmlcommon::row_closure(1);
2003: }
2004: }
2005: return $output;
2006: }
2007:
2008: sub get_course_dom {
2009: my $codedom = &Apache::lonnet::default_login_domain();
2010: if ($env{'form.showdom'} ne '') {
2011: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
2012: return $env{'form.showdom'};
2013: }
2014: }
2015: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
2016: my ($types,$typename) = &course_types();
2017: if (ref($types) eq 'ARRAY') {
2018: foreach my $type (@{$types}) {
2019: if (&Apache::lonnet::usertools_access($env{'user.name'},
2020: $env{'user.domain'},$type,
2021: undef,'requestcourses')) {
2022: return $env{'user.domain'};
2023: }
2024: }
2025: my @possible_doms;
2026: foreach my $type (@{$types}) {
2027: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
2028: if ($dom_str ne '') {
2029: my @domains = split(',',$dom_str);
2030: foreach my $entry (@domains) {
2031: my ($extdom,$extopt) = split(':',$entry);
2032: if ($extdom eq $env{'request.role.domain'}) {
2033: return $extdom;
2034: }
2035: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
2036: push(@possible_doms,$extdom);
2037: }
2038: }
2039: }
2040: }
2041: if (@possible_doms) {
2042: @possible_doms = sort(@possible_doms);
2043: return $possible_doms[0];
2044: }
2045: }
2046: $codedom = $env{'user.domain'};
2047: if ($env{'request.role.domain'} ne '') {
2048: $codedom = $env{'request.role.domain'};
2049: }
2050: }
2051: return $codedom;
2052: }
2053:
2054: sub display_navbuttons {
2055: my ($r,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
2056: $r->print('<div class="LC_navbuttons">');
2057: if ($prev) {
2058: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2059: 'onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>'.
2060: (' 'x3));
2061: } elsif ($prevtext) {
2062: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2063: 'onclick="javascript:history.back()"/>'.(' 'x3));
2064: }
2065: if ($state eq 'details') {
2066: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
2067: 'onclick="javascript:nextPage(document.'.$formname.','."'".$other."'".
2068: ')" />');
2069: }
2070: if ($state eq 'courseinfo') {
2071: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2072: 'onclick="javascript:validateForm();" />');
2073: } elsif ($next) {
2074: $r->print('
2075: <input type="button" name="next" value="'.$nexttext.'" '.
2076: 'onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
2077: }
2078: $r->print('</div>');
2079: }
2080:
2081: sub print_request_outcome {
2082: my ($dom,$codetitles,$code_order) = @_;
2083: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
2084: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
2085: my $sectotal = $env{'form.sectotal'};
2086: my $crosslisttotal = 0;
2087: $cnum = $env{'form.cnum'};
2088: unless ($cnum =~ /^$match_courseid$/) {
2089: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
2090: return $output;
2091: }
2092:
2093: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
2094: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2095: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
2096: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
2097: }
2098: }
2099: $now = time;
2100: $crstype = $env{'form.crstype'};
2101: my @instsections;
2102: if ($crstype eq 'official') {
2103: if (&Apache::lonnet::auto_run('',$dom)) {
2104: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
2105: }
2106: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2107: if ($env{'form.sec_'.$i}) {
2108: if ($env{'form.secnum_'.$i} ne '') {
2109: my $sec = $env{'form.secnum_'.$i};
2110: $sections{$i}{'inst'} = $sec;
2111: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
2112: push(@instsections,$sec);
2113: }
2114: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
2115: }
2116: }
2117: }
2118: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
2119: if ($env{'form.crosslist_'.$i}) {
2120: my $xlistinfo = '';
2121: if (ref($code_order) eq 'ARRAY') {
2122: if (@{$code_order} > 0) {
2123: foreach my $item (@{$code_order}) {
2124: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
2125: }
2126: }
2127: }
2128: $crosslistings{$i}{'instcode'} = $xlistinfo;
2129: if ($xlistinfo ne '') {
2130: $crosslisttotal ++;
2131: }
2132: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
2133: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
2134: }
2135: }
2136: } else {
2137: $enrollstart = '';
2138: $enrollend = '';
2139: }
2140: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2141: my $uname = $env{'form.person_'.$i.'_uname'};
2142: my $udom = $env{'form.person_'.$i.'_dom'};
2143: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
2144: if (&Apache::lonnet::domain($udom) ne '') {
2145: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
2146: $personnel{$uname.':'.$udom} = {
2147: firstname => $env{'form.person_'.$i.'_firstname'},
2148: lastname => $env{'form.person_'.$i.'_lastname'},
2149: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
2150: };
2151: }
2152: my $role = $env{'form.person_'.$i.'_role'};
2153: unless ($role eq '') {
2154: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
2155: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
2156: unless (grep(/^\Q$role\E$/,@curr_roles)) {
2157: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
2158: }
2159: } else {
2160: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
2161: }
2162: if ($role eq 'cc') {
2163: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
2164: } else {
2165: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2166: my $newsec = $env{'form.person_'.$i.'_newsec'};
2167: $newsec =~ s/^\s+//;
2168: $newsec =~s/\s+$//;
2169: my @newsecs = split(/[\s,;]+/,$newsec);
2170: foreach my $sec (@newsecs) {
2171: next if ($sec =~ /\W/);
2172: next if ($newsec eq 'none');
2173: if ($sec ne '') {
2174: unless (grep(/^\Q$sec\E$/,@currsec)) {
2175: push(@currsec,$sec);
2176: }
2177: }
2178: }
2179: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @currsec;
2180: }
2181: }
2182: } else {
2183: push(@missingdom,$uname.':'.$udom);
2184: }
2185: } else {
2186: push(@baduname,$uname.':'.$udom);
2187: }
2188: }
2189: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2190: my $autodrops = 0;
2191: if ($env{'form.autodrops'}) {
2192: $autodrops = $env{'form.autodrops'};
2193: }
2194: my $autoadds = 0;
2195: if ($env{'form.autoadds'}) {
2196: $autodrops = $env{'form.autoadds'};
2197: }
2198: if ($env{'form.autoadds'}) {
2199: $autodrops = $env{'form.autoadds'};
2200: }
2201: my $instcode = '';
2202: if (exists($env{'form.instcode'})) {
2203: $instcode = $env{'form.instcode'};
2204: }
2205: my $clonecrs = '';
2206: my $clonedom = '';
2207: if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
2208: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
2209: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
2210: $env{'form.clonedom'});
2211: if ($clonehome ne 'no_host') {
2212: my $canclone =
2213: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
2214: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
2215: if ($canclone) {
2216: $clonecrs = $env{'form.clonecrs'};
2217: $clonedom = $env{'form.clonedom'};
2218: }
2219: }
2220: }
2221: my $details = {
2222: owner => $env{'user.name'},
2223: domain => $env{'user.domain'},
2224: cdom => $dom,
2225: cnum => $cnum,
2226: coursehome => $env{'form.chome'},
2227: cdescr => $env{'form.cdescr'},
2228: crstype => $env{'form.crstype'},
2229: instcode => $instcode,
2230: clonedom => $clonedom,
2231: clonecrs => $clonecrs,
2232: datemode => $env{'form.datemode'},
2233: dateshift => $env{'form.dateshift'},
2234: sectotal => $sectotal,
2235: sections => \%sections,
2236: crosslisttotal => $crosslisttotal,
2237: crosslists => \%crosslistings,
2238: autoadds => $autoadds,
2239: autodrops => $autodrops,
2240: enrollstart => $enrollstart,
2241: enrollend => $enrollend,
2242: accessstart => $accessstart,
2243: accessend => $accessend,
2244: personnel => \%personnel,
2245: };
2246: my (@inststatuses,$storeresult,$creationresult);
2247: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
2248: if ($val eq '') {
2249: if ($crstype eq 'official') {
2250: $output = &mt('You are not permitted to request creation of official courses.');
2251: } elsif ($crstype eq 'unofficial') {
2252: $output = &mt('You are not permitted to request creation of unofficial courses.');
2253: } elsif ($crstype eq 'community') {
2254: $output = &mt('You are not permitted to request creation of communities');
2255: } else {
2256: $output = &mt('Unrecognized course type: [_1]',$crstype);
2257: }
2258: $storeresult = 'notpermitted';
2259: } else {
2260: my ($disposition,$message,$reqstatus);
2261: my %reqhash = (
2262: reqtime => $now,
2263: crstype => $crstype,
2264: details => $details,
2265: );
2266: my $requestkey = $dom.'_'.$cnum;
2267: my $validationerror;
2268: if ($val eq 'autolimit=') {
2269: $disposition = 'process';
2270: } elsif ($val =~ /^autolimit=(\d+)$/) {
2271: my $limit = $1;
2272: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
2273: $dom,$crstype,$limit,\$message);
2274: } elsif ($val eq 'validate') {
2275: my ($inststatuslist,$validationchk,$validation);
2276: if (@inststatuses > 0) {
2277: $inststatuslist = join(',',@inststatuses);
2278: }
2279: my $instseclist;
2280: if (@instsections > 0) {
2281: $instseclist = join(',',@instsections);
2282: }
2283: $validationchk =
2284: &Apache::lonnet::auto_courserequest_validation($dom,
2285: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
2286: $inststatuslist,$instcode,$instseclist);
2287: if ($validationchk =~ /:/) {
2288: ($validation,$message) = split(':',$validationchk);
2289: } else {
2290: $validation = $validationchk;
2291: }
2292: if ($validation =~ /^error(.*)$/) {
2293: $disposition = 'approval';
2294: $validationerror = $1;
2295: } else {
2296: $disposition = $validation;
2297: }
2298: } else {
2299: $disposition = 'approval';
2300: }
2301: $reqhash{'disposition'} = $disposition;
2302: $reqstatus = $disposition;
2303: my ($modified,$queued);
2304: if ($disposition eq 'rejected') {
2305: $output = &mt('Your course request was rejected.');
2306: if ($message) {
2307: $output .= '<div class="LC_warning">'.$message.'</div>';
2308: }
2309: $storeresult = 'rejected';
2310: } elsif ($disposition eq 'process') {
2311: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
2312: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
2313: my @roles = &Apache::lonuserutils::roles_by_context('course');
2314: my $type = 'Course';
2315: if ($crstype eq 'community') {
2316: $type = 'Community';
2317: }
2318: foreach my $role (@roles) {
2319: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
2320: }
2321: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
2322: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
2323: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
2324: if ($result eq 'created') {
2325: $disposition = 'created';
2326: $reqstatus = 'created';
2327: $output = &mt('Your course request has been processed and the course has been created.').
2328: '<br />'.
2329: &mt('You will need to logout and log-in again to be able to select a role in the course.');
2330: $creationresult = 'created';
2331: } else {
2332: $output = '<span class="LC_error">'.
2333: &mt('An error occurred when processing your course request.').
2334: '<br />'.
2335: &mt('You may want to review the request details and submit the request again.').
2336: '</span>';
2337: $creationresult = 'error';
2338: }
2339: } else {
2340: my $requestid = $cnum.'_'.$disposition;
2341: my $request = {
2342: $requestid => {
2343: timestamp => $now,
2344: crstype => $crstype,
2345: ownername => $env{'user.name'},
2346: ownerdom => $env{'user.domain'},
2347: description => $env{'form.cdescr'},
2348: },
2349: };
2350: my $statuskey = 'status:'.$dom.':'.$cnum;
2351: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
2352: $env{'user.domain'},$env{'user.name'});
2353: if ($userreqhash{$statuskey} ne '') {
2354: $modified = 1;
2355: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
2356: my %queuehash = &Apache::lonnet::get('courserequestqueue',
2357: [$cnum.'_approval',
2358: $cnum.'_pending'],$dom,$uname);
2359: if (($queuehash{$cnum.'_approval'} ne '') ||
2360: ($queuehash{$cnum.'_pending'} ne '')) {
2361: $queued = 1;
2362: }
2363: }
2364: unless ($queued) {
2365: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
2366: $dom);
2367: if ($putresult eq 'ok') {
2368: $output = &mt('Your course request has been recorded.').'<br />'.
2369: ¬ification_information($disposition,$req_notifylist,
2370: $cnum,$now);
2371: } else {
2372: $reqstatus = 'domainerror';
2373: $reqhash{'disposition'} = $disposition;
2374: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
2375: $output = '<span class"LC_warning">'.$warning.'</span><br />';
2376: }
2377: }
2378: }
2379: my ($statusresult);
2380: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2381: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
2382: 'courserequests');
2383: if ($storeresult eq 'ok') {
2384: my %status = (
2385: 'status:'.$dom.':'.$cnum => $reqstatus,
2386: );
2387: $statusresult = &Apache::lonnet::put('courserequests',\%status);
2388: }
2389: } else {
2390: $storeresult = 'error: invalid requestkey format';
2391: }
2392: if ($storeresult ne 'ok') {
2393: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
2394: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
2395: } elsif ($statusresult ne 'ok') {
2396: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
2397: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
2398: }
2399: if ($modified && $queued && $storeresult eq 'ok') {
2400: $output .= '<p>'.&mt('Your course request has been updated').'</p>'.
2401: ¬ification_information($disposition,$req_notifylist,$cnum,$now);
2402: }
2403: if ($validationerror ne '') {
2404: $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
2405: }
2406: }
2407: if ($creationresult ne '') {
2408: return ($creationresult,$output);
2409: } else {
2410: return ($storeresult,$output);
2411: }
2412: }
2413:
2414: sub notification_information {
2415: my ($disposition,$req_notifylist,$cnum,$now) = @_;
2416: my %emails = &Apache::loncommon::getemails();
2417: my $address;
2418: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
2419: $address = $emails{'permanentemail'};
2420: if ($address eq '') {
2421: $address = $emails{'notification'};
2422: }
2423: }
2424: my $output;
2425: if ($disposition eq 'approval') {
2426: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
2427: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
2428: if ($address ne '') {
2429: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
2430: }
2431: if ($req_notifylist) {
2432: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
2433: $env{'user.domain'});
2434: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
2435: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
2436: }
2437: } elsif ($disposition eq 'pending') {
2438: $output .= '<div class="LC_info">'.
2439: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
2440: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
2441: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
2442: '</div>';
2443: } else {
2444: $output .= '<div class="LC_warning">'.
2445: &mt('Your request status is: [_1].',$disposition).
2446: '</div>'
2447: }
2448: return $output;
2449: }
2450:
2451: sub get_processtype {
2452: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
2453: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
2454: my (%userenv,%settings,$val);
2455: my @options = ('autolimit','validate','approval');
2456: if ($dom eq $env{'user.domain'}) {
2457: %userenv =
2458: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
2459: 'requestcourses.'.$crstype,'inststatus');
2460: if ($userenv{'requestcourses.'.$crstype}) {
2461: $val = $userenv{'requestcourses.'.$crstype};
2462: @{$inststatuses} = ('_custom_');
2463: } else {
2464: my ($task,%alltasks);
2465: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
2466: %settings = %{$domconfig->{'requestcourses'}};
2467: if (ref($settings{$crstype}) eq 'HASH') {
2468: if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
2469: $val = $settings{$crstype}{'_LC_adv'};
2470: @{$inststatuses} = ('_LC_adv_');
2471: } else {
2472: if ($userenv{'inststatus'} ne '') {
2473: @{$inststatuses} = split(',',$userenv{'inststatus'});
2474: } else {
2475: @{$inststatuses} = ('default');
2476: }
2477: foreach my $status (@{$inststatuses}) {
2478: if (exists($settings{$crstype}{$status})) {
2479: my $value = $settings{$crstype}{$status};
2480: next unless ($value);
2481: unless (exists($alltasks{$value})) {
2482: if (ref($alltasks{$value}) eq 'ARRAY') {
2483: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
2484: push(@{$alltasks{$value}},$status);
2485: }
2486: } else {
2487: @{$alltasks{$value}} = ($status);
2488: }
2489: }
2490: }
2491: }
2492: my $maxlimit = 0;
2493:
2494: foreach my $key (sort(keys(%alltasks))) {
2495: if ($key =~ /^autolimit=(\d*)$/) {
2496: if ($1 eq '') {
2497: $val ='autolimit=';
2498: last;
2499: } elsif ($1 > $maxlimit) {
2500: $maxlimit = $1;
2501: }
2502: }
2503: }
2504: if ($maxlimit) {
2505: $val = 'autolimit='.$maxlimit;
2506: } else {
2507: foreach my $option (@options) {
2508: if ($alltasks{$option}) {
2509: $val = $option;
2510: last;
2511: }
2512: }
2513: }
2514: }
2515: }
2516: }
2517: }
2518: } else {
2519: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
2520: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
2521: if ($userenv{'reqcrsotherdom.'.$crstype}) {
2522: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
2523: my $optregex = join('|',@options);
2524: foreach my $item (@doms) {
2525: my ($extdom,$extopt) = split(':',$item);
2526: if ($extdom eq $dom) {
2527: if ($extopt =~ /^($optregex)(=?\d*)$/) {
2528: $val = $1.$2;
2529: }
2530: last;
2531: }
2532: }
2533: @{$inststatuses} = ('_external_');
2534: }
2535: }
2536: return $val;
2537: }
2538:
2539: sub check_autolimit {
2540: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
2541: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
2542: 'userroles',['active','future'],['cc'],[$dom]);
2543: my ($types,$typename) = &course_types();
2544: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
2545: my %count;
2546: if (ref($types) eq 'ARRAY') {
2547: foreach my $type (@{$types}) {
2548: $count{$type} = 0;
2549: }
2550: }
2551: foreach my $key (keys(%requests)) {
2552: my ($cdom,$cnum) = split('_',$key);
2553: if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
2554: if (ref($requests{$key}) eq 'HASH') {
2555: my $type = $requests{$key}{'crstype'};
2556: if ($type =~ /^official|unofficial|community$/) {
2557: $count{$type} ++;
2558: }
2559: }
2560: }
2561: }
2562: if ($count{$crstype} < $limit) {
2563: return 'process';
2564: } else {
2565: if (ref($typename) eq 'HASH') {
2566: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').'<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
2567: }
2568: return 'rejected';
2569: }
2570: return;
2571: }
2572:
2573: sub retrieve_settings {
2574: my ($dom,$cnum,$udom,$uname) = @_;
2575: if ($udom eq '' || $uname eq '') {
2576: $udom = $env{'user.domain'};
2577: $uname = $env{'user.name'};
2578: }
2579: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
2580: if ($result eq 'ok') {
2581: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
2582: $env{'form.chome'} = $reqinfo{'coursehome'};
2583: $env{'form.cdescr'} = $reqinfo{'cdescr'};
2584: $env{'form.crstype'} = $reqinfo{'crstype'};
2585: &generate_date_items($reqinfo{'accessstart'},'accessstart');
2586: &generate_date_items($reqinfo{'accessend'},'accessend');
2587: if ($reqinfo{'accessend'} == 0) {
2588: $env{'form.no_end_date'} = 1;
2589: }
2590: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
2591: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
2592: &generate_date_items($reqinfo{'enrollend'},'enrollend');
2593: }
2594: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
2595: $env{'form.clonedom'} = $reqinfo{'clonedom'};
2596: $env{'form.datemode'} = $reqinfo{'datemode'};
2597: $env{'form.dateshift'} = $reqinfo{'dateshift'};
2598: if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
2599: $env{'form.sectotal'} = $reqinfo{'sectotal'};
2600: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
2601: $env{'form.autoadds'} = $reqinfo{'autoadds'};
2602: $env{'form.autdrops'} = $reqinfo{'autodrops'};
2603: $env{'form.instcode'} = $reqinfo{'instcode'};
2604: my $crscode = {
2605: $cnum => $reqinfo{'instcode'},
2606: };
2607: &extract_instcode($dom,'instcode',$crscode,$cnum);
2608: }
2609: my @currsec;
2610: if (ref($reqinfo{'sections'}) eq 'HASH') {
2611: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
2612: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
2613: my $sec = $reqinfo{'sections'}{$i}{'inst'};
2614: $env{'form.secnum_'.$i} = $sec;
2615: $env{'form.sec_'.$i} = '1';
2616: if (!grep(/^\Q$sec\E$/,@currsec)) {
2617: push(@currsec,$sec);
2618: }
2619: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
2620: }
2621: }
2622: }
2623: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
2624: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
2625: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
2626: $env{'form.crosslist_'.$i} = '1';
2627: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
2628: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
2629: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
2630: my $key = $cnum.$i;
2631: my $crscode = {
2632: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
2633: };
2634: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
2635: }
2636: }
2637: }
2638: }
2639: if (ref($reqinfo{'personnel'}) eq 'HASH') {
2640: my $i = 0;
2641: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
2642: my ($uname,$udom) = split(':',$user);
2643: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
2644: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
2645: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
2646: $env{'form.person_'.$i.'_role'} = $role;
2647: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
2648: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
2649: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
2650: $env{'form.person_'.$i.'_uname'} = $uname;
2651: $env{'form.person_'.$i.'_dom'} = $udom;
2652: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
2653: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
2654: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
2655: my @newsecs;
2656: if (@usecs > 0) {
2657: foreach my $sec (@usecs) {
2658: if (grep(/^\Q$sec\E/,@currsec)) {
2659: $env{'form.person_'.$i.'_sec'} = $sec;
2660: } else {
2661: push(@newsecs,$sec);
2662: }
2663: }
2664: }
2665: if (@newsecs > 0) {
2666: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
2667: }
2668: }
2669: }
2670: $i ++;
2671: }
2672: }
2673: }
2674: }
2675: $env{'form.persontotal'} = $i;
2676: }
2677: }
2678: }
2679: return $result;
2680: }
2681:
2682: sub get_request_settings {
2683: my ($dom,$cnum,$udom,$uname) = @_;
2684: my $requestkey = $dom.'_'.$cnum;
2685: my ($result,%reqinfo);
2686: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2687: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
2688: my $disposition = $history{'disposition'};
2689: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
2690: if (ref($history{'details'}) eq 'HASH') {
2691: %reqinfo = %{$history{'details'}};
2692: $result = 'ok';
2693: } else {
2694: $result = 'nothash';
2695: }
2696: } else {
2697: $result = 'notqueued';
2698: }
2699: } else {
2700: $result = 'invalid';
2701: }
2702: return ($result,%reqinfo);
2703: }
2704:
2705: sub extract_instcode {
2706: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
2707: my (%codes,@codetitles,%cat_titles,%cat_order);
2708: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
2709: \@codetitles,\%cat_titles,
2710: \%cat_order) eq 'ok') {
2711: if (ref($codes{$crskey}) eq 'HASH') {
2712: if (@codetitles > 0) {
2713: my $sel = $element;
2714: if ($element eq 'crosslist') {
2715: $sel .= '_'.$counter;
2716: }
2717: foreach my $title (@codetitles) {
2718: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
2719: }
2720: }
2721: }
2722: }
2723: return;
2724: }
2725:
2726: sub generate_date_items {
2727: my ($currentval,$item) = @_;
2728: if ($currentval =~ /\d+/) {
2729: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
2730: &Apache::lonhtmlcommon::get_timedates($currentval);
2731: $env{'form.'.$item.'_day'} = $mday;
2732: $env{'form.'.$item.'_month'} = $month+1;
2733: $env{'form.'.$item.'_year'} = $year;
2734: }
2735: return;
2736: }
2737:
2738: 1;
2739:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>