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