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