Annotation of loncom/interface/lonrequestcourse.pm, revision 1.15
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.15 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.14 2009/08/16 19:16:16 raeburn Exp $
1.1 raeburn 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:
1.12 raeburn 47: =item header()
48:
49: =item form_elements()
50:
51: =item onload_action()
52:
53: =item check_can_request()
54:
55: =item course_types()
56:
57: =item print_main_menu()
58:
59: =item request_administration()
60:
61: =item print_request_form()
62:
63: =item print_enrollment_menu()
64:
65: =item inst_section_selector()
66:
67: =item date_setting_table()
68:
69: =item print_personnel_menu()
70:
71: =item print_request_status()
72:
73: =item print_request_logs()
74:
75: =item print_review()
76:
77: =item dates_from_form()
78:
79: =item courseinfo_form()
80:
81: =item clone_form()
82:
83: =item clone_text()
84:
85: =item coursecode_form()
86:
87: =item get_course_dom()
88:
89: =item display_navbuttons()
90:
91: =item print_request_outcome()
92:
93: =item get_processtype()
94:
95: =item check_autolimit()
96:
97: =item build_batchcreatehash()
98:
99: =item retrieve_settings()
100:
101: =item get_request_settings()
102:
1.1 raeburn 103: =back
104:
105: =cut
106:
107: package Apache::lonrequestcourse;
108:
109: use strict;
110: use Apache::Constants qw(:common :http);
111: use Apache::lonnet;
112: use Apache::loncommon;
113: use Apache::lonlocal;
1.8 raeburn 114: use Apache::loncoursequeueadmin;
1.4 raeburn 115: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 116:
117: sub handler {
118: my ($r) = @_;
119: if ($r->header_only) {
120: &Apache::loncommon::content_type($r,'text/html');
121: $r->send_http_header;
122: return OK;
123: }
124: &Apache::loncommon::content_type($r,'text/html');
125: $r->send_http_header;
126:
1.2 raeburn 127: &Apache::lonhtmlcommon::clear_breadcrumbs();
128: my $dom = &get_course_dom();
1.1 raeburn 129: my $action = $env{'form.action'};
130: my $state = $env{'form.state'};
1.2 raeburn 131:
132: my %stored;
133: my $jscript;
134: if ((defined($state)) && (defined($action))) {
135: my %elements = &form_elements($dom);
136: if (($action eq 'view') && ($state ne 'crstype')) {
137: if (defined($env{'form.request_id'})) {
138: %stored = &retrieve_settings($dom,$env{'form.request_id'});
139: }
140: }
141: my $elementsref = {};
142: if (ref($elements{$action}) eq 'HASH') {
143: if (ref($elements{$action}{$state}) eq 'HASH') {
144: $elementsref = $elements{$action}{$state};
145: }
146: }
147: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
148: }
149:
150: if ($state eq 'personnel') {
151: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
152: }
153:
154: my $loaditems = &onload_action($action,$state);
155:
156: my %states;
157: $states{'view'} = ['pick_request','details','review','process'];
158: $states{'log'} = ['filter','display'];
159: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
160: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
161: unless ($env{'form.state'} eq 'crstype') {
162: unshift (@{$states{'new'}},'codepick');
163: }
164: }
165:
166: foreach my $key (keys(%states)) {
167: if (ref($states{$key}) eq 'ARRAY') {
168: unshift (@{$states{$key}},'crstype');
169: }
170: }
171:
1.3 raeburn 172: my %trail = (
1.10 raeburn 173: crstype => 'Course Request Action',
174: codepick => 'Category',
175: courseinfo => 'Description',
176: enrollment => 'Enrollment',
177: personnel => 'Personnel',
178: review => 'Review',
179: process => 'Result',
180: pick_request => 'Display Summary',
1.3 raeburn 181: );
182:
1.2 raeburn 183: my $page = 0;
1.3 raeburn 184: my $crumb;
1.2 raeburn 185: if (defined($action)) {
186: my $done = 0;
187: my $i=0;
188: if (ref($states{$action}) eq 'ARRAY') {
189: while ($i<@{$states{$action}} && !$done) {
190: if ($states{$action}[$i] eq $state) {
191: $page = $i;
192: $done = 1;
193: }
194: $i++;
195: }
196: }
1.3 raeburn 197: for (my $i=0; $i<@{$states{$action}}; $i++) {
198: if ($state eq $states{$action}[$i]) {
199: &Apache::lonhtmlcommon::add_breadcrumb(
200: {text=>"$trail{$state}"});
201: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
202: last;
203: } else {
204: if (($state eq 'process') && ($i > 0)) {
205: &Apache::lonhtmlcommon::add_breadcrumb(
206: {href=>"javascript:backPage(document.requestcrs,'$states{$action}[0]')",
207: text=>"$trail{$states{$action}[$i]}"});
208: } else {
209: &Apache::lonhtmlcommon::add_breadcrumb(
210: {href=>"javascript:backPage(document.requestcrs,'$states{$action}[$i]')",
211: text=>"$trail{$states{$action}[$i]}"});
212: }
213: }
214: }
215: } else {
216: &Apache::lonhtmlcommon::add_breadcrumb(
217: {text=>'Pick Action'});
218: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
1.2 raeburn 219: }
220:
1.1 raeburn 221: my %can_request;
222: my $canreq = &check_can_request($dom,\%can_request);
223: if ($action eq 'new') {
224: if ($canreq) {
225: if ($state eq 'crstype') {
1.3 raeburn 226: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
227: $crumb);
1.1 raeburn 228: } else {
1.2 raeburn 229: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.3 raeburn 230: $loaditems,$crumb);
1.1 raeburn 231: }
232: } else {
1.3 raeburn 233: $r->print(&header('Course Requests').$crumb.
1.1 raeburn 234: '<div class="LC_warning">'.
235: &mt('You do not have privileges to request creation of courses.').
1.2 raeburn 236: '</div>'.&Apache::loncommon::end_page());
1.1 raeburn 237: }
238: } elsif ($action eq 'view') {
1.10 raeburn 239: if ($state eq 'crstype') {
1.11 raeburn 240: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
241: } else {
242: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
243: $loaditems,$crumb);
1.10 raeburn 244: }
1.1 raeburn 245: } elsif ($action eq 'log') {
1.3 raeburn 246: &print_request_logs($jscript,$loaditems,$crumb);
1.1 raeburn 247: } else {
1.3 raeburn 248: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
1.1 raeburn 249: }
250: return OK;
251: }
252:
1.2 raeburn 253: sub header {
254: my ($bodytitle,$jscript,$loaditems,$jsextra) = @_;
255: if ($jscript) {
1.6 raeburn 256: $jscript = '<script type="text/javascript">'."\n".
257: '// <![CDATA['."\n".
258: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
1.2 raeburn 259: }
260: if ($loaditems) {
1.3 raeburn 261: $loaditems = {'add_entries' => $loaditems,};
262: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$loaditems);
263: } else {
264: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra);
265: }
1.2 raeburn 266: }
267:
268: sub form_elements {
269: my ($dom) = @_;
270: my %elements =
271: (
272: new => {
273: crstype => {
274: crstype => 'selectbox',
275: action => 'selectbox',
276: },
277: courseinfo => {
278: cdescr => 'text',
1.13 raeburn 279: clonecrs => 'text',
280: clonedom => 'selectbox',
1.2 raeburn 281: datemode => 'radio',
282: dateshift => 'text',
283: },
284: enrollment => {
1.13 raeburn 285: accessstart_month => 'selectbox',
286: accessstart_hour => 'selectbox',
287: accessend_month => 'selectbox',
288: accessend_hour => 'selectbox',
289: accessstart_day => 'text',
290: accessstart_year => 'text',
291: accessstart_minute => 'text',
292: accessstart_second => 'text',
293: accessend_day => 'text',
294: accessend_year => 'text',
295: accessend_minute => 'text',
296: accessend_second => 'text',
1.2 raeburn 297: no_end_date => 'checkbox',
298: },
299: personnel => {
300: persontotal => 'hidden',
301: addperson => 'checkbox',
302: },
1.13 raeburn 303: review => {
304: cnum => 'hidden',
305: },
1.2 raeburn 306: },
307: view => {
308: crstype => {
309: crstype => 'selectbox',
310: action => 'selectbox',
311: },
312: },
313: );
1.13 raeburn 314: my %servers = &Apache::lonnet::get_servers($dom,'library');
315: my $numlib = keys(%servers);
316: if ($numlib > 1) {
317: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
318: } else {
319: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
320: }
1.2 raeburn 321: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
322: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
323: \%cat_order,\@code_order);
324: my $numtitles = scalar(@codetitles);
325: if ($numtitles) {
326: my %extras;
327: $lastitem = pop(@codetitles);
328: $extras{'instcode_'.$lastitem} = 'text';
329: foreach my $item (@codetitles) {
330: $extras{'instcode_'.$item} = 'selectbox';
331: }
332: $elements{'new'}{'codepick'} = \%extras;
333: }
334: if (&Apache::lonnet::auto_run('',$dom)) {
335: my %extras = (
336: sectotal => 'hidden',
1.13 raeburn 337: enrollstart_month => 'selectbox',
338: enrollstart_hour => 'selectbox',
339: enrollend_month => 'selectbox',
340: enrollend_hour => 'selectbox',
341: enrollstart_day => 'text',
342: enrollstart_year => 'text',
343: enrollstart_minute => 'text',
344: enrollstart_second => 'text',
345: enrollend_day => 'text',
346: enrollend_year => 'text',
347: enrollend_minute => 'text',
348: enrollend_second => 'text',
1.2 raeburn 349: crosslisttotal => 'hidden',
350: addcrosslist => 'checkbox',
351: autoadds => 'radio',
352: autodrops => 'radio',
353: );
354: if ($env{'form.sectotal'} > 0) {
355: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
356: $extras{'sec_'.$i} = 'checkbox',
357: $extras{'secnum_'.$i} = 'text',
358: $extras{'loncapasec_'.$i} = 'checkbox',
359: }
360: }
361: my $crosslisttotal = $env{'form.crosslisttotal'};
362: if (!defined($crosslisttotal)) {
363: $crosslisttotal = 1;
364: }
365: if ($crosslisttotal > 0) {
366: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
367: if ($numtitles) {
368: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
369: }
370: if (@codetitles > 0) {
371: foreach my $item (@codetitles) {
372: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
373: }
374: }
375: $extras{'crosslist_'.$i} = 'checkbox';
376: $extras{'crosslist_'.$i.'_instsec'} = 'text',
377: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
378: }
379: }
380: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
381: %{$elements{'new'}{'enrollment'}} = %mergedhash;
382: }
383: my %people;
384: my $persontotal = $env{'form.persontotal'};
385: if (!defined($persontotal)) {
386: $persontotal = 1;
387: }
388: for (my $i=0; $i<$persontotal; $i++) {
1.13 raeburn 389: $people{'person_'.$i.'_uname'} = 'text',
390: $people{'person_'.$i.'_dom'} = 'selectbox',
391: $people{'person_'.$i.'_hidedom'} = 'hidden',
392: $people{'person_'.$i.'_firstname'} = 'text',
393: $people{'person_'.$i.'_lastname'} = 'text',
394: $people{'person_'.$i.'_emailaddr'} = 'text',
395: $people{'person_'.$i.'_role'} = 'selectbox',
396: $people{'person_'.$i.'_sec'} = 'selectbox',
397: $people{'person_'.$i.'_newsec'} = 'text',
1.2 raeburn 398: }
399: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
400: %{$elements{'new'}{'personnel'}} = %personnelhash;
401: return %elements;
402: }
403:
404: sub onload_action {
405: my ($action,$state) = @_;
406: my %loaditems;
407: if (($action eq 'new') || ($action eq 'view')) {
408: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)';
409: }
410: return \%loaditems;
411: }
412:
1.1 raeburn 413: sub check_can_request {
414: my ($dom,$can_request) = @_;
415: my $canreq = 0;
1.4 raeburn 416: my ($types,$typename) = &course_types();
417: if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) {
418: foreach my $type (@{$types}) {
1.1 raeburn 419: if (&Apache::lonnet::usertools_access($env{'user.name'},
420: $env{'user.domain'},
421: $type,undef,'requestcourses')) {
422: $canreq ++;
423: if ($dom eq $env{'user.domain'}) {
424: $can_request->{$type} = 1;
425: }
426: }
427: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
428: my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type});
429: if (@curr > 0) {
430: $canreq ++;
431: unless ($dom eq $env{'user.domain'}) {
432: if (grep(/^\Q$dom\E$/,@curr)) {
433: $can_request->{$type} = 1;
434: }
435: }
436: }
437: }
438: }
439: }
440: return $canreq;
441: }
442:
1.4 raeburn 443: sub course_types {
444: my @types = ('official','unofficial','community');
445: my %typename = (
446: official => 'Official course',
447: unofficial => 'Unofficial course',
448: community => 'Community',
449: );
450: return (\@types,\%typename);
451: }
452:
453:
1.1 raeburn 454: sub print_main_menu {
1.3 raeburn 455: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_;
1.4 raeburn 456: my ($types,$typename) = &course_types();
1.1 raeburn 457: my $onchange;
458: unless ($env{'form.interface'} eq 'textual') {
459: $onchange = 1;
460: }
461:
1.2 raeburn 462: my $nextstate_setter = "\n";
463: if (ref($states) eq 'HASH') {
464: foreach my $key (keys(%{$states})) {
465: if (ref($states->{$key}) eq 'ARRAY') {
466: $nextstate_setter .=
467: " if (actionchoice == '$key') {
468: nextstate = '".$states->{$key}[1]."';
469: }
470: ";
471: }
472: }
473: }
1.1 raeburn 474:
1.2 raeburn 475: my $js = <<"END";
1.1 raeburn 476:
1.2 raeburn 477: function nextPage(formname) {
478: var crschoice = document.requestcrs.crstype.value;
479: var actionchoice = document.requestcrs.action.value;
480: if (check_can_request(crschoice,actionchoice) == true) {
481: if ((actionchoice == 'new') && (crschoice == 'official')) {
482: nextstate = 'codepick';
483: } else {
484: $nextstate_setter
485: }
1.1 raeburn 486: formname.state.value= nextstate;
487: formname.submit();
488: }
489: return;
490: }
491:
1.2 raeburn 492: function check_can_request(crschoice,actionchoice) {
1.1 raeburn 493: var official = '';
494: var unofficial = '';
495: var community = '';
496: END
497:
498: foreach my $item (keys(%{$can_request})) {
499: $js .= "
500: $item = 1;
501: ";
502: }
503: my %lt = &Apache::lonlocal::texthash(
504: official => 'You are not permitted to request creation of an official course in this domain.',
505: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
506: community => 'You are not permitted to request creation of a community this domain.',
507: all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
508: );
509: $js .= <<END;
510: if (crschoice == 'official') {
511: if (official != 1) {
512: alert("$lt{'official'}");
513: return false;
514: }
515: } else {
516: if (crschoice == 'unofficial') {
517: if (unofficial != 1) {
518: alert("$lt{'unofficial'}");
519: return false;
520: }
521: } else {
522: if (crschoice == 'community') {
523: if (community != 1) {
524: alert("$lt{'community'}");
525: return false;
526: }
527: } else {
528: if (actionchoice == 'new') {
529: alert("$lt{'all'}");
530: return false;
531: }
532: }
533: }
534: }
535: return true;
536: }
537:
538: END
539:
1.3 raeburn 540: $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.
541: '<div>'.
1.1 raeburn 542: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
543: &Apache::lonhtmlcommon::start_pick_box().
1.8 raeburn 544: &Apache::lonhtmlcommon::row_title('Course Domain').
1.1 raeburn 545: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange));
546: if (!$onchange) {
547: $r->print(' <input type="submit" name="godom" value="'.
548: &mt('Change').'" />');
549: }
550: $r->print(&Apache::lonhtmlcommon::row_closure(1).
551: &Apache::lonhtmlcommon::end_pick_box().'</form></div>');
552:
1.2 raeburn 553: my $formname = 'requestcrs';
1.1 raeburn 554: my $nexttext = &mt('Next');
1.14 raeburn 555: $r->print(
556: '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'.
1.1 raeburn 557: &Apache::lonhtmlcommon::start_pick_box().
558: &Apache::lonhtmlcommon::row_title('Action').'
559: <input type="hidden" name="showdom" value="'.$dom.'" />
560: <select size="1" name="action" >
1.2 raeburn 561: <option value="new">'.&mt('New request').'</option>
1.1 raeburn 562: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
563: <option value="log">'.&mt('View request history').'</option>
564: </select>'.
565: &Apache::lonhtmlcommon::row_closure().
566: &Apache::lonhtmlcommon::row_title('Course Type').'
567: <select size="1" name="crstype">
1.4 raeburn 568: <option value="any">'.&mt('All types').'</option>');
569: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
570: foreach my $type (@{$types}) {
571: my $selected = '';
572: if ($type eq 'official') {
573: $selected = ' selected="selected"';
574: }
575: $r->print('<option value="'.$type.'"'.$selected.'>'.$typename->{$type}.
576: '</option>'."\n");
577: }
578: }
579: $r->print('</select>
1.1 raeburn 580: <input type="hidden" name="state" value="crstype" />'.
581: &Apache::lonhtmlcommon::row_closure(1).
582: &Apache::lonhtmlcommon::end_pick_box().'<br />
1.2 raeburn 583: <input type="button" name="next" value="'.$nexttext.'" onclick="javascript:nextPage(document.'.$formname.')" />
1.1 raeburn 584: </form></div>');
585: $r->print(&Apache::loncommon::end_page());
586: return;
587: }
588:
589: sub request_administration {
1.3 raeburn 590: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb) = @_;
1.2 raeburn 591: my $js;
592: if (($action eq 'new') || ($action eq 'view')) {
593: $js = <<END;
1.1 raeburn 594:
595: function nextPage(formname,nextstate) {
596: formname.state.value= nextstate;
597: formname.submit();
598: }
599: function backPage(formname,prevstate) {
600: formname.state.value = prevstate;
601: formname.submit();
602: }
603:
604: END
1.2 raeburn 605: }
606: if ($action eq 'new') {
607: my $jsextra;
1.1 raeburn 608: unless (($state eq 'review') || ($state eq 'process')) {
1.2 raeburn 609: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.1 raeburn 610: }
1.3 raeburn 611: $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb);
1.8 raeburn 612: &print_request_form($r,$action,$state,$page,$states,$dom);
1.2 raeburn 613: } elsif ($action eq 'view') {
1.3 raeburn 614: $r->print(&header('Manage course requests',$js.$jscript,$loaditems).$crumb);
1.11 raeburn 615: if ($state eq 'pick_request') {
616: $r->print(&print_request_status($dom));
617: }
1.1 raeburn 618: } elsif ($action eq 'log') {
1.11 raeburn 619: $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
1.1 raeburn 620: }
1.2 raeburn 621: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 622: return;
623: }
624:
625: sub print_request_form {
1.2 raeburn 626: my ($r,$action,$state,$page,$states,$dom) = @_;
1.1 raeburn 627: my $formname = 'requestcrs';
1.2 raeburn 628: my ($next,$prev,$message,$output,$codepicker,$crstype);
629: $prev = $states->{$action}[$page-1];
630: $next = $states->{$action}[$page+1];
1.4 raeburn 631: my %navtxt = &Apache::lonlocal::texthash (
1.10 raeburn 632: prev => 'Back',
1.4 raeburn 633: next => 'Next',
634: );
1.2 raeburn 635: $crstype = $env{'form.crstype'};
1.1 raeburn 636: $r->print('<form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.2 raeburn 637: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1.1 raeburn 638: if ($crstype eq 'official') {
1.2 raeburn 639: if ($env{'form.instcode'} ne '') {
640: $instcode = $env{'form.instcode'};
641: }
642: }
643: if ($prev eq 'codepick') {
1.4 raeburn 644: if ($crstype eq 'official') {
645: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
646: \%cat_order,\@code_order);
647: }
1.2 raeburn 648: if (@code_order > 0) {
649: my $message;
650: if ($instcode eq '') {
1.1 raeburn 651: foreach my $item (@code_order) {
1.2 raeburn 652: $instcode .= $env{'form.instcode_'.$item};
1.1 raeburn 653: }
1.2 raeburn 654: $r->print('<input type="hidden" name="instcode" value="'.$instcode.'" />'."\n");
1.1 raeburn 655: }
656: if ($instcode ne '') {
1.2 raeburn 657: $code_chk = &Apache::lonnet::auto_validate_instcode('',$dom,$instcode);
1.1 raeburn 658: if ($code_chk eq 'ok') {
659: $message = '<div class="LC_info">'.
660: &mt('The chosen course category [_1] is valid.','<b>'.
1.2 raeburn 661: $instcode.'</b>').'</div>';
1.1 raeburn 662: } else {
663: $message = '<div class="LC_warning">'.
664: &mt('No course was found matching your choice of institutional course category.');
665: if ($code_chk ne '') {
666: $message .= '<br />'.$code_chk;
667: }
668: $message .= '</div>';
669: }
1.2 raeburn 670: } else {
671: $message = '<div class="LC_warning">'.
672: &mt('No course was found matching your choice of institutional course category.');
1.1 raeburn 673: }
1.2 raeburn 674: unless ($code_chk eq 'ok') {
675: $prev = 'crstype';
676: }
677: $r->print($message);
1.1 raeburn 678: }
1.2 raeburn 679: }
680: if ($prev eq 'crstype') {
1.4 raeburn 681: if ($crstype eq 'official') {
682: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
683: \%cat_order,\@code_order);
684: }
1.2 raeburn 685: if (@code_order > 0) {
1.1 raeburn 686: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
687: \%cat_titles,\%cat_order);
1.2 raeburn 688: if ($codepicker) {
689: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box().$codepicker.
690: &Apache::lonhtmlcommon::end_pick_box().'</div>');
691: } else {
1.15 ! raeburn 692: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 693: }
694: } else {
1.15 ! raeburn 695: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.1 raeburn 696: }
1.2 raeburn 697: } elsif ($prev eq 'codepick') {
1.15 ! raeburn 698: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 699: } elsif ($state eq 'enrollment') {
1.4 raeburn 700: if ($crstype eq 'official') {
701: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
702: \%cat_order,\@code_order);
703: }
1.2 raeburn 704: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
705: \%cat_titles,\%cat_order,\@code_order));
706: } elsif ($state eq 'personnel') {
1.8 raeburn 707: $r->print(&print_personnel_menu($dom,$formname,$crstype));
1.4 raeburn 708: } elsif ($state eq 'review') {
709: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
710: \%cat_order,\@code_order);
711: $r->print(&print_review($formname,$dom,\@codetitles,\%cat_titles,\%cat_order,
712: \@code_order));
713: $navtxt{'next'} = &mt('Submit course request');
1.10 raeburn 714: } elsif ($state eq 'process') {
715: if ($crstype eq 'official') {
716: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
717: \%cat_order,\@code_order);
718: }
719: my $result = &print_request_outcome($dom,\@codetitles,\@code_order);
1.13 raeburn 720: $r->print($result);
1.1 raeburn 721: }
1.2 raeburn 722: my @excluded = ('counter');
723: my %elements = &form_elements($dom);
724: if (ref($states) eq 'HASH') {
725: if (ref($states->{$action}) eq 'ARRAY') {
726: my @items = @{$states->{$action}};
727: my $numitems = scalar(@items);
728: if ($numitems) {
729: for (my $i=$numitems-1; $i>=0; $i--) {
730: if (ref($elements{$action}) eq 'HASH') {
731: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
732: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
733: push(@excluded,$key);
734: }
735: }
736: }
737: last if ($items[$i] eq $state);
738: }
739: }
740: }
741: }
742: if (grep(/^instcode_/,@excluded)) {
743: push(@excluded,'instcode');
1.1 raeburn 744: }
1.2 raeburn 745: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1.15 ! raeburn 746: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'},$state);
1.1 raeburn 747: return;
748: }
749:
1.2 raeburn 750: sub print_enrollment_menu {
751: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order) =@_;
752: my ($sections,$autoenroll,$access_dates);
753: my $starttime = time;
754: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
755:
756: my %accesstitles = (
757: 'start' => 'Default start access',
758: 'end' => 'Default end accss',
759: );
760: my %enrolltitles = (
761: 'start' => 'Start auto-enrollment',
762: 'end' => 'End auto-enrollment',
763: );
764: if ($env{'form.crstype'} eq 'official') {
765: if (&Apache::lonnet::auto_run('',$dom)) {
766: my ($section_form,$crosslist_form,$autoenroll_form);
767: $section_form = &inst_section_selector($dom,$instcode);
768: my $crosslisttotal = $env{'form.crosslisttotal'};
769: if (!defined($crosslisttotal)) {
770: $crosslisttotal = 1;
771: }
772: if ($env{'form.addcrosslist'}) {
773: $crosslisttotal ++;
774: }
775: for (my $i=0; $i<$crosslisttotal; $i++) {
776: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
777: $cat_titles,$cat_order,$i);
778: }
779: if ($crosslist_form) {
780: $crosslist_form .=
781: &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
782: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
783: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
784: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
785: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1);
786: }
787: if ($section_form || $crosslist_form) {
788: $sections = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
789: $section_form.$crosslist_form.
790: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
791: }
792: $autoenroll_form =
793: &Apache::lonhtmlcommon::row_title(&mt('Add registered students automatically')).
794: '<span class="LC_nobreak"><label>'.
795: '<input type="radio" name="autoadds" value="1">'.
796: &mt('Yes').'</label>'.(' 'x3).'<label>'.
797: '<input type="radio" name="autoadds" value="0" checked="checked">'.
798: &mt('No').'</label></span>'.
799: &Apache::lonhtmlcommon::row_closure().
800: &Apache::lonhtmlcommon::row_title(&mt('Drop unregistered students automatically')).
801: '<span class="LC_nobreak"><label>'.
802: '<input type="radio" name="autodrops" value="1">'.
803: &mt('Yes').'</label>'.(' 'x3).'<label>'.
804: '<input type="radio" name="autodrops" value="0" checked="checked">'.
805: &mt('No').'</label></span>'.
806: &Apache::lonhtmlcommon::row_closure().
807: &date_setting_table($starttime,$endtime,$formname,'enroll',%enrolltitles);
808: if ($autoenroll_form) {
809: $autoenroll = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
810: $autoenroll_form.
811: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
812: }
813: }
814: }
815: my $access_dates_form =
816: &date_setting_table($starttime,$endtime,$formname,'access',%accesstitles);
817: if ($access_dates_form) {
818: $access_dates = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
819: $access_dates_form.
820: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
821: }
822: return $sections.$autoenroll.$access_dates;
823: }
824:
1.1 raeburn 825: sub inst_section_selector {
1.2 raeburn 826: my ($dom,$instcode) = @_;
827: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
828: my $sectotal = scalar(@sections);
1.1 raeburn 829: my $output;
1.2 raeburn 830: if ($sectotal) {
831: $output .= &Apache::lonhtmlcommon::row_title('Sections').
832: &Apache::loncommon::start_data_table().
833: &Apache::loncommon::start_data_table_row().
834: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
835: 'value="'.$sectotal.'"</th>'.
836: '<th>'.&mt('Institutional Section').'</th>'.
837: '<th>'.&mt('LON-CAPA section').'</th>'.
838: &Apache::loncommon::end_data_table_row();
839: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 840: my $colflag = $i%2;
841: $output .= &Apache::loncommon::start_data_table_row().
1.2 raeburn 842: '<td><input type="checkbox" name="sec_'.$i.
843: '" checked="checked" /></td>'.
844: '<td>'.$sections[$i].
1.1 raeburn 845: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 846: $sections[$i].'" /></td>'.
1.1 raeburn 847: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 848: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 849: &Apache::loncommon::end_data_table_row();
850: }
1.2 raeburn 851: $output .= &Apache::loncommon::end_data_table().
852: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 853: }
854: return $output;
855: }
856:
1.2 raeburn 857: sub date_setting_table {
1.14 raeburn 858: my ($starttime,$endtime,$formname,$prefix,%datetitles) = @_;
1.2 raeburn 859: my ($perpetual,$table);
1.14 raeburn 860: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.2 raeburn 861: $starttime,'','','',1,'','','',1);
1.14 raeburn 862: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.2 raeburn 863: $endtime,'','','',1,'','','',1);
1.14 raeburn 864: if ($prefix eq 'access') {
1.2 raeburn 865: $perpetual = ' <span class="LC_nobreak"><label>'.
866: '<input type="checkbox" name="no_end_date" />'.
867: &mt('No end date').'</label></span>';
868: }
869: $table = &Apache::lonhtmlcommon::row_title($datetitles{'start'}).
870: $startform.
871: &Apache::lonhtmlcommon::row_closure().
872: &Apache::lonhtmlcommon::row_title($datetitles{'end'}).
873: $endform.$perpetual.
874: &Apache::lonhtmlcommon::row_closure(1);
875: return $table;
876: }
877:
878: sub print_personnel_menu {
1.8 raeburn 879: my ($dom,$formname,$crstype) = @_;
1.2 raeburn 880: my $output = '<div>'.&Apache::lonhtmlcommon::start_pick_box();
881: my $persontotal = $env{'form.persontotal'};
882: if (!defined($persontotal)) {
883: $persontotal = 1;
884: }
885: if ($env{'form.addperson'}) {
886: $persontotal ++;
887: }
888: my $userlinktxt = &mt('Set User');
1.13 raeburn 889: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2 raeburn 890:
891: my $roleoptions;
892: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 893: my $type = 'Course';
894: if ($crstype eq 'community') {
895: $type = 'Community';
896: }
1.2 raeburn 897: foreach my $role (@roles) {
1.8 raeburn 898: my $plrole=&Apache::lonnet::plaintext($role,$type);
1.2 raeburn 899: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
900: }
901: my %customroles=&Apache::lonuserutils::my_custom_roles();
902: if (keys(%customroles) > 0) {
903: foreach my $cust (sort(keys(%customroles))) {
904: my $custrole='cr_cr_'.$env{'user.domain'}.
905: '_'.$env{'user.name'}.'_'.$cust;
906: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
907: }
908: }
909:
910: my @currsecs;
911: if ($env{'form.sectotal'}) {
912: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
913: if (defined($env{'form.loncapasec_'.$i})) {
914: my $lcsec = $env{'form.loncapasec_'.$i};
915: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
916: push(@currsecs,$lcsec);
917: }
918: }
919: }
920: }
921:
922: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
923: if (@currsecs) {
924: my $existsize = scalar(@currsecs);
925: if ($existsize > 3) {
926: $existsize = 3;
927: }
928: if ($existsize > 1) {
929: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
930: }
931: @currsecs = sort { $a <=> $b } (@currsecs);
932: $existtitle = &mt('Official').': ';
933: $existops = '<option value="">'.&mt('None').'</option>';
934: foreach my $sec (@currsecs) {
935: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
936: }
937: $seccolspan = ' colspan="2"';
938: $newtitle = &mt('Other').': ';
939: }
940:
941: for (my $i=0; $i<$persontotal; $i++) {
942: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
943: my $linkargstr = join("','",@linkargs);
1.7 raeburn 944: my $userlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,$userlinktxt);
1.2 raeburn 945: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value=""'.
946: ' onFocus="this.blur();'.
1.7 raeburn 947: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');" />';
1.2 raeburn 948: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
949: "'person_".$i."_hidedom'".');'.
1.7 raeburn 950: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');';
1.2 raeburn 951: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
952: 1,$onchange).
953: '<input type="hidden" name="person_'.$i.'_hidedom" value="'.$dom.'" />';
954: my %form_elems;
955: foreach my $item (@items) {
956: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
957: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
958: 'value="" readonly="readonly" />';
959: }
960: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
961: $roleoptions.'</select>';
962: my $sectionselector;
963: if (@currsecs) {
964: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
965: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
966: }
967: $sectionselector .= $newtitle.
1.14 raeburn 968: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.2 raeburn 969: $output .=
970: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel').'<br />'.
971: '<span class="LC_nobreak">'.$userlink.
972: '</span>').
973: '<table><tr><td align="center" valign="top">'.&mt('Username').'<br />'.$uname_form.'</td>'."\n".
974: '<td align="center" valign="top" colspan="2">'.&mt('Domain').'<br />'.$udom_form.'</td></tr><tr>'."\n".
1.13 raeburn 975: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
976: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
977: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.2 raeburn 978: '<tr><td align="center" valign="top">'.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
979: '<td'.$seccolspan.' align="center" valign="top">'.&mt('Section(s)').'<br />'.$sectionselector.'</td>'."\n".
980: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
981: }
982: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
983: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
984: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
985: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
986: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
987: &Apache::lonhtmlcommon::end_pick_box().'</div>';
988: return $output;
989: }
990:
1.1 raeburn 991: sub print_request_status {
1.11 raeburn 992: my ($dom) = @_;
1.14 raeburn 993: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
994: $env{'user.name'},'^status:'.$dom);
995: my ($output,$formname,%queue_by_date,%typenames);
996: if ($env{'form.crstype'} eq 'any') {
997: %typenames = &Apache::lonlocal::texthash (
998: official => 'Official course',
999: unofficial => 'Unofficial course',
1000: community => 'Community',
1001: );
1002: }
1003: foreach my $key (keys(%statusinfo)) {
1004: if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {
1005: (undef,my($cdom,$cnum)) = split(':',$key);
1006: next if ($cdom ne $dom);
1007: my $requestkey = $cdom.'_'.$cnum;
1008: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1009: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1010: $env{'user.domain'},$env{'user.name'});
1011: my $entry;
1012: my $timestamp = $history{'reqtime'};
1013: my $crstype = $history{'crstype'};
1014: my $disposition = $history{'disposition'};
1015: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1016: next unless (($env{'form.crstype'} eq 'any') ||
1017: ($env{'form.crstype'} eq $crstype));
1018: next unless (($disposition eq 'approval') ||
1019: ($disposition eq 'pending'));
1020: if (ref($history{'details'}) eq 'HASH') {
1021: $entry = $requestkey.':'.$crstype.':'.
1022: &escape($history{'details'}{'cdescr'});
1023: if ($crstype eq 'official') {
1024: $entry .= ':'.&escape($history{'details'}{'instcode'});
1025: }
1026: }
1027: if ($entry ne '') {
1028: if (exists($queue_by_date{$timestamp})) {
1029: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
1030: push(@{$queue_by_date{$timestamp}},$entry);
1031: }
1032: } else {
1033: @{$queue_by_date{$timestamp}} = ($entry);
1.10 raeburn 1034: }
1035: }
1036: }
1037: }
1038: }
1.11 raeburn 1039: $formname = 'requestcrs';
1.10 raeburn 1040: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.14 raeburn 1041: $output = '<h3>'.&mt('Pending course requests').'</h3><div>'."\n".
1042: '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />'."\n".
1.10 raeburn 1043: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1044: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1045: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n";
1046: if (@sortedtimes > 0) {
1047: $output .= &Apache::loncommon::start_data_table().
1048: &Apache::loncommon::start_data_table_header_row().
1049: '<th>'.&mt('Action').'</th>'.
1.14 raeburn 1050: '<th>'.&mt('Course Description').'</th>'.
1051: '<th>'.&mt('Domain').'</th>';
1052: if ($env{'form.crstype'} eq 'any') {
1.10 raeburn 1053: $output .= '<th>'.&mt('Type').'</th>';
1054: }
1.14 raeburn 1055: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10 raeburn 1056: $output .= '<th>'.&mt('Institutional Code').'</th>';
1057: }
1058: $output .= '<th>'.&mt('Date requested').'</th>'.
1059: &Apache::loncommon::end_data_table_header_row();
1060: my $count = 0;
1061: foreach my $item (@sortedtimes) {
1062: my $showtime = &Apache::lonlocal::locallocaltime($item);
1063: if (ref($queue_by_date{$item}) eq 'ARRAY') {
1064: foreach my $request (sort(@{$queue_by_date{$item}})) {
1065: my ($key,$type,$desc,$instcode) = split(':',$request);
1066: my ($cdom,$cnum) = split('_',$key);
1067: $output .= &Apache::loncommon::start_data_table_row().
1068: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:viewrequest('."'$cdom','$cnum'".')" /></td>'.
1.14 raeburn 1069: '<td>'.&unescape($desc).'</td>'.
1070: '<td>'.$cdom.'</td>';
1071: if ($env{'form.crstype'} eq 'any') {
1072: my $typename = $typenames{$type};
1073: if ($typename eq '') {
1074: $typename = &mt('Unknown type');
1075: }
1076: $output .= '<td>'.$typename.'</td>';
1.10 raeburn 1077: }
1.14 raeburn 1078: if (($env{'form.crstype'} eq 'any') ||
1.10 raeburn 1079: ($env{'form.crstype'} eq 'official')) {
1.14 raeburn 1080: my $showinstcode;
1081: if ($type eq 'official') {
1082: $showinstcode = &unescape($instcode);
1083: } else {
1084: $showinstcode = &mt('Not applicable');
1085: }
1086: $output .= '<td>'.$showinstcode.'</td>';
1.10 raeburn 1087: }
1088: $output .= '<td>'.$showtime.'</td>'.
1089: &Apache::loncommon::end_data_table_row();
1090: }
1091: }
1092: }
1093: $output .= &Apache::loncommon::end_data_table();
1094: } else {
1.11 raeburn 1095: $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>';
1.10 raeburn 1096: }
1097: $output .= '
1.14 raeburn 1098: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />
1099: </form></div>';
1.10 raeburn 1100: return $output;
1.1 raeburn 1101: }
1102:
1103: sub print_request_logs {
1.10 raeburn 1104: my ($jscript,$loaditems,$crumb) = @_;
1.1 raeburn 1105: return;
1106: }
1107:
1108: sub print_review {
1.4 raeburn 1109: my ($formname,$dom,$codetitles,$cat_titles,$cat_order,$code_order) = @_;
1110: my ($types,$typename) = &course_types();
1111: my ($owner,$ownername,$owneremail);
1112: $owner = $env{'user.name'}.':'.$env{'user.domain'};
1113: $ownername = &Apache::loncommon::plainname($env{'user.name'},
1114: $env{'user.domain'},'first');
1115: my %emails = &Apache::loncommon::getemails();
1116: foreach my $email ('permanentemail','critnotification','notification') {
1117: $owneremail = $emails{$email};
1118: last if ($owneremail ne '');
1119: }
1120: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
1121: $section_headers,$section_values,$personnel_headers,$personnel_values);
1122:
1123: $crstypename = $env{'form.crstype'};
1124: if (ref($typename) eq 'HASH') {
1125: unless ($typename->{$env{'form.crstype'}} eq '') {
1126: $crstypename = $typename->{$env{'form.crstype'}};
1127: }
1128: }
1129:
1130: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
1131: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
1132:
1133: if ($env{'form.crstype'} eq 'official') {
1134: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
1135: foreach my $title (@{$codetitles}) {
1136: if ($env{'form.instcode_'.$title} ne '') {
1137: $inst_headers .= '<th>'.$title.'</th>';
1138: my $longitem = $env{'form.instcode_'.$title};
1139: if (ref($cat_titles->{$title}) eq 'HASH') {
1140: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
1141: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
1142: }
1143: }
1144: $inst_values .= '<td>'.$longitem.'</td>';
1145: }
1146: }
1147: }
1148: if (&Apache::lonnet::auto_run('',$dom)) {
1149: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
1150: '<th>'.&mt('Automatic Drops').'</th>'.
1151: '<th>'.&mt('Enrollment Starts').'</th>'.
1152: '<th>'.&mt('Enrollment Ends').'</th>';
1153: $section_headers = '<th>'.&mt('Sections').'</th>'.
1154: '<th>'.&mt('Crosslistings').'</th>';
1155:
1.13 raeburn 1156: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4 raeburn 1157: my @autoroster = (&mt('No'),&mt('Yes'));
1158: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
1159: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13 raeburn 1160: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
1161: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6 raeburn 1162: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
1163: &mt('Institutional section').'</th>'.
1164: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 1165: my $secinfo;
1.4 raeburn 1166: if ($env{'form.sectotal'} > 0) {
1167: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1168: if ($env{'form.sec_'.$i}) {
1.5 raeburn 1169: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 1170: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 1171: $secinfo .= $env{'form.loncapasec_'.$i};
1172: } else {
1173: $secinfo .= &mt('None');
1.4 raeburn 1174: }
1.5 raeburn 1175: $secinfo .= '</td></tr>';
1.4 raeburn 1176: }
1177: }
1178: }
1.6 raeburn 1179: if ($secinfo eq '') {
1180: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 1181: }
1.6 raeburn 1182: $section_values .= $secinfo.'</table></td><td>'.
1183: '<table class="LC_innerpickbox"><tr><th>'.
1184: &mt('Institutional course/section').'</th>'.
1185: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 1186: my $xlistinfo;
1.4 raeburn 1187: if ($env{'form.crosslisttotal'}) {
1188: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1189: if ($env{'form.crosslist_'.$i}) {
1.5 raeburn 1190: $xlistinfo .= '<tr><td>';
1191: if (ref($code_order) eq 'ARRAY') {
1192: if (@{$code_order} > 0) {
1193: foreach my $item (@{$code_order}) {
1194: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 1195: }
1196: }
1197: }
1.5 raeburn 1198: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
1.4 raeburn 1199: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
1.5 raeburn 1200: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
1201: } else {
1202: $xlistinfo .= &mt('None');
1.4 raeburn 1203: }
1.5 raeburn 1204: $xlistinfo .= '</td></tr>';
1.4 raeburn 1205: }
1206: }
1207: }
1.6 raeburn 1208: if ($xlistinfo eq '') {
1209: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 1210: }
1.6 raeburn 1211: $section_values .= $xlistinfo.'</table></td>';
1.4 raeburn 1212: }
1213: }
1214:
1215: my %ctxt = &clone_text();
1216: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1.13 raeburn 1217: if (($env{'form.clonecrs'} =~ /^$match_name$/) &&
1218: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1.15 ! raeburn 1219: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
! 1220: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
! 1221: if ($canclone) {
! 1222: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
! 1223: $env{'form.clonecrs'},('description','internal.coursecode'));
! 1224: if (keys(%courseenv) > 0) {
! 1225: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
! 1226: $inst_values .= '<td>'.$courseenv{'description'}.' ';
! 1227: my $cloneinst = $courseenv{'internal.coursecode'};
! 1228: if ($cloneinst ne '') {
! 1229: $inst_values .= &mt('([_1] in [_2])',$cloneinst,$env{'form.clonedom'});
! 1230: } else {
! 1231: $inst_values .= &mt('(from [_1])',$env{'form.clonedom'});
! 1232: }
! 1233: $inst_values .= '</td><td>';
! 1234: if ($env{'form.datemode'} eq 'preserve') {
! 1235: $inst_values .= $ctxt{'pcd'};
! 1236: } elsif ($env{'form.datemode'} eq 'shift') {
! 1237: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
! 1238: } else {
! 1239: $inst_values .= $ctxt{'ncd'};
! 1240: }
! 1241: $inst_values .= '</td>';
! 1242: } else {
! 1243: $inst_values .= '<td>'.&mt('Unknown').'</td>';
! 1244: }
! 1245: } else {
! 1246: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
! 1247: }
1.4 raeburn 1248: } else {
1249: $inst_values .= '<td>'.&mt('None').'</td>';
1250: }
1251: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
1252: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 1253: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1254: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
1255: if ($accessend == 0) {
1.4 raeburn 1256: $enroll_values .= '<td>'.&mt('No end date').'</td>';
1257: } else {
1.13 raeburn 1258: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 1259: }
1260:
1261: my $container = 'Course';
1262: if ($env{'form.crstype'} eq 'community') {
1263: $container = 'Community';
1264: }
1265:
1266: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
1267: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
1268: '</th>';
1269: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1270: '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
1271: '<td>'.&mt('None').'</td></tr>';
1272: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1273: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.14 raeburn 1274: my @allsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1275: my $newsec = $env{'form.person_'.$i.'_newsec'};
1276: $newsec =~ s/^\s+//;
1277: $newsec =~s/\s+$//;
1278: my @newsecs = split(/[\s,;]+/,$newsec);
1279: foreach my $sec (@newsecs) {
1280: next if ($sec =~ /\W/);
1281: next if ($newsec eq 'none');
1282: if ($sec ne '') {
1283: unless (grep(/^\Q$sec\E$/,@allsecs)) {
1284: push(@allsecs,$sec);
1285: }
1286: }
1287: }
1288: my $showsec = 'None';
1289: if (@allsecs) {
1290: $showsec = join(', ',@allsecs);
1291: }
1.4 raeburn 1292: $personnel_values .=
1.13 raeburn 1293: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
1294: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 1295: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
1296: $env{'form.person_'.$i.'_dom'}.'</td>'.
1297: '<td>'.&Apache::lonnet::plaintext($env{'form.person_'.$i.'_role'},
1298: $container).'</td>'.
1.14 raeburn 1299: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 1300: }
1301: }
1302: my $output = '<p>'.&mt('Review the details of the course request before submission.').'</p>'.
1303: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1304: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 1305: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 1306: '<th>'.&mt('Name').'</th>'.
1307: '<th>'.&mt('Username:Domain').'</th>'.
1308: '<th>'.&mt('E-mail address').'</th>'.
1309: '</tr><tr>'."\n".
1310: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
1311: '<td>'.$owneremail.'</td>'.
1312: '</tr></table>'."\n".
1313: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 1314: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 1315: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
1316: '<tr>'.$inst_values.'</tr></table>'."\n".
1317: &Apache::lonhtmlcommon::row_closure().
1318: &Apache::lonhtmlcommon::row_title(&mt('Enrollment')).
1319: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
1320: '<tr>'.$enroll_values.'</tr></table>'."\n".
1321: &Apache::lonhtmlcommon::row_closure();
1322: if ($section_headers ne '') {
1323: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
1324: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
1325: '<tr>'.$section_values.'</tr></table>'."\n".
1326: &Apache::lonhtmlcommon::row_closure();
1327: }
1328: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
1329: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
1330: $personnel_values.'</table>'."\n".
1331: &Apache::lonhtmlcommon::row_closure(1).
1332: &Apache::lonhtmlcommon::end_pick_box();
1.8 raeburn 1333: my $cnum = &Apache::lonnet::generate_coursenum($dom);
1334: $output .= '<input type="hidden" name="cnum" value="'.$cnum.'" />';
1.4 raeburn 1335: return $output;
1336: }
1337:
1338: sub dates_from_form {
1339: my ($startname,$endname) = @_;
1340: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1341: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 1342: if ($endname eq 'accessend') {
1.4 raeburn 1343: if (exists($env{'form.no_end_date'}) ) {
1344: $enddate = 0;
1345: }
1346: }
1347: return ($startdate,$enddate);
1.1 raeburn 1348: }
1349:
1350: sub courseinfo_form {
1.15 ! raeburn 1351: my ($dom,$formname,$crstype,$next) = @_;
! 1352: my $nodescr = &mt('You must provide a (brief) course description.');
! 1353: my $js_validate = <<"ENDJS";
! 1354: <script type="text/javascript">
! 1355: // <![CDATA['
! 1356:
! 1357: function validateForm() {
! 1358: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
! 1359: alert('$nodescr');
! 1360: return;
! 1361: }
! 1362: nextPage(document.$formname,'$next');
! 1363: }
! 1364: // ]]
! 1365: </script>
! 1366:
! 1367: ENDJS
! 1368:
! 1369: my $output .= $js_validate."\n".'<div>'.&Apache::lonhtmlcommon::start_pick_box().
! 1370: &Apache::lonhtmlcommon::row_title('Course Description').
1.13 raeburn 1371: '<input type="text" size="40" name="cdescr" />';
1372: my ($home_server_pick,$numlib) =
1373: &Apache::loncommon::home_server_form_item($dom,'chome',
1374: 'default','hide');
1375: if ($numlib > 1) {
1376: $output .= &Apache::lonhtmlcommon::row_closure().
1377: &Apache::lonhtmlcommon::row_title(
1378: &mt('Home Server for Course'));
1379: }
1380: $output .= $home_server_pick.
1381: &Apache::lonhtmlcommon::row_closure(1).
1382: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
1383: '<div>'.&clone_form($dom,$formname,$crstype).'</div>'."\n";
1.1 raeburn 1384: return $output;
1385: }
1386:
1387: sub clone_form {
1388: my ($dom,$formname,$crstype) = @_;
1389: my $type = 'Course';
1390: if ($crstype eq 'community') {
1391: $type = 'Community';
1392: }
1.13 raeburn 1393: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').
1394: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1.4 raeburn 1395: my %lt = &clone_text();
1.2 raeburn 1396: my $output .=
1397: &Apache::lonhtmlcommon::start_pick_box().
1398: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.13 raeburn 1399: '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();'.
1400: 'opencrsbrowser('."'$formname','clonecrs','clonedom','','','','$type'".');" />'.
1.2 raeburn 1401: '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
1402: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
1403: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure().
1404: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
1405: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
1406: '</label><br /><label>'.
1407: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
1408: '</label><br /><label>'.
1409: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
1410: $lt{'shd'}.'</label>'.
1411: '<input type="text" size="5" name="dateshift" value="365" />'.
1412: &Apache::lonhtmlcommon::row_closure(1).
1413: &Apache::lonhtmlcommon::end_pick_box();
1.1 raeburn 1414: return $output;
1415: }
1416:
1.4 raeburn 1417: sub clone_text {
1418: return &Apache::lonlocal::texthash(
1419: 'cid' => 'Course ID',
1420: 'dmn' => 'Domain',
1421: 'dsh' => 'Date Shift',
1422: 'ncd' => 'Do not clone date parameters',
1423: 'prd' => 'Clone date parameters as-is',
1424: 'shd' => 'Shift date parameters by number of days',
1425: );
1426: }
1427:
1.1 raeburn 1428: sub coursecode_form {
1.2 raeburn 1429: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 1430: my $output;
1.2 raeburn 1431: my %rowtitle = (
1432: instcode => 'Course Category',
1433: crosslist => 'Cross Listed Course',
1434: );
1.1 raeburn 1435: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
1436: (ref($cat_order))) {
1.2 raeburn 1437: my ($sel,$instsec,$lcsec);
1438: $sel = $context;
1439: if ($context eq 'crosslist') {
1440: $sel .= '_'.$num;
1441: $instsec = &mt('Institutional section').'<br />'.
1442: '<input type="text" size="10" name="'.$sel.'_instsec" />';
1443: $lcsec = &mt('LON-CAPA section').'<br />'.
1444: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
1445: }
1.1 raeburn 1446: if (@{$codetitles} > 0) {
1447: my $lastitem = pop(@{$codetitles});
1.2 raeburn 1448: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 1449: if (@{$codetitles} > 0) {
1.2 raeburn 1450: $output = &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1451: '<table><tr>';
1.1 raeburn 1452: if ($context eq 'crosslist') {
1.2 raeburn 1453: $output .= '<td>'.&mt('Include?').'<br />'.
1454: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 1455: }
1456: foreach my $title (@{$codetitles}) {
1457: if (ref($cat_order->{$title}) eq 'ARRAY') {
1458: if (@{$cat_order->{$title}} > 0) {
1459: $output .= '<td align="center">'.$title.'<br />'."\n".
1460: '<select name="'.$sel.'_'.$title.'">'."\n".
1461: ' <option value="" selected="selected">'.
1462: &mt('Select').'</option>'."\n";
1463: foreach my $item (@{$cat_order->{$title}}) {
1464: my $longitem = $item;
1465: if (ref($cat_titles->{$title}) eq 'HASH') {
1466: if ($cat_titles->{$title}{$item} ne '') {
1467: $longitem = $cat_titles->{$title}{$item};
1468: }
1469: }
1470: $output .= '<option value="'.$item.'">'.$longitem.
1471: '</option>'."\n";
1472: }
1473: }
1474: $output .= '</select></td>'."\n";
1475: }
1476: }
1477: if ($context eq 'crosslist') {
1478: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 1479: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
1480: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 1481: } else {
1482: $output .= '</tr></table>'.
1483: &Apache::lonhtmlcommon::row_closure().
1484: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1485: $lastinput;
1486: }
1487: } else {
1488: if ($context eq 'crosslist') {
1489: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 1490: '<table><tr>'.
1491: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
1492: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
1493: '</tr></table>';
1.1 raeburn 1494: } else {
1495: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1496: $lastinput;
1497: }
1498: }
1.2 raeburn 1499: $output .= &Apache::lonhtmlcommon::row_closure(1);
1500: push(@$codetitles,$lastitem);
1501: } elsif ($context eq 'crosslist') {
1502: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1503: '<table><tr><td align="center">'.
1504: '<span class="LC_nobreak">'.&mt('Include?').
1505: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
1506: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
1507: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
1508: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
1509: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 1510: }
1511: }
1512: return $output;
1513: }
1514:
1515: sub get_course_dom {
1516: my $codedom = &Apache::lonnet::default_login_domain();
1517: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1518: $codedom = $env{'user.domain'};
1519: if ($env{'request.role.domain'} ne '') {
1520: $codedom = $env{'request.role.domain'};
1521: }
1522: }
1523: if ($env{'form.showdom'} ne '') {
1524: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
1525: $codedom = $env{'form.showdom'};
1526: }
1527: }
1528: return $codedom;
1529: }
1530:
1531: sub display_navbuttons {
1.15 ! raeburn 1532: my ($r,$formname,$prev,$prevtext,$next,$nexttext,$state) = @_;
1.1 raeburn 1533: $r->print('<div class="LC_navbuttons">');
1534: if ($prev) {
1535: $r->print('
1536: <input type="button" name="previous" value = "'.$prevtext.'"
1537: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1538: ');
1539: } elsif ($prevtext) {
1540: $r->print('
1541: <input type="button" name="previous" value = "'.$prevtext.'"
1542: onclick="javascript:history.back()"/>
1543: ');
1544: }
1.15 ! raeburn 1545: if ($state eq 'courseinfo') {
! 1546: $r->print('
! 1547: <input type="button" name="next" value="'.$nexttext.'" onclick="javascript:validateForm();" />');
! 1548: } elsif ($next) {
1.1 raeburn 1549: $r->print('
1550: <input type="button" name="next" value="'.$nexttext.'"
1551: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1552: }
1553: $r->print('</div>');
1554: }
1555:
1556: sub print_request_outcome {
1.10 raeburn 1557: my ($dom,$codetitles,$code_order) = @_;
1.13 raeburn 1558: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10 raeburn 1559: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1560: $cnum = $env{'form.cnum'};
1.8 raeburn 1561: unless ($cnum =~ /^$match_courseid$/) {
1562: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
1563: return $output;
1564: }
1.11 raeburn 1565:
1.10 raeburn 1566: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 1567: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
1568: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
1569: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
1570: }
1571: }
1.10 raeburn 1572: $now = time;
1573: $crstype = $env{'form.crstype'};
1.8 raeburn 1574: if ($crstype eq 'official') {
1575: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 1576: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 1577: }
1.10 raeburn 1578: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1579: if ($env{'form.sec_'.$i}) {
1580: if ($env{'form.secnum_'.$i} ne '') {
1.13 raeburn 1581: $sections{$i}{'inst'} = $env{'form.secnum_'.$i};
1582: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.10 raeburn 1583: }
1584: }
1585: }
1586: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1587: if ($env{'form.crosslist_'.$i}) {
1588: my $xlistinfo = '';
1589: if (ref($code_order) eq 'ARRAY') {
1590: if (@{$code_order} > 0) {
1591: foreach my $item (@{$code_order}) {
1592: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1593: }
1594: }
1595: }
1596: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 1597: $crosslistings{$i}{'inst'} = $xlistinfo;
1598: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 1599: }
1600: }
1.14 raeburn 1601: } else {
1602: $enrollstart = '';
1603: $enrollend = '';
1.10 raeburn 1604: }
1605: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1606: my $uname = $env{'form.person_'.$i.'_uname'};
1607: my $udom = $env{'form.person_'.$i.'_uname'};
1608: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
1609: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 1610: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
1611: $personnel{$uname.':'.$udom} = {
1612: firstname => $env{'form.person_'.$i.'_firstname'},
1613: lastname => $env{'form.person_'.$i.'_lastname'},
1614: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
1615: };
1616: }
1617: my $role = $env{'form.person_'.$i.'_role'};
1618: unless ($role eq '') {
1619: if (ref(@{$personnel{$uname.':'.$udom}{'roles'}}) eq 'ARRAY') {
1620: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
1621: unless (grep(/^\Q$role\E$/,@curr_roles)) {
1622: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
1623: }
1624: } else {
1625: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
1626: }
1627: if ($role eq 'cc') {
1628: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
1629: } else {
1.14 raeburn 1630: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1631: my $newsec = $env{'form.person_'.$i.'_newsec'};
1632: $newsec =~ s/^\s+//;
1633: $newsec =~s/\s+$//;
1634: my @newsecs = split(/[\s,;]+/,$newsec);
1635: foreach my $sec (@newsecs) {
1636: next if ($sec =~ /\W/);
1637: next if ($newsec eq 'none');
1638: if ($sec ne '') {
1639: unless (grep(/^\Q$sec\E$/,@currsec)) {
1640: push(@currsec,$sec);
1.13 raeburn 1641: }
1642: }
1643: }
1644: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @currsec;
1645: }
1646: }
1.10 raeburn 1647: } else {
1648: push(@missingdom,$uname.':'.$udom);
1649: }
1650: } else {
1651: push(@baduname,$uname.':'.$udom);
1652: }
1.8 raeburn 1653: }
1.13 raeburn 1654: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 1655: my $autodrops = 0;
1656: if ($env{'form.autodrops'}) {
1657: $autodrops = $env{'form.autodrops'};
1658: }
1659: my $autoadds = 0;
1660: if ($env{'form.autoadds'}) {
1661: $autodrops = $env{'form.autoadds'};
1662: }
1663: my $sectotal = 0;
1664: if ($env{'form.sectotal'}) {
1665: $sectotal = $env{'form.sectotal'};
1666: }
1667: if ($env{'form.autoadds'}) {
1668: $autodrops = $env{'form.autoadds'};
1669: }
1670: my $crosslisttotal = 0;
1671: if ($env{'form.crosslisttotal'}) {
1672: $crosslisttotal = $env{'form.crosslisttotal'};
1673: }
1674: my $instcode = '';
1675: if (exists($env{'form.instcode'})) {
1676: $instcode = $env{'form.instcode'};
1677: }
1.15 ! raeburn 1678: my $clonecrs = '';
! 1679: my $clonedom = '';
! 1680: if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
! 1681: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
! 1682: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonedom'},$env{'form.clonecrs'});
! 1683: if ($clonehome ne 'no_host') {
! 1684: my $canclone = &can_clone_course($env{'user.name'},$env{'user.domain'},
! 1685: $env{'form.clonecrs'}, $env{'form.clonedom'});
! 1686: if ($canclone) {
! 1687: $clonecrs = $env{'form.clonecrs'};
! 1688: $clonedom = $env{'form.clonedom'};
! 1689: }
! 1690: }
! 1691: }
1.8 raeburn 1692: my $details = {
1.10 raeburn 1693: owner => $env{'user.name'},
1694: domain => $env{'user.domain'},
1695: cdom => $dom,
1.11 raeburn 1696: cnum => $cnum,
1.13 raeburn 1697: coursehome => $env{'form.chome'},
1698: cdescr => $env{'form.cdescr'},
1.10 raeburn 1699: crstype => $env{'form.crstype'},
1.14 raeburn 1700: instcode => $instcode,
1.15 ! raeburn 1701: clonedom => $clonedom,
! 1702: clonecrs => $clonecrs,
1.10 raeburn 1703: datemode => $env{'form.datemode'},
1.14 raeburn 1704: dateshift => $env{'form.dateshift'},
1705: sectotal => $sectotal,
1.10 raeburn 1706: sections => \%sections,
1.14 raeburn 1707: crosslisttotal => $crosslisttotal,
1.13 raeburn 1708: crosslists => \%crosslistings,
1.14 raeburn 1709: autoadds => $autoadds,
1710: autodrops => $autodrops,
1.13 raeburn 1711: enrollstart => $enrollstart,
1712: enrollend => $enrollend,
1713: accessstart => $accessstart,
1714: accessend => $accessend,
1.10 raeburn 1715: personnel => \%personnel,
1.8 raeburn 1716: };
1717: my @inststatuses;
1.9 raeburn 1718: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 1719: if ($val eq '') {
1720: if ($crstype eq 'official') {
1721: $output = &mt('You are not permitted to request creation of official courses');
1722: } elsif ($crstype eq 'unofficial') {
1723: $output = &mt('You are not permitted to request creation of unofficial courses');
1724: } elsif ($crstype eq 'community') {
1725: $output = &mt('You are not permitted to request creation of communities');
1726: } else {
1727: $output = &mt('Unrecognized course type: [_1]',$crstype);
1728: }
1729: } else {
1.14 raeburn 1730: my ($disposition,$message,$reqstatus);
1.8 raeburn 1731: my %reqhash = (
1.14 raeburn 1732: reqtime => $now,
1.10 raeburn 1733: crstype => $crstype,
1734: details => $details,
1.8 raeburn 1735: );
1736: my $requestkey = $dom.'_'.$cnum;
1.10 raeburn 1737: if ($val eq 'autolimit=') {
1738: $disposition = 'process';
1739: } elsif ($val =~ /^autolimit=(\d+)$/) {
1740: my $limit = $1;
1.8 raeburn 1741: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 1742: $dom,$crstype,$limit,\$message);
1.8 raeburn 1743: } elsif ($val eq 'validate') {
1744: $disposition =
1745: &Apache::lonnet::auto_courserequest_validation($dom,$details,
1746: \@inststatuses,\$message);
1747: } else {
1748: $disposition = 'approval';
1749: }
1.14 raeburn 1750: $reqhash{'disposition'} = $disposition;
1751: $reqstatus = $disposition;
1.8 raeburn 1752: if ($disposition eq 'rejected') {
1753: $output = &mt('Your course request was rejected.');
1754: if ($message) {
1755: $output .= '<div class="LC_warning">'.$message.'</div>';
1756: }
1757: } elsif ($disposition eq 'process') {
1.14 raeburn 1758: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1759: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
1760: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 1761: my $type = 'Course';
1762: if ($crstype eq 'community') {
1763: $type = 'Community';
1764: }
1765: foreach my $role (@roles) {
1766: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
1767: }
1.14 raeburn 1768: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
1769: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
1770: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
1771: if ($result eq 'created') {
1.8 raeburn 1772: $disposition = 'created';
1.14 raeburn 1773: $reqstatus = 'created';
1774: $output = &mt('Your course request has been processed and the course has been created.').
1775: '<br />'.
1776: &mt('You will need to logout and log-in again to be able to select a role in the course.');
1.8 raeburn 1777: } else {
1.14 raeburn 1778: $output = '<span class="LC_error">'.
1779: &mt('An error occurred when processing your course request.').
1780: '<br />'.
1781: &mt('You may want to review the request details and submit the request again.').
1782: '</span>';
1.8 raeburn 1783: }
1784: } else {
1785: my $requestid = $cnum.'_'.$disposition;
1786: my $request = {
1787: $requestid => {
1788: timestamp => $now,
1789: crstype => $crstype,
1790: ownername => $env{'user.name'},
1791: ownerdom => $env{'user.domain'},
1.13 raeburn 1792: description => $env{'form.cdescr'},
1.8 raeburn 1793: },
1794: };
1795: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
1796: $dom);
1797: if ($putresult eq 'ok') {
1798: my %emails = &Apache::loncommon::getemails();
1799: my $address;
1800: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
1801: $address = $emails{'permanentemail'};
1802: if ($address eq '') {
1803: $address = $emails{'notification'};
1804: }
1805: }
1806: $output = &mt('Your course request has been recorded.').'<br />';
1807: if ($disposition eq 'approval') {
1.14 raeburn 1808: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
1809: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
1.8 raeburn 1810: if ($address ne '') {
1811: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
1812: }
1813: if ($req_notifylist) {
1814: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
1815: $env{'user.domain'});
1.14 raeburn 1816: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
1817: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
1.8 raeburn 1818: }
1819: } else {
1820: $output .= '<div class="LC_info">'.
1821: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
1822: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
1823: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
1824: '</div>';
1825: }
1826: } else {
1.14 raeburn 1827: $reqstatus = 'domainerror';
1.8 raeburn 1828: $reqhash{'disposition'} = $disposition;
1829: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
1830: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1831:
1832: }
1833: }
1.14 raeburn 1834: my ($storeresult,$statusresult);
1.10 raeburn 1835: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1836: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
1837: 'courserequests');
1.14 raeburn 1838: if ($storeresult eq 'ok') {
1839: my %status = (
1840: 'status:'.$dom.':'.$cnum => $reqstatus,
1841: );
1842: $statusresult = &Apache::lonnet::put('courserequests',\%status);
1843: }
1.10 raeburn 1844: } else {
1845: $storeresult = 'error: invalid requestkey format';
1846: }
1.8 raeburn 1847: if ($storeresult ne 'ok') {
1.13 raeburn 1848: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
1849: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1.14 raeburn 1850: } elsif ($statusresult ne 'ok') {
1851: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
1852: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
1.8 raeburn 1853: }
1854: }
1855: return $output;
1856: }
1857:
1858: sub get_processtype {
1.9 raeburn 1859: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
1860: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1.8 raeburn 1861: my (%userenv,%settings,$val);
1862: my @options = ('autolimit','validate','approve');
1863: if ($dom eq $env{'user.domain'}) {
1864: %userenv =
1865: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
1866: 'requestcourses.'.$crstype,'inststatus');
1867: if ($userenv{'requestcourses.'.$crstype}) {
1868: $val = $userenv{'requestcourses.'.$crstype};
1869: @{$inststatuses} = ('_custom_');
1870: } else {
1871: my ($task,%alltasks);
1.9 raeburn 1872: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
1873: %settings = %{$domconfig->{'requestcourses'}};
1.8 raeburn 1874: if (ref($settings{$crstype}) eq 'HASH') {
1875: if (($env{'user.adv'}) && (exists($settings{$crstype}{'_LC_adv'}))) {
1876: $val = $settings{$crstype}{'_LC_adv'};
1877: @{$inststatuses} = ('_LC_adv_');
1878: } else {
1879: if ($userenv{'inststatus'} ne '') {
1880: @{$inststatuses} = split(',',$userenv{'inststatus'});
1881: } else {
1.13 raeburn 1882: @{$inststatuses} = ('default');
1.8 raeburn 1883: }
1884: foreach my $status (@{$inststatuses}) {
1885: if (exists($settings{$crstype}{$status})) {
1886: my $value = $settings{$crstype}{$status};
1887: next unless ($value);
1888: unless (exists($alltasks{$value})) {
1889: if (ref($alltasks{$value}) eq 'ARRAY') {
1890: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
1891: push(@{$alltasks{$value}},$status);
1892: }
1893: } else {
1894: @{$alltasks{$value}} = ($status);
1895: }
1896: }
1897: }
1898: }
1899: my $maxlimit = 0;
1.13 raeburn 1900:
1.8 raeburn 1901: foreach my $key (sort(keys(%alltasks))) {
1902: if ($key =~ /^autolimit=(\d*)$/) {
1903: if ($1 eq '') {
1904: $val ='autolimit=';
1905: last;
1906: } elsif ($1 > $maxlimit) {
1907: $maxlimit = $1;
1908: }
1909: }
1910: }
1911: if ($maxlimit) {
1912: $val = 'autolimit='.$maxlimit;
1913: } else {
1914: foreach my $option (@options) {
1915: if ($alltasks{$option}) {
1916: $val = $option;
1917: last;
1918: }
1919: }
1920: }
1921: }
1922: }
1923: }
1924: }
1925: } else {
1926: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
1927: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1928: if ($userenv{'reqcrsotherdom'}) {
1929: my @doms = split(',',$userenv{'reqcrsotherdom'});
1930: my $optregex = join('|',@options);
1931: if (grep(/^\Q$dom\E:($optregex=?\d*)/,@doms)) {
1932: $val = $1;
1933: }
1934: @{$inststatuses} = ('_external_');
1935: }
1936: }
1937: return $val;
1938: }
1939:
1940: sub check_autolimit {
1.10 raeburn 1941: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
1942: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
1943: 'userroles',['active','future'],['cc'],[$dom]);
1944: my ($types,$typename) = &course_types();
1945: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
1946: my %count;
1947: if (ref($types) eq 'ARRAY') {
1948: foreach my $type (@{$types}) {
1949: $count{$type} = 0;
1950: }
1951: }
1952: foreach my $key (keys(%requests)) {
1953: my ($cdom,$cnum) = split('_',$key);
1954: if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
1955: if (ref($requests{$key}) eq 'HASH') {
1956: my $type = $requests{$key}{'crstype'};
1957: if ($type =~ /^official|unofficial|community$/) {
1958: $count{$type} ++;
1959: }
1960: }
1961: }
1962: }
1963: if ($count{$crstype} < $limit) {
1964: return 'process';
1965: } else {
1966: if (ref($typename) eq 'HASH') {
1967: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').'<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
1968: }
1969: return 'rejected';
1970: }
1.1 raeburn 1971: return;
1972: }
1973:
1.2 raeburn 1974: sub retrieve_settings {
1975: my ($dom,$request_id) = @_;
1976: my %reqinfo = &get_request_settings($request_id,$dom);
1977: my %stored;
1978: $stored{'cdescr'} = &unescape($reqinfo{'description'});
1.13 raeburn 1979: $stored{'accessstart'} = $reqinfo{'accessstart'};
1980: $stored{'accessend'} = $reqinfo{'accessend'};
1981: if ($stored{'accessend'} == 0) {
1.2 raeburn 1982: $stored{'no_end_date'} = 1;
1983: }
1.13 raeburn 1984: $stored{'enrollstart'} = $reqinfo{'enrollstart'};
1985: $stored{'enrollend'} = $reqinfo{'enrollend'};
1.2 raeburn 1986: $stored{'crosslist'} = $reqinfo{'crosslist'};
1.13 raeburn 1987: $stored{'clonecrs'} = $reqinfo{'clonecrs'};
1988: $stored{'clonedom'} = $reqinfo{'clonedom'};
1.2 raeburn 1989: $stored{'sections'} = $reqinfo{'sections'};
1990: $stored{'personnel'} = $reqinfo{'personnel'};
1991:
1992: return %stored;
1993: }
1994:
1995: sub get_request_settings {
1996: my ($request_id,$dom);
1997: }
1998:
1.1 raeburn 1999: 1;
2000:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>