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