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