Annotation of loncom/interface/lonrequestcourse.pm, revision 1.12
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.12 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.11 2009/08/12 14:24:35 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',
279: clonecourse => 'text',
280: clonedomain => 'selectbox',
281: datemode => 'radio',
282: dateshift => 'text',
283: },
284: enrollment => {
285: startaccess_month => 'selectbox',
286: startaccess_hour => 'selectbox',
287: endaccess_month => 'selectbox',
288: endaccess_hour => 'selectbox',
289: startaccess_day => 'text',
290: startaccess_year => 'text',
291: startaccess_minute => 'text',
292: startaccess_second => 'text',
293: endaccess_day => 'text',
294: endaccess_year => 'text',
295: endaccess_minute => 'text',
296: endaccess_second => 'text',
297: no_end_date => 'checkbox',
298: },
299: personnel => {
300: persontotal => 'hidden',
301: addperson => 'checkbox',
302: },
303: },
304: view => {
305: crstype => {
306: crstype => 'selectbox',
307: action => 'selectbox',
308: },
309: },
310: );
311: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
312: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
313: \%cat_order,\@code_order);
314: my $numtitles = scalar(@codetitles);
315: if ($numtitles) {
316: my %extras;
317: $lastitem = pop(@codetitles);
318: $extras{'instcode_'.$lastitem} = 'text';
319: foreach my $item (@codetitles) {
320: $extras{'instcode_'.$item} = 'selectbox';
321: }
322: $elements{'new'}{'codepick'} = \%extras;
323: }
324: if (&Apache::lonnet::auto_run('',$dom)) {
325: my %extras = (
326: sectotal => 'hidden',
327: startenroll_month => 'selectbox',
328: startenroll_hour => 'selectbox',
329: endenroll_month => 'selectbox',
330: endenroll_hour => 'selectbox',
331: startenroll_day => 'text',
332: startenroll_year => 'text',
333: startenroll_minute => 'text',
334: startenroll_second => 'text',
335: endenroll_day => 'text',
336: endenroll_year => 'text',
337: endenroll_minute => 'text',
338: endenroll_second => 'text',
339: crosslisttotal => 'hidden',
340: addcrosslist => 'checkbox',
341: autoadds => 'radio',
342: autodrops => 'radio',
343: );
344: if ($env{'form.sectotal'} > 0) {
345: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
346: $extras{'sec_'.$i} = 'checkbox',
347: $extras{'secnum_'.$i} = 'text',
348: $extras{'loncapasec_'.$i} = 'checkbox',
349: }
350: }
351: my $crosslisttotal = $env{'form.crosslisttotal'};
352: if (!defined($crosslisttotal)) {
353: $crosslisttotal = 1;
354: }
355: if ($crosslisttotal > 0) {
356: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
357: if ($numtitles) {
358: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
359: }
360: if (@codetitles > 0) {
361: foreach my $item (@codetitles) {
362: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
363: }
364: }
365: $extras{'crosslist_'.$i} = 'checkbox';
366: $extras{'crosslist_'.$i.'_instsec'} = 'text',
367: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
368: }
369: }
370: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
371: %{$elements{'new'}{'enrollment'}} = %mergedhash;
372: }
373: my %people;
374: my $persontotal = $env{'form.persontotal'};
375: if (!defined($persontotal)) {
376: $persontotal = 1;
377: }
378: for (my $i=0; $i<$persontotal; $i++) {
379: $people{'person_'.$i.'_uname'} = 'text',
380: $people{'person_'.$i.'_dom'} = 'selectbox',
381: $people{'person_'.$i.'_hidedom'} = 'hidden',
382: $people{'person_'.$i.'_first'} = 'text',
383: $people{'person_'.$i.'_last'} = 'text',
384: $people{'person_'.$i.'_email'} = 'text',
385: $people{'person_'.$i.'_role'} = 'selectbox',
386: $people{'person_'.$i.'_sec'} = 'selectbox',
387: $people{'person_'.$i.'_newsec'} = 'text',
388: $people{'person_'.$i.'_sections'} = 'hidden',
389: }
390: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
391: %{$elements{'new'}{'personnel'}} = %personnelhash;
392: return %elements;
393: }
394:
395: sub onload_action {
396: my ($action,$state) = @_;
397: my %loaditems;
398: if (($action eq 'new') || ($action eq 'view')) {
399: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)';
400: }
401: return \%loaditems;
402: }
403:
1.1 raeburn 404: sub check_can_request {
405: my ($dom,$can_request) = @_;
406: my $canreq = 0;
1.4 raeburn 407: my ($types,$typename) = &course_types();
408: if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) {
409: foreach my $type (@{$types}) {
1.1 raeburn 410: if (&Apache::lonnet::usertools_access($env{'user.name'},
411: $env{'user.domain'},
412: $type,undef,'requestcourses')) {
413: $canreq ++;
414: if ($dom eq $env{'user.domain'}) {
415: $can_request->{$type} = 1;
416: }
417: }
418: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
419: my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type});
420: if (@curr > 0) {
421: $canreq ++;
422: unless ($dom eq $env{'user.domain'}) {
423: if (grep(/^\Q$dom\E$/,@curr)) {
424: $can_request->{$type} = 1;
425: }
426: }
427: }
428: }
429: }
430: }
431: return $canreq;
432: }
433:
1.4 raeburn 434: sub course_types {
435: my @types = ('official','unofficial','community');
436: my %typename = (
437: official => 'Official course',
438: unofficial => 'Unofficial course',
439: community => 'Community',
440: );
441: return (\@types,\%typename);
442: }
443:
444:
1.1 raeburn 445: sub print_main_menu {
1.3 raeburn 446: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_;
1.4 raeburn 447: my ($types,$typename) = &course_types();
1.1 raeburn 448: my $onchange;
449: unless ($env{'form.interface'} eq 'textual') {
450: $onchange = 1;
451: }
452:
1.2 raeburn 453: my $nextstate_setter = "\n";
454: if (ref($states) eq 'HASH') {
455: foreach my $key (keys(%{$states})) {
456: if (ref($states->{$key}) eq 'ARRAY') {
457: $nextstate_setter .=
458: " if (actionchoice == '$key') {
459: nextstate = '".$states->{$key}[1]."';
460: }
461: ";
462: }
463: }
464: }
1.1 raeburn 465:
1.2 raeburn 466: my $js = <<"END";
1.1 raeburn 467:
1.2 raeburn 468: function nextPage(formname) {
469: var crschoice = document.requestcrs.crstype.value;
470: var actionchoice = document.requestcrs.action.value;
471: if (check_can_request(crschoice,actionchoice) == true) {
472: if ((actionchoice == 'new') && (crschoice == 'official')) {
473: nextstate = 'codepick';
474: } else {
475: $nextstate_setter
476: }
1.1 raeburn 477: formname.state.value= nextstate;
478: formname.submit();
479: }
480: return;
481: }
482:
1.2 raeburn 483: function check_can_request(crschoice,actionchoice) {
1.1 raeburn 484: var official = '';
485: var unofficial = '';
486: var community = '';
487: END
488:
489: foreach my $item (keys(%{$can_request})) {
490: $js .= "
491: $item = 1;
492: ";
493: }
494: my %lt = &Apache::lonlocal::texthash(
495: official => 'You are not permitted to request creation of an official course in this domain.',
496: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
497: community => 'You are not permitted to request creation of a community this domain.',
498: all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
499: );
500: $js .= <<END;
501: if (crschoice == 'official') {
502: if (official != 1) {
503: alert("$lt{'official'}");
504: return false;
505: }
506: } else {
507: if (crschoice == 'unofficial') {
508: if (unofficial != 1) {
509: alert("$lt{'unofficial'}");
510: return false;
511: }
512: } else {
513: if (crschoice == 'community') {
514: if (community != 1) {
515: alert("$lt{'community'}");
516: return false;
517: }
518: } else {
519: if (actionchoice == 'new') {
520: alert("$lt{'all'}");
521: return false;
522: }
523: }
524: }
525: }
526: return true;
527: }
528:
529: END
530:
1.3 raeburn 531: $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.
532: '<div>'.
1.1 raeburn 533: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
534: &Apache::lonhtmlcommon::start_pick_box().
1.8 raeburn 535: &Apache::lonhtmlcommon::row_title('Course Domain').
1.1 raeburn 536: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange));
537: if (!$onchange) {
538: $r->print(' <input type="submit" name="godom" value="'.
539: &mt('Change').'" />');
540: }
541: $r->print(&Apache::lonhtmlcommon::row_closure(1).
542: &Apache::lonhtmlcommon::end_pick_box().'</form></div>');
543:
1.2 raeburn 544: my $formname = 'requestcrs';
1.1 raeburn 545: my $nexttext = &mt('Next');
546: $r->print('<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'.
547: &Apache::lonhtmlcommon::start_pick_box().
548: &Apache::lonhtmlcommon::row_title('Action').'
549: <input type="hidden" name="showdom" value="'.$dom.'" />
550: <select size="1" name="action" >
1.2 raeburn 551: <option value="new">'.&mt('New request').'</option>
1.1 raeburn 552: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
553: <option value="log">'.&mt('View request history').'</option>
554: </select>'.
555: &Apache::lonhtmlcommon::row_closure().
556: &Apache::lonhtmlcommon::row_title('Course Type').'
557: <select size="1" name="crstype">
1.4 raeburn 558: <option value="any">'.&mt('All types').'</option>');
559: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
560: foreach my $type (@{$types}) {
561: my $selected = '';
562: if ($type eq 'official') {
563: $selected = ' selected="selected"';
564: }
565: $r->print('<option value="'.$type.'"'.$selected.'>'.$typename->{$type}.
566: '</option>'."\n");
567: }
568: }
569: $r->print('</select>
1.1 raeburn 570: <input type="hidden" name="state" value="crstype" />'.
571: &Apache::lonhtmlcommon::row_closure(1).
572: &Apache::lonhtmlcommon::end_pick_box().'<br />
1.2 raeburn 573: <input type="button" name="next" value="'.$nexttext.'" onclick="javascript:nextPage(document.'.$formname.')" />
1.1 raeburn 574: </form></div>');
575: $r->print(&Apache::loncommon::end_page());
576: return;
577: }
578:
579: sub request_administration {
1.3 raeburn 580: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb) = @_;
1.2 raeburn 581: my $js;
582: if (($action eq 'new') || ($action eq 'view')) {
583: $js = <<END;
1.1 raeburn 584:
585: function nextPage(formname,nextstate) {
586: formname.state.value= nextstate;
587: formname.submit();
588: }
589: function backPage(formname,prevstate) {
590: formname.state.value = prevstate;
591: formname.submit();
592: }
593:
594: END
1.2 raeburn 595: }
596: if ($action eq 'new') {
597: my $jsextra;
1.1 raeburn 598: unless (($state eq 'review') || ($state eq 'process')) {
1.2 raeburn 599: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.1 raeburn 600: }
1.3 raeburn 601: $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb);
1.8 raeburn 602: &print_request_form($r,$action,$state,$page,$states,$dom);
1.2 raeburn 603: } elsif ($action eq 'view') {
1.3 raeburn 604: $r->print(&header('Manage course requests',$js.$jscript,$loaditems).$crumb);
1.11 raeburn 605: if ($state eq 'pick_request') {
606: $r->print(&print_request_status($dom));
607: }
1.1 raeburn 608: } elsif ($action eq 'log') {
1.11 raeburn 609: $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
1.1 raeburn 610: }
1.2 raeburn 611: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 612: return;
613: }
614:
615: sub print_request_form {
1.2 raeburn 616: my ($r,$action,$state,$page,$states,$dom) = @_;
1.1 raeburn 617: my $formname = 'requestcrs';
1.2 raeburn 618: my ($next,$prev,$message,$output,$codepicker,$crstype);
619: $prev = $states->{$action}[$page-1];
620: $next = $states->{$action}[$page+1];
1.4 raeburn 621: my %navtxt = &Apache::lonlocal::texthash (
1.10 raeburn 622: prev => 'Back',
1.4 raeburn 623: next => 'Next',
624: );
1.2 raeburn 625: $crstype = $env{'form.crstype'};
1.1 raeburn 626: $r->print('<form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.2 raeburn 627: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1.1 raeburn 628: if ($crstype eq 'official') {
1.2 raeburn 629: if ($env{'form.instcode'} ne '') {
630: $instcode = $env{'form.instcode'};
631: }
632: }
633: if ($prev eq 'codepick') {
1.4 raeburn 634: if ($crstype eq 'official') {
635: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
636: \%cat_order,\@code_order);
637: }
1.2 raeburn 638: if (@code_order > 0) {
639: my $message;
640: if ($instcode eq '') {
1.1 raeburn 641: foreach my $item (@code_order) {
1.2 raeburn 642: $instcode .= $env{'form.instcode_'.$item};
1.1 raeburn 643: }
1.2 raeburn 644: $r->print('<input type="hidden" name="instcode" value="'.$instcode.'" />'."\n");
1.1 raeburn 645: }
646: if ($instcode ne '') {
1.2 raeburn 647: $code_chk = &Apache::lonnet::auto_validate_instcode('',$dom,$instcode);
1.1 raeburn 648: if ($code_chk eq 'ok') {
649: $message = '<div class="LC_info">'.
650: &mt('The chosen course category [_1] is valid.','<b>'.
1.2 raeburn 651: $instcode.'</b>').'</div>';
1.1 raeburn 652: } else {
653: $message = '<div class="LC_warning">'.
654: &mt('No course was found matching your choice of institutional course category.');
655: if ($code_chk ne '') {
656: $message .= '<br />'.$code_chk;
657: }
658: $message .= '</div>';
659: }
1.2 raeburn 660: } else {
661: $message = '<div class="LC_warning">'.
662: &mt('No course was found matching your choice of institutional course category.');
1.1 raeburn 663: }
1.2 raeburn 664: unless ($code_chk eq 'ok') {
665: $prev = 'crstype';
666: }
667: $r->print($message);
1.1 raeburn 668: }
1.2 raeburn 669: }
670: if ($prev eq 'crstype') {
1.4 raeburn 671: if ($crstype eq 'official') {
672: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
673: \%cat_order,\@code_order);
674: }
1.2 raeburn 675: if (@code_order > 0) {
1.1 raeburn 676: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
677: \%cat_titles,\%cat_order);
1.2 raeburn 678: if ($codepicker) {
679: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box().$codepicker.
680: &Apache::lonhtmlcommon::end_pick_box().'</div>');
681: } else {
682: $r->print(&courseinfo_form($dom,$formname,$crstype));
683: }
684: } else {
685: $r->print(&courseinfo_form($dom,$formname,$crstype));
1.1 raeburn 686: }
1.2 raeburn 687: } elsif ($prev eq 'codepick') {
688: $r->print(&courseinfo_form($dom,$formname,$crstype));
689: } elsif ($state eq 'enrollment') {
1.4 raeburn 690: if ($crstype eq 'official') {
691: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
692: \%cat_order,\@code_order);
693: }
1.2 raeburn 694: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
695: \%cat_titles,\%cat_order,\@code_order));
696: } elsif ($state eq 'personnel') {
1.8 raeburn 697: $r->print(&print_personnel_menu($dom,$formname,$crstype));
1.4 raeburn 698: } elsif ($state eq 'review') {
699: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
700: \%cat_order,\@code_order);
701: $r->print(&print_review($formname,$dom,\@codetitles,\%cat_titles,\%cat_order,
702: \@code_order));
703: $navtxt{'next'} = &mt('Submit course request');
1.10 raeburn 704: } elsif ($state eq 'process') {
705: if ($crstype eq 'official') {
706: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
707: \%cat_order,\@code_order);
708: }
709: my $result = &print_request_outcome($dom,\@codetitles,\@code_order);
1.1 raeburn 710: }
1.2 raeburn 711: my @excluded = ('counter');
712: my %elements = &form_elements($dom);
713: if (ref($states) eq 'HASH') {
714: if (ref($states->{$action}) eq 'ARRAY') {
715: my @items = @{$states->{$action}};
716: my $numitems = scalar(@items);
717: if ($numitems) {
718: for (my $i=$numitems-1; $i>=0; $i--) {
719: if (ref($elements{$action}) eq 'HASH') {
720: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
721: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
722: push(@excluded,$key);
723: }
724: }
725: }
726: last if ($items[$i] eq $state);
727: }
728: }
729: }
730: }
731: if (grep(/^instcode_/,@excluded)) {
732: push(@excluded,'instcode');
1.1 raeburn 733: }
1.2 raeburn 734: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1.4 raeburn 735: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'});
1.1 raeburn 736: return;
737: }
738:
1.2 raeburn 739: sub print_enrollment_menu {
740: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order) =@_;
741: my ($sections,$autoenroll,$access_dates);
742: my $starttime = time;
743: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
744:
745: my %accesstitles = (
746: 'start' => 'Default start access',
747: 'end' => 'Default end accss',
748: );
749: my %enrolltitles = (
750: 'start' => 'Start auto-enrollment',
751: 'end' => 'End auto-enrollment',
752: );
753: if ($env{'form.crstype'} eq 'official') {
754: if (&Apache::lonnet::auto_run('',$dom)) {
755: my ($section_form,$crosslist_form,$autoenroll_form);
756: $section_form = &inst_section_selector($dom,$instcode);
757: my $crosslisttotal = $env{'form.crosslisttotal'};
758: if (!defined($crosslisttotal)) {
759: $crosslisttotal = 1;
760: }
761: if ($env{'form.addcrosslist'}) {
762: $crosslisttotal ++;
763: }
764: for (my $i=0; $i<$crosslisttotal; $i++) {
765: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
766: $cat_titles,$cat_order,$i);
767: }
768: if ($crosslist_form) {
769: $crosslist_form .=
770: &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
771: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
772: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
773: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
774: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1);
775: }
776: if ($section_form || $crosslist_form) {
777: $sections = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
778: $section_form.$crosslist_form.
779: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
780: }
781: $autoenroll_form =
782: &Apache::lonhtmlcommon::row_title(&mt('Add registered students automatically')).
783: '<span class="LC_nobreak"><label>'.
784: '<input type="radio" name="autoadds" value="1">'.
785: &mt('Yes').'</label>'.(' 'x3).'<label>'.
786: '<input type="radio" name="autoadds" value="0" checked="checked">'.
787: &mt('No').'</label></span>'.
788: &Apache::lonhtmlcommon::row_closure().
789: &Apache::lonhtmlcommon::row_title(&mt('Drop unregistered students automatically')).
790: '<span class="LC_nobreak"><label>'.
791: '<input type="radio" name="autodrops" value="1">'.
792: &mt('Yes').'</label>'.(' 'x3).'<label>'.
793: '<input type="radio" name="autodrops" value="0" checked="checked">'.
794: &mt('No').'</label></span>'.
795: &Apache::lonhtmlcommon::row_closure().
796: &date_setting_table($starttime,$endtime,$formname,'enroll',%enrolltitles);
797: if ($autoenroll_form) {
798: $autoenroll = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
799: $autoenroll_form.
800: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
801: }
802: }
803: }
804: my $access_dates_form =
805: &date_setting_table($starttime,$endtime,$formname,'access',%accesstitles);
806: if ($access_dates_form) {
807: $access_dates = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
808: $access_dates_form.
809: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
810: }
811: return $sections.$autoenroll.$access_dates;
812: }
813:
1.1 raeburn 814: sub inst_section_selector {
1.2 raeburn 815: my ($dom,$instcode) = @_;
816: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
817: my $sectotal = scalar(@sections);
1.1 raeburn 818: my $output;
1.2 raeburn 819: if ($sectotal) {
820: $output .= &Apache::lonhtmlcommon::row_title('Sections').
821: &Apache::loncommon::start_data_table().
822: &Apache::loncommon::start_data_table_row().
823: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
824: 'value="'.$sectotal.'"</th>'.
825: '<th>'.&mt('Institutional Section').'</th>'.
826: '<th>'.&mt('LON-CAPA section').'</th>'.
827: &Apache::loncommon::end_data_table_row();
828: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 829: my $colflag = $i%2;
830: $output .= &Apache::loncommon::start_data_table_row().
1.2 raeburn 831: '<td><input type="checkbox" name="sec_'.$i.
832: '" checked="checked" /></td>'.
833: '<td>'.$sections[$i].
1.1 raeburn 834: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 835: $sections[$i].'" /></td>'.
1.1 raeburn 836: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 837: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 838: &Apache::loncommon::end_data_table_row();
839: }
1.2 raeburn 840: $output .= &Apache::loncommon::end_data_table().
841: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 842: }
843: return $output;
844: }
845:
1.2 raeburn 846: sub date_setting_table {
847: my ($starttime,$endtime,$formname,$suffix,%datetitles) = @_;
848: my ($perpetual,$table);
849: my $startform = &Apache::lonhtmlcommon::date_setter($formname,'start'.$suffix,
850: $starttime,'','','',1,'','','',1);
851: my $endform = &Apache::lonhtmlcommon::date_setter($formname,'end'.$suffix,
852: $endtime,'','','',1,'','','',1);
853: if ($suffix eq 'access') {
854: $perpetual = ' <span class="LC_nobreak"><label>'.
855: '<input type="checkbox" name="no_end_date" />'.
856: &mt('No end date').'</label></span>';
857: }
858: $table = &Apache::lonhtmlcommon::row_title($datetitles{'start'}).
859: $startform.
860: &Apache::lonhtmlcommon::row_closure().
861: &Apache::lonhtmlcommon::row_title($datetitles{'end'}).
862: $endform.$perpetual.
863: &Apache::lonhtmlcommon::row_closure(1);
864: return $table;
865: }
866:
867: sub print_personnel_menu {
1.8 raeburn 868: my ($dom,$formname,$crstype) = @_;
1.2 raeburn 869: my $output = '<div>'.&Apache::lonhtmlcommon::start_pick_box();
870: my $persontotal = $env{'form.persontotal'};
871: if (!defined($persontotal)) {
872: $persontotal = 1;
873: }
874: if ($env{'form.addperson'}) {
875: $persontotal ++;
876: }
877: my $userlinktxt = &mt('Set User');
878: my @items = ('uname','dom','last','first','email','hidedom');
879:
880: my $roleoptions;
881: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 882: my $type = 'Course';
883: if ($crstype eq 'community') {
884: $type = 'Community';
885: }
1.2 raeburn 886: foreach my $role (@roles) {
1.8 raeburn 887: my $plrole=&Apache::lonnet::plaintext($role,$type);
1.2 raeburn 888: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
889: }
890: my %customroles=&Apache::lonuserutils::my_custom_roles();
891: if (keys(%customroles) > 0) {
892: foreach my $cust (sort(keys(%customroles))) {
893: my $custrole='cr_cr_'.$env{'user.domain'}.
894: '_'.$env{'user.name'}.'_'.$cust;
895: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
896: }
897: }
898:
899: my @currsecs;
900: if ($env{'form.sectotal'}) {
901: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
902: if (defined($env{'form.loncapasec_'.$i})) {
903: my $lcsec = $env{'form.loncapasec_'.$i};
904: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
905: push(@currsecs,$lcsec);
906: }
907: }
908: }
909: }
910:
911: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
912: if (@currsecs) {
913: my $existsize = scalar(@currsecs);
914: if ($existsize > 3) {
915: $existsize = 3;
916: }
917: if ($existsize > 1) {
918: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
919: }
920: @currsecs = sort { $a <=> $b } (@currsecs);
921: $existtitle = &mt('Official').': ';
922: $existops = '<option value="">'.&mt('None').'</option>';
923: foreach my $sec (@currsecs) {
924: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
925: }
926: $seccolspan = ' colspan="2"';
927: $newtitle = &mt('Other').': ';
928: }
929:
930: for (my $i=0; $i<$persontotal; $i++) {
931: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
932: my $linkargstr = join("','",@linkargs);
1.7 raeburn 933: my $userlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,$userlinktxt);
1.2 raeburn 934: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value=""'.
935: ' onFocus="this.blur();'.
1.7 raeburn 936: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');" />';
1.2 raeburn 937: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
938: "'person_".$i."_hidedom'".');'.
1.7 raeburn 939: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');';
1.2 raeburn 940: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
941: 1,$onchange).
942: '<input type="hidden" name="person_'.$i.'_hidedom" value="'.$dom.'" />';
943: my %form_elems;
944: foreach my $item (@items) {
945: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
946: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
947: 'value="" readonly="readonly" />';
948: }
949: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
950: $roleoptions.'</select>';
951: my $sectionselector;
952: if (@currsecs) {
953: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
954: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
955: }
956: $sectionselector .= $newtitle.
957: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'.
958: '<input type="hidden" name="person_'.$i.'_sections" value="" />'."\n";
959:
960: $output .=
961: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel').'<br />'.
962: '<span class="LC_nobreak">'.$userlink.
963: '</span>').
964: '<table><tr><td align="center" valign="top">'.&mt('Username').'<br />'.$uname_form.'</td>'."\n".
965: '<td align="center" valign="top" colspan="2">'.&mt('Domain').'<br />'.$udom_form.'</td></tr><tr>'."\n".
966: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'first'}.'</td>'."\n".
967: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'last'}.'</td>'."\n".
968: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{email}.'</td></tr>'."\n".
969: '<tr><td align="center" valign="top">'.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
970: '<td'.$seccolspan.' align="center" valign="top">'.&mt('Section(s)').'<br />'.$sectionselector.'</td>'."\n".
971: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
972: }
973: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
974: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
975: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
976: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
977: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
978: &Apache::lonhtmlcommon::end_pick_box().'</div>';
979: return $output;
980: }
981:
1.1 raeburn 982: sub print_request_status {
1.11 raeburn 983: my ($dom) = @_;
1.10 raeburn 984: my %requests = &Apache::lonnet::dumpstore('courserequests',$env{'user.domain'},
985: $env{'user.name'});
1.11 raeburn 986: my ($output,$formname,%queue_by_date);
1.10 raeburn 987: foreach my $key (keys(%requests)) {
988: if (ref($requests{$key}) eq 'HASH') {
989: my ($cdom,$cnum) = split('_',$key);
990: next if ($cdom ne $dom);
991: my $entry;
992: my $timestamp = $requests{$key}{'timestamp'};
993: my $crstype = $requests{$key}{'crstype'};
994: my $status = $requests{$key}{'status'};
995: next unless (($env{'form.crstype'} eq 'all') ||
996: ($env{'form.crstype'} eq $crstype));
997: next unless (($status eq 'approval') || ($status eq 'pending'));
998: if (ref($requests{$key}{'details'}) eq 'HASH') {
999: $entry = $key.':'.$crstype.':'.$requests{$key}{'details'}{'cdesc'};
1000: if ($crstype eq 'official') {
1001: $entry .= ':'.$requests{$key}{'details'}{'instcode'};
1002: }
1003: }
1004: if ($entry ne '') {
1005: if (exists($queue_by_date{$timestamp})) {
1006: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
1007: push(@{$queue_by_date{$timestamp}},$entry);
1008: }
1009: } else {
1010: @{$queue_by_date{$timestamp}} = ($entry);
1011: }
1012: }
1013: }
1014: }
1.11 raeburn 1015: $formname = 'requestcrs';
1.10 raeburn 1016: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.11 raeburn 1017: $output = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />'."\n".
1.10 raeburn 1018: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1019: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1020: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n";
1021: if (@sortedtimes > 0) {
1022: $output .= &Apache::loncommon::start_data_table().
1023: &Apache::loncommon::start_data_table_header_row().
1024: '<th>'.&mt('Action').'</th>'.
1025: '<th>'.&mt('Description').'</th>';
1026: if ($env{'form.crstype'} eq 'all') {
1027: $output .= '<th>'.&mt('Type').'</th>';
1028: }
1029: if (($env{'form.crstype'} eq 'all') || ($env{'form.crstype'} eq 'official')) {
1030: $output .= '<th>'.&mt('Institutional Code').'</th>';
1031: }
1032: $output .= '<th>'.&mt('Date requested').'</th>'.
1033: &Apache::loncommon::end_data_table_header_row();
1034: my $count = 0;
1035: foreach my $item (@sortedtimes) {
1036: my $showtime = &Apache::lonlocal::locallocaltime($item);
1037: if (ref($queue_by_date{$item}) eq 'ARRAY') {
1038: foreach my $request (sort(@{$queue_by_date{$item}})) {
1039: my ($key,$type,$desc,$instcode) = split(':',$request);
1040: my ($cdom,$cnum) = split('_',$key);
1041: $output .= &Apache::loncommon::start_data_table_row().
1042: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:viewrequest('."'$cdom','$cnum'".')" /></td>'.
1043: '<td>'.$desc.'</td>';
1044: if ($env{'form.crstype'} eq 'all') {
1045: $output .= '<td>'.&course_types($type).'</td>';
1046: }
1047: if (($env{'form.crstype'} eq 'all') ||
1048: ($env{'form.crstype'} eq 'official')) {
1049: $output .= '<td>'.$instcode.'</td>';
1050: }
1051: $output .= '<td>'.$showtime.'</td>'.
1052: &Apache::loncommon::end_data_table_row();
1053: }
1054: }
1055: }
1056: $output .= &Apache::loncommon::end_data_table();
1057: } else {
1.11 raeburn 1058: $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 1059: }
1060: $output .= '
1061: <input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />
1.11 raeburn 1062: </form>';
1.10 raeburn 1063: return $output;
1.1 raeburn 1064: }
1065:
1066: sub print_request_logs {
1.10 raeburn 1067: my ($jscript,$loaditems,$crumb) = @_;
1.1 raeburn 1068: return;
1069: }
1070:
1071: sub print_review {
1.4 raeburn 1072: my ($formname,$dom,$codetitles,$cat_titles,$cat_order,$code_order) = @_;
1073: my ($types,$typename) = &course_types();
1074: my ($owner,$ownername,$owneremail);
1075: $owner = $env{'user.name'}.':'.$env{'user.domain'};
1076: $ownername = &Apache::loncommon::plainname($env{'user.name'},
1077: $env{'user.domain'},'first');
1078: my %emails = &Apache::loncommon::getemails();
1079: foreach my $email ('permanentemail','critnotification','notification') {
1080: $owneremail = $emails{$email};
1081: last if ($owneremail ne '');
1082: }
1083: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
1084: $section_headers,$section_values,$personnel_headers,$personnel_values);
1085:
1086: $crstypename = $env{'form.crstype'};
1087: if (ref($typename) eq 'HASH') {
1088: unless ($typename->{$env{'form.crstype'}} eq '') {
1089: $crstypename = $typename->{$env{'form.crstype'}};
1090: }
1091: }
1092:
1093: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
1094: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
1095:
1096: if ($env{'form.crstype'} eq 'official') {
1097: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
1098: foreach my $title (@{$codetitles}) {
1099: if ($env{'form.instcode_'.$title} ne '') {
1100: $inst_headers .= '<th>'.$title.'</th>';
1101: my $longitem = $env{'form.instcode_'.$title};
1102: if (ref($cat_titles->{$title}) eq 'HASH') {
1103: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
1104: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
1105: }
1106: }
1107: $inst_values .= '<td>'.$longitem.'</td>';
1108: }
1109: }
1110: }
1111: if (&Apache::lonnet::auto_run('',$dom)) {
1112: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
1113: '<th>'.&mt('Automatic Drops').'</th>'.
1114: '<th>'.&mt('Enrollment Starts').'</th>'.
1115: '<th>'.&mt('Enrollment Ends').'</th>';
1116: $section_headers = '<th>'.&mt('Sections').'</th>'.
1117: '<th>'.&mt('Crosslistings').'</th>';
1118:
1119: my ($startenroll,$endenroll) = &dates_from_form('startenroll','endenroll');
1120: my @autoroster = (&mt('No'),&mt('Yes'));
1121: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
1122: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1123: '<td>'.&Apache::lonlocal::locallocaltime($startenroll).'</td>'.
1124: '<td>'.&Apache::lonlocal::locallocaltime($endenroll).'</td>';
1.6 raeburn 1125: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
1126: &mt('Institutional section').'</th>'.
1127: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 1128: my $secinfo;
1.4 raeburn 1129: if ($env{'form.sectotal'} > 0) {
1130: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1131: if ($env{'form.sec_'.$i}) {
1.5 raeburn 1132: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 1133: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 1134: $secinfo .= $env{'form.loncapasec_'.$i};
1135: } else {
1136: $secinfo .= &mt('None');
1.4 raeburn 1137: }
1.5 raeburn 1138: $secinfo .= '</td></tr>';
1.4 raeburn 1139: }
1140: }
1141: }
1.6 raeburn 1142: if ($secinfo eq '') {
1143: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 1144: }
1.6 raeburn 1145: $section_values .= $secinfo.'</table></td><td>'.
1146: '<table class="LC_innerpickbox"><tr><th>'.
1147: &mt('Institutional course/section').'</th>'.
1148: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 1149: my $xlistinfo;
1.4 raeburn 1150: if ($env{'form.crosslisttotal'}) {
1151: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1152: if ($env{'form.crosslist_'.$i}) {
1.5 raeburn 1153: $xlistinfo .= '<tr><td>';
1154: if (ref($code_order) eq 'ARRAY') {
1155: if (@{$code_order} > 0) {
1156: foreach my $item (@{$code_order}) {
1157: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 1158: }
1159: }
1160: }
1.5 raeburn 1161: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
1.4 raeburn 1162: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
1.5 raeburn 1163: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
1164: } else {
1165: $xlistinfo .= &mt('None');
1.4 raeburn 1166: }
1.5 raeburn 1167: $xlistinfo .= '</td></tr>';
1.4 raeburn 1168: }
1169: }
1170: }
1.6 raeburn 1171: if ($xlistinfo eq '') {
1172: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 1173: }
1.6 raeburn 1174: $section_values .= $xlistinfo.'</table></td>';
1.4 raeburn 1175: }
1176: }
1177:
1178: my %ctxt = &clone_text();
1179: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1180: if (($env{'form.clonecourse'} =~ /^$match_name$/) &&
1181: ($env{'form.clonedomain'} =~ /^$match_domain$/)) {
1182: my %coursehash =
1183: &Apache::lonnet::courseiddump($env{'form.clonedomain'},'.',1,'.','.',
1184: $env{'form.clonecourse'},undef,undef,'.');
1185: my $cloneid = $env{'form.clonedomain'}.'_'.$env{'form.clonecourse'};
1186: if (ref($coursehash{$cloneid}) eq 'HASH') {
1187: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
1188: my $clonedesc = $coursehash{$cloneid}{'description'};
1189: my $cloneinst = $coursehash{$cloneid}{'inst_code'};
1190:
1191: $inst_values .= '<td>'.$clonedesc.' ';
1192: if ($cloneinst ne '') {
1193: $inst_values .= &mt('([_1] in [_2])',$cloneinst,$env{'form.clonedomain'});
1194: } else {
1195: $inst_values .= &mt('(from [_1])',$env{'form.clonedomain'});
1196: }
1197: $inst_values .= '</td><td>';
1198: if ($env{'form.datemode'} eq 'preserve') {
1199: $inst_values .= $ctxt{'pcd'};
1200: } elsif ($env{'form.datemode'} eq 'shift') {
1201: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
1202: } else {
1203: $inst_values .= $ctxt{'ncd'};
1204: }
1205: $inst_values .= '</td>';
1206: } else {
1207: $inst_values .= '<td>'.&mt('Unknown').'</td>';
1208: }
1209: } else {
1210: $inst_values .= '<td>'.&mt('None').'</td>';
1211: }
1212: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
1213: '<th>'.&mt('Access Ends').'</th>';
1214: my ($startaccess,$endaccess) = &dates_from_form('startaccess','endaccess');
1215: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($startaccess).'</td>';
1216: if ($endaccess == 0) {
1217: $enroll_values .= '<td>'.&mt('No end date').'</td>';
1218: } else {
1219: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($endaccess).'</td>';
1220: }
1221:
1222: my $container = 'Course';
1223: if ($env{'form.crstype'} eq 'community') {
1224: $container = 'Community';
1225: }
1226:
1227: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
1228: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
1229: '</th>';
1230: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1231: '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
1232: '<td>'.&mt('None').'</td></tr>';
1233: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1234: if ($env{'form.person_'.$i.'_uname'} ne '') {
1235: $personnel_values .=
1236: '<tr><td>'.$env{'form.person_'.$i.'_first'}.' '.
1237: $env{'form.person_'.$i.'_last'}.'</td>'.
1238: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
1239: $env{'form.person_'.$i.'_dom'}.'</td>'.
1240: '<td>'.&Apache::lonnet::plaintext($env{'form.person_'.$i.'_role'},
1241: $container).'</td>'.
1242: '<td>'.$env{'form.person_'.$i.'_sections'}.'</td></tr>';
1243: }
1244: }
1245: my $output = '<p>'.&mt('Review the details of the course request before submission.').'</p>'.
1246: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1247: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 1248: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 1249: '<th>'.&mt('Name').'</th>'.
1250: '<th>'.&mt('Username:Domain').'</th>'.
1251: '<th>'.&mt('E-mail address').'</th>'.
1252: '</tr><tr>'."\n".
1253: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
1254: '<td>'.$owneremail.'</td>'.
1255: '</tr></table>'."\n".
1256: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 1257: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 1258: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
1259: '<tr>'.$inst_values.'</tr></table>'."\n".
1260: &Apache::lonhtmlcommon::row_closure().
1261: &Apache::lonhtmlcommon::row_title(&mt('Enrollment')).
1262: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
1263: '<tr>'.$enroll_values.'</tr></table>'."\n".
1264: &Apache::lonhtmlcommon::row_closure();
1265: if ($section_headers ne '') {
1266: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
1267: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
1268: '<tr>'.$section_values.'</tr></table>'."\n".
1269: &Apache::lonhtmlcommon::row_closure();
1270: }
1271: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
1272: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
1273: $personnel_values.'</table>'."\n".
1274: &Apache::lonhtmlcommon::row_closure(1).
1275: &Apache::lonhtmlcommon::end_pick_box();
1.8 raeburn 1276: my $cnum = &Apache::lonnet::generate_coursenum($dom);
1277: $output .= '<input type="hidden" name="cnum" value="'.$cnum.'" />';
1.4 raeburn 1278: return $output;
1279: }
1280:
1281: sub dates_from_form {
1282: my ($startname,$endname) = @_;
1283: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1284: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1285: if ($endname eq 'endaccess') {
1286: if (exists($env{'form.no_end_date'}) ) {
1287: $enddate = 0;
1288: }
1289: }
1290: return ($startdate,$enddate);
1.1 raeburn 1291: }
1292:
1293: sub courseinfo_form {
1.2 raeburn 1294: my ($dom,$formname,$crstype) = @_;
1295: my $output = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1296: &Apache::lonhtmlcommon::row_title('Course Description').
1297: '<input type="text" size="40" name="cdescr" />'.
1298: &Apache::lonhtmlcommon::row_closure(1).
1299: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
1300: '<div>'.&clone_form($dom,$formname,$crstype).'</div>'."\n";
1.1 raeburn 1301: return $output;
1302: }
1303:
1304: sub clone_form {
1305: my ($dom,$formname,$crstype) = @_;
1306: my $type = 'Course';
1307: if ($crstype eq 'community') {
1308: $type = 'Community';
1309: }
1310: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedomain').
1.2 raeburn 1311: &Apache::loncommon::selectcourse_link($formname,'clonecourse','clonedomain','','','',$type);
1.4 raeburn 1312: my %lt = &clone_text();
1.2 raeburn 1313: my $output .=
1314: &Apache::lonhtmlcommon::start_pick_box().
1315: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1316: '<input type="text" size="25" name="clonecourse" value="" onfocus="this.blur();'.
1317: 'opencrsbrowser('."'$formname','clonecourse','clonedomain','','','','$type'".');" />'.
1318: '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
1319: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
1320: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure().
1321: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
1322: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
1323: '</label><br /><label>'.
1324: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
1325: '</label><br /><label>'.
1326: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
1327: $lt{'shd'}.'</label>'.
1328: '<input type="text" size="5" name="dateshift" value="365" />'.
1329: &Apache::lonhtmlcommon::row_closure(1).
1330: &Apache::lonhtmlcommon::end_pick_box();
1.1 raeburn 1331: return $output;
1332: }
1333:
1.4 raeburn 1334: sub clone_text {
1335: return &Apache::lonlocal::texthash(
1336: 'cid' => 'Course ID',
1337: 'dmn' => 'Domain',
1338: 'dsh' => 'Date Shift',
1339: 'ncd' => 'Do not clone date parameters',
1340: 'prd' => 'Clone date parameters as-is',
1341: 'shd' => 'Shift date parameters by number of days',
1342: );
1343: }
1344:
1.1 raeburn 1345: sub coursecode_form {
1.2 raeburn 1346: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 1347: my $output;
1.2 raeburn 1348: my %rowtitle = (
1349: instcode => 'Course Category',
1350: crosslist => 'Cross Listed Course',
1351: );
1.1 raeburn 1352: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
1353: (ref($cat_order))) {
1.2 raeburn 1354: my ($sel,$instsec,$lcsec);
1355: $sel = $context;
1356: if ($context eq 'crosslist') {
1357: $sel .= '_'.$num;
1358: $instsec = &mt('Institutional section').'<br />'.
1359: '<input type="text" size="10" name="'.$sel.'_instsec" />';
1360: $lcsec = &mt('LON-CAPA section').'<br />'.
1361: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
1362: }
1.1 raeburn 1363: if (@{$codetitles} > 0) {
1364: my $lastitem = pop(@{$codetitles});
1.2 raeburn 1365: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 1366: if (@{$codetitles} > 0) {
1.2 raeburn 1367: $output = &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1368: '<table><tr>';
1.1 raeburn 1369: if ($context eq 'crosslist') {
1.2 raeburn 1370: $output .= '<td>'.&mt('Include?').'<br />'.
1371: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 1372: }
1373: foreach my $title (@{$codetitles}) {
1374: if (ref($cat_order->{$title}) eq 'ARRAY') {
1375: if (@{$cat_order->{$title}} > 0) {
1376: $output .= '<td align="center">'.$title.'<br />'."\n".
1377: '<select name="'.$sel.'_'.$title.'">'."\n".
1378: ' <option value="" selected="selected">'.
1379: &mt('Select').'</option>'."\n";
1380: foreach my $item (@{$cat_order->{$title}}) {
1381: my $longitem = $item;
1382: if (ref($cat_titles->{$title}) eq 'HASH') {
1383: if ($cat_titles->{$title}{$item} ne '') {
1384: $longitem = $cat_titles->{$title}{$item};
1385: }
1386: }
1387: $output .= '<option value="'.$item.'">'.$longitem.
1388: '</option>'."\n";
1389: }
1390: }
1391: $output .= '</select></td>'."\n";
1392: }
1393: }
1394: if ($context eq 'crosslist') {
1395: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 1396: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
1397: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 1398: } else {
1399: $output .= '</tr></table>'.
1400: &Apache::lonhtmlcommon::row_closure().
1401: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1402: $lastinput;
1403: }
1404: } else {
1405: if ($context eq 'crosslist') {
1406: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 1407: '<table><tr>'.
1408: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
1409: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
1410: '</tr></table>';
1.1 raeburn 1411: } else {
1412: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1413: $lastinput;
1414: }
1415: }
1.2 raeburn 1416: $output .= &Apache::lonhtmlcommon::row_closure(1);
1417: push(@$codetitles,$lastitem);
1418: } elsif ($context eq 'crosslist') {
1419: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1420: '<table><tr><td align="center">'.
1421: '<span class="LC_nobreak">'.&mt('Include?').
1422: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
1423: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
1424: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
1425: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
1426: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 1427: }
1428: }
1429: return $output;
1430: }
1431:
1432: sub get_course_dom {
1433: my $codedom = &Apache::lonnet::default_login_domain();
1434: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1435: $codedom = $env{'user.domain'};
1436: if ($env{'request.role.domain'} ne '') {
1437: $codedom = $env{'request.role.domain'};
1438: }
1439: }
1440: if ($env{'form.showdom'} ne '') {
1441: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
1442: $codedom = $env{'form.showdom'};
1443: }
1444: }
1445: return $codedom;
1446: }
1447:
1448: sub display_navbuttons {
1449: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1450: $r->print('<div class="LC_navbuttons">');
1451: if ($prev) {
1452: $r->print('
1453: <input type="button" name="previous" value = "'.$prevtext.'"
1454: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1455: ');
1456: } elsif ($prevtext) {
1457: $r->print('
1458: <input type="button" name="previous" value = "'.$prevtext.'"
1459: onclick="javascript:history.back()"/>
1460: ');
1461: }
1462: if ($next) {
1463: $r->print('
1464: <input type="button" name="next" value="'.$nexttext.'"
1465: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1466: }
1467: $r->print('</div>');
1468: }
1469:
1470: sub print_request_outcome {
1.10 raeburn 1471: my ($dom,$codetitles,$code_order) = @_;
1472: my ($output,$cnum,$now,$req_notifylist,$crstype,$startenroll,$endenroll,
1473: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1474: $cnum = $env{'form.cnum'};
1.8 raeburn 1475: unless ($cnum =~ /^$match_courseid$/) {
1476: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
1477: return $output;
1478: }
1.11 raeburn 1479:
1.10 raeburn 1480: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 1481: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
1482: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
1483: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
1484: }
1485: }
1.10 raeburn 1486: $now = time;
1487: $crstype = $env{'form.crstype'};
1.8 raeburn 1488: if ($crstype eq 'official') {
1489: if (&Apache::lonnet::auto_run('',$dom)) {
1490: ($startenroll,$endenroll)=&dates_from_form('startenroll','endenroll');
1491: }
1.10 raeburn 1492: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1493: if ($env{'form.sec_'.$i}) {
1494: if ($env{'form.secnum_'.$i} ne '') {
1495: $sections{$env{'form.secnum_'.$i}} = $env{'form.loncapasec_'.$i};
1496: }
1497: }
1498: }
1499: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1500: if ($env{'form.crosslist_'.$i}) {
1501: my $xlistinfo = '';
1502: if (ref($code_order) eq 'ARRAY') {
1503: if (@{$code_order} > 0) {
1504: foreach my $item (@{$code_order}) {
1505: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1506: }
1507: }
1508: }
1509: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'};
1510: $crosslistings{$xlistinfo} = $env{'form.crosslist_'.$i.'_lcsec'};
1511: }
1512: }
1513: }
1514:
1515: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1516: my $uname = $env{'form.person_'.$i.'_uname'};
1517: my $udom = $env{'form.person_'.$i.'_uname'};
1518: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
1519: if (&Apache::lonnet::domain($udom) ne '') {
1520: $personnel{$uname.':'.$udom} = {
1521: first => $env{'form.person_'.$i.'_first'},
1522: last => $env{'form.person_'.$i.'_last'},
1523: email => $env{'form.person_'.$i.'_email'},
1524: role => $env{'form.person_'.$i.'_role'},
1525: sections => $env{'form.person_'.$i.'_sections'},
1526: };
1527: } else {
1528: push(@missingdom,$uname.':'.$udom);
1529: }
1530: } else {
1531: push(@baduname,$uname.':'.$udom);
1532: }
1.8 raeburn 1533: }
1.10 raeburn 1534:
1.8 raeburn 1535: my ($startaccess,$endaccess) = &dates_from_form('startaccess','endacess');
1536: my $details = {
1.10 raeburn 1537: owner => $env{'user.name'},
1538: domain => $env{'user.domain'},
1539: cdom => $dom,
1.11 raeburn 1540: cnum => $cnum,
1.10 raeburn 1541: cdesc => $env{'form.cdesc'},
1542: crstype => $env{'form.crstype'},
1543: instcode => $env{'form.instcode'},
1544: clonedomain => $env{'form.clonedomain'},
1545: clonecourse => $env{'form.clonecourse'},
1546: datemode => $env{'form.datemode'},
1547: dateshift => $env{'form.datshift'},
1548: sectotal => $env{'form.sectotal'},
1549: sections => \%sections,
1550: crosslisttotal => $env{'form.crosslisttotal'},
1551: crosslistings => \%crosslistings,
1552: autoadds => $env{'form.autoadds'},
1553: autodrops => $env{'form.autodrops'},
1554: startenroll => $startenroll,
1555: endenroll => $endenroll,
1556: startaccess => $startaccess,
1557: endaccess => $endaccess,
1558: personnel => \%personnel,
1.8 raeburn 1559: };
1560: my @inststatuses;
1.9 raeburn 1561: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 1562: if ($val eq '') {
1563: if ($crstype eq 'official') {
1564: $output = &mt('You are not permitted to request creation of official courses');
1565: } elsif ($crstype eq 'unofficial') {
1566: $output = &mt('You are not permitted to request creation of unofficial courses');
1567: } elsif ($crstype eq 'community') {
1568: $output = &mt('You are not permitted to request creation of communities');
1569: } else {
1570: $output = &mt('Unrecognized course type: [_1]',$crstype);
1571: }
1572: } else {
1573: my ($disposition,$message);
1574: my %reqhash = (
1.10 raeburn 1575: timestamp => $now,
1576: crstype => $crstype,
1577: details => $details,
1.8 raeburn 1578: );
1579: my $requestkey = $dom.'_'.$cnum;
1.10 raeburn 1580: if ($val eq 'autolimit=') {
1581: $disposition = 'process';
1582: } elsif ($val =~ /^autolimit=(\d+)$/) {
1583: my $limit = $1;
1.8 raeburn 1584: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 1585: $dom,$crstype,$limit,\$message);
1.8 raeburn 1586: } elsif ($val eq 'validate') {
1587: $disposition =
1588: &Apache::lonnet::auto_courserequest_validation($dom,$details,
1589: \@inststatuses,\$message);
1590: } else {
1591: $disposition = 'approval';
1592: }
1593: $reqhash{'status'} = $disposition;
1594: if ($disposition eq 'rejected') {
1595: $output = &mt('Your course request was rejected.');
1596: if ($message) {
1597: $output .= '<div class="LC_warning">'.$message.'</div>';
1598: }
1599: } elsif ($disposition eq 'process') {
1600: my $type = 'Course';
1601: if ($crstype eq 'community') {
1602: $type = 'Community';
1603: }
1604: my ($logmsg,$newusermsg,$addresult,$enrollcount,$output,$keysmsg,%longroles);
1605: my @roles = &Apache::lonuserutils::roles_by_context('course');
1606: foreach my $role (@roles) {
1607: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
1608: }
1609: my %reqdetails = &build_batchcreatehash($details);
1610: my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'request',\%reqdetails,\%longroles,\$logmsg,\$newusermsg,\$addresult,\$enrollcount,\$output,\$keysmsg,$env{'user.domain'},$env{'user.name'},$cnum);
1611: $disposition = 'created';
1612: if ($cid eq $cnum) {
1613: $disposition = 'created';
1614: $output = &mt('Your course request has been processed and the course has been created.').'<br />'.&mt('You will need to logout and log-in again to be able to select a role in the course.');
1615: } else {
1616: $output = &mt('An error occurred when processing your course request.').'<br />'.&mt('You may want to review the request details and submit the request again.');
1617: }
1618: } else {
1619: my $requestid = $cnum.'_'.$disposition;
1620: my $request = {
1621: $requestid => {
1622: timestamp => $now,
1623: crstype => $crstype,
1624: ownername => $env{'user.name'},
1625: ownerdom => $env{'user.domain'},
1626: description => $env{'form.cdesc'},
1627: },
1628: };
1629: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
1630: $dom);
1631: if ($putresult eq 'ok') {
1632: my %emails = &Apache::loncommon::getemails();
1633: my $address;
1634: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
1635: $address = $emails{'permanentemail'};
1636: if ($address eq '') {
1637: $address = $emails{'notification'};
1638: }
1639: }
1640: $output = &mt('Your course request has been recorded.').'<br />';
1641: if ($disposition eq 'approval') {
1642: $output .= &mt('Your course request has been recorded.').'<br />'.
1643: &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
1644: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
1645: if ($address ne '') {
1646: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
1647: }
1648: if ($req_notifylist) {
1649: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
1650: $env{'user.domain'});
1651: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,$fullname,$now,$dom,$details);
1652: }
1653: } else {
1654: $output .= '<div class="LC_info">'.
1655: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
1656: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
1657: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
1658: '</div>';
1659: }
1660: } else {
1661: $reqhash{'status'} = 'domainerror';
1662: $reqhash{'disposition'} = $disposition;
1663: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
1664: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1665:
1666: }
1667: }
1.10 raeburn 1668: my $storeresult;
1669: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1670: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
1671: 'courserequests');
1672: } else {
1673: $storeresult = 'error: invalid requestkey format';
1674: }
1.8 raeburn 1675: if ($storeresult ne 'ok') {
1676: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request.').'</span><br />';
1677: &logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1678: }
1679: }
1680: return $output;
1681: }
1682:
1683: sub get_processtype {
1.9 raeburn 1684: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
1685: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1.8 raeburn 1686: my (%userenv,%settings,$val);
1687: my @options = ('autolimit','validate','approve');
1688: if ($dom eq $env{'user.domain'}) {
1689: %userenv =
1690: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
1691: 'requestcourses.'.$crstype,'inststatus');
1692: if ($userenv{'requestcourses.'.$crstype}) {
1693: $val = $userenv{'requestcourses.'.$crstype};
1694: @{$inststatuses} = ('_custom_');
1695: } else {
1696: my ($task,%alltasks);
1.9 raeburn 1697: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
1698: %settings = %{$domconfig->{'requestcourses'}};
1.8 raeburn 1699: if (ref($settings{$crstype}) eq 'HASH') {
1700: if (($env{'user.adv'}) && (exists($settings{$crstype}{'_LC_adv'}))) {
1701: $val = $settings{$crstype}{'_LC_adv'};
1702: @{$inststatuses} = ('_LC_adv_');
1703: } else {
1704: if ($userenv{'inststatus'} ne '') {
1705: @{$inststatuses} = split(',',$userenv{'inststatus'});
1706: } else {
1707: @{$inststatuses} = ('other');
1708: }
1709: foreach my $status (@{$inststatuses}) {
1710: if (exists($settings{$crstype}{$status})) {
1711: my $value = $settings{$crstype}{$status};
1712: next unless ($value);
1713: unless (exists($alltasks{$value})) {
1714: if (ref($alltasks{$value}) eq 'ARRAY') {
1715: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
1716: push(@{$alltasks{$value}},$status);
1717: }
1718: } else {
1719: @{$alltasks{$value}} = ($status);
1720: }
1721: }
1722: }
1723: }
1724: my $maxlimit = 0;
1725: foreach my $key (sort(keys(%alltasks))) {
1726: if ($key =~ /^autolimit=(\d*)$/) {
1727: if ($1 eq '') {
1728: $val ='autolimit=';
1729: last;
1730: } elsif ($1 > $maxlimit) {
1731: $maxlimit = $1;
1732: }
1733: }
1734: }
1735: if ($maxlimit) {
1736: $val = 'autolimit='.$maxlimit;
1737: } else {
1738: foreach my $option (@options) {
1739: if ($alltasks{$option}) {
1740: $val = $option;
1741: last;
1742: }
1743: }
1744: }
1745: }
1746: }
1747: }
1748: }
1749: } else {
1750: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
1751: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1752: if ($userenv{'reqcrsotherdom'}) {
1753: my @doms = split(',',$userenv{'reqcrsotherdom'});
1754: my $optregex = join('|',@options);
1755: if (grep(/^\Q$dom\E:($optregex=?\d*)/,@doms)) {
1756: $val = $1;
1757: }
1758: @{$inststatuses} = ('_external_');
1759: }
1760: }
1761: return $val;
1762: }
1763:
1764: sub check_autolimit {
1.10 raeburn 1765: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
1766: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
1767: 'userroles',['active','future'],['cc'],[$dom]);
1768: my ($types,$typename) = &course_types();
1769: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
1770: my %count;
1771: if (ref($types) eq 'ARRAY') {
1772: foreach my $type (@{$types}) {
1773: $count{$type} = 0;
1774: }
1775: }
1776: foreach my $key (keys(%requests)) {
1777: my ($cdom,$cnum) = split('_',$key);
1778: if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
1779: if (ref($requests{$key}) eq 'HASH') {
1780: my $type = $requests{$key}{'crstype'};
1781: if ($type =~ /^official|unofficial|community$/) {
1782: $count{$type} ++;
1783: }
1784: }
1785: }
1786: }
1787: if ($count{$crstype} < $limit) {
1788: return 'process';
1789: } else {
1790: if (ref($typename) eq 'HASH') {
1791: $$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);
1792: }
1793: return 'rejected';
1794: }
1.1 raeburn 1795: return;
1796: }
1797:
1.8 raeburn 1798: sub build_batchcreatehash {
1799: my ($details) = @_;
1800: my %batchhash;
1801: if (ref($details) eq 'HASH') {
1802:
1803: }
1804: return %batchhash;
1805: }
1806:
1.2 raeburn 1807: sub retrieve_settings {
1808: my ($dom,$request_id) = @_;
1809: my %reqinfo = &get_request_settings($request_id,$dom);
1810: my %stored;
1811: $stored{'cdescr'} = &unescape($reqinfo{'description'});
1812: $stored{'startaccess'} = $reqinfo{'startaccess'};
1813: $stored{'endaccess'} = $reqinfo{'endaccess'};
1814: if ($stored{'endaccess'} == 0) {
1815: $stored{'no_end_date'} = 1;
1816: }
1817: $stored{'startenroll'} = $reqinfo{'startenroll'};
1818: $stored{'endenroll'} = $reqinfo{'endenroll'};
1819: $stored{'crosslist'} = $reqinfo{'crosslist'};
1820: $stored{'clonecourse'} = $reqinfo{'clonecourse'};
1821: $stored{'clonedomain'} = $reqinfo{'clonedomain'};
1822: $stored{'sections'} = $reqinfo{'sections'};
1823: $stored{'personnel'} = $reqinfo{'personnel'};
1824:
1825: return %stored;
1826: }
1827:
1828: sub get_request_settings {
1829: my ($request_id,$dom);
1830: }
1831:
1.1 raeburn 1832: 1;
1833:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>