File:
[LON-CAPA] /
loncom /
interface /
lonrequestcourse.pm
Revision
1.8:
download - view:
text,
annotated -
select for diffs
Tue Aug 11 01:39:34 2009 UTC (15 years ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Course Requests
lonrequestcourse.pm
- &print_review() which displays details of a course request prior to submissi
on now includes a call to &Apache::lonnet::generate_coursenum() to retrieve a un
ique course number to be used for the requested course.
- &print_request_outcome() determines how a request should be processed, based on course type, and domain setting for requestor's instiutional affiliations(s), (overridden by user-specific settings), and performs the required actions.
- &get_processtype() retrieves the setting: norequest, approval, validate, or autolimit=N (N is requests per user).
- &check_autolimit() will check if requests per user limit reached.
- Call to &Apache::lonnet::auto_courserequest_validation() to perform institutional check - response is either process or pending.
- $disposition indicates how request should be handled
- approval, rejected, process, or pending.
- case: approval and pending - place in a queue (domain's courserequestqueue.db); approval means DC needs to approve; pending means institutional change ne
eded (e.g., assign owner as instructor of record)
- case: process - create the course using &build_course() in batchcreatecourse.pm
- case: rejected - course request not allowed
lonnet.pm
- &store_coursereq() is used to store (versioned) course requests in a courserequests.db file which belongs to the requestor. The unique key is the course number assigned to the (yet to be created) course.
Work in progress.
1: # The LearningOnline Network
2: # Request a course
3: #
4: # $Id: lonrequestcourse.pm,v 1.8 2009/08/11 01:39:34 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: =back
48:
49: =cut
50:
51: package Apache::lonrequestcourse;
52:
53: use strict;
54: use Apache::Constants qw(:common :http);
55: use Apache::lonnet;
56: use Apache::loncommon;
57: use Apache::lonlocal;
58: use Apache::loncoursequeueadmin;
59: use LONCAPA qw(:DEFAULT :match);
60:
61: sub handler {
62: my ($r) = @_;
63: if ($r->header_only) {
64: &Apache::loncommon::content_type($r,'text/html');
65: $r->send_http_header;
66: return OK;
67: }
68: &Apache::loncommon::content_type($r,'text/html');
69: $r->send_http_header;
70:
71: &Apache::lonhtmlcommon::clear_breadcrumbs();
72: my $dom = &get_course_dom();
73: my $action = $env{'form.action'};
74: my $state = $env{'form.state'};
75:
76: my %stored;
77: my $jscript;
78: if ((defined($state)) && (defined($action))) {
79: my %elements = &form_elements($dom);
80: if (($action eq 'view') && ($state ne 'crstype')) {
81: if (defined($env{'form.request_id'})) {
82: %stored = &retrieve_settings($dom,$env{'form.request_id'});
83: }
84: }
85: my $elementsref = {};
86: if (ref($elements{$action}) eq 'HASH') {
87: if (ref($elements{$action}{$state}) eq 'HASH') {
88: $elementsref = $elements{$action}{$state};
89: }
90: }
91: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
92: }
93:
94: if ($state eq 'personnel') {
95: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
96: }
97:
98: my $loaditems = &onload_action($action,$state);
99:
100: my %states;
101: $states{'view'} = ['pick_request','details','review','process'];
102: $states{'log'} = ['filter','display'];
103: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
104: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
105: unless ($env{'form.state'} eq 'crstype') {
106: unshift (@{$states{'new'}},'codepick');
107: }
108: }
109:
110: foreach my $key (keys(%states)) {
111: if (ref($states{$key}) eq 'ARRAY') {
112: unshift (@{$states{$key}},'crstype');
113: }
114: }
115:
116: my %trail = (
117: crstype => 'Course Request Action',
118: codepick => 'Category',
119: courseinfo => 'Description',
120: enrollment => 'Enrollment',
121: personnel => 'Personnel',
122: review => 'Review',
123: process => 'Result',
124: );
125:
126: my $page = 0;
127: my $crumb;
128: if (defined($action)) {
129: my $done = 0;
130: my $i=0;
131: if (ref($states{$action}) eq 'ARRAY') {
132: while ($i<@{$states{$action}} && !$done) {
133: if ($states{$action}[$i] eq $state) {
134: $page = $i;
135: $done = 1;
136: }
137: $i++;
138: }
139: }
140: for (my $i=0; $i<@{$states{$action}}; $i++) {
141: if ($state eq $states{$action}[$i]) {
142: &Apache::lonhtmlcommon::add_breadcrumb(
143: {text=>"$trail{$state}"});
144: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
145: last;
146: } else {
147: if (($state eq 'process') && ($i > 0)) {
148: &Apache::lonhtmlcommon::add_breadcrumb(
149: {href=>"javascript:backPage(document.requestcrs,'$states{$action}[0]')",
150: text=>"$trail{$states{$action}[$i]}"});
151: } else {
152: &Apache::lonhtmlcommon::add_breadcrumb(
153: {href=>"javascript:backPage(document.requestcrs,'$states{$action}[$i]')",
154: text=>"$trail{$states{$action}[$i]}"});
155: }
156: }
157: }
158: } else {
159: &Apache::lonhtmlcommon::add_breadcrumb(
160: {text=>'Pick Action'});
161: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
162: }
163:
164: my %can_request;
165: my $canreq = &check_can_request($dom,\%can_request);
166: if ($action eq 'new') {
167: if ($canreq) {
168: if ($state eq 'crstype') {
169: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
170: $crumb);
171: } else {
172: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
173: $loaditems,$crumb);
174: }
175: } else {
176: $r->print(&header('Course Requests').$crumb.
177: '<div class="LC_warning">'.
178: &mt('You do not have privileges to request creation of courses.').
179: '</div>'.&Apache::loncommon::end_page());
180: }
181: } elsif ($action eq 'view') {
182: &print_request_status($jscript,$loaditems,$crumb);
183: } elsif ($action eq 'log') {
184: &print_request_logs($jscript,$loaditems,$crumb);
185: } else {
186: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
187: }
188: return OK;
189: }
190:
191: sub header {
192: my ($bodytitle,$jscript,$loaditems,$jsextra) = @_;
193: if ($jscript) {
194: $jscript = '<script type="text/javascript">'."\n".
195: '// <![CDATA['."\n".
196: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
197: }
198: if ($loaditems) {
199: $loaditems = {'add_entries' => $loaditems,};
200: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$loaditems);
201: } else {
202: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra);
203: }
204: }
205:
206: sub form_elements {
207: my ($dom) = @_;
208: my %elements =
209: (
210: new => {
211: crstype => {
212: crstype => 'selectbox',
213: action => 'selectbox',
214: },
215: courseinfo => {
216: cdescr => 'text',
217: clonecourse => 'text',
218: clonedomain => 'selectbox',
219: datemode => 'radio',
220: dateshift => 'text',
221: },
222: enrollment => {
223: startaccess_month => 'selectbox',
224: startaccess_hour => 'selectbox',
225: endaccess_month => 'selectbox',
226: endaccess_hour => 'selectbox',
227: startaccess_day => 'text',
228: startaccess_year => 'text',
229: startaccess_minute => 'text',
230: startaccess_second => 'text',
231: endaccess_day => 'text',
232: endaccess_year => 'text',
233: endaccess_minute => 'text',
234: endaccess_second => 'text',
235: no_end_date => 'checkbox',
236: },
237: personnel => {
238: persontotal => 'hidden',
239: addperson => 'checkbox',
240: },
241: },
242: view => {
243: crstype => {
244: crstype => 'selectbox',
245: action => 'selectbox',
246: },
247: },
248: );
249: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
250: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
251: \%cat_order,\@code_order);
252: my $numtitles = scalar(@codetitles);
253: if ($numtitles) {
254: my %extras;
255: $lastitem = pop(@codetitles);
256: $extras{'instcode_'.$lastitem} = 'text';
257: foreach my $item (@codetitles) {
258: $extras{'instcode_'.$item} = 'selectbox';
259: }
260: $elements{'new'}{'codepick'} = \%extras;
261: }
262: if (&Apache::lonnet::auto_run('',$dom)) {
263: my %extras = (
264: sectotal => 'hidden',
265: startenroll_month => 'selectbox',
266: startenroll_hour => 'selectbox',
267: endenroll_month => 'selectbox',
268: endenroll_hour => 'selectbox',
269: startenroll_day => 'text',
270: startenroll_year => 'text',
271: startenroll_minute => 'text',
272: startenroll_second => 'text',
273: endenroll_day => 'text',
274: endenroll_year => 'text',
275: endenroll_minute => 'text',
276: endenroll_second => 'text',
277: crosslisttotal => 'hidden',
278: addcrosslist => 'checkbox',
279: autoadds => 'radio',
280: autodrops => 'radio',
281: );
282: if ($env{'form.sectotal'} > 0) {
283: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
284: $extras{'sec_'.$i} = 'checkbox',
285: $extras{'secnum_'.$i} = 'text',
286: $extras{'loncapasec_'.$i} = 'checkbox',
287: }
288: }
289: my $crosslisttotal = $env{'form.crosslisttotal'};
290: if (!defined($crosslisttotal)) {
291: $crosslisttotal = 1;
292: }
293: if ($crosslisttotal > 0) {
294: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
295: if ($numtitles) {
296: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
297: }
298: if (@codetitles > 0) {
299: foreach my $item (@codetitles) {
300: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
301: }
302: }
303: $extras{'crosslist_'.$i} = 'checkbox';
304: $extras{'crosslist_'.$i.'_instsec'} = 'text',
305: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
306: }
307: }
308: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
309: %{$elements{'new'}{'enrollment'}} = %mergedhash;
310: }
311: my %people;
312: my $persontotal = $env{'form.persontotal'};
313: if (!defined($persontotal)) {
314: $persontotal = 1;
315: }
316: for (my $i=0; $i<$persontotal; $i++) {
317: $people{'person_'.$i.'_uname'} = 'text',
318: $people{'person_'.$i.'_dom'} = 'selectbox',
319: $people{'person_'.$i.'_hidedom'} = 'hidden',
320: $people{'person_'.$i.'_first'} = 'text',
321: $people{'person_'.$i.'_last'} = 'text',
322: $people{'person_'.$i.'_email'} = 'text',
323: $people{'person_'.$i.'_role'} = 'selectbox',
324: $people{'person_'.$i.'_sec'} = 'selectbox',
325: $people{'person_'.$i.'_newsec'} = 'text',
326: $people{'person_'.$i.'_sections'} = 'hidden',
327: }
328: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
329: %{$elements{'new'}{'personnel'}} = %personnelhash;
330: return %elements;
331: }
332:
333: sub onload_action {
334: my ($action,$state) = @_;
335: my %loaditems;
336: if (($action eq 'new') || ($action eq 'view')) {
337: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)';
338: }
339: return \%loaditems;
340: }
341:
342: sub check_can_request {
343: my ($dom,$can_request) = @_;
344: my $canreq = 0;
345: my ($types,$typename) = &course_types();
346: if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) {
347: foreach my $type (@{$types}) {
348: if (&Apache::lonnet::usertools_access($env{'user.name'},
349: $env{'user.domain'},
350: $type,undef,'requestcourses')) {
351: $canreq ++;
352: if ($dom eq $env{'user.domain'}) {
353: $can_request->{$type} = 1;
354: }
355: }
356: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
357: my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type});
358: if (@curr > 0) {
359: $canreq ++;
360: unless ($dom eq $env{'user.domain'}) {
361: if (grep(/^\Q$dom\E$/,@curr)) {
362: $can_request->{$type} = 1;
363: }
364: }
365: }
366: }
367: }
368: }
369: return $canreq;
370: }
371:
372: sub course_types {
373: my @types = ('official','unofficial','community');
374: my %typename = (
375: official => 'Official course',
376: unofficial => 'Unofficial course',
377: community => 'Community',
378: );
379: return (\@types,\%typename);
380: }
381:
382:
383: sub print_main_menu {
384: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_;
385: my ($types,$typename) = &course_types();
386: my $onchange;
387: unless ($env{'form.interface'} eq 'textual') {
388: $onchange = 1;
389: }
390:
391: my $nextstate_setter = "\n";
392: if (ref($states) eq 'HASH') {
393: foreach my $key (keys(%{$states})) {
394: if (ref($states->{$key}) eq 'ARRAY') {
395: $nextstate_setter .=
396: " if (actionchoice == '$key') {
397: nextstate = '".$states->{$key}[1]."';
398: }
399: ";
400: }
401: }
402: }
403:
404: my $js = <<"END";
405:
406: function nextPage(formname) {
407: var crschoice = document.requestcrs.crstype.value;
408: var actionchoice = document.requestcrs.action.value;
409: if (check_can_request(crschoice,actionchoice) == true) {
410: if ((actionchoice == 'new') && (crschoice == 'official')) {
411: nextstate = 'codepick';
412: } else {
413: $nextstate_setter
414: }
415: formname.state.value= nextstate;
416: formname.submit();
417: }
418: return;
419: }
420:
421: function check_can_request(crschoice,actionchoice) {
422: var official = '';
423: var unofficial = '';
424: var community = '';
425: END
426:
427: foreach my $item (keys(%{$can_request})) {
428: $js .= "
429: $item = 1;
430: ";
431: }
432: my %lt = &Apache::lonlocal::texthash(
433: official => 'You are not permitted to request creation of an official course in this domain.',
434: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
435: community => 'You are not permitted to request creation of a community this domain.',
436: all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
437: );
438: $js .= <<END;
439: if (crschoice == 'official') {
440: if (official != 1) {
441: alert("$lt{'official'}");
442: return false;
443: }
444: } else {
445: if (crschoice == 'unofficial') {
446: if (unofficial != 1) {
447: alert("$lt{'unofficial'}");
448: return false;
449: }
450: } else {
451: if (crschoice == 'community') {
452: if (community != 1) {
453: alert("$lt{'community'}");
454: return false;
455: }
456: } else {
457: if (actionchoice == 'new') {
458: alert("$lt{'all'}");
459: return false;
460: }
461: }
462: }
463: }
464: return true;
465: }
466:
467: END
468:
469: $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.
470: '<div>'.
471: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
472: &Apache::lonhtmlcommon::start_pick_box().
473: &Apache::lonhtmlcommon::row_title('Course Domain').
474: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange));
475: if (!$onchange) {
476: $r->print(' <input type="submit" name="godom" value="'.
477: &mt('Change').'" />');
478: }
479: $r->print(&Apache::lonhtmlcommon::row_closure(1).
480: &Apache::lonhtmlcommon::end_pick_box().'</form></div>');
481:
482: my $formname = 'requestcrs';
483: my $nexttext = &mt('Next');
484: $r->print('<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'.
485: &Apache::lonhtmlcommon::start_pick_box().
486: &Apache::lonhtmlcommon::row_title('Action').'
487: <input type="hidden" name="showdom" value="'.$dom.'" />
488: <select size="1" name="action" >
489: <option value="new">'.&mt('New request').'</option>
490: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
491: <option value="log">'.&mt('View request history').'</option>
492: </select>'.
493: &Apache::lonhtmlcommon::row_closure().
494: &Apache::lonhtmlcommon::row_title('Course Type').'
495: <select size="1" name="crstype">
496: <option value="any">'.&mt('All types').'</option>');
497: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
498: foreach my $type (@{$types}) {
499: my $selected = '';
500: if ($type eq 'official') {
501: $selected = ' selected="selected"';
502: }
503: $r->print('<option value="'.$type.'"'.$selected.'>'.$typename->{$type}.
504: '</option>'."\n");
505: }
506: }
507: $r->print('</select>
508: <input type="hidden" name="state" value="crstype" />'.
509: &Apache::lonhtmlcommon::row_closure(1).
510: &Apache::lonhtmlcommon::end_pick_box().'<br />
511: <input type="button" name="next" value="'.$nexttext.'" onclick="javascript:nextPage(document.'.$formname.')" />
512: </form></div>');
513: $r->print(&Apache::loncommon::end_page());
514: return;
515: }
516:
517: sub request_administration {
518: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb) = @_;
519: my $js;
520: if (($action eq 'new') || ($action eq 'view')) {
521: $js = <<END;
522:
523: function nextPage(formname,nextstate) {
524: formname.state.value= nextstate;
525: formname.submit();
526: }
527: function backPage(formname,prevstate) {
528: formname.state.value = prevstate;
529: formname.submit();
530: }
531:
532: END
533: }
534: if ($action eq 'new') {
535: my $jsextra;
536: unless (($state eq 'review') || ($state eq 'process')) {
537: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
538: }
539: $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb);
540: &print_request_form($r,$action,$state,$page,$states,$dom);
541: } elsif ($action eq 'view') {
542: $r->print(&header('Manage course requests',$js.$jscript,$loaditems).$crumb);
543: } elsif ($action eq 'log') {
544: $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
545: }
546: $r->print(&Apache::loncommon::end_page());
547: return;
548: }
549:
550: sub print_request_form {
551: my ($r,$action,$state,$page,$states,$dom) = @_;
552: my $formname = 'requestcrs';
553: my ($next,$prev,$message,$output,$codepicker,$crstype);
554: $prev = $states->{$action}[$page-1];
555: $next = $states->{$action}[$page+1];
556: my %navtxt = &Apache::lonlocal::texthash (
557: prev => 'Previous',
558: next => 'Next',
559: );
560: $crstype = $env{'form.crstype'};
561: $r->print('<form name="'.$formname.'" method="post" action="/adm/requestcourse">');
562: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
563: if ($crstype eq 'official') {
564: if ($env{'form.instcode'} ne '') {
565: $instcode = $env{'form.instcode'};
566: }
567: }
568: if ($prev eq 'codepick') {
569: if ($crstype eq 'official') {
570: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
571: \%cat_order,\@code_order);
572: }
573: if (@code_order > 0) {
574: my $message;
575: if ($instcode eq '') {
576: foreach my $item (@code_order) {
577: $instcode .= $env{'form.instcode_'.$item};
578: }
579: $r->print('<input type="hidden" name="instcode" value="'.$instcode.'" />'."\n");
580: }
581: if ($instcode ne '') {
582: $code_chk = &Apache::lonnet::auto_validate_instcode('',$dom,$instcode);
583: if ($code_chk eq 'ok') {
584: $message = '<div class="LC_info">'.
585: &mt('The chosen course category [_1] is valid.','<b>'.
586: $instcode.'</b>').'</div>';
587: } else {
588: $message = '<div class="LC_warning">'.
589: &mt('No course was found matching your choice of institutional course category.');
590: if ($code_chk ne '') {
591: $message .= '<br />'.$code_chk;
592: }
593: $message .= '</div>';
594: }
595: } else {
596: $message = '<div class="LC_warning">'.
597: &mt('No course was found matching your choice of institutional course category.');
598: }
599: unless ($code_chk eq 'ok') {
600: $prev = 'crstype';
601: }
602: $r->print($message);
603: }
604: }
605: if ($prev eq 'crstype') {
606: if ($crstype eq 'official') {
607: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
608: \%cat_order,\@code_order);
609: }
610: if (@code_order > 0) {
611: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
612: \%cat_titles,\%cat_order);
613: if ($codepicker) {
614: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box().$codepicker.
615: &Apache::lonhtmlcommon::end_pick_box().'</div>');
616: } else {
617: $r->print(&courseinfo_form($dom,$formname,$crstype));
618: }
619: } else {
620: $r->print(&courseinfo_form($dom,$formname,$crstype));
621: }
622: } elsif ($prev eq 'codepick') {
623: $r->print(&courseinfo_form($dom,$formname,$crstype));
624: } elsif ($state eq 'enrollment') {
625: if ($crstype eq 'official') {
626: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
627: \%cat_order,\@code_order);
628: }
629: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
630: \%cat_titles,\%cat_order,\@code_order));
631: } elsif ($state eq 'personnel') {
632: $r->print(&print_personnel_menu($dom,$formname,$crstype));
633: } elsif ($state eq 'review') {
634: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
635: \%cat_order,\@code_order);
636: $r->print(&print_review($formname,$dom,\@codetitles,\%cat_titles,\%cat_order,
637: \@code_order));
638: $navtxt{'next'} = &mt('Submit course request');
639: } elsif ($state eq '') {
640: my $result = &print_request_outcome($dom);
641: }
642: my @excluded = ('counter');
643: my %elements = &form_elements($dom);
644: if (ref($states) eq 'HASH') {
645: if (ref($states->{$action}) eq 'ARRAY') {
646: my @items = @{$states->{$action}};
647: my $numitems = scalar(@items);
648: if ($numitems) {
649: for (my $i=$numitems-1; $i>=0; $i--) {
650: if (ref($elements{$action}) eq 'HASH') {
651: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
652: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
653: push(@excluded,$key);
654: }
655: }
656: }
657: last if ($items[$i] eq $state);
658: }
659: }
660: }
661: }
662: if (grep(/^instcode_/,@excluded)) {
663: push(@excluded,'instcode');
664: }
665: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
666: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'});
667: return;
668: }
669:
670: sub print_enrollment_menu {
671: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order) =@_;
672: my ($sections,$autoenroll,$access_dates);
673: my $starttime = time;
674: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
675:
676: my %accesstitles = (
677: 'start' => 'Default start access',
678: 'end' => 'Default end accss',
679: );
680: my %enrolltitles = (
681: 'start' => 'Start auto-enrollment',
682: 'end' => 'End auto-enrollment',
683: );
684: if ($env{'form.crstype'} eq 'official') {
685: if (&Apache::lonnet::auto_run('',$dom)) {
686: my ($section_form,$crosslist_form,$autoenroll_form);
687: $section_form = &inst_section_selector($dom,$instcode);
688: my $crosslisttotal = $env{'form.crosslisttotal'};
689: if (!defined($crosslisttotal)) {
690: $crosslisttotal = 1;
691: }
692: if ($env{'form.addcrosslist'}) {
693: $crosslisttotal ++;
694: }
695: for (my $i=0; $i<$crosslisttotal; $i++) {
696: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
697: $cat_titles,$cat_order,$i);
698: }
699: if ($crosslist_form) {
700: $crosslist_form .=
701: &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
702: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
703: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
704: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
705: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1);
706: }
707: if ($section_form || $crosslist_form) {
708: $sections = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
709: $section_form.$crosslist_form.
710: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
711: }
712: $autoenroll_form =
713: &Apache::lonhtmlcommon::row_title(&mt('Add registered students automatically')).
714: '<span class="LC_nobreak"><label>'.
715: '<input type="radio" name="autoadds" value="1">'.
716: &mt('Yes').'</label>'.(' 'x3).'<label>'.
717: '<input type="radio" name="autoadds" value="0" checked="checked">'.
718: &mt('No').'</label></span>'.
719: &Apache::lonhtmlcommon::row_closure().
720: &Apache::lonhtmlcommon::row_title(&mt('Drop unregistered students automatically')).
721: '<span class="LC_nobreak"><label>'.
722: '<input type="radio" name="autodrops" value="1">'.
723: &mt('Yes').'</label>'.(' 'x3).'<label>'.
724: '<input type="radio" name="autodrops" value="0" checked="checked">'.
725: &mt('No').'</label></span>'.
726: &Apache::lonhtmlcommon::row_closure().
727: &date_setting_table($starttime,$endtime,$formname,'enroll',%enrolltitles);
728: if ($autoenroll_form) {
729: $autoenroll = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
730: $autoenroll_form.
731: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
732: }
733: }
734: }
735: my $access_dates_form =
736: &date_setting_table($starttime,$endtime,$formname,'access',%accesstitles);
737: if ($access_dates_form) {
738: $access_dates = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
739: $access_dates_form.
740: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
741: }
742: return $sections.$autoenroll.$access_dates;
743: }
744:
745: sub inst_section_selector {
746: my ($dom,$instcode) = @_;
747: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
748: my $sectotal = scalar(@sections);
749: my $output;
750: if ($sectotal) {
751: $output .= &Apache::lonhtmlcommon::row_title('Sections').
752: &Apache::loncommon::start_data_table().
753: &Apache::loncommon::start_data_table_row().
754: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
755: 'value="'.$sectotal.'"</th>'.
756: '<th>'.&mt('Institutional Section').'</th>'.
757: '<th>'.&mt('LON-CAPA section').'</th>'.
758: &Apache::loncommon::end_data_table_row();
759: for (my $i=0; $i<@sections; $i++) {
760: my $colflag = $i%2;
761: $output .= &Apache::loncommon::start_data_table_row().
762: '<td><input type="checkbox" name="sec_'.$i.
763: '" checked="checked" /></td>'.
764: '<td>'.$sections[$i].
765: '<input type="hidden" name="secnum_'.$i.'" value="'.
766: $sections[$i].'" /></td>'.
767: '<td><input type="text" size="10" name="loncapasec_'.$i.
768: '" value="'.$sections[$i].'" /></td>'.
769: &Apache::loncommon::end_data_table_row();
770: }
771: $output .= &Apache::loncommon::end_data_table().
772: &Apache::lonhtmlcommon::row_closure();
773: }
774: return $output;
775: }
776:
777: sub date_setting_table {
778: my ($starttime,$endtime,$formname,$suffix,%datetitles) = @_;
779: my ($perpetual,$table);
780: my $startform = &Apache::lonhtmlcommon::date_setter($formname,'start'.$suffix,
781: $starttime,'','','',1,'','','',1);
782: my $endform = &Apache::lonhtmlcommon::date_setter($formname,'end'.$suffix,
783: $endtime,'','','',1,'','','',1);
784: if ($suffix eq 'access') {
785: $perpetual = ' <span class="LC_nobreak"><label>'.
786: '<input type="checkbox" name="no_end_date" />'.
787: &mt('No end date').'</label></span>';
788: }
789: $table = &Apache::lonhtmlcommon::row_title($datetitles{'start'}).
790: $startform.
791: &Apache::lonhtmlcommon::row_closure().
792: &Apache::lonhtmlcommon::row_title($datetitles{'end'}).
793: $endform.$perpetual.
794: &Apache::lonhtmlcommon::row_closure(1);
795: return $table;
796: }
797:
798: sub print_personnel_menu {
799: my ($dom,$formname,$crstype) = @_;
800: my $output = '<div>'.&Apache::lonhtmlcommon::start_pick_box();
801: my $persontotal = $env{'form.persontotal'};
802: if (!defined($persontotal)) {
803: $persontotal = 1;
804: }
805: if ($env{'form.addperson'}) {
806: $persontotal ++;
807: }
808: my $userlinktxt = &mt('Set User');
809: my @items = ('uname','dom','last','first','email','hidedom');
810:
811: my $roleoptions;
812: my @roles = &Apache::lonuserutils::roles_by_context('course');
813: my $type = 'Course';
814: if ($crstype eq 'community') {
815: $type = 'Community';
816: }
817: foreach my $role (@roles) {
818: my $plrole=&Apache::lonnet::plaintext($role,$type);
819: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
820: }
821: my %customroles=&Apache::lonuserutils::my_custom_roles();
822: if (keys(%customroles) > 0) {
823: foreach my $cust (sort(keys(%customroles))) {
824: my $custrole='cr_cr_'.$env{'user.domain'}.
825: '_'.$env{'user.name'}.'_'.$cust;
826: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
827: }
828: }
829:
830: my @currsecs;
831: if ($env{'form.sectotal'}) {
832: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
833: if (defined($env{'form.loncapasec_'.$i})) {
834: my $lcsec = $env{'form.loncapasec_'.$i};
835: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
836: push(@currsecs,$lcsec);
837: }
838: }
839: }
840: }
841:
842: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
843: if (@currsecs) {
844: my $existsize = scalar(@currsecs);
845: if ($existsize > 3) {
846: $existsize = 3;
847: }
848: if ($existsize > 1) {
849: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
850: }
851: @currsecs = sort { $a <=> $b } (@currsecs);
852: $existtitle = &mt('Official').': ';
853: $existops = '<option value="">'.&mt('None').'</option>';
854: foreach my $sec (@currsecs) {
855: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
856: }
857: $seccolspan = ' colspan="2"';
858: $newtitle = &mt('Other').': ';
859: }
860:
861: for (my $i=0; $i<$persontotal; $i++) {
862: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
863: my $linkargstr = join("','",@linkargs);
864: my $userlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,$userlinktxt);
865: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value=""'.
866: ' onFocus="this.blur();'.
867: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');" />';
868: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
869: "'person_".$i."_hidedom'".');'.
870: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');';
871: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
872: 1,$onchange).
873: '<input type="hidden" name="person_'.$i.'_hidedom" value="'.$dom.'" />';
874: my %form_elems;
875: foreach my $item (@items) {
876: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
877: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
878: 'value="" readonly="readonly" />';
879: }
880: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
881: $roleoptions.'</select>';
882: my $sectionselector;
883: if (@currsecs) {
884: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
885: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
886: }
887: $sectionselector .= $newtitle.
888: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'.
889: '<input type="hidden" name="person_'.$i.'_sections" value="" />'."\n";
890:
891: $output .=
892: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel').'<br />'.
893: '<span class="LC_nobreak">'.$userlink.
894: '</span>').
895: '<table><tr><td align="center" valign="top">'.&mt('Username').'<br />'.$uname_form.'</td>'."\n".
896: '<td align="center" valign="top" colspan="2">'.&mt('Domain').'<br />'.$udom_form.'</td></tr><tr>'."\n".
897: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'first'}.'</td>'."\n".
898: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'last'}.'</td>'."\n".
899: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{email}.'</td></tr>'."\n".
900: '<tr><td align="center" valign="top">'.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
901: '<td'.$seccolspan.' align="center" valign="top">'.&mt('Section(s)').'<br />'.$sectionselector.'</td>'."\n".
902: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
903: }
904: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
905: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
906: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
907: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
908: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
909: &Apache::lonhtmlcommon::end_pick_box().'</div>';
910: return $output;
911: }
912:
913: sub print_request_status {
914: return;
915: }
916:
917: sub print_request_logs {
918: return;
919: }
920:
921: sub print_review {
922: my ($formname,$dom,$codetitles,$cat_titles,$cat_order,$code_order) = @_;
923: my ($types,$typename) = &course_types();
924: my ($owner,$ownername,$owneremail);
925: $owner = $env{'user.name'}.':'.$env{'user.domain'};
926: $ownername = &Apache::loncommon::plainname($env{'user.name'},
927: $env{'user.domain'},'first');
928: my %emails = &Apache::loncommon::getemails();
929: foreach my $email ('permanentemail','critnotification','notification') {
930: $owneremail = $emails{$email};
931: last if ($owneremail ne '');
932: }
933: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
934: $section_headers,$section_values,$personnel_headers,$personnel_values);
935:
936: $crstypename = $env{'form.crstype'};
937: if (ref($typename) eq 'HASH') {
938: unless ($typename->{$env{'form.crstype'}} eq '') {
939: $crstypename = $typename->{$env{'form.crstype'}};
940: }
941: }
942:
943: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
944: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
945:
946: if ($env{'form.crstype'} eq 'official') {
947: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
948: foreach my $title (@{$codetitles}) {
949: if ($env{'form.instcode_'.$title} ne '') {
950: $inst_headers .= '<th>'.$title.'</th>';
951: my $longitem = $env{'form.instcode_'.$title};
952: if (ref($cat_titles->{$title}) eq 'HASH') {
953: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
954: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
955: }
956: }
957: $inst_values .= '<td>'.$longitem.'</td>';
958: }
959: }
960: }
961: if (&Apache::lonnet::auto_run('',$dom)) {
962: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
963: '<th>'.&mt('Automatic Drops').'</th>'.
964: '<th>'.&mt('Enrollment Starts').'</th>'.
965: '<th>'.&mt('Enrollment Ends').'</th>';
966: $section_headers = '<th>'.&mt('Sections').'</th>'.
967: '<th>'.&mt('Crosslistings').'</th>';
968:
969: my ($startenroll,$endenroll) = &dates_from_form('startenroll','endenroll');
970: my @autoroster = (&mt('No'),&mt('Yes'));
971: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
972: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
973: '<td>'.&Apache::lonlocal::locallocaltime($startenroll).'</td>'.
974: '<td>'.&Apache::lonlocal::locallocaltime($endenroll).'</td>';
975: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
976: &mt('Institutional section').'</th>'.
977: '<th>'.&mt('LON-CAPA section').'</th></tr>';
978: my $secinfo;
979: if ($env{'form.sectotal'} > 0) {
980: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
981: if ($env{'form.sec_'.$i}) {
982: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
983: if ($env{'form.loncapasec_'.$i} ne '') {
984: $secinfo .= $env{'form.loncapasec_'.$i};
985: } else {
986: $secinfo .= &mt('None');
987: }
988: $secinfo .= '</td></tr>';
989: }
990: }
991: }
992: if ($secinfo eq '') {
993: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
994: }
995: $section_values .= $secinfo.'</table></td><td>'.
996: '<table class="LC_innerpickbox"><tr><th>'.
997: &mt('Institutional course/section').'</th>'.
998: '<th>'.&mt('LON-CAPA section').'</th></tr>';
999: my $xlistinfo;
1000: if ($env{'form.crosslisttotal'}) {
1001: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1002: if ($env{'form.crosslist_'.$i}) {
1003: $xlistinfo .= '<tr><td>';
1004: if (ref($code_order) eq 'ARRAY') {
1005: if (@{$code_order} > 0) {
1006: foreach my $item (@{$code_order}) {
1007: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1008: }
1009: }
1010: }
1011: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
1012: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
1013: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
1014: } else {
1015: $xlistinfo .= &mt('None');
1016: }
1017: $xlistinfo .= '</td></tr>';
1018: }
1019: }
1020: }
1021: if ($xlistinfo eq '') {
1022: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1023: }
1024: $section_values .= $xlistinfo.'</table></td>';
1025: }
1026: }
1027:
1028: my %ctxt = &clone_text();
1029: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1030: if (($env{'form.clonecourse'} =~ /^$match_name$/) &&
1031: ($env{'form.clonedomain'} =~ /^$match_domain$/)) {
1032: my %coursehash =
1033: &Apache::lonnet::courseiddump($env{'form.clonedomain'},'.',1,'.','.',
1034: $env{'form.clonecourse'},undef,undef,'.');
1035: my $cloneid = $env{'form.clonedomain'}.'_'.$env{'form.clonecourse'};
1036: if (ref($coursehash{$cloneid}) eq 'HASH') {
1037: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
1038: my $clonedesc = $coursehash{$cloneid}{'description'};
1039: my $cloneinst = $coursehash{$cloneid}{'inst_code'};
1040:
1041: $inst_values .= '<td>'.$clonedesc.' ';
1042: if ($cloneinst ne '') {
1043: $inst_values .= &mt('([_1] in [_2])',$cloneinst,$env{'form.clonedomain'});
1044: } else {
1045: $inst_values .= &mt('(from [_1])',$env{'form.clonedomain'});
1046: }
1047: $inst_values .= '</td><td>';
1048: if ($env{'form.datemode'} eq 'preserve') {
1049: $inst_values .= $ctxt{'pcd'};
1050: } elsif ($env{'form.datemode'} eq 'shift') {
1051: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
1052: } else {
1053: $inst_values .= $ctxt{'ncd'};
1054: }
1055: $inst_values .= '</td>';
1056: } else {
1057: $inst_values .= '<td>'.&mt('Unknown').'</td>';
1058: }
1059: } else {
1060: $inst_values .= '<td>'.&mt('None').'</td>';
1061: }
1062: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
1063: '<th>'.&mt('Access Ends').'</th>';
1064: my ($startaccess,$endaccess) = &dates_from_form('startaccess','endaccess');
1065: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($startaccess).'</td>';
1066: if ($endaccess == 0) {
1067: $enroll_values .= '<td>'.&mt('No end date').'</td>';
1068: } else {
1069: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($endaccess).'</td>';
1070: }
1071:
1072: my $container = 'Course';
1073: if ($env{'form.crstype'} eq 'community') {
1074: $container = 'Community';
1075: }
1076:
1077: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
1078: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
1079: '</th>';
1080: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1081: '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
1082: '<td>'.&mt('None').'</td></tr>';
1083: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1084: if ($env{'form.person_'.$i.'_uname'} ne '') {
1085: $personnel_values .=
1086: '<tr><td>'.$env{'form.person_'.$i.'_first'}.' '.
1087: $env{'form.person_'.$i.'_last'}.'</td>'.
1088: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
1089: $env{'form.person_'.$i.'_dom'}.'</td>'.
1090: '<td>'.&Apache::lonnet::plaintext($env{'form.person_'.$i.'_role'},
1091: $container).'</td>'.
1092: '<td>'.$env{'form.person_'.$i.'_sections'}.'</td></tr>';
1093: }
1094: }
1095: my $output = '<p>'.&mt('Review the details of the course request before submission.').'</p>'.
1096: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1097: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1098: '<table class="LC_innerpickbox"><tr>'.
1099: '<th>'.&mt('Name').'</th>'.
1100: '<th>'.&mt('Username:Domain').'</th>'.
1101: '<th>'.&mt('E-mail address').'</th>'.
1102: '</tr><tr>'."\n".
1103: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
1104: '<td>'.$owneremail.'</td>'.
1105: '</tr></table>'."\n".
1106: &Apache::lonhtmlcommon::row_closure().
1107: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1108: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
1109: '<tr>'.$inst_values.'</tr></table>'."\n".
1110: &Apache::lonhtmlcommon::row_closure().
1111: &Apache::lonhtmlcommon::row_title(&mt('Enrollment')).
1112: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
1113: '<tr>'.$enroll_values.'</tr></table>'."\n".
1114: &Apache::lonhtmlcommon::row_closure();
1115: if ($section_headers ne '') {
1116: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
1117: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
1118: '<tr>'.$section_values.'</tr></table>'."\n".
1119: &Apache::lonhtmlcommon::row_closure();
1120: }
1121: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
1122: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
1123: $personnel_values.'</table>'."\n".
1124: &Apache::lonhtmlcommon::row_closure(1).
1125: &Apache::lonhtmlcommon::end_pick_box();
1126: my $cnum = &Apache::lonnet::generate_coursenum($dom);
1127: $output .= '<input type="hidden" name="cnum" value="'.$cnum.'" />';
1128: return $output;
1129: }
1130:
1131: sub dates_from_form {
1132: my ($startname,$endname) = @_;
1133: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1134: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1135: if ($endname eq 'endaccess') {
1136: if (exists($env{'form.no_end_date'}) ) {
1137: $enddate = 0;
1138: }
1139: }
1140: return ($startdate,$enddate);
1141: }
1142:
1143: sub courseinfo_form {
1144: my ($dom,$formname,$crstype) = @_;
1145: my $output = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1146: &Apache::lonhtmlcommon::row_title('Course Description').
1147: '<input type="text" size="40" name="cdescr" />'.
1148: &Apache::lonhtmlcommon::row_closure(1).
1149: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
1150: '<div>'.&clone_form($dom,$formname,$crstype).'</div>'."\n";
1151: return $output;
1152: }
1153:
1154: sub clone_form {
1155: my ($dom,$formname,$crstype) = @_;
1156: my $type = 'Course';
1157: if ($crstype eq 'community') {
1158: $type = 'Community';
1159: }
1160: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedomain').
1161: &Apache::loncommon::selectcourse_link($formname,'clonecourse','clonedomain','','','',$type);
1162: my %lt = &clone_text();
1163: my $output .=
1164: &Apache::lonhtmlcommon::start_pick_box().
1165: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1166: '<input type="text" size="25" name="clonecourse" value="" onfocus="this.blur();'.
1167: 'opencrsbrowser('."'$formname','clonecourse','clonedomain','','','','$type'".');" />'.
1168: '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
1169: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
1170: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure().
1171: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
1172: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
1173: '</label><br /><label>'.
1174: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
1175: '</label><br /><label>'.
1176: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
1177: $lt{'shd'}.'</label>'.
1178: '<input type="text" size="5" name="dateshift" value="365" />'.
1179: &Apache::lonhtmlcommon::row_closure(1).
1180: &Apache::lonhtmlcommon::end_pick_box();
1181: return $output;
1182: }
1183:
1184: sub clone_text {
1185: return &Apache::lonlocal::texthash(
1186: 'cid' => 'Course ID',
1187: 'dmn' => 'Domain',
1188: 'dsh' => 'Date Shift',
1189: 'ncd' => 'Do not clone date parameters',
1190: 'prd' => 'Clone date parameters as-is',
1191: 'shd' => 'Shift date parameters by number of days',
1192: );
1193: }
1194:
1195: sub coursecode_form {
1196: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1197: my $output;
1198: my %rowtitle = (
1199: instcode => 'Course Category',
1200: crosslist => 'Cross Listed Course',
1201: );
1202: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
1203: (ref($cat_order))) {
1204: my ($sel,$instsec,$lcsec);
1205: $sel = $context;
1206: if ($context eq 'crosslist') {
1207: $sel .= '_'.$num;
1208: $instsec = &mt('Institutional section').'<br />'.
1209: '<input type="text" size="10" name="'.$sel.'_instsec" />';
1210: $lcsec = &mt('LON-CAPA section').'<br />'.
1211: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
1212: }
1213: if (@{$codetitles} > 0) {
1214: my $lastitem = pop(@{$codetitles});
1215: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1216: if (@{$codetitles} > 0) {
1217: $output = &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1218: '<table><tr>';
1219: if ($context eq 'crosslist') {
1220: $output .= '<td>'.&mt('Include?').'<br />'.
1221: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1222: }
1223: foreach my $title (@{$codetitles}) {
1224: if (ref($cat_order->{$title}) eq 'ARRAY') {
1225: if (@{$cat_order->{$title}} > 0) {
1226: $output .= '<td align="center">'.$title.'<br />'."\n".
1227: '<select name="'.$sel.'_'.$title.'">'."\n".
1228: ' <option value="" selected="selected">'.
1229: &mt('Select').'</option>'."\n";
1230: foreach my $item (@{$cat_order->{$title}}) {
1231: my $longitem = $item;
1232: if (ref($cat_titles->{$title}) eq 'HASH') {
1233: if ($cat_titles->{$title}{$item} ne '') {
1234: $longitem = $cat_titles->{$title}{$item};
1235: }
1236: }
1237: $output .= '<option value="'.$item.'">'.$longitem.
1238: '</option>'."\n";
1239: }
1240: }
1241: $output .= '</select></td>'."\n";
1242: }
1243: }
1244: if ($context eq 'crosslist') {
1245: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1246: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
1247: '<td align="center">'.$lcsec.'</td></tr></table>';
1248: } else {
1249: $output .= '</tr></table>'.
1250: &Apache::lonhtmlcommon::row_closure().
1251: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1252: $lastinput;
1253: }
1254: } else {
1255: if ($context eq 'crosslist') {
1256: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1257: '<table><tr>'.
1258: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
1259: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
1260: '</tr></table>';
1261: } else {
1262: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1263: $lastinput;
1264: }
1265: }
1266: $output .= &Apache::lonhtmlcommon::row_closure(1);
1267: push(@$codetitles,$lastitem);
1268: } elsif ($context eq 'crosslist') {
1269: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1270: '<table><tr><td align="center">'.
1271: '<span class="LC_nobreak">'.&mt('Include?').
1272: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
1273: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
1274: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
1275: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
1276: &Apache::lonhtmlcommon::row_closure(1);
1277: }
1278: }
1279: return $output;
1280: }
1281:
1282: sub get_course_dom {
1283: my $codedom = &Apache::lonnet::default_login_domain();
1284: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1285: $codedom = $env{'user.domain'};
1286: if ($env{'request.role.domain'} ne '') {
1287: $codedom = $env{'request.role.domain'};
1288: }
1289: }
1290: if ($env{'form.showdom'} ne '') {
1291: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
1292: $codedom = $env{'form.showdom'};
1293: }
1294: }
1295: return $codedom;
1296: }
1297:
1298: sub display_navbuttons {
1299: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1300: $r->print('<div class="LC_navbuttons">');
1301: if ($prev) {
1302: $r->print('
1303: <input type="button" name="previous" value = "'.$prevtext.'"
1304: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1305: ');
1306: } elsif ($prevtext) {
1307: $r->print('
1308: <input type="button" name="previous" value = "'.$prevtext.'"
1309: onclick="javascript:history.back()"/>
1310: ');
1311: }
1312: if ($next) {
1313: $r->print('
1314: <input type="button" name="next" value="'.$nexttext.'"
1315: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1316: }
1317: $r->print('</div>');
1318: }
1319:
1320: sub print_request_outcome {
1321: my ($dom) = @_;
1322: my $output;
1323: my $cnum = $env{'form.cnum'};
1324: unless ($cnum =~ /^$match_courseid$/) {
1325: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
1326: return $output;
1327: }
1328: my $req_notifylist = &Apache::lonnet::get_dom('configuration',['requestcourses'],
1329: $dom);
1330: my $now = time;
1331: my $crstype = $env{'form.crstype'};
1332: my ($startenroll,$endenroll,%sections,%crosslistings,%personnel);
1333: if ($crstype eq 'official') {
1334: if (&Apache::lonnet::auto_run('',$dom)) {
1335: ($startenroll,$endenroll)=&dates_from_form('startenroll','endenroll');
1336: }
1337: %sections = ();
1338: %crosslistings = ();
1339: }
1340: my ($startaccess,$endaccess) = &dates_from_form('startaccess','endacess');
1341: my $details = {
1342: owner => $env{'user.name'},
1343: domain => $env{'user.domain'},
1344: cdom => $dom,
1345: cnum => $cnum,
1346: cdesc => $env{'form.cdesc'},
1347: crstype => $env{'form.crstype'},
1348: instcode => $env{'form.instcode'},
1349: clonedomain => $env{'form.clonedomain'},
1350: clonecourse => $env{'form.clonecourse'},
1351: datemode => $env{'form.datemode'},
1352: dateshift => $env{'form.datshift'},
1353: sectotal => $env{'form.sectotal'},
1354: sections => \%sections,
1355: crosstotal => $env{'form.crosstotal'},
1356: crosslistings => \%crosslistings,
1357: autoadds => $env{'form.autoadds'},
1358: autodrops => $env{'form.autodrops'},
1359: startenroll => $startenroll,
1360: endenroll => $endenroll,
1361: startaccess => $startaccess,
1362: endaccess => $endaccess,
1363: personnel => \%personnel
1364: };
1365: my @inststatuses;
1366: my $val = &get_processtype($dom,$crstype,\@inststatuses);
1367: if ($val eq '') {
1368: if ($crstype eq 'official') {
1369: $output = &mt('You are not permitted to request creation of official courses');
1370: } elsif ($crstype eq 'unofficial') {
1371: $output = &mt('You are not permitted to request creation of unofficial courses');
1372: } elsif ($crstype eq 'community') {
1373: $output = &mt('You are not permitted to request creation of communities');
1374: } else {
1375: $output = &mt('Unrecognized course type: [_1]',$crstype);
1376: }
1377: } else {
1378: my ($disposition,$message);
1379: my %reqhash = (
1380: crstype => $crstype,
1381: details => $details,
1382: );
1383: my $requestkey = $dom.'_'.$cnum;
1384: if ($val =~ /^autolimit=/) {
1385: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1386: $dom,$crstype,$val,\$message);
1387: } elsif ($val eq 'validate') {
1388: $disposition =
1389: &Apache::lonnet::auto_courserequest_validation($dom,$details,
1390: \@inststatuses,\$message);
1391: } else {
1392: $disposition = 'approval';
1393: }
1394: $reqhash{'status'} = $disposition;
1395: if ($disposition eq 'rejected') {
1396: $output = &mt('Your course request was rejected.');
1397: if ($message) {
1398: $output .= '<div class="LC_warning">'.$message.'</div>';
1399: }
1400: } elsif ($disposition eq 'process') {
1401: my $type = 'Course';
1402: if ($crstype eq 'community') {
1403: $type = 'Community';
1404: }
1405: my ($logmsg,$newusermsg,$addresult,$enrollcount,$output,$keysmsg,%longroles);
1406: my @roles = &Apache::lonuserutils::roles_by_context('course');
1407: foreach my $role (@roles) {
1408: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
1409: }
1410: my %reqdetails = &build_batchcreatehash($details);
1411: my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'request',\%reqdetails,\%longroles,\$logmsg,\$newusermsg,\$addresult,\$enrollcount,\$output,\$keysmsg,$env{'user.domain'},$env{'user.name'},$cnum);
1412: $disposition = 'created';
1413: if ($cid eq $cnum) {
1414: $disposition = 'created';
1415: $output = &mt('Your course request has been processed and the course has been created.').'<br />'.&mt('You will need to logout and log-in again to be able to select a role in the course.');
1416: } else {
1417: $output = &mt('An error occurred when processing your course request.').'<br />'.&mt('You may want to review the request details and submit the request again.');
1418: }
1419: } else {
1420: my $requestid = $cnum.'_'.$disposition;
1421: my $request = {
1422: $requestid => {
1423: timestamp => $now,
1424: crstype => $crstype,
1425: ownername => $env{'user.name'},
1426: ownerdom => $env{'user.domain'},
1427: description => $env{'form.cdesc'},
1428: },
1429: };
1430: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
1431: $dom);
1432: if ($putresult eq 'ok') {
1433: my %emails = &Apache::loncommon::getemails();
1434: my $address;
1435: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
1436: $address = $emails{'permanentemail'};
1437: if ($address eq '') {
1438: $address = $emails{'notification'};
1439: }
1440: }
1441: $output = &mt('Your course request has been recorded.').'<br />';
1442: if ($disposition eq 'approval') {
1443: $output .= &mt('Your course request has been recorded.').'<br />'.
1444: &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
1445: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
1446: if ($address ne '') {
1447: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
1448: }
1449: if ($req_notifylist) {
1450: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
1451: $env{'user.domain'});
1452: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,$fullname,$now,$dom,$details);
1453: }
1454: } else {
1455: $output .= '<div class="LC_info">'.
1456: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
1457: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
1458: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
1459: '</div>';
1460: }
1461: } else {
1462: $reqhash{'status'} = 'domainerror';
1463: $reqhash{'disposition'} = $disposition;
1464: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
1465: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1466:
1467: }
1468: }
1469: my $storeresult = &Apache::lonnet::store_coursereq($requestkey,\%reqhash);
1470: if ($storeresult ne 'ok') {
1471: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request.').'</span><br />';
1472: &logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1473: }
1474: }
1475: return $output;
1476: }
1477:
1478: sub get_processtype {
1479: my ($dom,$crstype,$inststatuses) = @_;
1480: return unless (ref($inststatuses) eq 'ARRAY');
1481: my (%userenv,%settings,$val);
1482: my @options = ('autolimit','validate','approve');
1483: if ($dom eq $env{'user.domain'}) {
1484: %userenv =
1485: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
1486: 'requestcourses.'.$crstype,'inststatus');
1487: if ($userenv{'requestcourses.'.$crstype}) {
1488: $val = $userenv{'requestcourses.'.$crstype};
1489: @{$inststatuses} = ('_custom_');
1490: } else {
1491: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1492: my ($task,%alltasks);
1493: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
1494: %settings = %{$domconfig{'requestcourses'}};
1495: if (ref($settings{$crstype}) eq 'HASH') {
1496: if (($env{'user.adv'}) && (exists($settings{$crstype}{'_LC_adv'}))) {
1497: $val = $settings{$crstype}{'_LC_adv'};
1498: @{$inststatuses} = ('_LC_adv_');
1499: } else {
1500: if ($userenv{'inststatus'} ne '') {
1501: @{$inststatuses} = split(',',$userenv{'inststatus'});
1502: } else {
1503: @{$inststatuses} = ('other');
1504: }
1505: foreach my $status (@{$inststatuses}) {
1506: if (exists($settings{$crstype}{$status})) {
1507: my $value = $settings{$crstype}{$status};
1508: next unless ($value);
1509: unless (exists($alltasks{$value})) {
1510: if (ref($alltasks{$value}) eq 'ARRAY') {
1511: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
1512: push(@{$alltasks{$value}},$status);
1513: }
1514: } else {
1515: @{$alltasks{$value}} = ($status);
1516: }
1517: }
1518: }
1519: }
1520: my $maxlimit = 0;
1521: foreach my $key (sort(keys(%alltasks))) {
1522: if ($key =~ /^autolimit=(\d*)$/) {
1523: if ($1 eq '') {
1524: $val ='autolimit=';
1525: last;
1526: } elsif ($1 > $maxlimit) {
1527: $maxlimit = $1;
1528: }
1529: }
1530: }
1531: if ($maxlimit) {
1532: $val = 'autolimit='.$maxlimit;
1533: } else {
1534: foreach my $option (@options) {
1535: if ($alltasks{$option}) {
1536: $val = $option;
1537: last;
1538: }
1539: }
1540: }
1541: }
1542: }
1543: }
1544: }
1545: } else {
1546: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
1547: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1548: if ($userenv{'reqcrsotherdom'}) {
1549: my @doms = split(',',$userenv{'reqcrsotherdom'});
1550: my $optregex = join('|',@options);
1551: if (grep(/^\Q$dom\E:($optregex=?\d*)/,@doms)) {
1552: $val = $1;
1553: }
1554: @{$inststatuses} = ('_external_');
1555: }
1556: }
1557: return $val;
1558: }
1559:
1560: sub check_autolimit {
1561: return;
1562: }
1563:
1564: sub build_batchcreatehash {
1565: my ($details) = @_;
1566: my %batchhash;
1567: if (ref($details) eq 'HASH') {
1568:
1569: }
1570: return %batchhash;
1571: }
1572:
1573: sub retrieve_settings {
1574: my ($dom,$request_id) = @_;
1575: my %reqinfo = &get_request_settings($request_id,$dom);
1576: my %stored;
1577: $stored{'cdescr'} = &unescape($reqinfo{'description'});
1578: $stored{'startaccess'} = $reqinfo{'startaccess'};
1579: $stored{'endaccess'} = $reqinfo{'endaccess'};
1580: if ($stored{'endaccess'} == 0) {
1581: $stored{'no_end_date'} = 1;
1582: }
1583: $stored{'startenroll'} = $reqinfo{'startenroll'};
1584: $stored{'endenroll'} = $reqinfo{'endenroll'};
1585: $stored{'crosslist'} = $reqinfo{'crosslist'};
1586: $stored{'clonecourse'} = $reqinfo{'clonecourse'};
1587: $stored{'clonedomain'} = $reqinfo{'clonedomain'};
1588: $stored{'sections'} = $reqinfo{'sections'};
1589: $stored{'personnel'} = $reqinfo{'personnel'};
1590:
1591: return %stored;
1592: }
1593:
1594: sub get_request_settings {
1595: my ($request_id,$dom);
1596: }
1597:
1598: 1;
1599:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>