File:
[LON-CAPA] /
loncom /
interface /
lonrequestcourse.pm
Revision
1.29:
download - view:
text,
annotated -
select for diffs
Sun Sep 6 19:09:54 2009 UTC (14 years, 11 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 5995.
- Username field in "Additional" personnel accepts type-in input from user.
- "Search for User" link provided for requestors who want to search.
- "Check username" link provided for requestors who know the username and
want to check it and/or complete the user information fields from stored data.
- Javascript function - openuserbrowser() takes additional argument - caller - to trigger immediate username search if "check username" link used.
- Javascript function - fix_domain() now fixes domain selector in opener
only after a username and domain have been set from the pickuser pop-up.
1: # The LearningOnline Network
2: # Request a course
3: #
4: # $Id: lonrequestcourse.pm,v 1.29 2009/09/06 19:09:54 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 @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1256:
1257: my $roleoptions;
1258: my @roles = &Apache::lonuserutils::roles_by_context('course');
1259: my $type = 'Course';
1260: if ($crstype eq 'community') {
1261: $type = 'Community';
1262: }
1263: foreach my $role (@roles) {
1264: my $plrole = &Apache::lonnet::plaintext($role,$type);
1265: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1266: }
1267: my %customroles=&Apache::lonuserutils::my_custom_roles();
1268: if (keys(%customroles) > 0) {
1269: foreach my $cust (sort(keys(%customroles))) {
1270: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1271: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1272: }
1273: }
1274:
1275: my @currsecs;
1276: if ($env{'form.sectotal'}) {
1277: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1278: if (defined($env{'form.loncapasec_'.$i})) {
1279: my $lcsec = $env{'form.loncapasec_'.$i};
1280: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
1281: push(@currsecs,$lcsec);
1282: }
1283: }
1284: }
1285: }
1286:
1287: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1288: if (@currsecs) {
1289: my $existsize = scalar(@currsecs);
1290: if ($existsize > 3) {
1291: $existsize = 3;
1292: }
1293: if ($existsize > 1) {
1294: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1295: }
1296: @currsecs = sort { $a <=> $b } (@currsecs);
1297: $existtitle = &mt('Official').': ';
1298: $existops = '<option value="">'.&mt('None').'</option>';
1299: foreach my $sec (@currsecs) {
1300: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1301: }
1302: $seccolspan = ' colspan="2"';
1303: $newtitle = &mt('Other').': ';
1304: }
1305:
1306: if ($persontotal) {
1307: $output .= &Apache::lonhtmlcommon::row_headline().
1308: '<h3>'.&mt('Requestor is automatically assigned Course Coordinator role.').' '.&mt('Include other personnel?').'</h3>';
1309: }
1310: for (my $i=0; $i<$persontotal; $i++) {
1311: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1312: my $linkargstr = join("','",@linkargs);
1313: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1314: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1315: "'person_".$i."_hidedom','person_".$i."_uname'".');';
1316: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1317: 1,$onchange).
1318: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1319: my %form_elems;
1320: foreach my $item (@items) {
1321: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1322: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1323: 'value="" readonly="readonly" />';
1324: }
1325: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1326: $roleoptions.'</select>';
1327: my $sectionselector;
1328: if (@currsecs) {
1329: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1330: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1331: }
1332: $sectionselector .= $newtitle.
1333: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1334: my $usersrchlinktxt = &mt('Search for user');
1335: my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1336: $usersrchlinktxt);
1337: my $userchklinktxt = &mt('Check username');
1338: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1339: $userchklinktxt,'checkusername');
1340: $output .=
1341: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
1342: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
1343: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
1344: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
1345: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
1346: '</tr>'."\n".'<tr>'.
1347: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1348: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1349: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1350: '<tr><td align="center" valign="top">'.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
1351: '<td'.$seccolspan.' align="center" valign="top">'.&mt('Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1352: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
1353: }
1354: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
1355: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
1356: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1357: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1358: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1359: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1360: return $output;
1361: }
1362:
1363: sub print_request_status {
1364: my ($dom) = @_;
1365: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
1366: $env{'user.name'},'^status:'.$dom);
1367: my ($output,$formname,%queue_by_date,%typenames);
1368: if ($env{'form.crstype'} eq 'any') {
1369: %typenames = &Apache::lonlocal::texthash (
1370: official => 'Official course',
1371: unofficial => 'Unofficial course',
1372: community => 'Community',
1373: );
1374: }
1375: foreach my $key (keys(%statusinfo)) {
1376: if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {
1377: (undef,my($cdom,$cnum)) = split(':',$key);
1378: next if ($cdom ne $dom);
1379: my $requestkey = $cdom.'_'.$cnum;
1380: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1381: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1382: $env{'user.domain'},$env{'user.name'});
1383: my $entry;
1384: my $timestamp = $history{'reqtime'};
1385: my $crstype = $history{'crstype'};
1386: my $disposition = $history{'disposition'};
1387: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1388: next unless (($env{'form.crstype'} eq 'any') ||
1389: ($env{'form.crstype'} eq $crstype));
1390: next unless (($disposition eq 'approval') ||
1391: ($disposition eq 'pending'));
1392: if (ref($history{'details'}) eq 'HASH') {
1393: $entry = $requestkey.':'.$crstype.':'.
1394: &escape($history{'details'}{'cdescr'});
1395: if ($crstype eq 'official') {
1396: $entry .= ':'.&escape($history{'details'}{'instcode'});
1397: }
1398: }
1399: if ($entry ne '') {
1400: if (exists($queue_by_date{$timestamp})) {
1401: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
1402: push(@{$queue_by_date{$timestamp}},$entry);
1403: }
1404: } else {
1405: @{$queue_by_date{$timestamp}} = ($entry);
1406: }
1407: }
1408: }
1409: }
1410: }
1411: $formname = 'requestcrs';
1412: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1413: $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1414:
1415: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1416: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
1417: '<input type="hidden" name="showdom" value="" />'."\n".
1418: '<input type="hidden" name="cnum" value="" />'."\n";
1419: if (@sortedtimes > 0) {
1420: $output .= &Apache::loncommon::start_data_table().
1421: &Apache::loncommon::start_data_table_header_row().
1422: '<th>'.&mt('Action').'</th>'.
1423: '<th>'.&mt('Course Description').'</th>'.
1424: '<th>'.&mt('Domain').'</th>';
1425: if ($env{'form.crstype'} eq 'any') {
1426: $output .= '<th>'.&mt('Type').'</th>';
1427: }
1428: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1429: $output .= '<th>'.&mt('Institutional Code').'</th>';
1430: }
1431: $output .= '<th>'.&mt('Date requested').'</th>'.
1432: &Apache::loncommon::end_data_table_header_row();
1433: my $count = 0;
1434: foreach my $item (@sortedtimes) {
1435: my $showtime = &Apache::lonlocal::locallocaltime($item);
1436: if (ref($queue_by_date{$item}) eq 'ARRAY') {
1437: foreach my $request (sort(@{$queue_by_date{$item}})) {
1438: my ($key,$type,$desc,$instcode) = split(':',$request);
1439: my ($cdom,$cnum) = split('_',$key);
1440: $output .= &Apache::loncommon::start_data_table_row().
1441: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1442: '<td>'.&unescape($desc).'</td>'.
1443: '<td>'.$cdom.'</td>';
1444: if ($env{'form.crstype'} eq 'any') {
1445: my $typename = $typenames{$type};
1446: if ($typename eq '') {
1447: $typename = &mt('Unknown type');
1448: }
1449: $output .= '<td>'.$typename.'</td>';
1450: }
1451: if (($env{'form.crstype'} eq 'any') ||
1452: ($env{'form.crstype'} eq 'official')) {
1453: my $showinstcode;
1454: if ($type eq 'official') {
1455: $showinstcode = &unescape($instcode);
1456: } else {
1457: $showinstcode = &mt('Not applicable');
1458: }
1459: $output .= '<td>'.$showinstcode.'</td>';
1460: }
1461: $output .= '<td>'.$showtime.'</td>'.
1462: &Apache::loncommon::end_data_table_row();
1463: }
1464: }
1465: }
1466: $output .= &Apache::loncommon::end_data_table();
1467: } else {
1468: $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>';
1469: }
1470: $output .= '
1471: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />
1472: </form></div>';
1473: return $output;
1474: }
1475:
1476: sub print_cancel_request {
1477: my ($dom,$cnum) = @_;
1478: my $requestkey = $dom.'_'.$cnum;
1479: my ($result,$output);
1480: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1481: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1482: $env{'user.domain'},$env{'user.name'});
1483: my $timestamp = $history{'reqtime'};
1484: my $crstype = $history{'crstype'};
1485: my $status = $history{'status'};
1486: if (($status eq 'cancelled') || ($status eq 'created')) {
1487: if ($status eq 'cancelled') {
1488: $output = &mt('This request has already been cancelled.');
1489: } elsif ($status eq 'created') {
1490: $output = &mt('This request has already been processed, and a course created.');
1491: }
1492: $output = &mt('No further action will be taken');
1493: } elsif (ref($history{'details'}) eq 'HASH') {
1494: my ($types,$typename) = &course_types();
1495: my $showtype = $crstype;
1496: if (defined($typename->{$crstype})) {
1497: $showtype = $typename->{$crstype};
1498: }
1499: $output = '<p>'.&Apache::loncommon::start_data_table().
1500: &Apache::loncommon::start_data_table_header_row().
1501: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
1502: '<th>'.&mt('Type').'</th>'.
1503: &Apache::loncommon::end_data_table_header_row().
1504: &Apache::loncommon::start_data_table_row().
1505: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
1506: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
1507: '<td>'.$showtype.'</td>'.
1508: &Apache::loncommon::end_data_table_row().
1509: &Apache::loncommon::end_data_table().
1510: '<br /><div class="LC_warning">'.
1511: &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
1512: $result = 'ok';
1513: } else {
1514: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
1515: }
1516: } else {
1517: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
1518: }
1519: return ($result,$output);
1520: }
1521:
1522: sub viewrequest_javascript {
1523: my ($formname,$next) = @_;
1524: return <<"ENDJS";
1525:
1526: function chooseRequest(cdom,cnum) {
1527: document.$formname.showdom.value = cdom;
1528: document.$formname.cnum.value = cnum;
1529: nextPage(document.$formname,'$next');
1530: }
1531:
1532: ENDJS
1533: }
1534:
1535: sub viewdetails_javascript {
1536: my ($formname) = @_;
1537: return << "ENDJS";
1538:
1539: function nextPage(formname,nextstate) {
1540: if (nextstate == "modify") {
1541: formname.state.value = "personnel";
1542: formname.action.value = "new";
1543: } else {
1544: formname.state.value = nextstate;
1545: }
1546: formname.submit();
1547: }
1548:
1549: function backPage(formname,prevstate) {
1550: formname.state.value = prevstate;
1551: formname.submit();
1552: }
1553:
1554: ENDJS
1555: }
1556:
1557: sub viewcancel_javascript {
1558: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
1559: 'Your request will be removed.');
1560: return << "ENDJS";
1561: function nextPage(formname,nextstate) {
1562: if (confirm('$alert')) {
1563: formname.state.value = nextstate;
1564: formname.submit();
1565: }
1566: return;
1567: }
1568:
1569: ENDJS
1570: }
1571:
1572: sub print_request_logs {
1573: my ($jscript,$loaditems,$crumb) = @_;
1574: return;
1575: }
1576:
1577: sub print_review {
1578: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom) = @_;
1579: my ($types,$typename) = &course_types();
1580: my ($owner,$ownername,$owneremail);
1581: if ($uname eq '' || $udom eq '') {
1582: $uname = $env{'user.name'};
1583: $udom = $env{'user.domain'};
1584: }
1585: $owner = $uname.':'.$udom;
1586: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
1587: my %emails = &Apache::loncommon::getemails($uname,$udom);
1588: foreach my $email ('permanentemail','critnotification','notification') {
1589: $owneremail = $emails{$email};
1590: last if ($owneremail ne '');
1591: }
1592: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
1593: $section_headers,$section_values,$personnel_headers,$personnel_values);
1594:
1595: $crstypename = $env{'form.crstype'};
1596: if (ref($typename) eq 'HASH') {
1597: unless ($typename->{$env{'form.crstype'}} eq '') {
1598: $crstypename = $typename->{$env{'form.crstype'}};
1599: }
1600: }
1601: my $category = 'Course';
1602: if ($env{'form.crstype'} eq 'community') {
1603: $category = 'Community';
1604: }
1605:
1606: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
1607: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
1608:
1609: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
1610: '('.&Apache::lonnet::plaintext('st',$category).')';
1611: if ($env{'form.crstype'} eq 'official') {
1612: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
1613: foreach my $title (@{$codetitles}) {
1614: if ($env{'form.instcode_'.$title} ne '') {
1615: $inst_headers .= '<th>'.$title.'</th>';
1616: my $longitem = $env{'form.instcode_'.$title};
1617: if (ref($cat_titles->{$title}) eq 'HASH') {
1618: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
1619: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
1620: }
1621: }
1622: $inst_values .= '<td>'.$longitem.'</td>';
1623: }
1624: }
1625: }
1626: if (&Apache::lonnet::auto_run('',$dom)) {
1627: $enrollrow_title = &mt('Enrollment');
1628: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
1629: '<th>'.&mt('Automatic Drops').'</th>'.
1630: '<th>'.&mt('Enrollment Starts').'</th>'.
1631: '<th>'.&mt('Enrollment Ends').'</th>';
1632: $section_headers = '<th>'.&mt('Sections').'</th>'.
1633: '<th>'.&mt('Crosslistings').'</th>';
1634:
1635: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1636: my @autoroster = (&mt('No'),&mt('Yes'));
1637: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
1638: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1639: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
1640: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1641: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
1642: &mt('Institutional section').'</th>'.
1643: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1644: my $secinfo;
1645: if ($env{'form.sectotal'} > 0) {
1646: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1647: if ($env{'form.sec_'.$i}) {
1648: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1649: if ($env{'form.loncapasec_'.$i} ne '') {
1650: $secinfo .= $env{'form.loncapasec_'.$i};
1651: } else {
1652: $secinfo .= &mt('None');
1653: }
1654: $secinfo .= '</td></tr>';
1655: }
1656: }
1657: }
1658: if ($secinfo eq '') {
1659: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1660: }
1661: $section_values .= $secinfo.'</table></td><td>'.
1662: '<table class="LC_innerpickbox"><tr><th>'.
1663: &mt('Institutional course/section').'</th>'.
1664: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1665: my $xlistinfo;
1666: my $crosslisttotal = $env{'form.crosslisttotal'};
1667: if (!$crosslisttotal) {
1668: $crosslisttotal = 1;
1669: }
1670: for (my $i=0; $i<$crosslisttotal; $i++) {
1671: if ($env{'form.crosslist_'.$i}) {
1672: $xlistinfo .= '<tr><td>';
1673: if (ref($code_order) eq 'ARRAY') {
1674: if (@{$code_order} > 0) {
1675: foreach my $item (@{$code_order}) {
1676: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1677: }
1678: }
1679: }
1680: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
1681: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
1682: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
1683: } else {
1684: $xlistinfo .= &mt('None');
1685: }
1686: $xlistinfo .= '</td></tr>';
1687: }
1688: }
1689: if ($xlistinfo eq '') {
1690: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1691: }
1692: $section_values .= $xlistinfo;
1693: }
1694: $section_values .= '</table></td>';
1695: }
1696:
1697: my %ctxt = &clone_text();
1698: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1699: if (($env{'form.clonecrs'} =~ /^$match_name$/) &&
1700: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1701: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1702: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
1703: if ($canclone) {
1704: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
1705: $env{'form.clonecrs'},('description','internal.coursecode'));
1706: if (keys(%courseenv) > 0) {
1707: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
1708: $inst_values .= '<td>'.$courseenv{'description'}.' ';
1709: my $cloneinst = $courseenv{'internal.coursecode'};
1710: if ($cloneinst ne '') {
1711: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1712: } else {
1713: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1714: }
1715: $inst_values .= '</td><td>';
1716: if ($env{'form.datemode'} eq 'preserve') {
1717: $inst_values .= $ctxt{'prd'};
1718: } elsif ($env{'form.datemode'} eq 'shift') {
1719: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
1720: } else {
1721: $inst_values .= $ctxt{'ncd'};
1722: }
1723: $inst_values .= '</td>';
1724: } else {
1725: $inst_values .= '<td>'.&mt('Unknown').'</td>';
1726: }
1727: } else {
1728: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
1729: }
1730: } else {
1731: $inst_values .= '<td>'.&mt('None').'</td>';
1732: }
1733: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
1734: '<th>'.&mt('Access Ends').'</th>';
1735: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1736: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
1737: if ($accessend == 0) {
1738: $enroll_values .= '<td>'.&mt('No end date').'</td>';
1739: } else {
1740: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1741: }
1742:
1743: my $container = 'Course';
1744: if ($env{'form.crstype'} eq 'community') {
1745: $container = 'Community';
1746: }
1747:
1748: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
1749: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
1750: '</th>';
1751: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1752: '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
1753: '<td>'.&mt('None').'</td></tr>';
1754: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1755: if ($env{'form.person_'.$i.'_uname'} ne '') {
1756: my @allsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1757: my $newsec = $env{'form.person_'.$i.'_newsec'};
1758: $newsec =~ s/^\s+//;
1759: $newsec =~s/\s+$//;
1760: my @newsecs = split(/[\s,;]+/,$newsec);
1761: foreach my $sec (@newsecs) {
1762: next if ($sec =~ /\W/);
1763: next if ($newsec eq 'none');
1764: if ($sec ne '') {
1765: unless (grep(/^\Q$sec\E$/,@allsecs)) {
1766: push(@allsecs,$sec);
1767: }
1768: }
1769: }
1770: my $showsec;
1771: if (@allsecs) {
1772: $showsec = join(', ',@allsecs);
1773: }
1774: if ($showsec eq '') {
1775: $showsec = &mt('None');
1776: }
1777: if ($env{'form.person_'.$i.'_role'} eq 'cc') {
1778: $showsec = &mt('None');
1779: }
1780: my $role = $env{'form.person_'.$i.'_role'};
1781: $personnel_values .=
1782: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
1783: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1784: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
1785: $env{'form.person_'.$i.'_dom'}.'</td>'.
1786: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1787: '<td>'.$showsec.'</td></tr>';
1788: }
1789: }
1790: my $output =
1791: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1792: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1793: '<table class="LC_innerpickbox"><tr>'.
1794: '<th>'.&mt('Name').'</th>'.
1795: '<th>'.&mt('Username:Domain').'</th>'.
1796: '<th>'.&mt('E-mail address').'</th>'.
1797: '</tr><tr>'."\n".
1798: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
1799: '<td>'.$owneremail.'</td>'.
1800: '</tr></table>'."\n".
1801: &Apache::lonhtmlcommon::row_closure().
1802: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1803: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
1804: '<tr>'.$inst_values.'</tr></table>'."\n".
1805: &Apache::lonhtmlcommon::row_closure().
1806: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1807: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
1808: '<tr>'.$enroll_values.'</tr></table>'."\n".
1809: &Apache::lonhtmlcommon::row_closure();
1810: if ($section_headers ne '') {
1811: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
1812: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
1813: '<tr>'.$section_values.'</tr></table>'."\n".
1814: &Apache::lonhtmlcommon::row_closure();
1815: }
1816: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
1817: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
1818: $personnel_values.'</table>'."\n".
1819: &Apache::lonhtmlcommon::row_closure(1).
1820: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1821: return $output;
1822: }
1823:
1824: sub dates_from_form {
1825: my ($startname,$endname) = @_;
1826: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1827: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1828: if ($endname eq 'accessend') {
1829: if (exists($env{'form.no_end_date'}) ) {
1830: $enddate = 0;
1831: }
1832: }
1833: return ($startdate,$enddate);
1834: }
1835:
1836: sub courseinfo_form {
1837: my ($dom,$formname,$crstype,$next) = @_;
1838: my $nodescr = &mt('You must provide a (brief) course description.');
1839: my $js_validate = <<"ENDJS";
1840: <script type="text/javascript">
1841: // <![CDATA['
1842:
1843: function validateForm() {
1844: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1845: alert('$nodescr');
1846: return;
1847: }
1848: nextPage(document.$formname,'$next');
1849: }
1850: // ]]
1851: </script>
1852:
1853: ENDJS
1854: my $title = &mt('Brief Course Description');
1855: if ($crstype eq 'community') {
1856: $title = &mt('Brief Community Description');
1857: }
1858: my $output .= $js_validate."\n".'<div>'.&Apache::lonhtmlcommon::start_pick_box().
1859: &Apache::lonhtmlcommon::row_headline().
1860: '<h3>'.$title.'</h3>'.
1861: &Apache::lonhtmlcommon::row_closure(1).
1862: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1863: '<input type="text" size="40" name="cdescr" />';
1864: my ($home_server_pick,$numlib) =
1865: &Apache::loncommon::home_server_form_item($dom,'chome',
1866: 'default','hide');
1867: if ($numlib > 1) {
1868: $output .= &Apache::lonhtmlcommon::row_closure().
1869: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1870: }
1871: $output .= $home_server_pick.
1872: &Apache::lonhtmlcommon::row_closure().
1873: &Apache::lonhtmlcommon::row_headline().
1874: '<h3>'.&mt('Clone content and settings from an existing course?').'</h3>'.
1875: &Apache::lonhtmlcommon::row_closure(1).
1876: &clone_form($dom,$formname,$crstype).
1877: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
1878: return $output;
1879: }
1880:
1881: sub clone_form {
1882: my ($dom,$formname,$crstype) = @_;
1883: my $type = 'Course';
1884: if ($crstype eq 'community') {
1885: $type = 'Community';
1886: }
1887: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').
1888: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1889: my %lt = &clone_text();
1890: my $output .=
1891: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1892: '<input type="text" size="25" name="clonecrs" value="" />'.
1893: '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
1894: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
1895: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
1896: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
1897: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
1898: '</label><br /><label>'.
1899: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
1900: '</label><br /><label>'.
1901: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
1902: $lt{'shd'}.'</label>'.
1903: '<input type="text" size="5" name="dateshift" value="365" />'.
1904: &Apache::lonhtmlcommon::row_closure(1);
1905: return $output;
1906: }
1907:
1908: sub clone_text {
1909: return &Apache::lonlocal::texthash(
1910: 'cid' => 'Course ID',
1911: 'dmn' => 'Domain',
1912: 'dsh' => 'Date Shift',
1913: 'ncd' => 'Do not clone date parameters',
1914: 'prd' => 'Clone date parameters as-is',
1915: 'shd' => 'Shift date parameters by number of days',
1916: );
1917: }
1918:
1919: sub coursecode_form {
1920: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1921: my $output;
1922: my %rowtitle = (
1923: instcode => 'Course Category',
1924: crosslist => 'Cross Listed Course',
1925: );
1926: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
1927: (ref($cat_order))) {
1928: my ($sel,$instsec,$lcsec);
1929: $sel = $context;
1930: if ($context eq 'crosslist') {
1931: $sel .= '_'.$num;
1932: $instsec = &mt('Institutional section').'<br />'.
1933: '<input type="text" size="10" name="'.$sel.'_instsec" />';
1934: $lcsec = &mt('LON-CAPA section').'<br />'.
1935: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
1936: }
1937: if (@{$codetitles} > 0) {
1938: my $lastitem = pop(@{$codetitles});
1939: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1940: if (@{$codetitles} > 0) {
1941: $output = &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1942: '<table><tr>';
1943: if ($context eq 'crosslist') {
1944: $output .= '<td>'.&mt('Include?').'<br />'.
1945: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1946: }
1947: foreach my $title (@{$codetitles}) {
1948: if (ref($cat_order->{$title}) eq 'ARRAY') {
1949: if (@{$cat_order->{$title}} > 0) {
1950: $output .= '<td align="center">'.$title.'<br />'."\n".
1951: '<select name="'.$sel.'_'.$title.'">'."\n".
1952: ' <option value="" selected="selected">'.
1953: &mt('Select').'</option>'."\n";
1954: foreach my $item (@{$cat_order->{$title}}) {
1955: my $longitem = $item;
1956: if (ref($cat_titles->{$title}) eq 'HASH') {
1957: if ($cat_titles->{$title}{$item} ne '') {
1958: $longitem = $cat_titles->{$title}{$item};
1959: }
1960: }
1961: $output .= '<option value="'.$item.'">'.$longitem.
1962: '</option>'."\n";
1963: }
1964: }
1965: $output .= '</select></td>'."\n";
1966: }
1967: }
1968: if ($context eq 'crosslist') {
1969: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1970: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
1971: '<td align="center">'.$lcsec.'</td></tr></table>';
1972: } else {
1973: $output .= '</tr></table>'.
1974: &Apache::lonhtmlcommon::row_closure().
1975: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1976: $lastinput;
1977: }
1978: } else {
1979: if ($context eq 'crosslist') {
1980: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1981: '<table><tr>'.
1982: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
1983: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
1984: '</tr></table>';
1985: } else {
1986: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1987: $lastinput;
1988: }
1989: }
1990: $output .= &Apache::lonhtmlcommon::row_closure(1);
1991: push(@$codetitles,$lastitem);
1992: } elsif ($context eq 'crosslist') {
1993: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1994: '<table><tr><td align="center">'.
1995: '<span class="LC_nobreak">'.&mt('Include?').
1996: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
1997: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
1998: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
1999: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
2000: &Apache::lonhtmlcommon::row_closure(1);
2001: }
2002: }
2003: return $output;
2004: }
2005:
2006: sub get_course_dom {
2007: my $codedom = &Apache::lonnet::default_login_domain();
2008: if ($env{'form.showdom'} ne '') {
2009: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
2010: return $env{'form.showdom'};
2011: }
2012: }
2013: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
2014: my ($types,$typename) = &course_types();
2015: if (ref($types) eq 'ARRAY') {
2016: foreach my $type (@{$types}) {
2017: if (&Apache::lonnet::usertools_access($env{'user.name'},
2018: $env{'user.domain'},$type,
2019: undef,'requestcourses')) {
2020: return $env{'user.domain'};
2021: }
2022: }
2023: my @possible_doms;
2024: foreach my $type (@{$types}) {
2025: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
2026: if ($dom_str ne '') {
2027: my @domains = split(',',$dom_str);
2028: foreach my $entry (@domains) {
2029: my ($extdom,$extopt) = split(':',$entry);
2030: if ($extdom eq $env{'request.role.domain'}) {
2031: return $extdom;
2032: }
2033: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
2034: push(@possible_doms,$extdom);
2035: }
2036: }
2037: }
2038: }
2039: if (@possible_doms) {
2040: @possible_doms = sort(@possible_doms);
2041: return $possible_doms[0];
2042: }
2043: }
2044: $codedom = $env{'user.domain'};
2045: if ($env{'request.role.domain'} ne '') {
2046: $codedom = $env{'request.role.domain'};
2047: }
2048: }
2049: return $codedom;
2050: }
2051:
2052: sub display_navbuttons {
2053: my ($r,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
2054: $r->print('<div class="LC_navbuttons">');
2055: if ($prev) {
2056: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2057: 'onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>'.
2058: (' 'x3));
2059: } elsif ($prevtext) {
2060: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2061: 'onclick="javascript:history.back()"/>'.(' 'x3));
2062: }
2063: if ($state eq 'details') {
2064: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
2065: 'onclick="javascript:nextPage(document.'.$formname.','."'".$other."'".
2066: ')" />');
2067: }
2068: if ($state eq 'courseinfo') {
2069: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2070: 'onclick="javascript:validateForm();" />');
2071: } elsif ($next) {
2072: $r->print('
2073: <input type="button" name="next" value="'.$nexttext.'" '.
2074: 'onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
2075: }
2076: $r->print('</div>');
2077: }
2078:
2079: sub print_request_outcome {
2080: my ($dom,$codetitles,$code_order) = @_;
2081: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
2082: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
2083: my $sectotal = $env{'form.sectotal'};
2084: my $crosslisttotal = 0;
2085: $cnum = $env{'form.cnum'};
2086: unless ($cnum =~ /^$match_courseid$/) {
2087: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
2088: return $output;
2089: }
2090:
2091: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
2092: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2093: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
2094: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
2095: }
2096: }
2097: $now = time;
2098: $crstype = $env{'form.crstype'};
2099: my @instsections;
2100: if ($crstype eq 'official') {
2101: if (&Apache::lonnet::auto_run('',$dom)) {
2102: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
2103: }
2104: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2105: if ($env{'form.sec_'.$i}) {
2106: if ($env{'form.secnum_'.$i} ne '') {
2107: my $sec = $env{'form.secnum_'.$i};
2108: $sections{$i}{'inst'} = $sec;
2109: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
2110: push(@instsections,$sec);
2111: }
2112: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
2113: }
2114: }
2115: }
2116: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
2117: if ($env{'form.crosslist_'.$i}) {
2118: my $xlistinfo = '';
2119: if (ref($code_order) eq 'ARRAY') {
2120: if (@{$code_order} > 0) {
2121: foreach my $item (@{$code_order}) {
2122: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
2123: }
2124: }
2125: }
2126: $crosslistings{$i}{'instcode'} = $xlistinfo;
2127: if ($xlistinfo ne '') {
2128: $crosslisttotal ++;
2129: }
2130: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
2131: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
2132: }
2133: }
2134: } else {
2135: $enrollstart = '';
2136: $enrollend = '';
2137: }
2138: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2139: my $uname = $env{'form.person_'.$i.'_uname'};
2140: my $udom = $env{'form.person_'.$i.'_dom'};
2141: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
2142: if (&Apache::lonnet::domain($udom) ne '') {
2143: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
2144: $personnel{$uname.':'.$udom} = {
2145: firstname => $env{'form.person_'.$i.'_firstname'},
2146: lastname => $env{'form.person_'.$i.'_lastname'},
2147: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
2148: };
2149: }
2150: my $role = $env{'form.person_'.$i.'_role'};
2151: unless ($role eq '') {
2152: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
2153: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
2154: unless (grep(/^\Q$role\E$/,@curr_roles)) {
2155: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
2156: }
2157: } else {
2158: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
2159: }
2160: if ($role eq 'cc') {
2161: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
2162: } else {
2163: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2164: my $newsec = $env{'form.person_'.$i.'_newsec'};
2165: $newsec =~ s/^\s+//;
2166: $newsec =~s/\s+$//;
2167: my @newsecs = split(/[\s,;]+/,$newsec);
2168: foreach my $sec (@newsecs) {
2169: next if ($sec =~ /\W/);
2170: next if ($newsec eq 'none');
2171: if ($sec ne '') {
2172: unless (grep(/^\Q$sec\E$/,@currsec)) {
2173: push(@currsec,$sec);
2174: }
2175: }
2176: }
2177: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @currsec;
2178: }
2179: }
2180: } else {
2181: push(@missingdom,$uname.':'.$udom);
2182: }
2183: } else {
2184: push(@baduname,$uname.':'.$udom);
2185: }
2186: }
2187: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2188: my $autodrops = 0;
2189: if ($env{'form.autodrops'}) {
2190: $autodrops = $env{'form.autodrops'};
2191: }
2192: my $autoadds = 0;
2193: if ($env{'form.autoadds'}) {
2194: $autodrops = $env{'form.autoadds'};
2195: }
2196: if ($env{'form.autoadds'}) {
2197: $autodrops = $env{'form.autoadds'};
2198: }
2199: my $instcode = '';
2200: if (exists($env{'form.instcode'})) {
2201: $instcode = $env{'form.instcode'};
2202: }
2203: my $clonecrs = '';
2204: my $clonedom = '';
2205: if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
2206: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
2207: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
2208: $env{'form.clonedom'});
2209: if ($clonehome ne 'no_host') {
2210: my $canclone =
2211: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
2212: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
2213: if ($canclone) {
2214: $clonecrs = $env{'form.clonecrs'};
2215: $clonedom = $env{'form.clonedom'};
2216: }
2217: }
2218: }
2219: my $details = {
2220: owner => $env{'user.name'},
2221: domain => $env{'user.domain'},
2222: cdom => $dom,
2223: cnum => $cnum,
2224: coursehome => $env{'form.chome'},
2225: cdescr => $env{'form.cdescr'},
2226: crstype => $env{'form.crstype'},
2227: instcode => $instcode,
2228: clonedom => $clonedom,
2229: clonecrs => $clonecrs,
2230: datemode => $env{'form.datemode'},
2231: dateshift => $env{'form.dateshift'},
2232: sectotal => $sectotal,
2233: sections => \%sections,
2234: crosslisttotal => $crosslisttotal,
2235: crosslists => \%crosslistings,
2236: autoadds => $autoadds,
2237: autodrops => $autodrops,
2238: enrollstart => $enrollstart,
2239: enrollend => $enrollend,
2240: accessstart => $accessstart,
2241: accessend => $accessend,
2242: personnel => \%personnel,
2243: };
2244: my (@inststatuses,$storeresult,$creationresult);
2245: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
2246: if ($val eq '') {
2247: if ($crstype eq 'official') {
2248: $output = &mt('You are not permitted to request creation of official courses.');
2249: } elsif ($crstype eq 'unofficial') {
2250: $output = &mt('You are not permitted to request creation of unofficial courses.');
2251: } elsif ($crstype eq 'community') {
2252: $output = &mt('You are not permitted to request creation of communities');
2253: } else {
2254: $output = &mt('Unrecognized course type: [_1]',$crstype);
2255: }
2256: $storeresult = 'notpermitted';
2257: } else {
2258: my ($disposition,$message,$reqstatus);
2259: my %reqhash = (
2260: reqtime => $now,
2261: crstype => $crstype,
2262: details => $details,
2263: );
2264: my $requestkey = $dom.'_'.$cnum;
2265: my $validationerror;
2266: if ($val eq 'autolimit=') {
2267: $disposition = 'process';
2268: } elsif ($val =~ /^autolimit=(\d+)$/) {
2269: my $limit = $1;
2270: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
2271: $dom,$crstype,$limit,\$message);
2272: } elsif ($val eq 'validate') {
2273: my ($inststatuslist,$validationchk,$validation);
2274: if (@inststatuses > 0) {
2275: $inststatuslist = join(',',@inststatuses);
2276: }
2277: my $instseclist;
2278: if (@instsections > 0) {
2279: $instseclist = join(',',@instsections);
2280: }
2281: $validationchk =
2282: &Apache::lonnet::auto_courserequest_validation($dom,
2283: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
2284: $inststatuslist,$instcode,$instseclist);
2285: if ($validationchk =~ /:/) {
2286: ($validation,$message) = split(':',$validationchk);
2287: } else {
2288: $validation = $validationchk;
2289: }
2290: if ($validation =~ /^error(.*)$/) {
2291: $disposition = 'approval';
2292: $validationerror = $1;
2293: } else {
2294: $disposition = $validation;
2295: }
2296: } else {
2297: $disposition = 'approval';
2298: }
2299: $reqhash{'disposition'} = $disposition;
2300: $reqstatus = $disposition;
2301: my ($modified,$queued);
2302: if ($disposition eq 'rejected') {
2303: $output = &mt('Your course request was rejected.');
2304: if ($message) {
2305: $output .= '<div class="LC_warning">'.$message.'</div>';
2306: }
2307: $storeresult = 'rejected';
2308: } elsif ($disposition eq 'process') {
2309: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
2310: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
2311: my @roles = &Apache::lonuserutils::roles_by_context('course');
2312: my $type = 'Course';
2313: if ($crstype eq 'community') {
2314: $type = 'Community';
2315: }
2316: foreach my $role (@roles) {
2317: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
2318: }
2319: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
2320: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
2321: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
2322: if ($result eq 'created') {
2323: $disposition = 'created';
2324: $reqstatus = 'created';
2325: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
2326: \%longroles);
2327: $output = '<p>'.&mt('Your course request has been processed and the course has been created.').
2328: '<br />'.$role_result.'</p>';
2329: $creationresult = 'created';
2330: } else {
2331: $output = '<span class="LC_error">'.
2332: &mt('An error occurred when processing your course request.').
2333: '<br />'.
2334: &mt('You may want to review the request details and submit the request again.').
2335: '</span>';
2336: $creationresult = 'error';
2337: }
2338: } else {
2339: my $requestid = $cnum.'_'.$disposition;
2340: my $request = {
2341: $requestid => {
2342: timestamp => $now,
2343: crstype => $crstype,
2344: ownername => $env{'user.name'},
2345: ownerdom => $env{'user.domain'},
2346: description => $env{'form.cdescr'},
2347: },
2348: };
2349: my $statuskey = 'status:'.$dom.':'.$cnum;
2350: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
2351: $env{'user.domain'},$env{'user.name'});
2352: if ($userreqhash{$statuskey} ne '') {
2353: $modified = 1;
2354: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
2355: my %queuehash = &Apache::lonnet::get('courserequestqueue',
2356: [$cnum.'_approval',
2357: $cnum.'_pending'],$dom,$uname);
2358: if (($queuehash{$cnum.'_approval'} ne '') ||
2359: ($queuehash{$cnum.'_pending'} ne '')) {
2360: $queued = 1;
2361: }
2362: }
2363: unless ($queued) {
2364: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
2365: $dom);
2366: if ($putresult eq 'ok') {
2367: $output = &mt('Your course request has been recorded.').'<br />'.
2368: ¬ification_information($disposition,$req_notifylist,
2369: $cnum,$now);
2370: } else {
2371: $reqstatus = 'domainerror';
2372: $reqhash{'disposition'} = $disposition;
2373: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
2374: $output = '<span class"LC_warning">'.$warning.'</span><br />';
2375: }
2376: }
2377: }
2378: my ($statusresult);
2379: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2380: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
2381: 'courserequests');
2382: if ($storeresult eq 'ok') {
2383: my %status = (
2384: 'status:'.$dom.':'.$cnum => $reqstatus,
2385: );
2386: $statusresult = &Apache::lonnet::put('courserequests',\%status);
2387: }
2388: } else {
2389: $storeresult = 'error: invalid requestkey format';
2390: }
2391: if ($storeresult ne 'ok') {
2392: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
2393: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
2394: } elsif ($statusresult ne 'ok') {
2395: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
2396: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
2397: }
2398: if ($modified && $queued && $storeresult eq 'ok') {
2399: $output .= '<p>'.&mt('Your course request has been updated').'</p>'.
2400: ¬ification_information($disposition,$req_notifylist,$cnum,$now);
2401: }
2402: if ($validationerror ne '') {
2403: $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
2404: }
2405: }
2406: if ($creationresult ne '') {
2407: return ($creationresult,$output);
2408: } else {
2409: return ($storeresult,$output);
2410: }
2411: }
2412:
2413: sub update_requestors_roles {
2414: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
2415: my $now = time;
2416: my ($active,$future,$numactive,$numfuture,$output);
2417: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
2418: if (ref($details) eq 'HASH') {
2419: if (ref($details->{'personnel'}) eq 'HASH') {
2420: if (ref($details->{'personnel'}{$owner}) eq 'HASH') {
2421: my @roles;
2422: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
2423: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
2424: unless (grep(/^cc$/,@roles)) {
2425: push(@roles,'cc');
2426: }
2427: } else {
2428: @roles = ('cc');
2429: }
2430: foreach my $role (@roles) {
2431: my $start = $now;
2432: my $end = '0';
2433: if ($role eq 'st') {
2434: if ($details->{'accessstart'} ne '') {
2435: $start = $details->{'accessstart'};
2436: }
2437: if ($details->{'accessend'} ne '') {
2438: $end = $details->{'accessend'};
2439: }
2440: }
2441: my @usecs;
2442: if ($role ne 'cc') {
2443: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
2444: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
2445: }
2446: }
2447: if ($role eq 'st') {
2448: if (@usecs > 1) {
2449: my $firstsec = $usecs[0];
2450: @usecs = ($firstsec);
2451: }
2452: }
2453: if (@usecs == 0) {
2454: push(@usecs,'');
2455: }
2456: foreach my $usec (@usecs) {
2457: my (%userroles,%newrole,%newgroups,$spec,$area);
2458: my $area = '/'.$dom.'/'.$cnum;
2459: my $spec = $role.'.'.$area;
2460: if ($usec ne '') {
2461: $spec .= '/'.$usec;
2462: $area .= '/'.$usec;
2463: }
2464: if ($role =~ /^cr\//) {
2465: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
2466: $cnum,$spec,$area);
2467: } else {
2468: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
2469: $spec,$cnum,$area);
2470: }
2471: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
2472: \%newgroups);
2473: $userroles{'user.role.'.$spec} = $start.'.'.$end;
2474: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
2475: if (($end == 0) || ($end > $now)) {
2476: my $showrole = $role;
2477: if ($role =~ /^cr\//) {
2478: $showrole = &Apache::lonnet::plaintext($role,$crstype);
2479: } elsif (ref($longroles) eq 'HASH') {
2480: if ($longroles->{$role} ne '') {
2481: $showrole = $longroles->{$role};
2482: }
2483: }
2484: if ($start <= $now) {
2485: $active .= '<li><a href="/adm/roles?selectrole=1&'. $spec.'=1">'.$showrole;
2486: if ($usec ne '') {
2487: $active .= ' - '.&mt('section:').' '.$usec;
2488: }
2489: $active .= '</a></li>';
2490: $numactive ++;
2491: } else {
2492: $future .= '<li>'.$showrole;
2493: if ($usec ne '') {
2494: $future .= ' - '.&mt('section:').' '.$usec;
2495: }
2496: $future .= '</li>';
2497: $numfuture ++;
2498: }
2499: }
2500: }
2501: }
2502: }
2503: }
2504: }
2505: if ($active) {
2506: if ($numactive == 1) {
2507: $output = &mt('Use the following link to enter the course:');
2508: } else {
2509: $output = &mt('Use the following links to your new roles to enter the course:');
2510: }
2511: $output .= ' <ul>'.$active.'</ul><br />';
2512: }
2513: if ($future) {
2514: $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'})).
2515: ' <ul>'.$future.'</ul>';
2516: }
2517: return $output;
2518: }
2519:
2520: sub notification_information {
2521: my ($disposition,$req_notifylist,$cnum,$now) = @_;
2522: my %emails = &Apache::loncommon::getemails();
2523: my $address;
2524: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
2525: $address = $emails{'permanentemail'};
2526: if ($address eq '') {
2527: $address = $emails{'notification'};
2528: }
2529: }
2530: my $output;
2531: if ($disposition eq 'approval') {
2532: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
2533: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
2534: if ($address ne '') {
2535: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
2536: }
2537: if ($req_notifylist) {
2538: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
2539: $env{'user.domain'});
2540: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
2541: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
2542: }
2543: } elsif ($disposition eq 'pending') {
2544: $output .= '<div class="LC_info">'.
2545: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
2546: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
2547: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
2548: '</div>';
2549: } else {
2550: $output .= '<div class="LC_warning">'.
2551: &mt('Your request status is: [_1].',$disposition).
2552: '</div>'
2553: }
2554: return $output;
2555: }
2556:
2557: sub get_processtype {
2558: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
2559: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
2560: my (%userenv,%settings,$val);
2561: my @options = ('autolimit','validate','approval');
2562: if ($dom eq $env{'user.domain'}) {
2563: %userenv =
2564: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
2565: 'requestcourses.'.$crstype,'inststatus');
2566: if ($userenv{'requestcourses.'.$crstype}) {
2567: $val = $userenv{'requestcourses.'.$crstype};
2568: @{$inststatuses} = ('_custom_');
2569: } else {
2570: my ($task,%alltasks);
2571: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
2572: %settings = %{$domconfig->{'requestcourses'}};
2573: if (ref($settings{$crstype}) eq 'HASH') {
2574: if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
2575: $val = $settings{$crstype}{'_LC_adv'};
2576: @{$inststatuses} = ('_LC_adv_');
2577: } else {
2578: if ($userenv{'inststatus'} ne '') {
2579: @{$inststatuses} = split(',',$userenv{'inststatus'});
2580: } else {
2581: @{$inststatuses} = ('default');
2582: }
2583: foreach my $status (@{$inststatuses}) {
2584: if (exists($settings{$crstype}{$status})) {
2585: my $value = $settings{$crstype}{$status};
2586: next unless ($value);
2587: unless (exists($alltasks{$value})) {
2588: if (ref($alltasks{$value}) eq 'ARRAY') {
2589: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
2590: push(@{$alltasks{$value}},$status);
2591: }
2592: } else {
2593: @{$alltasks{$value}} = ($status);
2594: }
2595: }
2596: }
2597: }
2598: my $maxlimit = 0;
2599:
2600: foreach my $key (sort(keys(%alltasks))) {
2601: if ($key =~ /^autolimit=(\d*)$/) {
2602: if ($1 eq '') {
2603: $val ='autolimit=';
2604: last;
2605: } elsif ($1 > $maxlimit) {
2606: $maxlimit = $1;
2607: }
2608: }
2609: }
2610: if ($maxlimit) {
2611: $val = 'autolimit='.$maxlimit;
2612: } else {
2613: foreach my $option (@options) {
2614: if ($alltasks{$option}) {
2615: $val = $option;
2616: last;
2617: }
2618: }
2619: }
2620: }
2621: }
2622: }
2623: }
2624: } else {
2625: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
2626: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
2627: if ($userenv{'reqcrsotherdom.'.$crstype}) {
2628: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
2629: my $optregex = join('|',@options);
2630: foreach my $item (@doms) {
2631: my ($extdom,$extopt) = split(':',$item);
2632: if ($extdom eq $dom) {
2633: if ($extopt =~ /^($optregex)(=?\d*)$/) {
2634: $val = $1.$2;
2635: }
2636: last;
2637: }
2638: }
2639: @{$inststatuses} = ('_external_');
2640: }
2641: }
2642: return $val;
2643: }
2644:
2645: sub check_autolimit {
2646: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
2647: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
2648: 'userroles',['active','future'],['cc'],[$dom]);
2649: my ($types,$typename) = &course_types();
2650: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
2651: my %count;
2652: if (ref($types) eq 'ARRAY') {
2653: foreach my $type (@{$types}) {
2654: $count{$type} = 0;
2655: }
2656: }
2657: foreach my $key (keys(%requests)) {
2658: my ($cdom,$cnum) = split('_',$key);
2659: if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
2660: if (ref($requests{$key}) eq 'HASH') {
2661: my $type = $requests{$key}{'crstype'};
2662: if ($type =~ /^official|unofficial|community$/) {
2663: $count{$type} ++;
2664: }
2665: }
2666: }
2667: }
2668: if ($count{$crstype} < $limit) {
2669: return 'process';
2670: } else {
2671: if (ref($typename) eq 'HASH') {
2672: $$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);
2673: }
2674: return 'rejected';
2675: }
2676: return;
2677: }
2678:
2679: sub retrieve_settings {
2680: my ($dom,$cnum,$udom,$uname) = @_;
2681: if ($udom eq '' || $uname eq '') {
2682: $udom = $env{'user.domain'};
2683: $uname = $env{'user.name'};
2684: }
2685: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
2686: if ($result eq 'ok') {
2687: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
2688: $env{'form.chome'} = $reqinfo{'coursehome'};
2689: $env{'form.cdescr'} = $reqinfo{'cdescr'};
2690: $env{'form.crstype'} = $reqinfo{'crstype'};
2691: &generate_date_items($reqinfo{'accessstart'},'accessstart');
2692: &generate_date_items($reqinfo{'accessend'},'accessend');
2693: if ($reqinfo{'accessend'} == 0) {
2694: $env{'form.no_end_date'} = 1;
2695: }
2696: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
2697: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
2698: &generate_date_items($reqinfo{'enrollend'},'enrollend');
2699: }
2700: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
2701: $env{'form.clonedom'} = $reqinfo{'clonedom'};
2702: $env{'form.datemode'} = $reqinfo{'datemode'};
2703: $env{'form.dateshift'} = $reqinfo{'dateshift'};
2704: if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
2705: $env{'form.sectotal'} = $reqinfo{'sectotal'};
2706: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
2707: $env{'form.autoadds'} = $reqinfo{'autoadds'};
2708: $env{'form.autdrops'} = $reqinfo{'autodrops'};
2709: $env{'form.instcode'} = $reqinfo{'instcode'};
2710: my $crscode = {
2711: $cnum => $reqinfo{'instcode'},
2712: };
2713: &extract_instcode($dom,'instcode',$crscode,$cnum);
2714: }
2715: my @currsec;
2716: if (ref($reqinfo{'sections'}) eq 'HASH') {
2717: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
2718: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
2719: my $sec = $reqinfo{'sections'}{$i}{'inst'};
2720: $env{'form.secnum_'.$i} = $sec;
2721: $env{'form.sec_'.$i} = '1';
2722: if (!grep(/^\Q$sec\E$/,@currsec)) {
2723: push(@currsec,$sec);
2724: }
2725: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
2726: }
2727: }
2728: }
2729: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
2730: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
2731: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
2732: $env{'form.crosslist_'.$i} = '1';
2733: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
2734: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
2735: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
2736: my $key = $cnum.$i;
2737: my $crscode = {
2738: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
2739: };
2740: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
2741: }
2742: }
2743: }
2744: }
2745: if (ref($reqinfo{'personnel'}) eq 'HASH') {
2746: my $i = 0;
2747: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
2748: my ($uname,$udom) = split(':',$user);
2749: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
2750: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
2751: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
2752: $env{'form.person_'.$i.'_role'} = $role;
2753: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
2754: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
2755: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
2756: $env{'form.person_'.$i.'_uname'} = $uname;
2757: $env{'form.person_'.$i.'_dom'} = $udom;
2758: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
2759: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
2760: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
2761: my @newsecs;
2762: if (@usecs > 0) {
2763: foreach my $sec (@usecs) {
2764: if (grep(/^\Q$sec\E/,@currsec)) {
2765: $env{'form.person_'.$i.'_sec'} = $sec;
2766: } else {
2767: push(@newsecs,$sec);
2768: }
2769: }
2770: }
2771: if (@newsecs > 0) {
2772: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
2773: }
2774: }
2775: }
2776: $i ++;
2777: }
2778: }
2779: }
2780: }
2781: $env{'form.persontotal'} = $i;
2782: }
2783: }
2784: }
2785: return $result;
2786: }
2787:
2788: sub get_request_settings {
2789: my ($dom,$cnum,$udom,$uname) = @_;
2790: my $requestkey = $dom.'_'.$cnum;
2791: my ($result,%reqinfo);
2792: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2793: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
2794: my $disposition = $history{'disposition'};
2795: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
2796: if (ref($history{'details'}) eq 'HASH') {
2797: %reqinfo = %{$history{'details'}};
2798: $result = 'ok';
2799: } else {
2800: $result = 'nothash';
2801: }
2802: } else {
2803: $result = 'notqueued';
2804: }
2805: } else {
2806: $result = 'invalid';
2807: }
2808: return ($result,%reqinfo);
2809: }
2810:
2811: sub extract_instcode {
2812: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
2813: my (%codes,@codetitles,%cat_titles,%cat_order);
2814: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
2815: \@codetitles,\%cat_titles,
2816: \%cat_order) eq 'ok') {
2817: if (ref($codes{$crskey}) eq 'HASH') {
2818: if (@codetitles > 0) {
2819: my $sel = $element;
2820: if ($element eq 'crosslist') {
2821: $sel .= '_'.$counter;
2822: }
2823: foreach my $title (@codetitles) {
2824: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
2825: }
2826: }
2827: }
2828: }
2829: return;
2830: }
2831:
2832: sub generate_date_items {
2833: my ($currentval,$item) = @_;
2834: if ($currentval =~ /\d+/) {
2835: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
2836: &Apache::lonhtmlcommon::get_timedates($currentval);
2837: $env{'form.'.$item.'_day'} = $mday;
2838: $env{'form.'.$item.'_month'} = $month+1;
2839: $env{'form.'.$item.'_year'} = $year;
2840: }
2841: return;
2842: }
2843:
2844: 1;
2845:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>