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