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