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