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