Annotation of loncom/interface/lonrequestcourse.pm, revision 1.14
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.14 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.13 2009/08/15 01:59:04 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 {
692: $r->print(&courseinfo_form($dom,$formname,$crstype));
693: }
694: } else {
695: $r->print(&courseinfo_form($dom,$formname,$crstype));
1.1 raeburn 696: }
1.2 raeburn 697: } elsif ($prev eq 'codepick') {
698: $r->print(&courseinfo_form($dom,$formname,$crstype));
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.4 raeburn 746: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'});
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.4 raeburn 1219: my %coursehash =
1.13 raeburn 1220: &Apache::lonnet::courseiddump($env{'form.clonedom'},'.',1,'.','.',
1221: $env{'form.clonecrs'},undef,undef,'.');
1222: my $cloneid = $env{'form.clonedom'}.'_'.$env{'form.clonecrs'};
1.4 raeburn 1223: if (ref($coursehash{$cloneid}) eq 'HASH') {
1224: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
1225: my $clonedesc = $coursehash{$cloneid}{'description'};
1226: my $cloneinst = $coursehash{$cloneid}{'inst_code'};
1227:
1228: $inst_values .= '<td>'.$clonedesc.' ';
1229: if ($cloneinst ne '') {
1.13 raeburn 1230: $inst_values .= &mt('([_1] in [_2])',$cloneinst,$env{'form.clonedom'});
1.4 raeburn 1231: } else {
1.13 raeburn 1232: $inst_values .= &mt('(from [_1])',$env{'form.clonedom'});
1.4 raeburn 1233: }
1234: $inst_values .= '</td><td>';
1235: if ($env{'form.datemode'} eq 'preserve') {
1236: $inst_values .= $ctxt{'pcd'};
1237: } elsif ($env{'form.datemode'} eq 'shift') {
1238: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
1239: } else {
1240: $inst_values .= $ctxt{'ncd'};
1241: }
1242: $inst_values .= '</td>';
1243: } else {
1244: $inst_values .= '<td>'.&mt('Unknown').'</td>';
1245: }
1246: } else {
1247: $inst_values .= '<td>'.&mt('None').'</td>';
1248: }
1249: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
1250: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 1251: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1252: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
1253: if ($accessend == 0) {
1.4 raeburn 1254: $enroll_values .= '<td>'.&mt('No end date').'</td>';
1255: } else {
1.13 raeburn 1256: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 1257: }
1258:
1259: my $container = 'Course';
1260: if ($env{'form.crstype'} eq 'community') {
1261: $container = 'Community';
1262: }
1263:
1264: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
1265: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
1266: '</th>';
1267: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1268: '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
1269: '<td>'.&mt('None').'</td></tr>';
1270: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1271: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.14 ! raeburn 1272: my @allsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
! 1273: my $newsec = $env{'form.person_'.$i.'_newsec'};
! 1274: $newsec =~ s/^\s+//;
! 1275: $newsec =~s/\s+$//;
! 1276: my @newsecs = split(/[\s,;]+/,$newsec);
! 1277: foreach my $sec (@newsecs) {
! 1278: next if ($sec =~ /\W/);
! 1279: next if ($newsec eq 'none');
! 1280: if ($sec ne '') {
! 1281: unless (grep(/^\Q$sec\E$/,@allsecs)) {
! 1282: push(@allsecs,$sec);
! 1283: }
! 1284: }
! 1285: }
! 1286: my $showsec = 'None';
! 1287: if (@allsecs) {
! 1288: $showsec = join(', ',@allsecs);
! 1289: }
1.4 raeburn 1290: $personnel_values .=
1.13 raeburn 1291: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
1292: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 1293: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
1294: $env{'form.person_'.$i.'_dom'}.'</td>'.
1295: '<td>'.&Apache::lonnet::plaintext($env{'form.person_'.$i.'_role'},
1296: $container).'</td>'.
1.14 ! raeburn 1297: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 1298: }
1299: }
1300: my $output = '<p>'.&mt('Review the details of the course request before submission.').'</p>'.
1301: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1302: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 1303: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 1304: '<th>'.&mt('Name').'</th>'.
1305: '<th>'.&mt('Username:Domain').'</th>'.
1306: '<th>'.&mt('E-mail address').'</th>'.
1307: '</tr><tr>'."\n".
1308: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
1309: '<td>'.$owneremail.'</td>'.
1310: '</tr></table>'."\n".
1311: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 1312: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 1313: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
1314: '<tr>'.$inst_values.'</tr></table>'."\n".
1315: &Apache::lonhtmlcommon::row_closure().
1316: &Apache::lonhtmlcommon::row_title(&mt('Enrollment')).
1317: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
1318: '<tr>'.$enroll_values.'</tr></table>'."\n".
1319: &Apache::lonhtmlcommon::row_closure();
1320: if ($section_headers ne '') {
1321: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
1322: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
1323: '<tr>'.$section_values.'</tr></table>'."\n".
1324: &Apache::lonhtmlcommon::row_closure();
1325: }
1326: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
1327: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
1328: $personnel_values.'</table>'."\n".
1329: &Apache::lonhtmlcommon::row_closure(1).
1330: &Apache::lonhtmlcommon::end_pick_box();
1.8 raeburn 1331: my $cnum = &Apache::lonnet::generate_coursenum($dom);
1332: $output .= '<input type="hidden" name="cnum" value="'.$cnum.'" />';
1.4 raeburn 1333: return $output;
1334: }
1335:
1336: sub dates_from_form {
1337: my ($startname,$endname) = @_;
1338: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1339: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 1340: if ($endname eq 'accessend') {
1.4 raeburn 1341: if (exists($env{'form.no_end_date'}) ) {
1342: $enddate = 0;
1343: }
1344: }
1345: return ($startdate,$enddate);
1.1 raeburn 1346: }
1347:
1348: sub courseinfo_form {
1.2 raeburn 1349: my ($dom,$formname,$crstype) = @_;
1350: my $output = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1351: &Apache::lonhtmlcommon::row_title('Course Description').
1.13 raeburn 1352: '<input type="text" size="40" name="cdescr" />';
1353: my ($home_server_pick,$numlib) =
1354: &Apache::loncommon::home_server_form_item($dom,'chome',
1355: 'default','hide');
1356: if ($numlib > 1) {
1357: $output .= &Apache::lonhtmlcommon::row_closure().
1358: &Apache::lonhtmlcommon::row_title(
1359: &mt('Home Server for Course'));
1360: }
1361: $output .= $home_server_pick.
1362: &Apache::lonhtmlcommon::row_closure(1).
1363: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
1364: '<div>'.&clone_form($dom,$formname,$crstype).'</div>'."\n";
1.1 raeburn 1365: return $output;
1366: }
1367:
1368: sub clone_form {
1369: my ($dom,$formname,$crstype) = @_;
1370: my $type = 'Course';
1371: if ($crstype eq 'community') {
1372: $type = 'Community';
1373: }
1.13 raeburn 1374: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').
1375: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1.4 raeburn 1376: my %lt = &clone_text();
1.2 raeburn 1377: my $output .=
1378: &Apache::lonhtmlcommon::start_pick_box().
1379: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.13 raeburn 1380: '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();'.
1381: 'opencrsbrowser('."'$formname','clonecrs','clonedom','','','','$type'".');" />'.
1.2 raeburn 1382: '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
1383: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
1384: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure().
1385: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
1386: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
1387: '</label><br /><label>'.
1388: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
1389: '</label><br /><label>'.
1390: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
1391: $lt{'shd'}.'</label>'.
1392: '<input type="text" size="5" name="dateshift" value="365" />'.
1393: &Apache::lonhtmlcommon::row_closure(1).
1394: &Apache::lonhtmlcommon::end_pick_box();
1.1 raeburn 1395: return $output;
1396: }
1397:
1.4 raeburn 1398: sub clone_text {
1399: return &Apache::lonlocal::texthash(
1400: 'cid' => 'Course ID',
1401: 'dmn' => 'Domain',
1402: 'dsh' => 'Date Shift',
1403: 'ncd' => 'Do not clone date parameters',
1404: 'prd' => 'Clone date parameters as-is',
1405: 'shd' => 'Shift date parameters by number of days',
1406: );
1407: }
1408:
1.1 raeburn 1409: sub coursecode_form {
1.2 raeburn 1410: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 1411: my $output;
1.2 raeburn 1412: my %rowtitle = (
1413: instcode => 'Course Category',
1414: crosslist => 'Cross Listed Course',
1415: );
1.1 raeburn 1416: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
1417: (ref($cat_order))) {
1.2 raeburn 1418: my ($sel,$instsec,$lcsec);
1419: $sel = $context;
1420: if ($context eq 'crosslist') {
1421: $sel .= '_'.$num;
1422: $instsec = &mt('Institutional section').'<br />'.
1423: '<input type="text" size="10" name="'.$sel.'_instsec" />';
1424: $lcsec = &mt('LON-CAPA section').'<br />'.
1425: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
1426: }
1.1 raeburn 1427: if (@{$codetitles} > 0) {
1428: my $lastitem = pop(@{$codetitles});
1.2 raeburn 1429: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 1430: if (@{$codetitles} > 0) {
1.2 raeburn 1431: $output = &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1432: '<table><tr>';
1.1 raeburn 1433: if ($context eq 'crosslist') {
1.2 raeburn 1434: $output .= '<td>'.&mt('Include?').'<br />'.
1435: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 1436: }
1437: foreach my $title (@{$codetitles}) {
1438: if (ref($cat_order->{$title}) eq 'ARRAY') {
1439: if (@{$cat_order->{$title}} > 0) {
1440: $output .= '<td align="center">'.$title.'<br />'."\n".
1441: '<select name="'.$sel.'_'.$title.'">'."\n".
1442: ' <option value="" selected="selected">'.
1443: &mt('Select').'</option>'."\n";
1444: foreach my $item (@{$cat_order->{$title}}) {
1445: my $longitem = $item;
1446: if (ref($cat_titles->{$title}) eq 'HASH') {
1447: if ($cat_titles->{$title}{$item} ne '') {
1448: $longitem = $cat_titles->{$title}{$item};
1449: }
1450: }
1451: $output .= '<option value="'.$item.'">'.$longitem.
1452: '</option>'."\n";
1453: }
1454: }
1455: $output .= '</select></td>'."\n";
1456: }
1457: }
1458: if ($context eq 'crosslist') {
1459: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 1460: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
1461: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 1462: } else {
1463: $output .= '</tr></table>'.
1464: &Apache::lonhtmlcommon::row_closure().
1465: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1466: $lastinput;
1467: }
1468: } else {
1469: if ($context eq 'crosslist') {
1470: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 1471: '<table><tr>'.
1472: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
1473: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
1474: '</tr></table>';
1.1 raeburn 1475: } else {
1476: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1477: $lastinput;
1478: }
1479: }
1.2 raeburn 1480: $output .= &Apache::lonhtmlcommon::row_closure(1);
1481: push(@$codetitles,$lastitem);
1482: } elsif ($context eq 'crosslist') {
1483: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1484: '<table><tr><td align="center">'.
1485: '<span class="LC_nobreak">'.&mt('Include?').
1486: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
1487: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
1488: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
1489: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
1490: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 1491: }
1492: }
1493: return $output;
1494: }
1495:
1496: sub get_course_dom {
1497: my $codedom = &Apache::lonnet::default_login_domain();
1498: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1499: $codedom = $env{'user.domain'};
1500: if ($env{'request.role.domain'} ne '') {
1501: $codedom = $env{'request.role.domain'};
1502: }
1503: }
1504: if ($env{'form.showdom'} ne '') {
1505: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
1506: $codedom = $env{'form.showdom'};
1507: }
1508: }
1509: return $codedom;
1510: }
1511:
1512: sub display_navbuttons {
1513: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1514: $r->print('<div class="LC_navbuttons">');
1515: if ($prev) {
1516: $r->print('
1517: <input type="button" name="previous" value = "'.$prevtext.'"
1518: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1519: ');
1520: } elsif ($prevtext) {
1521: $r->print('
1522: <input type="button" name="previous" value = "'.$prevtext.'"
1523: onclick="javascript:history.back()"/>
1524: ');
1525: }
1526: if ($next) {
1527: $r->print('
1528: <input type="button" name="next" value="'.$nexttext.'"
1529: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1530: }
1531: $r->print('</div>');
1532: }
1533:
1534: sub print_request_outcome {
1.10 raeburn 1535: my ($dom,$codetitles,$code_order) = @_;
1.13 raeburn 1536: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10 raeburn 1537: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1538: $cnum = $env{'form.cnum'};
1.8 raeburn 1539: unless ($cnum =~ /^$match_courseid$/) {
1540: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
1541: return $output;
1542: }
1.11 raeburn 1543:
1.10 raeburn 1544: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 1545: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
1546: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
1547: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
1548: }
1549: }
1.10 raeburn 1550: $now = time;
1551: $crstype = $env{'form.crstype'};
1.8 raeburn 1552: if ($crstype eq 'official') {
1553: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 1554: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 1555: }
1.10 raeburn 1556: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1557: if ($env{'form.sec_'.$i}) {
1558: if ($env{'form.secnum_'.$i} ne '') {
1.13 raeburn 1559: $sections{$i}{'inst'} = $env{'form.secnum_'.$i};
1560: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.10 raeburn 1561: }
1562: }
1563: }
1564: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1565: if ($env{'form.crosslist_'.$i}) {
1566: my $xlistinfo = '';
1567: if (ref($code_order) eq 'ARRAY') {
1568: if (@{$code_order} > 0) {
1569: foreach my $item (@{$code_order}) {
1570: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1571: }
1572: }
1573: }
1574: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 1575: $crosslistings{$i}{'inst'} = $xlistinfo;
1576: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 1577: }
1578: }
1.14 ! raeburn 1579: } else {
! 1580: $enrollstart = '';
! 1581: $enrollend = '';
1.10 raeburn 1582: }
1583: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1584: my $uname = $env{'form.person_'.$i.'_uname'};
1585: my $udom = $env{'form.person_'.$i.'_uname'};
1586: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
1587: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 1588: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
1589: $personnel{$uname.':'.$udom} = {
1590: firstname => $env{'form.person_'.$i.'_firstname'},
1591: lastname => $env{'form.person_'.$i.'_lastname'},
1592: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
1593: };
1594: }
1595: my $role = $env{'form.person_'.$i.'_role'};
1596: unless ($role eq '') {
1597: if (ref(@{$personnel{$uname.':'.$udom}{'roles'}}) eq 'ARRAY') {
1598: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
1599: unless (grep(/^\Q$role\E$/,@curr_roles)) {
1600: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
1601: }
1602: } else {
1603: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
1604: }
1605: if ($role eq 'cc') {
1606: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
1607: } else {
1.14 ! raeburn 1608: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
! 1609: my $newsec = $env{'form.person_'.$i.'_newsec'};
! 1610: $newsec =~ s/^\s+//;
! 1611: $newsec =~s/\s+$//;
! 1612: my @newsecs = split(/[\s,;]+/,$newsec);
! 1613: foreach my $sec (@newsecs) {
! 1614: next if ($sec =~ /\W/);
! 1615: next if ($newsec eq 'none');
! 1616: if ($sec ne '') {
! 1617: unless (grep(/^\Q$sec\E$/,@currsec)) {
! 1618: push(@currsec,$sec);
1.13 raeburn 1619: }
1620: }
1621: }
1622: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @currsec;
1623: }
1624: }
1.10 raeburn 1625: } else {
1626: push(@missingdom,$uname.':'.$udom);
1627: }
1628: } else {
1629: push(@baduname,$uname.':'.$udom);
1630: }
1.8 raeburn 1631: }
1.13 raeburn 1632: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 ! raeburn 1633: my $autodrops = 0;
! 1634: if ($env{'form.autodrops'}) {
! 1635: $autodrops = $env{'form.autodrops'};
! 1636: }
! 1637: my $autoadds = 0;
! 1638: if ($env{'form.autoadds'}) {
! 1639: $autodrops = $env{'form.autoadds'};
! 1640: }
! 1641: my $sectotal = 0;
! 1642: if ($env{'form.sectotal'}) {
! 1643: $sectotal = $env{'form.sectotal'};
! 1644: }
! 1645: if ($env{'form.autoadds'}) {
! 1646: $autodrops = $env{'form.autoadds'};
! 1647: }
! 1648: my $crosslisttotal = 0;
! 1649: if ($env{'form.crosslisttotal'}) {
! 1650: $crosslisttotal = $env{'form.crosslisttotal'};
! 1651: }
! 1652: my $instcode = '';
! 1653: if (exists($env{'form.instcode'})) {
! 1654: $instcode = $env{'form.instcode'};
! 1655: }
1.8 raeburn 1656: my $details = {
1.10 raeburn 1657: owner => $env{'user.name'},
1658: domain => $env{'user.domain'},
1659: cdom => $dom,
1.11 raeburn 1660: cnum => $cnum,
1.13 raeburn 1661: coursehome => $env{'form.chome'},
1662: cdescr => $env{'form.cdescr'},
1.10 raeburn 1663: crstype => $env{'form.crstype'},
1.14 ! raeburn 1664: instcode => $instcode,
1.13 raeburn 1665: clonedom => $env{'form.clonedom'},
1666: clonecrs => $env{'form.clonecrs'},
1.10 raeburn 1667: datemode => $env{'form.datemode'},
1.14 ! raeburn 1668: dateshift => $env{'form.dateshift'},
! 1669: sectotal => $sectotal,
1.10 raeburn 1670: sections => \%sections,
1.14 ! raeburn 1671: crosslisttotal => $crosslisttotal,
1.13 raeburn 1672: crosslists => \%crosslistings,
1.14 ! raeburn 1673: autoadds => $autoadds,
! 1674: autodrops => $autodrops,
1.13 raeburn 1675: enrollstart => $enrollstart,
1676: enrollend => $enrollend,
1677: accessstart => $accessstart,
1678: accessend => $accessend,
1.10 raeburn 1679: personnel => \%personnel,
1.8 raeburn 1680: };
1681: my @inststatuses;
1.9 raeburn 1682: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 1683: if ($val eq '') {
1684: if ($crstype eq 'official') {
1685: $output = &mt('You are not permitted to request creation of official courses');
1686: } elsif ($crstype eq 'unofficial') {
1687: $output = &mt('You are not permitted to request creation of unofficial courses');
1688: } elsif ($crstype eq 'community') {
1689: $output = &mt('You are not permitted to request creation of communities');
1690: } else {
1691: $output = &mt('Unrecognized course type: [_1]',$crstype);
1692: }
1693: } else {
1.14 ! raeburn 1694: my ($disposition,$message,$reqstatus);
1.8 raeburn 1695: my %reqhash = (
1.14 ! raeburn 1696: reqtime => $now,
1.10 raeburn 1697: crstype => $crstype,
1698: details => $details,
1.8 raeburn 1699: );
1700: my $requestkey = $dom.'_'.$cnum;
1.10 raeburn 1701: if ($val eq 'autolimit=') {
1702: $disposition = 'process';
1703: } elsif ($val =~ /^autolimit=(\d+)$/) {
1704: my $limit = $1;
1.8 raeburn 1705: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 1706: $dom,$crstype,$limit,\$message);
1.8 raeburn 1707: } elsif ($val eq 'validate') {
1708: $disposition =
1709: &Apache::lonnet::auto_courserequest_validation($dom,$details,
1710: \@inststatuses,\$message);
1711: } else {
1712: $disposition = 'approval';
1713: }
1.14 ! raeburn 1714: $reqhash{'disposition'} = $disposition;
! 1715: $reqstatus = $disposition;
1.8 raeburn 1716: if ($disposition eq 'rejected') {
1717: $output = &mt('Your course request was rejected.');
1718: if ($message) {
1719: $output .= '<div class="LC_warning">'.$message.'</div>';
1720: }
1721: } elsif ($disposition eq 'process') {
1.14 ! raeburn 1722: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
! 1723: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
! 1724: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 1725: my $type = 'Course';
1726: if ($crstype eq 'community') {
1727: $type = 'Community';
1728: }
1729: foreach my $role (@roles) {
1730: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
1731: }
1.14 ! raeburn 1732: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
! 1733: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
! 1734: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
! 1735: if ($result eq 'created') {
1.8 raeburn 1736: $disposition = 'created';
1.14 ! raeburn 1737: $reqstatus = 'created';
! 1738: $output = &mt('Your course request has been processed and the course has been created.').
! 1739: '<br />'.
! 1740: &mt('You will need to logout and log-in again to be able to select a role in the course.');
1.8 raeburn 1741: } else {
1.14 ! raeburn 1742: $output = '<span class="LC_error">'.
! 1743: &mt('An error occurred when processing your course request.').
! 1744: '<br />'.
! 1745: &mt('You may want to review the request details and submit the request again.').
! 1746: '</span>';
1.8 raeburn 1747: }
1748: } else {
1749: my $requestid = $cnum.'_'.$disposition;
1750: my $request = {
1751: $requestid => {
1752: timestamp => $now,
1753: crstype => $crstype,
1754: ownername => $env{'user.name'},
1755: ownerdom => $env{'user.domain'},
1.13 raeburn 1756: description => $env{'form.cdescr'},
1.8 raeburn 1757: },
1758: };
1759: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
1760: $dom);
1761: if ($putresult eq 'ok') {
1762: my %emails = &Apache::loncommon::getemails();
1763: my $address;
1764: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
1765: $address = $emails{'permanentemail'};
1766: if ($address eq '') {
1767: $address = $emails{'notification'};
1768: }
1769: }
1770: $output = &mt('Your course request has been recorded.').'<br />';
1771: if ($disposition eq 'approval') {
1.14 ! raeburn 1772: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
! 1773: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
1.8 raeburn 1774: if ($address ne '') {
1775: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
1776: }
1777: if ($req_notifylist) {
1778: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
1779: $env{'user.domain'});
1.14 ! raeburn 1780: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
! 1781: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
1.8 raeburn 1782: }
1783: } else {
1784: $output .= '<div class="LC_info">'.
1785: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
1786: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
1787: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
1788: '</div>';
1789: }
1790: } else {
1.14 ! raeburn 1791: $reqstatus = 'domainerror';
1.8 raeburn 1792: $reqhash{'disposition'} = $disposition;
1793: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
1794: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1795:
1796: }
1797: }
1.14 ! raeburn 1798: my ($storeresult,$statusresult);
1.10 raeburn 1799: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1800: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
1801: 'courserequests');
1.14 ! raeburn 1802: if ($storeresult eq 'ok') {
! 1803: my %status = (
! 1804: 'status:'.$dom.':'.$cnum => $reqstatus,
! 1805: );
! 1806: $statusresult = &Apache::lonnet::put('courserequests',\%status);
! 1807: }
1.10 raeburn 1808: } else {
1809: $storeresult = 'error: invalid requestkey format';
1810: }
1.8 raeburn 1811: if ($storeresult ne 'ok') {
1.13 raeburn 1812: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
1813: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1.14 ! raeburn 1814: } elsif ($statusresult ne 'ok') {
! 1815: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
! 1816: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
1.8 raeburn 1817: }
1818: }
1819: return $output;
1820: }
1821:
1822: sub get_processtype {
1.9 raeburn 1823: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
1824: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1.8 raeburn 1825: my (%userenv,%settings,$val);
1826: my @options = ('autolimit','validate','approve');
1827: if ($dom eq $env{'user.domain'}) {
1828: %userenv =
1829: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
1830: 'requestcourses.'.$crstype,'inststatus');
1831: if ($userenv{'requestcourses.'.$crstype}) {
1832: $val = $userenv{'requestcourses.'.$crstype};
1833: @{$inststatuses} = ('_custom_');
1834: } else {
1835: my ($task,%alltasks);
1.9 raeburn 1836: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
1837: %settings = %{$domconfig->{'requestcourses'}};
1.8 raeburn 1838: if (ref($settings{$crstype}) eq 'HASH') {
1839: if (($env{'user.adv'}) && (exists($settings{$crstype}{'_LC_adv'}))) {
1840: $val = $settings{$crstype}{'_LC_adv'};
1841: @{$inststatuses} = ('_LC_adv_');
1842: } else {
1843: if ($userenv{'inststatus'} ne '') {
1844: @{$inststatuses} = split(',',$userenv{'inststatus'});
1845: } else {
1.13 raeburn 1846: @{$inststatuses} = ('default');
1.8 raeburn 1847: }
1848: foreach my $status (@{$inststatuses}) {
1849: if (exists($settings{$crstype}{$status})) {
1850: my $value = $settings{$crstype}{$status};
1851: next unless ($value);
1852: unless (exists($alltasks{$value})) {
1853: if (ref($alltasks{$value}) eq 'ARRAY') {
1854: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
1855: push(@{$alltasks{$value}},$status);
1856: }
1857: } else {
1858: @{$alltasks{$value}} = ($status);
1859: }
1860: }
1861: }
1862: }
1863: my $maxlimit = 0;
1.13 raeburn 1864:
1.8 raeburn 1865: foreach my $key (sort(keys(%alltasks))) {
1866: if ($key =~ /^autolimit=(\d*)$/) {
1867: if ($1 eq '') {
1868: $val ='autolimit=';
1869: last;
1870: } elsif ($1 > $maxlimit) {
1871: $maxlimit = $1;
1872: }
1873: }
1874: }
1875: if ($maxlimit) {
1876: $val = 'autolimit='.$maxlimit;
1877: } else {
1878: foreach my $option (@options) {
1879: if ($alltasks{$option}) {
1880: $val = $option;
1881: last;
1882: }
1883: }
1884: }
1885: }
1886: }
1887: }
1888: }
1889: } else {
1890: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
1891: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1892: if ($userenv{'reqcrsotherdom'}) {
1893: my @doms = split(',',$userenv{'reqcrsotherdom'});
1894: my $optregex = join('|',@options);
1895: if (grep(/^\Q$dom\E:($optregex=?\d*)/,@doms)) {
1896: $val = $1;
1897: }
1898: @{$inststatuses} = ('_external_');
1899: }
1900: }
1901: return $val;
1902: }
1903:
1904: sub check_autolimit {
1.10 raeburn 1905: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
1906: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
1907: 'userroles',['active','future'],['cc'],[$dom]);
1908: my ($types,$typename) = &course_types();
1909: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
1910: my %count;
1911: if (ref($types) eq 'ARRAY') {
1912: foreach my $type (@{$types}) {
1913: $count{$type} = 0;
1914: }
1915: }
1916: foreach my $key (keys(%requests)) {
1917: my ($cdom,$cnum) = split('_',$key);
1918: if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
1919: if (ref($requests{$key}) eq 'HASH') {
1920: my $type = $requests{$key}{'crstype'};
1921: if ($type =~ /^official|unofficial|community$/) {
1922: $count{$type} ++;
1923: }
1924: }
1925: }
1926: }
1927: if ($count{$crstype} < $limit) {
1928: return 'process';
1929: } else {
1930: if (ref($typename) eq 'HASH') {
1931: $$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);
1932: }
1933: return 'rejected';
1934: }
1.1 raeburn 1935: return;
1936: }
1937:
1.2 raeburn 1938: sub retrieve_settings {
1939: my ($dom,$request_id) = @_;
1940: my %reqinfo = &get_request_settings($request_id,$dom);
1941: my %stored;
1942: $stored{'cdescr'} = &unescape($reqinfo{'description'});
1.13 raeburn 1943: $stored{'accessstart'} = $reqinfo{'accessstart'};
1944: $stored{'accessend'} = $reqinfo{'accessend'};
1945: if ($stored{'accessend'} == 0) {
1.2 raeburn 1946: $stored{'no_end_date'} = 1;
1947: }
1.13 raeburn 1948: $stored{'enrollstart'} = $reqinfo{'enrollstart'};
1949: $stored{'enrollend'} = $reqinfo{'enrollend'};
1.2 raeburn 1950: $stored{'crosslist'} = $reqinfo{'crosslist'};
1.13 raeburn 1951: $stored{'clonecrs'} = $reqinfo{'clonecrs'};
1952: $stored{'clonedom'} = $reqinfo{'clonedom'};
1.2 raeburn 1953: $stored{'sections'} = $reqinfo{'sections'};
1954: $stored{'personnel'} = $reqinfo{'personnel'};
1955:
1956: return %stored;
1957: }
1958:
1959: sub get_request_settings {
1960: my ($request_id,$dom);
1961: }
1962:
1.1 raeburn 1963: 1;
1964:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>