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