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