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