File:
[LON-CAPA] /
loncom /
interface /
lonrequestcourse.pm
Revision
1.65:
download - view:
text,
annotated -
select for diffs
Wed Aug 15 14:37:13 2012 UTC (12 years ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Requests author roles by users who do not have them.
- Move code from lonroles.pm to new routines in loncoursequeueadmin.pm
is_active_author(), author_prompt(), reqauthor_check(), process_reqauthor()
to facilitate re-use.
- At conclusion of course/community request process, offer option to
request an author role to users without one, who have to rights to
request one.
1: # The LearningOnline Network
2: # Request a course
3: #
4: # $Id: lonrequestcourse.pm,v 1.65 2012/08/15 14:37:13 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 get_breadcrumbs()
48:
49: =item header()
50:
51: =item form_elements()
52:
53: =item onload_action()
54:
55: =item print_main_menu()
56:
57: =item request_administration()
58:
59: =item close_popup_form()
60:
61: =item get_instcode()
62:
63: =item print_request_form()
64:
65: =item print_enrollment_menu()
66:
67: =item show_invalid_crosslists()
68:
69: =item inst_section_selector()
70:
71: =item date_setting_table()
72:
73: =item print_personnel_menu()
74:
75: =item print_request_status()
76:
77: =item print_request_logs()
78:
79: =item print_review()
80:
81: =item dates_from_form()
82:
83: =item courseinfo_form()
84:
85: =item clone_form()
86:
87: =item clone_text()
88:
89: =item coursecode_form()
90:
91: =item get_course_dom()
92:
93: =item display_navbuttons()
94:
95: =item print_request_outcome()
96:
97: =item check_autolimit()
98:
99: =item retrieve_settings()
100:
101: =item get_request_settings()
102:
103: =item extract_instcode()
104:
105: =item generate_date_items()
106:
107: =back
108:
109: =cut
110:
111: package Apache::lonrequestcourse;
112:
113: use strict;
114: use Apache::Constants qw(:common :http);
115: use Apache::lonnet;
116: use Apache::loncommon;
117: use Apache::lonlocal;
118: use Apache::loncoursequeueadmin;
119: use Apache::lonuserutils;
120: use LONCAPA qw(:DEFAULT :match);
121:
122: sub handler {
123: my ($r) = @_;
124: &Apache::loncommon::content_type($r,'text/html');
125: $r->send_http_header;
126: if ($r->header_only) {
127: return OK;
128: }
129:
130: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
131: ['action','showdom','cnum','state','crstype','queue']);
132: &Apache::lonhtmlcommon::clear_breadcrumbs();
133: my $dom = &get_course_dom();
134: my $action = $env{'form.action'};
135: my $state = $env{'form.state'};
136: my (%states,%stored);
137: my ($jscript,$uname,$udom,$result,$warning);
138:
139: $states{'display'} = ['details'];
140: $states{'view'} = ['pick_request','details','cancel','removal'];
141: $states{'log'} = ['display'];
142: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
143:
144: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
145: unless ($env{'form.state'} eq 'crstype') {
146: unshift(@{$states{'new'}},'codepick');
147: }
148: }
149:
150: if (($action eq 'new') && (&Apache::loncoursequeueadmin::author_prompt())) {
151: if (ref($states{$action}) eq 'ARRAY') {
152: push(@{$states{$action}},'reqauthor');
153: }
154: }
155:
156: foreach my $key (keys(%states)) {
157: if (ref($states{$key}) eq 'ARRAY') {
158: unshift (@{$states{$key}},'crstype');
159: }
160: }
161:
162: my @invalidcrosslist;
163: my %trail = (
164: crstype => 'Request Action',
165: codepick => 'Category',
166: courseinfo => 'Description',
167: enrollment => 'Access Dates',
168: personnel => 'Personnel',
169: review => 'Review',
170: process => 'Result',
171: reqauthor => 'Authoring Space Result',
172: pick_request => 'Display Summary',
173: details => 'Request Details',
174: cancel => 'Cancel Request',
175: removal => 'Outcome',
176: display => 'Request Logs',
177: );
178:
179: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
180: $trail{'enrollment'} = 'Enrollment';
181: }
182:
183: my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) =
184: &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
185: if ($action eq 'display') {
186: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
187: if ($env{'form.cnum'} ne '') {
188: my $cnum = $env{'form.cnum'};
189: my $queue = $env{'form.queue'};
190: my $reqkey = $cnum.'_'.$queue;
191: my $namespace = 'courserequestqueue';
192: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
193: my %queued =
194: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
195: if (ref($queued{$reqkey}) eq 'HASH') {
196: $uname = $queued{$reqkey}{'ownername'};
197: $udom = $queued{$reqkey}{'ownerdom'};
198: if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
199: $result = &retrieve_settings($dom,$cnum,$udom,$uname);
200: } else {
201: if ($env{'form.crstype'} eq 'community') {
202: $warning = &mt('Invalid username or domain for community requestor');
203: } else {
204: $warning = &mt('Invalid username or domain for course requestor');
205: }
206: }
207: } else {
208: if ($env{'form.crstype'} eq 'community') {
209: $warning = &mt('No information was found for this community request.');
210: } else {
211: $warning = &mt('No information was found for this course request.');
212: }
213: }
214: } else {
215: $warning = &mt('No course request ID provided.');
216: }
217: } else {
218: if ($env{'form.crstype'} eq 'any') {
219: $warning = &mt('You do not have rights to view course or community request information.');
220: } elsif ($env{'form.crstype'} eq 'community') {
221: $warning = &mt('You do not have rights to view community request information.');
222: } else {
223: $warning = &mt('You do not have rights to view course request information.');
224: }
225: }
226: } elsif ((defined($state)) && (defined($action))) {
227: if (($action eq 'view') && ($state eq 'details')) {
228: if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
229: my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
230: }
231: } elsif ($env{'form.crstype'} eq 'official') {
232: if (&Apache::lonnet::auto_run('',$dom)) {
233: if (($action eq 'new') && (($state eq 'enrollment') ||
234: ($state eq 'personnel'))) {
235: my $checkcrosslist = 0;
236: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
237: if ($env{'form.crosslist_'.$i}) {
238: $checkcrosslist ++;
239: }
240: }
241: if ($checkcrosslist) {
242: my %codechk;
243: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
244: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
245: \%cat_titles,
246: \%cat_order,
247: \@code_order);
248: my $numtitles = scalar(@codetitles);
249: if ($numtitles) {
250: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
251: if ($env{'form.crosslist_'.$i}) {
252: my $codecheck;
253: my $crosslistcode = '';
254: foreach my $item (@code_order) {
255: $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item};
256: }
257: if ($crosslistcode ne '') {
258: ($codechk{$i}, my $rest) =
259: &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
260: }
261: unless ($codechk{$i} eq 'valid') {
262: $env{'form.crosslist_'.$i} = '';
263: push(@invalidcrosslist,$crosslistcode);
264: }
265: }
266: }
267: }
268: }
269: }
270: }
271: }
272: my %elements = &form_elements($dom);
273: my $elementsref = {};
274: if (ref($elements{$action}) eq 'HASH') {
275: if (ref($elements{$action}{$state}) eq 'HASH') {
276: $elementsref = $elements{$action}{$state};
277: }
278: }
279: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
280: $env{'form.clonedom'} = $dom;
281: }
282: if ($state eq 'crstype') {
283: $jscript = &mainmenu_javascript();
284: } else {
285: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
286: if ($state eq 'courseinfo') {
287: $jscript .= &cloning_javascript();
288: }
289: }
290: }
291:
292: if ($state eq 'personnel') {
293: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
294: }
295:
296: my $loaditems = &onload_action($action,$state);
297:
298: my (%can_request,%request_domains);
299: my $canreq =
300: &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains);
301: if ($action eq 'new') {
302: if ($canreq) {
303: if ($state eq 'crstype') {
304: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
305: $crumb,\%request_domains);
306: } else {
307: &request_administration($r,$action,$state,$page,\%states,$dom,
308: $jscript,$loaditems,$crumb,$newinstcode,
309: $codechk,$checkedcode,$description,
310: \@invalidcrosslist);
311: }
312: } else {
313: $r->print(&header('Course/Community Requests').$crumb.
314: '<div class="LC_warning">'.
315: &mt('You do not have privileges to request creation of courses or communities.').
316: '</div>'.&Apache::loncommon::end_page());
317: }
318: } elsif ($action eq 'view') {
319: if ($state eq 'crstype') {
320: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains);
321: } else {
322: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
323: $loaditems,$crumb);
324: }
325: } elsif ($action eq 'display') {
326: if ($warning ne '') {
327: my $args = { only_body => 1 };
328: $r->print(&header('Course/Community Requests','','' ,'',$args).$crumb.
329: '<h3>'.&mt('Course/Community Request Details').'</h3>'.
330: '<div class="LC_warning">'.$warning.'</div>'.
331: &close_popup_form());
332: } else {
333: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
334: $loaditems,$crumb,'','','','','',$uname,$udom);
335: }
336: } elsif ($action eq 'log') {
337: if ($state eq 'crstype') {
338: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
339: } else {
340: $jscript .= <<ENDJS;
341:
342: function backPage(formname,prevstate) {
343: formname.state.value = prevstate;
344: formname.submit();
345: }
346:
347: function setPage(formname) {
348: formname.page.value = '1';
349: return;
350: }
351:
352: ENDJS
353: &print_request_logs($r,$dom,$jscript,$loaditems,$crumb);
354: }
355: } else {
356: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
357: }
358: return OK;
359: }
360:
361: sub mainmenu_javascript {
362: return <<"END";
363: function setType(courseForm) {
364: for (var i=0; i<courseForm.crstype.length; i++) {
365: if (courseForm.crstype.options[i].value == "$env{'form.crstype'}") {
366: courseForm.crstype.options[i].selected = true;
367: } else {
368: courseForm.crstype.options[i].selected = false;
369: }
370: }
371: }
372:
373: function setAction(courseForm) {
374: for (var i=0; i<courseForm.action.length; i++) {
375: if (courseForm.action.options[i].value == "$env{'form.action'}") {
376: courseForm.action.options[i].selected = true;
377: } else {
378: courseForm.action.options[i].selected = false;
379: }
380: }
381: }
382: END
383: }
384:
385: sub cloning_javascript {
386: return <<"END";
387: function setCloneDisplay(courseForm) {
388: if (courseForm.cloning.length > 1) {
389: for (var i=0; i<courseForm.cloning.length; i++) {
390: if (courseForm.cloning[i].checked) {
391: if (courseForm.cloning[i].value == 1) {
392: document.getElementById('cloneoptions').style.display="block";;
393: }
394: }
395: }
396: }
397: }
398: END
399: }
400:
401: sub get_breadcrumbs {
402: my ($dom,$action,$state,$states,$trail) = @_;
403: my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
404: my $page = 0;
405: if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
406: if (defined($action)) {
407: my $done = 0;
408: my $i=0;
409: if (ref($states->{$action}) eq 'ARRAY') {
410: while ($i<@{$states->{$action}} && !$done) {
411: if ($states->{$action}[$i] eq $$state) {
412: $page = $i;
413: $done = 1;
414: }
415: $i++;
416: }
417: }
418: if ($env{'form.crstype'} eq 'official') {
419: if ($page > 1) {
420: if ($states->{$action}[$page-1] eq 'codepick') {
421: if ($env{'form.instcode'} eq '') {
422: ($newinstcode,$numtitles) = &get_instcode($dom);
423: if ($numtitles) {
424: if ($newinstcode eq '') {
425: $$state = 'codepick';
426: $page --;
427: } else {
428: ($codechk,$description) =
429: &Apache::lonnet::auto_validate_instcode('',
430: $dom,$newinstcode);
431: if ($codechk ne 'valid') {
432: $$state = 'codepick';
433: $page --;
434: }
435: $checkedcode = 1;
436: }
437: }
438: }
439: }
440: }
441: }
442: for (my $i=0; $i<@{$states->{$action}}; $i++) {
443: if ($$state eq $states->{$action}[$i]) {
444: &Apache::lonhtmlcommon::add_breadcrumb(
445: {text=>"$trail->{$$state}"});
446: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
447: last;
448: } else {
449: if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) {
450: &Apache::lonhtmlcommon::add_breadcrumb(
451: { href => '/adm/requestcourse',
452: text => "$trail->{$states->{$action}[$i]}",
453: }
454: );
455: } else {
456: &Apache::lonhtmlcommon::add_breadcrumb(
457: { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')",
458: text => "$trail->{$states->{$action}[$i]}", }
459: );
460: }
461: }
462: }
463: } else {
464: &Apache::lonhtmlcommon::add_breadcrumb(
465: {text=>'Pick Action'});
466: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
467: }
468: } else {
469: &Apache::lonhtmlcommon::add_breadcrumb(
470: {text=>'Pick Action'});
471: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
472: }
473: return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
474: }
475:
476: sub header {
477: my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
478: if ($jscript) {
479: $jscript = '<script type="text/javascript">'."\n".
480: '// <![CDATA['."\n".
481: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
482: }
483: if ($loaditems) {
484: if (ref($args) eq 'HASH') {
485: my %loadhash = (
486: 'add_entries' => $loaditems,
487: );
488: my %arghash = (%loadhash,%{$args});
489: $args = \%arghash;
490: } else {
491: $args = {'add_entries' => $loaditems,};
492: }
493: }
494: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
495: }
496:
497: sub form_elements {
498: my ($dom) = @_;
499: my %elements =
500: (
501: new => {
502: crstype => {
503: crstype => 'selectbox',
504: action => 'selectbox',
505: origcnum => 'hidden',
506: },
507: courseinfo => {
508: cdescr => 'text',
509: cloning => 'radio',
510: clonecrs => 'text',
511: clonedom => 'selectbox',
512: datemode => 'radio',
513: dateshift => 'text',
514: },
515: enrollment => {
516: accessstart_month => 'selectbox',
517: accessstart_hour => 'selectbox',
518: accessend_month => 'selectbox',
519: accessend_hour => 'selectbox',
520: accessstart_day => 'text',
521: accessstart_year => 'text',
522: accessstart_minute => 'text',
523: accessstart_second => 'text',
524: accessend_day => 'text',
525: accessend_year => 'text',
526: accessend_minute => 'text',
527: accessend_second => 'text',
528: no_end_date => 'checkbox',
529: },
530: personnel => {
531: addperson => 'checkbox',
532: },
533: review => {
534: cnum => 'hidden',
535: },
536: },
537: view => {
538: crstype => {
539: crstype => 'selectbox',
540: action => 'selectbox',
541: },
542: },
543: );
544: my %servers = &Apache::lonnet::get_servers($dom,'library');
545: my $numlib = keys(%servers);
546: if ($numlib > 1) {
547: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
548: } else {
549: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
550: }
551: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
552: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
553: \%cat_order,\@code_order);
554: my $numtitles = scalar(@codetitles);
555: if ($numtitles) {
556: my %extras;
557: $lastitem = pop(@codetitles);
558: $extras{'instcode_'.$lastitem} = 'text';
559: foreach my $item (@codetitles) {
560: $extras{'instcode_'.$item} = 'selectbox';
561: }
562: $elements{'new'}{'codepick'} = \%extras;
563: }
564: if (&Apache::lonnet::auto_run('',$dom)) {
565: my %extras = (
566: enrollstart_month => 'selectbox',
567: enrollstart_hour => 'selectbox',
568: enrollend_month => 'selectbox',
569: enrollend_hour => 'selectbox',
570: enrollstart_day => 'text',
571: enrollstart_year => 'text',
572: enrollstart_minute => 'text',
573: enrollstart_second => 'text',
574: enrollend_day => 'text',
575: enrollend_year => 'text',
576: enrollend_minute => 'text',
577: enrollend_second => 'text',
578: addcrosslist => 'checkbox',
579: autoadds => 'radio',
580: autodrops => 'radio',
581: );
582: my ($instcode,$titlescount) = &get_instcode($dom);
583: if ($instcode) {
584: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
585: if (@sections) {
586: $extras{'sectotal'} = 'hidden';
587: if ($env{'form.sectotal'} > 0) {
588: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
589: $extras{'sec_'.$i} = 'radio';
590: $extras{'secnum_'.$i} = 'text';
591: $extras{'loncapasec_'.$i} = 'text';
592: }
593: }
594: } else {
595: $extras{'addsection'} = 'checkbox';
596: my $sectotal = $env{'form.sectotal'};
597: if ($env{'form.addsection'}) {
598: $sectotal ++;
599: }
600: for (my $i=0; $i<$sectotal; $i++) {
601: $extras{'sec_'.$i} = 'checkbox';
602: $extras{'secnum_'.$i} = 'text',
603: $extras{'loncapasec_'.$i} = 'text',
604: }
605: }
606: }
607: my $crosslisttotal = $env{'form.crosslisttotal'};
608: if ($env{'form.addcrosslist'}) {
609: $crosslisttotal ++;
610: }
611: if (!$crosslisttotal) {
612: $crosslisttotal = 1;
613: }
614: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
615: if ($numtitles) {
616: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
617: }
618: if (@codetitles > 0) {
619: foreach my $item (@codetitles) {
620: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
621: }
622: }
623: $extras{'crosslist_'.$i} = 'checkbox';
624: $extras{'crosslist_'.$i.'_instsec'} = 'text',
625: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
626: }
627: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
628: %{$elements{'new'}{'enrollment'}} = %mergedhash;
629: }
630: my %people;
631: my $persontotal = $env{'form.persontotal'};
632: if ($env{'form.addperson'}) {
633: $persontotal ++;
634: }
635: if ((!defined($persontotal)) || (!$persontotal)) {
636: $persontotal = 1;
637: }
638: for (my $i=0; $i<$persontotal; $i++) {
639: $people{'person_'.$i.'_uname'} = 'text',
640: $people{'person_'.$i.'_dom'} = 'selectbox',
641: $people{'person_'.$i.'_hidedom'} = 'hidden',
642: $people{'person_'.$i.'_firstname'} = 'text',
643: $people{'person_'.$i.'_lastname'} = 'text',
644: $people{'person_'.$i.'_emailaddr'} = 'text',
645: $people{'person_'.$i.'_role'} = 'selectbox',
646: $people{'person_'.$i.'_sec'} = 'selectbox',
647: $people{'person_'.$i.'_newsec'} = 'text',
648: }
649: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
650: %{$elements{'new'}{'personnel'}} = %personnelhash;
651: return %elements;
652: }
653:
654: sub onload_action {
655: my ($action,$state) = @_;
656: my %loaditems;
657: if (($action eq 'new') || ($action eq 'view')) {
658: if ($state eq 'crstype') {
659: $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
660: } else {
661: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
662: }
663: if ($state eq 'courseinfo') {
664: $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);';
665: }
666: }
667: return \%loaditems;
668: }
669:
670: sub print_main_menu {
671: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_;
672: my ($types,$typename) = &Apache::loncommon::course_types();
673: my $onchange = 'this.form.submit()';
674: my $nextstate_setter = "\n";
675: if (ref($states) eq 'HASH') {
676: foreach my $key (keys(%{$states})) {
677: if (ref($states->{$key}) eq 'ARRAY') {
678: $nextstate_setter .=
679: " if (actionchoice == '$key') {
680: nextstate = '".$states->{$key}[1]."';
681: }
682: ";
683: }
684: }
685: }
686:
687: my $js = <<"END";
688:
689: function nextPage(formname) {
690: var crschoice = document.mainmenu_coursetype.crstype.value;
691: var actionchoice = document.mainmenu_action.action.value;
692: if (check_can_request(crschoice,actionchoice) == true) {
693: if ((actionchoice == 'new') && (crschoice == 'official')) {
694: nextstate = 'codepick';
695: } else {
696: $nextstate_setter
697: }
698: formname.crstype.value = crschoice;
699: formname.action.value = actionchoice;
700: formname.state.value= nextstate;
701: formname.submit();
702: }
703: return;
704: }
705:
706: function check_can_request(crschoice,actionchoice) {
707: var official = '';
708: var unofficial = '';
709: var community = '';
710: END
711: if (ref($can_request) eq 'HASH') {
712: foreach my $item (keys(%{$can_request})) {
713: $js .= "
714: $item = 1;
715: ";
716: }
717: }
718: my %lt = &Apache::lonlocal::texthash(
719: official => 'You are not permitted to request creation of an official course in this domain.',
720: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
721: community => 'You are not permitted to request creation of a community this domain.',
722: all => 'You must choose a specific course type when making a new course request.\\n\"All types\" is not allowed.',
723: );
724: $js .= <<END;
725: if (crschoice == 'official') {
726: if (official != 1) {
727: alert("$lt{'official'}");
728: return false;
729: }
730: } else {
731: if (crschoice == 'unofficial') {
732: if (unofficial != 1) {
733: alert("$lt{'unofficial'}");
734: return false;
735: }
736: } else {
737: if (crschoice == 'community') {
738: if (community != 1) {
739: alert("$lt{'community'}");
740: return false;
741: }
742: } else {
743: if (actionchoice == 'new') {
744: alert("$lt{'all'}");
745: return false;
746: }
747: }
748: }
749: }
750: return true;
751: }
752: END
753: my ($pagetitle,$pageinfo,$domaintitle);
754: if (ref($can_request) eq 'HASH') {
755: if (($can_request->{'official'}) || ($can_request->{'unofficial'})) {
756: if ($can_request->{'community'}) {
757: $pagetitle = 'Course/Community Requests';
758: $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
759: $domaintitle = &mt('Course/Community Domain');
760: } else {
761: $pagetitle = 'Course Requests';
762: $pageinfo = &mt('Request creation of a new course, or review your pending course requests.');
763: $domaintitle = &mt('Course Domain');
764: }
765: } elsif ($can_request->{'community'}) {
766: $pagetitle = 'Community Requests';
767: $pageinfo = &mt('Request creation of a new course, or review your pending requests.');
768: $domaintitle = &mt('Community Domain');
769: } else {
770: $pagetitle = 'Course/Community Requests';
771: $pageinfo = &mt('You do not have rights to request creation of courses in this domain; please choose a different domain.');
772: $domaintitle = &mt('Course/Community Domain');
773: }
774: }
775: my @incdoms;
776: if (ref($request_domains) eq 'HASH') {
777: foreach my $item (keys(%{$request_domains})) {
778: if (ref($request_domains->{$item}) eq 'ARRAY') {
779: foreach my $possdom (@{$request_domains->{$item}}) {
780: unless(grep(/^\Q$possdom\E$/,@incdoms)) {
781: push(@incdoms,$possdom);
782: }
783: }
784: }
785: }
786: }
787: $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
788: '<p>'.$pageinfo.'</p>'.
789: '<div>'.
790: &Apache::lonhtmlcommon::start_pick_box().
791: &Apache::lonhtmlcommon::row_title($domaintitle).
792: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
793: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,\@incdoms));
794: if (!$onchange) {
795: $r->print(' <input type="submit" name="godom" value="'.
796: &mt('Change').'" />');
797: }
798: unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) {
799: $r->print(&Apache::lonhtmlcommon::row_closure(1)."\n".
800: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
801: &Apache::loncommon::end_page());
802: return;
803: }
804: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
805: my $formname = 'requestcrs';
806: my $nexttext = &mt('Next');
807: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
808: <form name="mainmenu_action" method="post" action="">
809: <select size="1" name="action" >
810: <option value="new">'.&mt('New request').'</option>
811: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
812: <option value="log">'.&mt('View request history').'</option>
813: </select></form>'.
814: &Apache::lonhtmlcommon::row_closure().
815: &Apache::lonhtmlcommon::row_title(&mt('Type')).'
816: <form name="mainmenu_coursetype" method="post" action="">
817: <select size="1" name="crstype">');
818: if (ref($can_request) eq 'HASH') {
819: if (keys(%{$can_request}) > 1) {
820: $r->print(' <option value="any">'.&mt('All types').'</option>');
821: }
822: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
823: foreach my $type (@{$types}) {
824: next unless($can_request->{$type});
825: my $selected = '';
826: if ($env{'form.crstype'} eq '') {
827: if ($type eq 'official') {
828: $selected = ' selected="selected"';
829: }
830: } else {
831: if ($type eq $env{'form.crstype'}) {
832: $selected = ' selected="selected"';
833: }
834: }
835: $r->print('<option value="'.$type.'"'.$selected.'>'.&mt($typename->{$type}).
836: '</option>'."\n");
837: }
838: }
839: }
840: $r->print('</select></form>'."\n".
841: &Apache::lonhtmlcommon::row_closure(1)."\n".
842: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
843: '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n".
844: '<input type="hidden" name="state" value="crstype" />'."\n".
845: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
846: '<input type="hidden" name="crstype" value="" />'."\n".
847: '<input type="hidden" name="action" value="" />'."\n".
848: '<input type="button" name="next" value="'.$nexttext.
849: '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
850: '</form></div>');
851: $r->print(&Apache::loncommon::end_page());
852: return;
853: }
854:
855: sub request_administration {
856: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
857: $newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist,
858: $uname,$udom) = @_;
859: my $js;
860: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
861: $js = <<END;
862:
863: function nextPage(formname,nextstate) {
864: formname.state.value= nextstate;
865: formname.submit();
866: }
867:
868: END
869: }
870: if (($action eq 'new') || ($action eq 'view')) {
871: $js .= <<END;
872:
873: function backPage(formname,prevstate) {
874: formname.state.value = prevstate;
875: formname.submit();
876: }
877:
878: END
879: }
880: if ($action eq 'new') {
881: my $jsextra;
882: if (($state eq 'courseinfo') || ($state eq 'codepick')) {
883: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
884: } elsif ($state eq 'enrollment') {
885: if (($env{'form.crstype'} eq 'official') &&
886: (&Apache::lonnet::auto_run('',$dom))) {
887: $js .= "\n".§ion_check_javascript()."\n".&enrollment_lcsec_js();
888: }
889: } elsif ($state eq 'personnel') {
890: $js .= "\n".§ion_check_javascript()."\n".&personnel_lcsec_js();
891: }
892: my $title;
893: if ($env{'form.crstype'} eq 'community') {
894: $title = 'Request a community';
895: } else {
896: $title = 'Request a course';
897: }
898: $r->print(&header($title,$js.$jscript,$loaditems,$jsextra).$crumb);
899: &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
900: $codechk,$checkedcode,$description,$invalidcrosslist);
901: } elsif ($action eq 'view') {
902: my $jsextra;
903: my $formname = 'requestcrs';
904: my $prev = $states->{$action}[$page-1];
905: my $next = $states->{$action}[$page+1];
906: if ($state eq 'pick_request') {
907: $next = $states->{$action}[$page+1];
908: $jsextra = &viewrequest_javascript($formname,$next);
909: } elsif ($state eq 'details') {
910: $jsextra = &viewdetails_javascript($formname);
911:
912: } elsif ($state eq 'cancel') {
913: $jsextra = &viewcancel_javascript($formname);
914: }
915: my $title;
916: if ($env{'form.crstype'} eq 'community') {
917: $title = 'Manage community requests';
918: } else {
919: $title = 'Manage course requests';
920: }
921: $r->print(&header($title,$js.$jscript.$jsextra,$loaditems).$crumb);
922: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
923: if ($state eq 'pick_request') {
924: my $title;
925: if ($env{'form.crstype'} eq 'community') {
926: $title = &mt('Pending community requests');
927: } elsif ($env{'form.crstype'} eq 'official') {
928: $title = &mt('Pending requests for official courses');
929: } elsif ($env{'form.crstype'} eq 'unofficial') {
930: $title = &mt('Pending requests for unofficial courses');
931: } else {
932: $title = &mt('Pending course/community requests');
933: }
934: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
935: &print_request_status($dom,$action).'</form></div>');
936: } elsif ($state eq 'details') {
937: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
938: my $origcnum = $env{'form.cnum'};
939: if ($origcnum eq '') {
940: $origcnum = $env{'form.origcnum'};
941: }
942: if ($env{'form.crstype'} eq 'official') {
943: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
944: \%cat_order,\@code_order);
945: }
946: my $title;
947: if ($env{'form.crstype'} eq 'community') {
948: $title = &mt('Community Request Details');
949: } else {
950: $title = &mt('Course Request Details');
951: }
952: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
953: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
954: \@code_order)."\n".
955: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
956: my @excluded = &get_excluded_elements($dom,$states,'new','review');
957: push(@excluded,'origcnum');
958: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
959: my $other = 'modify';
960: my %navtxt = &Apache::lonlocal::texthash (
961: prev => 'Back',
962: other => 'Modify Request',
963: next => 'Cancel Request',
964: );
965: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
966: $navtxt{'next'},$state,$other,$navtxt{'other'});
967: $r->print('</form>');
968: } elsif ($state eq 'cancel') {
969: my $title;
970: if ($env{'form.crstype'} eq 'community') {
971: $title = &mt('Cancel community request');
972: } else {
973: $title = &mt('Cancel course request');
974: }
975: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
976: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
977: $output);
978: my @excluded = &get_excluded_elements($dom,$states,'view','cancel');
979: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
980: my %navtxt = &Apache::lonlocal::texthash (
981: prev => 'Back',
982: next => 'Confirm Cancellation',
983: );
984: if ($result eq 'ok') {
985: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
986: $navtxt{'next'},$state);
987: } else {
988: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
989: '',$state);
990: }
991: $r->print('</form>');
992: } elsif ($state eq 'removal') {
993: my $cnum = $env{'form.origcnum'};
994: my $statuskey = 'status:'.$dom.':'.$cnum;
995: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
996: $env{'user.domain'},$env{'user.name'});
997: my $currstatus = $userreqhash{$statuskey};
998: my ($result,$error);
999: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
1000: my %status = (
1001: $statuskey => 'cancelled',
1002: );
1003: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
1004: if ($statusresult eq 'ok') {
1005: my $delresult =
1006: &Apache::lonnet::del_dom('courserequestqueue',
1007: [$cnum.'_'.$currstatus],$dom);
1008: if ($delresult eq 'ok') {
1009: $result = 'ok';
1010: } else {
1011: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
1012: }
1013: } else {
1014: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
1015: }
1016: } else {
1017: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
1018: }
1019: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
1020: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
1021: '<input type="hidden" name="action" value="'.$action.'" />'."\n".
1022: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
1023: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
1024: if ($result eq 'ok') {
1025: if ($env{'form.crstype'} eq 'community') {
1026: $r->print(&mt('Your community request has been cancelled.'));
1027: } else {
1028: $r->print(&mt('Your course request has been cancelled.'));
1029: }
1030: } else {
1031: $r->print('<div class="LC_error">'.
1032: &mt('The request cancellation process was not complete.').
1033: '<br />'.$error.'</div>');
1034: }
1035: $r->print('</form>');
1036: }
1037: } elsif ($action eq 'display') {
1038: my $formname = 'requestcrs';
1039: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1040: if ($env{'form.crstype'} eq 'official') {
1041: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1042: \%cat_order,\@code_order);
1043: }
1044: my ($title,$header);
1045: if ($env{'form.crstype'} eq 'community') {
1046: $title = 'Community Request';
1047: $header = &mt('Community Request');
1048: } else {
1049: $title = 'Course Request';
1050: $header = &mt('Course Request');
1051: }
1052: $r->print(&header($title,'','','',{ 'only_body' => 1}).
1053: $crumb."\n".'<h3>'.$header.'</h3>'.
1054: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1055: \@code_order,$uname,$udom)."\n".'</div>'.
1056: &close_popup_form());
1057: }
1058: $r->print(&Apache::loncommon::end_page());
1059: return;
1060: }
1061:
1062: sub enrollment_lcsec_js {
1063: my %alerts = §ion_check_alerts();
1064: my $secname = $alerts{'badsec'};
1065: my $secnone = $alerts{'reserved'};
1066: my $output = '
1067: function validateEnrollSections(formname,nextstate) {
1068: var badsectotal = 0;
1069: var reservedtotal = 0;
1070: var secTest = "";
1071: ';
1072: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1073: $output .= "
1074: var selSec = 0;
1075: for (var j=0; j<document.requestcrs.sec_".$i.".length; j++) {
1076: if (document.requestcrs.sec_".$i."[j].checked) {
1077: selSec = document.requestcrs.sec_".$i."[j].value;
1078: }
1079: if (selSec == 1) {
1080: secTest = validsection(document.requestcrs.loncapasec_".$i.");
1081: if (secTest == 'badsec') {
1082: badsectotal++;
1083: }
1084: if (secTest == 'reserved') {
1085: reservedtotal++;
1086: }
1087: }
1088: }
1089: ";
1090: }
1091: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1092: $output .= "
1093: if (document.requestcrs.crosslist_".$i.".checked) {
1094: secTest = validsection(document.requestcrs.crosslist_".$i."_lcsec);
1095: if (secTest == 'badsec') {
1096: badsectotal++;
1097: }
1098: if (secTest == 'reserved') {
1099: reservedtotal++;
1100: }
1101: }
1102: ";
1103: }
1104: $output .= "
1105: if (badsectotal>0) {
1106: alert('$secname');
1107: return false;
1108: }
1109: if (reservedtotal>0) {
1110: alert('$secnone');
1111: return false;
1112: }
1113: formname.state.value= nextstate;
1114: formname.submit();
1115: return;
1116: }
1117: ";
1118: return $output;
1119: }
1120:
1121: sub personnel_lcsec_js {
1122: my %alerts = §ion_check_alerts();
1123: my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'};
1124: my $secnone = $alerts{'reserved'};
1125: my $output = '
1126: function validatePersonnelSections(formname,nextstate) {
1127: var badsectotal = 0;
1128: var reservedtotal = 0;
1129: var secTest = "";
1130: ';
1131: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1132: $output .= "
1133: if (document.requestcrs.person_".$i."_uname.value != '') {
1134: secTest = validsection(document.requestcrs.person_".$i."_newsec,'1');
1135: if (secTest == 'badsec') {
1136: badsectotal++;
1137: }
1138: if (secTest == 'reserved') {
1139: reservedtotal++;
1140: }
1141: }
1142: ";
1143: }
1144: $output .= "
1145: if (badsectotal > 0) {
1146: alert('$secname');
1147: return false;
1148: } else {
1149: if (reservedtotal > 0) {
1150: alert('$secnone');
1151: return false;
1152: }
1153: }
1154: formname.state.value = nextstate;
1155: formname.submit();
1156: return;
1157: }
1158: ";
1159: return $output;
1160: }
1161:
1162: sub section_check_alerts {
1163: my %lt =
1164: &Apache::lonlocal::texthash(
1165: reserved => "You need to change one or more LON-CAPA section names - none is a reserved word in the system, and may not be used.",
1166: badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
1167: separate => 'Separate multiple sections with a comma.'
1168: );
1169: return %lt;
1170: }
1171:
1172: sub section_check_javascript {
1173: return <<"END";
1174: function validsection(field,mult) {
1175: var str = field.value;
1176: var badsec=0;
1177: var reserved=0;
1178: if (window.RegExp) {
1179: var badsecnum=0;
1180: var reservednum=0;
1181: var pattern=/[^a-zA-Z0-9]/;
1182: str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
1183: str = str.replace(/[ ]{2,}/gi," ");
1184: if (mult == '1') {
1185: var sections = new Array();
1186: sections = str.split(/\\s*[\\s,;:]\\s*/);
1187: var i;
1188: for (i=0; i<sections.length; i++) {
1189: if ((sections[i] != '') && (sections[i] != undefined) && (sections[i] != null)) {
1190: if (pattern.test(sections[i])) {
1191: badsecnum++;
1192: } else {
1193: if (sections[i] == 'none') {
1194: reservednum++;
1195: }
1196: }
1197: }
1198: }
1199: } else {
1200: if ((str != '') && (str != undefined) && (str != null)) {
1201: if (pattern.test(str)) {
1202: badsecnum++;
1203: } else {
1204: if (str == 'none') {
1205: reservednum++;
1206: }
1207: }
1208: }
1209: }
1210: if (badsecnum > 0) {
1211: return 'badsec';
1212: }
1213: if (reservednum > 0) {
1214: return 'reserved';
1215: }
1216: }
1217: return;
1218: }
1219: END
1220: }
1221:
1222: sub close_popup_form {
1223: my $close= &mt('Close Window');
1224: return << "END";
1225: <p><form name="displayreq" action="" method="post">
1226: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
1227: </form></p>
1228: END
1229: }
1230:
1231: sub get_instcode {
1232: my ($dom) = @_;
1233: my ($instcode,$numtitles);
1234: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1235: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1236: \%cat_order,\@code_order);
1237: $numtitles = scalar(@codetitles);
1238: if (@code_order > 0) {
1239: my $message;
1240: foreach my $item (@code_order) {
1241: $instcode .= $env{'form.instcode_'.$item};
1242: }
1243: }
1244: return ($instcode,$numtitles);
1245: }
1246:
1247: sub print_request_form {
1248: my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1249: $description,$invalidcrosslist) = @_;
1250: my $formname = 'requestcrs';
1251: my ($next,$prev,$message,$output,$codepicker,$crstype);
1252: $prev = $states->{$action}[$page-1];
1253: $next = $states->{$action}[$page+1];
1254: my %navtxt = &Apache::lonlocal::texthash (
1255: prev => 'Back',
1256: next => 'Next',
1257: );
1258: $crstype = $env{'form.crstype'};
1259: $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1260: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
1261: @disallowed);
1262: if ($crstype eq 'official') {
1263: if ($env{'form.instcode'} ne '') {
1264: $instcode = $env{'form.instcode'};
1265: } elsif ($newinstcode ne '') {
1266: $instcode = $newinstcode;
1267: }
1268: if ($checkedcode) {
1269: if ($codechk eq 'valid') {
1270: $message = '<div class="LC_info">'.
1271: &mt('The chosen course category [_1] is valid.','<b>'.
1272: $instcode.'</b>').
1273: '<input type="hidden" name="instcode" value="'.
1274: $instcode.'" /></div>';
1275: } else {
1276: $message = '<div class="LC_warning">'.
1277: &mt('No course was found matching your choice of institutional course category.');
1278: if ($codechk ne '') {
1279: $message .= '<br />'.$codechk;
1280: }
1281: $message .= '</div>';
1282: $prev = 'crstype';
1283: }
1284: $r->print($message);
1285: }
1286: }
1287: if ($prev eq 'crstype') {
1288: if ($crstype eq 'official') {
1289: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1290: \%cat_order,\@code_order);
1291: }
1292: if (@code_order > 0) {
1293: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
1294: \%cat_titles,\%cat_order);
1295: if ($codepicker) {
1296: $r->print(&mt('Specify the course to be created.').
1297: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1298: $codepicker.
1299: &Apache::lonhtmlcommon::end_pick_box().'</div>');
1300: } else {
1301: $next = $states->{$action}[$page+2];
1302: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1303: }
1304: } else {
1305: if ($crstype eq 'official') {
1306: $next = $states->{$action}[$page+2];
1307: }
1308: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1309: }
1310: } elsif ($prev eq 'codepick') {
1311: if ($instcode eq '') {
1312: $prev = $states->{$action}[$page-2];
1313: }
1314: $r->print(&courseinfo_form($dom,$formname,$crstype,$next,$description));
1315: } elsif ($state eq 'enrollment') {
1316: if ($crstype eq 'official') {
1317: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1318: \%cat_order,\@code_order);
1319: }
1320: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
1321: \%cat_titles,\%cat_order,\@code_order,
1322: $invalidcrosslist));
1323: } elsif ($state eq 'personnel') {
1324: $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
1325: } elsif ($state eq 'review') {
1326: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
1327: my $now = time;
1328: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1329: my $personname = $env{'form.person_'.$i.'_uname'};
1330: my $persondom = $env{'form.person_'.$i.'_dom'};
1331: if (($personname =~ /^$match_username$/) &&
1332: ($persondom =~ /^$match_domain$/)) {
1333: if (&Apache::lonnet::domain($persondom)) {
1334: my $personhome =
1335: &Apache::lonnet::homeserver($personname,$persondom);
1336: if ($personhome eq 'no_host') {
1337: if ($persondom ne $dom) {
1338: my $skipuser = 1;
1339: if ($env{'user.role.dc./'.$persondom.'/'}) {
1340: my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
1341: if (((!$start) || ($start < $now)) &&
1342: ((!$end) || ($end > $now))) {
1343: $skipuser = 0;
1344: }
1345: }
1346: if ($skipuser) {
1347: push(@disallowed,$i);
1348: $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
1349: next;
1350: }
1351: }
1352: my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules);
1353: if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) {
1354: my ($allowed,$msg,$authtype,$authparam) =
1355: &check_newuser_rules($persondom,$personname,
1356: \%alerts,\%rulematch,\%inst_results,
1357: \%curr_rules,\%got_rules);
1358: if ($allowed) {
1359: my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom);
1360: if ($usertype eq 'official') {
1361: if ($authtype eq '') {
1362: $authtype = $domdefaults{'auth_def'};
1363: $authparam = $domdefaults{'auth_arg_def'};
1364: }
1365: } elsif ($usertype eq 'unofficial') {
1366: if ($authtype eq '') {
1367: $authtype = 'internal';
1368: $authparam = '';
1369: }
1370: } else {
1371: $authtype = $domdefaults{'auth_def'};
1372: $authparam = $domdefaults{'auth_arg_def'};
1373: }
1374: if (($authtype eq '') ||
1375: (($authtype =~/^krb/) && ($authparam eq ''))) {
1376: push(@disallowed,$i);
1377: $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.','<tt>'.$personname.':'.$persondom.'</tt>');
1378: next;
1379: }
1380: if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
1381: if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
1382: $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
1383: }
1384: if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
1385: $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
1386: }
1387: if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
1388: $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
1389: }
1390: }
1391: } else {
1392: push(@disallowed,$i);
1393: $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1394: }
1395: } else {
1396: push(@disallowed,$i);
1397: $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1398: }
1399: } else {
1400: my %userenv =
1401: &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
1402: if ($env{'form.person_'.$i.'_lastname'} eq '') {
1403: $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
1404: }
1405: if ($env{'form.person_'.$i.'_firstname'} eq '') {
1406: $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
1407: }
1408: if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
1409: $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
1410: }
1411: }
1412: } elsif ($personname ne '') {
1413: push(@disallowed,$i);
1414: $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
1415: }
1416: } elsif ($personname ne '') {
1417: push(@disallowed,$i);
1418: $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
1419: }
1420: }
1421: my $cnum;
1422: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
1423: $cnum = $env{'form.origcnum'};
1424: } else {
1425: my $gentype = 'Course';
1426: if ($crstype eq 'community') {
1427: $gentype = 'Community';
1428: }
1429: $cnum = &Apache::lonnet::generate_coursenum($dom,$gentype);
1430: }
1431: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1432: \%cat_order,\@code_order);
1433: if ($crstype eq 'community') {
1434: $r->print('<h3>'.&mt('Review community request details before submission').'</h3>');
1435: } else {
1436: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>');
1437: }
1438: $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg).
1439: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1440: if ($crstype eq 'community') {
1441: $navtxt{'next'} = &mt('Submit community request');
1442: } else {
1443: $navtxt{'next'} = &mt('Submit course request');
1444: }
1445: } elsif ($state eq 'process') {
1446: if ($crstype eq 'official') {
1447: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1448: \%cat_order,\@code_order);
1449: }
1450: my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles,
1451: \@code_order);
1452: $r->print($result);
1453: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1454: if ($storeresult eq 'ok') {
1455: $r->print('<p><a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1456: &mt('Modify this request').'</a>'.(' 'x4).
1457: '<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1458: }
1459: if (&Apache::loncoursequeueadmin::author_prompt()) {
1460: $r->print('<h3>'.&mt('Access to authoring space').'</h3>'.
1461: '<p>'.
1462: &mt('Although assessment items can be created directly inside a course, such items only use part of the assessment capabilities of LON-CAPA.').
1463: '<br />'.
1464: &mt('By contrast, items created in authoring space, then imported into a course, can use all of the features of the assessment engine.').'</p>'.
1465: '<p>'.&mt('Request authoring space access now?').
1466: '<span class="LC_nobreak"> '.
1467: '<label><input type="radio" name="requestauthor" value="1" />'.&mt('Yes').'</label>'.
1468: (' 'x2).
1469: '<label><input type="radio" name="requestauthor" value="0" checked="checked"/>'.&mt('No').'</label>'.
1470: '</span></p>'.
1471: '<input type="submit" name="newauthor" value="'.&mt('Submit authoring request').'" />'.
1472: '<input type="hidden" name="state" value="reqauthor" />'.
1473: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1474: '<input type="hidden" name="cnum" value="'.$env{'form.cnum'}.'" />'.
1475: '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
1476: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'.
1477: '<input type="hidden" name="disposition" value="'.$storeresult.'" />'.
1478: '<br />');
1479: } elsif ($storeresult eq 'created') {
1480: $r->print('<p><a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1481: }
1482: }
1483: } elsif ($state eq 'reqauthor') {
1484: my ($result,@links);
1485: if ($env{'form.requestauthor'}) {
1486: $r->print(&Apache::loncoursequeueadmin::process_reqauthor(\$result));
1487: if ($result eq 'created') {
1488: my $role = 'au';
1489: my $spec = "$role./$env{'form.showdom'}/";
1490: push(@links,&mt('Enter your authoring space with role: [_1]',
1491: '<a href="/adm/roles?selectrole=1&'.$spec.'=1">'.
1492: &Apache::lonnet::plaintext($role).'</a>'));
1493: }
1494: }
1495: if (($env{'form.disposition'} eq 'created') &&
1496: ($env{'form.cnum'} =~ /^$match_courseid$/) &&
1497: ($env{'form.showdom'} =~ /^$match_domain$/)) {
1498: my ($spec,$area,$role,$type);
1499: my $role = 'cc';
1500: my $spec = "$role./$env{'form.showdom'}/$env{'form.cnum'}";
1501: my $type = 'Course';
1502: if ($env{'form.crstype'} eq 'community') {
1503: $type = 'Community';
1504: }
1505: my $showrole = &Apache::lonnet::plaintext($role,$type);
1506: unshift(@links,&mt('Enter new course with role: [_1]',
1507: '<a href="/adm/roles?selectrole=1&'.$spec.'=1">'.$showrole.'</a>'));
1508: }
1509: if (@links > 1) {
1510: $r->print(&mt('New roles will be listed on your [_1]Roles[_2] page.',
1511: '<a href="/adm/roles">','</a>').' '.&mt('Choose a role:').
1512: '<ul>');
1513: foreach my $link (@links) {
1514: $r->print('<li>'.$link.'</li>');
1515: }
1516: $r->print('</ul>');
1517: } elsif (@links == 1) {
1518: $r->print('<p>'.$links[0].'</p>');
1519: }
1520: }
1521: my @excluded = &get_excluded_elements($dom,$states,$action,$state);
1522: if ($state eq 'personnel') {
1523: push(@excluded,'persontotal');
1524: }
1525: if ($state eq 'review') {
1526: if (@disallowed > 0) {
1527: my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
1528: my @currsecs = ¤t_lc_sections();
1529: if (@currsecs) {
1530: push(@items,'sec');
1531: }
1532: my $count = 0;
1533: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1534: unless ($env{'form.person_'.$i.'_uname'} eq '') {
1535: if (grep(/^$i$/,@disallowed)) {
1536: foreach my $item (@items) {
1537: $env{'form.person_'.$i.'_'.$item} = '';
1538: }
1539: } else {
1540: foreach my $item (@items) {
1541: $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
1542: }
1543: }
1544: }
1545: $count ++;
1546: }
1547: $env{'form.persontotal'} = $count;
1548: }
1549: }
1550: if ($state eq 'enrollment') {
1551: push(@excluded,('sectotal','crosslisttotal'));
1552: }
1553: if (($state eq 'process') || ($state eq 'reqauthor')) {
1554: $r->print('</form>');
1555: } else {
1556: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1557: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1558: $navtxt{'next'},$state);
1559: }
1560: return;
1561: }
1562:
1563: sub get_usertype {
1564: my ($persondom,$personname,$curr_rules,$got_rules) = @_;
1565: my ($rules,$ruleorder) =
1566: &Apache::lonnet::inst_userrules($persondom,'username');
1567: my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1568: $rules,$curr_rules,$got_rules);
1569: return $usertype;
1570: }
1571:
1572: sub check_newuser_rules {
1573: my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
1574: $got_rules) = @_;
1575: my $allowed = 1;
1576: my $newuser = 1;
1577: my ($checkhash,$userchkmsg,$authtype,$authparam);
1578: my $checks = { 'username' => 1 };
1579: $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
1580: &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
1581: $inst_results,$curr_rules,$got_rules);
1582: if (ref($alerts->{'username'}) eq 'HASH') {
1583: if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
1584: my $domdesc =
1585: &Apache::lonnet::domain($persondom,'description');
1586: if ($alerts->{'username'}{$persondom}{$personname}) {
1587: if (ref($curr_rules->{$persondom}) eq 'HASH') {
1588: $userchkmsg =
1589: &Apache::loncommon::instrule_disallow_msg('username',
1590: $domdesc,1).
1591: &Apache::loncommon::user_rule_formats($persondom,
1592: $domdesc,$curr_rules->{$persondom}{'username'},
1593: 'username');
1594: }
1595: $allowed = 0;
1596: }
1597: }
1598: }
1599: if ($allowed) {
1600: if (ref($rulematch) eq 'HASH') {
1601: if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') {
1602: my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'};
1603: my ($rules,$ruleorder) =
1604: &Apache::lonnet::inst_userrules($persondom,'username');
1605: if (ref($rules) eq 'HASH') {
1606: if (ref($rules->{$matchedrule}) eq 'HASH') {
1607: $authtype = $rules->{$matchedrule}{'authtype'};
1608: $authparam = $rules->{$matchedrule}{'authparm'};
1609: }
1610: }
1611: }
1612: }
1613: }
1614: return ($allowed,$userchkmsg,$authtype,$authparam);
1615: }
1616:
1617: sub get_excluded_elements {
1618: my ($dom,$states,$action,$state) = @_;
1619: my @excluded = ('counter');
1620: my %elements = &form_elements($dom);
1621: if (ref($states) eq 'HASH') {
1622: if (ref($states->{$action}) eq 'ARRAY') {
1623: my @items = @{$states->{$action}};
1624: my $numitems = scalar(@items);
1625: if ($numitems) {
1626: for (my $i=$numitems-1; $i>=0; $i--) {
1627: if (ref($elements{$action}) eq 'HASH') {
1628: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1629: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1630: push(@excluded,$key);
1631: }
1632: }
1633: }
1634: last if ($items[$i] eq $state);
1635: }
1636: }
1637: }
1638: }
1639: if (grep(/^instcode_/,@excluded)) {
1640: push(@excluded,'instcode');
1641: }
1642: return @excluded;
1643: }
1644:
1645: sub print_enrollment_menu {
1646: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1647: $invalidcrosslist) =@_;
1648: my ($sections,$autoenroll,$access_dates,$output,$hasauto);
1649: my $starttime = time;
1650: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1651:
1652: my %accesstitles = (
1653: 'start' => 'Default start access',
1654: 'end' => 'Default end access',
1655: );
1656: my %enrolltitles = (
1657: 'start' => 'Start auto-enrollment',
1658: 'end' => 'End auto-enrollment',
1659: );
1660: if ($env{'form.crstype'} eq 'official') {
1661: if (&Apache::lonnet::auto_run('',$dom)) {
1662: $output = &show_invalid_crosslists($invalidcrosslist);
1663: my ($section_form,$crosslist_form);
1664: if ($instcode ne '') {
1665: $section_form = &inst_section_selector($dom,$instcode);
1666: if ($section_form eq '') {
1667: my $sectotal = $env{'form.sectotal'};
1668: if (!$sectotal) {
1669: $sectotal = 1;
1670: }
1671: if ($env{'form.addsection'}) {
1672: $sectotal ++;
1673: }
1674: for (my $i=0; $i<$sectotal; $i++) {
1675: $section_form .= §ions_form($dom,$instcode,$i);
1676: }
1677: if ($section_form) {
1678: $section_form .=
1679: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1680: '<input name="sectotal" type="hidden" value="'.$sectotal.'" />'.
1681: '<input name="addsection" type="checkbox" value="'.$sectotal.'"'.
1682: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1683: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1684: }
1685: }
1686: }
1687: if ($section_form) {
1688: $sections = &Apache::lonhtmlcommon::row_headline().
1689: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
1690: ' '.&mt('Sections for auto-enrollment').'</h3>'.
1691: &Apache::lonhtmlcommon::row_closure(1).
1692: $section_form;
1693: }
1694: my $crosslisttotal = $env{'form.crosslisttotal'};
1695: if (!$crosslisttotal) {
1696: $crosslisttotal = 1;
1697: }
1698: if ($env{'form.addcrosslist'}) {
1699: $crosslisttotal ++;
1700: }
1701: for (my $i=0; $i<$crosslisttotal; $i++) {
1702: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1703: $cat_titles,$cat_order,$i);
1704: }
1705: if ($crosslist_form) {
1706: $crosslist_form .=
1707: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1708: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1709: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1710: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1711: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1712: $sections .= &Apache::lonhtmlcommon::row_headline.
1713: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Crosslist').' '.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1714: &Apache::lonhtmlcommon::row_closure(1).
1715: $crosslist_form;
1716: }
1717: $hasauto = 1;
1718: $autoenroll =
1719: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')).
1720: '<span class="LC_nobreak"><label>'.
1721: '<input type="radio" name="autoadds" value="1">'.
1722: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1723: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1724: &mt('No').'</label></span>'.
1725: &Apache::lonhtmlcommon::row_closure(1).
1726: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')).
1727: '<span class="LC_nobreak"><label>'.
1728: '<input type="radio" name="autodrops" value="1">'.
1729: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1730: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1731: &mt('No').'</label></span>'.
1732: &Apache::lonhtmlcommon::row_closure(1).
1733: &date_setting_table($starttime,$endtime,$formname,'enroll',
1734: $hasauto,%enrolltitles);
1735: }
1736: }
1737: my $access_dates =
1738: &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
1739: %accesstitles);
1740: $output .= &Apache::lonhtmlcommon::start_pick_box();
1741: if ($sections) {
1742: $output .= $sections;
1743: }
1744: if ($autoenroll) {
1745: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1746: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1747: &Apache::lonhtmlcommon::row_closure(1).
1748: $autoenroll;
1749: }
1750: if ($access_dates) {
1751: my $header = &mt('Access dates for students');
1752: if ($env{'form.crstype'} eq 'community') {
1753: $header = &mt('Access dates for community members');
1754: }
1755: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1756: '<h3>'.$header.'</h3>'.
1757: &Apache::lonhtmlcommon::row_closure(1).
1758: $access_dates
1759: }
1760: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1761: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1762: }
1763:
1764: sub show_invalid_crosslists {
1765: my ($invalidcrosslist) = @_;
1766: my $output;
1767: if (ref($invalidcrosslist) eq 'ARRAY') {
1768: if (@{$invalidcrosslist} > 0) {
1769: $output = '<div class="LC_warning">'.
1770: &mt('The following crosslisted courses were invalid:').'<ul>';
1771: foreach my $item (@{$invalidcrosslist}) {
1772: $output .= '<li>'.$item.'</li>';
1773: }
1774: $output .= '</ul></div><br />';
1775: }
1776: }
1777: return $output;
1778: }
1779:
1780:
1781: sub inst_section_selector {
1782: my ($dom,$instcode) = @_;
1783: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1784: my $sectotal = scalar(@sections);
1785: my $output;
1786: if ($sectotal) {
1787: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1788: &Apache::loncommon::start_data_table().
1789: &Apache::loncommon::start_data_table_row().
1790: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1791: 'value="'.$sectotal.'" /></th>'.
1792: '<th>'.&mt('Institutional Section').'</th>'.
1793: '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
1794: ' '.&mt('LON-CAPA section').'</th>'.
1795: &Apache::loncommon::end_data_table_row();
1796: for (my $i=0; $i<@sections; $i++) {
1797: my $colflag = $i%2;
1798: my $secon = ' checked="checked"';
1799: my $secoff = '';
1800: if ($env{'form.origcnum'}) {
1801: $secoff = $secon;
1802: $secon='';
1803: }
1804: $output .= &Apache::loncommon::start_data_table_row().
1805: '<td><label><input type="radio" name="sec_'.$i.
1806: '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
1807: (' 'x2).'<label><input type="radio" name="sec_'.$i.
1808: '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
1809: '<td align="center">'.$sections[$i].
1810: '<input type="hidden" name="secnum_'.$i.'" value="'.
1811: $sections[$i].'" /></td>'.
1812: '<td><input type="text" size="10" name="loncapasec_'.$i.
1813: '" value="'.$sections[$i].'" /></td>'.
1814: &Apache::loncommon::end_data_table_row();
1815: }
1816: $output .= &Apache::loncommon::end_data_table().
1817: &Apache::lonhtmlcommon::row_closure();
1818: }
1819: return $output;
1820: }
1821:
1822: sub date_setting_table {
1823: my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_;
1824: my ($perpetual,$table);
1825: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1826: $starttime,'','','',1,'','','',1);
1827: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1828: $endtime,'','','',1,'','','',1);
1829: my $closure = '';
1830: if ($prefix eq 'access') {
1831: $perpetual = ' <span class="LC_nobreak"><label>'.
1832: '<input type="checkbox" name="no_end_date" />'.
1833: &mt('No end date').'</label></span>';
1834: $closure = '1';
1835: }
1836:
1837: my %help_item = (
1838: access => {
1839: start => 'Course_Request_Access_Start',
1840: end => 'Course_Request_Access_End',
1841: },
1842: enroll => {
1843: start => 'Course_Request_Enroll_Start',
1844: end => 'Course_Request_Enroll_End',
1845: },
1846: );
1847: if ($hasauto) {
1848: $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
1849: $help_item{'access'}{'end'} = 'Course_Request_RegAccess_End';
1850: }
1851:
1852: $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
1853: ' '.&mt($datetitles{'start'})).$startform.
1854: &Apache::lonhtmlcommon::row_closure(1).
1855: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
1856: ' '.&mt($datetitles{'end'})).$endform.$perpetual.
1857: &Apache::lonhtmlcommon::row_closure($closure);
1858: return $table;
1859: }
1860:
1861: sub print_personnel_menu {
1862: my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
1863: my $output;
1864: if ($crstype eq 'official') {
1865: if (&Apache::lonnet::auto_run('',$dom)) {
1866: $output .= &show_invalid_crosslists($invalidcrosslist);
1867: }
1868: }
1869: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1870: my $persontotal = $env{'form.persontotal'};
1871: if ((!defined($persontotal)) || (!$persontotal)) {
1872: $persontotal = 1;
1873: }
1874: if ($env{'form.addperson'}) {
1875: $persontotal ++;
1876: }
1877: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1878:
1879: my $type = 'Course';
1880: if ($crstype eq 'community') {
1881: $type = 'Community';
1882: }
1883: my $roleoptions;
1884: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1885: foreach my $role (@roles) {
1886: my $plrole = &Apache::lonnet::plaintext($role,$type);
1887: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1888: }
1889: my %customroles=&Apache::lonuserutils::my_custom_roles();
1890: if (keys(%customroles) > 0) {
1891: foreach my $cust (sort(keys(%customroles))) {
1892: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1893: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1894: }
1895: }
1896:
1897: my @currsecs = ¤t_lc_sections();
1898:
1899: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1900: if (@currsecs) {
1901: my $existsize = scalar(@currsecs);
1902: if ($existsize > 3) {
1903: $existsize = 3;
1904: }
1905: if ($existsize > 1) {
1906: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1907: }
1908: @currsecs = sort { $a <=> $b } (@currsecs);
1909: $existtitle = &mt('Official').': ';
1910: $existops = '<option value="">'.&mt('None').'</option>';
1911: foreach my $sec (@currsecs) {
1912: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1913: }
1914: $seccolspan = ' colspan="2"';
1915: $newtitle = &mt('Other').': ';
1916: }
1917:
1918: if ($persontotal) {
1919: my %lt = &Apache::lonlocal::texthash(
1920: community => 'Requestor is automatically assigned Coordinator role.',
1921: official => 'Requestor is automatically assigned Course Coordinator role.',
1922: );
1923: $lt{'unofficial'} = $lt{'official'};
1924: $output .= &Apache::lonhtmlcommon::row_headline().
1925: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
1926: }
1927: for (my $i=0; $i<$persontotal; $i++) {
1928: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1929: my $linkargstr = join("','",@linkargs);
1930: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1931: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1932: "'person_".$i."_hidedom','person_".$i."_uname'".');';
1933: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1934: 1,$onchange).
1935: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1936: my %form_elems;
1937: foreach my $item (@items) {
1938: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1939: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1940: 'value="" readonly="readonly" />';
1941: }
1942: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1943: $roleoptions.'</select>';
1944: my $sectionselector;
1945: if (@currsecs) {
1946: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1947: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1948: }
1949: $sectionselector .= $newtitle.
1950: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1951: my $usersrchlinktxt = &mt('Search for user');
1952: my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1953: $usersrchlinktxt);
1954: my $userchklinktxt = &mt('Check username');
1955: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1956: $userchklinktxt,'checkusername');
1957: $output .=
1958: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
1959: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
1960: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
1961: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
1962: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
1963: '</tr>'."\n".'<tr>'.
1964: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1965: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1966: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1967: '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
1968: '<td'.$seccolspan.' align="center" valign="top">'.
1969: &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1970: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
1971: }
1972: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1973: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
1974: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1975: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1976: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1977: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1978: if ($crstype eq 'community') {
1979: $output .= '<p>'.&mt('You may also add users later, once the community has been created, by using the "Manage community users" link, accessible from the "Main Menu".').'</p>';
1980: } else {
1981: $output .= '<p>'.&mt('You may also add users later, once the course has been created, by using the "Manage course users" link, accessible from the "Main Menu".').'</p>';
1982: }
1983: return $output;
1984: }
1985:
1986: sub current_lc_sections {
1987: my @currsecs;
1988: if ($env{'form.sectotal'}) {
1989: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1990: if ($env{'form.sec_'.$i}) {
1991: if (defined($env{'form.loncapasec_'.$i})) {
1992: my $lcsec = $env{'form.loncapasec_'.$i};
1993: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
1994: push(@currsecs,$lcsec);
1995: }
1996: }
1997: }
1998: }
1999: }
2000: return @currsecs;
2001: }
2002:
2003: sub sorted_request_history {
2004: my ($dom,$action,$curr_req) = @_;
2005: my ($after,$before,$statusfilter,$crstypefilter);
2006: if ($env{'form.status'} ne '') {
2007: $statusfilter = $env{'form.status'};
2008: }
2009: if ($env{'form.crstype'} ne '') {
2010: $crstypefilter = $env{'form.crstype'};
2011: }
2012: if (ref($curr_req) eq 'HASH') {
2013: $after = $curr_req->{'requested_after_date'},
2014: $before = $curr_req->{'requested_before_date'};
2015: $statusfilter = $curr_req->{'status'};
2016: $crstypefilter = $curr_req->{'crstype'};
2017: }
2018: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
2019: $env{'user.name'},'^status:'.$dom);
2020: my %queue_by_date;
2021: my ($types,$typenames) = &Apache::loncommon::course_types();
2022: foreach my $key (keys(%statusinfo)) {
2023: if ($action eq 'view') {
2024: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
2025: } else {
2026: next unless (($statusfilter eq 'any') ||
2027: ($statusfilter eq $statusinfo{$key}));
2028: }
2029: (undef,my($cdom,$cnum)) = split(':',$key);
2030: next if ($cdom ne $dom);
2031: my $requestkey = $cdom.'_'.$cnum;
2032: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2033: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2034: $env{'user.domain'},$env{'user.name'});
2035: my $entry;
2036: my $reqtime = $history{'reqtime'};
2037: my $lastupdate = $history{'timestamp'};
2038: my $crstype = $history{'crstype'};
2039: my $disposition = $history{'disposition'};
2040: my $status = $history{'status'};
2041: if ($action eq 'view') {
2042: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
2043: } else {
2044: next if (($reqtime < $after) || ($reqtime > $before));
2045: }
2046: next unless (($crstypefilter eq 'any') ||
2047: ($crstypefilter eq $crstype));
2048: if ($action eq 'view') {
2049: next unless (($disposition eq 'approval') ||
2050: ($disposition eq 'pending'));
2051: }
2052: if (ref($history{'details'}) eq 'HASH') {
2053: $entry = $requestkey.':'.$crstype.':'.
2054: &escape($history{'details'}{'cdescr'});
2055: if ($action eq 'log') {
2056: $entry .= ':'.$lastupdate.':';
2057: if ($statusinfo{$key} ne '') {
2058: $entry .= $statusinfo{$key};
2059: } elsif ($status ne '') {
2060: $entry .= $status;
2061: } else {
2062: $entry .= $disposition;
2063: }
2064: }
2065: if ($crstype eq 'official') {
2066: $entry .= ':'.&escape($history{'details'}{'instcode'});
2067: }
2068: }
2069: if ($entry ne '') {
2070: if (exists($queue_by_date{$reqtime})) {
2071: if (ref($queue_by_date{$reqtime}) eq 'ARRAY') {
2072: push(@{$queue_by_date{$reqtime}},$entry);
2073: }
2074: } else {
2075: @{$queue_by_date{$reqtime}} = ($entry);
2076: }
2077: }
2078: }
2079: }
2080: return %queue_by_date;
2081: }
2082:
2083: sub print_request_status {
2084: my ($dom,$action) = @_;
2085: my %queue_by_date = &sorted_request_history($dom,$action);
2086: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
2087: my $formname = 'requestcrs';
2088: my ($types,$typenames) = &Apache::loncommon::course_types();
2089: my $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
2090:
2091: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
2092: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
2093: '<input type="hidden" name="showdom" value="" />'."\n".
2094: '<input type="hidden" name="cnum" value="" />'."\n";
2095: if (@sortedtimes > 0) {
2096: my $desctitle;
2097: if ($env{'form.crstype'} eq 'any') {
2098: $desctitle = &mt('Course/Community Description')
2099: } elsif ($env{'form.crstype'} eq 'community') {
2100: $desctitle = &mt('Community Description')
2101: } else {
2102: $desctitle = &mt('Course Description');
2103: }
2104: $output .= &Apache::loncommon::start_data_table().
2105: &Apache::loncommon::start_data_table_header_row().
2106: '<th>'.&mt('Action').'</th>'.
2107: '<th>'.$desctitle.'</th>'.
2108: '<th>'.&mt('Domain').'</th>';
2109: if ($env{'form.crstype'} eq 'any') {
2110: $output .= '<th>'.&mt('Type').'</th>';
2111: }
2112: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
2113: $output .= '<th>'.&mt('Institutional Code').'</th>';
2114: }
2115: $output .= '<th>'.&mt('Date requested').'</th>'.
2116: &Apache::loncommon::end_data_table_header_row();
2117: my $count = 0;
2118: foreach my $item (@sortedtimes) {
2119: my $showtime = &Apache::lonlocal::locallocaltime($item);
2120: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2121: foreach my $request (sort(@{$queue_by_date{$item}})) {
2122: my ($key,$type,$desc,$instcode) = split(':',$request);
2123: my ($cdom,$cnum) = split('_',$key);
2124: $output .= &Apache::loncommon::start_data_table_row().
2125: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
2126: '<td>'.&unescape($desc).'</td>'.
2127: '<td>'.$cdom.'</td>';
2128: if ($env{'form.crstype'} eq 'any') {
2129: my $typename;
2130: if (ref($typenames) eq 'HASH') {
2131: $typename = &mt($typenames->{$type});
2132: }
2133: if ($typename eq '') {
2134: $typename = &mt('Unknown type');
2135: }
2136: $output .= '<td>'.$typename.'</td>';
2137: }
2138: if (($env{'form.crstype'} eq 'any') ||
2139: ($env{'form.crstype'} eq 'official')) {
2140: my $showinstcode;
2141: if ($type eq 'official') {
2142: $showinstcode = &unescape($instcode);
2143: } else {
2144: $showinstcode = &mt('Not applicable');
2145: }
2146: $output .= '<td>'.$showinstcode.'</td>';
2147: }
2148: $output .= '<td>'.$showtime.'</td>'.
2149: &Apache::loncommon::end_data_table_row();
2150: }
2151: }
2152: }
2153: $output .= &Apache::loncommon::end_data_table();
2154: } else {
2155: if ($env{'form.crstype'} eq 'any') {
2156: $output .= '<div>'.&mt('You have no matching course or community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'</div>';
2157: } elsif ($env{'form.crstype'} eq 'community') {
2158: $output .= '<div>'.&mt('You have no matching community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'</div>';
2159: } else {
2160: $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>';
2161: }
2162: }
2163: $output .= '
2164: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
2165: return $output;
2166: }
2167:
2168: sub print_cancel_request {
2169: my ($dom,$cnum) = @_;
2170: my $requestkey = $dom.'_'.$cnum;
2171: my ($result,$output);
2172: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2173: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2174: $env{'user.domain'},$env{'user.name'});
2175: my $timestamp = $history{'reqtime'};
2176: my $crstype = $history{'crstype'};
2177: my $status = $history{'status'};
2178: if (($status eq 'cancelled') || ($status eq 'created')) {
2179: if ($status eq 'cancelled') {
2180: $output = &mt('This request has already been cancelled.');
2181: } elsif ($status eq 'created') {
2182: $output = &mt('This request has already been processed, and a course created.');
2183: }
2184: $output = &mt('No further action will be taken');
2185: } elsif (ref($history{'details'}) eq 'HASH') {
2186: my ($types,$typename) = &Apache::loncommon::course_types();
2187: my $showtype = $crstype;
2188: if (defined($typename->{$crstype})) {
2189: $showtype = $typename->{$crstype};
2190: }
2191: $output = '<p>'.&Apache::loncommon::start_data_table().
2192: &Apache::loncommon::start_data_table_header_row().
2193: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
2194: '<th>'.&mt('Type').'</th>'.
2195: &Apache::loncommon::end_data_table_header_row().
2196: &Apache::loncommon::start_data_table_row().
2197: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
2198: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
2199: '<td>'.$showtype.'</td>'.
2200: &Apache::loncommon::end_data_table_row().
2201: &Apache::loncommon::end_data_table().
2202: '<br /><div class="LC_warning">';
2203: if ($crstype eq 'community') {
2204: $output .= &mt('Cancelling the request will remove it from the queue of pending community requests').'</div>';
2205: } else {
2206: $output .= &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
2207: }
2208: $result = 'ok';
2209: } else {
2210: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
2211: }
2212: } else {
2213: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
2214: }
2215: return ($result,$output);
2216: }
2217:
2218: sub viewrequest_javascript {
2219: my ($formname,$next) = @_;
2220: return <<"ENDJS";
2221:
2222: function chooseRequest(cdom,cnum) {
2223: document.$formname.showdom.value = cdom;
2224: document.$formname.cnum.value = cnum;
2225: nextPage(document.$formname,'$next');
2226: }
2227:
2228: ENDJS
2229: }
2230:
2231: sub viewdetails_javascript {
2232: my ($formname) = @_;
2233: return << "ENDJS";
2234:
2235: function nextPage(formname,nextstate) {
2236: if (nextstate == "modify") {
2237: formname.state.value = "personnel";
2238: formname.action.value = "new";
2239: } else {
2240: formname.state.value = nextstate;
2241: }
2242: formname.submit();
2243: }
2244:
2245: function backPage(formname,prevstate) {
2246: formname.state.value = prevstate;
2247: formname.submit();
2248: }
2249:
2250: ENDJS
2251: }
2252:
2253: sub viewcancel_javascript {
2254: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
2255: 'Your request will be removed.');
2256: return << "ENDJS";
2257: function nextPage(formname,nextstate) {
2258: if (confirm('$alert')) {
2259: formname.state.value = nextstate;
2260: formname.submit();
2261: }
2262: return;
2263: }
2264:
2265: ENDJS
2266: }
2267:
2268: sub print_request_logs {
2269: my ($r,$dom,$jscript,$loaditems,$crumb) = @_;
2270: my $title;
2271: if ($env{'form.crstype'} eq 'community') {
2272: $title = 'Community Request Logs';
2273: } elsif ($env{'form.crstype'} eq 'any') {
2274: $title = 'Course/Community Request Logs';
2275: } else {
2276: $title = 'Course Request Logs';
2277: }
2278: $r->print(&header($title,$jscript,$loaditems).$crumb);
2279: my $formname = 'requestcrs';
2280: $r->print('<form action="/adm/requestcourse" method="post" name="'.$formname.'" onsubmit="javascript:setPage(this);">'."\n".
2281: '<input type="hidden" name="action" value="log" />'."\n".
2282: '<input type="hidden" name="state" value="display" />'."\n");
2283: # set defaults
2284: my $now = time();
2285: my $defstart = $now - (7*24*3600); #7 days ago
2286: my %defaults = (
2287: page => '1',
2288: show => '10',
2289: crstype => 'any',
2290: status => 'any',
2291: requested_before_date => $now,
2292: requested_after_date => $defstart,
2293: );
2294: my ($types,$typenames) = &Apache::loncommon::course_types();
2295: my $more_records = 0;
2296: my %curr;
2297: foreach my $item ('show','page','crstype','status') {
2298: $curr{$item} = $env{'form.'.$item};
2299: }
2300: $curr{'requested_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_after_date');
2301: $curr{'requested_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_before_date');
2302: foreach my $key (keys(%defaults)) {
2303: if ($curr{$key} eq '') {
2304: $curr{$key} = $defaults{$key};
2305: }
2306: }
2307: my ($statuses,$statusnames) = &reqstatus_names($curr{'crstype'});
2308: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
2309: &requestlog_display_filter($formname,\%curr));
2310: my %queue_by_date = &sorted_request_history($dom,$env{'form.action'},\%curr);
2311: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
2312: my $showntablehdr = 0;
2313: my $tablehdr = &Apache::loncommon::start_data_table().
2314: &Apache::loncommon::start_data_table_header_row().
2315: '<th> </th><th>'.&mt('Request Date').'</th>'.
2316: '<th>'.&mt('Description').'</th>';
2317: if ($curr{'crstype'} eq 'any') {
2318: $tablehdr .= '<th>'.&mt('Course Type').'</th>';
2319: }
2320: if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) {
2321: $tablehdr .= '<th>'.&mt('Institutional Code').'</th>';
2322: }
2323: if ($curr{'status'} eq 'any') {
2324: $tablehdr .= '<th>'.&mt('Status').'</th>';
2325: } elsif ($curr{'status'} eq 'created') {
2326: $tablehdr .= '<th>'.&mt('Creation Date').'</th>';
2327: } elsif ($curr{'status'} eq 'cancelled') {
2328: $tablehdr .= '<th>'.&mt('Cancellation Date').'</th>';
2329: } elsif ($curr{'status'} eq 'rejected') {
2330: $tablehdr .= '<th>'.&mt('Rejection Date').'</th>';
2331: }
2332: $tablehdr .= &Apache::loncommon::end_data_table_header_row();
2333: my ($minshown,$maxshown);
2334: $minshown = 1;
2335: my $count = 0;
2336: if ($curr{'show'} ne &mt('all')) {
2337: $maxshown = $curr{'page'} * $curr{'show'};
2338: if ($curr{'page'} > 1) {
2339: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
2340: }
2341: }
2342: my $norecords;
2343: if (@sortedtimes > 0) {
2344: foreach my $item (@sortedtimes) {
2345: if ($curr{'show'} ne &mt('all')) {
2346: if ($count >= $curr{'page'} * $curr{'show'}) {
2347: $more_records = 1;
2348: last;
2349: }
2350: }
2351: $count ++;
2352: next if ($count < $minshown);
2353: if (!$showntablehdr) {
2354: $r->print($tablehdr);
2355: $showntablehdr = 1;
2356: }
2357: my $showtime = &Apache::lonlocal::locallocaltime($item);
2358: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2359: foreach my $request (sort(@{$queue_by_date{$item}})) {
2360: my ($key,$crstype,$desc,$timestamp,$status,$instcode) = split(':',$request);
2361: my ($cdom,$cnum) = split('_',$key);
2362: my $output = &Apache::loncommon::start_data_table_row().
2363: '<td>'.$count.'</td>'.
2364: '<td>'.$showtime.'</td>'.
2365: '<td>'.&unescape($desc).'</td>';
2366: if ($curr{'crstype'} eq 'any') {
2367: my $typename;
2368: if (ref($typenames) eq 'HASH') {
2369: $typename = &mt($typenames->{$crstype});
2370: }
2371: if ($typename eq '') {
2372: $typename = &mt('Unknown type');
2373: }
2374: $output .= '<td>'.$typename.'</td>';
2375: }
2376: if (($curr{'crstype'} eq 'any') ||
2377: ($curr{'crstype'} eq 'official')) {
2378: my $showinstcode;
2379: if ($crstype eq 'official') {
2380: $showinstcode = &unescape($instcode);
2381: } else {
2382: $showinstcode = &mt('Not applicable');
2383: }
2384: $output .= '<td>'.$showinstcode.'</td>';
2385: }
2386: if ($curr{'status'} eq 'any') {
2387: my $statusname = &mt('Unknown status');
2388: if (ref($statusnames) eq 'HASH') {
2389: if ($statusnames->{$status} ne '') {
2390: $statusname = $statusnames->{$status};
2391: }
2392: }
2393: if (($status eq 'created') || ($status eq 'cancelled') ||
2394: ($status eq 'rejected')) {
2395: $statusname .= ' '.&Apache::lonlocal::locallocaltime($timestamp);
2396: }
2397: $output .= '<td>'.$statusname.'</td>';
2398: } elsif (($status eq 'created') || ($status eq 'cancelled') ||
2399: ($status eq 'rejected')) {
2400: $output .= '<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>';
2401: }
2402: $output .= &Apache::loncommon::end_data_table_row();
2403: $r->print($output);
2404: }
2405: }
2406: }
2407: if ($showntablehdr) {
2408: $r->print(&Apache::loncommon::end_data_table());
2409: if (($curr{'page'} > 1) || ($more_records)) {
2410: $r->print('<table><tr>');
2411: if ($curr{'page'} > 1) {
2412: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
2413: }
2414: if ($more_records) {
2415: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
2416: }
2417: $r->print('</tr></table>');
2418: $r->print(<<"ENDSCRIPT");
2419: <script type="text/javascript">
2420: // <![CDATA[
2421: function chgPage(caller) {
2422: if (caller == 'previous') {
2423: document.$formname.page.value --;
2424: }
2425: if (caller == 'next') {
2426: document.$formname.page.value ++;
2427: }
2428: document.$formname.submit();
2429: return;
2430: }
2431: // ]]>
2432: </script>
2433: ENDSCRIPT
2434: }
2435: } else {
2436: $norecords = 1;
2437: }
2438: } else {
2439: $norecords = 1;
2440: }
2441: if ($norecords) {
2442: $r->print('<p class="LC_info">'.
2443: &mt('There are no records to display').
2444: '</p>');
2445: }
2446: $r->print('</form>'.
2447: &Apache::loncommon::end_page());
2448: return;
2449: }
2450:
2451: sub reqstatus_names {
2452: my ($crstype) = @_;
2453: my @statuses = qw(created approval pending rejected cancelled);
2454: my %statusnames =
2455: &Apache::lonlocal::texthash (
2456: created => 'Created',
2457: approval => 'Queued pending approval',
2458: pending => 'Queued pending validation',
2459: rejected => 'Request rejected',
2460: cancelled => 'Request cancelled',
2461: );
2462: if (($crstype eq 'official') || ($crstype eq 'unofficial')) {
2463: $statusnames{'created'} = &mt('Course created');
2464: } elsif ($crstype eq 'community') {
2465: $statusnames{'created'} = &mt('Community created');
2466: }
2467: return (\@statuses,\%statusnames);
2468: }
2469:
2470: sub requestlog_display_filter {
2471: my ($formname,$curr) = @_;
2472: my $nolink = 1;
2473: my $output = '<table><tr><td valign="top">'.
2474: '<span class="LC_nobreak"><b>'.&mt('Records/page:').'</b></span><br />'.
2475: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
2476: (&mt('all'),5,10,20,50,100,1000,10000)).
2477: '</td><td> </td>';
2478: my $startform =
2479: &Apache::lonhtmlcommon::date_setter($formname,'requested_after_date',
2480: $curr->{'requested_after_date'},undef,
2481: undef,undef,undef,undef,undef,undef,$nolink);
2482: my $endform =
2483: &Apache::lonhtmlcommon::date_setter($formname,'requested_before_date',
2484: $curr->{'requested_before_date'},undef,
2485: undef,undef,undef,undef,undef,undef,$nolink);
2486: $output .= '<td valign="top"><b>'.&mt('Window during which course/community was requested:').'</b><br />'.
2487: '<table><tr><td>'.&mt('After:').
2488: '</td><td>'.$startform.'</td></tr>'.
2489: '<tr><td>'.&mt('Before:').'</td>'.
2490: '<td>'.$endform.'</td></tr></table>'.
2491: '</td>'.
2492: '<td> </td>';
2493: my ($types,$typenames) = &Apache::loncommon::course_types();
2494: if (ref($types) eq 'ARRAY') {
2495: if (@{$types} > 1) {
2496: $output .= '<td valign="top"><b>'.
2497: &mt('Course Type:').'</b><br /><select name="crstype">';
2498: my $selstr = '';
2499: if ($curr->{'crstype'} eq 'any') {
2500: $selstr = ' selected="selected"';
2501: }
2502: $output .= '<option value="any"'.$selstr.'>'.&mt('All types').'</option>'."\n";
2503: foreach my $crstype (@{$types}) {
2504: my $selstr = '';
2505: if ($curr->{'crstype'} eq $crstype) {
2506: $selstr = ' selected="selected"';
2507: }
2508: my $typename = $crstype;
2509: if (ref($typenames) eq 'HASH') {
2510: if ($typenames->{$crstype} ne '') {
2511: $typename = $typenames->{$crstype};
2512: }
2513: }
2514: $output .= '<option value="'.$crstype.'"'.$selstr.'>'.$typename.'</option>'."\n";
2515: }
2516: $output .= '</select></td>';
2517: }
2518: }
2519: my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'});
2520: if (ref($statuses) eq 'ARRAY') {
2521: if (@{$statuses} > 1) {
2522: $output .= '<td valign="top"><b>'.
2523: &mt('Request Status:').'</b><br /><select name="status">';
2524: my $selstr = '';
2525: if ($curr->{'status'} eq 'any') {
2526: $selstr = ' selected="selected"';
2527: }
2528: $output .= '<option value="any"'.$selstr.'>'.&mt('Any status').'</option>'."\n";
2529: foreach my $status (@{$statuses}) {
2530: my $selstr = '';
2531: if ($curr->{'status'} eq $status) {
2532: $selstr = ' selected="selected"';
2533: }
2534: my $statusname = $status;
2535: if (ref($statusnames) eq 'HASH') {
2536: if ($statusnames->{$status} ne '') {
2537: $statusname = $statusnames->{$status};
2538: }
2539: }
2540: $output .= '<option value="'.$status.'"'.$selstr.'>'.$statusname.'</option>'."\n";
2541: }
2542: $output .= '</select></td>';
2543: }
2544: }
2545: $output .= '</tr></table>';
2546:
2547: # Update Display button
2548: $output .= '<p>'.
2549: '<input type="submit" value="'.&mt('Update Display').'" />'.
2550: '</p><hr />';
2551: return $output;
2552: }
2553:
2554: sub print_review {
2555: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
2556: $disallowed,$disallowmsg) = @_;
2557: my ($types,$typename) = &Apache::loncommon::course_types();
2558: my ($owner,$ownername,$owneremail);
2559: if ($uname eq '' || $udom eq '') {
2560: $uname = $env{'user.name'};
2561: $udom = $env{'user.domain'};
2562: }
2563: $owner = $uname.':'.$udom;
2564: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
2565: my %emails = &Apache::loncommon::getemails($uname,$udom);
2566: foreach my $email ('permanentemail','critnotification','notification') {
2567: $owneremail = $emails{$email};
2568: last if ($owneremail ne '');
2569: }
2570: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
2571: $section_headers,$section_values,$personnel_headers,$personnel_values);
2572:
2573: $crstypename = $env{'form.crstype'};
2574: if (ref($typename) eq 'HASH') {
2575: unless ($typename->{$env{'form.crstype'}} eq '') {
2576: $crstypename = &mt($typename->{$env{'form.crstype'}});
2577: }
2578: }
2579: my $category = 'Course';
2580: if ($env{'form.crstype'} eq 'community') {
2581: $category = 'Community';
2582: }
2583:
2584: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
2585: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
2586:
2587: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
2588: '('.&Apache::lonnet::plaintext('st',$category).')';
2589: if ($env{'form.crstype'} eq 'official') {
2590: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
2591: foreach my $title (@{$codetitles}) {
2592: if ($env{'form.instcode_'.$title} ne '') {
2593: $inst_headers .= '<th>'.$title.'</th>';
2594: my $longitem = $env{'form.instcode_'.$title};
2595: if (ref($cat_titles->{$title}) eq 'HASH') {
2596: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
2597: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
2598: }
2599: }
2600: $inst_values .= '<td>'.$longitem.'</td>';
2601: }
2602: }
2603: }
2604: if (&Apache::lonnet::auto_run('',$dom)) {
2605: $enrollrow_title = &mt('Enrollment');
2606: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
2607: '<th>'.&mt('Automatic Drops').'</th>'.
2608: '<th>'.&mt('Enrollment Starts').'</th>'.
2609: '<th>'.&mt('Enrollment Ends').'</th>';
2610: $section_headers = '<th>'.&mt('Sections').'</th>'.
2611: '<th>'.&mt('Crosslistings').'</th>';
2612:
2613: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
2614: my @autoroster = (&mt('No'),&mt('Yes'));
2615: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
2616: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
2617: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
2618: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
2619: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
2620: &mt('Institutional section').'</th>'.
2621: '<th>'.&mt('LON-CAPA section').'</th></tr>';
2622: my $secinfo;
2623: if ($env{'form.sectotal'} > 0) {
2624: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2625: if ($env{'form.sec_'.$i}) {
2626: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
2627: if ($env{'form.loncapasec_'.$i} ne '') {
2628: $secinfo .= $env{'form.loncapasec_'.$i};
2629: } else {
2630: $secinfo .= &mt('None');
2631: }
2632: $secinfo .= '</td></tr>';
2633: }
2634: }
2635: }
2636: if ($secinfo eq '') {
2637: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
2638: }
2639: $section_values .= $secinfo.'</table></td><td>'.
2640: '<table class="LC_innerpickbox"><tr><th>'.
2641: &mt('Institutional course/section').'</th>'.
2642: '<th>'.&mt('LON-CAPA section').'</th></tr>';
2643: my $xlistinfo;
2644: my $crosslisttotal = $env{'form.crosslisttotal'};
2645: if (!$crosslisttotal) {
2646: $crosslisttotal = 1;
2647: }
2648: for (my $i=0; $i<$crosslisttotal; $i++) {
2649: if ($env{'form.crosslist_'.$i}) {
2650: $xlistinfo .= '<tr><td>';
2651: if (ref($code_order) eq 'ARRAY') {
2652: if (@{$code_order} > 0) {
2653: foreach my $item (@{$code_order}) {
2654: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
2655: }
2656: }
2657: }
2658: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
2659: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
2660: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
2661: } else {
2662: $xlistinfo .= &mt('None');
2663: }
2664: $xlistinfo .= '</td></tr>';
2665: }
2666: }
2667: if ($xlistinfo eq '') {
2668: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
2669: }
2670: $section_values .= $xlistinfo;
2671: }
2672: $section_values .= '</table></td>';
2673: }
2674:
2675: my %ctxt = &clone_text();
2676: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
2677: if (($env{'form.cloning'}) &&
2678: ($env{'form.clonecrs'} =~ /^$match_name$/) &&
2679: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
2680: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname,
2681: $udom,$env{'form.clonecrs'},$env{'form.clonedom'},
2682: $env{'form.crstype'});
2683: if ($canclone) {
2684: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
2685: $env{'form.clonecrs'},('description','internal.coursecode'));
2686: if (keys(%courseenv) > 0) {
2687: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
2688: $inst_values .= '<td>'.$courseenv{'description'}.' ';
2689: my $cloneinst = $courseenv{'internal.coursecode'};
2690: if ($cloneinst ne '') {
2691: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
2692: } else {
2693: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
2694: }
2695: $inst_values .= '</td><td>';
2696: if ($env{'form.datemode'} eq 'preserve') {
2697: $inst_values .= $ctxt{'prd'};
2698: } elsif ($env{'form.datemode'} eq 'shift') {
2699: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
2700: } else {
2701: $inst_values .= $ctxt{'ncd'};
2702: }
2703: $inst_values .= '</td>';
2704: } else {
2705: $inst_values .= '<td>'.&mt('Unknown').'</td>';
2706: }
2707: } else {
2708: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
2709: }
2710: } else {
2711: $inst_values .= '<td>'.&mt('None').'</td>';
2712: }
2713: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
2714: '<th>'.&mt('Access Ends').'</th>';
2715: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2716: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
2717: if ($accessend == 0) {
2718: $enroll_values .= '<td>'.&mt('No end date').'</td>';
2719: } else {
2720: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
2721: }
2722:
2723: my $container = 'Course';
2724: my $ccrole = 'cc';
2725: if ($env{'form.crstype'} eq 'community') {
2726: $container = 'Community';
2727: $ccrole = 'co';
2728: }
2729:
2730: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
2731: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
2732: '</th>';
2733:
2734: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
2735: '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
2736: '<td>'.&mt('None').'</td></tr>';
2737: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2738: if ($env{'form.person_'.$i.'_uname'} ne '') {
2739: if (ref($disallowed) eq 'ARRAY') {
2740: next if (grep(/^$i$/,@{$disallowed}));
2741: }
2742: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2743: my @allsecs;
2744: foreach my $sec (@officialsecs) {
2745: next unless ($sec =~ /\w/);
2746: next if ($sec =~ /\W/);
2747: next if ($sec eq 'none');
2748: push(@allsecs,$sec);
2749: }
2750: my $newsec = $env{'form.person_'.$i.'_newsec'};
2751: $newsec =~ s/^\s+//;
2752: $newsec =~s/\s+$//;
2753: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
2754: foreach my $sec (@newsecs) {
2755: next unless ($sec =~ /\w/);
2756: next if ($sec =~ /\W/);
2757: next if ($sec eq 'none');
2758: if ($sec ne '') {
2759: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2760: push(@allsecs,$sec);
2761: }
2762: }
2763: }
2764: my $showsec;
2765: if (@allsecs) {
2766: $showsec = join(', ',@allsecs);
2767: }
2768: if ($showsec eq '') {
2769: $showsec = &mt('None');
2770: }
2771: if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
2772: $showsec = &mt('None');
2773: }
2774: my $role = $env{'form.person_'.$i.'_role'};
2775: $personnel_values .=
2776: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
2777: $env{'form.person_'.$i.'_lastname'}.'</td>'.
2778: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
2779: $env{'form.person_'.$i.'_dom'}.'</td>'.
2780: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
2781: '<td>'.$showsec.'</td></tr>';
2782: }
2783: }
2784: my $output;
2785: if (ref($disallowed) eq 'ARRAY') {
2786: if (@{$disallowed} > 0) {
2787: if (ref($disallowmsg) eq 'HASH') {
2788: $output = '<p class="LC_warning">'.
2789: &mt('Not all requested personnel could be included.').'<ul>';
2790: foreach my $item (@{$disallowed}) {
2791: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
2792: }
2793: $output .= '</ul></p>';
2794: }
2795: }
2796: }
2797: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
2798: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
2799: '<table class="LC_innerpickbox"><tr>'.
2800: '<th>'.&mt('Name').'</th>'.
2801: '<th>'.&mt('Username:Domain').'</th>'.
2802: '<th>'.&mt('E-mail address').'</th>'.
2803: '</tr><tr>'."\n".
2804: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
2805: '<td>'.$owneremail.'</td>'.
2806: '</tr></table>'."\n".
2807: &Apache::lonhtmlcommon::row_closure().
2808: &Apache::lonhtmlcommon::row_title(&mt('Description')).
2809: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
2810: '<tr>'.$inst_values.'</tr></table>'."\n".
2811: &Apache::lonhtmlcommon::row_closure().
2812: &Apache::lonhtmlcommon::row_title($enrollrow_title).
2813: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
2814: '<tr>'.$enroll_values.'</tr></table>'."\n".
2815: &Apache::lonhtmlcommon::row_closure();
2816: if ($section_headers ne '') {
2817: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
2818: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
2819: '<tr>'.$section_values.'</tr></table>'."\n".
2820: &Apache::lonhtmlcommon::row_closure();
2821: }
2822: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
2823: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
2824: $personnel_values.'</table>'."\n".
2825: &Apache::lonhtmlcommon::row_closure(1).
2826: &Apache::lonhtmlcommon::end_pick_box().'</div>';
2827: return $output;
2828: }
2829:
2830: sub dates_from_form {
2831: my ($startname,$endname) = @_;
2832: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
2833: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
2834: if ($endname eq 'accessend') {
2835: if (exists($env{'form.no_end_date'}) ) {
2836: $enddate = 0;
2837: }
2838: }
2839: return ($startdate,$enddate);
2840: }
2841:
2842: sub courseinfo_form {
2843: my ($dom,$formname,$crstype,$next,$description) = @_;
2844: my %lt = &Apache::lonlocal::texthash(
2845: official => 'You must provide a (brief) course description.',
2846: community => 'You must provide a (brief) community description.'
2847: );
2848: $lt{'unofficial'} = $lt{'official'};
2849: my $js_validate = <<"ENDJS";
2850: <script type="text/javascript">
2851: // <![CDATA['
2852:
2853: function validateForm() {
2854: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
2855: alert('$lt{$crstype}');
2856: return;
2857: }
2858: nextPage(document.$formname,'$next');
2859: }
2860:
2861: function toggleCloning() {
2862: var willclone;
2863: if (document.$formname.cloning.length > 1) {
2864: for (var i=0; i<document.$formname.cloning.length; i++) {
2865: if (document.$formname.cloning[i].checked) {
2866: willclone = document.$formname.cloning[i].value;
2867: }
2868: }
2869: }
2870: if (willclone == 1) {
2871: document.getElementById('cloneoptions').style.display="block";
2872: } else {
2873: document.getElementById('cloneoptions').style.display="none";
2874: document.$formname.clonecrs.value = '';
2875: }
2876: }
2877:
2878: // ]]
2879: </script>
2880:
2881: ENDJS
2882: my $title = &mt('Brief Course Description');
2883: my $clonetitle = &mt('Clone content and settings from an existing course?');
2884: if ($crstype eq 'community') {
2885: $title = &mt('Brief Community Description');
2886: $clonetitle = &mt('Clone content and settings from an existing community?');
2887: }
2888: my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box().
2889: &Apache::lonhtmlcommon::row_headline().
2890: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'.
2891: &Apache::lonhtmlcommon::row_closure(1).
2892: &Apache::lonhtmlcommon::row_title(&mt('Description')).
2893: '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
2894: my ($home_server_pick,$numlib) =
2895: &Apache::loncommon::home_server_form_item($dom,'chome',
2896: 'default','hide');
2897: if ($numlib > 1) {
2898: $output .= &Apache::lonhtmlcommon::row_closure().
2899: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
2900: }
2901: $output .= $home_server_pick.
2902: &Apache::lonhtmlcommon::row_closure().
2903: &Apache::lonhtmlcommon::row_headline().
2904: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.
2905: &Apache::lonhtmlcommon::row_closure(1).
2906: &Apache::lonhtmlcommon::row_title(&mt('Clone?')).
2907: '<label><input type="radio" name="cloning" value="1" '.
2908: 'onclick="javascript:toggleCloning()" />'.
2909: &mt('Yes').(' 'x2).'</label><label>'.
2910: '<input type="radio" name="cloning" value="0" checked="checked" '.
2911: 'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'.
2912: '</h3>'.
2913: &Apache::lonhtmlcommon::row_closure(1).
2914: &Apache::lonhtmlcommon::row_headline().
2915: '<div id="cloneoptions" style="display: none" >'.
2916: &Apache::lonhtmlcommon::start_pick_box().
2917: &clone_form($dom,$formname,$crstype).
2918: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
2919: &Apache::lonhtmlcommon::end_pick_box()."\n";
2920: return $output;
2921: }
2922:
2923: sub clone_form {
2924: my ($dom,$formname,$crstype) = @_;
2925: my $type = 'Course';
2926: if ($crstype eq 'community') {
2927: $type = 'Community';
2928: }
2929: my %lt = &clone_text();
2930: my $output .=
2931: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
2932: &Apache::loncommon::select_dom_form($dom,'clonedom').'</label>'.
2933: &Apache::lonhtmlcommon::row_closure(1).
2934: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
2935: '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();opencrsbrowser('."'$formname','clonecrs','clonedom','','','','','$type'".')" />'.
2936: '</label> '.
2937: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type).
2938: &Apache::lonhtmlcommon::row_closure(1).
2939: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
2940: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
2941: '</label><br /><label>'.
2942: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
2943: '</label><br /><label>'.
2944: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
2945: $lt{'shd'}.'</label>'.
2946: '<input type="text" size="5" name="dateshift" value="365" />'.
2947: &Apache::lonhtmlcommon::row_closure(1);
2948: return $output;
2949: }
2950:
2951: sub clone_text {
2952: return &Apache::lonlocal::texthash(
2953: 'cid' => 'Course ID',
2954: 'dmn' => 'Domain',
2955: 'dsh' => 'Date Shift',
2956: 'ncd' => 'Do not clone date parameters',
2957: 'prd' => 'Clone date parameters as-is',
2958: 'shd' => 'Shift date parameters by number of days',
2959: );
2960: }
2961:
2962: sub coursecode_form {
2963: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
2964: my $output;
2965: my %rowtitle = &Apache::lonlocal::texthash (
2966: instcode => 'Course Category',
2967: crosslist => 'Cross Listed Course',
2968: );
2969: my %helpitem = (
2970: instcode => 'Course_Request_Category',
2971: );
2972: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
2973: (ref($cat_order))) {
2974: my ($sel,$instsec,$lcsec);
2975: $sel = $context;
2976: if ($context eq 'crosslist') {
2977: $sel .= '_'.$num;
2978: $instsec = &mt('Institutional section').'<br />'.
2979: '<input type="text" size="10" name="'.$sel.'_instsec" />';
2980: $lcsec = &mt('LON-CAPA section').'<br />'.
2981: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
2982: }
2983: if (@{$codetitles} > 0) {
2984: my $lastitem = pop(@{$codetitles});
2985: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
2986: if (@{$codetitles} > 0) {
2987: my $helplink;
2988: if (defined($helpitem{$context})) {
2989: $helplink = &Apache::loncommon::help_open_topic($helpitem{$context}).' ';
2990: }
2991: $output = &Apache::lonhtmlcommon::row_title($helplink.$rowtitle{$context}).
2992: '<table><tr>';
2993: if ($context eq 'crosslist') {
2994: $output .= '<td>'.&mt('Include?').'<br />'.
2995: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
2996: }
2997: foreach my $title (@{$codetitles}) {
2998: if (ref($cat_order->{$title}) eq 'ARRAY') {
2999: if (@{$cat_order->{$title}} > 0) {
3000: $output .= '<td align="center">'.$title.'<br />'."\n".
3001: '<select name="'.$sel.'_'.$title.'">'."\n".
3002: ' <option value="" selected="selected">'.
3003: &mt('Select').'</option>'."\n";
3004: foreach my $item (@{$cat_order->{$title}}) {
3005: my $longitem = $item;
3006: if (ref($cat_titles->{$title}) eq 'HASH') {
3007: if ($cat_titles->{$title}{$item} ne '') {
3008: $longitem = $cat_titles->{$title}{$item};
3009: }
3010: }
3011: $output .= '<option value="'.$item.'">'.$longitem.
3012: '</option>'."\n";
3013: }
3014: }
3015: $output .= '</select></td>'."\n";
3016: }
3017: }
3018: if ($context eq 'crosslist') {
3019: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
3020: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
3021: '<td align="center">'.$lcsec.'</td></tr></table>';
3022: } else {
3023: $output .= '</tr></table>'.
3024: &Apache::lonhtmlcommon::row_closure().
3025: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
3026: $lastinput;
3027: }
3028: } else {
3029: if ($context eq 'crosslist') {
3030: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
3031: '<table><tr>'.
3032: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
3033: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
3034: '</tr></table>';
3035: } else {
3036: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
3037: $lastinput;
3038: }
3039: }
3040: $output .= &Apache::lonhtmlcommon::row_closure(1);
3041: push(@$codetitles,$lastitem);
3042: } elsif ($context eq 'crosslist') {
3043: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
3044: '<table><tr><td align="center">'.
3045: '<span class="LC_nobreak">'.&mt('Include?').
3046: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
3047: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
3048: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
3049: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
3050: &Apache::lonhtmlcommon::row_closure(1);
3051: }
3052: }
3053: return $output;
3054: }
3055:
3056: sub sections_form {
3057: my ($dom,$instcode,$num) = @_;
3058: my $rowtitle;
3059: if ($instcode eq '') {
3060: $rowtitle = &mt('Sections');
3061: } else {
3062: $rowtitle = &mt('Sections of [_1]',$instcode);
3063: }
3064: return &Apache::lonhtmlcommon::row_title($rowtitle).
3065: '<table><tr><td align="center">'.
3066: '<span class="LC_nobreak">'.&mt('Include?').
3067: '<input type="checkbox" name="sec_'.$num.'" value="1" /></span>'.
3068: '</td><td align="center">'.&mt('Institutional section').'<br />'.
3069: '<input type="text" size="10" name="secnum_'.$num.'" />'.
3070: '</td><td align="center">'.&mt('LON-CAPA section').'<br />'.
3071: '<input type="text" size="10" name="loncapasec_'.$num.'" />'.
3072: '</td></tr></table>'.
3073: &Apache::lonhtmlcommon::row_closure(1);
3074: }
3075:
3076: sub get_course_dom {
3077: my $codedom = &Apache::lonnet::default_login_domain();
3078: if ($env{'form.showdom'} ne '') {
3079: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
3080: return $env{'form.showdom'};
3081: }
3082: }
3083: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
3084: my ($types,$typename) = &Apache::loncommon::course_types();
3085: if (ref($types) eq 'ARRAY') {
3086: foreach my $type (@{$types}) {
3087: if (&Apache::lonnet::usertools_access($env{'user.name'},
3088: $env{'user.domain'},$type,
3089: undef,'requestcourses')) {
3090: return $env{'user.domain'};
3091: }
3092: }
3093: my @possible_doms;
3094: foreach my $type (@{$types}) {
3095: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
3096: if ($dom_str ne '') {
3097: my @domains = split(',',$dom_str);
3098: foreach my $entry (@domains) {
3099: my ($extdom,$extopt) = split(':',$entry);
3100: if ($extdom eq $env{'request.role.domain'}) {
3101: return $extdom;
3102: }
3103: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
3104: push(@possible_doms,$extdom);
3105: }
3106: }
3107: }
3108: }
3109: if (@possible_doms) {
3110: @possible_doms = sort(@possible_doms);
3111: return $possible_doms[0];
3112: }
3113: }
3114: $codedom = $env{'user.domain'};
3115: if ($env{'request.role.domain'} ne '') {
3116: $codedom = $env{'request.role.domain'};
3117: }
3118: }
3119: return $codedom;
3120: }
3121:
3122: sub display_navbuttons {
3123: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
3124: $r->print('<div class="LC_navbuttons">');
3125: if ($prev) {
3126: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
3127: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
3128: (' 'x3));
3129: } elsif ($prevtext) {
3130: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
3131: 'onclick="javascript:history.back()"/>'.(' 'x3));
3132: }
3133: if ($state eq 'details') {
3134: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
3135: 'onclick="javascript:nextPage('."document.$formname,'$other'".
3136: ')" />');
3137: }
3138: my $gotnext;
3139: if ($state eq 'courseinfo') {
3140: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3141: 'onclick="javascript:validateForm();" />');
3142: $gotnext = 1;
3143: } elsif ($state eq 'enrollment') {
3144: if (($env{'form.crstype'} eq 'official') &&
3145: (&Apache::lonnet::auto_run('',$dom))) {
3146: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3147: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
3148: $gotnext = 1;
3149: }
3150: } elsif ($state eq 'personnel') {
3151: if ($env{'form.persontotal'} > 0) {
3152: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3153: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
3154: $gotnext = 1;
3155: }
3156: }
3157: unless ($gotnext) {
3158: if ($next) {
3159: $r->print('
3160: <input type="button" name="next" value="'.$nexttext.'" '.
3161: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
3162: }
3163: }
3164: $r->print('</div>');
3165: }
3166:
3167: sub print_request_outcome {
3168: my ($dom,$codetitles,$code_order) = @_;
3169: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
3170: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
3171: my $sectotal = $env{'form.sectotal'};
3172: my $crosslisttotal = 0;
3173: $cnum = $env{'form.cnum'};
3174: unless ($cnum =~ /^$match_courseid$/) {
3175: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
3176: return $output;
3177: }
3178:
3179: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
3180: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
3181: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
3182: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
3183: }
3184: }
3185: $now = time;
3186: $crstype = $env{'form.crstype'};
3187: my $ccrole = 'cc';
3188: if ($crstype eq 'community') {
3189: $ccrole = 'co';
3190: }
3191: my @instsections;
3192: if ($crstype eq 'official') {
3193: if (&Apache::lonnet::auto_run('',$dom)) {
3194: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
3195: }
3196: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
3197: if ($env{'form.sec_'.$i}) {
3198: if ($env{'form.secnum_'.$i} ne '') {
3199: my $sec = $env{'form.secnum_'.$i};
3200: $sections{$i}{'inst'} = $sec;
3201: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
3202: push(@instsections,$sec);
3203: }
3204: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
3205: $sections{$i}{'loncapa'} =~ s/\W//g;
3206: if ($sections{$i}{'loncapa'} eq 'none') {
3207: $sections{$i}{'loncapa'} = '';
3208: }
3209: }
3210: }
3211: }
3212: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
3213: if ($env{'form.crosslist_'.$i}) {
3214: my $xlistinfo = '';
3215: if (ref($code_order) eq 'ARRAY') {
3216: if (@{$code_order} > 0) {
3217: foreach my $item (@{$code_order}) {
3218: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
3219: }
3220: }
3221: }
3222: $crosslistings{$i}{'instcode'} = $xlistinfo;
3223: if ($xlistinfo ne '') {
3224: $crosslisttotal ++;
3225: }
3226: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
3227: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
3228: }
3229: }
3230: } else {
3231: $enrollstart = '';
3232: $enrollend = '';
3233: }
3234: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg,%skipped);
3235: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
3236: my $uname = $env{'form.person_'.$i.'_uname'};
3237: my $udom = $env{'form.person_'.$i.'_dom'};
3238: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
3239: if (&Apache::lonnet::domain($udom) ne '') {
3240: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
3241: $personnel{$uname.':'.$udom} = {
3242: firstname => $env{'form.person_'.$i.'_firstname'},
3243: lastname => $env{'form.person_'.$i.'_lastname'},
3244: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
3245: };
3246: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
3247: my $usertype = &get_usertype($udom,$uname,\%curr_rules,\%got_rules);
3248: if (&Apache::lonuserutils::can_create_user($udom,'requestcrs',$usertype)) {
3249: my ($allowed,$msg,$authtype,$authparam) =
3250: &check_newuser_rules($udom,$uname,\%alerts,\%rulematch,
3251: \%inst_results,\%curr_rules,\%got_rules);
3252: if ($allowed) {
3253: my %domdefaults = &Apache::lonnet::get_domain_defaults($udom);
3254: if ($usertype eq 'official') {
3255: if ($authtype eq '') {
3256: $authtype = $domdefaults{'auth_def'};
3257: $authparam = $domdefaults{'auth_arg_def'};
3258: } else {
3259: if ($authtype eq 'loc') {
3260: $authtype = 'localauth';
3261: } elsif ($authtype eq 'int') {
3262: $authtype = 'internal';
3263: }
3264: if ($authtype !~ /^(krb4|krb5|internal|localauth)$/) {
3265: $authtype = $domdefaults{'auth_def'};
3266: $authparam = $domdefaults{'auth_arg_def'};
3267: }
3268: }
3269: } elsif ($usertype eq 'unofficial') {
3270: if ($authtype eq '') {
3271: $authtype = 'internal';
3272: $authparam = '';
3273: }
3274: } else {
3275: $authtype = $domdefaults{'auth_def'};
3276: $authparam = $domdefaults{'auth_arg_def'};
3277: }
3278: if (($authtype eq '') ||
3279: (($authtype =~/^krb(4|5)$/) && ($authparam eq '')) ||
3280: ($authtype !~ /^(krb4|krb5|internal|localauth)$/)) {
3281: $skipped{$uname.':'.$udom} = 1;
3282: next;
3283: } else {
3284: $personnel{$uname.':'.$udom}{'authtype'} = $authtype;
3285: $personnel{$uname.':'.$udom}{'autharg'} = $authparam;
3286: }
3287: } else {
3288: $skipped{$uname.':'.$udom} = 1;
3289: next;
3290: }
3291: } else {
3292: $skipped{$uname.':'.$udom} = 1;
3293: next;
3294: }
3295: }
3296: }
3297: my $role = $env{'form.person_'.$i.'_role'};
3298: unless ($role eq '') {
3299: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
3300: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
3301: unless (grep(/^\Q$role\E$/,@curr_roles)) {
3302: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
3303: }
3304: } else {
3305: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
3306: }
3307: if ($role eq $ccrole) {
3308: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
3309: } else {
3310: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
3311: my @allsecs;
3312: foreach my $sec (@currsec) {
3313: next unless ($sec =~ /\w/);
3314: next if ($sec =~ /\W/);
3315: next if ($sec eq 'none');
3316: push(@allsecs,$sec);
3317: }
3318: my $newsec = $env{'form.person_'.$i.'_newsec'};
3319: $newsec =~ s/^\s+//;
3320: $newsec =~s/\s+$//;
3321: my @newsecs = split(/[\s,;]+/,$newsec);
3322: foreach my $sec (@newsecs) {
3323: next if ($sec =~ /\W/);
3324: next if ($sec eq 'none');
3325: if ($sec ne '') {
3326: unless (grep(/^\Q$sec\E$/,@allsecs)) {
3327: push(@allsecs,$sec);
3328: }
3329: }
3330: }
3331: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
3332: }
3333: }
3334: } else {
3335: push(@missingdom,$uname.':'.$udom);
3336: }
3337: } else {
3338: push(@baduname,$uname.':'.$udom);
3339: }
3340: }
3341: if (keys(%skipped)) {
3342: foreach my $key (keys(%skipped)) {
3343: delete($personnel{$key});
3344: }
3345: }
3346: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
3347: my $autodrops = 0;
3348: if ($env{'form.autodrops'}) {
3349: $autodrops = $env{'form.autodrops'};
3350: }
3351: my $autoadds = 0;
3352: if ($env{'form.autoadds'}) {
3353: $autoadds = $env{'form.autoadds'};
3354: }
3355: my $instcode = '';
3356: if (exists($env{'form.instcode'})) {
3357: $instcode = $env{'form.instcode'};
3358: }
3359: my $clonecrs = '';
3360: my $clonedom = '';
3361: if (($env{'form.cloning'}) &&
3362: ($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
3363: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
3364: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
3365: $env{'form.clonedom'});
3366: if ($clonehome ne 'no_host') {
3367: my $canclone =
3368: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
3369: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
3370: $crstype);
3371: if ($canclone) {
3372: $clonecrs = $env{'form.clonecrs'};
3373: $clonedom = $env{'form.clonedom'};
3374: }
3375: }
3376: }
3377: my $details = {
3378: owner => $env{'user.name'},
3379: domain => $env{'user.domain'},
3380: cdom => $dom,
3381: cnum => $cnum,
3382: coursehome => $env{'form.chome'},
3383: cdescr => $env{'form.cdescr'},
3384: crstype => $env{'form.crstype'},
3385: instcode => $instcode,
3386: clonedom => $clonedom,
3387: clonecrs => $clonecrs,
3388: datemode => $env{'form.datemode'},
3389: dateshift => $env{'form.dateshift'},
3390: sectotal => $sectotal,
3391: sections => \%sections,
3392: crosslisttotal => $crosslisttotal,
3393: crosslists => \%crosslistings,
3394: autoadds => $autoadds,
3395: autodrops => $autodrops,
3396: enrollstart => $enrollstart,
3397: enrollend => $enrollend,
3398: accessstart => $accessstart,
3399: accessend => $accessend,
3400: personnel => \%personnel,
3401: };
3402: my (@inststatuses,$storeresult,$creationresult);
3403: my $val =
3404: &Apache::loncoursequeueadmin::get_processtype('course',$env{'user.name'},
3405: $env{'user.domain'},$env{'user.adv'},
3406: $dom,$crstype,\@inststatuses,\%domconfig);
3407: if ($val eq '') {
3408: if ($crstype eq 'official') {
3409: $output = &mt('You are not permitted to request creation of official courses.');
3410: } elsif ($crstype eq 'unofficial') {
3411: $output = &mt('You are not permitted to request creation of unofficial courses.');
3412: } elsif ($crstype eq 'community') {
3413: $output = &mt('You are not permitted to request creation of communities');
3414: } else {
3415: $output = &mt('Unrecognized course type: [_1]',$crstype);
3416: }
3417: $storeresult = 'notpermitted';
3418: } else {
3419: my ($disposition,$message,$reqstatus);
3420: my %reqhash = (
3421: reqtime => $now,
3422: crstype => $crstype,
3423: details => $details,
3424: );
3425: my $requestkey = $dom.'_'.$cnum;
3426: my $validationerror;
3427: if ($val eq 'autolimit=') {
3428: $disposition = 'process';
3429: } elsif ($val =~ /^autolimit=(\d+)$/) {
3430: my $limit = $1;
3431: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
3432: $dom,$crstype,$limit,\$message);
3433: } elsif ($val eq 'validate') {
3434: my ($inststatuslist,$validationchk,$validation);
3435: if (@inststatuses > 0) {
3436: $inststatuslist = join(',',@inststatuses);
3437: }
3438: my $instseclist;
3439: if (@instsections > 0) {
3440: $instseclist = join(',',@instsections);
3441: }
3442: $validationchk =
3443: &Apache::lonnet::auto_courserequest_validation($dom,
3444: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
3445: $inststatuslist,$instcode,$instseclist);
3446: if ($validationchk =~ /:/) {
3447: ($validation,$message) = split(':',$validationchk);
3448: } else {
3449: $validation = $validationchk;
3450: }
3451: if ($validation =~ /^error(.*)$/) {
3452: $disposition = 'approval';
3453: $validationerror = $1;
3454: } else {
3455: $disposition = $validation;
3456: }
3457: } else {
3458: $disposition = 'approval';
3459: }
3460: $reqhash{'disposition'} = $disposition;
3461: $reqstatus = $disposition;
3462: my ($modified,$queued);
3463: if ($disposition eq 'rejected') {
3464: if ($crstype eq 'community') {
3465: $output = &mt('Your community request was rejected.');
3466: } else {
3467: $output = &mt('Your course request was rejected.');
3468: }
3469: if ($message) {
3470: $output .= '<div class="LC_warning">'.$message.'</div>';
3471: }
3472: $storeresult = 'rejected';
3473: } elsif ($disposition eq 'process') {
3474: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
3475: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
3476: my $type = 'Course';
3477: if ($crstype eq 'community') {
3478: $type = 'Community';
3479: }
3480: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
3481: foreach my $role (@roles) {
3482: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
3483: }
3484: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
3485: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
3486: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
3487: if ($result eq 'created') {
3488: $disposition = 'created';
3489: $reqstatus = 'created';
3490: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
3491: \%longroles);
3492: if ($crstype eq 'community') {
3493: $output = '<p>'.&mt('Your community request has been processed and the community has been created.');
3494: } else {
3495: $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
3496: }
3497: $output .= '<br />'.$role_result.'</p>';
3498: $creationresult = 'created';
3499: } else {
3500: $output = '<span class="LC_error">';
3501: if ($crstype eq 'community') {
3502: $output .= &mt('An error occurred when processing your community request.');
3503: } else {
3504: $output .= &mt('An error occurred when processing your course request.');
3505: }
3506: $output .= '<br />'.
3507: &mt('You may want to review the request details and submit the request again.').
3508: '</span>';
3509: $creationresult = 'error';
3510: }
3511: } else {
3512: my $requestid = $cnum.'_'.$disposition;
3513: my $request = {
3514: $requestid => {
3515: timestamp => $now,
3516: crstype => $crstype,
3517: ownername => $env{'user.name'},
3518: ownerdom => $env{'user.domain'},
3519: description => $env{'form.cdescr'},
3520: },
3521: };
3522: if ($crstype eq 'official') {
3523: $request->{$requestid}->{'instcode'} = $instcode;
3524: }
3525: my $statuskey = 'status:'.$dom.':'.$cnum;
3526: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
3527: $env{'user.domain'},$env{'user.name'});
3528: if ($userreqhash{$statuskey} ne '') {
3529: $modified = 1;
3530: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
3531: my %queuehash = &Apache::lonnet::get('courserequestqueue',
3532: [$cnum.'_approval',
3533: $cnum.'_pending'],$dom,$uname);
3534: if (($queuehash{$cnum.'_approval'} ne '') ||
3535: ($queuehash{$cnum.'_pending'} ne '')) {
3536: $queued = 1;
3537: }
3538: }
3539: unless ($queued) {
3540: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
3541: $dom);
3542: if ($putresult eq 'ok') {
3543: if ($crstype eq 'community') {
3544: $output .= &mt('Your community request has been recorded.');
3545: } else {
3546: $output .= &mt('Your course request has been recorded.')
3547: }
3548: $output .= '<br />'.
3549: ¬ification_information($disposition,$req_notifylist,
3550: $cnum,$now);
3551: } else {
3552: $reqstatus = 'domainerror';
3553: $reqhash{'disposition'} = $disposition;
3554: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
3555: $output = '<span class"LC_warning">'.$warning.'</span><br />';
3556: }
3557: }
3558: }
3559: ($storeresult,my $updateresult) =
3560: &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
3561: $cnum,$reqstatus,'request',$env{'user.domain'},$env{'user.name'});
3562: if ($modified && $queued && $storeresult eq 'ok') {
3563: if ($crstype eq 'community') {
3564: $output .= '<p>'.&mt('Your community request has been updated').'</p>';
3565: } else {
3566: $output .= '<p>'.&mt('Your course request has been updated').'</p>';
3567: }
3568: $output .= ¬ification_information($disposition,$req_notifylist,$cnum,$now);
3569: }
3570: if ($validationerror ne '') {
3571: $output .= '<p class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
3572: }
3573: if ($updateresult) {
3574: $output .= $updateresult;
3575: }
3576: }
3577: if ($creationresult ne '') {
3578: return ($creationresult,$output);
3579: } else {
3580: return ($storeresult,$output);
3581: }
3582: }
3583:
3584: sub update_requestors_roles {
3585: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
3586: my $now = time;
3587: my ($active,$future,$numactive,$numfuture,$output);
3588: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
3589: if (ref($details) eq 'HASH') {
3590: if (ref($details->{'personnel'}) eq 'HASH') {
3591: my $ccrole = 'cc';
3592: if ($crstype eq 'community') {
3593: $ccrole = 'co';
3594: }
3595: unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
3596: $details->{'personnel'}{$owner} = {
3597: 'roles' => [$ccrole],
3598: $ccrole => { 'usec' => [] },
3599: };
3600: }
3601: my @roles;
3602: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
3603: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
3604: unless (grep(/^\Q$ccrole\E$/,@roles)) {
3605: push(@roles,$ccrole);
3606: }
3607: } else {
3608: @roles = ($ccrole);
3609: }
3610: foreach my $role (@roles) {
3611: my $refresh=$env{'user.refresh.time'};
3612: if ($refresh eq '') {
3613: $refresh = $env{'user.login.time'};
3614: }
3615: if ($refresh eq '') {
3616: $refresh = $now;
3617: }
3618: my $start = $refresh-1;
3619: my $end = '0';
3620: if ($role eq 'st') {
3621: if ($details->{'accessstart'} ne '') {
3622: $start = $details->{'accessstart'};
3623: }
3624: if ($details->{'accessend'} ne '') {
3625: $end = $details->{'accessend'};
3626: }
3627: }
3628: my @usecs;
3629: if ($role ne $ccrole) {
3630: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
3631: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
3632: }
3633: }
3634: if ($role eq 'st') {
3635: if (@usecs > 1) {
3636: my $firstsec = $usecs[0];
3637: @usecs = ($firstsec);
3638: }
3639: }
3640: if (@usecs == 0) {
3641: push(@usecs,'');
3642: }
3643: foreach my $usec (@usecs) {
3644: my (%userroles,%newrole,%newgroups,$spec,$area);
3645: my $area = '/'.$dom.'/'.$cnum;
3646: my $spec = $role.'.'.$area;
3647: if ($usec ne '') {
3648: $spec .= '/'.$usec;
3649: $area .= '/'.$usec;
3650: }
3651: if ($role =~ /^cr\//) {
3652: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
3653: $cnum,$spec,$area);
3654: } else {
3655: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
3656: $spec,$cnum,$area);
3657: }
3658: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
3659: \%newgroups);
3660: $userroles{'user.role.'.$spec} = $start.'.'.$end;
3661: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
3662: if (($end == 0) || ($end > $now)) {
3663: my $showrole = $role;
3664: if ($role =~ /^cr\//) {
3665: $showrole = &Apache::lonnet::plaintext($role,$crstype);
3666: } elsif (ref($longroles) eq 'HASH') {
3667: if ($longroles->{$role} ne '') {
3668: $showrole = $longroles->{$role};
3669: }
3670: }
3671: if ($start <= $now) {
3672: $active .= '<li><a href="/adm/roles?selectrole=1&'.
3673: $spec.'=1">'.$showrole;
3674: if ($usec ne '') {
3675: $active .= ' - '.&mt('section:').' '.$usec;
3676: }
3677: $active .= '</a></li>';
3678: $numactive ++;
3679: } else {
3680: $future .= '<li>'.$showrole;
3681: if ($usec ne '') {
3682: $future .= ' - '.&mt('section:').' '.$usec;
3683: }
3684: $future .= '</li>';
3685: $numfuture ++;
3686: }
3687: }
3688: }
3689: }
3690: }
3691: }
3692: if ($active) {
3693: if ($numactive == 1) {
3694: if ($crstype eq 'Community') {
3695: $output = &mt('Use the following link to enter the community:');
3696: } else {
3697: $output = &mt('Use the following link to enter the course:');
3698: }
3699: } else {
3700: if ($crstype eq 'Community') {
3701: $output = &mt('Use the following links to your new roles to enter the community:');
3702: } else {
3703: $output = &mt('Use the following links to your new roles to enter the course:');
3704: }
3705: }
3706: $output .= ' <ul>'.$active.'</ul><br />';
3707: }
3708: if ($future) {
3709: if ($crstype eq 'Community') {
3710: $output .= &mt('The following community [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'}))
3711: } else {
3712: $output .= &mt('The following course [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'}));
3713: }
3714: $output .= ' <ul>'.$future.'</ul>';
3715: }
3716: return $output;
3717: }
3718:
3719: sub notification_information {
3720: my ($disposition,$req_notifylist,$cnum,$now) = @_;
3721: my %emails = &Apache::loncommon::getemails();
3722: my $address;
3723: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
3724: $address = $emails{'permanentemail'};
3725: if ($address eq '') {
3726: $address = $emails{'notification'};
3727: }
3728: }
3729: my $output;
3730: if ($disposition eq 'approval') {
3731: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
3732: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
3733: if ($address ne '') {
3734: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
3735: }
3736: if ($req_notifylist) {
3737: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3738: $env{'user.domain'});
3739: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
3740: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
3741: }
3742: } elsif ($disposition eq 'pending') {
3743: $output .= '<div class="LC_info">'.
3744: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
3745: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
3746: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
3747: '</div>';
3748: } else {
3749: $output .= '<div class="LC_warning">'.
3750: &mt('Your request status is: [_1].',$disposition).
3751: '</div>';
3752: }
3753: return $output;
3754: }
3755:
3756: sub check_autolimit {
3757: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
3758: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
3759: 'userroles',['active','future'],['cc','co'],[$dom]);
3760: my ($types,$typename) = &Apache::loncommon::course_types();
3761: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
3762: my $count = 0;
3763: foreach my $key (keys(%requests)) {
3764: my ($cdom,$cnum) = split('_',$key);
3765: if (ref($requests{$key}) eq 'HASH') {
3766: next if ($requests{$key}{'crstype'} ne $crstype);
3767: if (($crstype eq 'community') &&
3768: (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
3769: $count ++;
3770: } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
3771: (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
3772: $count ++;
3773: }
3774: }
3775: }
3776: if ($count < $limit) {
3777: return 'process';
3778: } else {
3779: if (ref($typename) eq 'HASH') {
3780: if ($crstype eq 'community') {
3781: $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
3782: '<br />'.&mt("Your limit is [_1].",$limit);
3783: } else {
3784: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
3785: '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
3786: }
3787: }
3788: return 'rejected';
3789: }
3790: return;
3791: }
3792:
3793: sub retrieve_settings {
3794: my ($dom,$cnum,$udom,$uname) = @_;
3795: if ($udom eq '' || $uname eq '') {
3796: $udom = $env{'user.domain'};
3797: $uname = $env{'user.name'};
3798: }
3799: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
3800: if ($result eq 'ok') {
3801: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
3802: $env{'form.chome'} = $reqinfo{'coursehome'};
3803: $env{'form.cdescr'} = $reqinfo{'cdescr'};
3804: $env{'form.crstype'} = $reqinfo{'crstype'};
3805: &generate_date_items($reqinfo{'accessstart'},'accessstart');
3806: &generate_date_items($reqinfo{'accessend'},'accessend');
3807: if ($reqinfo{'accessend'} == 0) {
3808: $env{'form.no_end_date'} = 1;
3809: }
3810: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
3811: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
3812: &generate_date_items($reqinfo{'enrollend'},'enrollend');
3813: }
3814: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
3815: $env{'form.clonedom'} = $reqinfo{'clonedom'};
3816: if (($reqinfo{'clonecrs'} ne '') && ($reqinfo{'clonedom'} ne '')) {
3817: $env{'form.cloning'} = 1;
3818: }
3819: $env{'form.datemode'} = $reqinfo{'datemode'};
3820: $env{'form.dateshift'} = $reqinfo{'dateshift'};
3821: if ($reqinfo{'crstype'} eq 'official') {
3822: $env{'form.autoadds'} = $reqinfo{'autoadds'};
3823: $env{'form.autodrops'} = $reqinfo{'autodrops'};
3824: if ($reqinfo{'instcode'} ne '') {
3825: $env{'form.sectotal'} = $reqinfo{'sectotal'};
3826: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
3827: $env{'form.instcode'} = $reqinfo{'instcode'};
3828: my $crscode = {
3829: $cnum => $reqinfo{'instcode'},
3830: };
3831: &extract_instcode($dom,'instcode',$crscode,$cnum);
3832: }
3833: }
3834: my @currsec;
3835: if (ref($reqinfo{'sections'}) eq 'HASH') {
3836: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
3837: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
3838: my $sec = $reqinfo{'sections'}{$i}{'inst'};
3839: $env{'form.secnum_'.$i} = $sec;
3840: $env{'form.sec_'.$i} = '1';
3841: if (!grep(/^\Q$sec\E$/,@currsec)) {
3842: push(@currsec,$sec);
3843: }
3844: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
3845: }
3846: }
3847: }
3848: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
3849: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
3850: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
3851: $env{'form.crosslist_'.$i} = '1';
3852: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
3853: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
3854: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
3855: my $key = $cnum.$i;
3856: my $crscode = {
3857: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
3858: };
3859: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
3860: }
3861: }
3862: }
3863: }
3864: if (ref($reqinfo{'personnel'}) eq 'HASH') {
3865: my $i = 0;
3866: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
3867: my ($uname,$udom) = split(':',$user);
3868: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
3869: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
3870: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
3871: $env{'form.person_'.$i.'_role'} = $role;
3872: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
3873: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
3874: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
3875: $env{'form.person_'.$i.'_uname'} = $uname;
3876: $env{'form.person_'.$i.'_dom'} = $udom;
3877: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
3878: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
3879: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
3880: my @newsecs;
3881: if (@usecs > 0) {
3882: foreach my $sec (@usecs) {
3883: if (grep(/^\Q$sec\E/,@currsec)) {
3884: $env{'form.person_'.$i.'_sec'} = $sec;
3885: } else {
3886: push(@newsecs,$sec);
3887: }
3888: }
3889: }
3890: if (@newsecs > 0) {
3891: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
3892: }
3893: }
3894: }
3895: $i ++;
3896: }
3897: }
3898: }
3899: }
3900: $env{'form.persontotal'} = $i;
3901: }
3902: }
3903: }
3904: return $result;
3905: }
3906:
3907: sub get_request_settings {
3908: my ($dom,$cnum,$udom,$uname) = @_;
3909: my $requestkey = $dom.'_'.$cnum;
3910: my ($result,%reqinfo);
3911: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
3912: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
3913: my $disposition = $history{'disposition'};
3914: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
3915: if (ref($history{'details'}) eq 'HASH') {
3916: %reqinfo = %{$history{'details'}};
3917: $result = 'ok';
3918: } else {
3919: $result = 'nothash';
3920: }
3921: } else {
3922: $result = 'notqueued';
3923: }
3924: } else {
3925: $result = 'invalid';
3926: }
3927: return ($result,%reqinfo);
3928: }
3929:
3930: sub extract_instcode {
3931: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
3932: my (%codes,@codetitles,%cat_titles,%cat_order);
3933: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
3934: \@codetitles,\%cat_titles,
3935: \%cat_order) eq 'ok') {
3936: if (ref($codes{$crskey}) eq 'HASH') {
3937: if (@codetitles > 0) {
3938: my $sel = $element;
3939: if ($element eq 'crosslist') {
3940: $sel .= '_'.$counter;
3941: }
3942: foreach my $title (@codetitles) {
3943: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
3944: }
3945: }
3946: }
3947: }
3948: return;
3949: }
3950:
3951: sub generate_date_items {
3952: my ($currentval,$item) = @_;
3953: if ($currentval =~ /\d+/) {
3954: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
3955: &Apache::lonhtmlcommon::get_timedates($currentval);
3956: $env{'form.'.$item.'_day'} = $mday;
3957: $env{'form.'.$item.'_month'} = $month+1;
3958: $env{'form.'.$item.'_year'} = $year;
3959: }
3960: return;
3961: }
3962:
3963: 1;
3964:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>