1: # The LearningOnline Network
2: # Request a course
3: #
4: # $Id: lonrequestcourse.pm,v 1.89 2015/06/09 21:22:57 damieng 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','tabs']);
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,%can_request,
138: %request_domains,@incdoms);
139: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
140: if ($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}) {
141: $showcredits = 1;
142: }
143:
144: my $canreq =
145: &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains);
146:
147: foreach my $item (keys(%request_domains)) {
148: if (ref($request_domains{$item}) eq 'ARRAY') {
149: foreach my $possdom (@{$request_domains{$item}}) {
150: unless(grep(/^\Q$possdom\E$/,@incdoms)) {
151: push(@incdoms,$possdom);
152: }
153: }
154: }
155: }
156:
157: if ($canreq) {
158: if (($env{'form.crstype'} eq 'textbook') ||
159: (scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) {
160: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
161: if ($action eq 'log') {
162: my $usetabs;
163: if ((scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) {
164: $usetabs = 1;
165: } elsif ($env{'form.tabs'} eq 'on') {
166: $usetabs = 1;
167: }
168: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
169: my $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
170: &print_request_logs($r,$dom,undef,undef,$crumb,$usetabs);
171: } elsif ($action eq 'process') {
172: if ($can_request{'textbook'}) {
173: &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig,\%can_request);
174: } else {
175: &textbook_request_disabled($r,$dom,$action,\%can_request);
176: }
177: } elsif ($action eq 'display') {
178: my ($uname,$udom,$result,$warning) = &domcoord_display($dom);
179: if ($warning ne '') {
180: my $args = { only_body => 1 };
181: $r->print(&header('Course/Community Requests','','' ,'',$args).
182: '<h3>'.&mt('Course/Community Request Details').'</h3>'.
183: '<div class="LC_warning">'.$warning.'</div>'.
184: &close_popup_form());
185: } else {
186: $states{'display'} = ['details'];
187: my $loaditems = &onload_action($action,$state);
188: my $page = 0;
189: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
190: $loaditems,'','','','','',$showcredits,'','',
191: $uname,$udom);
192: }
193: } else {
194: if ($can_request{'textbook'}) {
195: &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'},\%can_request);
196: } else {
197: &textbook_request_disabled($r,$dom,$action,\%can_request);
198: }
199: }
200: return OK;
201: }
202: }
203:
204: $states{'display'} = ['details'];
205: $states{'view'} = ['pick_request','details','cancel','removal'];
206: $states{'log'} = ['display'];
207: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
208:
209: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
210: unless ($env{'form.state'} eq 'crstype') {
211: unshift(@{$states{'new'}},'codepick');
212: }
213: }
214:
215: if (($action eq 'new') && (&Apache::loncoursequeueadmin::author_prompt())) {
216: if (ref($states{$action}) eq 'ARRAY') {
217: push(@{$states{$action}},'reqauthor');
218: }
219: }
220:
221: foreach my $key (keys(%states)) {
222: if (ref($states{$key}) eq 'ARRAY') {
223: unshift (@{$states{$key}},'crstype');
224: }
225: }
226:
227: my @invalidcrosslist;
228: my %trail = (
229: crstype => 'Pick Action',
230: codepick => 'Category',
231: courseinfo => 'Description',
232: enrollment => 'Access Dates',
233: personnel => 'Personnel',
234: review => 'Review',
235: process => 'Result',
236: reqauthor => 'Authoring Space Result',
237: pick_request => 'Display Summary',
238: details => 'Request Details',
239: cancel => 'Cancel Request',
240: removal => 'Outcome',
241: display => 'Request Logs',
242: );
243:
244: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
245: $trail{'enrollment'} = 'Enrollment';
246: }
247:
248: my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) =
249: &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
250: if ($action eq 'display') {
251: ($uname,$udom,$result,$warning) = &domcoord_display($dom);
252: } elsif ((defined($state)) && (defined($action))) {
253: if (($action eq 'view') && ($state eq 'details')) {
254: if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
255: my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
256: }
257: } elsif ($env{'form.crstype'} eq 'official') {
258: if (&Apache::lonnet::auto_run('',$dom)) {
259: if (($action eq 'new') && (($state eq 'enrollment') ||
260: ($state eq 'personnel'))) {
261: my $checkcrosslist = 0;
262: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
263: if ($env{'form.crosslist_'.$i}) {
264: $checkcrosslist ++;
265: }
266: }
267: if ($checkcrosslist) {
268: my %codechk;
269: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
270: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
271: \%cat_titles,
272: \%cat_order,
273: \@code_order);
274: my $numtitles = scalar(@codetitles);
275: if ($numtitles) {
276: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
277: if ($env{'form.crosslist_'.$i}) {
278: my $codecheck;
279: my $crosslistcode = '';
280: foreach my $item (@code_order) {
281: $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item};
282: }
283: if ($crosslistcode ne '') {
284: ($codechk{$i}, my $rest) =
285: &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
286: }
287: unless ($codechk{$i} eq 'valid') {
288: $env{'form.crosslist_'.$i} = '';
289: push(@invalidcrosslist,$crosslistcode);
290: }
291: }
292: }
293: }
294: }
295: }
296: }
297: }
298: (my $elements,$instcredits) = &form_elements($dom,$showcredits);
299: my $elementsref = {};
300: if ((ref($elements) eq 'HASH') && (ref($elements->{$action}) eq 'HASH')) {
301: if (ref($elements->{$action}{$state}) eq 'HASH') {
302: $elementsref = $elements->{$action}{$state};
303: }
304: }
305: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
306: $env{'form.clonedom'} = $dom;
307: }
308: if ($state eq 'crstype') {
309: $jscript = &mainmenu_javascript();
310: } else {
311: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
312: if ($state eq 'courseinfo') {
313: $jscript .= &cloning_javascript();
314: } elsif ($state eq 'process') {
315: $jscript .= &processing_javascript();
316: }
317: }
318: }
319:
320: if ($state eq 'personnel') {
321: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
322: }
323:
324: my $loaditems = &onload_action($action,$state);
325:
326: if ($action eq 'new') {
327: if ($canreq) {
328: if ($state eq 'crstype') {
329: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
330: $crumb,\@incdoms);
331: } else {
332: &request_administration($r,$action,$state,$page,\%states,$dom,
333: $jscript,$loaditems,$crumb,$newinstcode,
334: $codechk,$checkedcode,$description,
335: $showcredits,$instcredits,\@invalidcrosslist);
336: }
337: } else {
338: $r->print(&header('Course/Community Requests').$crumb.
339: '<div class="LC_warning">'.
340: &mt('You do not have privileges to request creation of courses or communities.').
341: '</div>'.&Apache::loncommon::end_page());
342: }
343: } elsif ($action eq 'view') {
344: if ($state eq 'crstype') {
345: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\@incdoms);
346: } else {
347: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
348: $loaditems,$crumb,'','','','',$showcredits);
349: }
350: } elsif ($action eq 'display') {
351: if ($warning ne '') {
352: my $args = { only_body => 1 };
353: $r->print(&header('Course/Community Requests','','' ,'',$args).$crumb.
354: '<h3>'.&mt('Course/Community Request Details').'</h3>'.
355: '<div class="LC_warning">'.$warning.'</div>'.
356: &close_popup_form());
357: } else {
358: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
359: $loaditems,$crumb,'','','','',$showcredits,'','',
360: $uname,$udom);
361: }
362: } elsif ($action eq 'log') {
363: if ($state eq 'crstype') {
364: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\@incdoms);
365: } else {
366: $jscript .= <<ENDJS;
367:
368: function backPage(formname,prevstate) {
369: formname.state.value = prevstate;
370: formname.submit();
371: }
372:
373: function setPage(formname) {
374: formname.page.value = '1';
375: return;
376: }
377:
378: ENDJS
379: &print_request_logs($r,$dom,$jscript,$loaditems,$crumb,\%can_request);
380: }
381: } else {
382: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\@incdoms);
383: }
384: return OK;
385: }
386:
387: sub mainmenu_javascript {
388: return <<"END";
389: function setType(courseForm) {
390: for (var i=0; i<courseForm.crstype.length; i++) {
391: if (courseForm.crstype.options[i].value == "$env{'form.crstype'}") {
392: courseForm.crstype.options[i].selected = true;
393: } else {
394: courseForm.crstype.options[i].selected = false;
395: }
396: }
397: }
398:
399: function setAction(courseForm) {
400: for (var i=0; i<courseForm.action.length; i++) {
401: if (courseForm.action.options[i].value == "$env{'form.action'}") {
402: courseForm.action.options[i].selected = true;
403: } else {
404: courseForm.action.options[i].selected = false;
405: }
406: }
407: }
408: END
409: }
410:
411: sub cloning_javascript {
412: return <<"END";
413: function setCloneDisplay(courseForm) {
414: if (courseForm.cloning.length > 1) {
415: for (var i=0; i<courseForm.cloning.length; i++) {
416: if (courseForm.cloning[i].checked) {
417: if (courseForm.cloning[i].value == 1) {
418: document.getElementById('cloneoptions').style.display="block";
419: }
420: }
421: }
422: }
423: }
424: END
425: }
426:
427: sub processing_javascript {
428: return <<"END";
429: function hideProcessing() {
430: if (document.getElementById('processing')) {
431: document.getElementById('processing').style.display="none";
432: }
433: }
434:
435: END
436: }
437:
438: sub get_breadcrumbs {
439: my ($dom,$action,$state,$states,$trail) = @_;
440: my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
441: my $page = 0;
442: if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
443: if (defined($action)) {
444: my $done = 0;
445: my $i=0;
446: if (ref($states->{$action}) eq 'ARRAY') {
447: while ($i<@{$states->{$action}} && !$done) {
448: if ($states->{$action}[$i] eq $$state) {
449: $page = $i;
450: $done = 1;
451: }
452: $i++;
453: }
454: }
455: if ($env{'form.crstype'} eq 'official') {
456: if ($page > 1) {
457: if ($states->{$action}[$page-1] eq 'codepick') {
458: if ($env{'form.instcode'} eq '') {
459: ($newinstcode,$numtitles) = &get_instcode($dom);
460: if ($numtitles) {
461: if ($newinstcode eq '') {
462: $$state = 'codepick';
463: $page --;
464: } else {
465: ($codechk,$description) =
466: &Apache::lonnet::auto_validate_instcode('',
467: $dom,$newinstcode);
468: if ($codechk ne 'valid') {
469: $$state = 'codepick';
470: $page --;
471: }
472: $checkedcode = 1;
473: }
474: }
475: }
476: }
477: }
478: }
479: if (ref($states->{$action}) eq 'ARRAY') {
480: for (my $i=0; $i<@{$states->{$action}}; $i++) {
481: if ($$state eq $states->{$action}[$i]) {
482: &Apache::lonhtmlcommon::add_breadcrumb(
483: {text=>"$trail->{$$state}"});
484: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
485: last;
486: } else {
487: if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) {
488: &Apache::lonhtmlcommon::add_breadcrumb(
489: { href => '/adm/requestcourse',
490: text => "$trail->{$states->{$action}[$i]}",
491: }
492: );
493: } else {
494: &Apache::lonhtmlcommon::add_breadcrumb(
495: { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')",
496: text => "$trail->{$states->{$action}[$i]}", }
497: );
498: }
499: }
500: }
501: }
502: } else {
503: &Apache::lonhtmlcommon::add_breadcrumb(
504: {text=>'Pick Action'});
505: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
506: }
507: } else {
508: &Apache::lonhtmlcommon::add_breadcrumb(
509: {text=>'Pick Action'});
510: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
511: }
512: return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
513: }
514:
515: sub header {
516: my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
517: if ($jscript) {
518: $jscript = '<script type="text/javascript">'."\n".
519: '// <![CDATA['."\n".
520: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
521: }
522: if ($loaditems) {
523: if (ref($args) eq 'HASH') {
524: my %loadhash = (
525: 'add_entries' => $loaditems,
526: );
527: my %arghash = (%loadhash,%{$args});
528: $args = \%arghash;
529: } else {
530: $args = {'add_entries' => $loaditems,};
531: }
532: }
533: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
534: }
535:
536: sub form_elements {
537: my ($dom,$showcredits) = @_;
538: my $instcredits;
539: my %elements =
540: (
541: new => {
542: crstype => {
543: crstype => 'selectbox',
544: action => 'selectbox',
545: origcnum => 'hidden',
546: },
547: courseinfo => {
548: cdescr => 'text',
549: cloning => 'radio',
550: clonecrs => 'text',
551: clonedom => 'selectbox',
552: datemode => 'radio',
553: dateshift => 'text',
554: },
555: enrollment => {
556: accessstart_month => 'selectbox',
557: accessstart_hour => 'selectbox',
558: accessend_month => 'selectbox',
559: accessend_hour => 'selectbox',
560: accessstart_day => 'text',
561: accessstart_year => 'text',
562: accessstart_minute => 'text',
563: accessstart_second => 'text',
564: accessend_day => 'text',
565: accessend_year => 'text',
566: accessend_minute => 'text',
567: accessend_second => 'text',
568: no_end_date => 'checkbox',
569: },
570: personnel => {
571: addperson => 'checkbox',
572: },
573: review => {
574: cnum => 'hidden',
575: },
576: },
577: view => {
578: crstype => {
579: crstype => 'selectbox',
580: action => 'selectbox',
581: },
582: },
583: );
584: my %servers = &Apache::lonnet::get_servers($dom,'library');
585: my $numlib = keys(%servers);
586: if ($numlib > 1) {
587: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
588: } else {
589: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
590: }
591: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
592: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
593: \%cat_order,\@code_order);
594: my $numtitles = scalar(@codetitles);
595: if ($numtitles) {
596: my %extras;
597: $lastitem = pop(@codetitles);
598: $extras{'instcode_'.$lastitem} = 'text';
599: foreach my $item (@codetitles) {
600: $extras{'instcode_'.$item} = 'selectbox';
601: }
602: $elements{'new'}{'codepick'} = \%extras;
603: }
604: if (&Apache::lonnet::auto_run('',$dom)) {
605: my %extras = (
606: enrollstart_month => 'selectbox',
607: enrollstart_hour => 'selectbox',
608: enrollend_month => 'selectbox',
609: enrollend_hour => 'selectbox',
610: enrollstart_day => 'text',
611: enrollstart_year => 'text',
612: enrollstart_minute => 'text',
613: enrollstart_second => 'text',
614: enrollend_day => 'text',
615: enrollend_year => 'text',
616: enrollend_minute => 'text',
617: enrollend_second => 'text',
618: addcrosslist => 'checkbox',
619: autoadds => 'radio',
620: autodrops => 'radio',
621: );
622: my ($instcode,$titlescount) = &get_instcode($dom);
623: if ($instcode) {
624: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
625: if (@sections) {
626: $extras{'sectotal'} = 'hidden';
627: if ($env{'form.sectotal'} > 0) {
628: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
629: $extras{'sec_'.$i} = 'radio';
630: $extras{'secnum_'.$i} = 'text';
631: $extras{'loncapasec_'.$i} = 'text';
632: }
633: }
634: } else {
635: $extras{'addsection'} = 'checkbox';
636: my $sectotal = $env{'form.sectotal'};
637: if ($env{'form.addsection'}) {
638: $sectotal ++;
639: }
640: for (my $i=0; $i<$sectotal; $i++) {
641: $extras{'sec_'.$i} = 'checkbox';
642: $extras{'secnum_'.$i} = 'text',
643: $extras{'loncapasec_'.$i} = 'text',
644: }
645: }
646: (my $outcome,my $desc,$instcredits) =
647: &Apache::lonnet::auto_validate_instcode(undef,$dom,$instcode);
648: if ($showcredits && $instcredits eq '') {
649: $extras{'coursecredits'} = 'text';
650: }
651: } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
652: if ($showcredits) {
653: $extras{'coursecredits'} = 'text';
654: }
655: }
656: my $crosslisttotal = $env{'form.crosslisttotal'};
657: if ($env{'form.addcrosslist'}) {
658: $crosslisttotal ++;
659: }
660: if (!$crosslisttotal) {
661: $crosslisttotal = 1;
662: }
663: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
664: if ($numtitles) {
665: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
666: }
667: if (@codetitles > 0) {
668: foreach my $item (@codetitles) {
669: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
670: }
671: }
672: $extras{'crosslist_'.$i} = 'checkbox';
673: $extras{'crosslist_'.$i.'_instsec'} = 'text',
674: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
675: }
676: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
677: %{$elements{'new'}{'enrollment'}} = %mergedhash;
678: }
679: my %people;
680: my $persontotal = $env{'form.persontotal'};
681: if ($env{'form.addperson'}) {
682: $persontotal ++;
683: }
684: if ((!defined($persontotal)) || (!$persontotal)) {
685: $persontotal = 1;
686: }
687: for (my $i=0; $i<$persontotal; $i++) {
688: $people{'person_'.$i.'_uname'} = 'text',
689: $people{'person_'.$i.'_dom'} = 'selectbox',
690: $people{'person_'.$i.'_hidedom'} = 'hidden',
691: $people{'person_'.$i.'_firstname'} = 'text',
692: $people{'person_'.$i.'_lastname'} = 'text',
693: $people{'person_'.$i.'_emailaddr'} = 'text',
694: $people{'person_'.$i.'_role'} = 'selectbox',
695: $people{'person_'.$i.'_sec'} = 'selectbox',
696: $people{'person_'.$i.'_newsec'} = 'text',
697: }
698: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
699: %{$elements{'new'}{'personnel'}} = %personnelhash;
700: return (\%elements,$instcredits);;
701: }
702:
703: sub onload_action {
704: my ($action,$state) = @_;
705: my %loaditems;
706: if (($action eq 'new') || ($action eq 'view')) {
707: if ($state eq 'crstype') {
708: $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
709: } else {
710: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
711: }
712: if ($state eq 'courseinfo') {
713: $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);';
714: }
715: if ($state eq 'process') {
716: $loaditems{'onload'} .= 'javascript:hideProcessing();';
717: }
718: }
719: return \%loaditems;
720: }
721:
722: sub print_main_menu {
723: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$incdoms) = @_;
724: my ($types,$typename) = &Apache::loncommon::course_types();
725: my $onchange = 'this.form.submit()';
726: my $nextstate_setter = "\n";
727: if (ref($states) eq 'HASH') {
728: foreach my $key (keys(%{$states})) {
729: if (ref($states->{$key}) eq 'ARRAY') {
730: $nextstate_setter .=
731: " if (actionchoice == '$key') {
732: nextstate = '".$states->{$key}[1]."';
733: }
734: ";
735: }
736: }
737: }
738:
739: my $js = <<"END";
740:
741: function nextPage(formname) {
742: var crschoice = document.mainmenu_coursetype.crstype.value;
743: var actionchoice = document.mainmenu_action.action.value;
744: if (check_can_request(crschoice,actionchoice) == true) {
745: if ((actionchoice == 'new') && (crschoice == 'official')) {
746: nextstate = 'codepick';
747: } else {
748: $nextstate_setter
749: }
750: formname.crstype.value = crschoice;
751: formname.action.value = actionchoice;
752: formname.state.value= nextstate;
753: formname.submit();
754: }
755: return;
756: }
757:
758: function check_can_request(crschoice,actionchoice) {
759: var official = '';
760: var unofficial = '';
761: var community = '';
762: var textbook = '';
763: END
764: if (ref($can_request) eq 'HASH') {
765: foreach my $item (keys(%{$can_request})) {
766: $js .= "
767: $item = 1;
768: ";
769: }
770: }
771: my %js_lt = &Apache::lonlocal::texthash(
772: official => 'You are not permitted to request creation of an official course in this domain.',
773: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
774: community => 'You are not permitted to request creation of a community in this domain.',
775: textbook => 'You are not permitted to request creation of a textbook course in this domain',
776: all => 'You must choose a specific course type when making a new course request.',
777: allt => '"All types" is not allowed.',
778: );
779: &js_escape(\%js_lt);
780: $js .= <<END;
781: if (crschoice == 'official') {
782: if (official != 1) {
783: alert("$js_lt{'official'}");
784: return false;
785: }
786: } else {
787: if (crschoice == 'unofficial') {
788: if (unofficial != 1) {
789: alert("$js_lt{'unofficial'}");
790: return false;
791: }
792: } else {
793: if (crschoice == 'community') {
794: if (community != 1) {
795: alert("$js_lt{'community'}");
796: return false;
797: }
798: } else {
799: if (crschoice == 'textbook') {
800: if (textbook != 1) {
801: alert("$js_lt{'textbook'}");
802: return false;
803: }
804: } else {
805: if (actionchoice == 'new') {
806: alert('$js_lt{'all'}'+'\\n'+'$js_lt{'allt'}');
807: return false;
808: }
809: }
810: }
811: }
812: }
813: return true;
814: }
815: END
816: my ($pagetitle,$pageinfo,$domaintitle,$earlyout);
817: if (ref($can_request) eq 'HASH') {
818: if (($can_request->{'official'}) || ($can_request->{'unofficial'}) || $can_request->{'textbook'}) {
819: if ($can_request->{'community'}) {
820: $pagetitle = 'Course/Community Requests';
821: $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
822: $domaintitle = &mt('Course/Community Domain');
823: } else {
824: $pagetitle = 'Course Requests';
825: $pageinfo = &mt('Request creation of a new course, or review your pending course requests.');
826: $domaintitle = &mt('Course Domain');
827: }
828: } elsif ($can_request->{'community'}) {
829: $pagetitle = 'Community Requests';
830: $pageinfo = &mt('Request creation of a new course, or review your pending requests.');
831: $domaintitle = &mt('Community Domain');
832: } elsif ((ref($incdoms) eq 'ARRAY') && ((@{$incdoms} > 1) ||
833: ((@{$incdoms} == 1) && ($incdoms->[0] ne $dom)))) {
834: $pagetitle = 'Course/Community Requests';
835: $pageinfo = &mt('You do not have rights to request creation of courses in this domain; please choose a different domain.');
836: $domaintitle = &mt('Course/Community Domain');
837: } else {
838: $pagetitle = 'Course/Community Requests';
839: $pageinfo = &mt('You do not have rights to request creation of courses or communities.');
840: $earlyout = 1;
841: }
842: }
843: $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
844: '<p>'.$pageinfo.'</p>');
845: if ($earlyout) {
846: $r->print(&Apache::loncommon::end_page());
847: return;
848: }
849: $r->print('<div>'.
850: &Apache::lonhtmlcommon::start_pick_box().
851: &Apache::lonhtmlcommon::row_title($domaintitle).
852: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
853: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms));
854: if (!$onchange) {
855: $r->print(' <input type="submit" name="godom" value="'.
856: &mt('Change').'" />');
857: }
858: unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) {
859: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure(1)."\n".
860: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
861: &Apache::loncommon::end_page());
862: return;
863: }
864: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
865: my $formname = 'requestcrs';
866: my $nexttext = &mt('Next');
867: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
868: <form name="mainmenu_action" method="post" action="">
869: <select size="1" name="action" >
870: <option value="new">'.&mt('New request').'</option>
871: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
872: <option value="log">'.&mt('View request history').'</option>
873: </select></form>'.
874: &Apache::lonhtmlcommon::row_closure().
875: &Apache::lonhtmlcommon::row_title(&mt('Type')).'
876: <form name="mainmenu_coursetype" method="post" action="">
877: <select size="1" name="crstype">');
878: if (ref($can_request) eq 'HASH') {
879: if (keys(%{$can_request}) > 1) {
880: $r->print(' <option value="any">'.&mt('All types').'</option>');
881: }
882: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
883: foreach my $type (@{$types}) {
884: next unless($can_request->{$type});
885: my $selected = '';
886: if ($env{'form.crstype'} eq '') {
887: if ($type eq 'official') {
888: $selected = ' selected="selected"';
889: }
890: } else {
891: if ($type eq $env{'form.crstype'}) {
892: $selected = ' selected="selected"';
893: }
894: }
895: $r->print('<option value="'.$type.'"'.$selected.'>'.&mt($typename->{$type}).
896: '</option>'."\n");
897: }
898: }
899: }
900: $r->print('</select></form>'."\n".
901: &Apache::lonhtmlcommon::row_closure(1)."\n".
902: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
903: '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n".
904: '<input type="hidden" name="state" value="crstype" />'."\n".
905: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
906: '<input type="hidden" name="crstype" value="" />'."\n".
907: '<input type="hidden" name="action" value="" />'."\n".
908: '<input type="button" name="next" value="'.$nexttext.
909: '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
910: '</form></div>');
911: $r->print(&Apache::loncommon::end_page());
912: return;
913: }
914:
915: sub request_administration {
916: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
917: $newinstcode,$codechk,$checkedcode,$description,$showcredits,
918: $instcredits,$invalidcrosslist,$uname,$udom) = @_;
919: my $js;
920: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
921: $js = <<END;
922:
923: function nextPage(formname,nextstate) {
924: formname.state.value= nextstate;
925: formname.submit();
926: }
927:
928: END
929: }
930: if (($action eq 'new') || ($action eq 'view')) {
931: $js .= <<END;
932:
933: function backPage(formname,prevstate) {
934: formname.state.value = prevstate;
935: formname.submit();
936: }
937:
938: END
939: }
940: if ($action eq 'new') {
941: my $jsextra;
942: if (($state eq 'courseinfo') || ($state eq 'codepick')) {
943: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom,'','','','','',
944: $newinstcode);
945: } elsif ($state eq 'enrollment') {
946: if (($env{'form.crstype'} eq 'official') &&
947: (&Apache::lonnet::auto_run('',$dom))) {
948: $js .= "\n".§ion_check_javascript()."\n".&enrollment_lcsec_js();
949: }
950: } elsif ($state eq 'personnel') {
951: $js .= "\n".§ion_check_javascript()."\n".&personnel_lcsec_js();
952: }
953: my $title;
954: if ($env{'form.crstype'} eq 'community') {
955: $title = 'Request a community';
956: } else {
957: $title = 'Request a course';
958: }
959: $r->print(&header($title,$js.$jscript,$loaditems,$jsextra).$crumb);
960: &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
961: $codechk,$checkedcode,$description,$showcredits,
962: $instcredits,$invalidcrosslist);
963: } elsif ($action eq 'view') {
964: my $jsextra;
965: my $formname = 'requestcrs';
966: my $prev = $states->{$action}[$page-1];
967: my $next = $states->{$action}[$page+1];
968: if ($state eq 'pick_request') {
969: $next = $states->{$action}[$page+1];
970: $jsextra = &viewrequest_javascript($formname,$next);
971: } elsif ($state eq 'details') {
972: $jsextra = &viewdetails_javascript($formname);
973:
974: } elsif ($state eq 'cancel') {
975: $jsextra = &viewcancel_javascript($formname);
976: }
977: my $title;
978: if ($env{'form.crstype'} eq 'community') {
979: $title = 'Manage community requests';
980: } else {
981: $title = 'Manage course requests';
982: }
983: $r->print(&header($title,$js.$jscript.$jsextra,$loaditems).$crumb);
984: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
985: if ($state eq 'pick_request') {
986: my $title;
987: if ($env{'form.crstype'} eq 'community') {
988: $title = &mt('Pending community requests');
989: } elsif ($env{'form.crstype'} eq 'official') {
990: $title = &mt('Pending requests for official courses');
991: } elsif ($env{'form.crstype'} eq 'unofficial') {
992: $title = &mt('Pending requests for unofficial courses');
993: } elsif ($env{'form.crstype'} eq 'textbook') {
994: $title = &mt('Pending requests for textbook courses');
995: } else {
996: $title = &mt('Pending course/community requests');
997: }
998: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
999: &print_request_status($dom,$action).'</form></div>');
1000: } elsif ($state eq 'details') {
1001: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1002: my $origcnum = $env{'form.cnum'};
1003: if ($origcnum eq '') {
1004: $origcnum = $env{'form.origcnum'};
1005: }
1006: if ($env{'form.crstype'} eq 'official') {
1007: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1008: \%cat_order,\@code_order);
1009: }
1010: my $title;
1011: if ($env{'form.crstype'} eq 'community') {
1012: $title = &mt('Community Request Details');
1013: } else {
1014: $title = &mt('Course Request Details');
1015: }
1016: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1017: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1018: \@code_order,'','','','',$instcredits)."\n".
1019: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
1020: my @excluded = &get_excluded_elements($dom,$states,'new','review',
1021: $showcredits);
1022: push(@excluded,'origcnum');
1023: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
1024: my $other = 'modify';
1025: my %navtxt = &Apache::lonlocal::texthash (
1026: prev => 'Back',
1027: other => 'Modify Request',
1028: next => 'Cancel Request',
1029: );
1030: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1031: $navtxt{'next'},$state,$other,$navtxt{'other'});
1032: $r->print('</form>');
1033: } elsif ($state eq 'cancel') {
1034: my $title;
1035: if ($env{'form.crstype'} eq 'community') {
1036: $title = &mt('Cancel community request');
1037: } else {
1038: $title = &mt('Cancel course request');
1039: }
1040: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
1041: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1042: $output);
1043: my @excluded = &get_excluded_elements($dom,$states,'view','cancel',
1044: $showcredits);
1045: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
1046: my %navtxt = &Apache::lonlocal::texthash (
1047: prev => 'Back',
1048: next => 'Confirm Cancellation',
1049: );
1050: if ($result eq 'ok') {
1051: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1052: $navtxt{'next'},$state);
1053: } else {
1054: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
1055: '',$state);
1056: }
1057: $r->print('</form>');
1058: } elsif ($state eq 'removal') {
1059: my $cnum = $env{'form.origcnum'};
1060: my $statuskey = 'status:'.$dom.':'.$cnum;
1061: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
1062: $env{'user.domain'},$env{'user.name'});
1063: my $currstatus = $userreqhash{$statuskey};
1064: my ($result,$error);
1065: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
1066: my %status = (
1067: $statuskey => 'cancelled',
1068: );
1069: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
1070: if ($statusresult eq 'ok') {
1071: my $delresult =
1072: &Apache::lonnet::del_dom('courserequestqueue',
1073: [$cnum.'_'.$currstatus],$dom);
1074: if ($delresult eq 'ok') {
1075: $result = 'ok';
1076: } else {
1077: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
1078: }
1079: } else {
1080: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
1081: }
1082: } else {
1083: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
1084: }
1085: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
1086: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
1087: '<input type="hidden" name="action" value="'.$action.'" />'."\n".
1088: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
1089: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
1090: if ($result eq 'ok') {
1091: if ($env{'form.crstype'} eq 'community') {
1092: $r->print(&mt('Your community request has been cancelled.'));
1093: } else {
1094: $r->print(&mt('Your course request has been cancelled.'));
1095: }
1096: } else {
1097: $r->print('<div class="LC_error">'.
1098: &mt('The request cancellation process was not complete.').
1099: '<br />'.$error.'</div>');
1100: }
1101: $r->print('</form>');
1102: }
1103: } elsif ($action eq 'display') {
1104: my $formname = 'requestcrs';
1105: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1106: if ($env{'form.crstype'} eq 'official') {
1107: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1108: \%cat_order,\@code_order);
1109: }
1110: my ($title,$header);
1111: if ($env{'form.crstype'} eq 'community') {
1112: $title = 'Community Request';
1113: $header = &mt('Community Request');
1114: } else {
1115: $title = 'Course Request';
1116: $header = &mt('Course Request');
1117: }
1118: $r->print(&header($title,'','','',{ 'only_body' => 1}).
1119: $crumb."\n".'<h3>'.$header.'</h3>'.
1120: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1121: \@code_order,$uname,$udom,'','',$instcredits)."\n".
1122: '</div>'.
1123: &close_popup_form());
1124: }
1125: $r->print(&Apache::loncommon::end_page());
1126: return;
1127: }
1128:
1129: sub domcoord_display {
1130: my ($dom) = @_;
1131: my ($uname,$udom,$result,$warning);
1132: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
1133: if ($env{'form.cnum'} ne '') {
1134: my $cnum = $env{'form.cnum'};
1135: my $queue = $env{'form.queue'};
1136: my $reqkey = $cnum.'_'.$queue;
1137: my $namespace = 'courserequestqueue';
1138: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
1139: my %queued =
1140: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
1141: if (ref($queued{$reqkey}) eq 'HASH') {
1142: $uname = $queued{$reqkey}{'ownername'};
1143: $udom = $queued{$reqkey}{'ownerdom'};
1144: if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
1145: $result = &retrieve_settings($dom,$cnum,$udom,$uname);
1146: } else {
1147: if ($env{'form.crstype'} eq 'community') {
1148: $warning = &mt('Invalid username or domain for community requestor');
1149: } else {
1150: $warning = &mt('Invalid username or domain for course requestor');
1151: }
1152: }
1153: } else {
1154: if ($env{'form.crstype'} eq 'community') {
1155: $warning = &mt('No information was found for this community request.');
1156: } else {
1157: $warning = &mt('No information was found for this course request.');
1158: }
1159: }
1160: } else {
1161: $warning = &mt('No course request ID provided.');
1162: }
1163: } else {
1164: if ($env{'form.crstype'} eq 'any') {
1165: $warning = &mt('You do not have rights to view course or community request information.');
1166: } elsif ($env{'form.crstype'} eq 'community') {
1167: $warning = &mt('You do not have rights to view community request information.');
1168: } else {
1169: $warning = &mt('You do not have rights to view course request information.');
1170: }
1171: }
1172: return ($uname,$udom,$result,$warning);
1173: }
1174:
1175: sub enrollment_lcsec_js {
1176: my %alerts = §ion_check_alerts();
1177: my $secname = $alerts{'badsec'};
1178: my $secnone = $alerts{'reserved'};
1179: &js_escape(\$secname);
1180: &js_escape(\$secnone);
1181: my $output = '
1182: function validateEnrollSections(formname,nextstate) {
1183: var badsectotal = 0;
1184: var reservedtotal = 0;
1185: var secTest = "";
1186: ';
1187: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1188: $output .= "
1189: var selSec = 0;
1190: for (var j=0; j<document.requestcrs.sec_".$i.".length; j++) {
1191: if (document.requestcrs.sec_".$i."[j].checked) {
1192: selSec = document.requestcrs.sec_".$i."[j].value;
1193: }
1194: if (selSec == 1) {
1195: secTest = validsection(document.requestcrs.loncapasec_".$i.");
1196: if (secTest == 'badsec') {
1197: badsectotal++;
1198: }
1199: if (secTest == 'reserved') {
1200: reservedtotal++;
1201: }
1202: }
1203: }
1204: ";
1205: }
1206: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1207: $output .= "
1208: if (document.requestcrs.crosslist_".$i.".checked) {
1209: secTest = validsection(document.requestcrs.crosslist_".$i."_lcsec);
1210: if (secTest == 'badsec') {
1211: badsectotal++;
1212: }
1213: if (secTest == 'reserved') {
1214: reservedtotal++;
1215: }
1216: }
1217: ";
1218: }
1219: $output .= "
1220: if (badsectotal>0) {
1221: alert('$secname');
1222: return false;
1223: }
1224: if (reservedtotal>0) {
1225: alert('$secnone');
1226: return false;
1227: }
1228: formname.state.value= nextstate;
1229: formname.submit();
1230: return;
1231: }
1232: ";
1233: return $output;
1234: }
1235:
1236: sub personnel_lcsec_js {
1237: my %alerts = §ion_check_alerts();
1238: my $secname = $alerts{'badsec'}."\n".$alerts{'separate'};
1239: my $secnone = $alerts{'reserved'};
1240: &js_escape(\$secname);
1241: &js_escape(\$secnone);
1242: my $output = '
1243: function validatePersonnelSections(formname,nextstate) {
1244: var badsectotal = 0;
1245: var reservedtotal = 0;
1246: var secTest = "";
1247: ';
1248: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1249: $output .= "
1250: if (document.requestcrs.person_".$i."_uname.value != '') {
1251: secTest = validsection(document.requestcrs.person_".$i."_newsec,'1');
1252: if (secTest == 'badsec') {
1253: badsectotal++;
1254: }
1255: if (secTest == 'reserved') {
1256: reservedtotal++;
1257: }
1258: }
1259: ";
1260: }
1261: $output .= "
1262: if (badsectotal > 0) {
1263: alert('$secname');
1264: return false;
1265: } else {
1266: if (reservedtotal > 0) {
1267: alert('$secnone');
1268: return false;
1269: }
1270: }
1271: formname.state.value = nextstate;
1272: formname.submit();
1273: return;
1274: }
1275: ";
1276: return $output;
1277: }
1278:
1279: sub section_check_alerts {
1280: my %lt =
1281: &Apache::lonlocal::texthash(
1282: 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.",
1283: badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
1284: separate => 'Separate multiple sections with a comma.'
1285: );
1286: return %lt;
1287: }
1288:
1289: sub section_check_javascript {
1290: return <<"END";
1291: function validsection(field,mult) {
1292: var str = field.value;
1293: var badsec=0;
1294: var reserved=0;
1295: if (window.RegExp) {
1296: var badsecnum=0;
1297: var reservednum=0;
1298: var pattern=/[^a-zA-Z0-9]/;
1299: str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
1300: str = str.replace(/[ ]{2,}/gi," ");
1301: if (mult == '1') {
1302: var sections = new Array();
1303: sections = str.split(/\\s*[\\s,;:]\\s*/);
1304: var i;
1305: for (i=0; i<sections.length; i++) {
1306: if ((sections[i] != '') && (sections[i] != undefined) && (sections[i] != null)) {
1307: if (pattern.test(sections[i])) {
1308: badsecnum++;
1309: } else {
1310: if (sections[i] == 'none') {
1311: reservednum++;
1312: }
1313: }
1314: }
1315: }
1316: } else {
1317: if ((str != '') && (str != undefined) && (str != null)) {
1318: if (pattern.test(str)) {
1319: badsecnum++;
1320: } else {
1321: if (str == 'none') {
1322: reservednum++;
1323: }
1324: }
1325: }
1326: }
1327: if (badsecnum > 0) {
1328: return 'badsec';
1329: }
1330: if (reservednum > 0) {
1331: return 'reserved';
1332: }
1333: }
1334: return;
1335: }
1336: END
1337: }
1338:
1339: sub close_popup_form {
1340: my $close= &mt('Close Window');
1341: return << "END";
1342: <p><form name="displayreq" action="" method="post">
1343: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
1344: </form></p>
1345: END
1346: }
1347:
1348: sub get_instcode {
1349: my ($dom) = @_;
1350: my ($instcode,$numtitles);
1351: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1352: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1353: \%cat_order,\@code_order);
1354: $numtitles = scalar(@codetitles);
1355: if (@code_order > 0) {
1356: my $message;
1357: foreach my $item (@code_order) {
1358: $instcode .= $env{'form.instcode_'.$item};
1359: }
1360: }
1361: return ($instcode,$numtitles);
1362: }
1363:
1364: sub print_request_form {
1365: my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1366: $description,$showcredits,$instcredits,$invalidcrosslist) = @_;
1367: my $formname = 'requestcrs';
1368: my ($next,$prev,$message,$output,$codepicker,$crstype);
1369: $prev = $states->{$action}[$page-1];
1370: $next = $states->{$action}[$page+1];
1371: my %navtxt = &Apache::lonlocal::texthash (
1372: prev => 'Back',
1373: next => 'Next',
1374: );
1375: $crstype = $env{'form.crstype'};
1376: $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1377: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
1378: @disallowed);
1379: if ($crstype eq 'official') {
1380: if ($env{'form.instcode'} ne '') {
1381: $instcode = $env{'form.instcode'};
1382: } elsif ($newinstcode ne '') {
1383: $instcode = $newinstcode;
1384: }
1385: if ($checkedcode) {
1386: if ($codechk eq 'valid') {
1387: $message = '<div class="LC_info">'.
1388: &mt('The chosen course category [_1] is valid.','<b>'.
1389: $instcode.'</b>').
1390: '<input type="hidden" name="instcode" value="'.
1391: $instcode.'" /></div>';
1392: } else {
1393: $message = '<div class="LC_warning">'.
1394: &mt('No course was found matching your choice of institutional course category.');
1395: if ($codechk ne '') {
1396: $message .= '<br />'.$codechk;
1397: }
1398: $message .= '</div>';
1399: $prev = 'crstype';
1400: }
1401: $r->print($message);
1402: }
1403: }
1404: if ($prev eq 'crstype') {
1405: if ($crstype eq 'official') {
1406: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1407: \%cat_order,\@code_order);
1408: }
1409: if (@code_order > 0) {
1410: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
1411: \%cat_titles,\%cat_order);
1412: if ($codepicker) {
1413: $r->print(&mt('Specify the course to be created.').
1414: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1415: $codepicker.
1416: &Apache::lonhtmlcommon::end_pick_box().'</div>');
1417: } else {
1418: $next = $states->{$action}[$page+2];
1419: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1420: }
1421: } else {
1422: if ($crstype eq 'official') {
1423: $next = $states->{$action}[$page+2];
1424: }
1425: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1426: }
1427: } elsif ($prev eq 'codepick') {
1428: if ($instcode eq '') {
1429: $prev = $states->{$action}[$page-2];
1430: }
1431: $r->print(&courseinfo_form($dom,$formname,$crstype,$next,$description));
1432: } elsif ($state eq 'enrollment') {
1433: if ($crstype eq 'official') {
1434: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1435: \%cat_order,\@code_order);
1436: }
1437: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
1438: \%cat_titles,\%cat_order,\@code_order,
1439: $showcredits,$instcredits,$invalidcrosslist));
1440: } elsif ($state eq 'personnel') {
1441: $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
1442: } elsif ($state eq 'review') {
1443: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
1444: my $now = time;
1445: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1446: my $personname = $env{'form.person_'.$i.'_uname'};
1447: my $persondom = $env{'form.person_'.$i.'_dom'};
1448: if (($personname =~ /^$match_username$/) &&
1449: ($persondom =~ /^$match_domain$/)) {
1450: if (&Apache::lonnet::domain($persondom)) {
1451: my $personhome =
1452: &Apache::lonnet::homeserver($personname,$persondom);
1453: if ($personhome eq 'no_host') {
1454: if ($persondom ne $dom) {
1455: my $skipuser = 1;
1456: if ($env{'user.role.dc./'.$persondom.'/'}) {
1457: my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
1458: if (((!$start) || ($start < $now)) &&
1459: ((!$end) || ($end > $now))) {
1460: $skipuser = 0;
1461: }
1462: }
1463: if ($skipuser) {
1464: push(@disallowed,$i);
1465: $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
1466: next;
1467: }
1468: }
1469: my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules);
1470: if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) {
1471: my ($allowed,$msg,$authtype,$authparam) =
1472: &check_newuser_rules($persondom,$personname,
1473: \%alerts,\%rulematch,\%inst_results,
1474: \%curr_rules,\%got_rules);
1475: if ($allowed) {
1476: my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom);
1477: if ($usertype eq 'official') {
1478: if ($authtype eq '') {
1479: $authtype = $domdefaults{'auth_def'};
1480: $authparam = $domdefaults{'auth_arg_def'};
1481: }
1482: } elsif ($usertype eq 'unofficial') {
1483: if ($authtype eq '') {
1484: $authtype = 'internal';
1485: $authparam = '';
1486: }
1487: } else {
1488: $authtype = $domdefaults{'auth_def'};
1489: $authparam = $domdefaults{'auth_arg_def'};
1490: }
1491: if (($authtype eq '') ||
1492: (($authtype =~/^krb/) && ($authparam eq ''))) {
1493: push(@disallowed,$i);
1494: $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.','<tt>'.$personname.':'.$persondom.'</tt>');
1495: next;
1496: }
1497: if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
1498: if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
1499: $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
1500: }
1501: if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
1502: $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
1503: }
1504: if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
1505: $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
1506: }
1507: }
1508: } else {
1509: push(@disallowed,$i);
1510: $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1511: }
1512: } else {
1513: push(@disallowed,$i);
1514: $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1515: }
1516: } else {
1517: my %userenv =
1518: &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
1519: if ($env{'form.person_'.$i.'_lastname'} eq '') {
1520: $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
1521: }
1522: if ($env{'form.person_'.$i.'_firstname'} eq '') {
1523: $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
1524: }
1525: if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
1526: $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
1527: }
1528: }
1529: } elsif ($personname ne '') {
1530: push(@disallowed,$i);
1531: $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
1532: }
1533: } elsif ($personname ne '') {
1534: push(@disallowed,$i);
1535: $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
1536: }
1537: }
1538: my $cnum;
1539: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
1540: $cnum = $env{'form.origcnum'};
1541: } else {
1542: my $gentype = 'Course';
1543: if ($crstype eq 'community') {
1544: $gentype = 'Community';
1545: }
1546: $cnum = &Apache::lonnet::generate_coursenum($dom,$gentype);
1547: }
1548: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1549: \%cat_order,\@code_order);
1550: if ($crstype eq 'community') {
1551: $r->print('<h3>'.&mt('Review community request details before submission').'</h3>');
1552: } else {
1553: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>');
1554: }
1555: $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg,$instcredits).
1556: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1557: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
1558: $env{'user.domain'});
1559: my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'review',$env{'user.name'},
1560: $env{'user.domain'},$fullname,$env{'form.cdescr'});
1561: if (ref($postprocess) eq 'HASH') {
1562: if ($postprocess->{'reviewweb'}) {
1563: $r->print($postprocess->{'reviewweb'});
1564: }
1565: }
1566: if ($crstype eq 'community') {
1567: $navtxt{'next'} = &mt('Submit community request');
1568: } else {
1569: $navtxt{'next'} = &mt('Submit course request');
1570: }
1571: } elsif ($state eq 'process') {
1572: if ($crstype eq 'official') {
1573: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1574: \%cat_order,\@code_order);
1575: }
1576: my $lonhost = $r->dir_config('lonHostID');
1577: my ($storeresult,$result) = &print_request_outcome($r,$lonhost,$dom,\@codetitles,
1578: \@code_order,$instcredits);
1579: $r->print($result);
1580: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1581: if ($storeresult eq 'ok') {
1582: $r->print('<p><a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1583: &mt('Modify this request').'</a>'.(' 'x4).
1584: '<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1585: }
1586: if (&Apache::loncoursequeueadmin::author_prompt()) {
1587: &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'},
1588: $env{'form.crstype'},$storeresult);
1589: } elsif ($storeresult eq 'created') {
1590: $r->print('<p><a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1591: }
1592: }
1593: } elsif ($state eq 'reqauthor') {
1594: my ($result,@links);
1595: if ($env{'form.requestauthor'}) {
1596: $r->print(&Apache::loncoursequeueadmin::process_reqauthor(\$result));
1597: if ($result eq 'created') {
1598: my $role = 'au';
1599: my $spec = "$role./$env{'form.showdom'}/";
1600: push(@links,&mt('Enter your Authoring Space with role: [_1]',
1601: '<a href="/adm/roles?selectrole=1&'.$spec.'=1">'.
1602: &Apache::lonnet::plaintext($role).'</a>'));
1603: }
1604: }
1605: if (($env{'form.disposition'} eq 'created') &&
1606: ($env{'form.cnum'} =~ /^$match_courseid$/) &&
1607: ($env{'form.showdom'} =~ /^$match_domain$/)) {
1608: my ($spec,$area,$role,$type);
1609: my $role = 'cc';
1610: my $spec = "$role./$env{'form.showdom'}/$env{'form.cnum'}";
1611: my $type = 'Course';
1612: if ($env{'form.crstype'} eq 'community') {
1613: $type = 'Community';
1614: }
1615: my $showrole = &Apache::lonnet::plaintext($role,$type);
1616: unshift(@links,&mt('Enter new course with role: [_1]',
1617: '<a href="/adm/roles?selectrole=1&'.$spec.'=1">'.$showrole.'</a>'));
1618: }
1619: if (@links > 1) {
1620: $r->print(&mt('New roles will be listed on your [_1]Roles[_2] page.',
1621: '<a href="/adm/roles">','</a>').' '.&mt('Choose a role:').
1622: '<ul>');
1623: foreach my $link (@links) {
1624: $r->print('<li>'.$link.'</li>');
1625: }
1626: $r->print('</ul>');
1627: } elsif (@links == 1) {
1628: $r->print('<p>'.$links[0].'</p>');
1629: }
1630: }
1631: my @excluded = &get_excluded_elements($dom,$states,$action,$state,$showcredits);
1632: if ($state eq 'personnel') {
1633: push(@excluded,'persontotal');
1634: }
1635: if ($state eq 'review') {
1636: if (@disallowed > 0) {
1637: my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
1638: my @currsecs = ¤t_lc_sections();
1639: if (@currsecs) {
1640: push(@items,'sec');
1641: }
1642: my $count = 0;
1643: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1644: unless ($env{'form.person_'.$i.'_uname'} eq '') {
1645: if (grep(/^$i$/,@disallowed)) {
1646: foreach my $item (@items) {
1647: $env{'form.person_'.$i.'_'.$item} = '';
1648: }
1649: } else {
1650: foreach my $item (@items) {
1651: $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
1652: }
1653: }
1654: }
1655: $count ++;
1656: }
1657: $env{'form.persontotal'} = $count;
1658: }
1659: }
1660: if ($state eq 'enrollment') {
1661: push(@excluded,('sectotal','crosslisttotal'));
1662: }
1663: if (($state eq 'process') || ($state eq 'reqauthor')) {
1664: $r->print('</form>');
1665: } else {
1666: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1667: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1668: $navtxt{'next'},$state);
1669: }
1670: return;
1671: }
1672:
1673: sub print_author_prompt {
1674: my ($r,$action,$cnum,$showdom,$crstype,$storeresult) = @_;
1675: $r->print('<h3>'.&mt('Access to Authoring Space').'</h3>'.
1676: '<p>'.
1677: &mt('Although assessment items can be created directly inside a course, such items only use part of the assessment capabilities of LON-CAPA.').
1678: '<br />'.
1679: &mt('By contrast, items created in Authoring Space, then imported into a course, can use all of the features of the assessment engine.').'</p>'.
1680: '<p>'.&mt('Request Authoring Space access now?').
1681: '<span class="LC_nobreak"> '.
1682: '<label><input type="radio" name="requestauthor" value="1" />'.&mt('Yes').'</label>'.
1683: (' 'x2).
1684: '<label><input type="radio" name="requestauthor" value="0" checked="checked"/>'.&mt('No').'</label>'.
1685: '</span></p>'.
1686: '<input type="submit" name="newauthor" value="'.&mt('Submit authoring request').'" />'.
1687: '<input type="hidden" name="state" value="reqauthor" />'.
1688: '<input type="hidden" name="action" value="'.$action.'" />'.
1689: '<input type="hidden" name="cnum" value="'.$cnum.'" />'.
1690: '<input type="hidden" name="showdom" value="'.$showdom.'" />'.
1691: '<input type="hidden" name="crstype" value="'.$crstype.'" />'.
1692: '<input type="hidden" name="disposition" value="'.$storeresult.'" />'.
1693: '<br />');
1694: }
1695:
1696: sub get_usertype {
1697: my ($persondom,$personname,$curr_rules,$got_rules) = @_;
1698: my ($rules,$ruleorder) =
1699: &Apache::lonnet::inst_userrules($persondom,'username');
1700: my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1701: $rules,$curr_rules,$got_rules);
1702: return $usertype;
1703: }
1704:
1705: sub check_newuser_rules {
1706: my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
1707: $got_rules) = @_;
1708: my $allowed = 1;
1709: my $newuser = 1;
1710: my ($checkhash,$userchkmsg,$authtype,$authparam);
1711: my $checks = { 'username' => 1 };
1712: $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
1713: &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
1714: $inst_results,$curr_rules,$got_rules);
1715: if (ref($alerts->{'username'}) eq 'HASH') {
1716: if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
1717: my $domdesc =
1718: &Apache::lonnet::domain($persondom,'description');
1719: if ($alerts->{'username'}{$persondom}{$personname}) {
1720: if (ref($curr_rules->{$persondom}) eq 'HASH') {
1721: $userchkmsg =
1722: &Apache::loncommon::instrule_disallow_msg('username',
1723: $domdesc,1).
1724: &Apache::loncommon::user_rule_formats($persondom,
1725: $domdesc,$curr_rules->{$persondom}{'username'},
1726: 'username');
1727: }
1728: $allowed = 0;
1729: }
1730: }
1731: }
1732: if ($allowed) {
1733: if (ref($rulematch) eq 'HASH') {
1734: if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') {
1735: my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'};
1736: my ($rules,$ruleorder) =
1737: &Apache::lonnet::inst_userrules($persondom,'username');
1738: if (ref($rules) eq 'HASH') {
1739: if (ref($rules->{$matchedrule}) eq 'HASH') {
1740: $authtype = $rules->{$matchedrule}{'authtype'};
1741: $authparam = $rules->{$matchedrule}{'authparm'};
1742: }
1743: }
1744: }
1745: }
1746: }
1747: return ($allowed,$userchkmsg,$authtype,$authparam);
1748: }
1749:
1750: sub get_excluded_elements {
1751: my ($dom,$states,$action,$state,$showcredits) = @_;
1752: my @excluded = ('counter');
1753: my ($elements,$instcredits) = &form_elements($dom,$showcredits);
1754: if (ref($states) eq 'HASH') {
1755: if (ref($states->{$action}) eq 'ARRAY') {
1756: my @items = @{$states->{$action}};
1757: my $numitems = scalar(@items);
1758: if ($numitems) {
1759: for (my $i=$numitems-1; $i>=0; $i--) {
1760: if ((ref($elements) eq 'HASH') &&
1761: (ref($elements->{$action}) eq 'HASH')) {
1762: if (ref($elements->{$action}{$items[$i]}) eq 'HASH') {
1763: foreach my $key (keys(%{$elements->{$action}{$items[$i]}})) {
1764: push(@excluded,$key);
1765: }
1766: }
1767: }
1768: last if ($items[$i] eq $state);
1769: }
1770: }
1771: }
1772: }
1773: if (grep(/^instcode_/,@excluded)) {
1774: push(@excluded,'instcode');
1775: }
1776: return @excluded;
1777: }
1778:
1779: sub print_enrollment_menu {
1780: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1781: $showcredits,$instcredits,$invalidcrosslist) =@_;
1782: my ($sections,$autoenroll,$access_dates,$output,$hasauto,$hascredits,
1783: $creditsrow,$domdefcredits);
1784: my $starttime = time;
1785: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1786:
1787: my %accesstitles = (
1788: 'start' => 'Default start access',
1789: 'end' => 'Default end access',
1790: );
1791: my %enrolltitles = (
1792: 'start' => 'Start auto-enrollment',
1793: 'end' => 'End auto-enrollment',
1794: );
1795: if ($showcredits) {
1796: unless ($env{'form.crstype'} eq 'community') {
1797: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1798: $domdefcredits = $domdefs{$env{'form.crstype'}.'credits'};
1799: }
1800: }
1801: if ($env{'form.crstype'} eq 'official') {
1802: if (&Apache::lonnet::auto_run('',$dom)) {
1803: $output = &show_invalid_crosslists($invalidcrosslist);
1804: my ($section_form,$crosslist_form);
1805: if ($instcode ne '') {
1806: $section_form = &inst_section_selector($dom,$instcode);
1807: if ($section_form eq '') {
1808: my $sectotal = $env{'form.sectotal'};
1809: if (!$sectotal) {
1810: $sectotal = 1;
1811: }
1812: if ($env{'form.addsection'}) {
1813: $sectotal ++;
1814: }
1815: for (my $i=0; $i<$sectotal; $i++) {
1816: $section_form .= §ions_form($dom,$instcode,$i);
1817: }
1818: if ($section_form) {
1819: $section_form .=
1820: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1821: '<input name="sectotal" type="hidden" value="'.$sectotal.'" />'.
1822: '<input name="addsection" type="checkbox" value="'.$sectotal.'"'.
1823: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1824: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1825: }
1826: }
1827: }
1828: if ($section_form) {
1829: $sections = &Apache::lonhtmlcommon::row_headline().
1830: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
1831: ' '.&mt('Sections for auto-enrollment').'</h3>'.
1832: &Apache::lonhtmlcommon::row_closure(1).
1833: $section_form;
1834: }
1835: my $crosslisttotal = $env{'form.crosslisttotal'};
1836: if (!$crosslisttotal) {
1837: $crosslisttotal = 1;
1838: }
1839: if ($env{'form.addcrosslist'}) {
1840: $crosslisttotal ++;
1841: }
1842: for (my $i=0; $i<$crosslisttotal; $i++) {
1843: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1844: $cat_titles,$cat_order,$i);
1845: }
1846: if ($crosslist_form) {
1847: $crosslist_form .=
1848: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1849: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1850: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1851: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1852: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1853: $sections .= &Apache::lonhtmlcommon::row_headline.
1854: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Crosslist').' '.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1855: &Apache::lonhtmlcommon::row_closure(1).
1856: $crosslist_form;
1857: }
1858: $hasauto = 1;
1859: $autoenroll =
1860: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')).
1861: '<span class="LC_nobreak"><label>'.
1862: '<input type="radio" name="autoadds" value="1">'.
1863: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1864: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1865: &mt('No').'</label></span>'.
1866: &Apache::lonhtmlcommon::row_closure(1).
1867: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')).
1868: '<span class="LC_nobreak"><label>'.
1869: '<input type="radio" name="autodrops" value="1">'.
1870: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1871: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1872: &mt('No').'</label></span>'.
1873: &Apache::lonhtmlcommon::row_closure(1).
1874: &date_setting_table($starttime,$endtime,$formname,'enroll',
1875: $hasauto,undef,%enrolltitles);
1876: if ($showcredits) {
1877: if ($instcredits) {
1878: $creditsrow = &mt('[quant,_1,credit]',$instcredits);
1879: } else {
1880: $creditsrow = '<span class="LC_nobreak">'.
1881: '<input type="text" size="3" name="coursecredits"'.
1882: ' value="'.$domdefcredits.'" />';
1883: }
1884: $hascredits = 1;
1885: }
1886: }
1887: } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
1888: if ($showcredits) {
1889: $creditsrow = '<span class="LC_nobreak">'.
1890: '<input type="text" size="3" name="coursecredits"'.
1891: ' value="'.$domdefcredits.'"/>';
1892: $hascredits = 1;
1893: }
1894: }
1895: my $access_dates =
1896: &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
1897: $hascredits,%accesstitles);
1898: $output .= &Apache::lonhtmlcommon::start_pick_box();
1899: if ($sections) {
1900: $output .= $sections;
1901: }
1902: if ($autoenroll) {
1903: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1904: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1905: &Apache::lonhtmlcommon::row_closure(1).
1906: $autoenroll;
1907: }
1908: if ($access_dates) {
1909: my $header = &mt('Access dates for students');
1910: if ($env{'form.crstype'} eq 'community') {
1911: $header = &mt('Access dates for community members');
1912: }
1913: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1914: '<h3>'.$header.'</h3>'.
1915: &Apache::lonhtmlcommon::row_closure(1).
1916: $access_dates;
1917: }
1918: if ($creditsrow) {
1919: $output .= &Apache::lonhtmlcommon::row_headline('Credits').
1920: '<h3>'.&mt('Credits earned by students').'</h3>'.
1921: &Apache::lonhtmlcommon::row_closure(1).
1922: &Apache::lonhtmlcommon::row_title(&mt('Default credits')).
1923: $creditsrow.
1924: &Apache::lonhtmlcommon::row_closure(1);
1925: }
1926: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1927: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1928: }
1929:
1930: sub show_invalid_crosslists {
1931: my ($invalidcrosslist) = @_;
1932: my $output;
1933: if (ref($invalidcrosslist) eq 'ARRAY') {
1934: if (@{$invalidcrosslist} > 0) {
1935: $output = '<div class="LC_warning">'.
1936: &mt('The following crosslisted courses were invalid:').'<ul>';
1937: foreach my $item (@{$invalidcrosslist}) {
1938: $output .= '<li>'.$item.'</li>';
1939: }
1940: $output .= '</ul></div><br />';
1941: }
1942: }
1943: return $output;
1944: }
1945:
1946:
1947: sub inst_section_selector {
1948: my ($dom,$instcode) = @_;
1949: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1950: my $sectotal = scalar(@sections);
1951: my $output;
1952: if ($sectotal) {
1953: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1954: &Apache::loncommon::start_data_table().
1955: &Apache::loncommon::start_data_table_row().
1956: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1957: 'value="'.$sectotal.'" /></th>'.
1958: '<th>'.&mt('Institutional Section').'</th>'.
1959: '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
1960: ' '.&mt('LON-CAPA section').'</th>'.
1961: &Apache::loncommon::end_data_table_row();
1962: for (my $i=0; $i<@sections; $i++) {
1963: my $colflag = $i%2;
1964: my $secon = ' checked="checked"';
1965: my $secoff = '';
1966: if ($env{'form.origcnum'}) {
1967: $secoff = $secon;
1968: $secon='';
1969: }
1970: $output .= &Apache::loncommon::start_data_table_row().
1971: '<td><label><input type="radio" name="sec_'.$i.
1972: '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
1973: (' 'x2).'<label><input type="radio" name="sec_'.$i.
1974: '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
1975: '<td align="center">'.$sections[$i].
1976: '<input type="hidden" name="secnum_'.$i.'" value="'.
1977: $sections[$i].'" /></td>'.
1978: '<td><input type="text" size="10" name="loncapasec_'.$i.
1979: '" value="'.$sections[$i].'" /></td>'.
1980: &Apache::loncommon::end_data_table_row();
1981: }
1982: $output .= &Apache::loncommon::end_data_table().
1983: &Apache::lonhtmlcommon::row_closure();
1984: }
1985: return $output;
1986: }
1987:
1988: sub date_setting_table {
1989: my ($starttime,$endtime,$formname,$prefix,$hasauto,$hascredits,%datetitles)=@_;
1990: my ($perpetual,$table);
1991: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1992: $starttime,'','','',1,'','','',1);
1993: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1994: $endtime,'','','',1,'','','',1);
1995: my $closure = '';
1996: if ($prefix eq 'access') {
1997: $perpetual = ' <span class="LC_nobreak"><label>'.
1998: '<input type="checkbox" name="no_end_date" />'.
1999: &mt('No end date').'</label></span>';
2000: unless ($hascredits) {
2001: $closure = '1';
2002: }
2003: }
2004:
2005: my %help_item = (
2006: access => {
2007: start => 'Course_Request_Access_Start',
2008: end => 'Course_Request_Access_End',
2009: },
2010: enroll => {
2011: start => 'Course_Request_Enroll_Start',
2012: end => 'Course_Request_Enroll_End',
2013: },
2014: );
2015: if ($hasauto) {
2016: $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
2017: $help_item{'access'}{'end'} = 'Course_Request_RegAccess_End';
2018: }
2019:
2020: $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
2021: ' '.&mt($datetitles{'start'})).$startform.
2022: &Apache::lonhtmlcommon::row_closure(1).
2023: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
2024: ' '.&mt($datetitles{'end'})).$endform.$perpetual.
2025: &Apache::lonhtmlcommon::row_closure($closure);
2026: return $table;
2027: }
2028:
2029: sub print_personnel_menu {
2030: my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
2031: my $output;
2032: if ($crstype eq 'official') {
2033: if (&Apache::lonnet::auto_run('',$dom)) {
2034: $output .= &show_invalid_crosslists($invalidcrosslist);
2035: }
2036: }
2037: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
2038: my $persontotal = $env{'form.persontotal'};
2039: if ((!defined($persontotal)) || (!$persontotal)) {
2040: $persontotal = 1;
2041: }
2042: if ($env{'form.addperson'}) {
2043: $persontotal ++;
2044: }
2045: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
2046:
2047: my $type = 'Course';
2048: if ($crstype eq 'community') {
2049: $type = 'Community';
2050: }
2051: my $roleoptions;
2052: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
2053: foreach my $role (@roles) {
2054: my $plrole = &Apache::lonnet::plaintext($role,$type);
2055: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
2056: }
2057: my %customroles=&Apache::lonuserutils::my_custom_roles();
2058: if (keys(%customroles) > 0) {
2059: foreach my $cust (sort(keys(%customroles))) {
2060: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
2061: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
2062: }
2063: }
2064:
2065: my @currsecs = ¤t_lc_sections();
2066:
2067: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
2068: if (@currsecs) {
2069: my $existsize = scalar(@currsecs);
2070: if ($existsize > 3) {
2071: $existsize = 3;
2072: }
2073: if ($existsize > 1) {
2074: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
2075: }
2076: @currsecs = sort { $a <=> $b } (@currsecs);
2077: $existtitle = &mt('Official').': ';
2078: $existops = '<option value="">'.&mt('None').'</option>';
2079: foreach my $sec (@currsecs) {
2080: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
2081: }
2082: $seccolspan = ' colspan="2"';
2083: $newtitle = &mt('Other').': ';
2084: }
2085:
2086: if ($persontotal) {
2087: my %lt = &Apache::lonlocal::texthash(
2088: community => 'Requestor is automatically assigned Coordinator role.',
2089: official => 'Requestor is automatically assigned Course Coordinator role.',
2090: );
2091: $lt{'unofficial'} = $lt{'official'};
2092: $lt{'textbook'} = $lt{'textbook'};
2093: $output .= &Apache::lonhtmlcommon::row_headline().
2094: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
2095: }
2096: for (my $i=0; $i<$persontotal; $i++) {
2097: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
2098: my $linkargstr = join("','",@linkargs);
2099: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
2100: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
2101: "'person_".$i."_hidedom','person_".$i."_uname'".');';
2102: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
2103: 1,$onchange).
2104: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
2105: my %form_elems;
2106: foreach my $item (@items) {
2107: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
2108: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
2109: 'value="" readonly="readonly" />';
2110: }
2111: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
2112: $roleoptions.'</select>';
2113: my $sectionselector;
2114: if (@currsecs) {
2115: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
2116: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
2117: }
2118: $sectionselector .= $newtitle.
2119: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
2120: my $usersrchlinktxt = &mt('Search for user');
2121: my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
2122: $usersrchlinktxt);
2123: my $userchklinktxt = &mt('Check username');
2124: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
2125: $userchklinktxt,'checkusername');
2126: $output .=
2127: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
2128: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
2129: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
2130: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
2131: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
2132: '</tr>'."\n".'<tr>'.
2133: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
2134: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
2135: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
2136: '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
2137: '<td'.$seccolspan.' align="center" valign="top">'.
2138: &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
2139: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
2140: }
2141: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another')).
2142: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
2143: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
2144: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
2145: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
2146: &Apache::lonhtmlcommon::end_pick_box().'</div>';
2147: if ($crstype eq 'community') {
2148: $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>';
2149: } else {
2150: $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>';
2151: }
2152: return $output;
2153: }
2154:
2155: sub current_lc_sections {
2156: my @currsecs;
2157: if ($env{'form.sectotal'}) {
2158: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2159: if ($env{'form.sec_'.$i}) {
2160: if (defined($env{'form.loncapasec_'.$i})) {
2161: my $lcsec = $env{'form.loncapasec_'.$i};
2162: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
2163: push(@currsecs,$lcsec);
2164: }
2165: }
2166: }
2167: }
2168: }
2169: return @currsecs;
2170: }
2171:
2172: sub sorted_request_history {
2173: my ($dom,$action,$curr_req) = @_;
2174: my ($after,$before,$statusfilter,$crstypefilter);
2175: if ($env{'form.status'} ne '') {
2176: $statusfilter = $env{'form.status'};
2177: }
2178: if ($env{'form.crstype'} ne '') {
2179: $crstypefilter = $env{'form.crstype'};
2180: }
2181: if (ref($curr_req) eq 'HASH') {
2182: $after = $curr_req->{'requested_after_date'},
2183: $before = $curr_req->{'requested_before_date'};
2184: $statusfilter = $curr_req->{'status'};
2185: $crstypefilter = $curr_req->{'crstype'};
2186: }
2187: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
2188: $env{'user.name'},'^status:'.$dom);
2189: my %queue_by_date;
2190: my ($types,$typenames) = &Apache::loncommon::course_types();
2191: foreach my $key (keys(%statusinfo)) {
2192: if ($action eq 'view') {
2193: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
2194: } else {
2195: next unless (($statusfilter eq 'any') ||
2196: ($statusfilter eq $statusinfo{$key}));
2197: }
2198: (undef,my($cdom,$cnum)) = split(':',$key);
2199: next if ($cdom ne $dom);
2200: my $requestkey = $cdom.'_'.$cnum;
2201: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2202: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2203: $env{'user.domain'},$env{'user.name'});
2204: my $entry;
2205: my $reqtime = $history{'reqtime'};
2206: my $lastupdate = $history{'timestamp'};
2207: my $crstype = $history{'crstype'};
2208: my $disposition = $history{'disposition'};
2209: my $status = $history{'status'};
2210: my $uniquecode = $history{'code'};
2211: if ($action eq 'view') {
2212: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
2213: } else {
2214: next if (($reqtime < $after) || ($reqtime > $before));
2215: }
2216: next unless (($crstypefilter eq 'any') ||
2217: ($crstypefilter eq $crstype));
2218: if ($action eq 'view') {
2219: next unless (($disposition eq 'approval') ||
2220: ($disposition eq 'pending'));
2221: }
2222: if (ref($history{'details'}) eq 'HASH') {
2223: $entry = $requestkey.':'.$crstype.':'.
2224: &escape($history{'details'}{'cdescr'});
2225: if ($action eq 'log') {
2226: $entry .= ':'.$uniquecode.':'.$lastupdate.':';
2227: if ($statusinfo{$key} ne '') {
2228: $entry .= $statusinfo{$key};
2229: } elsif ($status ne '') {
2230: $entry .= $status;
2231: } else {
2232: $entry .= $disposition;
2233: }
2234: }
2235: if ($crstype eq 'official') {
2236: $entry .= ':'.&escape($history{'details'}{'instcode'});
2237: }
2238: }
2239: if ($entry ne '') {
2240: if (exists($queue_by_date{$reqtime})) {
2241: if (ref($queue_by_date{$reqtime}) eq 'ARRAY') {
2242: push(@{$queue_by_date{$reqtime}},$entry);
2243: }
2244: } else {
2245: @{$queue_by_date{$reqtime}} = ($entry);
2246: }
2247: }
2248: }
2249: }
2250: return %queue_by_date;
2251: }
2252:
2253: sub print_request_status {
2254: my ($dom,$action) = @_;
2255: my %queue_by_date = &sorted_request_history($dom,$action);
2256: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
2257: my $formname = 'requestcrs';
2258: my ($types,$typenames) = &Apache::loncommon::course_types();
2259: my $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
2260:
2261: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
2262: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
2263: '<input type="hidden" name="showdom" value="" />'."\n".
2264: '<input type="hidden" name="cnum" value="" />'."\n";
2265: if (@sortedtimes > 0) {
2266: my $desctitle;
2267: if ($env{'form.crstype'} eq 'any') {
2268: $desctitle = &mt('Course/Community Description')
2269: } elsif ($env{'form.crstype'} eq 'community') {
2270: $desctitle = &mt('Community Description')
2271: } else {
2272: $desctitle = &mt('Course Description');
2273: }
2274: $output .= &Apache::loncommon::start_data_table().
2275: &Apache::loncommon::start_data_table_header_row().
2276: '<th>'.&mt('Action').'</th>'.
2277: '<th>'.$desctitle.'</th>'.
2278: '<th>'.&mt('Domain').'</th>';
2279: if ($env{'form.crstype'} eq 'any') {
2280: $output .= '<th>'.&mt('Type').'</th>';
2281: }
2282: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
2283: $output .= '<th>'.&mt('Institutional Code').'</th>';
2284: }
2285: $output .= '<th>'.&mt('Date requested').'</th>'.
2286: &Apache::loncommon::end_data_table_header_row();
2287: my $count = 0;
2288: foreach my $item (@sortedtimes) {
2289: my $showtime = &Apache::lonlocal::locallocaltime($item);
2290: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2291: foreach my $request (sort(@{$queue_by_date{$item}})) {
2292: my ($key,$type,$desc,$instcode) = split(':',$request);
2293: my ($cdom,$cnum) = split('_',$key);
2294: $output .= &Apache::loncommon::start_data_table_row().
2295: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
2296: '<td>'.&unescape($desc).'</td>'.
2297: '<td>'.$cdom.'</td>';
2298: if ($env{'form.crstype'} eq 'any') {
2299: my $typename;
2300: if (ref($typenames) eq 'HASH') {
2301: $typename = &mt($typenames->{$type});
2302: }
2303: if ($typename eq '') {
2304: $typename = &mt('Unknown type');
2305: }
2306: $output .= '<td>'.$typename.'</td>';
2307: }
2308: if (($env{'form.crstype'} eq 'any') ||
2309: ($env{'form.crstype'} eq 'official')) {
2310: my $showinstcode;
2311: if ($type eq 'official') {
2312: $showinstcode = &unescape($instcode);
2313: } else {
2314: $showinstcode = &mt('Not applicable');
2315: }
2316: $output .= '<td>'.$showinstcode.'</td>';
2317: }
2318: $output .= '<td>'.$showtime.'</td>'.
2319: &Apache::loncommon::end_data_table_row();
2320: }
2321: }
2322: }
2323: $output .= &Apache::loncommon::end_data_table();
2324: } else {
2325: if ($env{'form.crstype'} eq 'any') {
2326: $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>';
2327: } elsif ($env{'form.crstype'} eq 'community') {
2328: $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>';
2329: } else {
2330: $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>';
2331: }
2332: }
2333: $output .= '
2334: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
2335: return $output;
2336: }
2337:
2338: sub print_cancel_request {
2339: my ($dom,$cnum) = @_;
2340: my $requestkey = $dom.'_'.$cnum;
2341: my ($result,$output);
2342: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2343: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2344: $env{'user.domain'},$env{'user.name'});
2345: my $timestamp = $history{'reqtime'};
2346: my $crstype = $history{'crstype'};
2347: my $status = $history{'status'};
2348: if (($status eq 'cancelled') || ($status eq 'created')) {
2349: if ($status eq 'cancelled') {
2350: $output = &mt('This request has already been cancelled.');
2351: } elsif ($status eq 'created') {
2352: $output = &mt('This request has already been processed, and a course created.');
2353: }
2354: $output = &mt('No further action will be taken');
2355: } elsif (ref($history{'details'}) eq 'HASH') {
2356: my ($types,$typename) = &Apache::loncommon::course_types();
2357: my $showtype = $crstype;
2358: if (defined($typename->{$crstype})) {
2359: $showtype = $typename->{$crstype};
2360: }
2361: $output = '<p>'.&Apache::loncommon::start_data_table().
2362: &Apache::loncommon::start_data_table_header_row().
2363: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
2364: '<th>'.&mt('Type').'</th>'.
2365: &Apache::loncommon::end_data_table_header_row().
2366: &Apache::loncommon::start_data_table_row().
2367: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
2368: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
2369: '<td>'.$showtype.'</td>'.
2370: &Apache::loncommon::end_data_table_row().
2371: &Apache::loncommon::end_data_table().
2372: '<br /><div class="LC_warning">';
2373: if ($crstype eq 'community') {
2374: $output .= &mt('Cancelling the request will remove it from the queue of pending community requests').'</div>';
2375: } else {
2376: $output .= &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
2377: }
2378: $result = 'ok';
2379: } else {
2380: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
2381: }
2382: } else {
2383: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
2384: }
2385: return ($result,$output);
2386: }
2387:
2388: sub viewrequest_javascript {
2389: my ($formname,$next) = @_;
2390: return <<"ENDJS";
2391:
2392: function chooseRequest(cdom,cnum) {
2393: document.$formname.showdom.value = cdom;
2394: document.$formname.cnum.value = cnum;
2395: nextPage(document.$formname,'$next');
2396: }
2397:
2398: ENDJS
2399: }
2400:
2401: sub viewdetails_javascript {
2402: my ($formname) = @_;
2403: return << "ENDJS";
2404:
2405: function nextPage(formname,nextstate) {
2406: if (nextstate == "modify") {
2407: formname.state.value = "personnel";
2408: formname.action.value = "new";
2409: } else {
2410: formname.state.value = nextstate;
2411: }
2412: formname.submit();
2413: }
2414:
2415: function backPage(formname,prevstate) {
2416: formname.state.value = prevstate;
2417: formname.submit();
2418: }
2419:
2420: ENDJS
2421: }
2422:
2423: sub viewcancel_javascript {
2424: my $alert = &mt('Are you sure you want to cancel this request?')."\n".
2425: &mt('Your request will be removed.');
2426: &js_escape(\$alert);
2427: return << "ENDJS";
2428: function nextPage(formname,nextstate) {
2429: if (confirm('$alert')) {
2430: formname.state.value = nextstate;
2431: formname.submit();
2432: }
2433: return;
2434: }
2435:
2436: ENDJS
2437: }
2438:
2439: sub print_request_logs {
2440: my ($r,$dom,$jscript,$loaditems,$crumb,$usetabs) = @_;
2441: my $title;
2442: if ($env{'form.crstype'} eq 'community') {
2443: $title = 'Community Request Logs';
2444: } elsif ($env{'form.crstype'} eq 'any') {
2445: $title = 'Course/Community Request Logs';
2446: } else {
2447: $title = 'Course Request Logs';
2448: }
2449: $r->print(&header($title,$jscript,$loaditems).$crumb);
2450: if ($usetabs) {
2451: &startContentScreen($r,'textbooklogs');
2452: }
2453: my $formname = 'requestcrs';
2454: $r->print('<form action="/adm/requestcourse" method="post" name="'.$formname.'" onsubmit="javascript:setPage(this);">'."\n".
2455: '<input type="hidden" name="action" value="log" />'."\n".
2456: '<input type="hidden" name="state" value="display" />'."\n");
2457: # set defaults
2458: my $now = time();
2459: my $defstart = $now - (7*24*3600); #7 days ago
2460: my %defaults = (
2461: page => '1',
2462: show => '10',
2463: crstype => 'any',
2464: status => 'any',
2465: requested_before_date => $now,
2466: requested_after_date => $defstart,
2467: );
2468: my ($types,$typenames) = &Apache::loncommon::course_types();
2469: my $more_records = 0;
2470: my %curr;
2471: foreach my $item ('show','page','crstype','status') {
2472: $curr{$item} = $env{'form.'.$item};
2473: }
2474: $curr{'requested_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_after_date');
2475: $curr{'requested_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_before_date');
2476: foreach my $key (keys(%defaults)) {
2477: if ($curr{$key} eq '') {
2478: $curr{$key} = $defaults{$key};
2479: }
2480: }
2481: my ($statuses,$statusnames) = &reqstatus_names($curr{'crstype'});
2482: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
2483: &requestlog_display_filter($formname,\%curr));
2484: my %queue_by_date = &sorted_request_history($dom,$env{'form.action'},\%curr);
2485: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
2486: my $showntablehdr = 0;
2487: my $tablehdr = &Apache::loncommon::start_data_table().
2488: &Apache::loncommon::start_data_table_header_row().
2489: '<th> </th><th>'.&mt('Request Date').'</th>'.
2490: '<th>'.&mt('Description').'</th>';
2491: if ($curr{'crstype'} eq 'any') {
2492: $tablehdr .= '<th>'.&mt('Course Type').'</th>';
2493: }
2494: if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) {
2495: $tablehdr .= '<th>'.&mt('Institutional Code').'</th>';
2496: }
2497: my $showuniquecode;
2498: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
2499: if (($curr{'status'} eq 'any') || ($curr{'status'} eq 'created')) {
2500: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2501: if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
2502: if ($curr{'crstype'} eq 'any') {
2503: my @types = qw(official unofficial community textbook);
2504: foreach my $type (@types) {
2505: if ($domconfig{'requestcourses'}{'uniquecode'}{$type}) {
2506: $showuniquecode = 1;
2507: last;
2508: }
2509: }
2510: } elsif ($domconfig{'requestcourses'}{'uniquecode'}{$curr{'crstype'}}) {
2511: $showuniquecode = 1;
2512: }
2513: }
2514: }
2515: }
2516: if ($showuniquecode) {
2517: $tablehdr .= '<th>'.&mt('Unique Code').'</th>';
2518: }
2519: if ($curr{'status'} eq 'any') {
2520: $tablehdr .= '<th>'.&mt('Status').'</th>';
2521: } elsif ($curr{'status'} eq 'created') {
2522: $tablehdr .= '<th>'.&mt('Creation Date').'</th>';
2523: } elsif ($curr{'status'} eq 'cancelled') {
2524: $tablehdr .= '<th>'.&mt('Cancellation Date').'</th>';
2525: } elsif ($curr{'status'} eq 'rejected') {
2526: $tablehdr .= '<th>'.&mt('Rejection Date').'</th>';
2527: }
2528: $tablehdr .= &Apache::loncommon::end_data_table_header_row();
2529: my ($minshown,$maxshown);
2530: $minshown = 1;
2531: my $count = 0;
2532: if ($curr{'show'} ne &mt('all')) {
2533: $maxshown = $curr{'page'} * $curr{'show'};
2534: if ($curr{'page'} > 1) {
2535: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
2536: }
2537: }
2538: my $norecords;
2539: if (@sortedtimes > 0) {
2540: foreach my $item (@sortedtimes) {
2541: if ($curr{'show'} ne &mt('all')) {
2542: if ($count >= $curr{'page'} * $curr{'show'}) {
2543: $more_records = 1;
2544: last;
2545: }
2546: }
2547: $count ++;
2548: next if ($count < $minshown);
2549: if (!$showntablehdr) {
2550: $r->print($tablehdr);
2551: $showntablehdr = 1;
2552: }
2553: my $showtime = &Apache::lonlocal::locallocaltime($item);
2554: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2555: foreach my $request (sort(@{$queue_by_date{$item}})) {
2556: my ($key,$crstype,$desc,$uniquecode,$timestamp,$status,$instcode) = split(':',$request);
2557: my ($cdom,$cnum) = split('_',$key);
2558: my $output = &Apache::loncommon::start_data_table_row().
2559: '<td>'.$count.'</td>'.
2560: '<td>'.$showtime.'</td>'.
2561: '<td>'.&unescape($desc).'</td>';
2562: if ($curr{'crstype'} eq 'any') {
2563: my $typename;
2564: if (ref($typenames) eq 'HASH') {
2565: $typename = &mt($typenames->{$crstype});
2566: }
2567: if ($typename eq '') {
2568: $typename = &mt('Unknown type');
2569: }
2570: $output .= '<td>'.$typename.'</td>';
2571: }
2572: if (($curr{'crstype'} eq 'any') ||
2573: ($curr{'crstype'} eq 'official')) {
2574: my $showinstcode;
2575: if ($crstype eq 'official') {
2576: $showinstcode = &unescape($instcode);
2577: } else {
2578: $showinstcode = &mt('Not applicable');
2579: }
2580: $output .= '<td>'.$showinstcode.'</td>';
2581: }
2582: if ($showuniquecode) {
2583: if ($status eq 'created') {
2584: $output .= '<td>'.$uniquecode.'</td>';
2585: } else {
2586: $output .= '<td>'.&mt('Not applicable').'</td>';
2587: }
2588: }
2589: if ($curr{'status'} eq 'any') {
2590: my $statusname = &mt('Unknown status');
2591: if (ref($statusnames) eq 'HASH') {
2592: if ($statusnames->{$status} ne '') {
2593: $statusname = $statusnames->{$status};
2594: }
2595: }
2596: if (($status eq 'created') || ($status eq 'cancelled') ||
2597: ($status eq 'rejected')) {
2598: $statusname .= ' '.&Apache::lonlocal::locallocaltime($timestamp);
2599: }
2600: $output .= '<td>'.$statusname.'</td>';
2601: } elsif (($status eq 'created') || ($status eq 'cancelled') ||
2602: ($status eq 'rejected')) {
2603: $output .= '<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>';
2604: }
2605: $output .= &Apache::loncommon::end_data_table_row();
2606: $r->print($output);
2607: }
2608: }
2609: }
2610: if ($showntablehdr) {
2611: $r->print(&Apache::loncommon::end_data_table());
2612: if (($curr{'page'} > 1) || ($more_records)) {
2613: $r->print('<table><tr>');
2614: if ($curr{'page'} > 1) {
2615: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
2616: }
2617: if ($more_records) {
2618: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
2619: }
2620: $r->print('</tr></table>');
2621: $r->print(<<"ENDSCRIPT");
2622: <script type="text/javascript">
2623: // <![CDATA[
2624: function chgPage(caller) {
2625: if (caller == 'previous') {
2626: document.$formname.page.value --;
2627: }
2628: if (caller == 'next') {
2629: document.$formname.page.value ++;
2630: }
2631: document.$formname.submit();
2632: return;
2633: }
2634: // ]]>
2635: </script>
2636: ENDSCRIPT
2637: }
2638: } else {
2639: $norecords = 1;
2640: }
2641: } else {
2642: $norecords = 1;
2643: }
2644: if ($norecords) {
2645: $r->print('<p class="LC_info">'.
2646: &mt('There are no records to display').
2647: '</p>');
2648: }
2649: if ($usetabs) {
2650: $r->print('<input type="hidden" name="tabs" value="on" />');
2651: }
2652: $r->print('</form>');
2653: if ($usetabs) {
2654: &endContentScreen($r);
2655: }
2656: $r->print(&Apache::loncommon::end_page());
2657: return;
2658: }
2659:
2660: sub reqstatus_names {
2661: my ($crstype) = @_;
2662: my @statuses = qw(created approval pending rejected cancelled);
2663: my %statusnames =
2664: &Apache::lonlocal::texthash (
2665: created => 'Created',
2666: approval => 'Queued pending approval',
2667: pending => 'Queued pending validation',
2668: rejected => 'Request rejected',
2669: cancelled => 'Request cancelled',
2670: );
2671: if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook')) {
2672: $statusnames{'created'} = &mt('Course created');
2673: } elsif ($crstype eq 'community') {
2674: $statusnames{'created'} = &mt('Community created');
2675: }
2676: return (\@statuses,\%statusnames);
2677: }
2678:
2679: sub requestlog_display_filter {
2680: my ($formname,$curr) = @_;
2681: my $nolink = 1;
2682: my $output = '<table><tr><td valign="top">'.
2683: '<span class="LC_nobreak"><b>'.&mt('Records/page:').'</b></span><br />'.
2684: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
2685: (&mt('all'),5,10,20,50,100,1000,10000)).
2686: '</td><td> </td>';
2687: my $startform =
2688: &Apache::lonhtmlcommon::date_setter($formname,'requested_after_date',
2689: $curr->{'requested_after_date'},undef,
2690: undef,undef,undef,undef,undef,undef,$nolink);
2691: my $endform =
2692: &Apache::lonhtmlcommon::date_setter($formname,'requested_before_date',
2693: $curr->{'requested_before_date'},undef,
2694: undef,undef,undef,undef,undef,undef,$nolink);
2695: $output .= '<td valign="top"><b>'.&mt('Window during which course/community was requested:').'</b><br />'.
2696: '<table><tr><td>'.&mt('After:').
2697: '</td><td>'.$startform.'</td></tr>'.
2698: '<tr><td>'.&mt('Before:').'</td>'.
2699: '<td>'.$endform.'</td></tr></table>'.
2700: '</td>'.
2701: '<td> </td>';
2702: my ($types,$typenames) = &Apache::loncommon::course_types();
2703: if (ref($types) eq 'ARRAY') {
2704: if (@{$types} > 1) {
2705: $output .= '<td valign="top"><b>'.
2706: &mt('Course Type:').'</b><br /><select name="crstype">';
2707: my $selstr = '';
2708: if ($curr->{'crstype'} eq 'any') {
2709: $selstr = ' selected="selected"';
2710: }
2711: $output .= '<option value="any"'.$selstr.'>'.&mt('All types').'</option>'."\n";
2712: foreach my $crstype (@{$types}) {
2713: my $selstr = '';
2714: if ($curr->{'crstype'} eq $crstype) {
2715: $selstr = ' selected="selected"';
2716: }
2717: my $typename = $crstype;
2718: if (ref($typenames) eq 'HASH') {
2719: if ($typenames->{$crstype} ne '') {
2720: $typename = $typenames->{$crstype};
2721: }
2722: }
2723: $output .= '<option value="'.$crstype.'"'.$selstr.'>'.$typename.'</option>'."\n";
2724: }
2725: $output .= '</select></td>';
2726: }
2727: }
2728: my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'});
2729: if (ref($statuses) eq 'ARRAY') {
2730: if (@{$statuses} > 1) {
2731: $output .= '<td valign="top"><b>'.
2732: &mt('Request Status:').'</b><br /><select name="status">';
2733: my $selstr = '';
2734: if ($curr->{'status'} eq 'any') {
2735: $selstr = ' selected="selected"';
2736: }
2737: $output .= '<option value="any"'.$selstr.'>'.&mt('Any status').'</option>'."\n";
2738: foreach my $status (@{$statuses}) {
2739: my $selstr = '';
2740: if ($curr->{'status'} eq $status) {
2741: $selstr = ' selected="selected"';
2742: }
2743: my $statusname = $status;
2744: if (ref($statusnames) eq 'HASH') {
2745: if ($statusnames->{$status} ne '') {
2746: $statusname = $statusnames->{$status};
2747: }
2748: }
2749: $output .= '<option value="'.$status.'"'.$selstr.'>'.$statusname.'</option>'."\n";
2750: }
2751: $output .= '</select></td>';
2752: }
2753: }
2754: $output .= '</tr></table>';
2755:
2756: # Update Display button
2757: $output .= '<p>'.
2758: '<input type="submit" value="'.&mt('Update Display').'" />'.
2759: '</p><hr />';
2760: return $output;
2761: }
2762:
2763: sub print_review {
2764: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
2765: $disallowed,$disallowmsg,$instcredits) = @_;
2766: my ($types,$typename) = &Apache::loncommon::course_types();
2767: my ($owner,$ownername,$owneremail);
2768: if ($uname eq '' || $udom eq '') {
2769: $uname = $env{'user.name'};
2770: $udom = $env{'user.domain'};
2771: }
2772: $owner = $uname.':'.$udom;
2773: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
2774: my %emails = &Apache::loncommon::getemails($uname,$udom);
2775: foreach my $email ('permanentemail','critnotification','notification') {
2776: $owneremail = $emails{$email};
2777: last if ($owneremail ne '');
2778: }
2779: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
2780: $section_headers,$section_values,$personnel_headers,$personnel_values);
2781:
2782: $crstypename = $env{'form.crstype'};
2783: if (ref($typename) eq 'HASH') {
2784: unless ($typename->{$env{'form.crstype'}} eq '') {
2785: $crstypename = &mt($typename->{$env{'form.crstype'}});
2786: }
2787: }
2788: my $category = 'Course';
2789: if ($env{'form.crstype'} eq 'community') {
2790: $category = 'Community';
2791: }
2792:
2793: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
2794: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
2795:
2796: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
2797: '('.&Apache::lonnet::plaintext('st',$category).')';
2798: my $instcode;
2799: if ($env{'form.crstype'} eq 'official') {
2800: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
2801: foreach my $title (@{$codetitles}) {
2802: if ($env{'form.instcode_'.$title} ne '') {
2803: $inst_headers .= '<th>'.$title.'</th>';
2804: my $longitem = $env{'form.instcode_'.$title};
2805: if (ref($cat_titles->{$title}) eq 'HASH') {
2806: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
2807: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
2808: }
2809: }
2810: $inst_values .= '<td>'.$longitem.'</td>';
2811: }
2812: }
2813: }
2814: if (ref($code_order) eq 'ARRAY') {
2815: foreach my $item (@{$code_order}) {
2816: $instcode .= $env{'form.instcode_'.$item};
2817: }
2818: }
2819: $inst_headers .= '<th>'.&mt('Credits').'</th>';
2820: if ($instcredits) {
2821: $inst_values .= '<td>'.$instcredits.'</td>';
2822: } else {
2823: $inst_values .= '<td>'.$env{'form.coursecredits'}.'</td>';
2824: }
2825: if (&Apache::lonnet::auto_run('',$dom)) {
2826: $enrollrow_title = &mt('Enrollment');
2827: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
2828: '<th>'.&mt('Automatic Drops').'</th>'.
2829: '<th>'.&mt('Enrollment Starts').'</th>'.
2830: '<th>'.&mt('Enrollment Ends').'</th>';
2831: $section_headers = '<th>'.&mt('Sections').'</th>'.
2832: '<th>'.&mt('Crosslistings').'</th>';
2833:
2834: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
2835: my @autoroster = (&mt('No'),&mt('Yes'));
2836: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
2837: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
2838: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
2839: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
2840: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
2841: &mt('Institutional section').'</th>'.
2842: '<th>'.&mt('LON-CAPA section').'</th></tr>';
2843: my $secinfo;
2844: if ($env{'form.sectotal'} > 0) {
2845: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2846: if ($env{'form.sec_'.$i}) {
2847: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
2848: if ($env{'form.loncapasec_'.$i} ne '') {
2849: $secinfo .= $env{'form.loncapasec_'.$i};
2850: } else {
2851: $secinfo .= &mt('None');
2852: }
2853: $secinfo .= '</td></tr>';
2854: }
2855: }
2856: }
2857: if ($secinfo eq '') {
2858: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
2859: }
2860: $section_values .= $secinfo.'</table></td><td>'.
2861: '<table class="LC_innerpickbox"><tr><th>'.
2862: &mt('Institutional course/section').'</th>'.
2863: '<th>'.&mt('LON-CAPA section').'</th></tr>';
2864: my $xlistinfo;
2865: my $crosslisttotal = $env{'form.crosslisttotal'};
2866: if (!$crosslisttotal) {
2867: $crosslisttotal = 1;
2868: }
2869: for (my $i=0; $i<$crosslisttotal; $i++) {
2870: if ($env{'form.crosslist_'.$i}) {
2871: $xlistinfo .= '<tr><td>';
2872: if (ref($code_order) eq 'ARRAY') {
2873: if (@{$code_order} > 0) {
2874: foreach my $item (@{$code_order}) {
2875: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
2876: }
2877: }
2878: }
2879: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
2880: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
2881: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
2882: } else {
2883: $xlistinfo .= &mt('None');
2884: }
2885: $xlistinfo .= '</td></tr>';
2886: }
2887: }
2888: if ($xlistinfo eq '') {
2889: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
2890: }
2891: $section_values .= $xlistinfo;
2892: }
2893: $section_values .= '</table></td>';
2894: } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
2895: $inst_headers .= '<th>'.&mt('Credits').'</th>';
2896: $inst_values .= '<td>'.$env{'form.coursecredits'}.'</td>';
2897: }
2898:
2899: my %ctxt = &clone_text();
2900: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
2901: if (($env{'form.cloning'}) &&
2902: ($env{'form.clonecrs'} =~ /^$match_name$/) &&
2903: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
2904: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname,
2905: $udom,$env{'form.clonecrs'},$env{'form.clonedom'},
2906: $env{'form.crstype'},$dom,$instcode);
2907: if ($canclone) {
2908: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
2909: $env{'form.clonecrs'},('description','internal.coursecode'));
2910: if (keys(%courseenv) > 0) {
2911: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
2912: $inst_values .= '<td>'.$courseenv{'description'}.' ';
2913: my $cloneinst = $courseenv{'internal.coursecode'};
2914: if ($cloneinst ne '') {
2915: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
2916: } else {
2917: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
2918: }
2919: $inst_values .= '</td><td>';
2920: if ($env{'form.datemode'} eq 'preserve') {
2921: $inst_values .= $ctxt{'prd'};
2922: } elsif ($env{'form.datemode'} eq 'shift') {
2923: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
2924: } else {
2925: $inst_values .= $ctxt{'ncd'};
2926: }
2927: $inst_values .= '</td>';
2928: } else {
2929: $inst_values .= '<td>'.&mt('Unknown').'</td>';
2930: }
2931: } else {
2932: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
2933: }
2934: } else {
2935: $inst_values .= '<td>'.&mt('None').'</td>';
2936: }
2937: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
2938: '<th>'.&mt('Access Ends').'</th>';
2939: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2940: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
2941: if ($accessend == 0) {
2942: $enroll_values .= '<td>'.&mt('No end date').'</td>';
2943: } else {
2944: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
2945: }
2946:
2947: my $container = 'Course';
2948: my $ccrole = 'cc';
2949: if ($env{'form.crstype'} eq 'community') {
2950: $container = 'Community';
2951: $ccrole = 'co';
2952: }
2953:
2954: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
2955: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
2956: '</th>';
2957:
2958: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
2959: '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
2960: '<td>'.&mt('None').'</td></tr>';
2961: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2962: if ($env{'form.person_'.$i.'_uname'} ne '') {
2963: if (ref($disallowed) eq 'ARRAY') {
2964: next if (grep(/^$i$/,@{$disallowed}));
2965: }
2966: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2967: my @allsecs;
2968: foreach my $sec (@officialsecs) {
2969: next unless ($sec =~ /\w/);
2970: next if ($sec =~ /\W/);
2971: next if ($sec eq 'none');
2972: push(@allsecs,$sec);
2973: }
2974: my $newsec = $env{'form.person_'.$i.'_newsec'};
2975: $newsec =~ s/^\s+//;
2976: $newsec =~s/\s+$//;
2977: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
2978: foreach my $sec (@newsecs) {
2979: next unless ($sec =~ /\w/);
2980: next if ($sec =~ /\W/);
2981: next if ($sec eq 'none');
2982: if ($sec ne '') {
2983: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2984: push(@allsecs,$sec);
2985: }
2986: }
2987: }
2988: my $showsec;
2989: if (@allsecs) {
2990: $showsec = join(', ',@allsecs);
2991: }
2992: if ($showsec eq '') {
2993: $showsec = &mt('None');
2994: }
2995: if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
2996: $showsec = &mt('None');
2997: }
2998: my $role = $env{'form.person_'.$i.'_role'};
2999: $personnel_values .=
3000: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
3001: $env{'form.person_'.$i.'_lastname'}.'</td>'.
3002: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
3003: $env{'form.person_'.$i.'_dom'}.'</td>'.
3004: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
3005: '<td>'.$showsec.'</td></tr>';
3006: }
3007: }
3008: my $output;
3009: if (ref($disallowed) eq 'ARRAY') {
3010: if (@{$disallowed} > 0) {
3011: if (ref($disallowmsg) eq 'HASH') {
3012: $output = '<p class="LC_warning">'.
3013: &mt('Not all requested personnel could be included.').'<ul>';
3014: foreach my $item (@{$disallowed}) {
3015: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
3016: }
3017: $output .= '</ul></p>';
3018: }
3019: }
3020: }
3021: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
3022: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
3023: '<table class="LC_innerpickbox"><tr>'.
3024: '<th>'.&mt('Name').'</th>'.
3025: '<th>'.&mt('Username:Domain').'</th>'.
3026: '<th>'.&mt('E-mail address').'</th>'.
3027: '</tr><tr>'."\n".
3028: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
3029: '<td>'.$owneremail.'</td>'.
3030: '</tr></table>'."\n".
3031: &Apache::lonhtmlcommon::row_closure().
3032: &Apache::lonhtmlcommon::row_title(&mt('Description')).
3033: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
3034: '<tr>'.$inst_values.'</tr></table>'."\n".
3035: &Apache::lonhtmlcommon::row_closure().
3036: &Apache::lonhtmlcommon::row_title($enrollrow_title).
3037: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
3038: '<tr>'.$enroll_values.'</tr></table>'."\n".
3039: &Apache::lonhtmlcommon::row_closure();
3040: if ($section_headers ne '') {
3041: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
3042: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
3043: '<tr>'.$section_values.'</tr></table>'."\n".
3044: &Apache::lonhtmlcommon::row_closure();
3045: }
3046: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
3047: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
3048: $personnel_values.'</table>'."\n".
3049: &Apache::lonhtmlcommon::row_closure(1).
3050: &Apache::lonhtmlcommon::end_pick_box().'</div>';
3051: return $output;
3052: }
3053:
3054: sub dates_from_form {
3055: my ($startname,$endname) = @_;
3056: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
3057: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
3058: if ($endname eq 'accessend') {
3059: if (exists($env{'form.no_end_date'}) ) {
3060: $enddate = 0;
3061: }
3062: }
3063: return ($startdate,$enddate);
3064: }
3065:
3066: sub courseinfo_form {
3067: my ($dom,$formname,$crstype,$next,$description) = @_;
3068: my %js_lt = &Apache::lonlocal::texthash(
3069: official => 'You must provide a (brief) course description.',
3070: community => 'You must provide a (brief) community description.'
3071: );
3072: &js_escape(\%js_lt);
3073: $js_lt{'unofficial'} = $js_lt{'official'};
3074: $js_lt{'textbook'} = $js_lt{'official'};
3075: my $js_validate = <<"ENDJS";
3076: <script type="text/javascript">
3077: // <![CDATA['
3078:
3079: function validateForm() {
3080: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
3081: alert('$js_lt{$crstype}');
3082: return;
3083: }
3084: nextPage(document.$formname,'$next');
3085: }
3086:
3087: function toggleCloning() {
3088: var willclone;
3089: if (document.$formname.cloning.length > 1) {
3090: for (var i=0; i<document.$formname.cloning.length; i++) {
3091: if (document.$formname.cloning[i].checked) {
3092: willclone = document.$formname.cloning[i].value;
3093: }
3094: }
3095: }
3096: if (willclone == 1) {
3097: document.getElementById('cloneoptions').style.display="block";
3098: } else {
3099: document.getElementById('cloneoptions').style.display="none";
3100: document.$formname.clonecrs.value = '';
3101: }
3102: }
3103:
3104: // ]]
3105: </script>
3106:
3107: ENDJS
3108: my $title = &mt('Brief Course Description');
3109: my $clonetitle = &mt('Clone content and settings from an existing course?');
3110: if ($crstype eq 'community') {
3111: $title = &mt('Brief Community Description');
3112: $clonetitle = &mt('Clone content and settings from an existing community?');
3113: }
3114: my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box().
3115: &Apache::lonhtmlcommon::row_headline().
3116: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'.
3117: &Apache::lonhtmlcommon::row_closure(1).
3118: &Apache::lonhtmlcommon::row_title(&mt('Description')).
3119: '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
3120: my ($home_server_pick,$numlib) =
3121: &Apache::loncommon::home_server_form_item($dom,'chome',
3122: 'default','hide');
3123: if ($numlib > 1) {
3124: $output .= &Apache::lonhtmlcommon::row_closure().
3125: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
3126: }
3127: $output .= $home_server_pick.
3128: &Apache::lonhtmlcommon::row_closure().
3129: &Apache::lonhtmlcommon::row_headline().
3130: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.
3131: &Apache::lonhtmlcommon::row_closure(1).
3132: &Apache::lonhtmlcommon::row_title(&mt('Clone?')).
3133: '<label><input type="radio" name="cloning" value="1" '.
3134: 'onclick="javascript:toggleCloning()" />'.
3135: &mt('Yes').(' 'x2).'</label><label>'.
3136: '<input type="radio" name="cloning" value="0" checked="checked" '.
3137: 'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'.
3138: '</h3>'.
3139: &Apache::lonhtmlcommon::row_closure(1).
3140: &Apache::lonhtmlcommon::row_headline().
3141: '<div id="cloneoptions" style="display: none" >'.
3142: &Apache::lonhtmlcommon::start_pick_box().
3143: &clone_form($dom,$formname,$crstype).
3144: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
3145: &Apache::lonhtmlcommon::end_pick_box()."\n";
3146: return $output;
3147: }
3148:
3149: sub clone_form {
3150: my ($dom,$formname,$crstype) = @_;
3151: my $type = 'Course';
3152: if ($crstype eq 'community') {
3153: $type = 'Community';
3154: }
3155: my %lt = &clone_text();
3156: my $output .=
3157: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
3158: &Apache::loncommon::select_dom_form($dom,'clonedom').'</label>'.
3159: &Apache::lonhtmlcommon::row_closure(1).
3160: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
3161: '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();opencrsbrowser('."'$formname','clonecrs','clonedom','','','','','$type'".')" />'.
3162: '</label> '.
3163: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type).
3164: &Apache::lonhtmlcommon::row_closure(1).
3165: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
3166: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
3167: '</label><br /><label>'.
3168: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
3169: '</label><br /><label>'.
3170: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
3171: $lt{'shd'}.'</label>'.
3172: '<input type="text" size="5" name="dateshift" value="365" />'.
3173: &Apache::lonhtmlcommon::row_closure(1);
3174: return $output;
3175: }
3176:
3177: sub clone_text {
3178: return &Apache::lonlocal::texthash(
3179: 'cid' => 'Course ID',
3180: 'dmn' => 'Domain',
3181: 'dsh' => 'Date Shift',
3182: 'ncd' => 'Do not clone date parameters',
3183: 'prd' => 'Clone date parameters as-is',
3184: 'shd' => 'Shift date parameters by number of days',
3185: );
3186: }
3187:
3188: sub coursecode_form {
3189: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
3190: my $output;
3191: my %rowtitle = &Apache::lonlocal::texthash (
3192: instcode => 'Course Category',
3193: crosslist => 'Cross Listed Course',
3194: );
3195: my %helpitem = (
3196: instcode => 'Course_Request_Category',
3197: );
3198: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
3199: (ref($cat_order))) {
3200: my ($sel,$instsec,$lcsec);
3201: $sel = $context;
3202: if ($context eq 'crosslist') {
3203: $sel .= '_'.$num;
3204: $instsec = &mt('Institutional section').'<br />'.
3205: '<input type="text" size="10" name="'.$sel.'_instsec" />';
3206: $lcsec = &mt('LON-CAPA section').'<br />'.
3207: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
3208: }
3209: if (@{$codetitles} > 0) {
3210: my $lastitem = pop(@{$codetitles});
3211: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
3212: if (@{$codetitles} > 0) {
3213: my $helplink;
3214: if (defined($helpitem{$context})) {
3215: $helplink = &Apache::loncommon::help_open_topic($helpitem{$context}).' ';
3216: }
3217: $output = &Apache::lonhtmlcommon::row_title($helplink.$rowtitle{$context}).
3218: '<table><tr>';
3219: if ($context eq 'crosslist') {
3220: $output .= '<td>'.&mt('Include?').'<br />'.
3221: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
3222: }
3223: foreach my $title (@{$codetitles}) {
3224: if (ref($cat_order->{$title}) eq 'ARRAY') {
3225: if (@{$cat_order->{$title}} > 0) {
3226: $output .= '<td align="center">'.$title.'<br />'."\n".
3227: '<select name="'.$sel.'_'.$title.'">'."\n".
3228: ' <option value="" selected="selected">'.
3229: &mt('Select').'</option>'."\n";
3230: foreach my $item (@{$cat_order->{$title}}) {
3231: my $longitem = $item;
3232: if (ref($cat_titles->{$title}) eq 'HASH') {
3233: if ($cat_titles->{$title}{$item} ne '') {
3234: $longitem = $cat_titles->{$title}{$item};
3235: }
3236: }
3237: $output .= '<option value="'.$item.'">'.$longitem.
3238: '</option>'."\n";
3239: }
3240: }
3241: $output .= '</select></td>'."\n";
3242: }
3243: }
3244: if ($context eq 'crosslist') {
3245: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
3246: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
3247: '<td align="center">'.$lcsec.'</td></tr></table>';
3248: } else {
3249: $output .= '</tr></table>'.
3250: &Apache::lonhtmlcommon::row_closure().
3251: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
3252: $lastinput;
3253: }
3254: } else {
3255: if ($context eq 'crosslist') {
3256: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
3257: '<table><tr>'.
3258: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
3259: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
3260: '</tr></table>';
3261: } else {
3262: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
3263: $lastinput;
3264: }
3265: }
3266: $output .= &Apache::lonhtmlcommon::row_closure(1);
3267: push(@$codetitles,$lastitem);
3268: } elsif ($context eq 'crosslist') {
3269: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
3270: '<table><tr><td align="center">'.
3271: '<span class="LC_nobreak">'.&mt('Include?').
3272: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
3273: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
3274: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
3275: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
3276: &Apache::lonhtmlcommon::row_closure(1);
3277: }
3278: }
3279: return $output;
3280: }
3281:
3282: sub sections_form {
3283: my ($dom,$instcode,$num) = @_;
3284: my $rowtitle;
3285: if ($instcode eq '') {
3286: $rowtitle = &mt('Sections');
3287: } else {
3288: $rowtitle = &mt('Sections of [_1]',$instcode);
3289: }
3290: return &Apache::lonhtmlcommon::row_title($rowtitle).
3291: '<table><tr><td align="center">'.
3292: '<span class="LC_nobreak">'.&mt('Include?').
3293: '<input type="checkbox" name="sec_'.$num.'" value="1" /></span>'.
3294: '</td><td align="center">'.&mt('Institutional section').'<br />'.
3295: '<input type="text" size="10" name="secnum_'.$num.'" />'.
3296: '</td><td align="center">'.&mt('LON-CAPA section').'<br />'.
3297: '<input type="text" size="10" name="loncapasec_'.$num.'" />'.
3298: '</td></tr></table>'.
3299: &Apache::lonhtmlcommon::row_closure(1);
3300: }
3301:
3302: sub get_course_dom {
3303: my $codedom = &Apache::lonnet::default_login_domain();
3304: if ($env{'form.showdom'} ne '') {
3305: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
3306: return $env{'form.showdom'};
3307: }
3308: }
3309: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
3310: my ($types,$typename) = &Apache::loncommon::course_types();
3311: if (ref($types) eq 'ARRAY') {
3312: foreach my $type (@{$types}) {
3313: if (&Apache::lonnet::usertools_access($env{'user.name'},
3314: $env{'user.domain'},$type,
3315: undef,'requestcourses')) {
3316: return $env{'user.domain'};
3317: }
3318: }
3319: my @possible_doms;
3320: foreach my $type (@{$types}) {
3321: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
3322: if ($dom_str ne '') {
3323: my @domains = split(',',$dom_str);
3324: foreach my $entry (@domains) {
3325: my ($extdom,$extopt) = split(':',$entry);
3326: if ($extdom eq $env{'request.role.domain'}) {
3327: return $extdom;
3328: }
3329: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
3330: push(@possible_doms,$extdom);
3331: }
3332: }
3333: }
3334: }
3335: if (@possible_doms) {
3336: @possible_doms = sort(@possible_doms);
3337: return $possible_doms[0];
3338: }
3339: }
3340: $codedom = $env{'user.domain'};
3341: if ($env{'request.role.domain'} ne '') {
3342: $codedom = $env{'request.role.domain'};
3343: }
3344: }
3345: return $codedom;
3346: }
3347:
3348: sub display_navbuttons {
3349: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
3350: $r->print('<div class="LC_navbuttons">');
3351: if ($prev) {
3352: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
3353: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
3354: (' 'x3));
3355: } elsif ($prevtext) {
3356: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
3357: 'onclick="javascript:history.back()"/>'.(' 'x3));
3358: }
3359: if ($state eq 'details') {
3360: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
3361: 'onclick="javascript:nextPage('."document.$formname,'$other'".
3362: ')" />');
3363: }
3364: my $gotnext;
3365: if ($state eq 'courseinfo') {
3366: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3367: 'onclick="javascript:validateForm();" />');
3368: $gotnext = 1;
3369: } elsif ($state eq 'enrollment') {
3370: if (($env{'form.crstype'} eq 'official') &&
3371: (&Apache::lonnet::auto_run('',$dom))) {
3372: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3373: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
3374: $gotnext = 1;
3375: }
3376: } elsif ($state eq 'personnel') {
3377: if ($env{'form.persontotal'} > 0) {
3378: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3379: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
3380: $gotnext = 1;
3381: }
3382: }
3383: unless ($gotnext) {
3384: if ($next) {
3385: $r->print('
3386: <input type="button" name="next" value="'.$nexttext.'" '.
3387: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
3388: }
3389: }
3390: $r->print('</div>');
3391: }
3392:
3393: sub print_request_outcome {
3394: my ($r,$lonhost,$dom,$codetitles,$code_order,$instcredits) = @_;
3395: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
3396: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,
3397: $uniquecode);
3398: my $sectotal = $env{'form.sectotal'};
3399: my $crosslisttotal = 0;
3400: $cnum = $env{'form.cnum'};
3401: unless ($cnum =~ /^$match_courseid$/) {
3402: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
3403: return $output;
3404: }
3405: $crstype = $env{'form.crstype'};
3406: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
3407: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
3408: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
3409: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
3410: }
3411: if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
3412: $uniquecode = $domconfig{'requestcourses'}{'uniquecode'}{$crstype};
3413: }
3414: }
3415: $now = time;
3416: my $ccrole = 'cc';
3417: if ($crstype eq 'community') {
3418: $ccrole = 'co';
3419: }
3420: my @instsections;
3421: if ($crstype eq 'official') {
3422: if (&Apache::lonnet::auto_run('',$dom)) {
3423: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
3424: }
3425: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
3426: if ($env{'form.sec_'.$i}) {
3427: if ($env{'form.secnum_'.$i} ne '') {
3428: my $sec = $env{'form.secnum_'.$i};
3429: $sections{$i}{'inst'} = $sec;
3430: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
3431: push(@instsections,$sec);
3432: }
3433: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
3434: $sections{$i}{'loncapa'} =~ s/\W//g;
3435: if ($sections{$i}{'loncapa'} eq 'none') {
3436: $sections{$i}{'loncapa'} = '';
3437: }
3438: }
3439: }
3440: }
3441: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
3442: if ($env{'form.crosslist_'.$i}) {
3443: my $xlistinfo = '';
3444: if (ref($code_order) eq 'ARRAY') {
3445: if (@{$code_order} > 0) {
3446: foreach my $item (@{$code_order}) {
3447: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
3448: }
3449: }
3450: }
3451: $crosslistings{$i}{'instcode'} = $xlistinfo;
3452: if ($xlistinfo ne '') {
3453: $crosslisttotal ++;
3454: }
3455: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
3456: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
3457: }
3458: }
3459: } else {
3460: $enrollstart = '';
3461: $enrollend = '';
3462: }
3463: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg,%skipped);
3464: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
3465: my $uname = $env{'form.person_'.$i.'_uname'};
3466: my $udom = $env{'form.person_'.$i.'_dom'};
3467: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
3468: if (&Apache::lonnet::domain($udom) ne '') {
3469: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
3470: $personnel{$uname.':'.$udom} = {
3471: firstname => $env{'form.person_'.$i.'_firstname'},
3472: lastname => $env{'form.person_'.$i.'_lastname'},
3473: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
3474: };
3475: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
3476: my $usertype = &get_usertype($udom,$uname,\%curr_rules,\%got_rules);
3477: if (&Apache::lonuserutils::can_create_user($udom,'requestcrs',$usertype)) {
3478: my ($allowed,$msg,$authtype,$authparam) =
3479: &check_newuser_rules($udom,$uname,\%alerts,\%rulematch,
3480: \%inst_results,\%curr_rules,\%got_rules);
3481: if ($allowed) {
3482: my %domdefaults = &Apache::lonnet::get_domain_defaults($udom);
3483: if ($usertype eq 'official') {
3484: if ($authtype eq '') {
3485: $authtype = $domdefaults{'auth_def'};
3486: $authparam = $domdefaults{'auth_arg_def'};
3487: } else {
3488: if ($authtype eq 'loc') {
3489: $authtype = 'localauth';
3490: } elsif ($authtype eq 'int') {
3491: $authtype = 'internal';
3492: }
3493: if ($authtype !~ /^(krb4|krb5|internal|localauth)$/) {
3494: $authtype = $domdefaults{'auth_def'};
3495: $authparam = $domdefaults{'auth_arg_def'};
3496: }
3497: }
3498: } elsif ($usertype eq 'unofficial') {
3499: if ($authtype eq '') {
3500: $authtype = 'internal';
3501: $authparam = '';
3502: }
3503: } else {
3504: $authtype = $domdefaults{'auth_def'};
3505: $authparam = $domdefaults{'auth_arg_def'};
3506: }
3507: if (($authtype eq '') ||
3508: (($authtype =~/^krb(4|5)$/) && ($authparam eq '')) ||
3509: ($authtype !~ /^(krb4|krb5|internal|localauth)$/)) {
3510: $skipped{$uname.':'.$udom} = 1;
3511: next;
3512: } else {
3513: $personnel{$uname.':'.$udom}{'authtype'} = $authtype;
3514: $personnel{$uname.':'.$udom}{'autharg'} = $authparam;
3515: }
3516: } else {
3517: $skipped{$uname.':'.$udom} = 1;
3518: next;
3519: }
3520: } else {
3521: $skipped{$uname.':'.$udom} = 1;
3522: next;
3523: }
3524: }
3525: }
3526: my $role = $env{'form.person_'.$i.'_role'};
3527: unless ($role eq '') {
3528: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
3529: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
3530: unless (grep(/^\Q$role\E$/,@curr_roles)) {
3531: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
3532: }
3533: } else {
3534: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
3535: }
3536: if ($role eq $ccrole) {
3537: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
3538: } else {
3539: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
3540: my @allsecs;
3541: foreach my $sec (@currsec) {
3542: next unless ($sec =~ /\w/);
3543: next if ($sec =~ /\W/);
3544: next if ($sec eq 'none');
3545: push(@allsecs,$sec);
3546: }
3547: my $newsec = $env{'form.person_'.$i.'_newsec'};
3548: $newsec =~ s/^\s+//;
3549: $newsec =~s/\s+$//;
3550: my @newsecs = split(/[\s,;]+/,$newsec);
3551: foreach my $sec (@newsecs) {
3552: next if ($sec =~ /\W/);
3553: next if ($sec eq 'none');
3554: if ($sec ne '') {
3555: unless (grep(/^\Q$sec\E$/,@allsecs)) {
3556: push(@allsecs,$sec);
3557: }
3558: }
3559: }
3560: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
3561: }
3562: }
3563: } else {
3564: push(@missingdom,$uname.':'.$udom);
3565: }
3566: } else {
3567: push(@baduname,$uname.':'.$udom);
3568: }
3569: }
3570: if (keys(%skipped)) {
3571: foreach my $key (keys(%skipped)) {
3572: delete($personnel{$key});
3573: }
3574: }
3575: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
3576: my $autodrops = 0;
3577: if ($env{'form.autodrops'}) {
3578: $autodrops = $env{'form.autodrops'};
3579: }
3580: my $autoadds = 0;
3581: if ($env{'form.autoadds'}) {
3582: $autoadds = $env{'form.autoadds'};
3583: }
3584: my $instcode = '';
3585: if (exists($env{'form.instcode'})) {
3586: $instcode = $env{'form.instcode'};
3587: }
3588: my $credits;
3589: if ($instcredits) {
3590: $credits = $instcredits;
3591: } elsif (exists($env{'form.coursecredits'})) {
3592: $credits = $env{'form.coursecredits'};
3593: }
3594: my $clonecrs = '';
3595: my $clonedom = '';
3596: if (($env{'form.cloning'}) &&
3597: ($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
3598: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
3599: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
3600: $env{'form.clonedom'});
3601: if ($clonehome ne 'no_host') {
3602: my $canclone =
3603: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
3604: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
3605: $crstype,$dom,$instcode);
3606: if ($canclone) {
3607: $clonecrs = $env{'form.clonecrs'};
3608: $clonedom = $env{'form.clonedom'};
3609: }
3610: }
3611: }
3612: my $details = {
3613: owner => $env{'user.name'},
3614: domain => $env{'user.domain'},
3615: cdom => $dom,
3616: cnum => $cnum,
3617: coursehome => $env{'form.chome'},
3618: cdescr => $env{'form.cdescr'},
3619: crstype => $env{'form.crstype'},
3620: instcode => $instcode,
3621: defaultcredits => $credits,
3622: uniquecode => $uniquecode,
3623: clonedom => $clonedom,
3624: clonecrs => $clonecrs,
3625: datemode => $env{'form.datemode'},
3626: dateshift => $env{'form.dateshift'},
3627: sectotal => $sectotal,
3628: sections => \%sections,
3629: crosslisttotal => $crosslisttotal,
3630: crosslists => \%crosslistings,
3631: autoadds => $autoadds,
3632: autodrops => $autodrops,
3633: enrollstart => $enrollstart,
3634: enrollend => $enrollend,
3635: accessstart => $accessstart,
3636: accessend => $accessend,
3637: personnel => \%personnel,
3638: };
3639: my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,
3640: $req_notifylist,\@instsections,\%domconfig);
3641: return ($result,$output);
3642: }
3643:
3644: sub process_request {
3645: my ($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections,
3646: $domconfig) = @_;
3647: my (@inststatuses,$storeresult,$creationresult,$output);
3648: my $val =
3649: &Apache::loncoursequeueadmin::get_processtype('course',$env{'user.name'},
3650: $env{'user.domain'},$env{'user.adv'},
3651: $dom,$crstype,\@inststatuses,$domconfig);
3652: if ($val eq '') {
3653: if ($crstype eq 'official') {
3654: $output = &mt('You are not permitted to request creation of official courses.');
3655: } elsif ($crstype eq 'unofficial') {
3656: $output = &mt('You are not permitted to request creation of unofficial courses.');
3657: } elsif ($crstype eq 'community') {
3658: $output = &mt('You are not permitted to request creation of communities');
3659: } elsif ($crstype eq 'textbook') {
3660: $output = &mt('You are not permitted to request creation of textbook courses');
3661: } else {
3662: $output = &mt('Unrecognized course type: [_1]',$crstype);
3663: }
3664: $storeresult = 'notpermitted';
3665: } else {
3666: my ($disposition,$message,$reqstatus,$coursedesc);
3667: my %reqhash = (
3668: reqtime => $now,
3669: crstype => $crstype,
3670: details => $details,
3671: );
3672: my $requestkey = $dom.'_'.$cnum;
3673: my $validationerror;
3674: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3675: $env{'user.domain'});
3676: if (ref($details) eq 'HASH') {
3677: $coursedesc = $details->{'cdescr'};
3678: }
3679: if ($val eq 'autolimit=') {
3680: $disposition = 'process';
3681: } elsif ($val =~ /^autolimit=(\d+)$/) {
3682: my $limit = $1;
3683: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
3684: $dom,$crstype,$limit,\$message);
3685: } elsif ($val eq 'validate') {
3686: my ($inststatuslist,$validationchk,$validation,%custominfo);
3687: if (ref($details) eq 'HASH') {
3688: if ($details->{'clonecrs'}) {
3689: $custominfo{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
3690: }
3691: }
3692: if (@inststatuses > 0) {
3693: $inststatuslist = join(',',@inststatuses);
3694: }
3695: my $instseclist;
3696: if (ref($instsections) eq 'ARRAY') {
3697: if (@{$instsections} > 0) {
3698: $instseclist = join(',',@{$instsections});
3699: }
3700: }
3701: my $preprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'prevalidate',$env{'user.name'},
3702: $env{'user.domain'},$fullname,$coursedesc);
3703: if (ref($preprocess) eq 'HASH') {
3704: if (ref($preprocess->{'formitems'}) eq 'HASH') {
3705: foreach my $key (keys(%{$preprocess->{'formitems'}})) {
3706: if ($preprocess->{'formitems'}->{$key} eq 'multiple') {
3707: if (exists($env{'form.'.$key})) {
3708: @{$custominfo{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
3709: }
3710: } else {
3711: if (exists($env{'form.'.$key})) {
3712: $custominfo{$key} = $env{'form.'.$key};
3713: }
3714: }
3715: }
3716: }
3717: }
3718: $validationchk =
3719: &Apache::lonnet::auto_courserequest_validation($dom,
3720: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
3721: $inststatuslist,$instcode,$instseclist,\%custominfo);
3722: if ($validationchk =~ /:/) {
3723: ($validation,$message) = split(':',$validationchk);
3724: } else {
3725: $validation = $validationchk;
3726: }
3727: if ($validation =~ /^error(.*)$/) {
3728: $disposition = 'approval';
3729: $validationerror = $1;
3730: } else {
3731: $disposition = $validation;
3732: }
3733: } else {
3734: $disposition = 'approval';
3735: }
3736: $reqhash{'disposition'} = $disposition;
3737: $reqstatus = $disposition;
3738: my ($modified,$queued,$coursedesc,$token,%customitems);
3739: unless ($disposition eq 'rejected') {
3740: my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$env{'user.name'},
3741: $env{'user.domain'},$fullname,$coursedesc);
3742: if (ref($inprocess) eq 'HASH') {
3743: if (ref($inprocess->{'formitems'}) eq 'HASH') {
3744: foreach my $key (keys(%{$inprocess->{'formitems'}})) {
3745: if ($inprocess->{'formitems'}->{$key} eq 'multiple') {
3746: if (exists($env{'form.'.$key})) {
3747: @{$customitems{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
3748: }
3749: } else {
3750: if (exists($env{'form.'.$key})) {
3751: $customitems{$key} = $env{'form.'.$key};
3752: $reqhash{'custom'}{$key} = $customitems{$key};
3753: }
3754: }
3755: }
3756: }
3757: }
3758: }
3759: if ($disposition eq 'rejected') {
3760: if ($crstype eq 'community') {
3761: $output = &mt('Your community request was rejected.');
3762: } else {
3763: $output = &mt('Your course request was rejected.');
3764: }
3765: if ($message) {
3766: $output .= '<div class="LC_warning">'.$message.'</div>';
3767: }
3768: $storeresult = 'rejected';
3769: } elsif ($disposition eq 'process') {
3770: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
3771: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles,$code);
3772: my $type = 'Course';
3773: if ($crstype eq 'community') {
3774: $type = 'Community';
3775: }
3776: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
3777: foreach my $role (@roles) {
3778: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
3779: }
3780: $r->print('<div id="processing" style="display:block;">'."\n".
3781: &mt('Your request is being processed; this page will update when processing is complete.').
3782: '</div>');
3783: $r->rflush();
3784: if (ref($details) eq 'HASH') {
3785: if ($details->{'clonecrs'}) {
3786: $customitems{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
3787: }
3788: }
3789: my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
3790: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
3791: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,
3792: \$code,\%customitems);
3793: if ($result eq 'created') {
3794: $disposition = 'created';
3795: $reqstatus = 'created';
3796: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
3797: \%longroles);
3798: if ($crstype eq 'community') {
3799: $output = '<p>'.&mt('Your community request has been processed and the community has been created.');
3800: } else {
3801: $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
3802: }
3803: if (($code) || ((ref($postprocess) eq 'HASH') &&
3804: (($postprocess->{'createdweb'}) || ($postprocess->{'createdmsg'})))) {
3805: $output .= ¬ification_information($disposition,$env{'user.name'}.':'.$env{'user.domain'},
3806: $dom,$cnum,$now,$code,$postprocess);
3807: }
3808: if ($code) {
3809: $reqhash{'code'} = $code;
3810: }
3811: if (ref($postprocess) eq 'HASH') {
3812: if (ref($postprocess->{'createdactions'}) eq 'HASH') {
3813: if (ref($postprocess->{'createdactions'}{'environment'}) eq 'HASH') {
3814: &Apache::loncoursequeueadmin::postprocess_crsenv($dom,$cnum,
3815: $postprocess->{'createdactions'}{'environment'});
3816: }
3817: }
3818: }
3819: $output .= '<br />'.$role_result.'</p>';
3820: $creationresult = 'created';
3821: } else {
3822: $output = '<span class="LC_error">';
3823: if ($crstype eq 'community') {
3824: $output .= &mt('An error occurred when processing your community request.');
3825: } else {
3826: $output .= &mt('An error occurred when processing your course request.');
3827: }
3828: $output .= '<br />'.
3829: &mt('You may want to review the request details and submit the request again.').
3830: '</span>';
3831: $creationresult = 'error';
3832: }
3833: } else {
3834: my $requestid = $cnum.'_'.$disposition;
3835: my $request = {
3836: $requestid => {
3837: timestamp => $now,
3838: crstype => $crstype,
3839: ownername => $env{'user.name'},
3840: ownerdom => $env{'user.domain'},
3841: description => $env{'form.cdescr'},
3842: lonhost => $lonhost,
3843: },
3844: };
3845: if ($crstype eq 'official') {
3846: $request->{$requestid}->{'instcode'} = $instcode;
3847: }
3848: my $statuskey = 'status:'.$dom.':'.$cnum;
3849: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
3850: $env{'user.domain'},$env{'user.name'});
3851: if ($userreqhash{$statuskey} ne '') {
3852: $modified = 1;
3853: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
3854: my %queuehash = &Apache::lonnet::get('courserequestqueue',
3855: [$cnum.'_approval',
3856: $cnum.'_pending'],$dom,$uname);
3857: if (($queuehash{$cnum.'_approval'} ne '') ||
3858: ($queuehash{$cnum.'_pending'} ne '')) {
3859: $queued = 1;
3860: if (ref($queuehash{$cnum.'_pending'}) eq 'HASH') {
3861: $token = $queuehash{$cnum.'_pending'}{'token'};
3862: }
3863: }
3864: }
3865: unless ($queued) {
3866: if (($disposition eq 'pending') && ($crstype ne 'official')) {
3867: my %reqinfo = (
3868: $cnum.':'.$dom => $now.':'.$env{'user.name'}.':'.$env{'user.domain'},
3869: );
3870: $token = &Apache::lonnet::tmpput(\%reqinfo,$lonhost);
3871: $request->{$requestid}->{'token'} = $token;
3872: }
3873: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
3874: $dom);
3875: if ($putresult eq 'ok') {
3876: if ($crstype eq 'community') {
3877: $output .= &mt('Your community request has been recorded.');
3878: } else {
3879: $output .= &mt('Your course request has been recorded.')
3880: }
3881: unless ($disposition eq 'pending') {
3882: $output .= '<br />'.
3883: ¬ification_information($disposition,$req_notifylist,
3884: $dom,$cnum,$now);
3885: }
3886: } else {
3887: $reqstatus = 'domainerror';
3888: $reqhash{'disposition'} = $disposition;
3889: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
3890: $output = '<span class"LC_warning">'.$warning.'</span><br />';
3891: }
3892: }
3893: }
3894: ($storeresult,my $updateresult) =
3895: &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
3896: $cnum,$reqstatus,'request',$env{'user.domain'},$env{'user.name'});
3897: if ($storeresult eq 'ok') {
3898: my $postprocess;
3899: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
3900: my $updateaction = $disposition;
3901: if ($disposition eq 'approval') {
3902: $updateaction = 'queued';
3903: }
3904: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3905: $env{'user.domain'});
3906: $postprocess =
3907: &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,$updateaction,$env{'user.name'},
3908: $env{'user.domain'},$fullname,$env{'form.cdescr'});
3909: }
3910: if ($modified && $queued) {
3911: if ($crstype eq 'community') {
3912: $output .= '<p>'.&mt('Your community request has been updated').'</p>';
3913: } else {
3914: $output .= '<p>'.&mt('Your course request has been updated').'</p>';
3915: }
3916: if ($disposition eq 'approval') {
3917: $output .= ¬ification_information($disposition,$req_notifylist,$dom,$cnum,$now);
3918: }
3919: }
3920: if ($disposition eq 'approval') {
3921: if ((ref($postprocess) eq 'HASH') &&
3922: ((ref($postprocess->{'queuedmsg'}) eq 'HASH') || ($postprocess->{'queuedweb'}))) {
3923: ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
3924: }
3925: } elsif ($disposition eq 'pending') {
3926: my $pendingform;
3927: if ($crstype ne 'official') {
3928: $pendingform = &pending_validation_form($dom,$cnum,$crstype,$now,$token,
3929: $lonhost,$env{'form.cdescr'});
3930: }
3931: if ($pendingform) {
3932: $output .= $pendingform;
3933: } else {
3934: $output .= ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
3935: }
3936: }
3937: }
3938: if ($validationerror ne '') {
3939: $output .= '<p class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
3940: }
3941: if ($updateresult) {
3942: $output .= $updateresult;
3943: }
3944: }
3945: if ($creationresult ne '') {
3946: return ($creationresult,$output);
3947: } else {
3948: return ($storeresult,$output);
3949: }
3950: }
3951:
3952: sub update_requestors_roles {
3953: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
3954: my $now = time;
3955: my ($active,$future,$numactive,$numfuture,$output);
3956: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
3957: if (ref($details) eq 'HASH') {
3958: if (ref($details->{'personnel'}) eq 'HASH') {
3959: my $ccrole = 'cc';
3960: if ($crstype eq 'community') {
3961: $ccrole = 'co';
3962: }
3963: unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
3964: $details->{'personnel'}{$owner} = {
3965: 'roles' => [$ccrole],
3966: $ccrole => { 'usec' => [] },
3967: };
3968: }
3969: my @roles;
3970: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
3971: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
3972: unless (grep(/^\Q$ccrole\E$/,@roles)) {
3973: push(@roles,$ccrole);
3974: }
3975: } else {
3976: @roles = ($ccrole);
3977: }
3978: foreach my $role (@roles) {
3979: my $refresh=$env{'user.refresh.time'};
3980: if ($refresh eq '') {
3981: $refresh = $env{'user.login.time'};
3982: }
3983: if ($refresh eq '') {
3984: $refresh = $now;
3985: }
3986: my $start = $refresh-1;
3987: my $end = '0';
3988: if ($role eq 'st') {
3989: if ($details->{'accessstart'} ne '') {
3990: $start = $details->{'accessstart'};
3991: }
3992: if ($details->{'accessend'} ne '') {
3993: $end = $details->{'accessend'};
3994: }
3995: }
3996: my @usecs;
3997: if ($role ne $ccrole) {
3998: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
3999: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
4000: }
4001: }
4002: if ($role eq 'st') {
4003: if (@usecs > 1) {
4004: my $firstsec = $usecs[0];
4005: @usecs = ($firstsec);
4006: }
4007: }
4008: if (@usecs == 0) {
4009: push(@usecs,'');
4010: }
4011: foreach my $usec (@usecs) {
4012: my (%userroles,%newrole,%newgroups,$spec,$area);
4013: my $area = '/'.$dom.'/'.$cnum;
4014: my $spec = $role.'.'.$area;
4015: if ($usec ne '') {
4016: $spec .= '/'.$usec;
4017: $area .= '/'.$usec;
4018: }
4019: if ($role =~ /^cr\//) {
4020: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
4021: $cnum,$spec,$area);
4022: } else {
4023: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
4024: $spec,$cnum,$area);
4025: }
4026: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
4027: \%newgroups);
4028: $userroles{'user.role.'.$spec} = $start.'.'.$end;
4029: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
4030: if (($end == 0) || ($end > $now)) {
4031: my $showrole = $role;
4032: if ($role =~ /^cr\//) {
4033: $showrole = &Apache::lonnet::plaintext($role,$crstype);
4034: } elsif (ref($longroles) eq 'HASH') {
4035: if ($longroles->{$role} ne '') {
4036: $showrole = $longroles->{$role};
4037: }
4038: }
4039: if ($start <= $now) {
4040: $active .= '<li><a href="/adm/roles?selectrole=1&'.
4041: $spec.'=1">'.$showrole;
4042: if ($usec ne '') {
4043: $active .= ' - '.&mt('section:').' '.$usec;
4044: }
4045: $active .= '</a></li>';
4046: $numactive ++;
4047: } else {
4048: $future .= '<li>'.$showrole;
4049: if ($usec ne '') {
4050: $future .= ' - '.&mt('section:').' '.$usec;
4051: }
4052: $future .= '</li>';
4053: $numfuture ++;
4054: }
4055: }
4056: }
4057: }
4058: }
4059: }
4060: if ($active) {
4061: if ($numactive == 1) {
4062: if ($crstype eq 'Community') {
4063: $output = &mt('Use the following link to enter the community:');
4064: } else {
4065: $output = &mt('Use the following link to enter the course:');
4066: }
4067: } else {
4068: if ($crstype eq 'Community') {
4069: $output = &mt('Use the following links to your new roles to enter the community:');
4070: } else {
4071: $output = &mt('Use the following links to your new roles to enter the course:');
4072: }
4073: }
4074: $output .= ' <ul>'.$active.'</ul><br />';
4075: }
4076: if ($future) {
4077: if ($crstype eq 'Community') {
4078: $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'}))
4079: } else {
4080: $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'}));
4081: }
4082: $output .= ' <ul>'.$future.'</ul>';
4083: }
4084: return $output;
4085: }
4086:
4087: sub notification_information {
4088: my ($disposition,$req_notifylist,$dom,$cnum,$now,$code,$postprocess) = @_;
4089: my %emails = &Apache::loncommon::getemails();
4090: my $address;
4091: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
4092: $address = $emails{'permanentemail'};
4093: if ($address eq '') {
4094: $address = $emails{'notification'};
4095: }
4096: }
4097: my $output;
4098: if ($disposition eq 'approval') {
4099: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
4100: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
4101: if ($address ne '') {
4102: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
4103: }
4104: if ($req_notifylist) {
4105: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
4106: $env{'user.domain'});
4107: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
4108: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",
4109: 'undef',$env{'form.cdescr'},$now,'coursereq',$sender);
4110: }
4111: if (ref($postprocess) eq 'HASH') {
4112: if (ref($postprocess->{'queuedmsg'}) eq 'ARRAY') {
4113: if (scalar(@{$postprocess->{'queuedmsg'}}) > 0) {
4114: my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
4115: my $sender = $recipient;
4116: my $addmsg = [];
4117: foreach my $item (@{$postprocess->{'queuedmsg'}}) {
4118: if (ref($item) eq 'HASH') {
4119: if ($item->{'mt'} ne '') {
4120: push(@{$addmsg},$item);
4121: }
4122: }
4123: }
4124: if (scalar(@{$addmsg}) > 0) {
4125: &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,undef,
4126: $env{'form.cdescr'},$now,
4127: 'queuedcrsreq',$sender);
4128: }
4129: }
4130: }
4131: if ($postprocess->{'queuedweb'}) {
4132: $output .= $postprocess->{'queuedweb'};
4133: }
4134: }
4135: } elsif ($disposition eq 'pending') {
4136: my $pending_default = '<div class="LC_info">'.
4137: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
4138: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
4139: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
4140: '</div>';
4141: if (ref($postprocess) eq 'HASH') {
4142: if ($postprocess->{'pendingweb'}) {
4143: $output .= $postprocess->{'pendingweb'};
4144: } else {
4145: $output .= $pending_default;
4146: }
4147: } else {
4148: $output .= $pending_default;
4149: }
4150: } elsif ($disposition eq 'created') {
4151: if (($code) || ((ref($postprocess) eq 'HASH') &&
4152: ((ref($postprocess->{'createdmsg'}) eq 'ARRAY') || ($postprocess->{'createdweb'})))) {
4153: my $addmsg = [];
4154: my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
4155: my $sender = $recipient;
4156: if ($code) {
4157: push(@{$addmsg},{
4158: mt => 'Students can automatically select your course: "[_1]" by entering this code: [_2]',
4159: args => [$env{'form.cdescr'},$code],
4160: });
4161: $output .= '<p>'.
4162: &mt('Students can automatically select your course by entering this code: [_1].','<b>'.$code.'</b>').
4163: '<br />'.
4164: &mt('A message has been sent to your LON-CAPA account with this information.');
4165: if ($address ne '') {
4166: $output.= '<br />'.&mt('An e-mail has also been sent to: [_1] with this code.',$address);
4167: }
4168: $output .= '</p>';
4169: }
4170: if (ref($postprocess) eq 'HASH') {
4171: if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
4172: foreach my $item (@{$postprocess->{'createdmsg'}}) {
4173: if (ref($item) eq 'HASH') {
4174: if ($item->{'mt'} ne '') {
4175: push(@{$addmsg},$item);
4176: }
4177: }
4178: }
4179: }
4180: if ($postprocess->{'createdweb'}) {
4181: $output .= $postprocess->{'createdweb'}
4182: }
4183: }
4184: if (scalar(@{$addmsg}) > 0) {
4185: my $type = 'createdcrsreq';
4186: if ($code) {
4187: $type = 'uniquecode';
4188: }
4189: &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,$dom.'_'.$cnum,$env{'form.cdescr'},
4190: $now,$type,$sender);
4191: }
4192: }
4193: } else {
4194: $output .= '<div class="LC_warning">'.
4195: &mt('Your request status is: [_1].',$disposition).
4196: '</div>';
4197: }
4198: return $output;
4199: }
4200:
4201: sub pending_validation_form {
4202: my ($cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
4203: my $output;
4204: my %postvalues = (
4205: 'owner' => $env{'user.name'}.':'.$env{'user.domain'},
4206: 'course' => $cdom.'_'.$cnum,
4207: 'coursetype' => $crstype,
4208: );
4209: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
4210:
4211: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
4212: my ($url,$buttontext,$code,@fields);
4213: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
4214: $postvalues{'description'} = $cdesc;
4215: $url = $domconfig{'requestcourses'}{'validation'}{'url'};
4216: if (ref($domconfig{'requestcourses'}{'validation'}{'fields'}) eq 'ARRAY') {
4217: @fields = @{$domconfig{'requestcourses'}{'validation'}{'fields'}};
4218: }
4219: $buttontext = $domconfig{'requestcourses'}{'validation'}{'button'};
4220: $output .= $domconfig{'requestcourses'}{'validation'}{'markup'};
4221: if (($url =~ m{^(https?\://|/)}) && (@fields > 0)) {
4222: $output .= '<form name="crsreqvalidation" action="'.$url.'" method="post">'."\n";
4223: foreach my $field (@fields) {
4224: if ($postvalues{$field}) {
4225: $output .= '<input type="hidden" name="'.$field.'" value="'.$postvalues{$field}.'" />'."\n";
4226: }
4227: }
4228: if ($buttontext eq '') {
4229: if ($crstype eq 'community') {
4230: $buttontext = &mt('Create community');
4231: } else {
4232: $buttontext = &mt('Create course');
4233: }
4234: }
4235: my $protocol = $Apache::lonnet::protocol{$lonhost};
4236: $protocol = 'http' if ($protocol ne 'https');
4237: my $crscreator = $protocol.'://'.&Apache::lonnet::hostname($lonhost).'/cgi-bin/createpending.pl';
4238: $output .= '<input type="hidden" name="crscreator" value="'.$crscreator.'" />'."\n".
4239: '<input type="hidden" name="token" value="'.$token.'" />'."\n".
4240: '<input type="submit" name="validate" value="'.$buttontext.'" />'."\n".
4241: '</form>'."\n";
4242: }
4243: }
4244: }
4245: return $output;
4246: }
4247:
4248: sub check_autolimit {
4249: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
4250: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
4251: 'userroles',['active','future'],['cc','co'],[$dom]);
4252: my ($types,$typename) = &Apache::loncommon::course_types();
4253: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
4254: my $count = 0;
4255: foreach my $key (keys(%requests)) {
4256: my ($cdom,$cnum) = split('_',$key);
4257: if (ref($requests{$key}) eq 'HASH') {
4258: next if ($requests{$key}{'crstype'} ne $crstype);
4259: if (($crstype eq 'community') &&
4260: (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
4261: $count ++;
4262: } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook')) &&
4263: (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
4264: $count ++;
4265: }
4266: }
4267: }
4268: if ($count < $limit) {
4269: return 'process';
4270: } else {
4271: if (ref($typename) eq 'HASH') {
4272: if ($crstype eq 'community') {
4273: $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
4274: '<br />'.&mt("Your limit is [_1].",$limit);
4275: } else {
4276: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
4277: '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
4278: }
4279: }
4280: return 'rejected';
4281: }
4282: return;
4283: }
4284:
4285: sub retrieve_settings {
4286: my ($dom,$cnum,$udom,$uname) = @_;
4287: if ($udom eq '' || $uname eq '') {
4288: $udom = $env{'user.domain'};
4289: $uname = $env{'user.name'};
4290: }
4291: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
4292: if ($result eq 'ok') {
4293: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
4294: $env{'form.chome'} = $reqinfo{'coursehome'};
4295: $env{'form.cdescr'} = $reqinfo{'cdescr'};
4296: $env{'form.crstype'} = $reqinfo{'crstype'};
4297: &generate_date_items($reqinfo{'accessstart'},'accessstart');
4298: &generate_date_items($reqinfo{'accessend'},'accessend');
4299: if ($reqinfo{'accessend'} == 0) {
4300: $env{'form.no_end_date'} = 1;
4301: }
4302: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
4303: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
4304: &generate_date_items($reqinfo{'enrollend'},'enrollend');
4305: }
4306: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
4307: $env{'form.clonedom'} = $reqinfo{'clonedom'};
4308: if (($reqinfo{'clonecrs'} ne '') && ($reqinfo{'clonedom'} ne '')) {
4309: $env{'form.cloning'} = 1;
4310: }
4311: $env{'form.datemode'} = $reqinfo{'datemode'};
4312: $env{'form.dateshift'} = $reqinfo{'dateshift'};
4313: if ($reqinfo{'crstype'} eq 'official') {
4314: $env{'form.autoadds'} = $reqinfo{'autoadds'};
4315: $env{'form.autodrops'} = $reqinfo{'autodrops'};
4316: if ($reqinfo{'instcode'} ne '') {
4317: $env{'form.sectotal'} = $reqinfo{'sectotal'};
4318: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
4319: $env{'form.instcode'} = $reqinfo{'instcode'};
4320: my $crscode = {
4321: $cnum => $reqinfo{'instcode'},
4322: };
4323: &extract_instcode($dom,'instcode',$crscode,$cnum);
4324: (undef,undef,my $instcredits) =
4325: &Apache::lonnet::auto_validate_instcode(undef,$dom,
4326: $reqinfo{'instcode'});
4327: if ($instcredits ne $reqinfo{'defaultcredits'}) {
4328: $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
4329: }
4330: }
4331: } elsif (($reqinfo{'crstype'} eq 'unofficial') || ($reqinfo{'crstype'} eq 'textbook')) {
4332: $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
4333: }
4334: my @currsec;
4335: if (ref($reqinfo{'sections'}) eq 'HASH') {
4336: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
4337: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
4338: my $sec = $reqinfo{'sections'}{$i}{'inst'};
4339: $env{'form.secnum_'.$i} = $sec;
4340: $env{'form.sec_'.$i} = '1';
4341: if (!grep(/^\Q$sec\E$/,@currsec)) {
4342: push(@currsec,$sec);
4343: }
4344: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
4345: }
4346: }
4347: }
4348: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
4349: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
4350: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
4351: $env{'form.crosslist_'.$i} = '1';
4352: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
4353: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
4354: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
4355: my $key = $cnum.$i;
4356: my $crscode = {
4357: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
4358: };
4359: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
4360: }
4361: }
4362: }
4363: }
4364: if (ref($reqinfo{'personnel'}) eq 'HASH') {
4365: my $i = 0;
4366: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
4367: my ($uname,$udom) = split(':',$user);
4368: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
4369: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
4370: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
4371: $env{'form.person_'.$i.'_role'} = $role;
4372: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
4373: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
4374: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
4375: $env{'form.person_'.$i.'_uname'} = $uname;
4376: $env{'form.person_'.$i.'_dom'} = $udom;
4377: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
4378: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
4379: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
4380: my @newsecs;
4381: if (@usecs > 0) {
4382: foreach my $sec (@usecs) {
4383: if (grep(/^\Q$sec\E/,@currsec)) {
4384: $env{'form.person_'.$i.'_sec'} = $sec;
4385: } else {
4386: push(@newsecs,$sec);
4387: }
4388: }
4389: }
4390: if (@newsecs > 0) {
4391: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
4392: }
4393: }
4394: }
4395: $i ++;
4396: }
4397: }
4398: }
4399: }
4400: $env{'form.persontotal'} = $i;
4401: }
4402: }
4403: }
4404: return $result;
4405: }
4406:
4407: sub get_request_settings {
4408: my ($dom,$cnum,$udom,$uname) = @_;
4409: my $requestkey = $dom.'_'.$cnum;
4410: my ($result,%reqinfo);
4411: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
4412: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
4413: my $disposition = $history{'disposition'};
4414: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
4415: if (ref($history{'details'}) eq 'HASH') {
4416: %reqinfo = %{$history{'details'}};
4417: $result = 'ok';
4418: } else {
4419: $result = 'nothash';
4420: }
4421: } else {
4422: $result = 'notqueued';
4423: }
4424: } else {
4425: $result = 'invalid';
4426: }
4427: return ($result,%reqinfo);
4428: }
4429:
4430: sub extract_instcode {
4431: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
4432: my (%codes,@codetitles,%cat_titles,%cat_order);
4433: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
4434: \@codetitles,\%cat_titles,
4435: \%cat_order) eq 'ok') {
4436: if (ref($codes{$crskey}) eq 'HASH') {
4437: if (@codetitles > 0) {
4438: my $sel = $element;
4439: if ($element eq 'crosslist') {
4440: $sel .= '_'.$counter;
4441: }
4442: foreach my $title (@codetitles) {
4443: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
4444: }
4445: }
4446: }
4447: }
4448: return;
4449: }
4450:
4451: sub generate_date_items {
4452: my ($currentval,$item) = @_;
4453: if ($currentval =~ /\d+/) {
4454: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
4455: &Apache::lonhtmlcommon::get_timedates($currentval);
4456: $env{'form.'.$item.'_day'} = $mday;
4457: $env{'form.'.$item.'_month'} = $month+1;
4458: $env{'form.'.$item.'_year'} = $year;
4459: }
4460: return;
4461: }
4462:
4463: sub print_textbook_form {
4464: my ($r,$dom,$incdoms,$domdefs,$settings,$can_request) = @_;
4465: my (%prefab,%ordered,%numprefab);
4466: my $crstype = 'textbook';
4467: #
4468: # Retrieve list of prefabricated courses (textbook courses and templates) cloneable by user
4469: #
4470: foreach my $type ('textbooks','templates') {
4471: $numprefab{$type} = 0;
4472: if (ref($settings) eq 'HASH') {
4473: $prefab{$type} = $settings->{$type};
4474: if (ref($prefab{$type}) eq 'HASH') {
4475: foreach my $item (keys(%{$prefab{$type}})) {
4476: my ($clonedom,$clonecrs) = split(/_/,$item);
4477: if (ref($prefab{$type}{$item}) eq 'HASH') {
4478: if (&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
4479: $env{'user.domain'},$clonecrs,$clonedom,$crstype,$dom)) {
4480:
4481: my $num = $prefab{$type}{$item}{'order'};
4482: $ordered{$type}{$num} = $item;
4483: $numprefab{$type} ++;
4484: }
4485: }
4486: }
4487: }
4488: }
4489: }
4490:
4491: #
4492: # Check if domain has multiple library servers
4493: #
4494: my ($home_server_pick,$numlib) =
4495: &Apache::loncommon::home_server_form_item($dom,'chome',
4496: 'default','hide');
4497: if ($numlib > 1) {
4498: $home_server_pick = &mt('Home Server for Course').': '.$home_server_pick.'<br />';
4499: }
4500:
4501: #
4502: # Retrieve information about courses owned by user, or in which user has an active or future
4503: # Course Coordinator role
4504: #
4505: my $numcurrent;
4506: my %cloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.',$env{'user.name'}.':'.$env{'user.domain'},
4507: undef,undef,undef,'Course');
4508: my %ccroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
4509: ['active','future'],['cc']);
4510: foreach my $role (keys(%ccroles)) {
4511: my ($cnum,$cdom,$rest) = split(/:/,$role,3);
4512: unless (exists($cloneable{$cdom.'_'.$cnum})) {
4513: my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1});
4514: $cloneable{$cdom.'_'.$cnum} = \%courseinfo;
4515: }
4516: }
4517:
4518: my $numcurrent = scalar(keys(%cloneable));
4519:
4520: my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent);
4521: my %loaditems;
4522: $loaditems{'onload'} = 'javascript:uncheckAllRadio();';
4523: $r->print(&header('Course Request',$jscript,\%loaditems));
4524:
4525: if (ref($can_request) eq 'HASH') {
4526: unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
4527: &Apache::lonhtmlcommon::add_breadcrumb(
4528: { href => '/adm/requestcourse',
4529: text => 'Pick action',
4530: });
4531: }
4532: }
4533: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
4534: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
4535:
4536: &startContentScreen($r,'textbookrequests');
4537: #
4538: # Show domain selector form, if required.
4539: #
4540: if (@{$incdoms} > 1) {
4541: my $onchange = 'this.form.submit()';
4542: $r->print('<form name="domforcourse" method="post" action="/adm/requestcourse">'.
4543: '<div><fieldset><legend>'.&mt('Domain').'</legend>'.
4544: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms).
4545: '</fieldset></form>');
4546: }
4547:
4548: #
4549: # Course request form
4550: #
4551:
4552: #
4553: # Course Title
4554: #
4555: $r->print('<form name="requestcourse" method="post" action="/adm/requestcourse" onsubmit="return validTextbookReq();">'.
4556: '<div>'.
4557: '<fieldset>'.
4558: '<legend>'.&mt('Course Information').'</legend>'.
4559: '<span class="LC_nobreak">'.&mt('Title').': '.
4560: '<input type="text" size="60" name="cdescr" value="" /></span><br />'.
4561: $home_server_pick.'<br /></fieldset>'.
4562: '</div>');
4563:
4564: #
4565: # Content source selection, if more than one available
4566: #
4567: if (keys(%cloneable) || keys(%ordered)) {
4568: $r->print('<div>'.
4569: '<fieldset><legend>'.&mt('Course Content').'</legend>');
4570: if (keys(%ordered)) {
4571: if (ref($ordered{'textbooks'}) eq 'HASH') {
4572: $r->print('<span class="LC_nobreak"><label>'.
4573: '<input type="radio" name="cloning" value="textbook" onclick="javascript:cloneChoice();" />'.
4574: &mt('Load textbook content').'</span>'.(' 'x2).' ');
4575: }
4576: if (ref($ordered{'templates'}) eq 'HASH') {
4577: $r->print('<span class="LC_nobreak"><label>'.
4578: '<input type="radio" name="cloning" value="template" onclick="javascript:cloneChoice();" />'.
4579: &mt('Load pre-existing template').'</span>'.(' 'x2).' ');
4580: }
4581: }
4582: if (keys(%cloneable)) {
4583: $r->print('<span class="LC_nobreak"><label>'.
4584: '<input type="radio" name="cloning" value="existing" onclick="javascript:cloneChoice();" />'.
4585: &mt('Copy one of your courses').'</label></span>'.(' 'x2).' ');
4586: }
4587: $r->print('<span class="LC_nobreak"><label>'.
4588: '<input type="radio" name="cloning" value="none" checked="checked" onclick="javascript:cloneChoice();" />'.
4589: &mt('Empty course shell').'</label></span>');
4590: } else {
4591: $r->print('<input type="hidden" name="cloning" value="none" />');
4592: }
4593:
4594: #
4595: # Table of cloneable textbook courses
4596: #
4597: if (keys(%ordered)) {
4598: foreach my $type ('textbooks','templates') {
4599: my $divid = 'showtextbook';
4600: my $radioid = 'book';
4601: if ($type eq 'templates') {
4602: $divid = 'showtemplate';
4603: $radioid = 'template';
4604: }
4605: if (ref($ordered{$type}) eq 'HASH') {
4606: $r->print('<div id="'.$divid.'" style="display:none">'.
4607: &Apache::loncommon::start_data_table().
4608: &Apache::loncommon::start_data_table_header_row().
4609: '<th>'.&mt('Title').'</th>');
4610: if ($type eq 'textbooks') {
4611: $r->print('<th>'.&mt('Author(s)').'</th>');
4612: }
4613: $r->print('<th>'.&mt('Subject').'</th>');
4614: if ($type eq 'textbooks') {
4615: $r->print('<th>'.&mt('Publisher').'</th>'.
4616: '<th>'.&mt('Book').'</th>');
4617: }
4618: $r->print(&Apache::loncommon::end_data_table_header_row());
4619: my @items = sort { $a <=> $b } keys(%{$ordered{$type}});
4620: foreach my $num (@items) {
4621: my $item = $ordered{$type}{$num};
4622: my $cleantitle=&HTML::Entities::encode($prefab{$type}{$item}{'title'},'<>&"');
4623: $cleantitle=~s/'/\\'/g;
4624: $cleantitle =~ s/^\s+//;
4625: $r->print(&Apache::loncommon::start_data_table_row().
4626: '<td><label><input type="radio" name="'.$radioid.'" value="'.$item.'" />'.
4627: $cleantitle.'</label></td>');
4628: if ($type eq 'textbooks') {
4629: $r->print('<td>'.$prefab{$type}{$item}{'author'}.'</td>');
4630: }
4631: $r->print('<td>'.$prefab{$type}{$item}{'subject'}.'</td>');
4632: if ($type eq 'textbooks') {
4633: $r->print('<td>'.$prefab{$type}{$item}{'publisher'}.'</td>'.
4634: '<td><img border="0" src="'.$prefab{$type}{$item}{'image'}.
4635: '" alt="'.$cleantitle.'" /></td>');
4636: }
4637: $r->print(&Apache::loncommon::end_data_table_row());
4638: }
4639: $r->print(&Apache::loncommon::end_data_table().
4640: '</div>');
4641: }
4642: }
4643: }
4644:
4645: #
4646: # Table of user's current courses (owner and/or course coordinator)
4647: #
4648: if (keys(%cloneable)) {
4649: my %lt = &clone_text();
4650: $r->print('<div id="showexisting" style="display:none">'.
4651: &Apache::loncommon::start_data_table().
4652: &Apache::loncommon::start_data_table_header_row().
4653: '<th>'.&mt('Title').'</th>'.
4654: '<th>'.&mt('Owner/co-owner(s)').'</th>'.
4655: &Apache::loncommon::end_data_table_header_row());
4656: my %allownernames;
4657: my %sortbytitle;
4658: foreach my $cid (sort(keys(%cloneable))) {
4659: if (ref($cloneable{$cid}) eq 'HASH') {
4660: my $cdesc = $cloneable{$cid}{'description'};
4661: $cdesc =~ s/`/'/g;
4662: if ($cdesc ne '') {
4663: push(@{$sortbytitle{$cdesc}},$cid);
4664: }
4665: }
4666: }
4667: foreach my $title (sort(keys(%sortbytitle))) {
4668: if (ref($sortbytitle{$title}) eq 'ARRAY') {
4669: foreach my $cid (sort(@{$sortbytitle{$title}})) {
4670: my $cleantitle=&HTML::Entities::encode($title,'<>&"');
4671: $cleantitle=~s/'/\\'/g;
4672: $cleantitle =~ s/^\s+//;
4673: my ($namestr,@owners,%ownernames);
4674: my $singleowner = $cloneable{$cid}{'internal.courseowner'};
4675: push(@owners,$singleowner);
4676: if ($cloneable{$cid}{'co-owners'} ne '') {
4677: foreach my $item (split(/,/,$cloneable{$cid}{'internal.co-owners'})) {
4678: push(@owners,$item);
4679: }
4680: }
4681: foreach my $owner (@owners) {
4682: my ($ownername,$ownerdom);
4683: if ($owner =~ /:/) {
4684: ($ownername,$ownerdom) = split(/:/,$owner);
4685: } else {
4686: $ownername = $owner;
4687: if ($owner ne '') {
4688: $ownerdom = $dom;
4689: }
4690: }
4691: if ($ownername ne '' && $ownerdom ne '') {
4692: if (exists($allownernames{$ownername.':'.$ownerdom})) {
4693: $ownernames{$ownername.':'.$ownerdom} = $allownernames{$ownername.':'.$ownerdom};
4694: } else {
4695: my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
4696: $ownernames{$ownername.':'.$ownerdom} = \%namehash;
4697: $allownernames{$ownername.':'.$ownerdom} = $ownernames{$ownername.':'.$ownerdom};
4698: }
4699: }
4700: }
4701: my @lastnames;
4702: foreach my $owner (keys(%ownernames)) {
4703: if (ref($ownernames{$owner}) eq 'HASH') {
4704: push(@lastnames,$ownernames{$owner}{'lastname'});
4705: }
4706: }
4707: if (@lastnames) {
4708: $namestr = join(', ',sort(@lastnames));
4709: }
4710: $r->print(&Apache::loncommon::start_data_table_row().
4711: '<td><label><input type="radio" name="owned" value="'.$cid.'" />'.
4712: ' '.$cleantitle.'</label></td>'.
4713: '<td>'.$namestr.'</td>'.
4714: &Apache::loncommon::end_data_table_row());
4715: }
4716: }
4717: }
4718: $r->print(&Apache::loncommon::end_data_table().
4719: '<p><input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
4720: '</label><br /><label>'.
4721: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
4722: '</label><br /><label>'.
4723: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
4724: $lt{'shd'}.'</label>'.
4725: '<input type="text" size="5" name="dateshift" value="365" />'.
4726: '</div>');
4727: }
4728: #
4729: # End of content selector
4730: #
4731: if (keys(%cloneable) || keys(%ordered)) {
4732: $r->print('</fieldset></div>');
4733: }
4734:
4735: my %accesstitles = (
4736: 'start' => 'Default start access',
4737: 'end' => 'Default end access',
4738: );
4739: my %help_item = (
4740: start => 'Course_Request_Access_Start',
4741: end => 'Course_Request_Access_End',
4742: );
4743: my $starttime = time;
4744: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
4745: my $startform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessstart',
4746: $starttime,'','','',1,'','','',1);
4747: my $endform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessend',
4748: $endtime,'','','',1,'','','',1);
4749: #
4750: # Set default start and end dates for student access
4751: #
4752: $r->print('<div>'.
4753: '<fieldset><legend>'.&mt('Student Access Dates').'</legend>'.
4754: &Apache::loncommon::help_open_topic($help_item{'start'}).
4755: ' '.&mt($accesstitles{'start'}).$startform.'<br />'.
4756: &Apache::loncommon::help_open_topic($help_item{'end'}).
4757: ' '.&mt($accesstitles{'end'}).$endform.'<br /></div>');
4758:
4759: #
4760: # Display any custom fields for this course type
4761: #
4762: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
4763: $env{'user.domain'});
4764: my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review',
4765: $env{'user.name'},
4766: $env{'user.domain'},$fullname);
4767: if (ref($postprocess) eq 'HASH') {
4768: if ($postprocess->{'reviewweb'}) {
4769: $r->print($postprocess->{'reviewweb'});
4770: }
4771: }
4772:
4773: #
4774: # Submit button
4775: #
4776: $r->print('<input type="hidden" name="crstype" value="textbook" />'.
4777: '<input type="hidden" name="action" value="process" />'.
4778: '<input type="submit" value="'.&mt('Create course').'" />');
4779:
4780: #
4781: # End request form
4782: #
4783: $r->print('</form>');
4784: &endContentScreen($r).
4785: $r->print(&Apache::loncommon::end_page());
4786: return;
4787: }
4788:
4789: sub process_textbook_request {
4790: my ($r,$dom,$action,$domdefs,$domconfig,$can_request) = @_;
4791: my ($uniquecode,$req_notifylist);
4792: my $crstype = 'textbook';
4793: if (ref($domconfig) eq 'HASH') {
4794: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
4795: if (ref($domconfig->{'requestcourses'}{'notify'}) eq 'HASH') {
4796: $req_notifylist = $domconfig->{'requestcourses'}{'notify'}{'approval'};
4797: }
4798: if (ref($domconfig->{'requestcourses'}{'uniquecode'}) eq 'HASH') {
4799: $uniquecode = $domconfig->{'requestcourses'}{'uniquecode'}{$crstype};
4800: }
4801: }
4802: }
4803: my $now = time;
4804: my $reqtype = $env{'form.cloning'};
4805: my (@inststatuses,$storeresult,$creationresult);
4806: my $cnum = &Apache::lonnet::generate_coursenum($dom,'Course');
4807: my ($clonefrom,$clonedom,$clonecrs);
4808: if ($reqtype eq 'textbook') {
4809: $clonefrom = $env{'form.book'};
4810: } elsif ($reqtype eq 'template') {
4811: $clonefrom = $env{'form.template'};
4812: } elsif ($reqtype eq 'existing') {
4813: $clonefrom = $env{'form.owned'};
4814: }
4815: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
4816: if ($clonefrom) {
4817: ($clonedom,$clonecrs) = split(/_/,$clonefrom);
4818: if (&Apache::lonnet::homeserver($clonecrs,$clonedom) ne 'no_host') {
4819: my $canclone =
4820: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
4821: $env{'user.domain'},$clonecrs,$clonedom,$crstype,$dom);
4822: unless ($canclone) {
4823: undef($clonecrs);
4824: undef($clonedom);
4825: }
4826: } else {
4827: undef($clonecrs);
4828: undef($clonedom);
4829: }
4830: }
4831: my $js = &processing_javascript();
4832: my $loaditems = {
4833: onload => 'javascript:hideProcessing();',
4834: };
4835: $r->print(&header('Course Creation',$js,$loaditems));
4836:
4837: if (ref($can_request) eq 'HASH') {
4838: unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
4839: &Apache::lonhtmlcommon::add_breadcrumb(
4840: { href => '/adm/requestcourse',
4841: text => 'Pick action',
4842: });
4843: }
4844: }
4845: &Apache::lonhtmlcommon::add_breadcrumb(
4846: { href => '/adm/requestcourse',
4847: text => "Create Course",
4848: }
4849: );
4850: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Request Processed'});
4851: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
4852: &startContentScreen($r,'textbookrequests');
4853:
4854: my $details = {
4855: owner => $env{'user.name'},
4856: domain => $env{'user.domain'},
4857: cdom => $dom,
4858: cnum => $cnum,
4859: coursehome => $env{'form.chome'},
4860: cdescr => $env{'form.cdescr'},
4861: crstype => $crstype,
4862: uniquecode => $uniquecode,
4863: clonedom => $clonedom,
4864: clonecrs => $clonecrs,
4865: accessstart => $accessstart,
4866: accessend => $accessend,
4867: personnel => {},
4868: };
4869: if ($reqtype eq 'existing') {
4870: $details->{datemode} = $env{'form.datemode'};
4871: $details->{dateshift} = $env{'form.dateshift'};
4872: }
4873: my $lonhost = $r->dir_config('lonHostID');
4874: $r->rflush();
4875: my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,'',
4876: $req_notifylist,[],$domconfig);
4877: $r->print($output);
4878: if (&Apache::loncoursequeueadmin::author_prompt()) {
4879: &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result);
4880: } elsif ($result eq 'created') {
4881: $r->print('<p><a href="/adm/requestcourse">'.&mt('Create another course').'</a></p>');
4882: }
4883: &endContentScreen($r);
4884: $r->print(&Apache::loncommon::end_page());
4885: }
4886:
4887: sub textbook_request_javascript {
4888: my ($numprefab,$numcurrent) = @_;
4889: return unless (ref($numprefab) eq 'HASH');
4890: return if (!$numprefab->{'textbooks'} && !$numprefab->{'templates'} && !$numcurrent);
4891: my %js_lt = &Apache::lonlocal::texthash(
4892: choose => 'Please select a content option.',
4893: textbook => 'Please select a textbook, or choose a different option.',
4894: template => 'Please select a template, or choose a different option.',
4895: existing => 'Please select one of your existing courses to copy, or choose a different option.',
4896: title => 'Please enter a course title.',
4897: );
4898: &js_escape(\%js_lt);
4899: return <<"ENDSCRIPT";
4900: function cloneChoice() {
4901: if (document.requestcourse.cloning) {
4902: var radioLength = document.requestcourse.cloning.length;
4903: if (radioLength == undefined) {
4904: var val = document.requestcourse.cloning.value;
4905: if ((val == 'textbook') || (val == 'template') || (val == 'existing')) {
4906: var elem = document.getElementById('show'+val);
4907: if (document.requestcourse.cloning.checked) {
4908: elem.style.display = 'block';
4909: } else {
4910: uncheckRadio(val);
4911: elem.style.display = 'none';
4912: }
4913: }
4914: } else {
4915: for (var i=0; i<radioLength; i++) {
4916: var val = document.requestcourse.cloning[i].value;
4917: if ((val == 'textbook') || (val == 'template') || (val == 'existing')) {
4918: var elem = document.getElementById('show'+val);
4919: if (document.requestcourse.cloning[i].checked) {
4920: elem.style.display = 'block';
4921: } else {
4922: if (val == 'textbook') {
4923: uncheckRadio('book');
4924: }
4925: if (val == 'template') {
4926: uncheckRadio('template');
4927: }
4928: if (val == 'existing') {
4929: uncheckRadio('owned');
4930: }
4931: elem.style.display = 'none';
4932: }
4933: }
4934: }
4935: }
4936: }
4937: return;
4938: }
4939:
4940: function uncheckRadio(radioGroupName) {
4941: var group = document.getElementsByName(radioGroupName);
4942: var radioLength = group.length;
4943: if (radioLength == undefined) {
4944: group.checked = false;
4945: } else {
4946: for (var i=0; i<radioLength; i++) {
4947: group[i].checked = false;
4948: }
4949: }
4950: return;
4951: }
4952:
4953: function uncheckAllRadio() {
4954: uncheckRadio('cloning');
4955: var numbook = $numprefab->{'textbooks'};
4956: var numtemplate = $numprefab->{'templates'};
4957: var numcurrent = $numcurrent;
4958: if (numbook > 0) {
4959: uncheckRadio('textbook');
4960: }
4961: if (numtemplate > 0) {
4962: uncheckRadio('template');
4963: }
4964: if (numcurrent > 0) {
4965: uncheckRadio('existing');
4966: }
4967: return;
4968: }
4969:
4970: function validTextbookReq() {
4971: if (document.requestcourse.cloning) {
4972: var cloneChoice = 0;
4973: var radioLength = document.requestcourse.cloning.length;
4974: if (radioLength == undefined) {
4975: if (document.requestcourse.cloning.checked == false) {
4976: alert("$js_lt{'choose'}");
4977: return false;
4978: } else {
4979: cloneChoice = document.requestcourse.cloning.value;
4980: }
4981: } else {
4982: for (var i=0; i<radioLength; i++) {
4983: if (document.requestcourse.cloning[i].checked) {
4984: cloneChoice = document.requestcourse.cloning[i].value;
4985: break;
4986: }
4987: }
4988: if (cloneChoice == 0) {
4989: alert("$js_lt{'choose'}");
4990: return false;
4991: }
4992: }
4993: var group;
4994: if ((cloneChoice == 'textbook') || (cloneChoice == 'template') || (cloneChoice == 'existing')) {
4995: var group;
4996: if (cloneChoice == 'textbook') {
4997: group = document.getElementsByName('book');
4998: } else {
4999: if (cloneChoice == 'template') {
5000: group = document.getElementsByName('template');
5001: } else {
5002: group = document.getElementsByName('owned');
5003: }
5004: }
5005: var groupLength = group.length;
5006: var chosen = 0;
5007: if (groupLength == undefined) {
5008: if (group.checked) {
5009: chosen = 1;
5010: }
5011: } else {
5012: for (var j=0; j<groupLength; j++) {
5013: if (group[j].checked) {
5014: chosen = 1;
5015: break;
5016: }
5017: }
5018: }
5019: if (chosen == 0) {
5020: if (cloneChoice == 'textbook') {
5021: alert("$js_lt{'textbook'}");
5022: } else {
5023: if (cloneChoice == 'template') {
5024: alert("$js_lt{'template'}");
5025: } else {
5026: alert("$js_lt{'existing'}");
5027: }
5028: }
5029: return false;
5030: }
5031: }
5032: }
5033: if (document.requestcourse.cdescr.value == '') {
5034: alert("$js_lt{'title'}");
5035: return false;
5036: }
5037: return true;
5038: }
5039:
5040: ENDSCRIPT
5041:
5042: }
5043:
5044: sub textbook_request_disabled {
5045: my ($r,$dom,$action,$can_request) = @_;
5046: if (ref($can_request) eq 'HASH') {
5047: if ($action eq 'process') {
5048: unless ((scalar(keys(%{$can_request})) == 1)) {
5049: &Apache::lonhtmlcommon::add_breadcrumb(
5050: { href => '/adm/requestcourse',
5051: text => 'Pick action',
5052: });
5053: }
5054: }
5055: }
5056: $r->print(&header('Course Request'));
5057: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
5058: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests').
5059: '<div>'.
5060: '<p class="LC_info">'.&mt('You do not have privileges to request creation of textbook courses.').'</p>');
5061: if (ref($can_request) eq 'HASH') {
5062: if (scalar(keys(%{$can_request})) > 1) {
5063: $r->print('<a href="/adm/requestcourse">'.&mt('Go back').'</a>');
5064: }
5065: }
5066: $r->print('</div>'.
5067: &Apache::loncommon::end_page());
5068: return;
5069: }
5070:
5071: sub startContentScreen {
5072: my ($r,$mode)=@_;
5073: $r->print("\n".'<ul class="LC_TabContentBigger" id="textbookreq">'."\n");
5074: $r->print('<li'.(($mode eq 'textbookrequests')?' class="active"':'').'><a href="/adm/requestcourse"><b> '.&mt('Request a Course').' </b></a></li>'."\n");
5075: $r->print('<li'.(($mode eq 'textbooklogs')?' class="active"':'').'><a href="/adm/requestcourse?action=log&crstype=textbook&tabs=on"><b> '.&mt('Course Request History').' </b></a></li>'."\n");
5076: $r->print("\n".'</ul>'."\n");
5077: $r->print('<div class="LC_Box" style="clear:both;margin:0;"><div id="mainbox" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="maincontentbox" style="display: block;">');
5078: }
5079:
5080: sub endContentScreen {
5081: my ($r)=@_;
5082: $r->print('</div></div></div>');
5083: }
5084:
5085: 1;
5086:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>