Annotation of loncom/interface/lonrequestcourse.pm, revision 1.60
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.60 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.59 2010/11/19 00:01:25 raeburn Exp $
1.1 raeburn 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:
1.27 raeburn 47: =item get_breadcrumbs()
48:
1.12 raeburn 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:
1.27 raeburn 59: =item close_popup_form()
60:
61: =item get_instcode()
62:
1.12 raeburn 63: =item print_request_form()
64:
65: =item print_enrollment_menu()
66:
1.27 raeburn 67: =item show_invalid_crosslists()
68:
1.12 raeburn 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:
1.27 raeburn 103: =item extract_instcode()
104:
105: =item generate_date_items()
106:
1.1 raeburn 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;
1.8 raeburn 118: use Apache::loncoursequeueadmin;
1.30 raeburn 119: use Apache::lonuserutils;
1.4 raeburn 120: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 121:
122: sub handler {
123: my ($r) = @_;
1.20 raeburn 124: &Apache::loncommon::content_type($r,'text/html');
125: $r->send_http_header;
1.1 raeburn 126: if ($r->header_only) {
127: return OK;
128: }
129:
1.27 raeburn 130: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.49 raeburn 131: ['action','showdom','cnum','state','crstype','queue']);
1.2 raeburn 132: &Apache::lonhtmlcommon::clear_breadcrumbs();
133: my $dom = &get_course_dom();
1.1 raeburn 134: my $action = $env{'form.action'};
135: my $state = $env{'form.state'};
1.27 raeburn 136: my (%states,%stored);
137: my ($jscript,$uname,$udom,$result,$warning);
138:
139: $states{'display'} = ['details'];
140: $states{'view'} = ['pick_request','details','cancel','removal'];
1.48 raeburn 141: $states{'log'} = ['display'];
1.27 raeburn 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 = (
1.40 raeburn 158: crstype => 'Request Action',
1.27 raeburn 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',
1.48 raeburn 169: display => 'Request Logs',
1.27 raeburn 170: );
171:
172: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
173: $trail{'enrollment'} = 'Enrollment';
174: }
175:
1.36 raeburn 176: my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) =
1.27 raeburn 177: &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
1.26 raeburn 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'};
1.49 raeburn 182: my $queue = $env{'form.queue'};
183: my $reqkey = $cnum.'_'.$queue;
1.26 raeburn 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 {
1.40 raeburn 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: }
1.26 raeburn 199: }
200: } else {
1.40 raeburn 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: }
1.26 raeburn 206: }
207: } else {
208: $warning = &mt('No course request ID provided.');
209: }
210: } else {
1.40 raeburn 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: }
1.26 raeburn 218: }
219: } elsif ((defined($state)) && (defined($action))) {
1.16 raeburn 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'});
1.2 raeburn 223: }
1.27 raeburn 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 '') {
1.36 raeburn 251: ($codechk{$i}, my $rest) =
1.27 raeburn 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: }
1.2 raeburn 264: }
1.16 raeburn 265: my %elements = &form_elements($dom);
1.2 raeburn 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: }
1.16 raeburn 272: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
273: $env{'form.clonedom'} = $dom;
274: }
1.30 raeburn 275: if ($state eq 'crstype') {
276: $jscript = &mainmenu_javascript();
277: } else {
278: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
1.45 raeburn 279: if ($state eq 'courseinfo') {
280: $jscript .= &cloning_javascript();
281: }
1.30 raeburn 282: }
1.2 raeburn 283: }
284:
285: if ($state eq 'personnel') {
286: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
287: }
288:
289: my $loaditems = &onload_action($action,$state);
290:
1.39 raeburn 291: my (%can_request,%request_domains);
292: my $canreq =
293: &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains);
1.1 raeburn 294: if ($action eq 'new') {
295: if ($canreq) {
296: if ($state eq 'crstype') {
1.3 raeburn 297: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
1.39 raeburn 298: $crumb,\%request_domains);
1.1 raeburn 299: } else {
1.27 raeburn 300: &request_administration($r,$action,$state,$page,\%states,$dom,
301: $jscript,$loaditems,$crumb,$newinstcode,
1.36 raeburn 302: $codechk,$checkedcode,$description,
303: \@invalidcrosslist);
1.1 raeburn 304: }
305: } else {
1.40 raeburn 306: $r->print(&header('Course/Community Requests').$crumb.
1.1 raeburn 307: '<div class="LC_warning">'.
1.40 raeburn 308: &mt('You do not have privileges to request creation of courses or communities.').
1.2 raeburn 309: '</div>'.&Apache::loncommon::end_page());
1.1 raeburn 310: }
311: } elsif ($action eq 'view') {
1.10 raeburn 312: if ($state eq 'crstype') {
1.39 raeburn 313: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains);
1.26 raeburn 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 };
1.49 raeburn 321: $r->print(&header('Course/Community Requests','','' ,'',$args).$crumb.
1.40 raeburn 322: '<h3>'.&mt('Course/Community Request Details').'</h3>'.
1.26 raeburn 323: '<div class="LC_warning">'.$warning.'</div>'.
324: &close_popup_form());
1.11 raeburn 325: } else {
1.26 raeburn 326: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.36 raeburn 327: $loaditems,$crumb,'','','','','',$uname,$udom);
1.10 raeburn 328: }
1.1 raeburn 329: } elsif ($action eq 'log') {
1.48 raeburn 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: }
1.1 raeburn 348: } else {
1.39 raeburn 349: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
1.1 raeburn 350: }
351: return OK;
352: }
353:
1.30 raeburn 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:
1.45 raeburn 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:
1.27 raeburn 394: sub get_breadcrumbs {
395: my ($dom,$action,$state,$states,$trail) = @_;
1.36 raeburn 396: my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
1.27 raeburn 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 {
1.36 raeburn 421: ($codechk,$description) =
1.27 raeburn 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}"});
1.40 raeburn 439: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
1.27 raeburn 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'});
1.40 raeburn 459: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
1.27 raeburn 460: }
461: } else {
462: &Apache::lonhtmlcommon::add_breadcrumb(
463: {text=>'Pick Action'});
1.40 raeburn 464: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
1.27 raeburn 465: }
1.36 raeburn 466: return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
1.27 raeburn 467: }
468:
1.2 raeburn 469: sub header {
1.26 raeburn 470: my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
1.2 raeburn 471: if ($jscript) {
1.6 raeburn 472: $jscript = '<script type="text/javascript">'."\n".
473: '// <![CDATA['."\n".
474: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
1.2 raeburn 475: }
476: if ($loaditems) {
1.26 raeburn 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: }
1.3 raeburn 486: }
1.26 raeburn 487: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
1.2 raeburn 488: }
489:
490: sub form_elements {
491: my ($dom) = @_;
492: my %elements =
493: (
494: new => {
495: crstype => {
496: crstype => 'selectbox',
497: action => 'selectbox',
1.16 raeburn 498: origcnum => 'hidden',
1.2 raeburn 499: },
500: courseinfo => {
501: cdescr => 'text',
1.45 raeburn 502: cloning => 'radio',
1.13 raeburn 503: clonecrs => 'text',
504: clonedom => 'selectbox',
1.2 raeburn 505: datemode => 'radio',
506: dateshift => 'text',
507: },
508: enrollment => {
1.13 raeburn 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',
1.2 raeburn 521: no_end_date => 'checkbox',
522: },
523: personnel => {
524: addperson => 'checkbox',
525: },
1.13 raeburn 526: review => {
527: cnum => 'hidden',
528: },
1.2 raeburn 529: },
530: view => {
531: crstype => {
532: crstype => 'selectbox',
533: action => 'selectbox',
534: },
535: },
536: );
1.13 raeburn 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: }
1.2 raeburn 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',
1.13 raeburn 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',
1.2 raeburn 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++) {
1.31 raeburn 578: $extras{'sec_'.$i} = 'radio';
579: $extras{'secnum_'.$i} = 'text';
580: $extras{'loncapasec_'.$i} = 'text';
1.2 raeburn 581: }
582: }
583: my $crosslisttotal = $env{'form.crosslisttotal'};
1.16 raeburn 584: if ($env{'form.addcrosslist'}) {
585: $crosslisttotal ++;
586: }
1.24 raeburn 587: if (!$crosslisttotal) {
1.2 raeburn 588: $crosslisttotal = 1;
589: }
1.27 raeburn 590:
1.24 raeburn 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';
1.2 raeburn 598: }
599: }
1.24 raeburn 600: $extras{'crosslist_'.$i} = 'checkbox';
601: $extras{'crosslist_'.$i.'_instsec'} = 'text',
602: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
1.2 raeburn 603: }
604: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
605: %{$elements{'new'}{'enrollment'}} = %mergedhash;
606: }
607: my %people;
608: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 609: if ($env{'form.addperson'}) {
610: $persontotal ++;
611: }
612: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 613: $persontotal = 1;
614: }
615: for (my $i=0; $i<$persontotal; $i++) {
1.13 raeburn 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',
1.2 raeburn 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')) {
1.30 raeburn 635: if ($state eq 'crstype') {
636: $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
637: } else {
1.45 raeburn 638: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
639: }
640: if ($state eq 'courseinfo') {
641: $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);';
1.30 raeburn 642: }
1.2 raeburn 643: }
644: return \%loaditems;
645: }
646:
1.1 raeburn 647: sub print_main_menu {
1.39 raeburn 648: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_;
1.37 raeburn 649: my ($types,$typename) = &Apache::loncommon::course_types();
1.52 bisitz 650: my $onchange = 'this.form.submit()';
1.2 raeburn 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: }
1.1 raeburn 663:
1.2 raeburn 664: my $js = <<"END";
1.1 raeburn 665:
1.2 raeburn 666: function nextPage(formname) {
1.27 raeburn 667: var crschoice = document.mainmenu_coursetype.crstype.value;
668: var actionchoice = document.mainmenu_action.action.value;
1.2 raeburn 669: if (check_can_request(crschoice,actionchoice) == true) {
670: if ((actionchoice == 'new') && (crschoice == 'official')) {
671: nextstate = 'codepick';
672: } else {
673: $nextstate_setter
1.27 raeburn 674: }
675: formname.crstype.value = crschoice;
676: formname.action.value = actionchoice;
1.1 raeburn 677: formname.state.value= nextstate;
678: formname.submit();
679: }
680: return;
681: }
682:
1.2 raeburn 683: function check_can_request(crschoice,actionchoice) {
1.1 raeburn 684: var official = '';
685: var unofficial = '';
686: var community = '';
687: END
1.39 raeburn 688: if (ref($can_request) eq 'HASH') {
689: foreach my $item (keys(%{$can_request})) {
690: $js .= "
1.1 raeburn 691: $item = 1;
692: ";
1.39 raeburn 693: }
1.1 raeburn 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.',
1.51 raeburn 699: all => 'You must choose a specific course type when making a new course request.\\n\"All types\" is not allowed.',
1.1 raeburn 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
1.39 raeburn 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'}) {
1.40 raeburn 743: $pagetitle = 'Community Requests';
744: $pageinfo = &mt('Request creation of a new course, or review your pending requests.');
1.39 raeburn 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>'.
1.34 raeburn 766: '<div>'.
1.27 raeburn 767: &Apache::lonhtmlcommon::start_pick_box().
1.39 raeburn 768: &Apache::lonhtmlcommon::row_title($domaintitle).
1.1 raeburn 769: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
1.39 raeburn 770: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,\@incdoms));
1.1 raeburn 771: if (!$onchange) {
772: $r->print(' <input type="submit" name="godom" value="'.
773: &mt('Change').'" />');
774: }
1.39 raeburn 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: }
1.27 raeburn 781: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
1.2 raeburn 782: my $formname = 'requestcrs';
1.1 raeburn 783: my $nexttext = &mt('Next');
1.27 raeburn 784: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
785: <form name="mainmenu_action" method="post" action="">
1.1 raeburn 786: <select size="1" name="action" >
1.2 raeburn 787: <option value="new">'.&mt('New request').'</option>
1.1 raeburn 788: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
789: <option value="log">'.&mt('View request history').'</option>
1.27 raeburn 790: </select></form>'.
1.46 wenzelju 791: &Apache::lonhtmlcommon::row_closure().
1.39 raeburn 792: &Apache::lonhtmlcommon::row_title(&mt('Type')).'
1.27 raeburn 793: <form name="mainmenu_coursetype" method="post" action="">
1.39 raeburn 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");
1.4 raeburn 814: }
815: }
816: }
1.27 raeburn 817: $r->print('</select></form>'."\n".
818: &Apache::lonhtmlcommon::row_closure(1)."\n".
819: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
1.38 raeburn 820: '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n".
1.27 raeburn 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>');
1.1 raeburn 828: $r->print(&Apache::loncommon::end_page());
829: return;
830: }
831:
832: sub request_administration {
1.27 raeburn 833: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
1.36 raeburn 834: $newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist,
835: $uname,$udom) = @_;
1.2 raeburn 836: my $js;
1.16 raeburn 837: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
1.2 raeburn 838: $js = <<END;
1.1 raeburn 839:
840: function nextPage(formname,nextstate) {
841: formname.state.value= nextstate;
842: formname.submit();
843: }
1.16 raeburn 844:
845: END
846: }
847: if (($action eq 'new') || ($action eq 'view')) {
848: $js .= <<END;
849:
1.1 raeburn 850: function backPage(formname,prevstate) {
851: formname.state.value = prevstate;
852: formname.submit();
853: }
854:
855: END
1.2 raeburn 856: }
857: if ($action eq 'new') {
858: my $jsextra;
1.54 raeburn 859: if (($state eq 'courseinfo') || ($state eq 'codepick')) {
1.2 raeburn 860: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.31 raeburn 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();
1.1 raeburn 868: }
1.40 raeburn 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);
1.27 raeburn 876: &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
1.36 raeburn 877: $codechk,$checkedcode,$description,$invalidcrosslist);
1.2 raeburn 878: } elsif ($action eq 'view') {
1.16 raeburn 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: }
1.40 raeburn 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);
1.16 raeburn 899: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
1.11 raeburn 900: if ($state eq 'pick_request') {
1.40 raeburn 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".
1.48 raeburn 912: &print_request_status($dom,$action).'</form></div>');
1.16 raeburn 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: }
1.40 raeburn 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".
1.26 raeburn 930: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.16 raeburn 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: );
1.31 raeburn 942: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
943: $navtxt{'next'},$state,$other,$navtxt{'other'});
1.16 raeburn 944: $r->print('</form>');
945: } elsif ($state eq 'cancel') {
1.40 raeburn 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: }
1.16 raeburn 952: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
1.40 raeburn 953: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.16 raeburn 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') {
1.31 raeburn 962: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1.16 raeburn 963: $navtxt{'next'},$state);
964: } else {
1.31 raeburn 965: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
966: '',$state);
1.16 raeburn 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') {
1.40 raeburn 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: }
1.16 raeburn 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>');
1.11 raeburn 1013: }
1.26 raeburn 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: }
1.40 raeburn 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>'.
1.26 raeburn 1031: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1032: \@code_order,$uname,$udom)."\n".'</div>'.
1033: &close_popup_form());
1.1 raeburn 1034: }
1.2 raeburn 1035: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 1036: return;
1037: }
1038:
1.31 raeburn 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:
1.26 raeburn 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:
1.27 raeburn 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:
1.1 raeburn 1224: sub print_request_form {
1.27 raeburn 1225: my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1.36 raeburn 1226: $description,$invalidcrosslist) = @_;
1.1 raeburn 1227: my $formname = 'requestcrs';
1.2 raeburn 1228: my ($next,$prev,$message,$output,$codepicker,$crstype);
1229: $prev = $states->{$action}[$page-1];
1230: $next = $states->{$action}[$page+1];
1.4 raeburn 1231: my %navtxt = &Apache::lonlocal::texthash (
1.10 raeburn 1232: prev => 'Back',
1.4 raeburn 1233: next => 'Next',
1234: );
1.2 raeburn 1235: $crstype = $env{'form.crstype'};
1.34 raeburn 1236: $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.30 raeburn 1237: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
1238: @disallowed);
1.1 raeburn 1239: if ($crstype eq 'official') {
1.2 raeburn 1240: if ($env{'form.instcode'} ne '') {
1241: $instcode = $env{'form.instcode'};
1.27 raeburn 1242: } elsif ($newinstcode ne '') {
1243: $instcode = $newinstcode;
1.2 raeburn 1244: }
1.27 raeburn 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>';
1.2 raeburn 1252: } else {
1253: $message = '<div class="LC_warning">'.
1.27 raeburn 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>';
1.2 raeburn 1259: $prev = 'crstype';
1260: }
1261: $r->print($message);
1.1 raeburn 1262: }
1.2 raeburn 1263: }
1264: if ($prev eq 'crstype') {
1.4 raeburn 1265: if ($crstype eq 'official') {
1266: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1267: \%cat_order,\@code_order);
1268: }
1.2 raeburn 1269: if (@code_order > 0) {
1.1 raeburn 1270: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
1271: \%cat_titles,\%cat_order);
1.2 raeburn 1272: if ($codepicker) {
1.34 raeburn 1273: $r->print(&mt('Specify the course to be created.').
1274: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1275: $codepicker.
1.2 raeburn 1276: &Apache::lonhtmlcommon::end_pick_box().'</div>');
1277: } else {
1.20 raeburn 1278: $next = $states->{$action}[$page+2];
1.15 raeburn 1279: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 1280: }
1281: } else {
1.20 raeburn 1282: if ($crstype eq 'official') {
1283: $next = $states->{$action}[$page+2];
1284: }
1.15 raeburn 1285: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.1 raeburn 1286: }
1.2 raeburn 1287: } elsif ($prev eq 'codepick') {
1.27 raeburn 1288: if ($instcode eq '') {
1.20 raeburn 1289: $prev = $states->{$action}[$page-2];
1290: }
1.36 raeburn 1291: $r->print(&courseinfo_form($dom,$formname,$crstype,$next,$description));
1.2 raeburn 1292: } elsif ($state eq 'enrollment') {
1.4 raeburn 1293: if ($crstype eq 'official') {
1294: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1295: \%cat_order,\@code_order);
1296: }
1.2 raeburn 1297: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
1.27 raeburn 1298: \%cat_titles,\%cat_order,\@code_order,
1299: $invalidcrosslist));
1.2 raeburn 1300: } elsif ($state eq 'personnel') {
1.27 raeburn 1301: $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
1.4 raeburn 1302: } elsif ($state eq 'review') {
1.30 raeburn 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);
1.60 ! raeburn 1325: $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
1.30 raeburn 1326: next;
1327: }
1328: }
1.60 ! raeburn 1329: my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules);
! 1330: if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) {
! 1331: my ($allowed,$msg,$authtype,$authparam) =
1.30 raeburn 1332: &check_newuser_rules($persondom,$personname,
1333: \%alerts,\%rulematch,\%inst_results,
1334: \%curr_rules,\%got_rules);
1335: if ($allowed) {
1.60 ! raeburn 1336: my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom);
! 1337: if ($usertype eq 'official') {
! 1338: if ($authtype eq '') {
! 1339: $authtype = $domdefaults{'auth_def'};
! 1340: $authparam = $domdefaults{'auth_arg_def'};
! 1341: }
! 1342: } elsif ($usertype eq 'unofficial') {
! 1343: if ($authtype eq '') {
! 1344: $authtype = 'internal';
! 1345: $authparam = '';
! 1346: }
! 1347: } else {
! 1348: $authtype = $domdefaults{'auth_def'};
! 1349: $authparam = $domdefaults{'auth_arg_def'};
! 1350: }
! 1351: if (($authtype eq '') ||
! 1352: (($authtype =~/^krb/) && ($authparam eq ''))) {
! 1353: push(@disallowed,$i);
! 1354: $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.','<tt>'.$personname.':'.$persondom.'</tt>');
! 1355: next;
! 1356: }
1.30 raeburn 1357: if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
1358: if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
1359: $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
1360: }
1361: if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
1362: $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
1363: }
1364: if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
1365: $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
1366: }
1367: }
1368: } else {
1369: push(@disallowed,$i);
1370: $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1371: }
1372: } else {
1373: push(@disallowed,$i);
1374: $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1375: }
1376: } else {
1377: my %userenv =
1378: &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
1379: if ($env{'form.person_'.$i.'_lastname'} eq '') {
1380: $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
1381: }
1382: if ($env{'form.person_'.$i.'_firstname'} eq '') {
1383: $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
1384: }
1385: if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
1386: $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
1387: }
1388: }
1389: } elsif ($personname ne '') {
1390: push(@disallowed,$i);
1391: $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
1392: }
1393: } elsif ($personname ne '') {
1394: push(@disallowed,$i);
1395: $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
1396: }
1397: }
1.16 raeburn 1398: my $cnum;
1399: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
1400: $cnum = $env{'form.origcnum'};
1401: } else {
1.47 raeburn 1402: my $gentype = 'Course';
1403: if ($crstype eq 'community') {
1404: $gentype = 'Community';
1405: }
1406: $cnum = &Apache::lonnet::generate_coursenum($dom,$gentype);
1.16 raeburn 1407: }
1.4 raeburn 1408: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1409: \%cat_order,\@code_order);
1.40 raeburn 1410: if ($crstype eq 'community') {
1411: $r->print('<h3>'.&mt('Review community request details before submission').'</h3>');
1412: } else {
1413: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>');
1414: }
1415: $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg).
1.16 raeburn 1416: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.40 raeburn 1417: if ($crstype eq 'community') {
1418: $navtxt{'next'} = &mt('Submit community request');
1419: } else {
1420: $navtxt{'next'} = &mt('Submit course request');
1421: }
1.10 raeburn 1422: } elsif ($state eq 'process') {
1423: if ($crstype eq 'official') {
1424: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1425: \%cat_order,\@code_order);
1426: }
1.27 raeburn 1427: my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles,
1428: \@code_order);
1.13 raeburn 1429: $r->print($result);
1.27 raeburn 1430: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1431: $r->print('<p>');
1432: if ($storeresult eq 'ok') {
1433: $r->print('<a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1434: &mt('Modify this request').'</a>'.(' 'x4));
1435: }
1436: $r->print('<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1437: return;
1438: }
1.1 raeburn 1439: }
1.16 raeburn 1440: my @excluded = &get_excluded_elements($dom,$states,$action,$state);
1.24 raeburn 1441: if ($state eq 'personnel') {
1442: push(@excluded,'persontotal');
1443: }
1.30 raeburn 1444: if ($state eq 'review') {
1445: if (@disallowed > 0) {
1446: my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
1447: my @currsecs = ¤t_lc_sections();
1448: if (@currsecs) {
1449: push(@items,'sec');
1450: }
1451: my $count = 0;
1452: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1453: unless ($env{'form.person_'.$i.'_uname'} eq '') {
1454: if (grep(/^$i$/,@disallowed)) {
1455: foreach my $item (@items) {
1456: $env{'form.person_'.$i.'_'.$item} = '';
1457: }
1458: } else {
1459: foreach my $item (@items) {
1460: $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
1461: }
1462: }
1463: }
1464: $count ++;
1465: }
1466: $env{'form.persontotal'} = $count;
1467:
1468: }
1469: }
1.27 raeburn 1470: if ($state eq 'enrollment') {
1471: push(@excluded,'crosslisttotal');
1472: }
1.16 raeburn 1473: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1.31 raeburn 1474: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1475: $navtxt{'next'},$state);
1.16 raeburn 1476: return;
1477: }
1478:
1.60 ! raeburn 1479: sub get_usertype {
! 1480: my ($persondom,$personname,$curr_rules,$got_rules) = @_;
1.30 raeburn 1481: my ($rules,$ruleorder) =
1482: &Apache::lonnet::inst_userrules($persondom,'username');
1483: my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1.60 ! raeburn 1484: $rules,$curr_rules,$got_rules);
! 1485: return $usertype;
1.30 raeburn 1486: }
1487:
1488: sub check_newuser_rules {
1489: my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
1490: $got_rules) = @_;
1491: my $allowed = 1;
1492: my $newuser = 1;
1.60 ! raeburn 1493: my ($checkhash,$userchkmsg,$authtype,$authparam);
1.30 raeburn 1494: my $checks = { 'username' => 1 };
1495: $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
1496: &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
1497: $inst_results,$curr_rules,$got_rules);
1498: if (ref($alerts->{'username'}) eq 'HASH') {
1499: if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
1500: my $domdesc =
1501: &Apache::lonnet::domain($persondom,'description');
1502: if ($alerts->{'username'}{$persondom}{$personname}) {
1503: if (ref($curr_rules->{$persondom}) eq 'HASH') {
1504: $userchkmsg =
1505: &Apache::loncommon::instrule_disallow_msg('username',
1506: $domdesc,1).
1507: &Apache::loncommon::user_rule_formats($persondom,
1508: $domdesc,$curr_rules->{$persondom}{'username'},
1509: 'username');
1510: }
1511: $allowed = 0;
1512: }
1513: }
1514: }
1.60 ! raeburn 1515: if ($allowed) {
! 1516: if (ref($rulematch) eq 'HASH') {
! 1517: if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') {
! 1518: my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'};
! 1519: my ($rules,$ruleorder) =
! 1520: &Apache::lonnet::inst_userrules($persondom,'username');
! 1521: if (ref($rules) eq 'HASH') {
! 1522: if (ref($rules->{$matchedrule}) eq 'HASH') {
! 1523: $authtype = $rules->{$matchedrule}{'authtype'};
! 1524: $authparam = $rules->{$matchedrule}{'authparm'};
! 1525: }
! 1526: }
! 1527: }
! 1528: }
! 1529: }
! 1530: return ($allowed,$userchkmsg,$authtype,$authparam);
1.30 raeburn 1531: }
1532:
1.16 raeburn 1533: sub get_excluded_elements {
1534: my ($dom,$states,$action,$state) = @_;
1.2 raeburn 1535: my @excluded = ('counter');
1536: my %elements = &form_elements($dom);
1537: if (ref($states) eq 'HASH') {
1538: if (ref($states->{$action}) eq 'ARRAY') {
1539: my @items = @{$states->{$action}};
1540: my $numitems = scalar(@items);
1541: if ($numitems) {
1542: for (my $i=$numitems-1; $i>=0; $i--) {
1543: if (ref($elements{$action}) eq 'HASH') {
1544: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1.16 raeburn 1545: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1.2 raeburn 1546: push(@excluded,$key);
1547: }
1548: }
1549: }
1550: last if ($items[$i] eq $state);
1551: }
1552: }
1553: }
1554: }
1555: if (grep(/^instcode_/,@excluded)) {
1556: push(@excluded,'instcode');
1.1 raeburn 1557: }
1.16 raeburn 1558: return @excluded;
1.1 raeburn 1559: }
1560:
1.2 raeburn 1561: sub print_enrollment_menu {
1.27 raeburn 1562: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1563: $invalidcrosslist) =@_;
1.34 raeburn 1564: my ($sections,$autoenroll,$access_dates,$output,$hasauto);
1.2 raeburn 1565: my $starttime = time;
1566: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1567:
1568: my %accesstitles = (
1569: 'start' => 'Default start access',
1.16 raeburn 1570: 'end' => 'Default end access',
1.2 raeburn 1571: );
1572: my %enrolltitles = (
1573: 'start' => 'Start auto-enrollment',
1574: 'end' => 'End auto-enrollment',
1575: );
1576: if ($env{'form.crstype'} eq 'official') {
1577: if (&Apache::lonnet::auto_run('',$dom)) {
1.27 raeburn 1578: $output = &show_invalid_crosslists($invalidcrosslist);
1579: my ($section_form,$crosslist_form);
1.2 raeburn 1580: $section_form = &inst_section_selector($dom,$instcode);
1.27 raeburn 1581: if ($section_form) {
1582: $sections = &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 1583: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
1584: ' '.&mt('Sections for auto-enrollment').'</h3>'.
1.27 raeburn 1585: &Apache::lonhtmlcommon::row_closure(1).
1586: $section_form;
1587: }
1.2 raeburn 1588: my $crosslisttotal = $env{'form.crosslisttotal'};
1.24 raeburn 1589: if (!$crosslisttotal) {
1.2 raeburn 1590: $crosslisttotal = 1;
1591: }
1592: if ($env{'form.addcrosslist'}) {
1593: $crosslisttotal ++;
1594: }
1595: for (my $i=0; $i<$crosslisttotal; $i++) {
1596: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1597: $cat_titles,$cat_order,$i);
1598: }
1599: if ($crosslist_form) {
1600: $crosslist_form .=
1.40 raeburn 1601: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2 raeburn 1602: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1603: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1604: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1.27 raeburn 1605: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1606: $sections .= &Apache::lonhtmlcommon::row_headline.
1607: '<h3>'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1608: &Apache::lonhtmlcommon::row_closure(1).
1609: $crosslist_form;
1.2 raeburn 1610: }
1.34 raeburn 1611: $hasauto = 1;
1.27 raeburn 1612: $autoenroll =
1.34 raeburn 1613: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')).
1.2 raeburn 1614: '<span class="LC_nobreak"><label>'.
1615: '<input type="radio" name="autoadds" value="1">'.
1616: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1617: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1618: &mt('No').'</label></span>'.
1.27 raeburn 1619: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1620: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')).
1.2 raeburn 1621: '<span class="LC_nobreak"><label>'.
1622: '<input type="radio" name="autodrops" value="1">'.
1623: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1624: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1625: &mt('No').'</label></span>'.
1.27 raeburn 1626: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1627: &date_setting_table($starttime,$endtime,$formname,'enroll',
1628: $hasauto,%enrolltitles);
1.2 raeburn 1629: }
1630: }
1.27 raeburn 1631: my $access_dates =
1.34 raeburn 1632: &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
1633: %accesstitles);
1.27 raeburn 1634: $output .= &Apache::lonhtmlcommon::start_pick_box();
1635: if ($sections) {
1636: $output .= $sections;
1637: }
1638: if ($autoenroll) {
1639: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1640: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1641: &Apache::lonhtmlcommon::row_closure(1).
1642: $autoenroll;
1643: }
1644: if ($access_dates) {
1645: my $header = &mt('Access dates for students');
1646: if ($env{'form.crstype'} eq 'community') {
1647: $header = &mt('Access dates for community members');
1648: }
1649: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1650: '<h3>'.$header.'</h3>'.
1651: &Apache::lonhtmlcommon::row_closure(1).
1652: $access_dates
1.2 raeburn 1653: }
1.27 raeburn 1654: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1655: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.2 raeburn 1656: }
1657:
1.27 raeburn 1658: sub show_invalid_crosslists {
1659: my ($invalidcrosslist) = @_;
1660: my $output;
1661: if (ref($invalidcrosslist) eq 'ARRAY') {
1662: if (@{$invalidcrosslist} > 0) {
1663: $output = '<div class="LC_warning">'.
1664: &mt('The following crosslisted courses were invalid:').'<ul>';
1665: foreach my $item (@{$invalidcrosslist}) {
1666: $output .= '<li>'.$item.'</li>';
1667: }
1668: $output .= '</ul></div><br />';
1669: }
1670: }
1671: return $output;
1672: }
1673:
1674:
1.1 raeburn 1675: sub inst_section_selector {
1.2 raeburn 1676: my ($dom,$instcode) = @_;
1677: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1678: my $sectotal = scalar(@sections);
1.1 raeburn 1679: my $output;
1.2 raeburn 1680: if ($sectotal) {
1.27 raeburn 1681: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1.2 raeburn 1682: &Apache::loncommon::start_data_table().
1683: &Apache::loncommon::start_data_table_row().
1684: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1.24 raeburn 1685: 'value="'.$sectotal.'" /></th>'.
1.2 raeburn 1686: '<th>'.&mt('Institutional Section').'</th>'.
1.34 raeburn 1687: '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
1688: ' '.&mt('LON-CAPA section').'</th>'.
1.2 raeburn 1689: &Apache::loncommon::end_data_table_row();
1690: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 1691: my $colflag = $i%2;
1.31 raeburn 1692: my $secon = ' checked="checked"';
1693: my $secoff = '';
1.24 raeburn 1694: if ($env{'form.origcnum'}) {
1.31 raeburn 1695: $secoff = $secon;
1696: $secon='';
1.24 raeburn 1697: }
1.1 raeburn 1698: $output .= &Apache::loncommon::start_data_table_row().
1.31 raeburn 1699: '<td><label><input type="radio" name="sec_'.$i.
1700: '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
1701: (' 'x2).'<label><input type="radio" name="sec_'.$i.
1702: '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
1703: '<td align="center">'.$sections[$i].
1.1 raeburn 1704: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 1705: $sections[$i].'" /></td>'.
1.1 raeburn 1706: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 1707: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 1708: &Apache::loncommon::end_data_table_row();
1709: }
1.2 raeburn 1710: $output .= &Apache::loncommon::end_data_table().
1711: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1712: }
1713: return $output;
1714: }
1715:
1.2 raeburn 1716: sub date_setting_table {
1.34 raeburn 1717: my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_;
1.2 raeburn 1718: my ($perpetual,$table);
1.14 raeburn 1719: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.2 raeburn 1720: $starttime,'','','',1,'','','',1);
1.14 raeburn 1721: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.2 raeburn 1722: $endtime,'','','',1,'','','',1);
1.27 raeburn 1723: my $closure = '';
1.14 raeburn 1724: if ($prefix eq 'access') {
1.2 raeburn 1725: $perpetual = ' <span class="LC_nobreak"><label>'.
1726: '<input type="checkbox" name="no_end_date" />'.
1727: &mt('No end date').'</label></span>';
1.27 raeburn 1728: $closure = '1';
1.2 raeburn 1729: }
1.34 raeburn 1730:
1731: my %help_item = (
1732: access => {
1733: start => 'Course_Request_Access_Start',
1734: end => 'Course_Request_Access_End',
1735: },
1736: enroll => {
1737: start => 'Course_Request_Enroll_Start',
1738: end => 'Course_Request_Enroll_End',
1739: },
1740: );
1741: if ($hasauto) {
1742: $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
1743: $help_item{'access'}{'end'} = 'Course_Request_RegAccess_End';
1744: }
1745:
1746: $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
1.46 wenzelju 1747: ' '.&mt($datetitles{'start'})).$startform.
1.27 raeburn 1748: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1749: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
1.46 wenzelju 1750: ' '.&mt($datetitles{'end'})).$endform.$perpetual.
1.27 raeburn 1751: &Apache::lonhtmlcommon::row_closure($closure);
1.2 raeburn 1752: return $table;
1753: }
1754:
1755: sub print_personnel_menu {
1.27 raeburn 1756: my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
1757: my $output;
1758: if ($crstype eq 'official') {
1759: if (&Apache::lonnet::auto_run('',$dom)) {
1760: $output .= &show_invalid_crosslists($invalidcrosslist);
1761: }
1762: }
1763: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1.2 raeburn 1764: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 1765: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 1766: $persontotal = 1;
1767: }
1768: if ($env{'form.addperson'}) {
1769: $persontotal ++;
1770: }
1.13 raeburn 1771: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2 raeburn 1772:
1.8 raeburn 1773: my $type = 'Course';
1774: if ($crstype eq 'community') {
1775: $type = 'Community';
1776: }
1.41 raeburn 1777: my $roleoptions;
1778: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.2 raeburn 1779: foreach my $role (@roles) {
1.28 raeburn 1780: my $plrole = &Apache::lonnet::plaintext($role,$type);
1.2 raeburn 1781: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1782: }
1783: my %customroles=&Apache::lonuserutils::my_custom_roles();
1784: if (keys(%customroles) > 0) {
1785: foreach my $cust (sort(keys(%customroles))) {
1.28 raeburn 1786: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1.2 raeburn 1787: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1788: }
1789: }
1790:
1.30 raeburn 1791: my @currsecs = ¤t_lc_sections();
1.2 raeburn 1792:
1793: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1794: if (@currsecs) {
1795: my $existsize = scalar(@currsecs);
1796: if ($existsize > 3) {
1797: $existsize = 3;
1798: }
1799: if ($existsize > 1) {
1800: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1801: }
1802: @currsecs = sort { $a <=> $b } (@currsecs);
1803: $existtitle = &mt('Official').': ';
1804: $existops = '<option value="">'.&mt('None').'</option>';
1805: foreach my $sec (@currsecs) {
1806: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1807: }
1808: $seccolspan = ' colspan="2"';
1809: $newtitle = &mt('Other').': ';
1810: }
1811:
1.27 raeburn 1812: if ($persontotal) {
1.32 raeburn 1813: my %lt = &Apache::lonlocal::texthash(
1814: community => 'Requestor is automatically assigned Coordinator role.',
1815: official => 'Requestor is automatically assigned Course Coordinator role.',
1816: );
1817: $lt{'unofficial'} = $lt{'official'};
1.27 raeburn 1818: $output .= &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 1819: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
1.27 raeburn 1820: }
1.2 raeburn 1821: for (my $i=0; $i<$persontotal; $i++) {
1822: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1823: my $linkargstr = join("','",@linkargs);
1.29 raeburn 1824: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1.2 raeburn 1825: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1.29 raeburn 1826: "'person_".$i."_hidedom','person_".$i."_uname'".');';
1.2 raeburn 1827: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1828: 1,$onchange).
1.29 raeburn 1829: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1.2 raeburn 1830: my %form_elems;
1831: foreach my $item (@items) {
1832: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1833: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1834: 'value="" readonly="readonly" />';
1835: }
1836: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1837: $roleoptions.'</select>';
1838: my $sectionselector;
1839: if (@currsecs) {
1840: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1841: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1842: }
1843: $sectionselector .= $newtitle.
1.14 raeburn 1844: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.29 raeburn 1845: my $usersrchlinktxt = &mt('Search for user');
1846: my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1847: $usersrchlinktxt);
1848: my $userchklinktxt = &mt('Check username');
1849: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1850: $userchklinktxt,'checkusername');
1.2 raeburn 1851: $output .=
1.29 raeburn 1852: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
1853: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
1854: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
1855: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
1856: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
1857: '</tr>'."\n".'<tr>'.
1.13 raeburn 1858: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1859: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1860: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.34 raeburn 1861: '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
1862: '<td'.$seccolspan.' align="center" valign="top">'.
1863: &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1.2 raeburn 1864: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
1865: }
1.40 raeburn 1866: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2 raeburn 1867: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
1868: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1869: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1870: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1.40 raeburn 1871: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1872: if ($crstype eq 'community') {
1873: $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>';
1874: } else {
1875: $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>';
1876: }
1.2 raeburn 1877: return $output;
1878: }
1879:
1.30 raeburn 1880: sub current_lc_sections {
1881: my @currsecs;
1882: if ($env{'form.sectotal'}) {
1883: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31 raeburn 1884: if ($env{'form.sec_'.$i}) {
1885: if (defined($env{'form.loncapasec_'.$i})) {
1886: my $lcsec = $env{'form.loncapasec_'.$i};
1887: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
1888: push(@currsecs,$lcsec);
1889: }
1.30 raeburn 1890: }
1891: }
1892: }
1893: }
1894: return @currsecs;
1895: }
1896:
1.48 raeburn 1897: sub sorted_request_history {
1.49 raeburn 1898: my ($dom,$action,$curr_req) = @_;
1899: my ($after,$before,$statusfilter,$crstypefilter);
1900: if ($env{'form.status'} ne '') {
1901: $statusfilter = $env{'form.status'};
1902: }
1903: if ($env{'form.crstype'} ne '') {
1904: $crstypefilter = $env{'form.crstype'};
1905: }
1906: if (ref($curr_req) eq 'HASH') {
1907: $after = $curr_req->{'requested_after_date'},
1908: $before = $curr_req->{'requested_before_date'};
1909: $statusfilter = $curr_req->{'status'};
1910: $crstypefilter = $curr_req->{'crstype'};
1911: }
1.14 raeburn 1912: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
1913: $env{'user.name'},'^status:'.$dom);
1.48 raeburn 1914: my %queue_by_date;
1.37 raeburn 1915: my ($types,$typenames) = &Apache::loncommon::course_types();
1.14 raeburn 1916: foreach my $key (keys(%statusinfo)) {
1.48 raeburn 1917: if ($action eq 'view') {
1918: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
1919: } else {
1.49 raeburn 1920: next unless (($statusfilter eq 'any') ||
1921: ($statusfilter eq $statusinfo{$key}));
1.48 raeburn 1922: }
1923: (undef,my($cdom,$cnum)) = split(':',$key);
1924: next if ($cdom ne $dom);
1925: my $requestkey = $cdom.'_'.$cnum;
1926: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1927: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1928: $env{'user.domain'},$env{'user.name'});
1929: my $entry;
1930: my $reqtime = $history{'reqtime'};
1931: my $lastupdate = $history{'timestamp'};
1932: my $crstype = $history{'crstype'};
1933: my $disposition = $history{'disposition'};
1934: my $status = $history{'status'};
1935: if ($action eq 'view') {
1.14 raeburn 1936: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1.48 raeburn 1937: } else {
1938: next if (($reqtime < $after) || ($reqtime > $before));
1939: }
1.49 raeburn 1940: next unless (($crstypefilter eq 'any') ||
1941: ($crstypefilter eq $crstype));
1.48 raeburn 1942: if ($action eq 'view') {
1.14 raeburn 1943: next unless (($disposition eq 'approval') ||
1944: ($disposition eq 'pending'));
1.48 raeburn 1945: }
1946: if (ref($history{'details'}) eq 'HASH') {
1947: $entry = $requestkey.':'.$crstype.':'.
1948: &escape($history{'details'}{'cdescr'});
1949: if ($action eq 'log') {
1950: $entry .= ':'.$lastupdate.':';
1951: if ($statusinfo{$key} ne '') {
1952: $entry .= $statusinfo{$key};
1953: } elsif ($status ne '') {
1954: $entry .= $status;
1955: } else {
1956: $entry .= $disposition;
1.14 raeburn 1957: }
1958: }
1.48 raeburn 1959: if ($crstype eq 'official') {
1960: $entry .= ':'.&escape($history{'details'}{'instcode'});
1961: }
1962: }
1963: if ($entry ne '') {
1964: if (exists($queue_by_date{$reqtime})) {
1965: if (ref($queue_by_date{$reqtime}) eq 'ARRAY') {
1966: push(@{$queue_by_date{$reqtime}},$entry);
1.10 raeburn 1967: }
1.48 raeburn 1968: } else {
1969: @{$queue_by_date{$reqtime}} = ($entry);
1.10 raeburn 1970: }
1971: }
1972: }
1973: }
1.48 raeburn 1974: return %queue_by_date;
1975: }
1976:
1977: sub print_request_status {
1978: my ($dom,$action) = @_;
1979: my %queue_by_date = &sorted_request_history($dom,$action);
1.10 raeburn 1980: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.48 raeburn 1981: my $formname = 'requestcrs';
1982: my ($types,$typenames) = &Apache::loncommon::course_types();
1983: my $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.16 raeburn 1984:
1.10 raeburn 1985: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1.16 raeburn 1986: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
1987: '<input type="hidden" name="showdom" value="" />'."\n".
1988: '<input type="hidden" name="cnum" value="" />'."\n";
1.10 raeburn 1989: if (@sortedtimes > 0) {
1.40 raeburn 1990: my $desctitle;
1991: if ($env{'form.crstype'} eq 'any') {
1992: $desctitle = &mt('Course/Community Description')
1993: } elsif ($env{'form.crstype'} eq 'community') {
1994: $desctitle = &mt('Community Description')
1995: } else {
1996: $desctitle = &mt('Course Description');
1997: }
1.10 raeburn 1998: $output .= &Apache::loncommon::start_data_table().
1999: &Apache::loncommon::start_data_table_header_row().
2000: '<th>'.&mt('Action').'</th>'.
1.40 raeburn 2001: '<th>'.$desctitle.'</th>'.
1.14 raeburn 2002: '<th>'.&mt('Domain').'</th>';
2003: if ($env{'form.crstype'} eq 'any') {
1.10 raeburn 2004: $output .= '<th>'.&mt('Type').'</th>';
2005: }
1.14 raeburn 2006: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10 raeburn 2007: $output .= '<th>'.&mt('Institutional Code').'</th>';
2008: }
2009: $output .= '<th>'.&mt('Date requested').'</th>'.
2010: &Apache::loncommon::end_data_table_header_row();
2011: my $count = 0;
2012: foreach my $item (@sortedtimes) {
2013: my $showtime = &Apache::lonlocal::locallocaltime($item);
2014: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2015: foreach my $request (sort(@{$queue_by_date{$item}})) {
2016: my ($key,$type,$desc,$instcode) = split(':',$request);
2017: my ($cdom,$cnum) = split('_',$key);
2018: $output .= &Apache::loncommon::start_data_table_row().
1.16 raeburn 2019: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14 raeburn 2020: '<td>'.&unescape($desc).'</td>'.
2021: '<td>'.$cdom.'</td>';
2022: if ($env{'form.crstype'} eq 'any') {
1.35 raeburn 2023: my $typename;
2024: if (ref($typenames) eq 'HASH') {
2025: $typename = &mt($typenames->{$type});
2026: }
1.14 raeburn 2027: if ($typename eq '') {
2028: $typename = &mt('Unknown type');
2029: }
2030: $output .= '<td>'.$typename.'</td>';
1.10 raeburn 2031: }
1.14 raeburn 2032: if (($env{'form.crstype'} eq 'any') ||
1.10 raeburn 2033: ($env{'form.crstype'} eq 'official')) {
1.14 raeburn 2034: my $showinstcode;
2035: if ($type eq 'official') {
2036: $showinstcode = &unescape($instcode);
2037: } else {
2038: $showinstcode = &mt('Not applicable');
2039: }
2040: $output .= '<td>'.$showinstcode.'</td>';
1.10 raeburn 2041: }
2042: $output .= '<td>'.$showtime.'</td>'.
2043: &Apache::loncommon::end_data_table_row();
2044: }
2045: }
2046: }
2047: $output .= &Apache::loncommon::end_data_table();
2048: } else {
1.40 raeburn 2049: if ($env{'form.crstype'} eq 'any') {
2050: $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>';
2051: } elsif ($env{'form.crstype'} eq 'community') {
2052: $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>';
2053: } else {
2054: $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>';
2055: }
1.10 raeburn 2056: }
2057: $output .= '
1.30 raeburn 2058: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
1.10 raeburn 2059: return $output;
1.1 raeburn 2060: }
2061:
1.16 raeburn 2062: sub print_cancel_request {
2063: my ($dom,$cnum) = @_;
2064: my $requestkey = $dom.'_'.$cnum;
2065: my ($result,$output);
2066: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2067: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2068: $env{'user.domain'},$env{'user.name'});
2069: my $timestamp = $history{'reqtime'};
2070: my $crstype = $history{'crstype'};
2071: my $status = $history{'status'};
2072: if (($status eq 'cancelled') || ($status eq 'created')) {
2073: if ($status eq 'cancelled') {
2074: $output = &mt('This request has already been cancelled.');
2075: } elsif ($status eq 'created') {
2076: $output = &mt('This request has already been processed, and a course created.');
2077: }
2078: $output = &mt('No further action will be taken');
2079: } elsif (ref($history{'details'}) eq 'HASH') {
1.37 raeburn 2080: my ($types,$typename) = &Apache::loncommon::course_types();
1.16 raeburn 2081: my $showtype = $crstype;
2082: if (defined($typename->{$crstype})) {
2083: $showtype = $typename->{$crstype};
2084: }
2085: $output = '<p>'.&Apache::loncommon::start_data_table().
2086: &Apache::loncommon::start_data_table_header_row().
2087: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
2088: '<th>'.&mt('Type').'</th>'.
2089: &Apache::loncommon::end_data_table_header_row().
2090: &Apache::loncommon::start_data_table_row().
2091: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
2092: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
2093: '<td>'.$showtype.'</td>'.
2094: &Apache::loncommon::end_data_table_row().
2095: &Apache::loncommon::end_data_table().
1.40 raeburn 2096: '<br /><div class="LC_warning">';
2097: if ($crstype eq 'community') {
2098: $output .= &mt('Cancelling the request will remove it from the queue of pending community requests').'</div>';
2099: } else {
2100: $output .= &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
2101: }
1.16 raeburn 2102: $result = 'ok';
2103: } else {
2104: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
2105: }
2106: } else {
2107: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
2108: }
2109: return ($result,$output);
2110: }
2111:
2112: sub viewrequest_javascript {
2113: my ($formname,$next) = @_;
2114: return <<"ENDJS";
2115:
2116: function chooseRequest(cdom,cnum) {
2117: document.$formname.showdom.value = cdom;
2118: document.$formname.cnum.value = cnum;
2119: nextPage(document.$formname,'$next');
2120: }
2121:
2122: ENDJS
2123: }
2124:
2125: sub viewdetails_javascript {
2126: my ($formname) = @_;
2127: return << "ENDJS";
2128:
2129: function nextPage(formname,nextstate) {
2130: if (nextstate == "modify") {
2131: formname.state.value = "personnel";
2132: formname.action.value = "new";
2133: } else {
2134: formname.state.value = nextstate;
2135: }
2136: formname.submit();
2137: }
2138:
2139: function backPage(formname,prevstate) {
2140: formname.state.value = prevstate;
2141: formname.submit();
2142: }
2143:
2144: ENDJS
2145: }
2146:
2147: sub viewcancel_javascript {
2148: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
2149: 'Your request will be removed.');
2150: return << "ENDJS";
2151: function nextPage(formname,nextstate) {
2152: if (confirm('$alert')) {
2153: formname.state.value = nextstate;
2154: formname.submit();
2155: }
2156: return;
2157: }
2158:
2159: ENDJS
2160: }
2161:
1.1 raeburn 2162: sub print_request_logs {
1.48 raeburn 2163: my ($r,$dom,$jscript,$loaditems,$crumb) = @_;
2164: my $title;
2165: if ($env{'form.crstype'} eq 'community') {
2166: $title = 'Community Request Logs';
2167: } elsif ($env{'form.crstype'} eq 'any') {
2168: $title = 'Course/Community Request Logs';
2169: } else {
2170: $title = 'Course Request Logs';
2171: }
2172: $r->print(&header($title,$jscript,$loaditems).$crumb);
2173: my $formname = 'requestcrs';
2174: $r->print('<form action="/adm/requestcourse" method="post" name="'.$formname.'" onsubmit="javascript:setPage(this);">'."\n".
2175: '<input type="hidden" name="action" value="log" />'."\n".
2176: '<input type="hidden" name="state" value="display" />'."\n");
2177: # set defaults
2178: my $now = time();
2179: my $defstart = $now - (7*24*3600); #7 days ago
2180: my %defaults = (
2181: page => '1',
2182: show => '10',
2183: crstype => 'any',
2184: status => 'any',
2185: requested_before_date => $now,
2186: requested_after_date => $defstart,
2187: );
2188: my ($types,$typenames) = &Apache::loncommon::course_types();
2189: my $more_records = 0;
2190: my %curr;
2191: foreach my $item ('show','page','crstype','status') {
2192: $curr{$item} = $env{'form.'.$item};
2193: }
2194: $curr{'requested_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_after_date');
2195: $curr{'requested_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_before_date');
2196: foreach my $key (keys(%defaults)) {
2197: if ($curr{$key} eq '') {
2198: $curr{$key} = $defaults{$key};
2199: }
2200: }
2201: my ($statuses,$statusnames) = &reqstatus_names($curr{'crstype'});
2202: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
2203: &requestlog_display_filter($formname,\%curr));
1.49 raeburn 2204: my %queue_by_date = &sorted_request_history($dom,$env{'form.action'},\%curr);
1.48 raeburn 2205: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
2206: my $showntablehdr = 0;
2207: my $tablehdr = &Apache::loncommon::start_data_table().
2208: &Apache::loncommon::start_data_table_header_row().
2209: '<th> </th><th>'.&mt('Request Date').'</th>'.
2210: '<th>'.&mt('Description').'</th>';
2211: if ($curr{'crstype'} eq 'any') {
2212: $tablehdr .= '<th>'.&mt('Course Type').'</th>';
2213: }
2214: if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) {
2215: $tablehdr .= '<th>'.&mt('Institutional Code').'</th>';
2216: }
2217: if ($curr{'status'} eq 'any') {
2218: $tablehdr .= '<th>'.&mt('Status').'</th>';
2219: } elsif ($curr{'status'} eq 'created') {
2220: $tablehdr .= '<th>'.&mt('Creation Date').'</th>';
2221: } elsif ($curr{'status'} eq 'cancelled') {
2222: $tablehdr .= '<th>'.&mt('Cancellation Date').'</th>';
2223: } elsif ($curr{'status'} eq 'rejected') {
2224: $tablehdr .= '<th>'.&mt('Rejection Date').'</th>';
2225: }
2226: $tablehdr .= &Apache::loncommon::end_data_table_header_row();
2227: my ($minshown,$maxshown);
2228: $minshown = 1;
2229: my $count = 0;
2230: if ($curr{'show'} ne &mt('all')) {
2231: $maxshown = $curr{'page'} * $curr{'show'};
2232: if ($curr{'page'} > 1) {
2233: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
2234: }
2235: }
2236: my $norecords;
2237: if (@sortedtimes > 0) {
2238: foreach my $item (@sortedtimes) {
2239: if ($curr{'show'} ne &mt('all')) {
2240: if ($count >= $curr{'page'} * $curr{'show'}) {
2241: $more_records = 1;
2242: last;
2243: }
2244: }
2245: $count ++;
2246: next if ($count < $minshown);
2247: if (!$showntablehdr) {
2248: $r->print($tablehdr);
2249: $showntablehdr = 1;
2250: }
2251: my $showtime = &Apache::lonlocal::locallocaltime($item);
2252: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2253: foreach my $request (sort(@{$queue_by_date{$item}})) {
2254: my ($key,$crstype,$desc,$timestamp,$status,$instcode) = split(':',$request);
2255: my ($cdom,$cnum) = split('_',$key);
2256: my $output = &Apache::loncommon::start_data_table_row().
2257: '<td>'.$count.'</td>'.
2258: '<td>'.$showtime.'</td>'.
2259: '<td>'.&unescape($desc).'</td>';
2260: if ($curr{'crstype'} eq 'any') {
2261: my $typename;
2262: if (ref($typenames) eq 'HASH') {
2263: $typename = &mt($typenames->{$crstype});
2264: }
2265: if ($typename eq '') {
2266: $typename = &mt('Unknown type');
2267: }
2268: $output .= '<td>'.$typename.'</td>';
2269: }
2270: if (($curr{'crstype'} eq 'any') ||
2271: ($curr{'crstype'} eq 'official')) {
2272: my $showinstcode;
2273: if ($crstype eq 'official') {
2274: $showinstcode = &unescape($instcode);
2275: } else {
2276: $showinstcode = &mt('Not applicable');
2277: }
2278: $output .= '<td>'.$showinstcode.'</td>';
2279: }
2280: if ($curr{'status'} eq 'any') {
2281: my $statusname = &mt('Unknown status');
2282: if (ref($statusnames) eq 'HASH') {
2283: if ($statusnames->{$status} ne '') {
2284: $statusname = $statusnames->{$status};
2285: }
2286: }
2287: if (($status eq 'created') || ($status eq 'cancelled') ||
2288: ($status eq 'rejected')) {
2289: $statusname .= ' '.&Apache::lonlocal::locallocaltime($timestamp);
2290: }
2291: $output .= '<td>'.$statusname.'</td>';
2292: } elsif (($status eq 'created') || ($status eq 'cancelled') ||
2293: ($status eq 'rejected')) {
2294: $output .= '<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>';
2295: }
2296: $output .= &Apache::loncommon::end_data_table_row();
2297: $r->print($output);
2298: }
2299: }
2300: }
2301: if ($showntablehdr) {
2302: $r->print(&Apache::loncommon::end_data_table());
2303: if (($curr{'page'} > 1) || ($more_records)) {
2304: $r->print('<table><tr>');
2305: if ($curr{'page'} > 1) {
2306: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
2307: }
2308: if ($more_records) {
2309: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
2310: }
2311: $r->print('</tr></table>');
2312: $r->print(<<"ENDSCRIPT");
2313: <script type="text/javascript">
2314: // <![CDATA[
2315: function chgPage(caller) {
2316: if (caller == 'previous') {
2317: document.$formname.page.value --;
2318: }
2319: if (caller == 'next') {
2320: document.$formname.page.value ++;
2321: }
2322: document.$formname.submit();
1.1 raeburn 2323: return;
2324: }
1.48 raeburn 2325: // ]]>
2326: </script>
2327: ENDSCRIPT
2328: }
2329: } else {
2330: $norecords = 1;
2331: }
2332: } else {
2333: $norecords = 1;
2334: }
2335: if ($norecords) {
2336: $r->print('<p class="LC_info">'.
2337: &mt('There are no records to display').
2338: '</p>');
2339: }
2340: $r->print('</form>'.
2341: &Apache::loncommon::end_page());
2342: return;
2343: }
2344:
2345: sub reqstatus_names {
2346: my ($crstype) = @_;
2347: my @statuses = qw(created approval pending rejected cancelled);
2348: my %statusnames =
2349: &Apache::lonlocal::texthash (
1.50 raeburn 2350: created => 'Created',
1.48 raeburn 2351: approval => 'Queued pending approval',
2352: pending => 'Queued pending validation',
2353: rejected => 'Request rejected',
2354: cancelled => 'Request cancelled',
2355: );
2356: if (($crstype eq 'official') || ($crstype eq 'unofficial')) {
2357: $statusnames{'created'} = &mt('Course created');
2358: } elsif ($crstype eq 'community') {
2359: $statusnames{'created'} = &mt('Community created');
2360: }
2361: return (\@statuses,\%statusnames);
2362: }
2363:
2364: sub requestlog_display_filter {
2365: my ($formname,$curr) = @_;
2366: my $nolink = 1;
2367: my $output = '<table><tr><td valign="top">'.
2368: '<span class="LC_nobreak"><b>'.&mt('Records/page:').'</b></span><br />'.
2369: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
2370: (&mt('all'),5,10,20,50,100,1000,10000)).
2371: '</td><td> </td>';
2372: my $startform =
2373: &Apache::lonhtmlcommon::date_setter($formname,'requested_after_date',
2374: $curr->{'requested_after_date'},undef,
2375: undef,undef,undef,undef,undef,undef,$nolink);
2376: my $endform =
2377: &Apache::lonhtmlcommon::date_setter($formname,'requested_before_date',
2378: $curr->{'requested_before_date'},undef,
2379: undef,undef,undef,undef,undef,undef,$nolink);
2380: $output .= '<td valign="top"><b>'.&mt('Window during which course/community was requested:').'</b><br />'.
2381: '<table><tr><td>'.&mt('After:').
2382: '</td><td>'.$startform.'</td></tr>'.
2383: '<tr><td>'.&mt('Before:').'</td>'.
2384: '<td>'.$endform.'</td></tr></table>'.
2385: '</td>'.
2386: '<td> </td>';
2387: my ($types,$typenames) = &Apache::loncommon::course_types();
2388: if (ref($types) eq 'ARRAY') {
2389: if (@{$types} > 1) {
2390: $output .= '<td valign="top"><b>'.
2391: &mt('Course Type:').'</b><br /><select name="crstype">';
2392: my $selstr = '';
2393: if ($curr->{'crstype'} eq 'any') {
2394: $selstr = ' selected="selected"';
2395: }
2396: $output .= '<option value="any"'.$selstr.'>'.&mt('All types').'</option>'."\n";
2397: foreach my $crstype (@{$types}) {
2398: my $selstr = '';
2399: if ($curr->{'crstype'} eq $crstype) {
2400: $selstr = ' selected="selected"';
2401: }
2402: my $typename = $crstype;
2403: if (ref($typenames) eq 'HASH') {
2404: if ($typenames->{$crstype} ne '') {
2405: $typename = $typenames->{$crstype};
2406: }
2407: }
2408: $output .= '<option value="'.$crstype.'"'.$selstr.'>'.$typename.'</option>'."\n";
2409: }
2410: $output .= '</select></td>';
2411: }
2412: }
2413: my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'});
2414: if (ref($statuses) eq 'ARRAY') {
2415: if (@{$statuses} > 1) {
2416: $output .= '<td valign="top"><b>'.
2417: &mt('Request Status:').'</b><br /><select name="status">';
2418: my $selstr = '';
2419: if ($curr->{'status'} eq 'any') {
2420: $selstr = ' selected="selected"';
2421: }
2422: $output .= '<option value="any"'.$selstr.'>'.&mt('Any status').'</option>'."\n";
2423: foreach my $status (@{$statuses}) {
2424: my $selstr = '';
2425: if ($curr->{'status'} eq $status) {
2426: $selstr = ' selected="selected"';
2427: }
2428: my $statusname = $status;
2429: if (ref($statusnames) eq 'HASH') {
2430: if ($statusnames->{$status} ne '') {
2431: $statusname = $statusnames->{$status};
2432: }
2433: }
2434: $output .= '<option value="'.$status.'"'.$selstr.'>'.$statusname.'</option>'."\n";
2435: }
2436: $output .= '</select></td>';
2437: }
2438: }
2439: $output .= '</tr></table>';
2440:
2441: # Update Display button
2442: $output .= '<p>'.
2443: '<input type="submit" value="'.&mt('Update Display').'" />'.
2444: '</p><hr />';
2445: return $output;
2446: }
1.1 raeburn 2447:
2448: sub print_review {
1.30 raeburn 2449: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
2450: $disallowed,$disallowmsg) = @_;
1.37 raeburn 2451: my ($types,$typename) = &Apache::loncommon::course_types();
1.4 raeburn 2452: my ($owner,$ownername,$owneremail);
1.26 raeburn 2453: if ($uname eq '' || $udom eq '') {
2454: $uname = $env{'user.name'};
2455: $udom = $env{'user.domain'};
2456: }
2457: $owner = $uname.':'.$udom;
2458: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
2459: my %emails = &Apache::loncommon::getemails($uname,$udom);
1.4 raeburn 2460: foreach my $email ('permanentemail','critnotification','notification') {
2461: $owneremail = $emails{$email};
2462: last if ($owneremail ne '');
2463: }
2464: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
2465: $section_headers,$section_values,$personnel_headers,$personnel_values);
2466:
2467: $crstypename = $env{'form.crstype'};
2468: if (ref($typename) eq 'HASH') {
2469: unless ($typename->{$env{'form.crstype'}} eq '') {
1.35 raeburn 2470: $crstypename = &mt($typename->{$env{'form.crstype'}});
1.4 raeburn 2471: }
2472: }
1.16 raeburn 2473: my $category = 'Course';
2474: if ($env{'form.crstype'} eq 'community') {
2475: $category = 'Community';
2476: }
1.4 raeburn 2477:
2478: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
2479: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
2480:
1.16 raeburn 2481: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
2482: '('.&Apache::lonnet::plaintext('st',$category).')';
1.4 raeburn 2483: if ($env{'form.crstype'} eq 'official') {
2484: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
2485: foreach my $title (@{$codetitles}) {
2486: if ($env{'form.instcode_'.$title} ne '') {
2487: $inst_headers .= '<th>'.$title.'</th>';
2488: my $longitem = $env{'form.instcode_'.$title};
2489: if (ref($cat_titles->{$title}) eq 'HASH') {
2490: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
2491: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
2492: }
2493: }
2494: $inst_values .= '<td>'.$longitem.'</td>';
2495: }
2496: }
2497: }
2498: if (&Apache::lonnet::auto_run('',$dom)) {
1.16 raeburn 2499: $enrollrow_title = &mt('Enrollment');
1.4 raeburn 2500: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
2501: '<th>'.&mt('Automatic Drops').'</th>'.
2502: '<th>'.&mt('Enrollment Starts').'</th>'.
2503: '<th>'.&mt('Enrollment Ends').'</th>';
2504: $section_headers = '<th>'.&mt('Sections').'</th>'.
2505: '<th>'.&mt('Crosslistings').'</th>';
2506:
1.13 raeburn 2507: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4 raeburn 2508: my @autoroster = (&mt('No'),&mt('Yes'));
2509: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
2510: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13 raeburn 2511: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
2512: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6 raeburn 2513: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
2514: &mt('Institutional section').'</th>'.
2515: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2516: my $secinfo;
1.4 raeburn 2517: if ($env{'form.sectotal'} > 0) {
2518: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2519: if ($env{'form.sec_'.$i}) {
1.5 raeburn 2520: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 2521: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 2522: $secinfo .= $env{'form.loncapasec_'.$i};
2523: } else {
2524: $secinfo .= &mt('None');
1.4 raeburn 2525: }
1.5 raeburn 2526: $secinfo .= '</td></tr>';
1.4 raeburn 2527: }
2528: }
2529: }
1.6 raeburn 2530: if ($secinfo eq '') {
2531: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2532: }
1.6 raeburn 2533: $section_values .= $secinfo.'</table></td><td>'.
2534: '<table class="LC_innerpickbox"><tr><th>'.
2535: &mt('Institutional course/section').'</th>'.
2536: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2537: my $xlistinfo;
1.24 raeburn 2538: my $crosslisttotal = $env{'form.crosslisttotal'};
2539: if (!$crosslisttotal) {
2540: $crosslisttotal = 1;
2541: }
2542: for (my $i=0; $i<$crosslisttotal; $i++) {
2543: if ($env{'form.crosslist_'.$i}) {
2544: $xlistinfo .= '<tr><td>';
2545: if (ref($code_order) eq 'ARRAY') {
2546: if (@{$code_order} > 0) {
2547: foreach my $item (@{$code_order}) {
2548: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 2549: }
2550: }
2551: }
1.24 raeburn 2552: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
2553: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
2554: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
2555: } else {
2556: $xlistinfo .= &mt('None');
2557: }
2558: $xlistinfo .= '</td></tr>';
1.4 raeburn 2559: }
2560: }
1.6 raeburn 2561: if ($xlistinfo eq '') {
2562: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2563: }
1.24 raeburn 2564: $section_values .= $xlistinfo;
1.4 raeburn 2565: }
1.24 raeburn 2566: $section_values .= '</table></td>';
1.4 raeburn 2567: }
2568:
2569: my %ctxt = &clone_text();
2570: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1.45 raeburn 2571: if (($env{'form.cloning'}) &&
2572: ($env{'form.clonecrs'} =~ /^$match_name$/) &&
1.13 raeburn 2573: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1.56 raeburn 2574: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname,
2575: $udom,$env{'form.clonecrs'},$env{'form.clonedom'},
1.39 raeburn 2576: $env{'form.crstype'});
1.15 raeburn 2577: if ($canclone) {
2578: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
2579: $env{'form.clonecrs'},('description','internal.coursecode'));
2580: if (keys(%courseenv) > 0) {
2581: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
2582: $inst_values .= '<td>'.$courseenv{'description'}.' ';
2583: my $cloneinst = $courseenv{'internal.coursecode'};
2584: if ($cloneinst ne '') {
1.18 raeburn 2585: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1.15 raeburn 2586: } else {
1.18 raeburn 2587: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1.15 raeburn 2588: }
2589: $inst_values .= '</td><td>';
2590: if ($env{'form.datemode'} eq 'preserve') {
1.16 raeburn 2591: $inst_values .= $ctxt{'prd'};
1.15 raeburn 2592: } elsif ($env{'form.datemode'} eq 'shift') {
2593: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
2594: } else {
2595: $inst_values .= $ctxt{'ncd'};
2596: }
2597: $inst_values .= '</td>';
2598: } else {
2599: $inst_values .= '<td>'.&mt('Unknown').'</td>';
2600: }
2601: } else {
2602: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
2603: }
1.4 raeburn 2604: } else {
2605: $inst_values .= '<td>'.&mt('None').'</td>';
2606: }
2607: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
2608: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 2609: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2610: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
2611: if ($accessend == 0) {
1.4 raeburn 2612: $enroll_values .= '<td>'.&mt('No end date').'</td>';
2613: } else {
1.13 raeburn 2614: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 2615: }
2616:
2617: my $container = 'Course';
1.41 raeburn 2618: my $ccrole = 'cc';
1.4 raeburn 2619: if ($env{'form.crstype'} eq 'community') {
2620: $container = 'Community';
1.41 raeburn 2621: $ccrole = 'co';
1.4 raeburn 2622: }
2623:
2624: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
2625: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
2626: '</th>';
1.41 raeburn 2627:
1.4 raeburn 2628: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1.41 raeburn 2629: '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
1.4 raeburn 2630: '<td>'.&mt('None').'</td></tr>';
2631: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2632: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.30 raeburn 2633: if (ref($disallowed) eq 'ARRAY') {
2634: next if (grep(/^$i$/,@{$disallowed}));
2635: }
1.31 raeburn 2636: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2637: my @allsecs;
2638: foreach my $sec (@officialsecs) {
2639: next unless ($sec =~ /\w/);
2640: next if ($sec =~ /\W/);
2641: next if ($sec eq 'none');
2642: push(@allsecs,$sec);
2643: }
1.14 raeburn 2644: my $newsec = $env{'form.person_'.$i.'_newsec'};
2645: $newsec =~ s/^\s+//;
2646: $newsec =~s/\s+$//;
1.31 raeburn 2647: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
1.14 raeburn 2648: foreach my $sec (@newsecs) {
1.31 raeburn 2649: next unless ($sec =~ /\w/);
1.14 raeburn 2650: next if ($sec =~ /\W/);
1.31 raeburn 2651: next if ($sec eq 'none');
1.14 raeburn 2652: if ($sec ne '') {
2653: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2654: push(@allsecs,$sec);
2655: }
2656: }
2657: }
1.24 raeburn 2658: my $showsec;
1.14 raeburn 2659: if (@allsecs) {
2660: $showsec = join(', ',@allsecs);
2661: }
1.24 raeburn 2662: if ($showsec eq '') {
2663: $showsec = &mt('None');
2664: }
1.41 raeburn 2665: if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
1.24 raeburn 2666: $showsec = &mt('None');
2667: }
1.28 raeburn 2668: my $role = $env{'form.person_'.$i.'_role'};
1.4 raeburn 2669: $personnel_values .=
1.13 raeburn 2670: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
2671: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 2672: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
2673: $env{'form.person_'.$i.'_dom'}.'</td>'.
1.28 raeburn 2674: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1.14 raeburn 2675: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 2676: }
2677: }
1.30 raeburn 2678: my $output;
2679: if (ref($disallowed) eq 'ARRAY') {
2680: if (@{$disallowed} > 0) {
2681: if (ref($disallowmsg) eq 'HASH') {
2682: $output = '<p class="LC_warning">'.
2683: &mt('Not all requested personnel could be included.').'<ul>';
2684: foreach my $item (@{$disallowed}) {
2685: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
2686: }
2687: $output .= '</ul></p>';
2688: }
2689: }
2690: }
2691: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.4 raeburn 2692: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 2693: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 2694: '<th>'.&mt('Name').'</th>'.
2695: '<th>'.&mt('Username:Domain').'</th>'.
2696: '<th>'.&mt('E-mail address').'</th>'.
2697: '</tr><tr>'."\n".
2698: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
2699: '<td>'.$owneremail.'</td>'.
2700: '</tr></table>'."\n".
2701: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 2702: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 2703: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
2704: '<tr>'.$inst_values.'</tr></table>'."\n".
2705: &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2706: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4 raeburn 2707: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
2708: '<tr>'.$enroll_values.'</tr></table>'."\n".
2709: &Apache::lonhtmlcommon::row_closure();
2710: if ($section_headers ne '') {
2711: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
2712: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
2713: '<tr>'.$section_values.'</tr></table>'."\n".
2714: &Apache::lonhtmlcommon::row_closure();
2715: }
2716: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
2717: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
2718: $personnel_values.'</table>'."\n".
2719: &Apache::lonhtmlcommon::row_closure(1).
1.26 raeburn 2720: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4 raeburn 2721: return $output;
2722: }
2723:
2724: sub dates_from_form {
2725: my ($startname,$endname) = @_;
2726: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
2727: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 2728: if ($endname eq 'accessend') {
1.4 raeburn 2729: if (exists($env{'form.no_end_date'}) ) {
2730: $enddate = 0;
2731: }
2732: }
2733: return ($startdate,$enddate);
1.1 raeburn 2734: }
2735:
2736: sub courseinfo_form {
1.36 raeburn 2737: my ($dom,$formname,$crstype,$next,$description) = @_;
1.32 raeburn 2738: my %lt = &Apache::lonlocal::texthash(
2739: official => 'You must provide a (brief) course description.',
2740: community => 'You must provide a (brief) community description.'
2741: );
2742: $lt{'unofficial'} = $lt{'official'};
1.15 raeburn 2743: my $js_validate = <<"ENDJS";
2744: <script type="text/javascript">
2745: // <![CDATA['
2746:
2747: function validateForm() {
2748: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1.32 raeburn 2749: alert('$lt{$crstype}');
1.15 raeburn 2750: return;
2751: }
2752: nextPage(document.$formname,'$next');
2753: }
1.45 raeburn 2754:
2755: function toggleCloning() {
2756: var willclone;
2757: if (document.$formname.cloning.length > 1) {
2758: for (var i=0; i<document.$formname.cloning.length; i++) {
2759: if (document.$formname.cloning[i].checked) {
2760: willclone = document.$formname.cloning[i].value;
2761: }
2762: }
2763: }
2764: if (willclone == 1) {
2765: document.getElementById('cloneoptions').style.display="block";
2766: } else {
2767: document.getElementById('cloneoptions').style.display="none";
2768: document.$formname.clonecrs.value = '';
2769: }
2770: }
2771:
1.15 raeburn 2772: // ]]
2773: </script>
2774:
2775: ENDJS
1.27 raeburn 2776: my $title = &mt('Brief Course Description');
1.40 raeburn 2777: my $clonetitle = &mt('Clone content and settings from an existing course?');
1.27 raeburn 2778: if ($crstype eq 'community') {
2779: $title = &mt('Brief Community Description');
1.40 raeburn 2780: $clonetitle = &mt('Clone content and settings from an existing community?');
1.27 raeburn 2781: }
1.45 raeburn 2782: my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 2783: &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 2784: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'.
1.27 raeburn 2785: &Apache::lonhtmlcommon::row_closure(1).
2786: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.36 raeburn 2787: '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
1.13 raeburn 2788: my ($home_server_pick,$numlib) =
2789: &Apache::loncommon::home_server_form_item($dom,'chome',
2790: 'default','hide');
2791: if ($numlib > 1) {
2792: $output .= &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2793: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13 raeburn 2794: }
2795: $output .= $home_server_pick.
1.27 raeburn 2796: &Apache::lonhtmlcommon::row_closure().
2797: &Apache::lonhtmlcommon::row_headline().
1.45 raeburn 2798: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.
1.46 wenzelju 2799: &Apache::lonhtmlcommon::row_closure(1).
2800: &Apache::lonhtmlcommon::row_title(&mt('Clone?')).
1.45 raeburn 2801: '<label><input type="radio" name="cloning" value="1" '.
2802: 'onclick="javascript:toggleCloning()" />'.
2803: &mt('Yes').(' 'x2).'</label><label>'.
1.49 raeburn 2804: '<input type="radio" name="cloning" value="0" checked="checked" '.
1.45 raeburn 2805: 'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'.
2806: '</h3>'.
1.13 raeburn 2807: &Apache::lonhtmlcommon::row_closure(1).
1.45 raeburn 2808: &Apache::lonhtmlcommon::row_headline().
2809: '<div id="cloneoptions" style="display: none" >'.
2810: &Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 2811: &clone_form($dom,$formname,$crstype).
1.45 raeburn 2812: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
2813: &Apache::lonhtmlcommon::end_pick_box()."\n";
1.1 raeburn 2814: return $output;
2815: }
2816:
2817: sub clone_form {
2818: my ($dom,$formname,$crstype) = @_;
2819: my $type = 'Course';
2820: if ($crstype eq 'community') {
2821: $type = 'Community';
2822: }
1.4 raeburn 2823: my %lt = &clone_text();
1.2 raeburn 2824: my $output .=
1.53 raeburn 2825: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
2826: &Apache::loncommon::select_dom_form($dom,'clonedom').'</label>'.
2827: &Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 2828: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.53 raeburn 2829: '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();opencrsbrowser('."'$formname','clonecrs','clonedom','','','','','$type'".')" />'.
2830: '</label> '.
2831: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type).
2832: &Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 2833: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
2834: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
2835: '</label><br /><label>'.
2836: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
2837: '</label><br /><label>'.
2838: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
2839: $lt{'shd'}.'</label>'.
2840: '<input type="text" size="5" name="dateshift" value="365" />'.
1.27 raeburn 2841: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2842: return $output;
2843: }
2844:
1.16 raeburn 2845: sub clone_text {
1.4 raeburn 2846: return &Apache::lonlocal::texthash(
2847: 'cid' => 'Course ID',
2848: 'dmn' => 'Domain',
2849: 'dsh' => 'Date Shift',
2850: 'ncd' => 'Do not clone date parameters',
2851: 'prd' => 'Clone date parameters as-is',
2852: 'shd' => 'Shift date parameters by number of days',
2853: );
2854: }
2855:
1.1 raeburn 2856: sub coursecode_form {
1.2 raeburn 2857: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 2858: my $output;
1.46 wenzelju 2859: my %rowtitle = &Apache::lonlocal::texthash (
1.2 raeburn 2860: instcode => 'Course Category',
2861: crosslist => 'Cross Listed Course',
2862: );
1.34 raeburn 2863: my %helpitem = (
2864: instcode => 'Course_Request_Category',
2865: crosslist => 'Course_Request_Crosslist',
2866: );
1.1 raeburn 2867: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
2868: (ref($cat_order))) {
1.2 raeburn 2869: my ($sel,$instsec,$lcsec);
2870: $sel = $context;
2871: if ($context eq 'crosslist') {
2872: $sel .= '_'.$num;
2873: $instsec = &mt('Institutional section').'<br />'.
2874: '<input type="text" size="10" name="'.$sel.'_instsec" />';
2875: $lcsec = &mt('LON-CAPA section').'<br />'.
2876: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
2877: }
1.1 raeburn 2878: if (@{$codetitles} > 0) {
2879: my $lastitem = pop(@{$codetitles});
1.2 raeburn 2880: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 2881: if (@{$codetitles} > 0) {
1.34 raeburn 2882: $output = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($helpitem{$context}).' '.$rowtitle{$context}).
1.2 raeburn 2883: '<table><tr>';
1.1 raeburn 2884: if ($context eq 'crosslist') {
1.2 raeburn 2885: $output .= '<td>'.&mt('Include?').'<br />'.
2886: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 2887: }
2888: foreach my $title (@{$codetitles}) {
2889: if (ref($cat_order->{$title}) eq 'ARRAY') {
2890: if (@{$cat_order->{$title}} > 0) {
2891: $output .= '<td align="center">'.$title.'<br />'."\n".
2892: '<select name="'.$sel.'_'.$title.'">'."\n".
2893: ' <option value="" selected="selected">'.
2894: &mt('Select').'</option>'."\n";
2895: foreach my $item (@{$cat_order->{$title}}) {
2896: my $longitem = $item;
2897: if (ref($cat_titles->{$title}) eq 'HASH') {
2898: if ($cat_titles->{$title}{$item} ne '') {
2899: $longitem = $cat_titles->{$title}{$item};
2900: }
2901: }
2902: $output .= '<option value="'.$item.'">'.$longitem.
2903: '</option>'."\n";
2904: }
2905: }
2906: $output .= '</select></td>'."\n";
2907: }
2908: }
2909: if ($context eq 'crosslist') {
2910: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 2911: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
2912: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 2913: } else {
2914: $output .= '</tr></table>'.
2915: &Apache::lonhtmlcommon::row_closure().
2916: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2917: $lastinput;
2918: }
2919: } else {
2920: if ($context eq 'crosslist') {
2921: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 2922: '<table><tr>'.
2923: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
2924: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
2925: '</tr></table>';
1.1 raeburn 2926: } else {
2927: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2928: $lastinput;
2929: }
2930: }
1.2 raeburn 2931: $output .= &Apache::lonhtmlcommon::row_closure(1);
2932: push(@$codetitles,$lastitem);
2933: } elsif ($context eq 'crosslist') {
2934: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
2935: '<table><tr><td align="center">'.
2936: '<span class="LC_nobreak">'.&mt('Include?').
2937: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
2938: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
2939: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
2940: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
2941: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2942: }
2943: }
2944: return $output;
2945: }
2946:
2947: sub get_course_dom {
2948: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 2949: if ($env{'form.showdom'} ne '') {
2950: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
2951: return $env{'form.showdom'};
2952: }
2953: }
1.1 raeburn 2954: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.37 raeburn 2955: my ($types,$typename) = &Apache::loncommon::course_types();
1.19 raeburn 2956: if (ref($types) eq 'ARRAY') {
2957: foreach my $type (@{$types}) {
2958: if (&Apache::lonnet::usertools_access($env{'user.name'},
2959: $env{'user.domain'},$type,
2960: undef,'requestcourses')) {
2961: return $env{'user.domain'};
2962: }
2963: }
2964: my @possible_doms;
2965: foreach my $type (@{$types}) {
2966: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
2967: if ($dom_str ne '') {
2968: my @domains = split(',',$dom_str);
2969: foreach my $entry (@domains) {
2970: my ($extdom,$extopt) = split(':',$entry);
2971: if ($extdom eq $env{'request.role.domain'}) {
2972: return $extdom;
2973: }
2974: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
2975: push(@possible_doms,$extdom);
2976: }
2977: }
2978: }
2979: }
2980: if (@possible_doms) {
2981: @possible_doms = sort(@possible_doms);
2982: return $possible_doms[0];
2983: }
2984: }
1.1 raeburn 2985: $codedom = $env{'user.domain'};
2986: if ($env{'request.role.domain'} ne '') {
2987: $codedom = $env{'request.role.domain'};
2988: }
2989: }
2990: return $codedom;
2991: }
2992:
2993: sub display_navbuttons {
1.31 raeburn 2994: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1 raeburn 2995: $r->print('<div class="LC_navbuttons">');
2996: if ($prev) {
1.16 raeburn 2997: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1.31 raeburn 2998: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
1.16 raeburn 2999: (' 'x3));
1.1 raeburn 3000: } elsif ($prevtext) {
1.16 raeburn 3001: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
3002: 'onclick="javascript:history.back()"/>'.(' 'x3));
3003: }
3004: if ($state eq 'details') {
3005: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1.31 raeburn 3006: 'onclick="javascript:nextPage('."document.$formname,'$other'".
1.16 raeburn 3007: ')" />');
1.1 raeburn 3008: }
1.31 raeburn 3009: my $gotnext;
1.15 raeburn 3010: if ($state eq 'courseinfo') {
1.16 raeburn 3011: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3012: 'onclick="javascript:validateForm();" />');
1.31 raeburn 3013: $gotnext = 1;
3014: } elsif ($state eq 'enrollment') {
3015: if (($env{'form.crstype'} eq 'official') &&
3016: (&Apache::lonnet::auto_run('',$dom))) {
3017: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3018: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
3019: $gotnext = 1;
3020: }
3021: } elsif ($state eq 'personnel') {
3022: if ($env{'form.persontotal'} > 0) {
3023: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3024: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
3025: $gotnext = 1;
3026: }
3027: }
3028: unless ($gotnext) {
3029: if ($next) {
3030: $r->print('
3031: <input type="button" name="next" value="'.$nexttext.'" '.
3032: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
3033: }
1.1 raeburn 3034: }
3035: $r->print('</div>');
3036: }
3037:
3038: sub print_request_outcome {
1.10 raeburn 3039: my ($dom,$codetitles,$code_order) = @_;
1.13 raeburn 3040: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10 raeburn 3041: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1.24 raeburn 3042: my $sectotal = $env{'form.sectotal'};
3043: my $crosslisttotal = 0;
1.10 raeburn 3044: $cnum = $env{'form.cnum'};
1.8 raeburn 3045: unless ($cnum =~ /^$match_courseid$/) {
3046: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
3047: return $output;
3048: }
1.11 raeburn 3049:
1.10 raeburn 3050: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 3051: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
3052: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
3053: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
3054: }
3055: }
1.10 raeburn 3056: $now = time;
3057: $crstype = $env{'form.crstype'};
1.41 raeburn 3058: my $ccrole = 'cc';
3059: if ($crstype eq 'community') {
3060: $ccrole = 'co';
3061: }
1.17 raeburn 3062: my @instsections;
1.8 raeburn 3063: if ($crstype eq 'official') {
3064: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 3065: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 3066: }
1.10 raeburn 3067: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
3068: if ($env{'form.sec_'.$i}) {
3069: if ($env{'form.secnum_'.$i} ne '') {
1.17 raeburn 3070: my $sec = $env{'form.secnum_'.$i};
3071: $sections{$i}{'inst'} = $sec;
3072: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
3073: push(@instsections,$sec);
3074: }
1.13 raeburn 3075: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.58 raeburn 3076: $sections{$i}{'loncapa'} =~ s/\W//g;
3077: if ($sections{$i}{'loncapa'} eq 'none') {
3078: $sections{$i}{'loncapa'} = '';
3079: }
1.10 raeburn 3080: }
3081: }
3082: }
3083: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
3084: if ($env{'form.crosslist_'.$i}) {
3085: my $xlistinfo = '';
3086: if (ref($code_order) eq 'ARRAY') {
3087: if (@{$code_order} > 0) {
3088: foreach my $item (@{$code_order}) {
3089: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
3090: }
3091: }
3092: }
1.22 raeburn 3093: $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24 raeburn 3094: if ($xlistinfo ne '') {
3095: $crosslisttotal ++;
3096: }
1.22 raeburn 3097: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 3098: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 3099: }
3100: }
1.14 raeburn 3101: } else {
3102: $enrollstart = '';
3103: $enrollend = '';
1.10 raeburn 3104: }
1.60 ! raeburn 3105: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
1.10 raeburn 3106: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
3107: my $uname = $env{'form.person_'.$i.'_uname'};
1.16 raeburn 3108: my $udom = $env{'form.person_'.$i.'_dom'};
1.10 raeburn 3109: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
3110: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 3111: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
3112: $personnel{$uname.':'.$udom} = {
3113: firstname => $env{'form.person_'.$i.'_firstname'},
3114: lastname => $env{'form.person_'.$i.'_lastname'},
3115: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
3116: };
1.60 ! raeburn 3117: my $usertype = &get_usertype($udom,$uname,\%curr_rules,\%got_rules);
! 3118: if (&Apache::lonuserutils::can_create_user($udom,'requestcrs',$usertype)) {
! 3119: my ($allowed,$msg,$authtype,$authparam) =
! 3120: &check_newuser_rules($udom,$uname,\%alerts,\%rulematch,
! 3121: \%inst_results,\%curr_rules,\%got_rules);
! 3122: if ($allowed) {
! 3123: my %domdefaults = &Apache::lonnet::get_domain_defaults($udom);
! 3124: if ($usertype eq 'official') {
! 3125: if ($authtype eq '') {
! 3126: $authtype = $domdefaults{'auth_def'};
! 3127: $authparam = $domdefaults{'auth_arg_def'};
! 3128: } else {
! 3129: if ($authtype eq 'loc') {
! 3130: $authtype = 'localauth';
! 3131: } elsif ($authtype eq 'int') {
! 3132: $authtype = 'internal';
! 3133: }
! 3134: if ($authtype !~ /^(krb4|krb5|internal|localauth)$/) {
! 3135: $authtype = $domdefaults{'auth_def'};
! 3136: $authparam = $domdefaults{'auth_arg_def'};
! 3137: }
! 3138: }
! 3139: } elsif ($usertype eq 'unofficial') {
! 3140: if ($authtype eq '') {
! 3141: $authtype = 'internal';
! 3142: $authparam = '';
! 3143: }
! 3144: } else {
! 3145: $authtype = $domdefaults{'auth_def'};
! 3146: $authparam = $domdefaults{'auth_arg_def'};
! 3147: }
! 3148: if (($authtype eq '') ||
! 3149: (($authtype =~/^krb(4|5)$/) && ($authparam eq '')) ||
! 3150: ($authtype !~ /^(krb4|krb5|internal|localauth)$/)) {
! 3151: next;
! 3152: } else {
! 3153: $personnel{$uname.':'.$udom}{'authtype'} = $authtype;
! 3154: $personnel{$uname.':'.$udom}{'autharg'} = $authparam;
! 3155: }
! 3156: } else {
! 3157: next;
! 3158: }
! 3159: } else {
! 3160: next;
! 3161: }
1.13 raeburn 3162: }
3163: my $role = $env{'form.person_'.$i.'_role'};
3164: unless ($role eq '') {
1.16 raeburn 3165: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13 raeburn 3166: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
3167: unless (grep(/^\Q$role\E$/,@curr_roles)) {
3168: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
3169: }
3170: } else {
3171: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
3172: }
1.41 raeburn 3173: if ($role eq $ccrole) {
1.13 raeburn 3174: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
3175: } else {
1.14 raeburn 3176: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1.31 raeburn 3177: my @allsecs;
3178: foreach my $sec (@currsec) {
3179: next unless ($sec =~ /\w/);
3180: next if ($sec =~ /\W/);
3181: next if ($sec eq 'none');
3182: push(@allsecs,$sec);
3183: }
1.14 raeburn 3184: my $newsec = $env{'form.person_'.$i.'_newsec'};
3185: $newsec =~ s/^\s+//;
3186: $newsec =~s/\s+$//;
3187: my @newsecs = split(/[\s,;]+/,$newsec);
3188: foreach my $sec (@newsecs) {
3189: next if ($sec =~ /\W/);
1.31 raeburn 3190: next if ($sec eq 'none');
1.14 raeburn 3191: if ($sec ne '') {
1.31 raeburn 3192: unless (grep(/^\Q$sec\E$/,@allsecs)) {
3193: push(@allsecs,$sec);
1.13 raeburn 3194: }
3195: }
3196: }
1.31 raeburn 3197: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
1.13 raeburn 3198: }
3199: }
1.10 raeburn 3200: } else {
3201: push(@missingdom,$uname.':'.$udom);
3202: }
3203: } else {
3204: push(@baduname,$uname.':'.$udom);
3205: }
1.8 raeburn 3206: }
1.13 raeburn 3207: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 3208: my $autodrops = 0;
3209: if ($env{'form.autodrops'}) {
3210: $autodrops = $env{'form.autodrops'};
3211: }
3212: my $autoadds = 0;
3213: if ($env{'form.autoadds'}) {
1.57 raeburn 3214: $autoadds = $env{'form.autoadds'};
1.14 raeburn 3215: }
3216: my $instcode = '';
3217: if (exists($env{'form.instcode'})) {
3218: $instcode = $env{'form.instcode'};
3219: }
1.15 raeburn 3220: my $clonecrs = '';
3221: my $clonedom = '';
1.45 raeburn 3222: if (($env{'form.cloning'}) &&
3223: ($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
1.15 raeburn 3224: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.16 raeburn 3225: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
3226: $env{'form.clonedom'});
1.15 raeburn 3227: if ($clonehome ne 'no_host') {
1.16 raeburn 3228: my $canclone =
3229: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.39 raeburn 3230: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
3231: $crstype);
1.15 raeburn 3232: if ($canclone) {
3233: $clonecrs = $env{'form.clonecrs'};
3234: $clonedom = $env{'form.clonedom'};
3235: }
3236: }
3237: }
1.8 raeburn 3238: my $details = {
1.10 raeburn 3239: owner => $env{'user.name'},
3240: domain => $env{'user.domain'},
3241: cdom => $dom,
1.11 raeburn 3242: cnum => $cnum,
1.13 raeburn 3243: coursehome => $env{'form.chome'},
3244: cdescr => $env{'form.cdescr'},
1.10 raeburn 3245: crstype => $env{'form.crstype'},
1.14 raeburn 3246: instcode => $instcode,
1.15 raeburn 3247: clonedom => $clonedom,
3248: clonecrs => $clonecrs,
1.10 raeburn 3249: datemode => $env{'form.datemode'},
1.14 raeburn 3250: dateshift => $env{'form.dateshift'},
3251: sectotal => $sectotal,
1.10 raeburn 3252: sections => \%sections,
1.14 raeburn 3253: crosslisttotal => $crosslisttotal,
1.13 raeburn 3254: crosslists => \%crosslistings,
1.14 raeburn 3255: autoadds => $autoadds,
3256: autodrops => $autodrops,
1.13 raeburn 3257: enrollstart => $enrollstart,
3258: enrollend => $enrollend,
3259: accessstart => $accessstart,
3260: accessend => $accessend,
1.10 raeburn 3261: personnel => \%personnel,
1.8 raeburn 3262: };
1.27 raeburn 3263: my (@inststatuses,$storeresult,$creationresult);
1.43 raeburn 3264: my $val =
3265: &Apache::loncoursequeueadmin::get_processtype($env{'user.name'},$env{'user.domain'},
3266: $env{'user.adv'},$dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 3267: if ($val eq '') {
3268: if ($crstype eq 'official') {
1.19 raeburn 3269: $output = &mt('You are not permitted to request creation of official courses.');
1.8 raeburn 3270: } elsif ($crstype eq 'unofficial') {
1.19 raeburn 3271: $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8 raeburn 3272: } elsif ($crstype eq 'community') {
3273: $output = &mt('You are not permitted to request creation of communities');
3274: } else {
3275: $output = &mt('Unrecognized course type: [_1]',$crstype);
3276: }
1.27 raeburn 3277: $storeresult = 'notpermitted';
1.8 raeburn 3278: } else {
1.14 raeburn 3279: my ($disposition,$message,$reqstatus);
1.8 raeburn 3280: my %reqhash = (
1.14 raeburn 3281: reqtime => $now,
1.10 raeburn 3282: crstype => $crstype,
3283: details => $details,
1.8 raeburn 3284: );
3285: my $requestkey = $dom.'_'.$cnum;
1.17 raeburn 3286: my $validationerror;
1.10 raeburn 3287: if ($val eq 'autolimit=') {
3288: $disposition = 'process';
3289: } elsif ($val =~ /^autolimit=(\d+)$/) {
3290: my $limit = $1;
1.8 raeburn 3291: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 3292: $dom,$crstype,$limit,\$message);
1.8 raeburn 3293: } elsif ($val eq 'validate') {
1.21 raeburn 3294: my ($inststatuslist,$validationchk,$validation);
1.17 raeburn 3295: if (@inststatuses > 0) {
3296: $inststatuslist = join(',',@inststatuses);
3297: }
3298: my $instseclist;
3299: if (@instsections > 0) {
3300: $instseclist = join(',',@instsections);
3301: }
1.21 raeburn 3302: $validationchk =
3303: &Apache::lonnet::auto_courserequest_validation($dom,
3304: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
3305: $inststatuslist,$instcode,$instseclist);
3306: if ($validationchk =~ /:/) {
3307: ($validation,$message) = split(':',$validationchk);
3308: } else {
3309: $validation = $validationchk;
3310: }
3311: if ($validation =~ /^error(.*)$/) {
1.17 raeburn 3312: $disposition = 'approval';
3313: $validationerror = $1;
1.23 raeburn 3314: } else {
3315: $disposition = $validation;
1.17 raeburn 3316: }
1.8 raeburn 3317: } else {
3318: $disposition = 'approval';
3319: }
1.14 raeburn 3320: $reqhash{'disposition'} = $disposition;
3321: $reqstatus = $disposition;
1.16 raeburn 3322: my ($modified,$queued);
1.8 raeburn 3323: if ($disposition eq 'rejected') {
1.40 raeburn 3324: if ($crstype eq 'community') {
3325: $output = &mt('Your community request was rejected.');
3326: } else {
3327: $output = &mt('Your course request was rejected.');
3328: }
1.8 raeburn 3329: if ($message) {
3330: $output .= '<div class="LC_warning">'.$message.'</div>';
3331: }
1.27 raeburn 3332: $storeresult = 'rejected';
1.8 raeburn 3333: } elsif ($disposition eq 'process') {
1.14 raeburn 3334: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
3335: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
1.8 raeburn 3336: my $type = 'Course';
3337: if ($crstype eq 'community') {
3338: $type = 'Community';
3339: }
1.41 raeburn 3340: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.8 raeburn 3341: foreach my $role (@roles) {
3342: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
3343: }
1.14 raeburn 3344: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
3345: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
3346: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
3347: if ($result eq 'created') {
1.8 raeburn 3348: $disposition = 'created';
1.14 raeburn 3349: $reqstatus = 'created';
1.28 raeburn 3350: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
3351: \%longroles);
1.40 raeburn 3352: if ($crstype eq 'community') {
3353: $output = '<p>'.&mt('Your community request has been processed and the community has been created.');
3354: } else {
3355: $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
3356: }
3357: $output .= '<br />'.$role_result.'</p>';
1.27 raeburn 3358: $creationresult = 'created';
1.8 raeburn 3359: } else {
1.40 raeburn 3360: $output = '<span class="LC_error">';
3361: if ($crstype eq 'community') {
3362: $output .= &mt('An error occurred when processing your community request.');
3363: } else {
3364: $output .= &mt('An error occurred when processing your course request.');
3365: }
3366: $output .= '<br />'.
3367: &mt('You may want to review the request details and submit the request again.').
1.14 raeburn 3368: '</span>';
1.27 raeburn 3369: $creationresult = 'error';
1.8 raeburn 3370: }
3371: } else {
3372: my $requestid = $cnum.'_'.$disposition;
3373: my $request = {
3374: $requestid => {
3375: timestamp => $now,
3376: crstype => $crstype,
3377: ownername => $env{'user.name'},
3378: ownerdom => $env{'user.domain'},
1.13 raeburn 3379: description => $env{'form.cdescr'},
1.8 raeburn 3380: },
3381: };
1.49 raeburn 3382: if ($crstype eq 'official') {
3383: $request->{$requestid}->{'instcode'} = $instcode;
3384: }
1.16 raeburn 3385: my $statuskey = 'status:'.$dom.':'.$cnum;
3386: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
3387: $env{'user.domain'},$env{'user.name'});
1.17 raeburn 3388: if ($userreqhash{$statuskey} ne '') {
1.16 raeburn 3389: $modified = 1;
1.25 raeburn 3390: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
3391: my %queuehash = &Apache::lonnet::get('courserequestqueue',
3392: [$cnum.'_approval',
3393: $cnum.'_pending'],$dom,$uname);
1.17 raeburn 3394: if (($queuehash{$cnum.'_approval'} ne '') ||
3395: ($queuehash{$cnum.'_pending'} ne '')) {
1.16 raeburn 3396: $queued = 1;
3397: }
3398: }
3399: unless ($queued) {
3400: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
3401: $dom);
3402: if ($putresult eq 'ok') {
1.40 raeburn 3403: if ($crstype eq 'community') {
3404: $output .= &mt('Your community request has been recorded.');
3405: } else {
3406: $output .= &mt('Your course request has been recorded.')
3407: }
3408: $output .= '<br />'.
1.16 raeburn 3409: ¬ification_information($disposition,$req_notifylist,
3410: $cnum,$now);
1.8 raeburn 3411: } else {
1.16 raeburn 3412: $reqstatus = 'domainerror';
3413: $reqhash{'disposition'} = $disposition;
3414: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
3415: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8 raeburn 3416: }
3417: }
3418: }
1.44 raeburn 3419: ($storeresult,my $updateresult) =
3420: &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
3421: $cnum,$reqstatus,'request');
1.16 raeburn 3422: if ($modified && $queued && $storeresult eq 'ok') {
1.40 raeburn 3423: if ($crstype eq 'community') {
3424: $output .= '<p>'.&mt('Your community request has been updated').'</p>';
3425: } else {
3426: $output .= '<p>'.&mt('Your course request has been updated').'</p>';
3427: }
3428: $output .= ¬ification_information($disposition,$req_notifylist,$cnum,$now);
1.16 raeburn 3429: }
1.17 raeburn 3430: if ($validationerror ne '') {
1.44 raeburn 3431: $output .= '<p class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
3432: }
3433: if ($updateresult) {
3434: $output .= $updateresult;
1.17 raeburn 3435: }
1.16 raeburn 3436: }
1.27 raeburn 3437: if ($creationresult ne '') {
3438: return ($creationresult,$output);
3439: } else {
3440: return ($storeresult,$output);
3441: }
1.16 raeburn 3442: }
3443:
1.28 raeburn 3444: sub update_requestors_roles {
3445: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
3446: my $now = time;
3447: my ($active,$future,$numactive,$numfuture,$output);
3448: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
3449: if (ref($details) eq 'HASH') {
3450: if (ref($details->{'personnel'}) eq 'HASH') {
1.41 raeburn 3451: my $ccrole = 'cc';
3452: if ($crstype eq 'community') {
3453: $ccrole = 'co';
3454: }
1.35 raeburn 3455: unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
3456: $details->{'personnel'}{$owner} = {
1.41 raeburn 3457: 'roles' => [$ccrole],
3458: $ccrole => { 'usec' => [] },
1.35 raeburn 3459: };
3460: }
3461: my @roles;
3462: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
3463: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
1.41 raeburn 3464: unless (grep(/^\Q$ccrole\E$/,@roles)) {
3465: push(@roles,$ccrole);
1.35 raeburn 3466: }
3467: } else {
1.41 raeburn 3468: @roles = ($ccrole);
1.35 raeburn 3469: }
3470: foreach my $role (@roles) {
1.42 raeburn 3471: my $refresh=$env{'user.refresh.time'};
3472: if ($refresh eq '') {
3473: $refresh = $env{'user.login.time'};
3474: }
3475: if ($refresh eq '') {
3476: $refresh = $now;
3477: }
3478: my $start = $refresh-1;
1.35 raeburn 3479: my $end = '0';
3480: if ($role eq 'st') {
3481: if ($details->{'accessstart'} ne '') {
3482: $start = $details->{'accessstart'};
3483: }
3484: if ($details->{'accessend'} ne '') {
3485: $end = $details->{'accessend'};
3486: }
3487: }
3488: my @usecs;
1.41 raeburn 3489: if ($role ne $ccrole) {
1.35 raeburn 3490: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
3491: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
3492: }
3493: }
3494: if ($role eq 'st') {
3495: if (@usecs > 1) {
3496: my $firstsec = $usecs[0];
3497: @usecs = ($firstsec);
3498: }
3499: }
3500: if (@usecs == 0) {
3501: push(@usecs,'');
3502: }
3503: foreach my $usec (@usecs) {
3504: my (%userroles,%newrole,%newgroups,$spec,$area);
3505: my $area = '/'.$dom.'/'.$cnum;
3506: my $spec = $role.'.'.$area;
3507: if ($usec ne '') {
3508: $spec .= '/'.$usec;
3509: $area .= '/'.$usec;
3510: }
3511: if ($role =~ /^cr\//) {
3512: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
3513: $cnum,$spec,$area);
3514: } else {
3515: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
3516: $spec,$cnum,$area);
1.28 raeburn 3517: }
1.35 raeburn 3518: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
3519: \%newgroups);
3520: $userroles{'user.role.'.$spec} = $start.'.'.$end;
3521: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
3522: if (($end == 0) || ($end > $now)) {
3523: my $showrole = $role;
1.28 raeburn 3524: if ($role =~ /^cr\//) {
1.35 raeburn 3525: $showrole = &Apache::lonnet::plaintext($role,$crstype);
3526: } elsif (ref($longroles) eq 'HASH') {
3527: if ($longroles->{$role} ne '') {
3528: $showrole = $longroles->{$role};
3529: }
1.28 raeburn 3530: }
1.35 raeburn 3531: if ($start <= $now) {
3532: $active .= '<li><a href="/adm/roles?selectrole=1&'.
3533: $spec.'=1">'.$showrole;
3534: if ($usec ne '') {
3535: $active .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 3536: }
1.35 raeburn 3537: $active .= '</a></li>';
3538: $numactive ++;
3539: } else {
3540: $future .= '<li>'.$showrole;
3541: if ($usec ne '') {
3542: $future .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 3543: }
1.35 raeburn 3544: $future .= '</li>';
3545: $numfuture ++;
1.28 raeburn 3546: }
3547: }
3548: }
3549: }
3550: }
3551: }
3552: if ($active) {
3553: if ($numactive == 1) {
1.41 raeburn 3554: if ($crstype eq 'Community') {
3555: $output = &mt('Use the following link to enter the community:');
3556: } else {
3557: $output = &mt('Use the following link to enter the course:');
3558: }
1.28 raeburn 3559: } else {
1.41 raeburn 3560: if ($crstype eq 'Community') {
3561: $output = &mt('Use the following links to your new roles to enter the community:');
3562: } else {
3563: $output = &mt('Use the following links to your new roles to enter the course:');
3564: }
1.28 raeburn 3565: }
3566: $output .= ' <ul>'.$active.'</ul><br />';
3567: }
3568: if ($future) {
1.41 raeburn 3569: if ($crstype eq 'Community') {
3570: $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'}))
3571: } else {
3572: $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'}));
3573: }
3574: $output .= ' <ul>'.$future.'</ul>';
1.28 raeburn 3575: }
3576: return $output;
3577: }
3578:
1.16 raeburn 3579: sub notification_information {
3580: my ($disposition,$req_notifylist,$cnum,$now) = @_;
3581: my %emails = &Apache::loncommon::getemails();
3582: my $address;
3583: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
3584: $address = $emails{'permanentemail'};
3585: if ($address eq '') {
3586: $address = $emails{'notification'};
3587: }
3588: }
3589: my $output;
3590: if ($disposition eq 'approval') {
3591: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
3592: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
3593: if ($address ne '') {
3594: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
3595: }
3596: if ($req_notifylist) {
3597: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3598: $env{'user.domain'});
3599: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
3600: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
3601: }
1.17 raeburn 3602: } elsif ($disposition eq 'pending') {
1.16 raeburn 3603: $output .= '<div class="LC_info">'.
3604: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
3605: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
3606: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
3607: '</div>';
1.17 raeburn 3608: } else {
3609: $output .= '<div class="LC_warning">'.
1.44 raeburn 3610: &mt('Your request status is: [_1].',$disposition).
3611: '</div>';
1.8 raeburn 3612: }
3613: return $output;
3614: }
3615:
3616: sub check_autolimit {
1.10 raeburn 3617: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
3618: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
1.41 raeburn 3619: 'userroles',['active','future'],['cc','co'],[$dom]);
1.37 raeburn 3620: my ($types,$typename) = &Apache::loncommon::course_types();
1.10 raeburn 3621: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
1.41 raeburn 3622: my $count = 0;
1.10 raeburn 3623: foreach my $key (keys(%requests)) {
3624: my ($cdom,$cnum) = split('_',$key);
1.41 raeburn 3625: if (ref($requests{$key}) eq 'HASH') {
3626: next if ($requests{$key}{'crstype'} ne $crstype);
3627: if (($crstype eq 'community') &&
3628: (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
3629: $count ++;
3630: } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
3631: (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
3632: $count ++;
1.10 raeburn 3633: }
3634: }
3635: }
1.41 raeburn 3636: if ($count < $limit) {
1.10 raeburn 3637: return 'process';
3638: } else {
3639: if (ref($typename) eq 'HASH') {
1.41 raeburn 3640: if ($crstype eq 'community') {
3641: $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
3642: '<br />'.&mt("Your limit is [_1].",$limit);
3643: } else {
3644: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
3645: '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
3646: }
1.10 raeburn 3647: }
3648: return 'rejected';
3649: }
1.1 raeburn 3650: return;
3651: }
3652:
1.2 raeburn 3653: sub retrieve_settings {
1.26 raeburn 3654: my ($dom,$cnum,$udom,$uname) = @_;
3655: if ($udom eq '' || $uname eq '') {
3656: $udom = $env{'user.domain'};
3657: $uname = $env{'user.name'};
3658: }
3659: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16 raeburn 3660: if ($result eq 'ok') {
1.26 raeburn 3661: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
1.16 raeburn 3662: $env{'form.chome'} = $reqinfo{'coursehome'};
3663: $env{'form.cdescr'} = $reqinfo{'cdescr'};
3664: $env{'form.crstype'} = $reqinfo{'crstype'};
3665: &generate_date_items($reqinfo{'accessstart'},'accessstart');
3666: &generate_date_items($reqinfo{'accessend'},'accessend');
3667: if ($reqinfo{'accessend'} == 0) {
3668: $env{'form.no_end_date'} = 1;
3669: }
3670: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
3671: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
3672: &generate_date_items($reqinfo{'enrollend'},'enrollend');
3673: }
3674: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
3675: $env{'form.clonedom'} = $reqinfo{'clonedom'};
1.55 raeburn 3676: if (($reqinfo{'clonecrs'} ne '') && ($reqinfo{'clonedom'} ne '')) {
3677: $env{'form.cloning'} = 1;
3678: }
1.16 raeburn 3679: $env{'form.datemode'} = $reqinfo{'datemode'};
3680: $env{'form.dateshift'} = $reqinfo{'dateshift'};
1.59 raeburn 3681: if ($reqinfo{'crstype'} eq 'official') {
3682: $env{'form.autoadds'} = $reqinfo{'autoadds'};
3683: $env{'form.autodrops'} = $reqinfo{'autodrops'};
3684: if ($reqinfo{'instcode'} ne '') {
3685: $env{'form.sectotal'} = $reqinfo{'sectotal'};
3686: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
3687: $env{'form.instcode'} = $reqinfo{'instcode'};
3688: my $crscode = {
3689: $cnum => $reqinfo{'instcode'},
3690: };
3691: &extract_instcode($dom,'instcode',$crscode,$cnum);
3692: }
1.16 raeburn 3693: }
3694: my @currsec;
3695: if (ref($reqinfo{'sections'}) eq 'HASH') {
3696: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
3697: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24 raeburn 3698: my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16 raeburn 3699: $env{'form.secnum_'.$i} = $sec;
1.24 raeburn 3700: $env{'form.sec_'.$i} = '1';
1.16 raeburn 3701: if (!grep(/^\Q$sec\E$/,@currsec)) {
3702: push(@currsec,$sec);
3703: }
3704: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
3705: }
3706: }
3707: }
1.24 raeburn 3708: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
3709: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
3710: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
3711: $env{'form.crosslist_'.$i} = '1';
3712: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
3713: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
3714: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
3715: my $key = $cnum.$i;
3716: my $crscode = {
3717: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
3718: };
3719: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
3720: }
1.16 raeburn 3721: }
3722: }
3723: }
3724: if (ref($reqinfo{'personnel'}) eq 'HASH') {
3725: my $i = 0;
3726: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
3727: my ($uname,$udom) = split(':',$user);
3728: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
3729: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
3730: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
3731: $env{'form.person_'.$i.'_role'} = $role;
3732: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
3733: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
3734: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
3735: $env{'form.person_'.$i.'_uname'} = $uname;
3736: $env{'form.person_'.$i.'_dom'} = $udom;
3737: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
3738: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
3739: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
3740: my @newsecs;
3741: if (@usecs > 0) {
3742: foreach my $sec (@usecs) {
3743: if (grep(/^\Q$sec\E/,@currsec)) {
3744: $env{'form.person_'.$i.'_sec'} = $sec;
3745: } else {
1.20 raeburn 3746: push(@newsecs,$sec);
1.16 raeburn 3747: }
3748: }
3749: }
3750: if (@newsecs > 0) {
3751: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
3752: }
3753: }
3754: }
3755: $i ++;
3756: }
3757: }
3758: }
3759: }
3760: $env{'form.persontotal'} = $i;
3761: }
3762: }
3763: }
3764: return $result;
3765: }
3766:
3767: sub get_request_settings {
1.26 raeburn 3768: my ($dom,$cnum,$udom,$uname) = @_;
1.16 raeburn 3769: my $requestkey = $dom.'_'.$cnum;
3770: my ($result,%reqinfo);
3771: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26 raeburn 3772: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16 raeburn 3773: my $disposition = $history{'disposition'};
3774: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
3775: if (ref($history{'details'}) eq 'HASH') {
3776: %reqinfo = %{$history{'details'}};
3777: $result = 'ok';
3778: } else {
3779: $result = 'nothash';
3780: }
3781: } else {
3782: $result = 'notqueued';
3783: }
3784: } else {
3785: $result = 'invalid';
3786: }
3787: return ($result,%reqinfo);
3788: }
1.2 raeburn 3789:
1.16 raeburn 3790: sub extract_instcode {
1.24 raeburn 3791: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16 raeburn 3792: my (%codes,@codetitles,%cat_titles,%cat_order);
1.24 raeburn 3793: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
3794: \@codetitles,\%cat_titles,
3795: \%cat_order) eq 'ok') {
3796: if (ref($codes{$crskey}) eq 'HASH') {
1.16 raeburn 3797: if (@codetitles > 0) {
3798: my $sel = $element;
3799: if ($element eq 'crosslist') {
3800: $sel .= '_'.$counter;
3801: }
3802: foreach my $title (@codetitles) {
1.24 raeburn 3803: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16 raeburn 3804: }
3805: }
3806: }
3807: }
3808: return;
1.2 raeburn 3809: }
3810:
1.16 raeburn 3811: sub generate_date_items {
3812: my ($currentval,$item) = @_;
3813: if ($currentval =~ /\d+/) {
3814: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
3815: &Apache::lonhtmlcommon::get_timedates($currentval);
3816: $env{'form.'.$item.'_day'} = $mday;
3817: $env{'form.'.$item.'_month'} = $month+1;
3818: $env{'form.'.$item.'_year'} = $year;
3819: }
3820: return;
1.2 raeburn 3821: }
3822:
1.1 raeburn 3823: 1;
3824:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>