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