Annotation of loncom/interface/lonrequestcourse.pm, revision 1.19
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.19 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.18 2009/08/19 20:12: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: my %stored;
132: my $jscript;
133: if ((defined($state)) && (defined($action))) {
1.16 raeburn 134: if (($action eq 'view') && ($state eq 'details')) {
135: if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
136: my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
1.2 raeburn 137: }
138: }
1.16 raeburn 139: my %elements = &form_elements($dom);
1.2 raeburn 140: my $elementsref = {};
141: if (ref($elements{$action}) eq 'HASH') {
142: if (ref($elements{$action}{$state}) eq 'HASH') {
143: $elementsref = $elements{$action}{$state};
144: }
145: }
1.16 raeburn 146: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
147: $env{'form.clonedom'} = $dom;
148: }
1.2 raeburn 149: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
150: }
151:
152: if ($state eq 'personnel') {
153: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
154: }
155:
156: my $loaditems = &onload_action($action,$state);
157:
158: my %states;
1.16 raeburn 159: $states{'view'} = ['pick_request','details','cancel','removal'];
1.2 raeburn 160: $states{'log'} = ['filter','display'];
161: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
162: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
163: unless ($env{'form.state'} eq 'crstype') {
164: unshift (@{$states{'new'}},'codepick');
165: }
166: }
167:
168: foreach my $key (keys(%states)) {
169: if (ref($states{$key}) eq 'ARRAY') {
170: unshift (@{$states{$key}},'crstype');
171: }
172: }
173:
1.3 raeburn 174: my %trail = (
1.10 raeburn 175: crstype => 'Course Request Action',
176: codepick => 'Category',
177: courseinfo => 'Description',
1.16 raeburn 178: enrollment => 'Access Dates',
1.10 raeburn 179: personnel => 'Personnel',
180: review => 'Review',
181: process => 'Result',
182: pick_request => 'Display Summary',
1.16 raeburn 183: details => 'Request Details',
184: cancel => 'Cancel Request',
185: removal => 'Outcome',
1.3 raeburn 186: );
187:
1.16 raeburn 188: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
189: $trail{'enrollment'} = 'Enrollment';
190: }
191:
1.2 raeburn 192: my $page = 0;
1.3 raeburn 193: my $crumb;
1.2 raeburn 194: if (defined($action)) {
195: my $done = 0;
196: my $i=0;
197: if (ref($states{$action}) eq 'ARRAY') {
198: while ($i<@{$states{$action}} && !$done) {
199: if ($states{$action}[$i] eq $state) {
200: $page = $i;
201: $done = 1;
202: }
203: $i++;
204: }
205: }
1.3 raeburn 206: for (my $i=0; $i<@{$states{$action}}; $i++) {
207: if ($state eq $states{$action}[$i]) {
208: &Apache::lonhtmlcommon::add_breadcrumb(
209: {text=>"$trail{$state}"});
210: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
211: last;
212: } else {
213: if (($state eq 'process') && ($i > 0)) {
214: &Apache::lonhtmlcommon::add_breadcrumb(
215: {href=>"javascript:backPage(document.requestcrs,'$states{$action}[0]')",
216: text=>"$trail{$states{$action}[$i]}"});
217: } else {
218: &Apache::lonhtmlcommon::add_breadcrumb(
219: {href=>"javascript:backPage(document.requestcrs,'$states{$action}[$i]')",
220: text=>"$trail{$states{$action}[$i]}"});
221: }
222: }
223: }
224: } else {
225: &Apache::lonhtmlcommon::add_breadcrumb(
226: {text=>'Pick Action'});
227: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
1.2 raeburn 228: }
229:
1.1 raeburn 230: my %can_request;
231: my $canreq = &check_can_request($dom,\%can_request);
232: if ($action eq 'new') {
233: if ($canreq) {
234: if ($state eq 'crstype') {
1.3 raeburn 235: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
236: $crumb);
1.1 raeburn 237: } else {
1.2 raeburn 238: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.3 raeburn 239: $loaditems,$crumb);
1.1 raeburn 240: }
241: } else {
1.3 raeburn 242: $r->print(&header('Course Requests').$crumb.
1.1 raeburn 243: '<div class="LC_warning">'.
244: &mt('You do not have privileges to request creation of courses.').
1.2 raeburn 245: '</div>'.&Apache::loncommon::end_page());
1.1 raeburn 246: }
247: } elsif ($action eq 'view') {
1.10 raeburn 248: if ($state eq 'crstype') {
1.11 raeburn 249: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
250: } else {
251: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
252: $loaditems,$crumb);
1.10 raeburn 253: }
1.1 raeburn 254: } elsif ($action eq 'log') {
1.3 raeburn 255: &print_request_logs($jscript,$loaditems,$crumb);
1.1 raeburn 256: } else {
1.3 raeburn 257: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
1.1 raeburn 258: }
259: return OK;
260: }
261:
1.2 raeburn 262: sub header {
263: my ($bodytitle,$jscript,$loaditems,$jsextra) = @_;
264: if ($jscript) {
1.6 raeburn 265: $jscript = '<script type="text/javascript">'."\n".
266: '// <![CDATA['."\n".
267: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
1.2 raeburn 268: }
269: if ($loaditems) {
1.3 raeburn 270: $loaditems = {'add_entries' => $loaditems,};
271: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$loaditems);
272: } else {
273: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra);
274: }
1.2 raeburn 275: }
276:
277: sub form_elements {
278: my ($dom) = @_;
279: my %elements =
280: (
281: new => {
282: crstype => {
283: crstype => 'selectbox',
284: action => 'selectbox',
1.16 raeburn 285: origcnum => 'hidden',
1.2 raeburn 286: },
287: courseinfo => {
288: cdescr => 'text',
1.13 raeburn 289: clonecrs => 'text',
290: clonedom => 'selectbox',
1.2 raeburn 291: datemode => 'radio',
292: dateshift => 'text',
293: },
294: enrollment => {
1.13 raeburn 295: accessstart_month => 'selectbox',
296: accessstart_hour => 'selectbox',
297: accessend_month => 'selectbox',
298: accessend_hour => 'selectbox',
299: accessstart_day => 'text',
300: accessstart_year => 'text',
301: accessstart_minute => 'text',
302: accessstart_second => 'text',
303: accessend_day => 'text',
304: accessend_year => 'text',
305: accessend_minute => 'text',
306: accessend_second => 'text',
1.2 raeburn 307: no_end_date => 'checkbox',
308: },
309: personnel => {
310: addperson => 'checkbox',
311: },
1.13 raeburn 312: review => {
313: cnum => 'hidden',
314: },
1.2 raeburn 315: },
316: view => {
317: crstype => {
318: crstype => 'selectbox',
319: action => 'selectbox',
320: },
321: },
322: );
1.13 raeburn 323: my %servers = &Apache::lonnet::get_servers($dom,'library');
324: my $numlib = keys(%servers);
325: if ($numlib > 1) {
326: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
327: } else {
328: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
329: }
1.2 raeburn 330: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
331: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
332: \%cat_order,\@code_order);
333: my $numtitles = scalar(@codetitles);
334: if ($numtitles) {
335: my %extras;
336: $lastitem = pop(@codetitles);
337: $extras{'instcode_'.$lastitem} = 'text';
338: foreach my $item (@codetitles) {
339: $extras{'instcode_'.$item} = 'selectbox';
340: }
341: $elements{'new'}{'codepick'} = \%extras;
342: }
343: if (&Apache::lonnet::auto_run('',$dom)) {
344: my %extras = (
345: sectotal => 'hidden',
1.13 raeburn 346: enrollstart_month => 'selectbox',
347: enrollstart_hour => 'selectbox',
348: enrollend_month => 'selectbox',
349: enrollend_hour => 'selectbox',
350: enrollstart_day => 'text',
351: enrollstart_year => 'text',
352: enrollstart_minute => 'text',
353: enrollstart_second => 'text',
354: enrollend_day => 'text',
355: enrollend_year => 'text',
356: enrollend_minute => 'text',
357: enrollend_second => 'text',
1.2 raeburn 358: crosslisttotal => 'hidden',
359: addcrosslist => 'checkbox',
360: autoadds => 'radio',
361: autodrops => 'radio',
362: );
363: if ($env{'form.sectotal'} > 0) {
364: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
365: $extras{'sec_'.$i} = 'checkbox',
366: $extras{'secnum_'.$i} = 'text',
367: $extras{'loncapasec_'.$i} = 'checkbox',
368: }
369: }
370: my $crosslisttotal = $env{'form.crosslisttotal'};
1.16 raeburn 371: if ($env{'form.addcrosslist'}) {
372: $crosslisttotal ++;
373: }
1.2 raeburn 374: if (!defined($crosslisttotal)) {
375: $crosslisttotal = 1;
376: }
377: if ($crosslisttotal > 0) {
378: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
379: if ($numtitles) {
380: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
381: }
382: if (@codetitles > 0) {
383: foreach my $item (@codetitles) {
384: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
385: }
386: }
387: $extras{'crosslist_'.$i} = 'checkbox';
388: $extras{'crosslist_'.$i.'_instsec'} = 'text',
389: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
390: }
391: }
392: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
393: %{$elements{'new'}{'enrollment'}} = %mergedhash;
394: }
395: my %people;
396: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 397: if ($env{'form.addperson'}) {
398: $persontotal ++;
399: }
400: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 401: $persontotal = 1;
402: }
403: for (my $i=0; $i<$persontotal; $i++) {
1.13 raeburn 404: $people{'person_'.$i.'_uname'} = 'text',
405: $people{'person_'.$i.'_dom'} = 'selectbox',
406: $people{'person_'.$i.'_hidedom'} = 'hidden',
407: $people{'person_'.$i.'_firstname'} = 'text',
408: $people{'person_'.$i.'_lastname'} = 'text',
409: $people{'person_'.$i.'_emailaddr'} = 'text',
410: $people{'person_'.$i.'_role'} = 'selectbox',
411: $people{'person_'.$i.'_sec'} = 'selectbox',
412: $people{'person_'.$i.'_newsec'} = 'text',
1.2 raeburn 413: }
414: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
415: %{$elements{'new'}{'personnel'}} = %personnelhash;
416: return %elements;
417: }
418:
419: sub onload_action {
420: my ($action,$state) = @_;
421: my %loaditems;
422: if (($action eq 'new') || ($action eq 'view')) {
423: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)';
424: }
425: return \%loaditems;
426: }
427:
1.1 raeburn 428: sub check_can_request {
429: my ($dom,$can_request) = @_;
430: my $canreq = 0;
1.4 raeburn 431: my ($types,$typename) = &course_types();
1.19 ! raeburn 432: my @options = ('approval','validate','autolimit');
! 433: my $optregex = join('|',@options);
1.4 raeburn 434: if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) {
435: foreach my $type (@{$types}) {
1.1 raeburn 436: if (&Apache::lonnet::usertools_access($env{'user.name'},
437: $env{'user.domain'},
438: $type,undef,'requestcourses')) {
439: $canreq ++;
440: if ($dom eq $env{'user.domain'}) {
441: $can_request->{$type} = 1;
442: }
443: }
444: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
445: my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type});
446: if (@curr > 0) {
447: $canreq ++;
448: unless ($dom eq $env{'user.domain'}) {
1.19 ! raeburn 449: if (grep(/^\Q$dom\E:($optregex)(=?\d*)$/,@curr)) {
1.1 raeburn 450: $can_request->{$type} = 1;
451: }
452: }
453: }
454: }
455: }
456: }
457: return $canreq;
458: }
459:
1.4 raeburn 460: sub course_types {
461: my @types = ('official','unofficial','community');
462: my %typename = (
463: official => 'Official course',
464: unofficial => 'Unofficial course',
465: community => 'Community',
466: );
467: return (\@types,\%typename);
468: }
469:
470:
1.1 raeburn 471: sub print_main_menu {
1.3 raeburn 472: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_;
1.4 raeburn 473: my ($types,$typename) = &course_types();
1.1 raeburn 474: my $onchange;
475: unless ($env{'form.interface'} eq 'textual') {
476: $onchange = 1;
477: }
478:
1.2 raeburn 479: my $nextstate_setter = "\n";
480: if (ref($states) eq 'HASH') {
481: foreach my $key (keys(%{$states})) {
482: if (ref($states->{$key}) eq 'ARRAY') {
483: $nextstate_setter .=
484: " if (actionchoice == '$key') {
485: nextstate = '".$states->{$key}[1]."';
486: }
487: ";
488: }
489: }
490: }
1.1 raeburn 491:
1.2 raeburn 492: my $js = <<"END";
1.1 raeburn 493:
1.2 raeburn 494: function nextPage(formname) {
495: var crschoice = document.requestcrs.crstype.value;
496: var actionchoice = document.requestcrs.action.value;
497: if (check_can_request(crschoice,actionchoice) == true) {
498: if ((actionchoice == 'new') && (crschoice == 'official')) {
499: nextstate = 'codepick';
500: } else {
501: $nextstate_setter
502: }
1.1 raeburn 503: formname.state.value= nextstate;
504: formname.submit();
505: }
506: return;
507: }
508:
1.2 raeburn 509: function check_can_request(crschoice,actionchoice) {
1.1 raeburn 510: var official = '';
511: var unofficial = '';
512: var community = '';
513: END
514:
515: foreach my $item (keys(%{$can_request})) {
516: $js .= "
517: $item = 1;
518: ";
519: }
520: my %lt = &Apache::lonlocal::texthash(
521: official => 'You are not permitted to request creation of an official course in this domain.',
522: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
523: community => 'You are not permitted to request creation of a community this domain.',
524: all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
525: );
526: $js .= <<END;
527: if (crschoice == 'official') {
528: if (official != 1) {
529: alert("$lt{'official'}");
530: return false;
531: }
532: } else {
533: if (crschoice == 'unofficial') {
534: if (unofficial != 1) {
535: alert("$lt{'unofficial'}");
536: return false;
537: }
538: } else {
539: if (crschoice == 'community') {
540: if (community != 1) {
541: alert("$lt{'community'}");
542: return false;
543: }
544: } else {
545: if (actionchoice == 'new') {
546: alert("$lt{'all'}");
547: return false;
548: }
549: }
550: }
551: }
552: return true;
553: }
554:
555: END
556:
1.3 raeburn 557: $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.
558: '<div>'.
1.1 raeburn 559: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
560: &Apache::lonhtmlcommon::start_pick_box().
1.8 raeburn 561: &Apache::lonhtmlcommon::row_title('Course Domain').
1.1 raeburn 562: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange));
563: if (!$onchange) {
564: $r->print(' <input type="submit" name="godom" value="'.
565: &mt('Change').'" />');
566: }
567: $r->print(&Apache::lonhtmlcommon::row_closure(1).
568: &Apache::lonhtmlcommon::end_pick_box().'</form></div>');
569:
1.2 raeburn 570: my $formname = 'requestcrs';
1.1 raeburn 571: my $nexttext = &mt('Next');
1.14 raeburn 572: $r->print(
573: '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'.
1.1 raeburn 574: &Apache::lonhtmlcommon::start_pick_box().
575: &Apache::lonhtmlcommon::row_title('Action').'
576: <input type="hidden" name="showdom" value="'.$dom.'" />
577: <select size="1" name="action" >
1.2 raeburn 578: <option value="new">'.&mt('New request').'</option>
1.1 raeburn 579: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
580: <option value="log">'.&mt('View request history').'</option>
581: </select>'.
582: &Apache::lonhtmlcommon::row_closure().
583: &Apache::lonhtmlcommon::row_title('Course Type').'
584: <select size="1" name="crstype">
1.4 raeburn 585: <option value="any">'.&mt('All types').'</option>');
586: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
587: foreach my $type (@{$types}) {
588: my $selected = '';
589: if ($type eq 'official') {
590: $selected = ' selected="selected"';
591: }
592: $r->print('<option value="'.$type.'"'.$selected.'>'.$typename->{$type}.
593: '</option>'."\n");
594: }
595: }
596: $r->print('</select>
1.1 raeburn 597: <input type="hidden" name="state" value="crstype" />'.
598: &Apache::lonhtmlcommon::row_closure(1).
599: &Apache::lonhtmlcommon::end_pick_box().'<br />
1.2 raeburn 600: <input type="button" name="next" value="'.$nexttext.'" onclick="javascript:nextPage(document.'.$formname.')" />
1.1 raeburn 601: </form></div>');
602: $r->print(&Apache::loncommon::end_page());
603: return;
604: }
605:
606: sub request_administration {
1.3 raeburn 607: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb) = @_;
1.2 raeburn 608: my $js;
1.16 raeburn 609: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
1.2 raeburn 610: $js = <<END;
1.1 raeburn 611:
612: function nextPage(formname,nextstate) {
613: formname.state.value= nextstate;
614: formname.submit();
615: }
1.16 raeburn 616:
617: END
618: }
619: if (($action eq 'new') || ($action eq 'view')) {
620: $js .= <<END;
621:
1.1 raeburn 622: function backPage(formname,prevstate) {
623: formname.state.value = prevstate;
624: formname.submit();
625: }
626:
627: END
1.2 raeburn 628: }
629: if ($action eq 'new') {
630: my $jsextra;
1.1 raeburn 631: unless (($state eq 'review') || ($state eq 'process')) {
1.2 raeburn 632: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.1 raeburn 633: }
1.3 raeburn 634: $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb);
1.8 raeburn 635: &print_request_form($r,$action,$state,$page,$states,$dom);
1.2 raeburn 636: } elsif ($action eq 'view') {
1.16 raeburn 637: my $jsextra;
638: my $formname = 'requestcrs';
639: my $prev = $states->{$action}[$page-1];
640: my $next = $states->{$action}[$page+1];
641: if ($state eq 'pick_request') {
642: $next = $states->{$action}[$page+1];
643: $jsextra = &viewrequest_javascript($formname,$next);
644: } elsif ($state eq 'details') {
645: $jsextra = &viewdetails_javascript($formname);
646:
647: } elsif ($state eq 'cancel') {
648: $jsextra = &viewcancel_javascript($formname);
649: }
650: $r->print(&header('Manage course requests',$js.$jscript.$jsextra,$loaditems).
651: $crumb);
652: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
1.11 raeburn 653: if ($state eq 'pick_request') {
1.16 raeburn 654: $r->print('<h3>'.&mt('Pending course requests').'</h3><div>'."\n".$form."\n".
655: &print_request_status($dom).'</form>');
656: } elsif ($state eq 'details') {
657: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
658: my $origcnum = $env{'form.cnum'};
659: if ($origcnum eq '') {
660: $origcnum = $env{'form.origcnum'};
661: }
662: if ($env{'form.crstype'} eq 'official') {
663: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
664: \%cat_order,\@code_order);
665: }
666: $r->print('<h3>'.&mt('Course Request Details').'</h3><div>'."\n".$form."\n".
667: &print_review($formname,$dom,\@codetitles,\%cat_titles,\%cat_order,
668: \@code_order)."\n".
669: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
670: my @excluded = &get_excluded_elements($dom,$states,'new','review');
671: push(@excluded,'origcnum');
672: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
673: my $other = 'modify';
674: my %navtxt = &Apache::lonlocal::texthash (
675: prev => 'Back',
676: other => 'Modify Request',
677: next => 'Cancel Request',
678: );
679: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'},
680: $state,$other,$navtxt{'other'});
681: $r->print('</form>');
682: } elsif ($state eq 'cancel') {
683: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
684: $r->print('<h3>'.&mt('Cancel course request').'</h3><div>'."\n".$form."\n".
685: $output);
686: my @excluded = &get_excluded_elements($dom,$states,'view','cancel');
687: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
688: my %navtxt = &Apache::lonlocal::texthash (
689: prev => 'Back',
690: next => 'Confirm Cancellation',
691: );
692: if ($result eq 'ok') {
693: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,
694: $navtxt{'next'},$state);
695: } else {
696: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},undef,'',$state);
697: }
698: $r->print('</form>');
699: } elsif ($state eq 'removal') {
700: my $cnum = $env{'form.origcnum'};
701: my $statuskey = 'status:'.$dom.':'.$cnum;
702: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
703: $env{'user.domain'},$env{'user.name'});
704: my $currstatus = $userreqhash{$statuskey};
705: my ($result,$error);
706: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
707: my %status = (
708: $statuskey => 'cancelled',
709: );
710: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
711: if ($statusresult eq 'ok') {
712: my $delresult =
713: &Apache::lonnet::del_dom('courserequestqueue',
714: [$cnum.'_'.$currstatus],$dom);
715: if ($delresult eq 'ok') {
716: $result = 'ok';
717: } else {
718: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
719: }
720: } else {
721: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
722: }
723: } else {
724: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
725: }
726: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
727: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
728: '<input type="hidden" name="action" value="'.$action.'" />'."\n".
729: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
730: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
731: if ($result eq 'ok') {
732: $r->print(&mt('Your course request has been cancelled.'));
733: } else {
734: $r->print('<div class="LC_error">'.
735: &mt('The request cancellation process was not complete.').
736: '<br />'.$error.'</div>');
737: }
738: $r->print('</form>');
1.11 raeburn 739: }
1.1 raeburn 740: } elsif ($action eq 'log') {
1.11 raeburn 741: $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
1.1 raeburn 742: }
1.2 raeburn 743: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 744: return;
745: }
746:
747: sub print_request_form {
1.2 raeburn 748: my ($r,$action,$state,$page,$states,$dom) = @_;
1.1 raeburn 749: my $formname = 'requestcrs';
1.2 raeburn 750: my ($next,$prev,$message,$output,$codepicker,$crstype);
751: $prev = $states->{$action}[$page-1];
752: $next = $states->{$action}[$page+1];
1.4 raeburn 753: my %navtxt = &Apache::lonlocal::texthash (
1.10 raeburn 754: prev => 'Back',
1.4 raeburn 755: next => 'Next',
756: );
1.2 raeburn 757: $crstype = $env{'form.crstype'};
1.1 raeburn 758: $r->print('<form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.2 raeburn 759: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1.1 raeburn 760: if ($crstype eq 'official') {
1.2 raeburn 761: if ($env{'form.instcode'} ne '') {
762: $instcode = $env{'form.instcode'};
763: }
764: }
765: if ($prev eq 'codepick') {
1.4 raeburn 766: if ($crstype eq 'official') {
767: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
768: \%cat_order,\@code_order);
769: }
1.2 raeburn 770: if (@code_order > 0) {
771: my $message;
772: if ($instcode eq '') {
1.1 raeburn 773: foreach my $item (@code_order) {
1.2 raeburn 774: $instcode .= $env{'form.instcode_'.$item};
1.1 raeburn 775: }
1.2 raeburn 776: $r->print('<input type="hidden" name="instcode" value="'.$instcode.'" />'."\n");
1.1 raeburn 777: }
778: if ($instcode ne '') {
1.2 raeburn 779: $code_chk = &Apache::lonnet::auto_validate_instcode('',$dom,$instcode);
1.17 raeburn 780: if ($code_chk eq 'valid') {
1.1 raeburn 781: $message = '<div class="LC_info">'.
782: &mt('The chosen course category [_1] is valid.','<b>'.
1.2 raeburn 783: $instcode.'</b>').'</div>';
1.1 raeburn 784: } else {
785: $message = '<div class="LC_warning">'.
786: &mt('No course was found matching your choice of institutional course category.');
787: if ($code_chk ne '') {
788: $message .= '<br />'.$code_chk;
789: }
790: $message .= '</div>';
791: }
1.2 raeburn 792: } else {
793: $message = '<div class="LC_warning">'.
794: &mt('No course was found matching your choice of institutional course category.');
1.1 raeburn 795: }
1.2 raeburn 796: unless ($code_chk eq 'ok') {
797: $prev = 'crstype';
798: }
799: $r->print($message);
1.1 raeburn 800: }
1.2 raeburn 801: }
802: if ($prev eq 'crstype') {
1.4 raeburn 803: if ($crstype eq 'official') {
804: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
805: \%cat_order,\@code_order);
806: }
1.2 raeburn 807: if (@code_order > 0) {
1.1 raeburn 808: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
809: \%cat_titles,\%cat_order);
1.2 raeburn 810: if ($codepicker) {
811: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box().$codepicker.
812: &Apache::lonhtmlcommon::end_pick_box().'</div>');
813: } else {
1.15 raeburn 814: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 815: }
816: } else {
1.15 raeburn 817: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.1 raeburn 818: }
1.2 raeburn 819: } elsif ($prev eq 'codepick') {
1.15 raeburn 820: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 821: } elsif ($state eq 'enrollment') {
1.4 raeburn 822: if ($crstype eq 'official') {
823: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
824: \%cat_order,\@code_order);
825: }
1.2 raeburn 826: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
827: \%cat_titles,\%cat_order,\@code_order));
828: } elsif ($state eq 'personnel') {
1.8 raeburn 829: $r->print(&print_personnel_menu($dom,$formname,$crstype));
1.4 raeburn 830: } elsif ($state eq 'review') {
1.16 raeburn 831: my $cnum;
832: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
833: $cnum = $env{'form.origcnum'};
834: } else {
835: $cnum = &Apache::lonnet::generate_coursenum($dom);
836: }
1.4 raeburn 837: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
838: \%cat_order,\@code_order);
1.16 raeburn 839: $r->print('<p>'.&mt('Review the details of the course request before submission.').'</p>'.
840: &print_review($formname,$dom,\@codetitles,\%cat_titles,\%cat_order,
841: \@code_order).
842: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.4 raeburn 843: $navtxt{'next'} = &mt('Submit course request');
1.10 raeburn 844: } elsif ($state eq 'process') {
845: if ($crstype eq 'official') {
846: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
847: \%cat_order,\@code_order);
848: }
849: my $result = &print_request_outcome($dom,\@codetitles,\@code_order);
1.13 raeburn 850: $r->print($result);
1.1 raeburn 851: }
1.16 raeburn 852: my @excluded = &get_excluded_elements($dom,$states,$action,$state);
853: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
854: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'},$state);
855: return;
856: }
857:
858: sub get_excluded_elements {
859: my ($dom,$states,$action,$state) = @_;
1.2 raeburn 860: my @excluded = ('counter');
861: my %elements = &form_elements($dom);
862: if (ref($states) eq 'HASH') {
863: if (ref($states->{$action}) eq 'ARRAY') {
864: my @items = @{$states->{$action}};
865: my $numitems = scalar(@items);
866: if ($numitems) {
867: for (my $i=$numitems-1; $i>=0; $i--) {
868: if (ref($elements{$action}) eq 'HASH') {
869: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1.16 raeburn 870: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1.2 raeburn 871: push(@excluded,$key);
872: }
873: }
874: }
875: last if ($items[$i] eq $state);
876: }
877: }
878: }
879: }
880: if (grep(/^instcode_/,@excluded)) {
881: push(@excluded,'instcode');
1.1 raeburn 882: }
1.16 raeburn 883: return @excluded;
1.1 raeburn 884: }
885:
1.2 raeburn 886: sub print_enrollment_menu {
887: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order) =@_;
888: my ($sections,$autoenroll,$access_dates);
889: my $starttime = time;
890: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
891:
892: my %accesstitles = (
893: 'start' => 'Default start access',
1.16 raeburn 894: 'end' => 'Default end access',
1.2 raeburn 895: );
896: my %enrolltitles = (
897: 'start' => 'Start auto-enrollment',
898: 'end' => 'End auto-enrollment',
899: );
900: if ($env{'form.crstype'} eq 'official') {
901: if (&Apache::lonnet::auto_run('',$dom)) {
902: my ($section_form,$crosslist_form,$autoenroll_form);
903: $section_form = &inst_section_selector($dom,$instcode);
904: my $crosslisttotal = $env{'form.crosslisttotal'};
905: if (!defined($crosslisttotal)) {
906: $crosslisttotal = 1;
907: }
908: if ($env{'form.addcrosslist'}) {
909: $crosslisttotal ++;
910: }
911: for (my $i=0; $i<$crosslisttotal; $i++) {
912: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
913: $cat_titles,$cat_order,$i);
914: }
915: if ($crosslist_form) {
916: $crosslist_form .=
917: &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
918: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
919: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
920: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
921: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1);
922: }
923: if ($section_form || $crosslist_form) {
924: $sections = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
925: $section_form.$crosslist_form.
926: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
927: }
928: $autoenroll_form =
929: &Apache::lonhtmlcommon::row_title(&mt('Add registered students automatically')).
930: '<span class="LC_nobreak"><label>'.
931: '<input type="radio" name="autoadds" value="1">'.
932: &mt('Yes').'</label>'.(' 'x3).'<label>'.
933: '<input type="radio" name="autoadds" value="0" checked="checked">'.
934: &mt('No').'</label></span>'.
935: &Apache::lonhtmlcommon::row_closure().
936: &Apache::lonhtmlcommon::row_title(&mt('Drop unregistered students automatically')).
937: '<span class="LC_nobreak"><label>'.
938: '<input type="radio" name="autodrops" value="1">'.
939: &mt('Yes').'</label>'.(' 'x3).'<label>'.
940: '<input type="radio" name="autodrops" value="0" checked="checked">'.
941: &mt('No').'</label></span>'.
942: &Apache::lonhtmlcommon::row_closure().
943: &date_setting_table($starttime,$endtime,$formname,'enroll',%enrolltitles);
944: if ($autoenroll_form) {
945: $autoenroll = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
946: $autoenroll_form.
947: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
948: }
949: }
950: }
951: my $access_dates_form =
952: &date_setting_table($starttime,$endtime,$formname,'access',%accesstitles);
953: if ($access_dates_form) {
954: $access_dates = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
955: $access_dates_form.
956: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
957: }
958: return $sections.$autoenroll.$access_dates;
959: }
960:
1.1 raeburn 961: sub inst_section_selector {
1.2 raeburn 962: my ($dom,$instcode) = @_;
963: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
964: my $sectotal = scalar(@sections);
1.1 raeburn 965: my $output;
1.2 raeburn 966: if ($sectotal) {
967: $output .= &Apache::lonhtmlcommon::row_title('Sections').
968: &Apache::loncommon::start_data_table().
969: &Apache::loncommon::start_data_table_row().
970: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
971: 'value="'.$sectotal.'"</th>'.
972: '<th>'.&mt('Institutional Section').'</th>'.
973: '<th>'.&mt('LON-CAPA section').'</th>'.
974: &Apache::loncommon::end_data_table_row();
975: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 976: my $colflag = $i%2;
977: $output .= &Apache::loncommon::start_data_table_row().
1.2 raeburn 978: '<td><input type="checkbox" name="sec_'.$i.
979: '" checked="checked" /></td>'.
980: '<td>'.$sections[$i].
1.1 raeburn 981: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 982: $sections[$i].'" /></td>'.
1.1 raeburn 983: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 984: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 985: &Apache::loncommon::end_data_table_row();
986: }
1.2 raeburn 987: $output .= &Apache::loncommon::end_data_table().
988: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 989: }
990: return $output;
991: }
992:
1.2 raeburn 993: sub date_setting_table {
1.14 raeburn 994: my ($starttime,$endtime,$formname,$prefix,%datetitles) = @_;
1.2 raeburn 995: my ($perpetual,$table);
1.14 raeburn 996: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.2 raeburn 997: $starttime,'','','',1,'','','',1);
1.14 raeburn 998: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.2 raeburn 999: $endtime,'','','',1,'','','',1);
1.14 raeburn 1000: if ($prefix eq 'access') {
1.2 raeburn 1001: $perpetual = ' <span class="LC_nobreak"><label>'.
1002: '<input type="checkbox" name="no_end_date" />'.
1003: &mt('No end date').'</label></span>';
1004: }
1005: $table = &Apache::lonhtmlcommon::row_title($datetitles{'start'}).
1006: $startform.
1007: &Apache::lonhtmlcommon::row_closure().
1008: &Apache::lonhtmlcommon::row_title($datetitles{'end'}).
1009: $endform.$perpetual.
1010: &Apache::lonhtmlcommon::row_closure(1);
1011: return $table;
1012: }
1013:
1014: sub print_personnel_menu {
1.8 raeburn 1015: my ($dom,$formname,$crstype) = @_;
1.2 raeburn 1016: my $output = '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1017: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 1018: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 1019: $persontotal = 1;
1020: }
1021: if ($env{'form.addperson'}) {
1022: $persontotal ++;
1023: }
1024: my $userlinktxt = &mt('Set User');
1.13 raeburn 1025: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2 raeburn 1026:
1027: my $roleoptions;
1028: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 1029: my $type = 'Course';
1030: if ($crstype eq 'community') {
1031: $type = 'Community';
1032: }
1.2 raeburn 1033: foreach my $role (@roles) {
1.8 raeburn 1034: my $plrole=&Apache::lonnet::plaintext($role,$type);
1.2 raeburn 1035: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1036: }
1037: my %customroles=&Apache::lonuserutils::my_custom_roles();
1038: if (keys(%customroles) > 0) {
1039: foreach my $cust (sort(keys(%customroles))) {
1040: my $custrole='cr_cr_'.$env{'user.domain'}.
1041: '_'.$env{'user.name'}.'_'.$cust;
1042: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1043: }
1044: }
1045:
1046: my @currsecs;
1047: if ($env{'form.sectotal'}) {
1048: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1049: if (defined($env{'form.loncapasec_'.$i})) {
1050: my $lcsec = $env{'form.loncapasec_'.$i};
1051: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
1052: push(@currsecs,$lcsec);
1053: }
1054: }
1055: }
1056: }
1057:
1058: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1059: if (@currsecs) {
1060: my $existsize = scalar(@currsecs);
1061: if ($existsize > 3) {
1062: $existsize = 3;
1063: }
1064: if ($existsize > 1) {
1065: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1066: }
1067: @currsecs = sort { $a <=> $b } (@currsecs);
1068: $existtitle = &mt('Official').': ';
1069: $existops = '<option value="">'.&mt('None').'</option>';
1070: foreach my $sec (@currsecs) {
1071: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1072: }
1073: $seccolspan = ' colspan="2"';
1074: $newtitle = &mt('Other').': ';
1075: }
1076:
1077: for (my $i=0; $i<$persontotal; $i++) {
1078: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1079: my $linkargstr = join("','",@linkargs);
1.7 raeburn 1080: my $userlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,$userlinktxt);
1.2 raeburn 1081: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value=""'.
1082: ' onFocus="this.blur();'.
1.7 raeburn 1083: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');" />';
1.2 raeburn 1084: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1085: "'person_".$i."_hidedom'".');'.
1.7 raeburn 1086: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');';
1.2 raeburn 1087: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1088: 1,$onchange).
1089: '<input type="hidden" name="person_'.$i.'_hidedom" value="'.$dom.'" />';
1090: my %form_elems;
1091: foreach my $item (@items) {
1092: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1093: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1094: 'value="" readonly="readonly" />';
1095: }
1096: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1097: $roleoptions.'</select>';
1098: my $sectionselector;
1099: if (@currsecs) {
1100: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1101: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1102: }
1103: $sectionselector .= $newtitle.
1.14 raeburn 1104: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.2 raeburn 1105: $output .=
1106: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel').'<br />'.
1107: '<span class="LC_nobreak">'.$userlink.
1108: '</span>').
1109: '<table><tr><td align="center" valign="top">'.&mt('Username').'<br />'.$uname_form.'</td>'."\n".
1110: '<td align="center" valign="top" colspan="2">'.&mt('Domain').'<br />'.$udom_form.'</td></tr><tr>'."\n".
1.13 raeburn 1111: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1112: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1113: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.2 raeburn 1114: '<tr><td align="center" valign="top">'.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
1115: '<td'.$seccolspan.' align="center" valign="top">'.&mt('Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1116: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
1117: }
1118: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
1119: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
1120: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1121: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1122: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1123: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1124: return $output;
1125: }
1126:
1.1 raeburn 1127: sub print_request_status {
1.11 raeburn 1128: my ($dom) = @_;
1.14 raeburn 1129: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
1130: $env{'user.name'},'^status:'.$dom);
1131: my ($output,$formname,%queue_by_date,%typenames);
1132: if ($env{'form.crstype'} eq 'any') {
1133: %typenames = &Apache::lonlocal::texthash (
1134: official => 'Official course',
1135: unofficial => 'Unofficial course',
1136: community => 'Community',
1137: );
1138: }
1139: foreach my $key (keys(%statusinfo)) {
1140: if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {
1141: (undef,my($cdom,$cnum)) = split(':',$key);
1142: next if ($cdom ne $dom);
1143: my $requestkey = $cdom.'_'.$cnum;
1144: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1145: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1146: $env{'user.domain'},$env{'user.name'});
1147: my $entry;
1148: my $timestamp = $history{'reqtime'};
1149: my $crstype = $history{'crstype'};
1150: my $disposition = $history{'disposition'};
1151: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1152: next unless (($env{'form.crstype'} eq 'any') ||
1153: ($env{'form.crstype'} eq $crstype));
1154: next unless (($disposition eq 'approval') ||
1155: ($disposition eq 'pending'));
1156: if (ref($history{'details'}) eq 'HASH') {
1157: $entry = $requestkey.':'.$crstype.':'.
1158: &escape($history{'details'}{'cdescr'});
1159: if ($crstype eq 'official') {
1160: $entry .= ':'.&escape($history{'details'}{'instcode'});
1161: }
1162: }
1163: if ($entry ne '') {
1164: if (exists($queue_by_date{$timestamp})) {
1165: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
1166: push(@{$queue_by_date{$timestamp}},$entry);
1167: }
1168: } else {
1169: @{$queue_by_date{$timestamp}} = ($entry);
1.10 raeburn 1170: }
1171: }
1172: }
1173: }
1174: }
1.11 raeburn 1175: $formname = 'requestcrs';
1.10 raeburn 1176: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.16 raeburn 1177: $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1178:
1.10 raeburn 1179: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1.16 raeburn 1180: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
1181: '<input type="hidden" name="showdom" value="" />'."\n".
1182: '<input type="hidden" name="cnum" value="" />'."\n";
1.10 raeburn 1183: if (@sortedtimes > 0) {
1184: $output .= &Apache::loncommon::start_data_table().
1185: &Apache::loncommon::start_data_table_header_row().
1186: '<th>'.&mt('Action').'</th>'.
1.14 raeburn 1187: '<th>'.&mt('Course Description').'</th>'.
1188: '<th>'.&mt('Domain').'</th>';
1189: if ($env{'form.crstype'} eq 'any') {
1.10 raeburn 1190: $output .= '<th>'.&mt('Type').'</th>';
1191: }
1.14 raeburn 1192: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10 raeburn 1193: $output .= '<th>'.&mt('Institutional Code').'</th>';
1194: }
1195: $output .= '<th>'.&mt('Date requested').'</th>'.
1196: &Apache::loncommon::end_data_table_header_row();
1197: my $count = 0;
1198: foreach my $item (@sortedtimes) {
1199: my $showtime = &Apache::lonlocal::locallocaltime($item);
1200: if (ref($queue_by_date{$item}) eq 'ARRAY') {
1201: foreach my $request (sort(@{$queue_by_date{$item}})) {
1202: my ($key,$type,$desc,$instcode) = split(':',$request);
1203: my ($cdom,$cnum) = split('_',$key);
1204: $output .= &Apache::loncommon::start_data_table_row().
1.16 raeburn 1205: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14 raeburn 1206: '<td>'.&unescape($desc).'</td>'.
1207: '<td>'.$cdom.'</td>';
1208: if ($env{'form.crstype'} eq 'any') {
1209: my $typename = $typenames{$type};
1210: if ($typename eq '') {
1211: $typename = &mt('Unknown type');
1212: }
1213: $output .= '<td>'.$typename.'</td>';
1.10 raeburn 1214: }
1.14 raeburn 1215: if (($env{'form.crstype'} eq 'any') ||
1.10 raeburn 1216: ($env{'form.crstype'} eq 'official')) {
1.14 raeburn 1217: my $showinstcode;
1218: if ($type eq 'official') {
1219: $showinstcode = &unescape($instcode);
1220: } else {
1221: $showinstcode = &mt('Not applicable');
1222: }
1223: $output .= '<td>'.$showinstcode.'</td>';
1.10 raeburn 1224: }
1225: $output .= '<td>'.$showtime.'</td>'.
1226: &Apache::loncommon::end_data_table_row();
1227: }
1228: }
1229: }
1230: $output .= &Apache::loncommon::end_data_table();
1231: } else {
1.11 raeburn 1232: $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 1233: }
1234: $output .= '
1.14 raeburn 1235: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />
1236: </form></div>';
1.10 raeburn 1237: return $output;
1.1 raeburn 1238: }
1239:
1.16 raeburn 1240: sub print_cancel_request {
1241: my ($dom,$cnum) = @_;
1242: my $requestkey = $dom.'_'.$cnum;
1243: my ($result,$output);
1244: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1245: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1246: $env{'user.domain'},$env{'user.name'});
1247: my $timestamp = $history{'reqtime'};
1248: my $crstype = $history{'crstype'};
1249: my $status = $history{'status'};
1250: if (($status eq 'cancelled') || ($status eq 'created')) {
1251: if ($status eq 'cancelled') {
1252: $output = &mt('This request has already been cancelled.');
1253: } elsif ($status eq 'created') {
1254: $output = &mt('This request has already been processed, and a course created.');
1255: }
1256: $output = &mt('No further action will be taken');
1257: } elsif (ref($history{'details'}) eq 'HASH') {
1258: my ($types,$typename) = &course_types();
1259: my $showtype = $crstype;
1260: if (defined($typename->{$crstype})) {
1261: $showtype = $typename->{$crstype};
1262: }
1263: $output = '<p>'.&Apache::loncommon::start_data_table().
1264: &Apache::loncommon::start_data_table_header_row().
1265: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
1266: '<th>'.&mt('Type').'</th>'.
1267: &Apache::loncommon::end_data_table_header_row().
1268: &Apache::loncommon::start_data_table_row().
1269: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
1270: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
1271: '<td>'.$showtype.'</td>'.
1272: &Apache::loncommon::end_data_table_row().
1273: &Apache::loncommon::end_data_table().
1274: '<br /><div class="LC_warning">'.
1275: &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
1276: $result = 'ok';
1277: } else {
1278: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
1279: }
1280: } else {
1281: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
1282: }
1283: return ($result,$output);
1284: }
1285:
1286: sub viewrequest_javascript {
1287: my ($formname,$next) = @_;
1288: return <<"ENDJS";
1289:
1290: function chooseRequest(cdom,cnum) {
1291: document.$formname.showdom.value = cdom;
1292: document.$formname.cnum.value = cnum;
1293: nextPage(document.$formname,'$next');
1294: }
1295:
1296: ENDJS
1297: }
1298:
1299: sub viewdetails_javascript {
1300: my ($formname) = @_;
1301: return << "ENDJS";
1302:
1303: function nextPage(formname,nextstate) {
1304: if (nextstate == "modify") {
1305: formname.state.value = "personnel";
1306: formname.action.value = "new";
1307: } else {
1308: formname.state.value = nextstate;
1309: }
1310: formname.submit();
1311: }
1312:
1313: function backPage(formname,prevstate) {
1314: formname.state.value = prevstate;
1315: formname.submit();
1316: }
1317:
1318: ENDJS
1319: }
1320:
1321: sub viewcancel_javascript {
1322: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
1323: 'Your request will be removed.');
1324: return << "ENDJS";
1325: function nextPage(formname,nextstate) {
1326: if (confirm('$alert')) {
1327: formname.state.value = nextstate;
1328: formname.submit();
1329: }
1330: return;
1331: }
1332:
1333: ENDJS
1334: }
1335:
1.1 raeburn 1336: sub print_request_logs {
1.10 raeburn 1337: my ($jscript,$loaditems,$crumb) = @_;
1.1 raeburn 1338: return;
1339: }
1340:
1341: sub print_review {
1.4 raeburn 1342: my ($formname,$dom,$codetitles,$cat_titles,$cat_order,$code_order) = @_;
1343: my ($types,$typename) = &course_types();
1344: my ($owner,$ownername,$owneremail);
1345: $owner = $env{'user.name'}.':'.$env{'user.domain'};
1346: $ownername = &Apache::loncommon::plainname($env{'user.name'},
1347: $env{'user.domain'},'first');
1348: my %emails = &Apache::loncommon::getemails();
1349: foreach my $email ('permanentemail','critnotification','notification') {
1350: $owneremail = $emails{$email};
1351: last if ($owneremail ne '');
1352: }
1353: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
1354: $section_headers,$section_values,$personnel_headers,$personnel_values);
1355:
1356: $crstypename = $env{'form.crstype'};
1357: if (ref($typename) eq 'HASH') {
1358: unless ($typename->{$env{'form.crstype'}} eq '') {
1359: $crstypename = $typename->{$env{'form.crstype'}};
1360: }
1361: }
1.16 raeburn 1362: my $category = 'Course';
1363: if ($env{'form.crstype'} eq 'community') {
1364: $category = 'Community';
1365: }
1.4 raeburn 1366:
1367: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
1368: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
1369:
1.16 raeburn 1370: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
1371: '('.&Apache::lonnet::plaintext('st',$category).')';
1.4 raeburn 1372: if ($env{'form.crstype'} eq 'official') {
1373: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
1374: foreach my $title (@{$codetitles}) {
1375: if ($env{'form.instcode_'.$title} ne '') {
1376: $inst_headers .= '<th>'.$title.'</th>';
1377: my $longitem = $env{'form.instcode_'.$title};
1378: if (ref($cat_titles->{$title}) eq 'HASH') {
1379: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
1380: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
1381: }
1382: }
1383: $inst_values .= '<td>'.$longitem.'</td>';
1384: }
1385: }
1386: }
1387: if (&Apache::lonnet::auto_run('',$dom)) {
1.16 raeburn 1388: $enrollrow_title = &mt('Enrollment');
1.4 raeburn 1389: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
1390: '<th>'.&mt('Automatic Drops').'</th>'.
1391: '<th>'.&mt('Enrollment Starts').'</th>'.
1392: '<th>'.&mt('Enrollment Ends').'</th>';
1393: $section_headers = '<th>'.&mt('Sections').'</th>'.
1394: '<th>'.&mt('Crosslistings').'</th>';
1395:
1.13 raeburn 1396: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4 raeburn 1397: my @autoroster = (&mt('No'),&mt('Yes'));
1398: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
1399: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13 raeburn 1400: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
1401: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6 raeburn 1402: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
1403: &mt('Institutional section').'</th>'.
1404: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 1405: my $secinfo;
1.4 raeburn 1406: if ($env{'form.sectotal'} > 0) {
1407: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1408: if ($env{'form.sec_'.$i}) {
1.5 raeburn 1409: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 1410: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 1411: $secinfo .= $env{'form.loncapasec_'.$i};
1412: } else {
1413: $secinfo .= &mt('None');
1.4 raeburn 1414: }
1.5 raeburn 1415: $secinfo .= '</td></tr>';
1.4 raeburn 1416: }
1417: }
1418: }
1.6 raeburn 1419: if ($secinfo eq '') {
1420: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 1421: }
1.6 raeburn 1422: $section_values .= $secinfo.'</table></td><td>'.
1423: '<table class="LC_innerpickbox"><tr><th>'.
1424: &mt('Institutional course/section').'</th>'.
1425: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 1426: my $xlistinfo;
1.4 raeburn 1427: if ($env{'form.crosslisttotal'}) {
1428: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1429: if ($env{'form.crosslist_'.$i}) {
1.5 raeburn 1430: $xlistinfo .= '<tr><td>';
1431: if (ref($code_order) eq 'ARRAY') {
1432: if (@{$code_order} > 0) {
1433: foreach my $item (@{$code_order}) {
1434: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 1435: }
1436: }
1437: }
1.5 raeburn 1438: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
1.4 raeburn 1439: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
1.5 raeburn 1440: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
1441: } else {
1442: $xlistinfo .= &mt('None');
1.4 raeburn 1443: }
1.5 raeburn 1444: $xlistinfo .= '</td></tr>';
1.4 raeburn 1445: }
1446: }
1447: }
1.6 raeburn 1448: if ($xlistinfo eq '') {
1449: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 1450: }
1.6 raeburn 1451: $section_values .= $xlistinfo.'</table></td>';
1.4 raeburn 1452: }
1453: }
1454:
1455: my %ctxt = &clone_text();
1456: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1.13 raeburn 1457: if (($env{'form.clonecrs'} =~ /^$match_name$/) &&
1458: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1.15 raeburn 1459: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1460: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
1461: if ($canclone) {
1462: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
1463: $env{'form.clonecrs'},('description','internal.coursecode'));
1464: if (keys(%courseenv) > 0) {
1465: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
1466: $inst_values .= '<td>'.$courseenv{'description'}.' ';
1467: my $cloneinst = $courseenv{'internal.coursecode'};
1468: if ($cloneinst ne '') {
1.18 raeburn 1469: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1.15 raeburn 1470: } else {
1.18 raeburn 1471: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1.15 raeburn 1472: }
1473: $inst_values .= '</td><td>';
1474: if ($env{'form.datemode'} eq 'preserve') {
1.16 raeburn 1475: $inst_values .= $ctxt{'prd'};
1.15 raeburn 1476: } elsif ($env{'form.datemode'} eq 'shift') {
1477: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
1478: } else {
1479: $inst_values .= $ctxt{'ncd'};
1480: }
1481: $inst_values .= '</td>';
1482: } else {
1483: $inst_values .= '<td>'.&mt('Unknown').'</td>';
1484: }
1485: } else {
1486: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
1487: }
1.4 raeburn 1488: } else {
1489: $inst_values .= '<td>'.&mt('None').'</td>';
1490: }
1491: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
1492: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 1493: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1494: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
1495: if ($accessend == 0) {
1.4 raeburn 1496: $enroll_values .= '<td>'.&mt('No end date').'</td>';
1497: } else {
1.13 raeburn 1498: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 1499: }
1500:
1501: my $container = 'Course';
1502: if ($env{'form.crstype'} eq 'community') {
1503: $container = 'Community';
1504: }
1505:
1506: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
1507: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
1508: '</th>';
1509: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1510: '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
1511: '<td>'.&mt('None').'</td></tr>';
1512: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1513: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.14 raeburn 1514: my @allsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1515: my $newsec = $env{'form.person_'.$i.'_newsec'};
1516: $newsec =~ s/^\s+//;
1517: $newsec =~s/\s+$//;
1518: my @newsecs = split(/[\s,;]+/,$newsec);
1519: foreach my $sec (@newsecs) {
1520: next if ($sec =~ /\W/);
1521: next if ($newsec eq 'none');
1522: if ($sec ne '') {
1523: unless (grep(/^\Q$sec\E$/,@allsecs)) {
1524: push(@allsecs,$sec);
1525: }
1526: }
1527: }
1528: my $showsec = 'None';
1529: if (@allsecs) {
1530: $showsec = join(', ',@allsecs);
1531: }
1.4 raeburn 1532: $personnel_values .=
1.13 raeburn 1533: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
1534: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 1535: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
1536: $env{'form.person_'.$i.'_dom'}.'</td>'.
1537: '<td>'.&Apache::lonnet::plaintext($env{'form.person_'.$i.'_role'},
1538: $container).'</td>'.
1.14 raeburn 1539: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 1540: }
1541: }
1.16 raeburn 1542: my $output =
1.4 raeburn 1543: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1544: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 1545: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 1546: '<th>'.&mt('Name').'</th>'.
1547: '<th>'.&mt('Username:Domain').'</th>'.
1548: '<th>'.&mt('E-mail address').'</th>'.
1549: '</tr><tr>'."\n".
1550: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
1551: '<td>'.$owneremail.'</td>'.
1552: '</tr></table>'."\n".
1553: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 1554: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 1555: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
1556: '<tr>'.$inst_values.'</tr></table>'."\n".
1557: &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 1558: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4 raeburn 1559: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
1560: '<tr>'.$enroll_values.'</tr></table>'."\n".
1561: &Apache::lonhtmlcommon::row_closure();
1562: if ($section_headers ne '') {
1563: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
1564: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
1565: '<tr>'.$section_values.'</tr></table>'."\n".
1566: &Apache::lonhtmlcommon::row_closure();
1567: }
1568: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
1569: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
1570: $personnel_values.'</table>'."\n".
1571: &Apache::lonhtmlcommon::row_closure(1).
1572: &Apache::lonhtmlcommon::end_pick_box();
1573: return $output;
1574: }
1575:
1576: sub dates_from_form {
1577: my ($startname,$endname) = @_;
1578: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1579: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 1580: if ($endname eq 'accessend') {
1.4 raeburn 1581: if (exists($env{'form.no_end_date'}) ) {
1582: $enddate = 0;
1583: }
1584: }
1585: return ($startdate,$enddate);
1.1 raeburn 1586: }
1587:
1588: sub courseinfo_form {
1.15 raeburn 1589: my ($dom,$formname,$crstype,$next) = @_;
1590: my $nodescr = &mt('You must provide a (brief) course description.');
1591: my $js_validate = <<"ENDJS";
1592: <script type="text/javascript">
1593: // <![CDATA['
1594:
1595: function validateForm() {
1596: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1597: alert('$nodescr');
1598: return;
1599: }
1600: nextPage(document.$formname,'$next');
1601: }
1602: // ]]
1603: </script>
1604:
1605: ENDJS
1606:
1607: my $output .= $js_validate."\n".'<div>'.&Apache::lonhtmlcommon::start_pick_box().
1608: &Apache::lonhtmlcommon::row_title('Course Description').
1.13 raeburn 1609: '<input type="text" size="40" name="cdescr" />';
1610: my ($home_server_pick,$numlib) =
1611: &Apache::loncommon::home_server_form_item($dom,'chome',
1612: 'default','hide');
1613: if ($numlib > 1) {
1614: $output .= &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 1615: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13 raeburn 1616: }
1617: $output .= $home_server_pick.
1618: &Apache::lonhtmlcommon::row_closure(1).
1619: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
1620: '<div>'.&clone_form($dom,$formname,$crstype).'</div>'."\n";
1.1 raeburn 1621: return $output;
1622: }
1623:
1624: sub clone_form {
1625: my ($dom,$formname,$crstype) = @_;
1626: my $type = 'Course';
1627: if ($crstype eq 'community') {
1628: $type = 'Community';
1629: }
1.13 raeburn 1630: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').
1631: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1.4 raeburn 1632: my %lt = &clone_text();
1.2 raeburn 1633: my $output .=
1634: &Apache::lonhtmlcommon::start_pick_box().
1635: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.13 raeburn 1636: '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();'.
1637: 'opencrsbrowser('."'$formname','clonecrs','clonedom','','','','$type'".');" />'.
1.2 raeburn 1638: '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
1639: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
1640: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure().
1641: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
1642: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
1643: '</label><br /><label>'.
1644: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
1645: '</label><br /><label>'.
1646: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
1647: $lt{'shd'}.'</label>'.
1648: '<input type="text" size="5" name="dateshift" value="365" />'.
1649: &Apache::lonhtmlcommon::row_closure(1).
1650: &Apache::lonhtmlcommon::end_pick_box();
1.1 raeburn 1651: return $output;
1652: }
1653:
1.16 raeburn 1654: sub clone_text {
1.4 raeburn 1655: return &Apache::lonlocal::texthash(
1656: 'cid' => 'Course ID',
1657: 'dmn' => 'Domain',
1658: 'dsh' => 'Date Shift',
1659: 'ncd' => 'Do not clone date parameters',
1660: 'prd' => 'Clone date parameters as-is',
1661: 'shd' => 'Shift date parameters by number of days',
1662: );
1663: }
1664:
1.1 raeburn 1665: sub coursecode_form {
1.2 raeburn 1666: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 1667: my $output;
1.2 raeburn 1668: my %rowtitle = (
1669: instcode => 'Course Category',
1670: crosslist => 'Cross Listed Course',
1671: );
1.1 raeburn 1672: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
1673: (ref($cat_order))) {
1.2 raeburn 1674: my ($sel,$instsec,$lcsec);
1675: $sel = $context;
1676: if ($context eq 'crosslist') {
1677: $sel .= '_'.$num;
1678: $instsec = &mt('Institutional section').'<br />'.
1679: '<input type="text" size="10" name="'.$sel.'_instsec" />';
1680: $lcsec = &mt('LON-CAPA section').'<br />'.
1681: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
1682: }
1.1 raeburn 1683: if (@{$codetitles} > 0) {
1684: my $lastitem = pop(@{$codetitles});
1.2 raeburn 1685: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 1686: if (@{$codetitles} > 0) {
1.2 raeburn 1687: $output = &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1688: '<table><tr>';
1.1 raeburn 1689: if ($context eq 'crosslist') {
1.2 raeburn 1690: $output .= '<td>'.&mt('Include?').'<br />'.
1691: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 1692: }
1693: foreach my $title (@{$codetitles}) {
1694: if (ref($cat_order->{$title}) eq 'ARRAY') {
1695: if (@{$cat_order->{$title}} > 0) {
1696: $output .= '<td align="center">'.$title.'<br />'."\n".
1697: '<select name="'.$sel.'_'.$title.'">'."\n".
1698: ' <option value="" selected="selected">'.
1699: &mt('Select').'</option>'."\n";
1700: foreach my $item (@{$cat_order->{$title}}) {
1701: my $longitem = $item;
1702: if (ref($cat_titles->{$title}) eq 'HASH') {
1703: if ($cat_titles->{$title}{$item} ne '') {
1704: $longitem = $cat_titles->{$title}{$item};
1705: }
1706: }
1707: $output .= '<option value="'.$item.'">'.$longitem.
1708: '</option>'."\n";
1709: }
1710: }
1711: $output .= '</select></td>'."\n";
1712: }
1713: }
1714: if ($context eq 'crosslist') {
1715: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 1716: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
1717: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 1718: } else {
1719: $output .= '</tr></table>'.
1720: &Apache::lonhtmlcommon::row_closure().
1721: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1722: $lastinput;
1723: }
1724: } else {
1725: if ($context eq 'crosslist') {
1726: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 1727: '<table><tr>'.
1728: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
1729: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
1730: '</tr></table>';
1.1 raeburn 1731: } else {
1732: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1733: $lastinput;
1734: }
1735: }
1.2 raeburn 1736: $output .= &Apache::lonhtmlcommon::row_closure(1);
1737: push(@$codetitles,$lastitem);
1738: } elsif ($context eq 'crosslist') {
1739: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1740: '<table><tr><td align="center">'.
1741: '<span class="LC_nobreak">'.&mt('Include?').
1742: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
1743: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
1744: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
1745: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
1746: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 1747: }
1748: }
1749: return $output;
1750: }
1751:
1752: sub get_course_dom {
1753: my $codedom = &Apache::lonnet::default_login_domain();
1.19 ! raeburn 1754: if ($env{'form.showdom'} ne '') {
! 1755: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
! 1756: return $env{'form.showdom'};
! 1757: }
! 1758: }
1.1 raeburn 1759: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.19 ! raeburn 1760: my ($types,$typename) = &course_types();
! 1761: if (ref($types) eq 'ARRAY') {
! 1762: foreach my $type (@{$types}) {
! 1763: if (&Apache::lonnet::usertools_access($env{'user.name'},
! 1764: $env{'user.domain'},$type,
! 1765: undef,'requestcourses')) {
! 1766: return $env{'user.domain'};
! 1767: }
! 1768: }
! 1769: my @possible_doms;
! 1770: foreach my $type (@{$types}) {
! 1771: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
! 1772: if ($dom_str ne '') {
! 1773: my @domains = split(',',$dom_str);
! 1774: foreach my $entry (@domains) {
! 1775: my ($extdom,$extopt) = split(':',$entry);
! 1776: if ($extdom eq $env{'request.role.domain'}) {
! 1777: return $extdom;
! 1778: }
! 1779: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
! 1780: push(@possible_doms,$extdom);
! 1781: }
! 1782: }
! 1783: }
! 1784: }
! 1785: if (@possible_doms) {
! 1786: @possible_doms = sort(@possible_doms);
! 1787: return $possible_doms[0];
! 1788: }
! 1789: }
1.1 raeburn 1790: $codedom = $env{'user.domain'};
1791: if ($env{'request.role.domain'} ne '') {
1792: $codedom = $env{'request.role.domain'};
1793: }
1794: }
1795: return $codedom;
1796: }
1797:
1798: sub display_navbuttons {
1.16 raeburn 1799: my ($r,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1 raeburn 1800: $r->print('<div class="LC_navbuttons">');
1801: if ($prev) {
1.16 raeburn 1802: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1803: 'onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>'.
1804: (' 'x3));
1.1 raeburn 1805: } elsif ($prevtext) {
1.16 raeburn 1806: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1807: 'onclick="javascript:history.back()"/>'.(' 'x3));
1808: }
1809: if ($state eq 'details') {
1810: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1811: 'onclick="javascript:nextPage(document.'.$formname.','."'".$other."'".
1812: ')" />');
1.1 raeburn 1813: }
1.15 raeburn 1814: if ($state eq 'courseinfo') {
1.16 raeburn 1815: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
1816: 'onclick="javascript:validateForm();" />');
1.15 raeburn 1817: } elsif ($next) {
1.1 raeburn 1818: $r->print('
1.16 raeburn 1819: <input type="button" name="next" value="'.$nexttext.'" '.
1820: 'onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1.1 raeburn 1821: }
1822: $r->print('</div>');
1823: }
1824:
1825: sub print_request_outcome {
1.10 raeburn 1826: my ($dom,$codetitles,$code_order) = @_;
1.13 raeburn 1827: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10 raeburn 1828: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1829: $cnum = $env{'form.cnum'};
1.8 raeburn 1830: unless ($cnum =~ /^$match_courseid$/) {
1831: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
1832: return $output;
1833: }
1.11 raeburn 1834:
1.10 raeburn 1835: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 1836: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
1837: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
1838: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
1839: }
1840: }
1.10 raeburn 1841: $now = time;
1842: $crstype = $env{'form.crstype'};
1.17 raeburn 1843: my @instsections;
1.8 raeburn 1844: if ($crstype eq 'official') {
1845: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 1846: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 1847: }
1.10 raeburn 1848: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1849: if ($env{'form.sec_'.$i}) {
1850: if ($env{'form.secnum_'.$i} ne '') {
1.17 raeburn 1851: my $sec = $env{'form.secnum_'.$i};
1852: $sections{$i}{'inst'} = $sec;
1853: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
1854: push(@instsections,$sec);
1855: }
1.13 raeburn 1856: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.10 raeburn 1857: }
1858: }
1859: }
1860: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1861: if ($env{'form.crosslist_'.$i}) {
1862: my $xlistinfo = '';
1863: if (ref($code_order) eq 'ARRAY') {
1864: if (@{$code_order} > 0) {
1865: foreach my $item (@{$code_order}) {
1866: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1867: }
1868: }
1869: }
1870: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 1871: $crosslistings{$i}{'inst'} = $xlistinfo;
1872: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 1873: }
1874: }
1.14 raeburn 1875: } else {
1876: $enrollstart = '';
1877: $enrollend = '';
1.10 raeburn 1878: }
1879: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1880: my $uname = $env{'form.person_'.$i.'_uname'};
1.16 raeburn 1881: my $udom = $env{'form.person_'.$i.'_dom'};
1.10 raeburn 1882: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
1883: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 1884: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
1885: $personnel{$uname.':'.$udom} = {
1886: firstname => $env{'form.person_'.$i.'_firstname'},
1887: lastname => $env{'form.person_'.$i.'_lastname'},
1888: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
1889: };
1890: }
1891: my $role = $env{'form.person_'.$i.'_role'};
1892: unless ($role eq '') {
1.16 raeburn 1893: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13 raeburn 1894: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
1895: unless (grep(/^\Q$role\E$/,@curr_roles)) {
1896: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
1897: }
1898: } else {
1899: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
1900: }
1901: if ($role eq 'cc') {
1902: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
1903: } else {
1.14 raeburn 1904: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1905: my $newsec = $env{'form.person_'.$i.'_newsec'};
1906: $newsec =~ s/^\s+//;
1907: $newsec =~s/\s+$//;
1908: my @newsecs = split(/[\s,;]+/,$newsec);
1909: foreach my $sec (@newsecs) {
1910: next if ($sec =~ /\W/);
1911: next if ($newsec eq 'none');
1912: if ($sec ne '') {
1913: unless (grep(/^\Q$sec\E$/,@currsec)) {
1914: push(@currsec,$sec);
1.13 raeburn 1915: }
1916: }
1917: }
1918: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @currsec;
1919: }
1920: }
1.10 raeburn 1921: } else {
1922: push(@missingdom,$uname.':'.$udom);
1923: }
1924: } else {
1925: push(@baduname,$uname.':'.$udom);
1926: }
1.8 raeburn 1927: }
1.13 raeburn 1928: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 1929: my $autodrops = 0;
1930: if ($env{'form.autodrops'}) {
1931: $autodrops = $env{'form.autodrops'};
1932: }
1933: my $autoadds = 0;
1934: if ($env{'form.autoadds'}) {
1935: $autodrops = $env{'form.autoadds'};
1936: }
1937: my $sectotal = 0;
1938: if ($env{'form.sectotal'}) {
1939: $sectotal = $env{'form.sectotal'};
1940: }
1941: if ($env{'form.autoadds'}) {
1942: $autodrops = $env{'form.autoadds'};
1943: }
1944: my $crosslisttotal = 0;
1945: if ($env{'form.crosslisttotal'}) {
1946: $crosslisttotal = $env{'form.crosslisttotal'};
1947: }
1948: my $instcode = '';
1949: if (exists($env{'form.instcode'})) {
1950: $instcode = $env{'form.instcode'};
1951: }
1.15 raeburn 1952: my $clonecrs = '';
1953: my $clonedom = '';
1954: if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
1955: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.16 raeburn 1956: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
1957: $env{'form.clonedom'});
1.15 raeburn 1958: if ($clonehome ne 'no_host') {
1.16 raeburn 1959: my $canclone =
1960: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1961: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
1.15 raeburn 1962: if ($canclone) {
1963: $clonecrs = $env{'form.clonecrs'};
1964: $clonedom = $env{'form.clonedom'};
1965: }
1966: }
1967: }
1.8 raeburn 1968: my $details = {
1.10 raeburn 1969: owner => $env{'user.name'},
1970: domain => $env{'user.domain'},
1971: cdom => $dom,
1.11 raeburn 1972: cnum => $cnum,
1.13 raeburn 1973: coursehome => $env{'form.chome'},
1974: cdescr => $env{'form.cdescr'},
1.10 raeburn 1975: crstype => $env{'form.crstype'},
1.14 raeburn 1976: instcode => $instcode,
1.15 raeburn 1977: clonedom => $clonedom,
1978: clonecrs => $clonecrs,
1.10 raeburn 1979: datemode => $env{'form.datemode'},
1.14 raeburn 1980: dateshift => $env{'form.dateshift'},
1981: sectotal => $sectotal,
1.10 raeburn 1982: sections => \%sections,
1.14 raeburn 1983: crosslisttotal => $crosslisttotal,
1.13 raeburn 1984: crosslists => \%crosslistings,
1.14 raeburn 1985: autoadds => $autoadds,
1986: autodrops => $autodrops,
1.13 raeburn 1987: enrollstart => $enrollstart,
1988: enrollend => $enrollend,
1989: accessstart => $accessstart,
1990: accessend => $accessend,
1.10 raeburn 1991: personnel => \%personnel,
1.8 raeburn 1992: };
1993: my @inststatuses;
1.9 raeburn 1994: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 1995: if ($val eq '') {
1996: if ($crstype eq 'official') {
1.19 ! raeburn 1997: $output = &mt('You are not permitted to request creation of official courses.');
1.8 raeburn 1998: } elsif ($crstype eq 'unofficial') {
1.19 ! raeburn 1999: $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8 raeburn 2000: } elsif ($crstype eq 'community') {
2001: $output = &mt('You are not permitted to request creation of communities');
2002: } else {
2003: $output = &mt('Unrecognized course type: [_1]',$crstype);
2004: }
2005: } else {
1.14 raeburn 2006: my ($disposition,$message,$reqstatus);
1.8 raeburn 2007: my %reqhash = (
1.14 raeburn 2008: reqtime => $now,
1.10 raeburn 2009: crstype => $crstype,
2010: details => $details,
1.8 raeburn 2011: );
2012: my $requestkey = $dom.'_'.$cnum;
1.17 raeburn 2013: my $validationerror;
1.10 raeburn 2014: if ($val eq 'autolimit=') {
2015: $disposition = 'process';
2016: } elsif ($val =~ /^autolimit=(\d+)$/) {
2017: my $limit = $1;
1.8 raeburn 2018: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 2019: $dom,$crstype,$limit,\$message);
1.8 raeburn 2020: } elsif ($val eq 'validate') {
1.17 raeburn 2021: my $inststatuslist;
2022: if (@inststatuses > 0) {
2023: $inststatuslist = join(',',@inststatuses);
2024: }
2025: my $instseclist;
2026: if (@instsections > 0) {
2027: $instseclist = join(',',@instsections);
2028: }
2029: my $validation =
2030: &Apache::lonnet::auto_validate_instcode('',$dom,$instcode,
2031: $env{'user.name'}.':'.$env{'user.domain'},$inststatuslist,
2032: $instseclist);
2033: if ($validation eq 'valid') {
2034: $disposition = 'process';
2035: } elsif ($validation eq 'rejected') {
2036: $disposition = 'rejected';
2037: } elsif ($validation eq 'pending') {
2038: $disposition = 'pending';
2039: } elsif ($disposition eq 'approval') {
2040: $disposition = 'approval';
2041: } elsif ($disposition =~ /^error(.*)$/) {
2042: $disposition = 'approval';
2043: $validationerror = $1;
2044: } else {
2045: $disposition = 'approval';
2046: }
1.8 raeburn 2047: } else {
2048: $disposition = 'approval';
2049: }
1.14 raeburn 2050: $reqhash{'disposition'} = $disposition;
2051: $reqstatus = $disposition;
1.16 raeburn 2052: my ($modified,$queued);
1.8 raeburn 2053: if ($disposition eq 'rejected') {
2054: $output = &mt('Your course request was rejected.');
2055: if ($message) {
2056: $output .= '<div class="LC_warning">'.$message.'</div>';
2057: }
2058: } elsif ($disposition eq 'process') {
1.14 raeburn 2059: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
2060: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
2061: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 2062: my $type = 'Course';
2063: if ($crstype eq 'community') {
2064: $type = 'Community';
2065: }
2066: foreach my $role (@roles) {
2067: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
2068: }
1.14 raeburn 2069: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
2070: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
2071: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
2072: if ($result eq 'created') {
1.8 raeburn 2073: $disposition = 'created';
1.14 raeburn 2074: $reqstatus = 'created';
2075: $output = &mt('Your course request has been processed and the course has been created.').
2076: '<br />'.
2077: &mt('You will need to logout and log-in again to be able to select a role in the course.');
1.8 raeburn 2078: } else {
1.14 raeburn 2079: $output = '<span class="LC_error">'.
2080: &mt('An error occurred when processing your course request.').
2081: '<br />'.
2082: &mt('You may want to review the request details and submit the request again.').
2083: '</span>';
1.8 raeburn 2084: }
2085: } else {
2086: my $requestid = $cnum.'_'.$disposition;
2087: my $request = {
2088: $requestid => {
2089: timestamp => $now,
2090: crstype => $crstype,
2091: ownername => $env{'user.name'},
2092: ownerdom => $env{'user.domain'},
1.13 raeburn 2093: description => $env{'form.cdescr'},
1.8 raeburn 2094: },
2095: };
1.16 raeburn 2096: my $statuskey = 'status:'.$dom.':'.$cnum;
2097: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
2098: $env{'user.domain'},$env{'user.name'});
1.17 raeburn 2099: if ($userreqhash{$statuskey} ne '') {
1.16 raeburn 2100: $modified = 1;
2101: my %queuehash = &Apache::lonnet::get_dom('courserequestqueue',
2102: [$cnum.'_approval',
2103: $cnum.'_pending'],$dom);
1.17 raeburn 2104: if (($queuehash{$cnum.'_approval'} ne '') ||
2105: ($queuehash{$cnum.'_pending'} ne '')) {
1.16 raeburn 2106: $queued = 1;
2107: }
2108: }
2109: unless ($queued) {
2110: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
2111: $dom);
2112: if ($putresult eq 'ok') {
2113: $output = &mt('Your course request has been recorded.').'<br />'.
2114: ¬ification_information($disposition,$req_notifylist,
2115: $cnum,$now);
1.8 raeburn 2116: } else {
1.16 raeburn 2117: $reqstatus = 'domainerror';
2118: $reqhash{'disposition'} = $disposition;
2119: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
2120: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8 raeburn 2121: }
2122: }
2123: }
1.14 raeburn 2124: my ($storeresult,$statusresult);
1.10 raeburn 2125: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2126: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
2127: 'courserequests');
1.14 raeburn 2128: if ($storeresult eq 'ok') {
2129: my %status = (
2130: 'status:'.$dom.':'.$cnum => $reqstatus,
2131: );
2132: $statusresult = &Apache::lonnet::put('courserequests',\%status);
2133: }
1.10 raeburn 2134: } else {
2135: $storeresult = 'error: invalid requestkey format';
2136: }
1.8 raeburn 2137: if ($storeresult ne 'ok') {
1.13 raeburn 2138: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
2139: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1.14 raeburn 2140: } elsif ($statusresult ne 'ok') {
2141: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
2142: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
1.8 raeburn 2143: }
1.16 raeburn 2144: if ($modified && $queued && $storeresult eq 'ok') {
2145: $output .= '<p>'.&mt('Your course request has been updated').'</p>'.
2146: ¬ification_information($disposition,$req_notifylist,$cnum,$now);
2147: }
1.17 raeburn 2148: if ($validationerror ne '') {
1.19 ! raeburn 2149: $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
1.17 raeburn 2150: }
1.16 raeburn 2151: }
2152: return $output;
2153: }
2154:
2155: sub notification_information {
2156: my ($disposition,$req_notifylist,$cnum,$now) = @_;
2157: my %emails = &Apache::loncommon::getemails();
2158: my $address;
2159: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
2160: $address = $emails{'permanentemail'};
2161: if ($address eq '') {
2162: $address = $emails{'notification'};
2163: }
2164: }
2165: my $output;
2166: if ($disposition eq 'approval') {
2167: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
2168: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
2169: if ($address ne '') {
2170: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
2171: }
2172: if ($req_notifylist) {
2173: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
2174: $env{'user.domain'});
2175: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
2176: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
2177: }
1.17 raeburn 2178: } elsif ($disposition eq 'pending') {
1.16 raeburn 2179: $output .= '<div class="LC_info">'.
2180: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
2181: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
2182: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
2183: '</div>';
1.17 raeburn 2184: } else {
2185: $output .= '<div class="LC_warning">'.
2186: &mt('Your request status is: [_1].',$disposition).
2187: '</div>'
1.8 raeburn 2188: }
2189: return $output;
2190: }
2191:
2192: sub get_processtype {
1.9 raeburn 2193: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
2194: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1.8 raeburn 2195: my (%userenv,%settings,$val);
1.19 ! raeburn 2196: my @options = ('autolimit','validate','approval');
1.8 raeburn 2197: if ($dom eq $env{'user.domain'}) {
2198: %userenv =
2199: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
2200: 'requestcourses.'.$crstype,'inststatus');
2201: if ($userenv{'requestcourses.'.$crstype}) {
2202: $val = $userenv{'requestcourses.'.$crstype};
2203: @{$inststatuses} = ('_custom_');
2204: } else {
2205: my ($task,%alltasks);
1.9 raeburn 2206: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
2207: %settings = %{$domconfig->{'requestcourses'}};
1.8 raeburn 2208: if (ref($settings{$crstype}) eq 'HASH') {
2209: if (($env{'user.adv'}) && (exists($settings{$crstype}{'_LC_adv'}))) {
2210: $val = $settings{$crstype}{'_LC_adv'};
2211: @{$inststatuses} = ('_LC_adv_');
2212: } else {
2213: if ($userenv{'inststatus'} ne '') {
2214: @{$inststatuses} = split(',',$userenv{'inststatus'});
2215: } else {
1.13 raeburn 2216: @{$inststatuses} = ('default');
1.8 raeburn 2217: }
2218: foreach my $status (@{$inststatuses}) {
2219: if (exists($settings{$crstype}{$status})) {
2220: my $value = $settings{$crstype}{$status};
2221: next unless ($value);
2222: unless (exists($alltasks{$value})) {
2223: if (ref($alltasks{$value}) eq 'ARRAY') {
2224: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
2225: push(@{$alltasks{$value}},$status);
2226: }
2227: } else {
2228: @{$alltasks{$value}} = ($status);
2229: }
2230: }
2231: }
2232: }
2233: my $maxlimit = 0;
1.13 raeburn 2234:
1.8 raeburn 2235: foreach my $key (sort(keys(%alltasks))) {
2236: if ($key =~ /^autolimit=(\d*)$/) {
2237: if ($1 eq '') {
2238: $val ='autolimit=';
2239: last;
2240: } elsif ($1 > $maxlimit) {
2241: $maxlimit = $1;
2242: }
2243: }
2244: }
2245: if ($maxlimit) {
2246: $val = 'autolimit='.$maxlimit;
2247: } else {
2248: foreach my $option (@options) {
2249: if ($alltasks{$option}) {
2250: $val = $option;
2251: last;
2252: }
2253: }
2254: }
2255: }
2256: }
2257: }
2258: }
2259: } else {
2260: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
2261: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1.19 ! raeburn 2262: if ($userenv{'reqcrsotherdom.'.$crstype}) {
! 2263: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
! 2264: my $optregex = join('|',@options);
! 2265: foreach my $item (@doms) {
! 2266: my ($extdom,$extopt) = split(':',$item);
! 2267: if ($extdom eq $dom) {
! 2268: if ($extopt =~ /^($optregex)(=?\d*)$/) {
! 2269: $val = $1.$2;
! 2270: }
! 2271: last;
! 2272: }
1.8 raeburn 2273: }
2274: @{$inststatuses} = ('_external_');
2275: }
2276: }
2277: return $val;
2278: }
2279:
2280: sub check_autolimit {
1.10 raeburn 2281: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
2282: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
2283: 'userroles',['active','future'],['cc'],[$dom]);
2284: my ($types,$typename) = &course_types();
2285: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
2286: my %count;
2287: if (ref($types) eq 'ARRAY') {
2288: foreach my $type (@{$types}) {
2289: $count{$type} = 0;
2290: }
2291: }
2292: foreach my $key (keys(%requests)) {
2293: my ($cdom,$cnum) = split('_',$key);
2294: if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
2295: if (ref($requests{$key}) eq 'HASH') {
2296: my $type = $requests{$key}{'crstype'};
2297: if ($type =~ /^official|unofficial|community$/) {
2298: $count{$type} ++;
2299: }
2300: }
2301: }
2302: }
2303: if ($count{$crstype} < $limit) {
2304: return 'process';
2305: } else {
2306: if (ref($typename) eq 'HASH') {
2307: $$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);
2308: }
2309: return 'rejected';
2310: }
1.1 raeburn 2311: return;
2312: }
2313:
1.2 raeburn 2314: sub retrieve_settings {
1.16 raeburn 2315: my ($dom,$cnum) = @_;
2316: my ($result,%reqinfo) = &get_request_settings($dom,$cnum);
2317: if ($result eq 'ok') {
2318: if (($env{'user.name'} eq $reqinfo{'owner'}) &&
2319: ($env{'user.domain'} eq $reqinfo{'domain'})) {
2320: $env{'form.chome'} = $reqinfo{'coursehome'};
2321: $env{'form.cdescr'} = $reqinfo{'cdescr'};
2322: $env{'form.crstype'} = $reqinfo{'crstype'};
2323: &generate_date_items($reqinfo{'accessstart'},'accessstart');
2324: &generate_date_items($reqinfo{'accessend'},'accessend');
2325: if ($reqinfo{'accessend'} == 0) {
2326: $env{'form.no_end_date'} = 1;
2327: }
2328: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
2329: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
2330: &generate_date_items($reqinfo{'enrollend'},'enrollend');
2331: }
2332: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
2333: $env{'form.clonedom'} = $reqinfo{'clonedom'};
2334: $env{'form.datemode'} = $reqinfo{'datemode'};
2335: $env{'form.dateshift'} = $reqinfo{'dateshift'};
2336: if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
2337: $env{'form.sectotal'} = $reqinfo{'sectotal'};
2338: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
2339: $env{'form.autoadds'} = $reqinfo{'autoadds'};
2340: $env{'form.autdrops'} = $reqinfo{'autodrops'};
2341: $env{'form.instcode'} = $reqinfo{'instcode'};
2342: my %crscode = (
2343: instcode => $reqinfo{'instcode'},
2344: );
2345: &extract_instcode($dom,'instcode',\%crscode);
2346: }
2347: my @currsec;
2348: if (ref($reqinfo{'sections'}) eq 'HASH') {
2349: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
2350: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
2351: my $sec = $reqinfo{'sections'}{$i}{'inst'};;
2352: $env{'form.secnum_'.$i} = $sec;
2353: if (!grep(/^\Q$sec\E$/,@currsec)) {
2354: push(@currsec,$sec);
2355: }
2356: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
2357: }
2358: }
2359: }
2360: if (ref($reqinfo{'crosslistings'}) eq 'HASH') {
2361: foreach my $i (sort(keys(%{$reqinfo{'crosslistings'}}))) {
2362: if (ref($reqinfo{'crosslistings'}{$i}) eq 'HASH') {
2363: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslistings'}{$i}{'loncapa'};
2364: my $xlistsec = $reqinfo{'crosslistings'}{$i}{'instsec'};
2365: my %crscode = (
2366: $i => $reqinfo{'crosslistings'}{$i}{'instcode'},
2367: );
2368: &extract_instcode($dom,'crosslist',\%crscode,$1,$xlistsec);
2369: }
2370: }
2371: }
2372: if (ref($reqinfo{'personnel'}) eq 'HASH') {
2373: my $i = 0;
2374: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
2375: my ($uname,$udom) = split(':',$user);
2376: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
2377: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
2378: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
2379: $env{'form.person_'.$i.'_role'} = $role;
2380: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
2381: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
2382: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
2383: $env{'form.person_'.$i.'_uname'} = $uname;
2384: $env{'form.person_'.$i.'_dom'} = $udom;
2385: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
2386: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
2387: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
2388: my @newsecs;
2389: if (@usecs > 0) {
2390: foreach my $sec (@usecs) {
2391: if (grep(/^\Q$sec\E/,@currsec)) {
2392: $env{'form.person_'.$i.'_sec'} = $sec;
2393: } else {
2394: push (@newsecs,$sec);
2395: }
2396: }
2397: }
2398: if (@newsecs > 0) {
2399: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
2400: }
2401: }
2402: }
2403: $i ++;
2404: }
2405: }
2406: }
2407: }
2408: $env{'form.persontotal'} = $i;
2409: }
2410: }
2411: }
2412: return $result;
2413: }
2414:
2415: sub get_request_settings {
2416: my ($dom,$cnum) = @_;
2417: my $requestkey = $dom.'_'.$cnum;
2418: my ($result,%reqinfo);
2419: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2420: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2421: $env{'user.domain'},$env{'user.name'});
2422: my $disposition = $history{'disposition'};
2423: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
2424: if (ref($history{'details'}) eq 'HASH') {
2425: %reqinfo = %{$history{'details'}};
2426: $result = 'ok';
2427: } else {
2428: $result = 'nothash';
2429: }
2430: } else {
2431: $result = 'notqueued';
2432: }
2433: } else {
2434: $result = 'invalid';
2435: }
2436: return ($result,%reqinfo);
2437: }
1.2 raeburn 2438:
1.16 raeburn 2439: sub extract_instcode {
2440: my ($cdom,$element,$crscodehashref,$counter,$xlistsec) = @_;
2441: my (%codes,@codetitles,%cat_titles,%cat_order);
2442: if (ref($crscodehashref) eq 'HASH') {
2443: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscodehashref,
2444: \%codes,\@codetitles,\%cat_titles,\%cat_order) eq 'ok') {
2445: if (@codetitles > 0) {
2446: my $sel = $element;
2447: if ($element eq 'crosslist') {
2448: $sel .= '_'.$counter;
2449: }
2450: my $lastitem = pop(@codetitles);
2451: foreach my $title (@codetitles) {
2452: if (ref($cat_order{$title}) eq 'ARRAY') {
2453: if (@{$cat_order{$title}} > 0) {
2454: $env{'form.'.$sel.'_'.$title} = $cat_order{$title}[0];
2455: }
2456: }
2457: }
2458: if ($element eq 'crosslist') {
2459: $env{'form.'.$sel.'_'.$lastitem} = $xlistsec;
2460: }
2461: }
2462: }
2463: }
2464: return;
1.2 raeburn 2465: }
2466:
1.16 raeburn 2467: sub generate_date_items {
2468: my ($currentval,$item) = @_;
2469: if ($currentval =~ /\d+/) {
2470: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
2471: &Apache::lonhtmlcommon::get_timedates($currentval);
2472: $env{'form.'.$item.'_day'} = $mday;
2473: $env{'form.'.$item.'_month'} = $month+1;
2474: $env{'form.'.$item.'_year'} = $year;
2475: }
2476: return;
1.2 raeburn 2477: }
2478:
1.1 raeburn 2479: 1;
2480:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>